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.

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