A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <string>
  3. namespace testlib {
  4. struct TestFailure {
  5. TestFailure(const char *msg, const char *file, int line):
  6. message(msg), filename(file), linenum(line) {}
  7. const char *message;
  8. const char *filename;
  9. int linenum;
  10. };
  11. struct TestSpec;
  12. void addTestCase(TestSpec *testcase);
  13. struct TestSpec {
  14. TestSpec(void (*f)(), const char *desc, const char *file, int line, int idx):
  15. func(f), description(desc), filename(file), linenum(line), index(idx) {
  16. addTestCase(this);
  17. }
  18. void (*func)();
  19. const char *description;
  20. const char *filename;
  21. int linenum;
  22. int index;
  23. };
  24. }
  25. #define test3(name, id) name ## id
  26. #define test2(uniqid, desc) \
  27. static void test3(_test_func_, uniqid)(); \
  28. static __attribute__((unused)) testlib::TestSpec test3(_test_register_, uniqid)( \
  29. &test3(_test_func_, uniqid), desc, __FILE__, __LINE__, uniqid); \
  30. static void test3(_test_func_, uniqid)()
  31. #define test(desc) test2(__COUNTER__, desc)
  32. #define expect(expr) do { \
  33. if (!(expr)) { \
  34. throw testlib::TestFailure( \
  35. "Expected '" #expr "' to be true.", __FILE__, __LINE__); \
  36. } \
  37. } while (0)
  38. #define expecteq(a, b) do { \
  39. if ((a) != (b)) { \
  40. throw testlib::TestFailure( \
  41. "Expected '" #a "' to equal '" #b "'.", __FILE__, __LINE__); \
  42. } \
  43. } while (0)
  44. #define expectneq(a, b) do { \
  45. if ((a) == (b)) { \
  46. throw testlib::TestFailure( \
  47. "Expected '" #a "' to not equal '" #b "'.", __FILE__, __LINE__); \
  48. } \
  49. } while (0)