|
@@ -122,10 +122,111 @@
|
|
|
#define AssertPtrLE(x, y) AssertPtr(x, y, <=, >)
|
|
|
|
|
|
|
|
|
+#define EXPECT_DECLS \
|
|
|
+ int _ret = 0
|
|
|
+#define EXPECT_RESULT() \
|
|
|
+ ((_ret == 0) ? TEST_SUCCESS : TEST_FAIL)
|
|
|
+#define EXPECT_SUCCESS() \
|
|
|
+ (_ret == 0)
|
|
|
+#define EXPECT_FAIL() \
|
|
|
+ (_ret != 0)
|
|
|
+
|
|
|
+#define ExpFail(description, result) do { \
|
|
|
+ printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
|
|
|
+ fputs("\n expected: ", stdout); printf description; \
|
|
|
+ fputs("\n result: ", stdout); printf result; fputs("\n\n", stdout); \
|
|
|
+ fflush(stdout); \
|
|
|
+ _ret = -1; \
|
|
|
+} while (0)
|
|
|
+
|
|
|
+#define Expect(test, description, result) \
|
|
|
+ if ((_ret == 0) && (!(test))) ExpFail(description, result)
|
|
|
+
|
|
|
+#define ExpectTrue(x) Expect( (x), ("%s is true", #x), (#x " => FALSE"))
|
|
|
+#define ExpectFalse(x) Expect(!(x), ("%s is false", #x), (#x " => TRUE"))
|
|
|
+#define ExpectNotNull(x) Expect( (x), ("%s is not null", #x), (#x " => NULL"))
|
|
|
+
|
|
|
+#define ExpectNull(x) do { \
|
|
|
+ if (_ret == 0) { \
|
|
|
+ PEDANTIC_EXTENSION void* _x = (void*)(x); \
|
|
|
+ Expect(!_x, ("%s is null", #x), (#x " => %p", _x)); \
|
|
|
+ } \
|
|
|
+} while(0)
|
|
|
+
|
|
|
+#define ExpectInt(x, y, op, er) do { \
|
|
|
+ if (_ret == 0) { \
|
|
|
+ int _x = (int)(x); \
|
|
|
+ int _y = (int)(y); \
|
|
|
+ Expect(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y));\
|
|
|
+ } \
|
|
|
+} while(0)
|
|
|
+
|
|
|
+#define ExpectIntEQ(x, y) ExpectInt(x, y, ==, !=)
|
|
|
+#define ExpectIntNE(x, y) ExpectInt(x, y, !=, ==)
|
|
|
+#define ExpectIntGT(x, y) ExpectInt(x, y, >, <=)
|
|
|
+#define ExpectIntLT(x, y) ExpectInt(x, y, <, >=)
|
|
|
+#define ExpectIntGE(x, y) ExpectInt(x, y, >=, <)
|
|
|
+#define ExpectIntLE(x, y) ExpectInt(x, y, <=, >)
|
|
|
+
|
|
|
+#define ExpectStr(x, y, op, er) do { \
|
|
|
+ if (_ret == 0) { \
|
|
|
+ const char* _x = (const char*)(x); \
|
|
|
+ const char* _y = (const char*)(y); \
|
|
|
+ int _z = (_x && _y) ? strcmp(_x, _y) : -1; \
|
|
|
+ Expect(_z op 0, ("%s " #op " %s", #x, #y), \
|
|
|
+ ("\"%s\" " #er " \"%s\"", _x, _y));\
|
|
|
+ } \
|
|
|
+} while(0)
|
|
|
+
|
|
|
+#define ExpectStrEQ(x, y) ExpectStr(x, y, ==, !=)
|
|
|
+#define ExpectStrNE(x, y) ExpectStr(x, y, !=, ==)
|
|
|
+#define ExpectStrGT(x, y) ExpectStr(x, y, >, <=)
|
|
|
+#define ExpectStrLT(x, y) ExpectStr(x, y, <, >=)
|
|
|
+#define ExpectStrGE(x, y) ExpectStr(x, y, >=, <)
|
|
|
+#define ExpectStrLE(x, y) ExpectStr(x, y, <=, >)
|
|
|
+
|
|
|
+#define ExpectPtr(x, y, op, er) do { \
|
|
|
+ if (_ret == 0) { \
|
|
|
+ PRAGMA_GCC_DIAG_PUSH; \
|
|
|
+ /* remarkably, without this inhibition, */ \
|
|
|
+ /* the _Pragma()s make the declarations warn. */ \
|
|
|
+ PRAGMA_GCC("GCC diagnostic ignored \"-Wdeclaration-after-statement\"");\
|
|
|
+ /* inhibit "ISO C forbids conversion of function pointer */ \
|
|
|
+ /* to object pointer type [-Werror=pedantic]" */ \
|
|
|
+ PRAGMA_GCC("GCC diagnostic ignored \"-Wpedantic\""); \
|
|
|
+ void* _x = (void*)(x); \
|
|
|
+ void* _y = (void*)(y); \
|
|
|
+ Expect(_x op _y, ("%s " #op " %s", #x, #y), ("%p " #er " %p", _x, _y));\
|
|
|
+ PRAGMA_GCC_DIAG_POP; \
|
|
|
+ } \
|
|
|
+} while(0)
|
|
|
+
|
|
|
+#define ExpectPtrEq(x, y) ExpectPtr(x, y, ==, !=)
|
|
|
+#define ExpectPtrNE(x, y) ExpectPtr(x, y, !=, ==)
|
|
|
+#define ExpectPtrGT(x, y) ExpectPtr(x, y, >, <=)
|
|
|
+#define ExpectPtrLT(x, y) ExpectPtr(x, y, <, >=)
|
|
|
+#define ExpectPtrGE(x, y) ExpectPtr(x, y, >=, <)
|
|
|
+#define ExpectPtrLE(x, y) ExpectPtr(x, y, <=, >)
|
|
|
+
|
|
|
+#define ExpectBuf(x, y, z, op, er) do { \
|
|
|
+ if (_ret == 0) { \
|
|
|
+ const byte* _x = (const byte*)(x); \
|
|
|
+ const byte* _y = (const byte*)(y); \
|
|
|
+ int _z = (int)(z); \
|
|
|
+ int _w = ((_x) && (_y)) ? XMEMCMP(_x, _y, _z) : -1; \
|
|
|
+ Expect(_w op 0, ("%s " #op " %s for %s", #x, #y, #z), \
|
|
|
+ ("\"%p\" " #er " \"%p\" for \"%d\"", _x, _y, _z));\
|
|
|
+ } \
|
|
|
+} while(0)
|
|
|
+
|
|
|
+#define ExpectBufEQ(x, y, z) ExpectBuf(x, y, z, ==, !=)
|
|
|
+#define ExpectBufNE(x, y, z) ExpectBuf(x, y, z, !=, ==)
|
|
|
+
|
|
|
+
|
|
|
void ApiTest_PrintTestCases(void);
|
|
|
int ApiTest_RunIdx(int idx);
|
|
|
int ApiTest_RunName(char* name);
|
|
|
-void ApiTest(void);
|
|
|
+int ApiTest(void);
|
|
|
|
|
|
int SuiteTest(int argc, char** argv);
|
|
|
int HashTest(void);
|