unit.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* unit.h unit tests driver */
  2. #ifndef CyaSSL_UNIT_H
  3. #define CyaSSL_UNIT_H
  4. #include <cyassl/test.h> /* thread and tcp stuff */
  5. #define Fail(description, result) do { \
  6. printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
  7. printf("\n\n test: "); printf description; \
  8. printf("\n\n result: "); printf result; \
  9. abort(); \
  10. } while(0)
  11. #define Assert(test, description, result) if (!(test)) Fail(description, result)
  12. #define AssertTrue(x) Assert( (x), ("%s is true", #x), (#x " => FALSE"))
  13. #define AssertFalse(x) Assert(!(x), ("%s is false", #x), (#x " => TRUE"))
  14. #define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL"))
  15. #define AssertNull(x) do { \
  16. void* _x = (void *) (x); \
  17. \
  18. Assert(!_x, ("%s is null", #x), (#x " => %p", _x)); \
  19. } while(0)
  20. #define AssertInt(x, y, op, er) do { \
  21. int _x = x; \
  22. int _y = y; \
  23. \
  24. Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y)); \
  25. } while(0)
  26. #define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
  27. #define AssertIntNE(x, y) AssertInt(x, y, !=, ==)
  28. #define AssertIntGT(x, y) AssertInt(x, y, >, <=)
  29. #define AssertIntLT(x, y) AssertInt(x, y, <, >=)
  30. #define AssertIntGE(x, y) AssertInt(x, y, >=, <)
  31. #define AssertIntLE(x, y) AssertInt(x, y, <=, >)
  32. #define AssertStr(x, y, op, er) do { \
  33. const char* _x = x; \
  34. const char* _y = y; \
  35. int _z = strcmp(_x, _y); \
  36. \
  37. Assert(_z op 0, ("%s " #op " %s", #x, #y), \
  38. ("\"%s\" " #er " \"%s\"", _x, _y));\
  39. } while(0)
  40. #define AssertStrEQ(x, y) AssertStr(x, y, ==, !=)
  41. #define AssertStrNE(x, y) AssertStr(x, y, !=, ==)
  42. #define AssertStrGT(x, y) AssertStr(x, y, >, <=)
  43. #define AssertStrLT(x, y) AssertStr(x, y, <, >=)
  44. #define AssertStrGE(x, y) AssertStr(x, y, >=, <)
  45. #define AssertStrLE(x, y) AssertStr(x, y, <=, >)
  46. void ApiTest(void);
  47. int SuiteTest(void);
  48. int HashTest(void);
  49. #endif /* CyaSSL_UNIT_H */