1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #ifndef _LSUP_TEST_H
- #define _LSUP_TEST_H
- #include <stdio.h>
- #include <stdlib.h>
- #include "lsup_rdf.h"
- /**
- * Minimal unit testing framework.
- * Inspired from http://www.jera.com/techinfo/jtns/jtn002.html
- */
- // NT tests are exposed to multiple test units.
- char *start_nt_doc, *bad_nt_doc;
- char *end_nt_doc[7];
- LSUP_Codec codec;
- // These are used by other codecs than just NT.
- LSUP_Term **init_terms (void);
- void init_triples(LSUP_Term **terms);
- void free_terms (LSUP_Term **terms);
- int test_encode_nt_term();
- int test_encode_nt_graph();
- int test_decode_nt_graph();
- int test_decode_nt_bad_graph();
- /** @brief assert true.
- */
- #define ASSERT(test, msg) do { \
- if (!(test)) {\
- log_error (\
- "!!! Assertion failed at %s:%d. Message: %s\n", \
- __FILE__, __LINE__, msg); \
- return -1; \
- }\
- } while (0)
- /** @brief Expect that two int values are equal.
- */
- #define EXPECT_INT_EQ(got, exp) do { \
- if ((exp) != (got)) {\
- log_error (\
- "!!! Test failed at %s:%d. Expected: %lu; got: %lu\n",\
- __FILE__, __LINE__, (size_t)(exp), (size_t)(got)); \
- return -1; \
- }\
- } while (0)
- /** @brief Expect that two string values are equal.
- */
- #define EXPECT_STR_EQ(got, exp) do { \
- const char *_str1 = (exp); \
- const char *_str2 = (got); \
- if (((_str1 == NULL) ^ (_str2 == NULL)) || strcmp(_str1, _str2) != 0) {\
- log_error (\
- "!!! Test failed at %s:%d. Expected: %s; got: %s\n", \
- __FILE__, __LINE__, (exp), (got)); \
- return -1; \
- }\
- } while (0)
- #define EXPECT_PASS(exp) do { \
- int _rc = (exp); \
- if (_rc != LSUP_OK) {\
- log_error (\
- "!!! Test failed at %s:%d. Error: %s (%d)\n",\
- __FILE__, __LINE__, LSUP_strerror(_rc), _rc); \
- return -1; \
- }\
- } while (0)
- /** @brief Run a test by function name.
- *
- * The function must not accept any parameters.
- */
- #define RUN(test) do { int rc = test(); tests_run++; \
- if (rc != 0) return -1; } while (0)
- int tests_run;
- #endif /* _LSUP_TEST_H */
|