mctest.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. static inline int
  71. mctest_run_all (TCase * tc_core)
  72. {
  73. Suite *s;
  74. SRunner *sr;
  75. int number_failed;
  76. s = suite_create (TEST_SUITE_NAME);
  77. suite_add_tcase (s, tc_core);
  78. sr = srunner_create (s);
  79. srunner_set_log (sr, "-");
  80. srunner_run_all (sr, CK_ENV);
  81. number_failed = srunner_ntests_failed (sr);
  82. srunner_free (sr);
  83. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  84. }
  85. #endif /* MC__TEST */