diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-31 09:19:23 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-31 09:19:23 -0400 |
| commit | 11880a33f8b3dcd8ffcdbef3c956fb0d09e090db (patch) | |
| tree | 4042a64e4a276054c045e994a004e44114911715 /tests/framework.h | |
| parent | 70b7285967f9d5e6f8a8c4624b69ebf1adedca76 (diff) | |
| download | spmc-11880a33f8b3dcd8ffcdbef3c956fb0d09e090db.tar.gz | |
Add test_checksum_sha256 test
Diffstat (limited to 'tests/framework.h')
| -rw-r--r-- | tests/framework.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/framework.h b/tests/framework.h index f1ce15c..7770ed7 100644 --- a/tests/framework.h +++ b/tests/framework.h @@ -51,6 +51,28 @@ char *array_to_string(char **array, const char *sep) { return buffer; } +/** + * Write data to a file + * @param filename name of file + * @param data data to write + * @param size type of data + * @param nelem number of elements of `size` to write + * @return bytes written (0 = failure) + */ +size_t mock(const char *filename, void *data, size_t size, size_t nelem) { + unsigned long written = 0; + FILE *fp = fopen(filename, "w+b"); + if (fp == NULL) { + perror(filename); + exit(errno); + } + if ((written = fwrite(data, size, nelem, fp)) == 0) { + fprintf(stderr, "warning: %s: no data written\n", filename); + } + fclose(fp); + return written; +} + #define myassert(condition, ...) \ do { \ if (!(condition)) { \ |
