mctest.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. { \
  10. tcase_add_loop_test (tc_core, test_func, 0, G_N_ELEMENTS (test_data_source)); \
  11. }
  12. #define mctest_assert_str_eq(actual_result, etalon_result) \
  13. { \
  14. g_assert_cmpstr (actual_result, ==, etalon_result); \
  15. }
  16. #define mctest_assert_ptr_eq(actual_pointer, etalon_pointer) \
  17. { \
  18. ck_assert_msg (actual_pointer == etalon_pointer, \
  19. "%s(%p) pointer should be equal to %s(%p)\n", #actual_pointer, \
  20. actual_pointer, #etalon_pointer, etalon_pointer); \
  21. }
  22. #define mctest_assert_ptr_ne(actual_pointer, etalon_pointer) \
  23. { \
  24. ck_assert_msg (actual_pointer != etalon_pointer, \
  25. "%s(%p) pointer should not be equal to %s(%p)\n", #actual_pointer, \
  26. actual_pointer, #etalon_pointer, etalon_pointer); \
  27. }
  28. #define mctest_assert_null(actual_pointer) \
  29. { \
  30. ck_assert_msg ((void *) actual_pointer == NULL, "%s(%p) variable should be NULL", \
  31. #actual_pointer, actual_pointer); \
  32. }
  33. #define mctest_assert_not_null(actual_pointer) \
  34. { \
  35. ck_assert_msg ((void *) actual_pointer != NULL, "%s(nil) variable should not be NULL", \
  36. #actual_pointer); \
  37. }
  38. #define mctest_assert_true(actual_pointer) \
  39. { \
  40. ck_assert_msg ((int) actual_pointer != 0, "%s variable should be TRUE", #actual_pointer); \
  41. }
  42. #define mctest_assert_false(actual_pointer) \
  43. { \
  44. ck_assert_msg ((int) actual_pointer == 0, "%s variable should be FALSE", #actual_pointer); \
  45. }
  46. /**
  47. * Define header for a parameterized test.
  48. * Declare 'data' variable for access to the parameters in current iteration
  49. */
  50. #define START_PARAMETRIZED_TEST(name_test, struct_name) \
  51. START_TEST (name_test) \
  52. { \
  53. const struct struct_name *data = &struct_name[_i];
  54. /**
  55. * Define footer for a parameterized test.
  56. */
  57. #define END_PARAMETRIZED_TEST \
  58. } \
  59. END_TEST
  60. /*** enums ***************************************************************************************/
  61. /*** structures declarations (and typedefs of structures)*****************************************/
  62. /*** global variables defined in .c file *********************************************************/
  63. /*** declarations of public functions ************************************************************/
  64. /*** inline functions ****************************************************************************/
  65. static inline int
  66. mctest_run_all (TCase *tc_core)
  67. {
  68. Suite *s;
  69. SRunner *sr;
  70. int number_failed;
  71. s = suite_create (TEST_SUITE_NAME);
  72. suite_add_tcase (s, tc_core);
  73. sr = srunner_create (s);
  74. srunner_set_log (sr, "-");
  75. srunner_run_all (sr, CK_ENV);
  76. number_failed = srunner_ntests_failed (sr);
  77. srunner_free (sr);
  78. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  79. }
  80. #endif /* MC__TEST */