test_def.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. Copyright Rene Rivera 2011-2015
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/predef.h>
  8. #define BOOST_PREDEF_INTERNAL_GENERATE_TESTS
  9. void * add_predef_entry(const char * name, const char * description, unsigned value);
  10. #undef BOOST_PREDEF_DECLARE_TEST
  11. #define BOOST_PREDEF_DECLARE_TEST(x,s) void predef_entry_##x() { add_predef_entry(#x, s, x); }
  12. #include <boost/predef.h>
  13. #undef BOOST_PREDEF_DECLARE_TEST
  14. #define BOOST_PREDEF_DECLARE_TEST(x,s) predef_entry_##x();
  15. void create_predef_entries()
  16. {
  17. #include <boost/predef.h>
  18. }
  19. #ifdef __cplusplus
  20. #include <cstring>
  21. #include <cstdio>
  22. #include <cstdlib>
  23. using namespace std;
  24. #else
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #endif
  29. typedef struct predef_info
  30. {
  31. const char * name;
  32. const char * description;
  33. unsigned value;
  34. } predef_info;
  35. #ifdef __cplusplus
  36. using namespace std;
  37. #endif
  38. unsigned generated_predef_info_count = 0;
  39. predef_info* generated_predef_info = 0;
  40. void * add_predef_entry(const char * name, const char * description, unsigned value)
  41. {
  42. if (0 == generated_predef_info_count)
  43. {
  44. generated_predef_info_count = 1;
  45. generated_predef_info = (predef_info*)malloc(sizeof(predef_info));
  46. }
  47. else
  48. {
  49. generated_predef_info_count += 1;
  50. generated_predef_info = (predef_info*)realloc(generated_predef_info,
  51. generated_predef_info_count*sizeof(predef_info));
  52. }
  53. generated_predef_info[generated_predef_info_count-1].name = name;
  54. generated_predef_info[generated_predef_info_count-1].description = description;
  55. generated_predef_info[generated_predef_info_count-1].value = value;
  56. return 0;
  57. }
  58. int predef_info_compare(const void * a, const void * b)
  59. {
  60. const predef_info * i = (const predef_info *)a;
  61. const predef_info * j = (const predef_info *)b;
  62. return strcmp(i->name,j->name);
  63. }