typedef struct collection_st collection_st;
typedef struct test_st test_st;
-typedef enum {
- TEST_SUCCESS= 0, /* Backwards compatibility */
+enum test_return_t {
+ TEST_SUCCESS, /* Backwards compatibility */
TEST_FAILURE,
TEST_MEMORY_ALLOCATION_FAILURE,
TEST_SKIPPED,
+ TEST_FATAL, // Collection should not be continued
TEST_MAXIMUM_RETURN /* Always add new error code before */
-} test_return_t;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum test_return_t test_return_t;
+
+#ifdef __cplusplus
+}
+#endif
+
typedef void *(*test_callback_create_fn)(test_return_t *error);
typedef test_return_t (*test_callback_fn)(void *);
} \
} while (0)
+#define test_compare(A,B) \
+do \
+{ \
+ if ((A) != (B)) \
+ { \
+ fprintf(stderr, "\n%s:%d: Expected %s, got %lu\n", __FILE__, __LINE__, #A, (unsigned long)(B)); \
+ create_core(); \
+ return TEST_FAILURE; \
+ } \
+} while (0)
+
+#define test_skip(A,B) \
+do \
+{ \
+ if ((A) != (B)) \
+ { \
+ return TEST_SKIPPED; \
+ } \
+} while (0)
+
+#define test_compare_got(A,B,C) \
+do \
+{ \
+ if ((A) != (B)) \
+ { \
+ fprintf(stderr, "\n%s:%d: Expected %s, got %s\n", __FILE__, __LINE__, #A, (C)); \
+ create_core(); \
+ return TEST_FAILURE; \
+ } \
+} while (0)
+
#define test_false(A) \
do \
{ \
} \
} while (0)
+#define test_false_with(A,B) \
+do \
+{ \
+ if ((A)) { \
+ fprintf(stderr, "\nAssertion failed at %s:%d: %s with %s\n", __FILE__, __LINE__, #A, (B));\
+ create_core(); \
+ return TEST_FAILURE; \
+ } \
+} while (0)
+
#define test_strcmp(A,B) \
do \
{ \
if (strcmp((A), (B))) \
{ \
- fprintf(stderr, "\n%s:%d: %s -> %s\n", __FILE__, __LINE__, (A), (B)); \
+ fprintf(stderr, "\n%s:%d: `%s` -> `%s`\n", __FILE__, __LINE__, (A), (B)); \
create_core(); \
return TEST_FAILURE; \
} \
} while (0)
+#define test_memcmp(A,B,C) \
+do \
+{ \
+ if (memcmp((A), (B), (C))) \
+ { \
+ fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
+ create_core(); \
+ return TEST_FAILURE; \
+ } \
+} while (0)
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)