Permalink
Browse files

use check for unit testing

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

0 comments on commit e926c73

Please sign in to comment.