Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use check for unit testing

  • Loading branch information...
commit e926c734513b7f638ee2b3f5b440b75d6e2ea5c4 1 parent b97214e
Daniel Schauenberg authored
2  Makefile
@@ -16,7 +16,7 @@ STATIC = $(LIBDIR)/chinstrap.a
16 16
17 17 # set library and include paths
18 18 INCLUDE = -Iinclude -I/usr/local/include
19   -TESTLIBS = -lcunit#-lyajl
  19 +TESTLIBS = -lcheck#-lyajl
20 20 LIBS =
21 21
22 22 # set compiler and linker flags
45 tests/test_chinstrap_main.c
... ... @@ -1,38 +1,15 @@
1   -#include <CUnit/Basic.h>
  1 +#include <stdlib.h>
  2 +#include <check.h>
2 3
3   -extern int init_scanner_suite(void);
4   -extern int clean_scanner_suite(void);
5   -extern void test_scanner_init_with_length(void);
6   -extern void test_scanner_init_without_length(void);
  4 +Suite* scanner_suite (void);
7 5
8   -int main()
  6 +int
  7 +main (void)
9 8 {
10   - CU_pSuite pSuite = NULL;
11   -
12   - /* initialize the CUnit test registry */
13   - if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error();
14   -
15   - /* add a suite to the registry */
16   - pSuite = CU_add_suite("scanner tests", init_scanner_suite,
17   - clean_scanner_suite);
18   - if (NULL == pSuite) {
19   - CU_cleanup_registry();
20   - return CU_get_error();
21   - }
22   -
23   - /* add the tests to the suite */
24   - /* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
25   - if ((NULL == CU_add_test(pSuite, "scanner init with length", test_scanner_init_with_length)) ||
26   - (NULL == CU_add_test(pSuite, "scanner init without length", test_scanner_init_without_length))
27   - )
28   - {
29   - CU_cleanup_registry();
30   - return CU_get_error();
31   - }
32   -
33   - /* Run all tests using the CUnit Basic interface */
34   - //CU_basic_set_mode(CU_BRM_VERBOSE);
35   - CU_automated_run_tests();
36   - CU_cleanup_registry();
37   - return CU_get_error();
  9 + int number_failed;
  10 + SRunner *sr = srunner_create (scanner_suite());
  11 + srunner_run_all (sr, CK_NORMAL);
  12 + number_failed = srunner_ntests_failed (sr);
  13 + srunner_free (sr);
  14 + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
38 15 }
55 tests/test_chinstrap_scanner.c
... ... @@ -1,37 +1,40 @@
1   -#include "CUnit/Basic.h"
2   -#include "chinstrap/scanner.h"
  1 +#include <check.h>
3 2 #include <string.h>
  3 +#include "chinstrap/scanner.h"
4 4
5   -
6   -static scanner s;
7   -static scanner s2;
8   -
9   -int init_scanner_suite(void)
  5 +START_TEST (test_scanner_init_with_length)
10 6 {
11   - s = scanner_init("foobar", 6);
12   - s2 = scanner_init("foobar", -1);
13   - return 0;
  7 + scanner s = scanner_init("foobar", 6);
  8 + fail_unless(s.current_row == 0);
  9 + fail_unless(s.current_col == 0);
  10 + fail_unless(strcmp(s.thetemplate, "foobar"));
  11 + fail_unless(s.template_length == 6);
  12 + fail_unless(s.pos == 0);
14 13 }
  14 +END_TEST
15 15
16   -int clean_scanner_suite(void)
17   -{
18   - return 0;
19   -}
20 16
21   -void test_scanner_init_with_length(void)
  17 +START_TEST (test_scanner_init_without_length)
22 18 {
23   - CU_ASSERT(s.current_row == 0);
24   - CU_ASSERT(s.current_col == 0);
25   - CU_ASSERT(strcmp(s.thetemplate, "foobar"));
26   - CU_ASSERT(s.template_length == 6);
27   - CU_ASSERT(s.pos == 0);
  19 + scanner s = scanner_init("foobar", -1);
  20 + fail_unless(s.current_row == 0);
  21 + fail_unless(s.current_col == 0);
  22 + fail_unless(strcmp(s.thetemplate, "foobar"));
  23 + fail_unless(s.template_length == 6);
  24 + fail_unless(s.pos == 0);
28 25 }
  26 +END_TEST
29 27
30   -void test_scanner_init_without_length(void)
  28 +Suite *
  29 +scanner_suite (void)
31 30 {
32   - CU_ASSERT(s.current_row == 0);
33   - CU_ASSERT(s.current_col == 0);
34   - CU_ASSERT(strcmp(s.thetemplate, "foobar"));
35   - CU_ASSERT(s.template_length == 6);
36   - CU_ASSERT(s.pos == 0);
  31 + Suite *s = suite_create ("Scanner");
  32 +
  33 + /* Core test case */
  34 + TCase *tc_core = tcase_create ("Core");
  35 + tcase_add_test (tc_core, test_scanner_init_with_length);
  36 + tcase_add_test (tc_core, test_scanner_init_without_length);
  37 + suite_add_tcase (s, tc_core);
  38 +
  39 + return s;
37 40 }

0 comments on commit e926c73

Please sign in to comment.
Something went wrong with that request. Please try again.