mctest.h 3.0 KB

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