mctest.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef MC__TEST
  2. #define MC__TEST
  3. #include <config.h>
  4. #include <stdlib.h>
  5. #include <check.h>
  6. #include "lib/global.h"
  7. /*** typedefs(not structures) and defined constants **********************************************/
  8. #define mctest_add_parameterized_test(tc_core, test_func, test_data_source) {\
  9. tcase_add_loop_test (tc_core, test_func, 0, G_N_ELEMENTS (test_data_source)); \
  10. }
  11. #define mctest_assert_str_eq(actual_result, etalon_result) { \
  12. g_assert_cmpstr (actual_result, ==, etalon_result); \
  13. }
  14. #define mctest_assert_int_eq(actual_result, etalon_result) { \
  15. ck_assert_int_eq (actual_result, etalon_result); \
  16. }
  17. #define mctest_assert_int_ne(actual_result, etalon_result) { \
  18. ck_assert_int_ne (actual_result, etalon_result); \
  19. }
  20. #define mctest_assert_ptr_eq(actual_pointer, etalon_pointer) { \
  21. ck_assert_msg ( actual_pointer == etalon_pointer, \
  22. "%s(%p) pointer should be equal to %s(%p)\n", \
  23. #actual_pointer, actual_pointer, #etalon_pointer , etalon_pointer \
  24. );\
  25. }
  26. #define mctest_assert_ptr_ne(actual_pointer, etalon_pointer) { \
  27. ck_assert_msg ( actual_pointer != etalon_pointer, \
  28. "%s(%p) pointer should not be equal to %s(%p)\n", \
  29. #actual_pointer, actual_pointer, #etalon_pointer , etalon_pointer \
  30. );\
  31. }
  32. #define mctest_assert_null(actual_pointer) { \
  33. ck_assert_msg( \
  34. (void *) actual_pointer == NULL, \
  35. "%s(%p) variable should be NULL", #actual_pointer, actual_pointer \
  36. ); \
  37. }
  38. #define mctest_assert_not_null(actual_pointer) { \
  39. ck_assert_msg( \
  40. (void *) actual_pointer != NULL, \
  41. "%s(nil) variable should not be NULL", #actual_pointer \
  42. ); \
  43. }
  44. #define mctest_assert_true(actual_pointer) { \
  45. ck_assert_msg( \
  46. (int) actual_pointer != 0, \
  47. "%s variable should be TRUE", #actual_pointer \
  48. ); \
  49. }
  50. #define mctest_assert_false(actual_pointer) { \
  51. ck_assert_msg( \
  52. (int) actual_pointer == 0, \
  53. "%s variable should be TRUE", #actual_pointer \
  54. ); \
  55. }
  56. /**
  57. * Define header for a parameterized test.
  58. * Declare 'data' variable for access to the parameters in current iteration
  59. */
  60. #define START_PARAMETRIZED_TEST(name_test, struct_name) START_TEST (name_test) { const struct struct_name *data = &struct_name[_i];
  61. /**
  62. * Define footer for a parameterized test.
  63. */
  64. #define END_PARAMETRIZED_TEST } END_TEST
  65. /*** enums ***************************************************************************************/
  66. /*** structures declarations (and typedefs of structures)*****************************************/
  67. /*** global variables defined in .c file *********************************************************/
  68. /*** declarations of public functions ************************************************************/
  69. /*** inline functions ****************************************************************************/
  70. #endif /* MC__TEST */