Advertisement
map_

C test framework proto

Jan 16th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4. // Here begins the framework header
  5.  
  6. int register_test(const char *name, void (*ptr)());
  7.  
  8. #define STRINGIFY(s) #s
  9.  
  10. // NOTE: The trick below, initializing a constant with an expression, doesn't work in C.
  11. // It works in C++ BUT the order of initialization is undefined. It's possible to maintain a
  12. // counter in a macro variable (e.g. Boost preprocessor does this),
  13. // or one could just run the tests in alphabetical order if one is lazy.
  14.  
  15. #define TEST(name) \
  16.   static void name(); \
  17.   static int name ## _registration = register_test(STRINGIFY(name), &name); \
  18.   static void name()
  19.  
  20.  
  21. // Here begins the framework implementation
  22.  
  23. int register_test(const char *name, void (*ptr)())
  24. {
  25.     printf("Adding test %s (%p) to global list.\n", name, ptr);
  26.     /* TODO */
  27.     return 0; // Dummy return
  28. }
  29.  
  30. // Here ends the framework
  31.  
  32. TEST(my_test) {
  33.     printf("trololoo\n");
  34. }
  35.  
  36. int main()
  37. {
  38.     /* run_all_tests(); */
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement