summaryrefslogtreecommitdiff
path: root/tests/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/common.h')
-rw-r--r--tests/common.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/common.h b/tests/common.h
new file mode 100644
index 0000000..97f0a22
--- /dev/null
+++ b/tests/common.h
@@ -0,0 +1,47 @@
+#ifndef _test_common_h_
+#define _test_common_h_
+
+#include <stdlib.h>
+
+/**
+ * Common functions for test.
+ */
+
+#define test_result(val) \
+{ \
+ if (!(val)) {\
+ fprintf(stderr, "Test \"%s\" failed!\n", ""#val); \
+ exit(2); \
+ } \
+}
+
+#define test_string(expected, actual, length) \
+{ \
+ for (i = 0; i < length; i++) { \
+ if ((unsigned char)expected[i] != actual[i]) { \
+ fprintf(stderr, "Test \"%s\" == \"%s\" failed!\n", ""#expected, ""#actual); \
+ fprintf(stderr, "[%d] \\x%02X != \\x%02X\n", (int)i, (unsigned char)expected[i], actual[i]); \
+ exit(2); \
+ } \
+ } \
+}
+
+#define gammu_test_result(error, text) \
+{ \
+ if (error != ERR_NONE) {\
+ fprintf(stderr, "%s\n", GSM_ErrorString(error)); \
+ fprintf(stderr, "Test \"%s\" failed!\n", text); \
+ exit(2); \
+ } \
+}
+
+#define gammu_test_result_code(error, text, expect) \
+{ \
+ if (error != expect) {\
+ fprintf(stderr, "%s\n", GSM_ErrorString(error)); \
+ fprintf(stderr, "Test \"%s\" failed!\n", text); \
+ exit(2); \
+ } \
+}
+
+#endif