diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-24 12:27:33 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-24 12:27:33 -0400 |
commit | ad07c35f12ca10bd3dfea50aaf8a9db8dcc9f630 (patch) | |
tree | 4b31aa43dcb942611fef8699bc96d166cf63b68e /tests/framework.h | |
parent | ccaeb7092b5ad40b1b3833c987ba3ec4d47f0bb8 (diff) | |
download | spmc-ad07c35f12ca10bd3dfea50aaf8a9db8dcc9f630.tar.gz |
Initial commit of tests
Diffstat (limited to 'tests/framework.h')
-rw-r--r-- | tests/framework.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/framework.h b/tests/framework.h new file mode 100644 index 0000000..1e5adaa --- /dev/null +++ b/tests/framework.h @@ -0,0 +1,61 @@ +#ifndef SPM_FRAMEWORK_H +#define SPM_FRAMEWORK_H +#include <limits.h> +#include <fcntl.h> + +union TestValue { + const char *sptr; + char **slptr; + char character; + unsigned int unsigned_integer; + signed int signed_integer; + float floating; + char str[PATH_MAX]; +}; + +struct TestCase { + union TestValue caseValue; + union TestValue inputValue; + union TestValue truthValue; +}; + +char *array_to_string(char **array, const char *sep) { + char *buffer = NULL; + size_t buffer_size = 0; + size_t records = 0; + + if (array == NULL || sep == NULL) { + return NULL; + } + + for (records = 0; array[records] != NULL; records++) { + buffer_size += strlen(array[records]) + 1; + } + buffer_size++; + + buffer = calloc(buffer_size, sizeof(char)); + if (buffer == NULL) { + perror("could not allocate buffer"); + exit(1); + } + + for (size_t i = 0; i < records; i++) { + for (size_t ch = 0; ch < strlen(array[i]); ch++) { + strncat(buffer, &array[i][ch], 1); + } + if ((records - (i + 1)) > 0) + strncat(buffer, sep, 2); + } + return buffer; +} + +#define myassert(condition, ...) \ + do { \ + if (!(condition)) { \ + fprintf(stderr, "%s:%d:%s :: ", __FILE__, __LINE__, __FUNCTION__); \ + fprintf(stderr, __VA_ARGS__); \ + return 1; \ + } \ + } while (0) + +#endif //SPM_FRAMEWORK_H |