aboutsummaryrefslogtreecommitdiff
path: root/tests/framework.h
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-03-31 09:23:36 -0400
committerGitHub <noreply@github.com>2020-03-31 09:23:36 -0400
commitbcc9a422cdd0f6b801b5bd4044125219cb3b74a6 (patch)
tree4042a64e4a276054c045e994a004e44114911715 /tests/framework.h
parent70b7285967f9d5e6f8a8c4624b69ebf1adedca76 (diff)
parent11880a33f8b3dcd8ffcdbef3c956fb0d09e090db (diff)
downloadspmc-bcc9a422cdd0f6b801b5bd4044125219cb3b74a6.tar.gz
Merge pull request #9 from jhunkeler/test-sha256
Add test_checksum_sha256 test
Diffstat (limited to 'tests/framework.h')
-rw-r--r--tests/framework.h22
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)) { \