aboutsummaryrefslogtreecommitdiff
path: root/tests/framework.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/framework.h')
-rw-r--r--tests/framework.h61
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