Test.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef CORE_TEST_H
  2. #define CORE_TEST_H
  3. #include "core/Types.h"
  4. void coreFinalizeTests(void);
  5. #define CORE_TEST_ARGS const char *file, int line
  6. #define CORE_TEST_FUNCTION(name, type) \
  7. bool coreTest##name(CORE_TEST_ARGS, type wanted, type actual)
  8. CORE_TEST_FUNCTION(Int, int);
  9. CORE_TEST_FUNCTION(I64, i64);
  10. CORE_TEST_FUNCTION(U64, u64);
  11. CORE_TEST_FUNCTION(Size, size_t);
  12. CORE_TEST_FUNCTION(Bool, bool);
  13. CORE_TEST_FUNCTION(String, const char*);
  14. bool coreTestFloat(CORE_TEST_ARGS, float wanted, float actual, float error);
  15. bool coreTestNull(CORE_TEST_ARGS, const void* p);
  16. bool coreTestNotNull(CORE_TEST_ARGS, const void* p);
  17. #define CORE_TEST(wanted, actual, name) \
  18. coreTest##name(__FILE__, __LINE__, wanted, actual)
  19. #define CORE_TEST_FLOAT(wanted, actual, error) \
  20. coreTestFloat(__FILE__, __LINE__, wanted, actual, error)
  21. #define CORE_TEST_BOOL(wanted, actual) CORE_TEST(wanted, actual, Bool)
  22. #define CORE_TEST_INT(wanted, actual) CORE_TEST(wanted, actual, Int)
  23. #define CORE_TEST_I64(wanted, actual) CORE_TEST(wanted, actual, I64)
  24. #define CORE_TEST_U64(wanted, actual) CORE_TEST(wanted, actual, U64)
  25. #define CORE_TEST_SIZE(wanted, actual) CORE_TEST(wanted, actual, Size)
  26. #define CORE_TEST_STRING(wanted, actual) CORE_TEST(wanted, actual, String)
  27. #define CORE_TEST_FALSE(actual) CORE_TEST(false, actual, Bool)
  28. #define CORE_TEST_TRUE(actual) CORE_TEST(true, actual, Bool)
  29. #define CORE_TEST_NULL(actual) coreTestNull(__FILE__, __LINE__, actual)
  30. #define CORE_TEST_NOT_NULL(actual) coreTestNotNull(__FILE__, __LINE__, actual)
  31. bool coreTestVectorN(CORE_TEST_ARGS, const float* wanted, const float* actual,
  32. size_t n);
  33. #define CORE_TEST_V2(wanted, actual) \
  34. coreTestVectorN(__FILE__, __LINE__, (wanted)->data, (actual)->data, 2)
  35. #define CORE_TEST_V3(wanted, actual) \
  36. coreTestVectorN(__FILE__, __LINE__, (wanted)->data, (actual)->data, 3)
  37. #define CORE_TEST_V4(wanted, actual) \
  38. coreTestVectorN(__FILE__, __LINE__, (wanted)->data, (actual)->data, 4)
  39. bool coreTestIntVectorN(CORE_TEST_ARGS, const int* wanted, const int* actual,
  40. size_t n);
  41. #define CORE_TEST_IV2(wanted, actual) \
  42. coreTestIntVectorN(__FILE__, __LINE__, (wanted)->data, (actual)->data, 2)
  43. #define CORE_TEST_IV3(wanted, actual) \
  44. coreTestIntVectorN(__FILE__, __LINE__, (wanted)->data, (actual)->data, 3)
  45. #define CORE_TEST_IV4(wanted, actual) \
  46. coreTestIntVectorN(__FILE__, __LINE__, (wanted)->data, (actual)->data, 4)
  47. #endif