├── checkmk ├── doc │ ├── manpage.links │ └── manpage.refs ├── test │ ├── empty_input │ │ ├── in │ │ ├── x_output │ │ └── x_err │ ├── name_enc │ │ ├── cmd │ │ └── x_output │ ├── single_test_line │ │ ├── in │ │ └── x_output │ ├── pass_thru │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── repeated_tests │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── repeated_suites │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── main_post_multiple │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── main_pre_multiple │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── no_args │ │ ├── cmd │ │ ├── in │ │ └── x_output │ ├── repeated_argument_tests │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── repeated_tcases │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── tcase_implied_repeat │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── main_pre_after_post │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── clean_mode │ │ ├── cmd │ │ ├── in │ │ └── x_output │ ├── test_after_main_pre │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── test_chars │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── num_start_test_name │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── test_after_main_post │ │ ├── x_err │ │ ├── in │ │ └── x_output │ ├── invalid_ucn │ │ ├── x_err │ │ ├── x_output │ │ └── in │ ├── between_the_lines │ │ ├── in │ │ └── x_output │ ├── basic_complete │ │ ├── in │ │ └── x_output │ ├── ucn │ │ ├── in │ │ └── x_output │ ├── case_insensitive_pp │ │ ├── in │ │ └── x_output │ ├── non_word_chars │ │ ├── in │ │ └── x_output │ ├── trailing_ws │ │ ├── in │ │ └── x_output │ ├── declarations │ │ ├── in │ │ └── x_output │ ├── main_post │ │ ├── in │ │ └── x_output │ ├── not_really_repeated │ │ ├── in │ │ └── x_output │ ├── multiple_everything │ │ ├── in │ │ └── x_output │ └── argument_ws │ │ └── in ├── examples │ ├── basic_complete.ts │ └── multiple_everything.ts ├── Makefile.am ├── README └── CMakeLists.txt ├── doc ├── man │ ├── Makefile.am │ ├── man7 │ │ ├── Makefile.am │ │ ├── libcheck.7.in │ │ └── CMakeLists.txt │ ├── man3 │ │ ├── Makefile.am │ │ ├── suite_create.3.in │ │ └── CMakeLists.txt │ └── CMakeLists.txt ├── example │ ├── Makefile.am │ ├── src │ │ ├── Makefile.am │ │ ├── CMakeLists.txt │ │ ├── money.1.c │ │ ├── money.1.h │ │ ├── money.2.h │ │ ├── money.h │ │ ├── main.c │ │ ├── money.3.c │ │ ├── money.4.c │ │ ├── money.5.c │ │ ├── money.c │ │ └── money.6.c │ ├── tests │ │ ├── Makefile.am │ │ ├── CMakeLists.txt │ │ ├── check_money.1.c │ │ ├── check_money.2.c │ │ ├── check_money.3.c │ │ ├── check_money.6.c │ │ ├── check_money.7.c │ │ └── check_money.c │ ├── cmake │ │ ├── config.h.in │ │ ├── COPYING-CMAKE-SCRIPTS.txt │ │ └── FindCheck.cmake │ ├── configure.ac │ └── README └── CMakeLists.txt ├── .github └── ISSUE_TEMPLATE │ ├── config.yml │ └── bug.md ├── web ├── img │ ├── menu_bg.gif │ ├── side_bg.gif │ ├── tab_bg.gif │ └── header_bg.gif └── License.txt ├── cmake ├── check-config.cmake.in ├── BuildType.cmake ├── CheckHeaderDirent.cmake ├── CheckTypeExists.cmake ├── CheckStructMember.cmake └── check_stdint.h.in ├── tests ├── cmake_project_usage_test │ ├── README │ ├── src │ │ ├── test_suite.h │ │ ├── tests.c │ │ ├── test_suite.c │ │ └── CMakeLists.txt │ └── CMakeLists.txt ├── test_vars.in ├── test_check_nofork_teardown.sh ├── test_check_nofork.sh ├── test_tap_output.sh ├── test_log_output.sh ├── test_mem_leaks.sh ├── test_set_max_msg_size.sh ├── check_check_export_main.c ├── test_xml_output.sh ├── check_check_limit.c ├── check_check_main.c ├── check_check_exit.c ├── check_stress.c ├── check_nofork.c ├── check_set_max_msg_size.c ├── check_check_log_internal.c ├── check_nofork_teardown.c ├── check_thread_stress.c ├── check_mem_leaks.c └── check_check.h ├── lib ├── Makefile.am ├── strdup.c ├── alarm.c ├── strsignal.c ├── libcompat.c ├── localtime_r.c ├── timer_create.c ├── malloc.c ├── realloc.c ├── gettimeofday.c ├── timer_delete.c ├── getline.c ├── fpclassify.c ├── pthread_mutex.c ├── timer_settime.c ├── CMakeLists.txt └── clock_gettime.c ├── .editorconfig ├── THANKS ├── check.pc.in ├── contrib ├── check_unittest.txt ├── eclipse │ ├── README │ └── check_template_eclipse_helios.xml ├── improved_make_check │ └── README └── XML_for_JUnit.xsl ├── src ├── check_print.h ├── check_msg.h ├── check_error.h ├── check_str.h ├── check_list.h ├── Makefile.am ├── check_pack.h ├── check_log.h └── check_error.c ├── .gitignore ├── Makefile.am ├── xml └── check_unittest.xslt ├── README.md └── m4 ├── ax_c_check_flag.m4 └── librt_timers.m4 /checkmk/doc/manpage.links: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /checkmk/test/empty_input/in: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /checkmk/test/empty_input/x_output: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/man/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = man3 man7 2 | -------------------------------------------------------------------------------- /checkmk/test/name_enc/cmd: -------------------------------------------------------------------------------- 1 | infname='\aa"' 2 | -------------------------------------------------------------------------------- /checkmk/test/single_test_line/in: -------------------------------------------------------------------------------- 1 | # test test_name 2 | -------------------------------------------------------------------------------- /doc/man/man7/Makefile.am: -------------------------------------------------------------------------------- 1 | dist_man_MANS = libcheck.7 2 | -------------------------------------------------------------------------------- /checkmk/examples/basic_complete.ts: -------------------------------------------------------------------------------- 1 | ../test/basic_complete/in -------------------------------------------------------------------------------- /doc/man/man3/Makefile.am: -------------------------------------------------------------------------------- 1 | dist_man_MANS = suite_create.3 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | -------------------------------------------------------------------------------- /checkmk/doc/manpage.refs: -------------------------------------------------------------------------------- 1 | { 2 | '' => '', 3 | '' => '' 4 | } 5 | -------------------------------------------------------------------------------- /checkmk/examples/multiple_everything.ts: -------------------------------------------------------------------------------- 1 | ../test/multiple_everything/in -------------------------------------------------------------------------------- /checkmk/test/empty_input/x_err: -------------------------------------------------------------------------------- 1 | checkmk: Expected at least one #test line. 2 | -------------------------------------------------------------------------------- /checkmk/test/pass_thru/x_err: -------------------------------------------------------------------------------- 1 | checkmk: Expected at least one #test line. 2 | -------------------------------------------------------------------------------- /checkmk/test/repeated_tests/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 14: Test "repeat" already exists. 2 | -------------------------------------------------------------------------------- /web/img/menu_bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libcheck/check/HEAD/web/img/menu_bg.gif -------------------------------------------------------------------------------- /web/img/side_bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libcheck/check/HEAD/web/img/side_bg.gif -------------------------------------------------------------------------------- /web/img/tab_bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libcheck/check/HEAD/web/img/tab_bg.gif -------------------------------------------------------------------------------- /checkmk/test/repeated_suites/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 10: Suite "Halibut" already exists. 2 | -------------------------------------------------------------------------------- /web/img/header_bg.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libcheck/check/HEAD/web/img/header_bg.gif -------------------------------------------------------------------------------- /checkmk/test/main_post_multiple/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 21: main-post specified multiple times. 2 | -------------------------------------------------------------------------------- /checkmk/test/main_pre_multiple/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 21: main-pre specified multiple times. 2 | -------------------------------------------------------------------------------- /checkmk/test/no_args/cmd: -------------------------------------------------------------------------------- 1 | checkmk_cmd='"$CHECKMK" < "$infname" > "$outfname" 2>"$errfname"' 2 | -------------------------------------------------------------------------------- /checkmk/test/repeated_argument_tests/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 9: Test "test2" already exists. 2 | -------------------------------------------------------------------------------- /checkmk/test/repeated_tcases/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 12: Test Case "Chopin" already exists. 2 | -------------------------------------------------------------------------------- /checkmk/test/tcase_implied_repeat/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 16: Test Case "Luck" already exists. 2 | -------------------------------------------------------------------------------- /checkmk/test/main_pre_after_post/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 21: main-pre specified after main-post. 2 | -------------------------------------------------------------------------------- /checkmk/test/clean_mode/cmd: -------------------------------------------------------------------------------- 1 | checkmk_cmd='"$CHECKMK" clean_mode=1 "$infname" > "$outfname" 2>"$errfname"' 2 | -------------------------------------------------------------------------------- /checkmk/test/test_after_main_pre/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 21: Cannot specify tests after main-pre or main-post. 2 | -------------------------------------------------------------------------------- /checkmk/test/test_chars/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 7: Malformed test name "test@me" (must be a C identifier). 2 | -------------------------------------------------------------------------------- /doc/example/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | SUBDIRS = src . tests -------------------------------------------------------------------------------- /checkmk/test/num_start_test_name/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 5: Malformed test name "1nsane" (must be a C identifier). 2 | -------------------------------------------------------------------------------- /checkmk/test/test_after_main_post/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 21: Cannot specify tests after main-pre or main-post. 2 | -------------------------------------------------------------------------------- /cmake/check-config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | include("${CMAKE_CURRENT_LIST_DIR}/@EXPORT_NAME@-targets.cmake") 3 | 4 | -------------------------------------------------------------------------------- /checkmk/test/invalid_ucn/x_err: -------------------------------------------------------------------------------- 1 | checkmk: in line 9: Malformed test name "the_\u4ECA\u65E5\u306_test" (must be a C identifier). 2 | -------------------------------------------------------------------------------- /checkmk/test/between_the_lines/in: -------------------------------------------------------------------------------- 1 | int foo; 2 | 3 | #suite A 4 | 5 | int bar; 6 | 7 | #tcase B 8 | 9 | int baz; 10 | 11 | #test C 12 | fail_unless(foo | bar | baz == 0); 13 | -------------------------------------------------------------------------------- /checkmk/test/num_start_test_name/in: -------------------------------------------------------------------------------- 1 | /* Ensure that test names starting with digits are refused. */ 2 | 3 | # suite The Suite 4 | # tcase The Test Case 5 | # test 1nsane 6 | fail_if(SANE); 7 | -------------------------------------------------------------------------------- /checkmk/test/test_chars/in: -------------------------------------------------------------------------------- 1 | /* tests shouldn't allow non-identifier characters. */ 2 | 3 | # suite The Suite 4 | 5 | # tcase The Test Case 6 | 7 | # test test@me 8 | fail_if(GOT_HERE); 9 | -------------------------------------------------------------------------------- /web/License.txt: -------------------------------------------------------------------------------- 1 | Copyright: Darren Hester 2006, http://www.designsbydarren.com 2 | License: Released Under the "Creative Commons License" 3 | http://creativecommons.org/licenses/by-nc/2.5/ 4 | -------------------------------------------------------------------------------- /checkmk/test/pass_thru/in: -------------------------------------------------------------------------------- 1 | /* 2 | * While a line such as 3 | * 4 | #define MY_VALUE 1 5 | * 6 | * will be passed; a line such as 7 | * 8 | #suite "Sweet" 9 | * 10 | * will not be. 11 | */ 12 | -------------------------------------------------------------------------------- /checkmk/test/repeated_suites/in: -------------------------------------------------------------------------------- 1 | /* Don't let suite names repeat. */ 2 | 3 | # suite Halibut 4 | 5 | # tcase Salmon 6 | 7 | # test ella 8 | fail_if(food_poisoned); 9 | 10 | # suite Halibut 11 | -------------------------------------------------------------------------------- /checkmk/test/repeated_tcases/in: -------------------------------------------------------------------------------- 1 | /* Don't let test case names repeat. */ 2 | 3 | # suite Mozart 4 | 5 | # tcase Chopin 6 | 7 | # test sticks 8 | fail_if(DEAD_COMPOSERS); 9 | 10 | # suite Rachmaninoff 11 | 12 | # tcase Chopin 13 | -------------------------------------------------------------------------------- /doc/example/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | lib_LTLIBRARIES = libmoney.la 4 | libmoney_la_SOURCES = money.c money.h 5 | 6 | bin_PROGRAMS = main 7 | main_SOURCES = main.c 8 | main_LDADD = libmoney.la 9 | -------------------------------------------------------------------------------- /tests/cmake_project_usage_test/README: -------------------------------------------------------------------------------- 1 | This project is used from :travis.sh to verify Check can be used in a CMake project in the right way. 2 | 3 | Attn. Do not use this as an example of how to use Check in your own project. Consult official documentation. 4 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | noinst_LTLIBRARIES = libcompat.la 4 | libcompat_la_LDFLAGS = -no-undefined 5 | libcompat_la_SOURCES = libcompat.c libcompat.h fpclassify.c 6 | libcompat_la_LIBADD = $(LTLIBOBJS) $(LTALLOCA) 7 | -------------------------------------------------------------------------------- /checkmk/test/test_chars/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* tests shouldn't allow non-identifier characters. */ 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /checkmk/test/invalid_ucn/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /checkmk/test/num_start_test_name/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Ensure that test names starting with digits are refused. */ 10 | 11 | -------------------------------------------------------------------------------- /checkmk/test/repeated_tests/in: -------------------------------------------------------------------------------- 1 | /* Can't use the same test name multiple times. */ 2 | 3 | # suite Foo 4 | 5 | # tcase Bar 6 | 7 | # test repeat 8 | fail_if(MISERABLY); 9 | 10 | # suite Baz 11 | 12 | # tcase Quux 13 | 14 | # test repeat 15 | fail_if(DONT_TRY_TRY_AGAIN); 16 | -------------------------------------------------------------------------------- /checkmk/test/repeated_argument_tests/in: -------------------------------------------------------------------------------- 1 | /* Fail when tests with identical name are detected */ 2 | 3 | #test-loop(1,4) test1 4 | ck_assert(1 == 1); 5 | #test-signal(-1) test2 6 | ck_assert(1 == 1); 7 | #suite secondary 8 | #tcase second 9 | #test-loop-exit(1, 1, 5) test2 10 | ck_assert(1 == 1); 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig 2 | # http://EditorConfig.org 3 | 4 | # top-most EditorConfig file 5 | root = true 6 | 7 | # LF end-of-line, insert an empty new line and UTF-8 8 | [*] 9 | end_of_line = lf 10 | insert_final_newline = true 11 | charset = utf-8 12 | 13 | [makefile,Makefile] 14 | indent_style = tab 15 | -------------------------------------------------------------------------------- /doc/example/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | TESTS = check_money 4 | check_PROGRAMS = check_money 5 | check_money_SOURCES = check_money.c $(top_builddir)/src/money.h 6 | check_money_CFLAGS = @CHECK_CFLAGS@ 7 | check_money_LDADD = $(top_builddir)/src/libmoney.la @CHECK_LIBS@ 8 | -------------------------------------------------------------------------------- /tests/cmake_project_usage_test/src/test_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef PROJECT_USAGE_TEST_TEST_SUITE_H 2 | #define PROJECT_USAGE_TEST_TEST_SUITE_H 3 | 4 | #include 5 | 6 | #define MAX_TESTS_IN_SUITE 20 7 | void add_tests(size_t const n, TTest const * tests[n]); 8 | 9 | #endif /* PROJECT_USAGE_TEST_TEST_SUITE_H */ 10 | 11 | -------------------------------------------------------------------------------- /checkmk/Makefile.am: -------------------------------------------------------------------------------- 1 | if INSTALL_CHECKMK 2 | bin_SCRIPTS = checkmk 3 | TESTS = test/check_checkmk 4 | endif 5 | EXTRA_DIST = test examples doc/checkmk.1 6 | CONFIG_STATUS_DEPENDENCIES = checkmk.in 7 | 8 | man_MANS = doc/checkmk.1 9 | 10 | clean-local: 11 | rm -rf test.out 12 | 13 | dist-hook: 14 | rm -rf `find $(distdir)/ -name '.svn'` 15 | -------------------------------------------------------------------------------- /checkmk/test/repeated_suites/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Don't let suite names repeat. */ 10 | 11 | 12 | 13 | START_TEST(ella) 14 | { 15 | #line 8 16 | fail_if(food_poisoned); 17 | 18 | -------------------------------------------------------------------------------- /checkmk/test/pass_thru/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* 10 | * While a line such as 11 | * 12 | #define MY_VALUE 1 13 | * 14 | * will be passed; a line such as 15 | * 16 | #line 9 17 | * 18 | * will not be. 19 | */ 20 | -------------------------------------------------------------------------------- /checkmk/test/repeated_tcases/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Don't let test case names repeat. */ 10 | 11 | 12 | 13 | START_TEST(sticks) 14 | { 15 | #line 8 16 | fail_if(DEAD_COMPOSERS); 17 | 18 | } 19 | END_TEST 20 | 21 | -------------------------------------------------------------------------------- /checkmk/test/repeated_tests/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Can't use the same test name multiple times. */ 10 | 11 | 12 | 13 | START_TEST(repeat) 14 | { 15 | #line 8 16 | fail_if(MISERABLY); 17 | 18 | } 19 | END_TEST 20 | 21 | 22 | -------------------------------------------------------------------------------- /checkmk/test/clean_mode/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | Design suggestions: 2 | Fred Drake (checked fixture functions) 3 | Jim O'Leary (forkless mode) 4 | 5 | Downstream maintainers: 6 | Robert Lemmen (Debian) 7 | Tom 'spot' Callaway (Fedora Extras) 8 | 9 | If you helped out with Check in some way and would like to be listed 10 | here, send a patch to . 11 | -------------------------------------------------------------------------------- /check.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: Check 7 | Description: A unit test framework for C 8 | URL: https://libcheck.github.io/check/ 9 | Version: @VERSION@ 10 | Requires.private: @LIBSUBUNIT_PC@ 11 | Libs: -L${libdir} -lcheck 12 | Libs.private: @GCOV_LIBS@ @PTHREAD_LIBS@ @LIBS@ 13 | Cflags: -I${includedir} @PTHREAD_CFLAGS@ 14 | -------------------------------------------------------------------------------- /checkmk/test/basic_complete/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | -------------------------------------------------------------------------------- /checkmk/test/ucn/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_\u4ECA\u65E5\u306F_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | -------------------------------------------------------------------------------- /checkmk/test/case_insensitive_pp/in: -------------------------------------------------------------------------------- 1 | /* Test case-insensitive directives. */ 2 | 3 | #include 4 | 5 | # SuiTe The Suite 6 | 7 | # tCaSe The Test Case 8 | 9 | # teSt the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | -------------------------------------------------------------------------------- /checkmk/test/invalid_ucn/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_\u4ECA\u65E5\u306_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | -------------------------------------------------------------------------------- /checkmk/test/non_word_chars/in: -------------------------------------------------------------------------------- 1 | /* Non-word characters */ 2 | 3 | #include 4 | 5 | # suite The Suite (of Test Cases/\TCases) 6 | 7 | # tcase The "Test Case" 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | -------------------------------------------------------------------------------- /checkmk/test/trailing_ws/in: -------------------------------------------------------------------------------- 1 | /* A complete test example (with trailing whitespace) */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | -------------------------------------------------------------------------------- /checkmk/test/declarations/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | 18 | # main-pre 19 | int declare_me = 0; 20 | -------------------------------------------------------------------------------- /checkmk/test/repeated_argument_tests/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Fail when tests with identical name are detected */ 10 | 11 | START_TEST(test1) 12 | { 13 | #line 4 14 | ck_assert(1 == 1); 15 | } 16 | END_TEST 17 | 18 | START_TEST(test2) 19 | { 20 | #line 6 21 | ck_assert(1 == 1); 22 | } 23 | END_TEST 24 | -------------------------------------------------------------------------------- /checkmk/test/main_post/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | 18 | # main-post 19 | return 0; /* Always report success. */ 20 | -------------------------------------------------------------------------------- /checkmk/test/no_args/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | 18 | #main-pre 19 | int fooyah; 20 | 21 | #main-post 22 | return nf; 23 | -------------------------------------------------------------------------------- /tests/cmake_project_usage_test/src/tests.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "test_suite.h" 5 | 6 | START_TEST (testSimple) { 7 | ck_assert(1 == 1); 8 | ck_assert(1 + 1 == 2); 9 | ck_assert(strlen("Test") == 4); 10 | } 11 | END_TEST 12 | 13 | void add_tests(size_t const n, TTest const * tests[n]) { 14 | assert(n > 0); 15 | size_t i = 0; 16 | tests[i++] = testSimple; 17 | assert(i <= n); 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/test_vars.in: -------------------------------------------------------------------------------- 1 | # defined to 1 if subunit is enabled 2 | ENABLE_SUBUNIT=@ENABLE_SUBUNIT@ 3 | export ENABLE_SUBUNIT 4 | EXEEXT=@EXEEXT@ 5 | export EXEEXT 6 | HAVE_FORK=@HAVE_FORK@ 7 | export HAVE_FORK 8 | 9 | # path of the tests directory 10 | if [ x"@srcdir@" != x"." ]; then 11 | if [ -z "@IS_MSVC@" -o "@IS_MSVC@" != "1" ]; then 12 | SRCDIR="@srcdir@/" 13 | else 14 | SRCDIR="@srcdir@\\" 15 | fi 16 | else 17 | SRCDIR="" 18 | fi 19 | 20 | export SRCDIR 21 | -------------------------------------------------------------------------------- /contrib/check_unittest.txt: -------------------------------------------------------------------------------- 1 | An XSLT stylesheet to transform Check its XML output to HTML 2 | 3 | Bart van Kuik - bkuik 4 | 2006-03-16 5 | 6 | This is an XSLT stylesheet to transform Check its XML 7 | output to HTML. It's very basic and could probably be a 8 | lot shorter. The HTML that is output isn't very 9 | standards compliant either, but it works. 10 | 11 | You can generate such a report on the commandline with a quick 12 | 13 | $ xsltproc check_unittest.xslt check_output.xml > report.html 14 | -------------------------------------------------------------------------------- /checkmk/test/test_after_main_pre/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | 18 | # main-pre 19 | int declare_me = 0; 20 | 21 | # test uh_oh 22 | fail("Phooey"); 23 | -------------------------------------------------------------------------------- /checkmk/test/main_pre_multiple/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | 18 | # main-pre 19 | int declare_me = 0; 20 | 21 | # main-pre 22 | int oh_wait_declare_me_too; 23 | -------------------------------------------------------------------------------- /checkmk/test/tcase_implied_repeat/in: -------------------------------------------------------------------------------- 1 | /* Make sure we catch implied tcase repeats (via same name as suite) */ 2 | 3 | # suite Lady 4 | 5 | # tcase Luck 6 | 7 | # test song 8 | fail_unless("be a lady tonight"); 9 | 10 | # suite Luck 11 | 12 | /* It's fine for a suite and tcase name to collide... 13 | but the suite name implies a tcase name of the same value until we 14 | override it. */ 15 | 16 | # test uh_oh 17 | /* Uh-oh! Now we're using the implied tcase Luck, which already 18 | * exists! */ 19 | -------------------------------------------------------------------------------- /checkmk/test/main_pre_after_post/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | 18 | # main-post 19 | return 0; /* Always report success. */ 20 | 21 | # main-pre 22 | int declare_me = 0; 23 | -------------------------------------------------------------------------------- /checkmk/test/not_really_repeated/in: -------------------------------------------------------------------------------- 1 | /* Test that repeated suites/tcases are only disallowed when they've 2 | * actually been used in defining a test. */ 3 | 4 | # suite Foo 5 | 6 | # tcase Bar 7 | 8 | /* But no test... */ 9 | 10 | # suite Baz 11 | 12 | # tcase Quux 13 | 14 | # test quuux 15 | const char msg[] = "Howdy doody!\n"; 16 | int nc = printf(msg); 17 | 18 | fail_unless(nc == sizeof msg - 1); 19 | 20 | # suite Foo 21 | 22 | # tcase Bar 23 | 24 | # test huh 25 | fail_unless(ALLOWED_AFTER_ALL); 26 | -------------------------------------------------------------------------------- /checkmk/test/test_after_main_post/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | 18 | # main-post 19 | return 0; /* Always report success. */ 20 | 21 | # test uh_oh 22 | fail("Phooey"); 23 | -------------------------------------------------------------------------------- /doc/example/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIB_SOURCES 2 | money.c 3 | ) 4 | 5 | set(MAIN_SOURCES 6 | main.c 7 | ) 8 | 9 | set(HEADERS 10 | ${CONFIG_HEADER} 11 | money.h 12 | ) 13 | 14 | add_library(money STATIC ${LIB_SOURCES} ${HEADERS}) 15 | 16 | add_executable(main ${HEADERS} ${MAIN_SOURCES}) 17 | target_link_libraries(main money) 18 | 19 | install(TARGETS money 20 | RUNTIME DESTINATION bin 21 | LIBRARY DESTINATION lib 22 | ARCHIVE DESTINATION lib) 23 | 24 | install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/money.h DESTINATION include) 25 | -------------------------------------------------------------------------------- /tests/test_check_nofork_teardown.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | . ./test_vars 4 | 5 | expected="Running suite(s): bug-99 6 | 0%: Checks: 1, Failures: 1, Errors: 0 7 | ${SRCDIR}check_nofork_teardown.c:56:F:tc:will_fail:0: Assertion '0' failed" 8 | 9 | actual=`./check_nofork_teardown${EXEEXT} | tr -d "\r"` 10 | if [ x"${expected}" = x"${actual}" ]; then 11 | exit 0 12 | else 13 | echo "Problem with check_nofork_teardown${EXEEXT}" 14 | echo "Expected: " 15 | echo "${expected}" 16 | echo "Got: " 17 | echo "${actual}" 18 | exit 1 19 | fi 20 | -------------------------------------------------------------------------------- /checkmk/test/main_post_multiple/in: -------------------------------------------------------------------------------- 1 | /* A complete test example */ 2 | 3 | #include 4 | 5 | # suite The Suite 6 | 7 | # tcase The Test Case 8 | 9 | # test the_test 10 | int nc; 11 | const char msg[] = "\n\n Hello, world!\n"; 12 | 13 | nc = printf("%s", msg); 14 | fail_unless(nc == (sizeof msg 15 | - 1) /* for terminating NUL. */ 16 | ); 17 | 18 | # main-post 19 | return 0; /* Always report success. */ 20 | 21 | # main-post 22 | return 0; /* We really want success, so we'll specify it twice! */ 23 | -------------------------------------------------------------------------------- /checkmk/test/tcase_implied_repeat/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Make sure we catch implied tcase repeats (via same name as suite) */ 10 | 11 | 12 | 13 | START_TEST(song) 14 | { 15 | #line 8 16 | fail_unless("be a lady tonight"); 17 | 18 | } 19 | END_TEST 20 | 21 | #line 12 22 | /* It's fine for a suite and tcase name to collide... 23 | but the suite name implies a tcase name of the same value until we 24 | override it. */ 25 | 26 | -------------------------------------------------------------------------------- /checkmk/README: -------------------------------------------------------------------------------- 1 | ======= 2 | checkmk 3 | ======= 4 | 5 | Written by Micah J Cowan. 6 | 7 | Translates concise versions of test suites into C programs 8 | suitable suitable for use with the Check unit test framework. 9 | 10 | See the source code in checkmk.in (checkmk when installed) for terms of 11 | distribution (scaled-down version of the modified BSD license). 12 | 13 | To see how it works, try running checkmk on the example files, 14 | basic_complete.ts and multiple_everything.ts: 15 | checkmk basic_complete.ts > basic_complete.c 16 | cc -o basic basic_complete.c -lcheck 17 | ./basic 18 | -------------------------------------------------------------------------------- /tests/cmake_project_usage_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.11 FATAL_ERROR) 2 | if(POLICY CMP0074) 3 | cmake_policy(SET CMP0074 NEW) # Use _ROOT variables 4 | endif() 5 | if(POLICY CMP0090) 6 | cmake_policy(SET CMP0090 NEW) 7 | # export(PACKAGE) does not populate package registry by default. 8 | endif() 9 | 10 | project( ProjectUsageTest 11 | VERSION "0.0.0.0" 12 | DESCRIPTION "Include Check project in this project in different ways" 13 | LANGUAGES C) 14 | 15 | set(CMAKE_C_STANDARD 99) 16 | set(CMAKE_C_STANDARD_REQUIRED ON) 17 | set(CMAKE_C_EXTENSIONS OFF) 18 | 19 | add_subdirectory(src) 20 | 21 | -------------------------------------------------------------------------------- /cmake/BuildType.cmake: -------------------------------------------------------------------------------- 1 | # Set a default build type if none was specified 2 | set(default_build_type "Release") 3 | if(EXISTS "${CMAKE_SOURCE_DIR}/.git") 4 | set(default_build_type "Debug") 5 | endif() 6 | 7 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 8 | message(STATUS "Setting build type to '${default_build_type}' as none was specified.") 9 | set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE 10 | STRING "Choose the type of build." FORCE) 11 | # Set the possible values of build type for cmake-gui 12 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 13 | "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 14 | endif() 15 | 16 | -------------------------------------------------------------------------------- /doc/example/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src) 2 | 3 | # If pkg-config is not installed on the system, then the 4 | # CHECK_INSTALL_DIR variable must be set to the install 5 | # location of Check. For example, on Windows, this may 6 | # be: C:/Program Files/check 7 | # set(CHECK_INSTALL_DIR "C:/Program Files/check") 8 | 9 | find_package(Check REQUIRED) 10 | include_directories(${CHECK_INCLUDE_DIRS}) 11 | link_directories(${CHECK_LIBRARY_DIRS}) 12 | 13 | set(TEST_SOURCES 14 | check_money.c 15 | ) 16 | 17 | add_executable(check_money ${TEST_SOURCES}) 18 | target_link_libraries(check_money money ${CHECK_LIBRARIES}) 19 | -------------------------------------------------------------------------------- /tests/test_check_nofork.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | . ./test_vars 4 | 5 | if [ $HAVE_FORK -eq 1 ]; then 6 | expected="Running suite(s): NoFork 7 | 0%: Checks: 1, Failures: 1, Errors: 0" 8 | else 9 | expected="Running suite(s): NoFork 10 | 0%: Checks: 1, Failures: 1, Errors: 0 11 | Running suite(s): NoForkSupport 12 | 100%: Checks: 1, Failures: 0, Errors: 0" 13 | fi 14 | 15 | actual=`./check_nofork${EXEEXT} | tr -d "\r"` 16 | if [ x"${expected}" = x"${actual}" ]; then 17 | exit 0 18 | else 19 | echo "Problem with check_nofork${EXEEXT}" 20 | echo "Expected: " 21 | echo "${expected}" 22 | echo "Got: " 23 | echo "${actual}" 24 | exit 1 25 | fi 26 | -------------------------------------------------------------------------------- /checkmk/test/single_test_line/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | START_TEST(test_name) 10 | { 11 | #line 2 12 | } 13 | END_TEST 14 | 15 | int main(void) 16 | { 17 | Suite *s1 = suite_create("Core"); 18 | TCase *tc1_1 = tcase_create("Core"); 19 | SRunner *sr = srunner_create(s1); 20 | int nf; 21 | 22 | suite_add_tcase(s1, tc1_1); 23 | tcase_add_test(tc1_1, test_name); 24 | 25 | srunner_run_all(sr, CK_ENV); 26 | nf = srunner_ntests_failed(sr); 27 | srunner_free(sr); 28 | 29 | return nf == 0 ? 0 : 1; 30 | } 31 | -------------------------------------------------------------------------------- /contrib/eclipse/README: -------------------------------------------------------------------------------- 1 | Eclipse template for creating unit tests with check framework 2 | 3 | The template has been tested with Eclipse Helios CDT. Note that check 4 | framework should be installed first and the check library should be 5 | found in system path. 6 | 7 | Installation: 8 | 9 | From the "New Source File" dialog, press "Configure...", then 10 | "Import..." and select the template XML file 11 | (e.g. check_template_eclipse_helios.xml). The template should appear 12 | under "C Source File" tree as "C source template with check unit 13 | testing" in "Preferences" dialog. 14 | 15 | The newly installed template should be available when creating a "New 16 | Source File" in "Template" combo box. 17 | -------------------------------------------------------------------------------- /doc/example/cmake/config.h.in: -------------------------------------------------------------------------------- 1 | /*-*- mode:C; -*- */ 2 | /* config.h. Generated from build/cmake/config.h.in by cmake configure */ 3 | 4 | /* 5 | * Ensure we have C99-style int64_t, etc, all defined. 6 | */ 7 | 8 | /* First, we need to know if the system has already defined them. */ 9 | #cmakedefine HAVE_INTMAX_T 10 | #cmakedefine HAVE_UINTMAX_T 11 | 12 | /* Define to `int' if doesn't define. */ 13 | #cmakedefine pid_t ${pid_t} 14 | 15 | /* Define intmax_t and uintmax_t if they are not already defined. */ 16 | #if !defined(HAVE_INTMAX_T) 17 | typedef int64_t intmax_t; 18 | #define INTMAX_MIN INT64_MIN 19 | #define INTMAX_MAX INT64_MAX 20 | #endif 21 | 22 | #if !defined(HAVE_UINTMAX_T) 23 | typedef uint64_t uintmax_t; 24 | #endif 25 | -------------------------------------------------------------------------------- /tests/test_tap_output.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | OUTPUT_FILE=test.tap 4 | 5 | . ./test_vars 6 | . $(dirname $0)/test_output_strings 7 | 8 | test_tap_output ( ) { 9 | rm -f ${OUTPUT_FILE} 10 | ./ex_output${EXEEXT} "CK_SILENT" "TAP" "${1}" > /dev/null 11 | actual_tap=`cat ${OUTPUT_FILE} | tr -d "\r"` 12 | expected_tap="${2}" 13 | if [ x"${expected_tap}" != x"${actual_tap}" ]; then 14 | echo "Problem with ex_tap_output${EXEEXT}"; 15 | echo "Expected:"; 16 | echo "${expected_tap}"; 17 | echo 18 | echo "Got:"; 19 | echo "${actual_tap}"; 20 | exit 1; 21 | fi 22 | } 23 | 24 | test_tap_output "NORMAL" "${expected_normal_tap}" 25 | test_tap_output "EXIT_TEST" "${expected_aborted_tap}" 26 | 27 | exit 0 28 | -------------------------------------------------------------------------------- /checkmk/test/between_the_lines/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | int foo; 10 | 11 | 12 | #line 5 13 | int bar; 14 | 15 | 16 | #line 9 17 | int baz; 18 | 19 | START_TEST(C) 20 | { 21 | #line 12 22 | fail_unless(foo | bar | baz == 0); 23 | } 24 | END_TEST 25 | 26 | int main(void) 27 | { 28 | Suite *s1 = suite_create("A"); 29 | TCase *tc1_1 = tcase_create("B"); 30 | SRunner *sr = srunner_create(s1); 31 | int nf; 32 | 33 | suite_add_tcase(s1, tc1_1); 34 | tcase_add_test(tc1_1, C); 35 | 36 | srunner_run_all(sr, CK_ENV); 37 | nf = srunner_ntests_failed(sr); 38 | srunner_free(sr); 39 | 40 | return nf == 0 ? 0 : 1; 41 | } 42 | -------------------------------------------------------------------------------- /tests/test_log_output.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | OUTPUT_FILE=test.log 4 | 5 | . ./test_vars 6 | . $(dirname $0)/test_output_strings 7 | 8 | test_log_output ( ) { 9 | rm -f ${OUTPUT_FILE} 10 | ./ex_output${EXEEXT} "${1}" "LOG" "NORMAL" > /dev/null 11 | actual=`cat ${OUTPUT_FILE} | tr -d "\r"` 12 | expected=${2} 13 | if [ x"${expected}" != x"${actual}" ]; then 14 | echo "Problem with ex_log_output${EXEEXT} ${1} LOG NORMAL"; 15 | echo "Expected:"; 16 | echo "${expected}"; 17 | echo "Got:"; 18 | echo "${actual}"; 19 | exit 1; 20 | fi 21 | 22 | } 23 | 24 | test_log_output "CK_SILENT" "${expected_log_log}" 25 | test_log_output "CK_MINIMAL" "${expected_log_log}" 26 | test_log_output "CK_NORMAL" "${expected_log_log}" 27 | test_log_output "CK_VERBOSE" "${expected_log_log}" 28 | exit 0 29 | -------------------------------------------------------------------------------- /checkmk/test/main_pre_multiple/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | 26 | } 27 | END_TEST 28 | 29 | int main(void) 30 | { 31 | Suite *s1 = suite_create("The Suite"); 32 | TCase *tc1_1 = tcase_create("The Test Case"); 33 | SRunner *sr = srunner_create(s1); 34 | int nf; 35 | 36 | /* User-specified pre-run code */ 37 | #line 19 38 | int declare_me = 0; 39 | 40 | -------------------------------------------------------------------------------- /checkmk/test/test_after_main_pre/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | 26 | } 27 | END_TEST 28 | 29 | int main(void) 30 | { 31 | Suite *s1 = suite_create("The Suite"); 32 | TCase *tc1_1 = tcase_create("The Test Case"); 33 | SRunner *sr = srunner_create(s1); 34 | int nf; 35 | 36 | /* User-specified pre-run code */ 37 | #line 19 38 | int declare_me = 0; 39 | 40 | -------------------------------------------------------------------------------- /doc/example/src/money.1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Check: a unit test framework for C 3 | # Copyright (C) 2020 Jose Fernando Lopez Fernandez 4 | # 5 | # This library is free software; you can redistribute 6 | # it and/or modify it under the terms of the GNU Lesser 7 | # General Public License as published by the Free Software 8 | # Foundation; either version 2.1 of the License, or (at 9 | # your option) any later version. 10 | # 11 | # This library is distributed in the hope that it will 12 | # be useful, but WITHOUT ANY WARRANTY; without even the 13 | # implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | # PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | # License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General 18 | # Public License along with this library; if not, write 19 | # to the Free Software Foundation, Inc., 51 Franklin St, 20 | # Fifth Floor, Boston, MA 02110-1301 USA 21 | # 22 | 23 | ADD_SUBDIRECTORY(man) 24 | -------------------------------------------------------------------------------- /checkmk/test/clean_mode/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | /* A complete test example */ 9 | 10 | #include 11 | 12 | 13 | 14 | START_TEST(the_test) 15 | { 16 | int nc; 17 | const char msg[] = "\n\n Hello, world!\n"; 18 | 19 | nc = printf("%s", msg); 20 | fail_unless(nc == (sizeof msg 21 | - 1) /* for terminating NUL. */ 22 | ); 23 | } 24 | END_TEST 25 | 26 | int main(void) 27 | { 28 | Suite *s1 = suite_create("The Suite"); 29 | TCase *tc1_1 = tcase_create("The Test Case"); 30 | SRunner *sr = srunner_create(s1); 31 | int nf; 32 | 33 | suite_add_tcase(s1, tc1_1); 34 | tcase_add_test(tc1_1, the_test); 35 | 36 | srunner_run_all(sr, CK_ENV); 37 | nf = srunner_ntests_failed(sr); 38 | srunner_free(sr); 39 | 40 | return nf == 0 ? 0 : 1; 41 | } 42 | -------------------------------------------------------------------------------- /doc/example/tests/check_money.1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | int main(void) 22 | { 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /doc/example/src/money.1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef MONEY_H 22 | #define MONEY_H 23 | 24 | #endif /* MONEY_H */ 25 | -------------------------------------------------------------------------------- /checkmk/test/basic_complete/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | } 26 | END_TEST 27 | 28 | int main(void) 29 | { 30 | Suite *s1 = suite_create("The Suite"); 31 | TCase *tc1_1 = tcase_create("The Test Case"); 32 | SRunner *sr = srunner_create(s1); 33 | int nf; 34 | 35 | suite_add_tcase(s1, tc1_1); 36 | tcase_add_test(tc1_1, the_test); 37 | 38 | srunner_run_all(sr, CK_ENV); 39 | nf = srunner_ntests_failed(sr); 40 | srunner_free(sr); 41 | 42 | return nf == 0 ? 0 : 1; 43 | } 44 | -------------------------------------------------------------------------------- /checkmk/test/name_enc/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "\aa"" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "\\aa\"" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | } 26 | END_TEST 27 | 28 | int main(void) 29 | { 30 | Suite *s1 = suite_create("The Suite"); 31 | TCase *tc1_1 = tcase_create("The Test Case"); 32 | SRunner *sr = srunner_create(s1); 33 | int nf; 34 | 35 | suite_add_tcase(s1, tc1_1); 36 | tcase_add_test(tc1_1, the_test); 37 | 38 | srunner_run_all(sr, CK_ENV); 39 | nf = srunner_ntests_failed(sr); 40 | srunner_free(sr); 41 | 42 | return nf == 0 ? 0 : 1; 43 | } 44 | -------------------------------------------------------------------------------- /checkmk/test/case_insensitive_pp/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Test case-insensitive directives. */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | } 26 | END_TEST 27 | 28 | int main(void) 29 | { 30 | Suite *s1 = suite_create("The Suite"); 31 | TCase *tc1_1 = tcase_create("The Test Case"); 32 | SRunner *sr = srunner_create(s1); 33 | int nf; 34 | 35 | suite_add_tcase(s1, tc1_1); 36 | tcase_add_test(tc1_1, the_test); 37 | 38 | srunner_run_all(sr, CK_ENV); 39 | nf = srunner_ntests_failed(sr); 40 | srunner_free(sr); 41 | 42 | return nf == 0 ? 0 : 1; 43 | } 44 | -------------------------------------------------------------------------------- /checkmk/test/non_word_chars/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Non-word characters */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | } 26 | END_TEST 27 | 28 | int main(void) 29 | { 30 | Suite *s1 = suite_create("The Suite (of Test Cases/\\TCases)"); 31 | TCase *tc1_1 = tcase_create("The \"Test Case\""); 32 | SRunner *sr = srunner_create(s1); 33 | int nf; 34 | 35 | suite_add_tcase(s1, tc1_1); 36 | tcase_add_test(tc1_1, the_test); 37 | 38 | srunner_run_all(sr, CK_ENV); 39 | nf = srunner_ntests_failed(sr); 40 | srunner_free(sr); 41 | 42 | return nf == 0 ? 0 : 1; 43 | } 44 | -------------------------------------------------------------------------------- /checkmk/test/trailing_ws/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example (with trailing whitespace) */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | } 26 | END_TEST 27 | 28 | int main(void) 29 | { 30 | Suite *s1 = suite_create("The Suite"); 31 | TCase *tc1_1 = tcase_create("The Test Case"); 32 | SRunner *sr = srunner_create(s1); 33 | int nf; 34 | 35 | suite_add_tcase(s1, tc1_1); 36 | tcase_add_test(tc1_1, the_test); 37 | 38 | srunner_run_all(sr, CK_ENV); 39 | nf = srunner_ntests_failed(sr); 40 | srunner_free(sr); 41 | 42 | return nf == 0 ? 0 : 1; 43 | } 44 | -------------------------------------------------------------------------------- /checkmk/test/ucn/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_\u4ECA\u65E5\u306F_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | } 26 | END_TEST 27 | 28 | int main(void) 29 | { 30 | Suite *s1 = suite_create("The Suite"); 31 | TCase *tc1_1 = tcase_create("The Test Case"); 32 | SRunner *sr = srunner_create(s1); 33 | int nf; 34 | 35 | suite_add_tcase(s1, tc1_1); 36 | tcase_add_test(tc1_1, the_\u4ECA\u65E5\u306F_test); 37 | 38 | srunner_run_all(sr, CK_ENV); 39 | nf = srunner_ntests_failed(sr); 40 | srunner_free(sr); 41 | 42 | return nf == 0 ? 0 : 1; 43 | } 44 | -------------------------------------------------------------------------------- /lib/strdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | char *strdup(const char *str CK_ATTRIBUTE_UNUSED) 24 | { 25 | assert(0); 26 | return NULL; 27 | } 28 | -------------------------------------------------------------------------------- /doc/example/configure.ac: -------------------------------------------------------------------------------- 1 | # Process this file with autoconf to produce a configure script. 2 | 3 | # Prelude. 4 | AC_PREREQ([2.59]) 5 | AC_INIT([Money], [0.3], [check-devel AT lists.sourceforge.net]) 6 | AM_PROG_AR 7 | 8 | # unique source file --- primitive safety check 9 | AC_CONFIG_SRCDIR([src/money.c]) 10 | 11 | # fairly severe build strictness 12 | # change foreign to gnu or gnits to comply with gnu standards 13 | AM_INIT_AUTOMAKE([-Wall -Werror foreign 1.11.2]) 14 | 15 | # Checks for programs. 16 | AC_PROG_CC 17 | AC_PROG_LIBTOOL 18 | 19 | # Checks for libraries. 20 | 21 | PKG_CHECK_MODULES([CHECK], [check >= 0.9.6]) 22 | AM_PROG_CC_C_O 23 | 24 | # Checks for header files. 25 | AC_HEADER_STDC 26 | AC_CHECK_HEADERS([stdlib.h]) 27 | 28 | # Checks for typedefs, structures, and compiler characteristics. 29 | 30 | # Checks for library functions. 31 | AC_FUNC_MALLOC 32 | 33 | # Output files 34 | AC_CONFIG_HEADERS([config.h]) 35 | 36 | AC_CONFIG_FILES([Makefile 37 | src/Makefile 38 | tests/Makefile]) 39 | 40 | AC_OUTPUT 41 | -------------------------------------------------------------------------------- /lib/alarm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | unsigned int alarm(unsigned int seconds CK_ATTRIBUTE_UNUSED) 24 | { 25 | assert(0); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /tests/cmake_project_usage_test/src/test_suite.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "test_suite.h" 4 | 5 | static Suite * test_suite(void) { 6 | Suite *s; 7 | TCase *tc_core; 8 | TTest const * tests[MAX_TESTS_IN_SUITE] = { 0 }; 9 | add_tests(MAX_TESTS_IN_SUITE, tests); 10 | 11 | s = suite_create("ProjectUsageTest"); 12 | 13 | /* Core test case */ 14 | tc_core = tcase_create("Core"); 15 | 16 | for(size_t i = 0; i < MAX_TESTS_IN_SUITE; ++i) { 17 | TTest const * test = tests[i]; 18 | if(test) { 19 | tcase_add_test(tc_core, test); 20 | } 21 | } 22 | suite_add_tcase(s, tc_core); 23 | 24 | return s; 25 | } 26 | 27 | int main(void) { 28 | int number_failed; 29 | Suite *s; 30 | SRunner *sr; 31 | 32 | s = test_suite(); 33 | sr = srunner_create(s); 34 | 35 | srunner_run_all(sr, CK_NORMAL); 36 | number_failed = srunner_ntests_failed(sr); 37 | srunner_free(sr); 38 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /checkmk/test/main_post/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | 26 | } 27 | END_TEST 28 | 29 | int main(void) 30 | { 31 | Suite *s1 = suite_create("The Suite"); 32 | TCase *tc1_1 = tcase_create("The Test Case"); 33 | SRunner *sr = srunner_create(s1); 34 | int nf; 35 | 36 | suite_add_tcase(s1, tc1_1); 37 | tcase_add_test(tc1_1, the_test); 38 | 39 | srunner_run_all(sr, CK_ENV); 40 | nf = srunner_ntests_failed(sr); 41 | srunner_free(sr); 42 | 43 | /* User-specified post-run code */ 44 | #line 19 45 | return 0; /* Always report success. */ 46 | } 47 | -------------------------------------------------------------------------------- /checkmk/test/main_post_multiple/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | 26 | } 27 | END_TEST 28 | 29 | int main(void) 30 | { 31 | Suite *s1 = suite_create("The Suite"); 32 | TCase *tc1_1 = tcase_create("The Test Case"); 33 | SRunner *sr = srunner_create(s1); 34 | int nf; 35 | 36 | suite_add_tcase(s1, tc1_1); 37 | tcase_add_test(tc1_1, the_test); 38 | 39 | srunner_run_all(sr, CK_ENV); 40 | nf = srunner_ntests_failed(sr); 41 | srunner_free(sr); 42 | 43 | /* User-specified post-run code */ 44 | #line 19 45 | return 0; /* Always report success. */ 46 | 47 | -------------------------------------------------------------------------------- /tests/test_mem_leaks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | SCRIPT_PATH="$(dirname "$(readlink -f "$0")")" 4 | if test -z "${1}"; then 5 | UNIT_TEST="${SCRIPT_PATH}/check_mem_leaks" 6 | else 7 | UNIT_TEST="${1}" 8 | fi 9 | VALGRIND_LOG_FILE=${UNIT_TEST}.valgrind 10 | LEAK_MESSAGE="are definitely lost" 11 | 12 | # This test runs valgrind against the check_mem_leaks unit test 13 | # program, looking for memory leaks. If any are found, "exit 1" 14 | # is invoked, and one must look through the resulting valgrind log 15 | # file for details on the leak. 16 | 17 | rm -f ${VALGRIND_LOG_FILE} 18 | libtool --mode=execute valgrind --leak-check=full ${UNIT_TEST} 2>&1 | tee ${VALGRIND_LOG_FILE} 19 | 20 | NUM_LEAKS=$(grep "${LEAK_MESSAGE}" ${VALGRIND_LOG_FILE} | wc -l) 21 | 22 | if test ${NUM_LEAKS} -gt 0; then 23 | echo "ERROR: ${NUM_LEAKS} memory leaks were detected by valgrind." 24 | echo " Look through ${VALGRIND_LOG_FILE} for details," 25 | echo " searching for \"${LEAK_MESSAGE}\"." 26 | exit 1 27 | else 28 | echo "No memory leaks found" 29 | exit 0 30 | fi 31 | -------------------------------------------------------------------------------- /checkmk/test/main_pre_after_post/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | 26 | } 27 | END_TEST 28 | 29 | int main(void) 30 | { 31 | Suite *s1 = suite_create("The Suite"); 32 | TCase *tc1_1 = tcase_create("The Test Case"); 33 | SRunner *sr = srunner_create(s1); 34 | int nf; 35 | 36 | suite_add_tcase(s1, tc1_1); 37 | tcase_add_test(tc1_1, the_test); 38 | 39 | srunner_run_all(sr, CK_ENV); 40 | nf = srunner_ntests_failed(sr); 41 | srunner_free(sr); 42 | 43 | /* User-specified post-run code */ 44 | #line 19 45 | return 0; /* Always report success. */ 46 | 47 | -------------------------------------------------------------------------------- /checkmk/test/no_args/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file (standard input) instead. 4 | */ 5 | 6 | #include 7 | 8 | /* A complete test example */ 9 | 10 | #include 11 | 12 | 13 | 14 | START_TEST(the_test) 15 | { 16 | int nc; 17 | const char msg[] = "\n\n Hello, world!\n"; 18 | 19 | nc = printf("%s", msg); 20 | fail_unless(nc == (sizeof msg 21 | - 1) /* for terminating NUL. */ 22 | ); 23 | 24 | } 25 | END_TEST 26 | 27 | int main(void) 28 | { 29 | Suite *s1 = suite_create("The Suite"); 30 | TCase *tc1_1 = tcase_create("The Test Case"); 31 | SRunner *sr = srunner_create(s1); 32 | int nf; 33 | 34 | /* User-specified pre-run code */ 35 | int fooyah; 36 | 37 | 38 | suite_add_tcase(s1, tc1_1); 39 | tcase_add_test(tc1_1, the_test); 40 | 41 | srunner_run_all(sr, CK_ENV); 42 | nf = srunner_ntests_failed(sr); 43 | srunner_free(sr); 44 | 45 | /* User-specified post-run code */ 46 | return nf; 47 | } 48 | -------------------------------------------------------------------------------- /checkmk/test/test_after_main_post/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | 26 | } 27 | END_TEST 28 | 29 | int main(void) 30 | { 31 | Suite *s1 = suite_create("The Suite"); 32 | TCase *tc1_1 = tcase_create("The Test Case"); 33 | SRunner *sr = srunner_create(s1); 34 | int nf; 35 | 36 | suite_add_tcase(s1, tc1_1); 37 | tcase_add_test(tc1_1, the_test); 38 | 39 | srunner_run_all(sr, CK_ENV); 40 | nf = srunner_ntests_failed(sr); 41 | srunner_free(sr); 42 | 43 | /* User-specified post-run code */ 44 | #line 19 45 | return 0; /* Always report success. */ 46 | 47 | -------------------------------------------------------------------------------- /checkmk/test/declarations/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* A complete test example */ 10 | 11 | #include 12 | 13 | 14 | 15 | START_TEST(the_test) 16 | { 17 | #line 10 18 | int nc; 19 | const char msg[] = "\n\n Hello, world!\n"; 20 | 21 | nc = printf("%s", msg); 22 | fail_unless(nc == (sizeof msg 23 | - 1) /* for terminating NUL. */ 24 | ); 25 | 26 | } 27 | END_TEST 28 | 29 | int main(void) 30 | { 31 | Suite *s1 = suite_create("The Suite"); 32 | TCase *tc1_1 = tcase_create("The Test Case"); 33 | SRunner *sr = srunner_create(s1); 34 | int nf; 35 | 36 | /* User-specified pre-run code */ 37 | #line 19 38 | int declare_me = 0; 39 | 40 | suite_add_tcase(s1, tc1_1); 41 | tcase_add_test(tc1_1, the_test); 42 | 43 | srunner_run_all(sr, CK_ENV); 44 | nf = srunner_ntests_failed(sr); 45 | srunner_free(sr); 46 | 47 | return nf == 0 ? 0 : 1; 48 | } 49 | -------------------------------------------------------------------------------- /lib/strsignal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | char *strsignal(int sig) 24 | { 25 | static char signame[40]; 26 | 27 | sprintf(signame, "SIG #%d", sig); 28 | return signame; 29 | } 30 | -------------------------------------------------------------------------------- /doc/man/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Check: a unit test framework for C 3 | # Copyright (C) 2020 Jose Fernando Lopez Fernandez 4 | # 5 | # This library is free software; you can redistribute 6 | # it and/or modify it under the terms of the GNU Lesser 7 | # General Public License as published by the Free Software 8 | # Foundation; either version 2.1 of the License, or (at 9 | # your option) any later version. 10 | # 11 | # This library is distributed in the hope that it will 12 | # be useful, but WITHOUT ANY WARRANTY; without even the 13 | # implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | # PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | # License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General 18 | # Public License along with this library; if not, write 19 | # to the Free Software Foundation, Inc., 51 Franklin St, 20 | # Fifth Floor, Boston, MA 02110-1301 USA 21 | # 22 | 23 | # Process each of the following man page directories once we 24 | # have successfully configured the necessary variable(s) 25 | # defined above. 26 | # 27 | ADD_SUBDIRECTORY(man3) 28 | ADD_SUBDIRECTORY(man7) 29 | -------------------------------------------------------------------------------- /checkmk/test/multiple_everything/in: -------------------------------------------------------------------------------- 1 | /* Multiple everything... */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void print_message(const char *msg, size_t msgsz) 8 | { 9 | int nc; 10 | 11 | nc = printf("%s", msg); 12 | fail_unless(nc == msgsz, "failed to print completely: %s", 13 | strerror(errno)); 14 | } 15 | 16 | # suite A Suite 17 | 18 | # tcase A Test Case 19 | 20 | # test hello_world 21 | const char msg[] = "Hello, world!\n"; 22 | print_message(msg, sizeof msg - 1); 23 | 24 | # test neverending_story 25 | const char msg[] = "Bastian Balthazar Bux\n"; 26 | print_message(msg, sizeof msg - 1); 27 | 28 | # tcase Another Test Case 29 | 30 | # test math_problem 31 | fail_unless(1 + 1 == 2, "Something's broken..."); 32 | 33 | # suite Another Suite 34 | 35 | # tcase A Test Case for Another Suite 36 | 37 | # test more_math 38 | fail_unless(2/2 == 1, "Another weird math result"); 39 | 40 | # tcase A Basket Case 41 | 42 | # test weave 43 | int i; 44 | const char msg[] = "###\n"; 45 | 46 | for (i=0; i != 3; ++i) 47 | print_message(row, sizeof row - 1); 48 | -------------------------------------------------------------------------------- /contrib/eclipse/check_template_eclipse_helios.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/example/src/money.2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef MONEY_H 22 | #define MONEY_H 23 | 24 | typedef struct Money Money; 25 | 26 | Money *money_create(int amount, char *currency); 27 | int money_amount(Money * m); 28 | char *money_currency(Money * m); 29 | void money_free(Money * m); 30 | 31 | #endif /* MONEY_H */ 32 | -------------------------------------------------------------------------------- /doc/example/src/money.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef MONEY_H 22 | #define MONEY_H 23 | 24 | typedef struct Money Money; 25 | 26 | Money *money_create(int amount, char *currency); 27 | int money_amount(Money * m); 28 | char *money_currency(Money * m); 29 | void money_free(Money * m); 30 | 31 | #endif /* MONEY_H */ 32 | -------------------------------------------------------------------------------- /doc/example/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "money.h" 22 | 23 | /* only main should be in this file, to make all other functions in 24 | the prograble testable by Check. in order to test main(), use a 25 | whole program testing framework like Autotest. 26 | */ 27 | 28 | int main(void) 29 | { 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /doc/man/man7/libcheck.7.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) LibCheck, 2001-2020. 2 | .\" 3 | .\" Permission is granted to copy, distribute and/or 4 | .\" modify this document under the terms of the GNU 5 | .\" Free Documentation License, Version 1.3 or any later 6 | .\" version published by the Free Software Foundation; with 7 | .\" no Invariant Sections, no Front-Cover Texts, and no 8 | .\" Back-Cover Texts. A copy of the license is included in 9 | .\" the section entitled "GNU Free Documentation License". 10 | .\" 11 | .TH "libcheck" "7" "" "@PROJECT_VERSION@" "LibCheck" 12 | .SH "PROLOG" 13 | This manual page is part of the Check Programmer's Manual. 14 | Additional information may be found at the Check Library 15 | home page, at https://libcheck.github.io/check/. 16 | .SH "NAME" 17 | libcheck 18 | \(em unit testing framework for C 19 | .SH "DESCRIPTION" 20 | Check is a unit testing framework for C. It features a 21 | simple interface for defining unit tests, putting little in 22 | the way of the developer. Tests are run in a separate 23 | address space, so Check can catch both assertion failures 24 | and code errors that cause segmentation faults or other 25 | signals. The output from unit tests can be used within 26 | source code editors and IDEs. 27 | -------------------------------------------------------------------------------- /contrib/improved_make_check/README: -------------------------------------------------------------------------------- 1 | The `check.mk' file in this directory will improve the behaviour of 2 | `make check' when using Automake. If you create one test program for 3 | each module you are testing in your program, then this will do this 4 | following: 5 | 6 | 1) Allow tests to be compiled and run in parallel 7 | 2) Only recompile and rerun test programs when the sources change 8 | 3) Produce a .log file with the output from each test 9 | 4) Only display the contents of .log files for failed tests 10 | 5) Print either a red or green status message at the end according to 11 | whether some tests failed or all tests passed 12 | 13 | Modifications to your project should be minimal. A working example 14 | can be found in libspmt, here: 15 | 16 | https://svn.sable.mcgill.ca/sable/spmt/libspmt/tests/ 17 | 18 | First, copy check.mk to trunk/build-aux/check.mk 19 | 20 | Second, add the following lines to tests/Makefile.am after `TESTS' and 21 | `check_PROGRAMS' are defined: 22 | 23 | ----- 24 | # quiet errors re: check.mk not knowing how to create .log 25 | .log: 26 | 27 | LAZY_TEST_SUITE = 1 28 | TEST_LOGS = $(TESTS:=.log) 29 | 30 | # improved make check 31 | include $(top_srcdir)/build-aux/check.mk 32 | ----- 33 | 34 | Third, rebuild and test with `make check'. 35 | -------------------------------------------------------------------------------- /cmake/CheckHeaderDirent.cmake: -------------------------------------------------------------------------------- 1 | # - Check if the system has the specified type 2 | # CHECK_HEADER_DIRENT (HEADER1 HEARDER2 ...) 3 | # 4 | # HEADER - the header(s) where the prototype should be declared 5 | # 6 | # The following variables may be set before calling this macro to 7 | # modify the way the check is run: 8 | # 9 | # CMAKE_REQUIRED_FLAGS = string of compile command line flags 10 | # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) 11 | # CMAKE_REQUIRED_INCLUDES = list of include directories 12 | # Copyright (c) 2009, Michihiro NAKAJIMA 13 | # 14 | # Redistribution and use is allowed according to the terms of the BSD license. 15 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 16 | 17 | 18 | INCLUDE(CheckTypeExists) 19 | 20 | MACRO (CHECK_HEADER_DIRENT) 21 | CHECK_TYPE_EXISTS("DIR *" dirent.h HAVE_DIRENT_H) 22 | IF(NOT HAVE_DIRENT_H) 23 | CHECK_TYPE_EXISTS("DIR *" sys/ndir.h HAVE_SYS_NDIR_H) 24 | IF(NOT HAVE_SYS_NDIR_H) 25 | CHECK_TYPE_EXISTS("DIR *" ndir.h HAVE_NDIR_H) 26 | IF(NOT HAVE_NDIR_H) 27 | CHECK_TYPE_EXISTS("DIR *" sys/dir.h HAVE_SYS_DIR_H) 28 | ENDIF(NOT HAVE_NDIR_H) 29 | ENDIF(NOT HAVE_SYS_NDIR_H) 30 | ENDIF(NOT HAVE_DIRENT_H) 31 | ENDMACRO (CHECK_HEADER_DIRENT) 32 | 33 | -------------------------------------------------------------------------------- /doc/example/src/money.3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include "money.h" 23 | 24 | Money *money_create(int amount, char *currency) 25 | { 26 | return NULL; 27 | } 28 | 29 | int money_amount(Money * m) 30 | { 31 | return 0; 32 | } 33 | 34 | char *money_currency(Money * m) 35 | { 36 | return NULL; 37 | } 38 | 39 | void money_free(Money * m) 40 | { 41 | return; 42 | } 43 | -------------------------------------------------------------------------------- /lib/libcompat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | /* silence warnings about an empty library */ 24 | void ck_do_nothing(void) 25 | { 26 | assert(0); 27 | 28 | /* 29 | * to silence warning about this function actually 30 | * returning, but being marked as noreturn. assert() 31 | * must be marked as a function that returns. 32 | */ 33 | exit(1); 34 | } 35 | -------------------------------------------------------------------------------- /doc/example/tests/check_money.2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include "../src/money.h" 23 | 24 | START_TEST(test_money_create) 25 | { 26 | Money *m; 27 | 28 | m = money_create(5, "USD"); 29 | ck_assert_int_eq(money_amount(m), 5); 30 | ck_assert_str_eq(money_currency(m), "USD"); 31 | money_free(m); 32 | } 33 | END_TEST 34 | 35 | int main(void) 36 | { 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /tests/cmake_project_usage_test/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if($ENV{INCLUDE_CHECK_WITH} STREQUAL "FetchContent") 2 | include(FetchContent) 3 | FetchContent_Declare(check 4 | URL "$ENV{INCLUDE_CHECK_FROM}" 5 | # URL file://${DIR}/check 6 | ) 7 | if(CMAKE_VERSION VERSION_LESS "3.14") 8 | FetchContent_GetProperties(check) 9 | if(NOT check_POPULATED) 10 | FetchContent_Populate(check) 11 | add_subdirectory(${check_SOURCE_DIR} ${check_BINARY_DIR}) 12 | endif() 13 | else() 14 | FetchContent_MakeAvailable(check) 15 | endif() 16 | elseif($ENV{INCLUDE_CHECK_WITH} STREQUAL "find_package_config") 17 | set(Check_ROOT "" CACHE PATH "Check installation root dir") 18 | find_package(Check 0.13.0 REQUIRED CONFIG) 19 | else() 20 | message(FATAL_ERROR "Variable INCLUDE_CHECK_WITH not properly set!") 21 | endif() 22 | 23 | include(CheckCCompilerFlag) 24 | check_c_compiler_flag("-pthread" HAVE_PTHREAD) 25 | if (HAVE_PTHREAD) 26 | add_definitions("-pthread") 27 | add_link_options("-pthread") 28 | endif() 29 | 30 | add_library(test_suite test_suite.c) 31 | target_link_libraries(test_suite PUBLIC Check::check) 32 | 33 | add_executable(tests.test tests.c) 34 | target_link_libraries(tests.test test_suite) 35 | 36 | -------------------------------------------------------------------------------- /checkmk/test/not_really_repeated/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Test that repeated suites/tcases are only disallowed when they've 10 | * actually been used in defining a test. */ 11 | 12 | 13 | 14 | #line 8 15 | /* But no test... */ 16 | 17 | 18 | 19 | START_TEST(quuux) 20 | { 21 | #line 15 22 | const char msg[] = "Howdy doody!\n"; 23 | int nc = printf(msg); 24 | 25 | fail_unless(nc == sizeof msg - 1); 26 | 27 | } 28 | END_TEST 29 | 30 | 31 | START_TEST(huh) 32 | { 33 | #line 25 34 | fail_unless(ALLOWED_AFTER_ALL); 35 | } 36 | END_TEST 37 | 38 | int main(void) 39 | { 40 | Suite *s1 = suite_create("Baz"); 41 | TCase *tc1_1 = tcase_create("Quux"); 42 | Suite *s2 = suite_create("Foo"); 43 | TCase *tc2_1 = tcase_create("Bar"); 44 | SRunner *sr = srunner_create(s1); 45 | int nf; 46 | 47 | suite_add_tcase(s1, tc1_1); 48 | tcase_add_test(tc1_1, quuux); 49 | suite_add_tcase(s2, tc2_1); 50 | tcase_add_test(tc2_1, huh); 51 | 52 | srunner_add_suite(sr, s2); 53 | 54 | srunner_run_all(sr, CK_ENV); 55 | nf = srunner_ntests_failed(sr); 56 | srunner_free(sr); 57 | 58 | return nf == 0 ? 0 : 1; 59 | } 60 | -------------------------------------------------------------------------------- /lib/localtime_r.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | #if !defined(localtime_r) 24 | 25 | struct tm *localtime_r(const time_t * clock, struct tm *result) 26 | { 27 | struct tm *now = localtime(clock); 28 | 29 | if(now == NULL) 30 | { 31 | return NULL; 32 | } 33 | else 34 | { 35 | *result = *now; 36 | } 37 | 38 | return result; 39 | } 40 | 41 | #endif /* !defined(localtime_r) */ 42 | -------------------------------------------------------------------------------- /doc/example/src/money.4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include "money.h" 23 | 24 | struct Money 25 | { 26 | int amount; 27 | }; 28 | 29 | Money *money_create(int amount, char *currency) 30 | { 31 | return NULL; 32 | } 33 | 34 | int money_amount(Money * m) 35 | { 36 | return m->amount; 37 | } 38 | 39 | char *money_currency(Money * m) 40 | { 41 | return NULL; 42 | } 43 | 44 | void money_free(Money * m) 45 | { 46 | return; 47 | } 48 | -------------------------------------------------------------------------------- /lib/timer_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | int timer_create(clockid_t clockid CK_ATTRIBUTE_UNUSED, 24 | struct sigevent *sevp CK_ATTRIBUTE_UNUSED, 25 | timer_t * timerid CK_ATTRIBUTE_UNUSED) 26 | { 27 | /* 28 | * The create function does nothing. timer_settime will use 29 | * alarm to set the timer, and timer_delete will stop the 30 | * alarm 31 | */ 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /doc/man/man3/suite_create.3.in: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) LibCheck, 2001-2020. 2 | .\" 3 | .\" Permission is granted to copy, distribute and/or 4 | .\" modify this document under the terms of the GNU 5 | .\" Free Documentation License, Version 1.3 or any later 6 | .\" version published by the Free Software Foundation; with 7 | .\" no Invariant Sections, no Front-Cover Texts, and no 8 | .\" Back-Cover Texts. A copy of the license is included in 9 | .\" the section entitled "GNU Free Documentation License". 10 | .\" 11 | .TH "suite_create" "3" "" "@PROJECT_VERSION@" "LibCheck" 12 | .SH "PROLOG" 13 | This manual page is part of the Check Programmer's Manual. 14 | Additional information may be found at the Check Library 15 | home page, at https://libcheck.github.io/check/. 16 | .SH "NAME" 17 | suite_create 18 | \(em create test case container object 19 | .SH "SYNOPSIS" 20 | .LP 21 | .nf 22 | #include 23 | .P 24 | Suite* suite_create(const char *name); 25 | .SH "DESCRIPTION" 26 | The 27 | \fIsuite_create\fR() 28 | function returns a pointer to a heap-allocated test suite 29 | object. 30 | .SH "RETURN VALUE" 31 | Upon successful completion, the 32 | \fIsuite_create\fR() 33 | function returns a pointer containing the address of the 34 | heap-allocated test suite object. Otherwise, the function 35 | prints an error message to standard error indicating that 36 | something went wrong, and then returns a NULL pointer. 37 | -------------------------------------------------------------------------------- /lib/malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | /* 22 | * AC_FUNC_MALLOC in configure defines malloc to rpl_malloc if 23 | * malloc (0) is NULL to provide GNU compatibility 24 | */ 25 | 26 | #include "libcompat.h" 27 | 28 | /* malloc has been defined to rpl_malloc, so first undo that */ 29 | #undef malloc 30 | 31 | /* this gives us the real malloc to use below */ 32 | void *malloc(size_t n); 33 | 34 | /* force malloc(0) to return a valid pointer */ 35 | void *rpl_malloc(size_t n) 36 | { 37 | if(n == 0) 38 | n = 1; 39 | return malloc(n); 40 | } 41 | -------------------------------------------------------------------------------- /doc/example/cmake/COPYING-CMAKE-SCRIPTS.txt: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 2. Redistributions in binary form must reproduce the copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote products 11 | derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /src/check_print.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef CHECK_PRINT_H 22 | #define CHECK_PRINT_H 23 | 24 | /* escape XML special characters (" ' < > &) in str and print to file */ 25 | void fprint_xml_esc(FILE * file, const char *str); 26 | void tr_fprint(FILE * file, TestResult * tr, enum print_output print_mode); 27 | void tr_xmlprint(FILE * file, TestResult * tr, enum print_output print_mode); 28 | void srunner_fprint(FILE * file, SRunner * sr, enum print_output print_mode); 29 | enum print_output get_env_printmode(void); 30 | 31 | 32 | #endif /* CHECK_PRINT_H */ 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Temp files 2 | *~ 3 | *.bak 4 | *.backup 5 | \#* 6 | .\#* 7 | *\# 8 | *.sav 9 | *.save 10 | *.autosav 11 | *.autosave 12 | *.swp 13 | *.swap 14 | 15 | # Generated binaries 16 | *.o 17 | *.lo 18 | *.la 19 | *.Po 20 | *.Plo 21 | 22 | # Generated folders 23 | bin/ 24 | build/ 25 | release/ 26 | debug/ 27 | 28 | # CMake 29 | CMakeCache.txt 30 | CMakeFiles/ 31 | CTestTestfile.cmake 32 | DartConfiguration.tcl 33 | Testing/ 34 | check_error_linenums_seRbql 35 | check_test_names__e1JTIe 36 | cmake_install.cmake 37 | lib/CMakeFiles/ 38 | lib/cmake_install.cmake 39 | lib/libcompat.a 40 | src/CMakeFiles/ 41 | src/cmake_install.cmake 42 | src/libcheck.a 43 | tests/CMakeFiles/ 44 | tests/CTestTestfile.cmake 45 | tests/check_check 46 | tests/check_check_export 47 | tests/check_nofork 48 | tests/check_nofork_teardown 49 | tests/cmake_install.cmake 50 | 51 | build-aux 52 | Makefile.in 53 | Makefile 54 | .libs 55 | INSTALL 56 | SVNChangeLog 57 | aclocal.m4 58 | autom4te.cache/ 59 | build-aus 60 | check.pc 61 | check_stdint.h 62 | test.out 63 | config.h 64 | config.log 65 | config.status 66 | configure 67 | check.info 68 | *.diff 69 | libtool 70 | libtool.m4 71 | ltoptions.m4 72 | ltsugar.m4 73 | ltversion.m4 74 | version.texi 75 | lt~obsolete.m4 76 | check.h 77 | exported.sym 78 | stamp-h1 79 | stamp-vti 80 | test_vars 81 | tests/ex_output 82 | tests/test.xml 83 | tests/*.log 84 | tests/*.sh.trs 85 | tests/*.tap 86 | checkmk/*.log 87 | checkmk/test/*.log 88 | -------------------------------------------------------------------------------- /src/check_msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef CHECK_MSG_NEW_H 22 | #define CHECK_MSG_NEW_H 23 | 24 | 25 | /* Functions implementing messaging during test runs */ 26 | 27 | void send_failure_info(const char *msg); 28 | void send_loc_info(const char *file, int line); 29 | void send_ctx_info(enum ck_result_ctx ctx); 30 | void send_duration_info(int duration); 31 | 32 | TestResult *receive_test_result(int waserror); 33 | 34 | void setup_messaging(void); 35 | void teardown_messaging(void); 36 | 37 | FILE *open_tmp_file(char **name); 38 | 39 | #endif /*CHECK_MSG_NEW_H */ 40 | -------------------------------------------------------------------------------- /cmake/CheckTypeExists.cmake: -------------------------------------------------------------------------------- 1 | # - Check if the system has the specified type 2 | # CHECK_TYPE_EXISTS (TYPE HEADER VARIABLE) 3 | # 4 | # TYPE - the name of the type or struct or class you are interested in 5 | # HEADER - the header(s) where the prototype should be declared 6 | # VARIABLE - variable to store the result 7 | # 8 | # The following variables may be set before calling this macro to 9 | # modify the way the check is run: 10 | # 11 | # CMAKE_REQUIRED_FLAGS = string of compile command line flags 12 | # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) 13 | # CMAKE_REQUIRED_INCLUDES = list of include directories 14 | # Copyright (c) 2009, Michihiro NAKAJIMA 15 | # Copyright (c) 2006, Alexander Neundorf, 16 | # 17 | # Redistribution and use is allowed according to the terms of the BSD license. 18 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 19 | 20 | 21 | INCLUDE(CheckCSourceCompiles) 22 | 23 | MACRO (CHECK_TYPE_EXISTS _TYPE _HEADER _RESULT) 24 | SET(_INCLUDE_FILES) 25 | FOREACH (it ${_HEADER}) 26 | SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") 27 | ENDFOREACH (it) 28 | 29 | SET(_CHECK_TYPE_EXISTS_SOURCE_CODE " 30 | ${_INCLUDE_FILES} 31 | int main() 32 | { 33 | static ${_TYPE} tmp; 34 | if (sizeof(tmp)) 35 | return 0; 36 | return 0; 37 | } 38 | ") 39 | CHECK_C_SOURCE_COMPILES("${_CHECK_TYPE_EXISTS_SOURCE_CODE}" ${_RESULT}) 40 | 41 | ENDMACRO (CHECK_TYPE_EXISTS) 42 | 43 | -------------------------------------------------------------------------------- /src/check_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef ERROR_H 22 | #define ERROR_H 23 | 24 | #include "../lib/libcompat.h" 25 | #include 26 | 27 | extern jmp_buf error_jmp_buffer; 28 | 29 | /* Include stdlib.h beforehand */ 30 | 31 | /* Print error message and die 32 | If fmt ends in colon, include system error information */ 33 | void eprintf(const char *fmt, const char *file, int line, 34 | ...) CK_ATTRIBUTE_NORETURN CK_ATTRIBUTE_FORMAT(printf, 1, 4); 35 | /* malloc or die */ 36 | void *emalloc(size_t n); 37 | void *erealloc(void *, size_t n); 38 | 39 | #endif /*ERROR_H */ 40 | -------------------------------------------------------------------------------- /tests/test_set_max_msg_size.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | UNIT_TEST=./check_set_max_msg_size 4 | MAX_MESSAGE_LOG_FILE=${UNIT_TEST}.output 5 | TOO_LONG_MESSAGE="Message string too long" 6 | 7 | # This test reduces the maximal message size using the provided function, 8 | # so that the assertion message becomes too long. 9 | # We set the maximal size to 32, which is shorter than the message. 10 | 11 | rm -f ${MAX_MESSAGE_LOG_FILE} 12 | ${UNIT_TEST} 32 2>&1 | tee ${MAX_MESSAGE_LOG_FILE} 13 | 14 | NUM_TOO_LONG_MESSAGES=$(grep "${TOO_LONG_MESSAGE}" ${MAX_MESSAGE_LOG_FILE} | wc -l) 15 | 16 | if test ${NUM_TOO_LONG_MESSAGES} -gt 0; then 17 | echo "Maximal message size was reduced by function call." 18 | rm -f ${MAX_MESSAGE_LOG_FILE} 19 | else 20 | echo "ERROR: Maximal message size was not reduced by function call." 21 | echo "Test output was preserved in ${MAX_MESSAGE_LOG_FILE}" 22 | exit 1 23 | fi 24 | 25 | rm -f ${MAX_MESSAGE_LOG_FILE} 26 | export CK_MAX_MSG_SIZE=32 27 | ${UNIT_TEST} 4096 2>&1 | tee ${MAX_MESSAGE_LOG_FILE} 28 | 29 | NUM_TOO_LONG_MESSAGES=$(grep "${TOO_LONG_MESSAGE}" ${MAX_MESSAGE_LOG_FILE} | wc -l) 30 | 31 | if test ${NUM_TOO_LONG_MESSAGES} -gt 0; then 32 | echo "Maximal message size was reduced by environment variable." 33 | else 34 | echo "ERROR: Maximal message size was not reduced by environment variable." 35 | echo "Test output was preserved in ${MAX_MESSAGE_LOG_FILE}" 36 | exit 1 37 | fi 38 | 39 | rm -f ${MAX_MESSAGE_LOG_FILE} 40 | exit 0 41 | -------------------------------------------------------------------------------- /cmake/CheckStructMember.cmake: -------------------------------------------------------------------------------- 1 | # - Check if the given struct or class has the specified member variable 2 | # CHECK_STRUCT_MEMBER (STRUCT MEMBER HEADER VARIABLE) 3 | # 4 | # STRUCT - the name of the struct or class you are interested in 5 | # MEMBER - the member which existence you want to check 6 | # HEADER - the header(s) where the prototype should be declared 7 | # VARIABLE - variable to store the result 8 | # 9 | # The following variables may be set before calling this macro to 10 | # modify the way the check is run: 11 | # 12 | # CMAKE_REQUIRED_FLAGS = string of compile command line flags 13 | # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) 14 | # CMAKE_REQUIRED_INCLUDES = list of include directories 15 | 16 | # Copyright (c) 2006, Alexander Neundorf, 17 | # 18 | # Redistribution and use is allowed according to the terms of the BSD license. 19 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 20 | 21 | 22 | INCLUDE(CheckCSourceCompiles) 23 | 24 | MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT) 25 | SET(_INCLUDE_FILES) 26 | FOREACH (it ${_HEADER}) 27 | SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") 28 | ENDFOREACH (it) 29 | 30 | SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE " 31 | ${_INCLUDE_FILES} 32 | int main() 33 | { 34 | static ${_STRUCT} tmp; 35 | if (sizeof(tmp.${_MEMBER})) 36 | return 0; 37 | return 0; 38 | } 39 | ") 40 | CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT}) 41 | 42 | ENDMACRO (CHECK_STRUCT_MEMBER) 43 | 44 | -------------------------------------------------------------------------------- /lib/realloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | /* 22 | * AC_FUNC_REALLOC in configure defines realloc to rpl_realloc if 23 | * realloc (p, 0) or realloc (0, n) is NULL to provide GNU 24 | * compatibility 25 | */ 26 | 27 | #include "libcompat.h" 28 | 29 | /* realloc has been defined to rpl_realloc, so first undo that */ 30 | #undef realloc 31 | 32 | /* this gives us the real realloc to use below */ 33 | void *realloc(void *p, size_t n); 34 | 35 | /* force realloc(p, 0) and realloc (NULL, n) to return a valid pointer */ 36 | void *rpl_realloc(void *p, size_t n) 37 | { 38 | if(n == 0) 39 | n = 1; 40 | if(p == 0) 41 | return malloc(n); 42 | return realloc(p, n); 43 | } 44 | -------------------------------------------------------------------------------- /doc/example/src/money.5.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include "money.h" 23 | 24 | struct Money 25 | { 26 | int amount; 27 | char *currency; 28 | }; 29 | 30 | Money *money_create(int amount, char *currency) 31 | { 32 | Money *m = malloc(sizeof(Money)); 33 | 34 | if (m == NULL) 35 | { 36 | return NULL; 37 | } 38 | 39 | m->amount = amount; 40 | m->currency = currency; 41 | return m; 42 | } 43 | 44 | int money_amount(Money * m) 45 | { 46 | return m->amount; 47 | } 48 | 49 | char *money_currency(Money * m) 50 | { 51 | return m->currency; 52 | } 53 | 54 | void money_free(Money * m) 55 | { 56 | free(m); 57 | return; 58 | } 59 | -------------------------------------------------------------------------------- /cmake/check_stdint.h.in: -------------------------------------------------------------------------------- 1 | /*-*- mode:C; -*- */ 2 | /* 3 | * Check: a unit test framework for C 4 | * 5 | * Copyright (C) 2013 Branden Archer 6 | * Copyright (C) 2019 Mikko Johannes Koivunalho 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | 24 | #ifndef _CHECK_CHECK_STDINT_H 25 | #define _CHECK_CHECK_STDINT_H 1 26 | #ifndef _GENERATED_STDINT_H 27 | #define _GENERATED_STDINT_H "@PROJECT_NAME@ @PROJECT_VERSION@" 28 | /* generated using CMake @CMAKE_VERSION@ from file cmake/check_stdint.h.in */ 29 | 30 | /* Imported CMake variables created during build. */ 31 | #cmakedefine HAVE_STDINT_H 1 32 | 33 | #ifdef HAVE_STDINT_H 34 | #define _STDINT_HAVE_STDINT_H 1 35 | #include 36 | #undef HAVE_STDINT_H 37 | #endif /* defined HAVE_STDINT_H */ 38 | 39 | /* Define only once */ 40 | #endif /* _GENERATED_STDINT_H */ 41 | #endif /* _CHECK_CHECK_STDINT_H */ 42 | -------------------------------------------------------------------------------- /tests/check_check_export_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include "check_check.h" 27 | 28 | int main (void) 29 | { 30 | int number_failed; 31 | SRunner *sr; 32 | 33 | fork_setup(); 34 | setup(); 35 | sr = srunner_create (make_master_suite()); 36 | srunner_add_suite(sr, make_log_suite()); 37 | srunner_add_suite(sr, make_fork_suite()); 38 | 39 | printf ("Ran %d tests in subordinate suite\n", sub_ntests); 40 | srunner_run_all (sr, CK_VERBOSE); 41 | cleanup(); 42 | fork_teardown(); 43 | number_failed = srunner_ntests_failed(sr); 44 | srunner_free(sr); 45 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 46 | } 47 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: There are no bugs here. But just in case... 4 | 5 | --- 6 | # Bug Report 7 | Thank you for filing a bug report! The more information you 8 | can give us about your development environment, toolchain, 9 | actions leading up to the bug, or any other contextual 10 | information, the faster we'll be able to verify and diagnose 11 | what went wrong. 12 | 13 | At a minimun, please be sure to include the library version 14 | you were working with. If you were trying to compile it from 15 | source, please be sure to specify the compiler, compiler 16 | version, operating system, operating system version, the 17 | build system you used to generate the project, and whether 18 | you were building from a source distribution or from version 19 | control. 20 | 21 | If you have no idea what any or all of the above terms mean, 22 | you are always welcome to submit a bug report anyways, but 23 | please remember the Fundamental Theorem of Bug Report 24 | Submissions: 25 | 26 | > The amount of information in a bug report is directly 27 | proportional to its resolution speed. 28 | 29 | ## Checklist 30 | Please do your best to include the following items with your 31 | bug report. 32 | 33 | ### The Bare Minimum 34 | Remember that this is the **minimum** required information. 35 | More is always more helpful. 36 | 37 | - [ ] [libcheck](https://github.com/libcheck/check) version 38 | - [ ] Operating system 39 | - [ ] Compiler 40 | 41 | ## Additional Information 42 | Please be sure to include any additional information you 43 | think may be helpful in helping us diagnose, understand, or 44 | replicate the problem. 45 | -------------------------------------------------------------------------------- /doc/example/src/money.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include "money.h" 23 | 24 | struct Money 25 | { 26 | int amount; 27 | char *currency; 28 | }; 29 | 30 | Money *money_create(int amount, char *currency) 31 | { 32 | Money *m; 33 | 34 | if (amount < 0) 35 | { 36 | return NULL; 37 | } 38 | 39 | m = malloc(sizeof(Money)); 40 | 41 | if (m == NULL) 42 | { 43 | return NULL; 44 | } 45 | 46 | m->amount = amount; 47 | m->currency = currency; 48 | return m; 49 | } 50 | 51 | int money_amount(Money * m) 52 | { 53 | return m->amount; 54 | } 55 | 56 | char *money_currency(Money * m) 57 | { 58 | return m->currency; 59 | } 60 | 61 | void money_free(Money * m) 62 | { 63 | free(m); 64 | return; 65 | } 66 | -------------------------------------------------------------------------------- /doc/example/src/money.6.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include "money.h" 23 | 24 | struct Money 25 | { 26 | int amount; 27 | char *currency; 28 | }; 29 | 30 | Money *money_create(int amount, char *currency) 31 | { 32 | Money *m; 33 | 34 | if (amount < 0) 35 | { 36 | return NULL; 37 | } 38 | 39 | m = malloc(sizeof(Money)); 40 | 41 | if (m == NULL) 42 | { 43 | return NULL; 44 | } 45 | 46 | m->amount = amount; 47 | m->currency = currency; 48 | return m; 49 | } 50 | 51 | int money_amount(Money * m) 52 | { 53 | return m->amount; 54 | } 55 | 56 | char *money_currency(Money * m) 57 | { 58 | return m->currency; 59 | } 60 | 61 | void money_free(Money * m) 62 | { 63 | free(m); 64 | return; 65 | } 66 | -------------------------------------------------------------------------------- /contrib/XML_for_JUnit.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 0 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | / 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /checkmk/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Check: a unit test framework for C 3 | # Copyright (C) 2020 Mikko Koivunalho 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2.1 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the 17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | # Boston, MA 02111-1307, USA. 19 | # 20 | 21 | set(conf_file "checkmk.in" FILEPATH) 22 | set(configure_input "Generated from ${conf_file} by configure.") 23 | find_program(AWK_PATH awk) 24 | 25 | configure_file(checkmk.in checkmk @ONLY) 26 | 27 | file(COPY doc/checkmk.1 DESTINATION man/man1) 28 | 29 | option(INSTALL_CHECKMK "Install checkmk" ON) 30 | if(INSTALL_CHECKMK AND NOT THIS_IS_SUBPROJECT) 31 | install( 32 | FILES ${CMAKE_CURRENT_BINARY_DIR}/checkmk 33 | DESTINATION ${CMAKE_INSTALL_BINDIR} 34 | PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE 35 | ) 36 | install( 37 | DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/man 38 | DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} 39 | ) 40 | endif() 41 | 42 | # vim: shiftwidth=2:softtabstop=2:tabstop=2:expandtab:autoindent 43 | 44 | -------------------------------------------------------------------------------- /lib/gettimeofday.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | #include 23 | 24 | #if defined(_MSC_VER) || defined(__BORLANDC__) 25 | #define EPOCHFILETIME (116444736000000000i64) 26 | #else 27 | #define EPOCHFILETIME (116444736000000000LL) 28 | #endif 29 | 30 | int gettimeofday(struct timeval *tv, void *tz) 31 | { 32 | #if defined(_MSC_VER) 33 | union 34 | { 35 | __int64 ns100; /* time since 1 Jan 1601 in 100ns units */ 36 | FILETIME ft; 37 | } now; 38 | 39 | GetSystemTimeAsFileTime(&now.ft); 40 | tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL); 41 | tv->tv_sec = (long)((now.ns100 - EPOCHFILETIME) / 10000000LL); 42 | return (0); 43 | #else 44 | /* Return that there is no implementation of this on the system */ 45 | errno = ENOSYS; 46 | return -1; 47 | #endif /* _MSC_VER */ 48 | } 49 | -------------------------------------------------------------------------------- /tests/test_xml_output.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | OUTPUT_FILE=test.xml 4 | CK_DEFAULT_TIMEOUT=4 5 | 6 | . ./test_vars 7 | . $(dirname $0)/test_output_strings 8 | 9 | rm -f ${OUTPUT_FILE} 10 | export CK_DEFAULT_TIMEOUT 11 | ./ex_output${EXEEXT} CK_MINIMAL XML NORMAL > /dev/null 12 | actual_xml=`cat ${OUTPUT_FILE} | tr -d "\r" | grep -v \ | grep -v \ | grep -v \` 13 | if [ x"${expected_xml}" != x"${actual_xml}" ]; then 14 | echo "Problem with ex_xml_output${EXEEXT}"; 15 | echo "Expected:"; 16 | echo "${expected_xml}"; 17 | echo "Got:"; 18 | echo "${actual_xml}"; 19 | exit 1; 20 | fi 21 | 22 | actual_duration_count=`grep -c \ ${OUTPUT_FILE}` 23 | if [ x"${expected_duration_count}" != x"${actual_duration_count}" ]; then 24 | echo "Wrong number of elements in ${OUTPUT_FILE}, ${expected_duration_count} vs ${actual_duration_count}"; 25 | exit 1; 26 | fi 27 | 28 | num_durations=`grep "\" ${OUTPUT_FILE} | wc -l` 29 | 30 | i=1 31 | while [ ${i} -le ${num_durations} ]; do 32 | duration=`grep "\" ${OUTPUT_FILE} | head -n ${i} | tail -n 1 | cut -d ">" -f 2 | cut -d "<" -f 1` 33 | int_duration=`echo $duration | cut -d "." -f 1` 34 | if [ "${int_duration}" -ne "-1" ] && [ "${int_duration}" -gt "${CK_DEFAULT_TIMEOUT}" ]; then 35 | echo "Problem with duration ${duration}; is not valid. Should be -1 or in [0, ${CK_DEFAULT_TIMEOUT}]" 36 | exit 1 37 | fi 38 | 39 | i=$((i+1)) 40 | done 41 | 42 | if [ ! -z `which xmllint` ]; then 43 | xmllint_output=`xmllint ${OUTPUT_FILE}` 44 | if [ $? -ne 0 ]; then 45 | echo "xmllint found an issue" 46 | echo ${xmllint_output} 47 | exit 1 48 | fi 49 | fi 50 | 51 | exit 0 52 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | ## run tests after everything else 4 | 5 | if MAKE_DOCS 6 | OPTIONAL_DOC_TARGET = doc 7 | else 8 | OPTIONAL_DOC_TARGET = 9 | endif 10 | 11 | SUBDIRS = lib src $(OPTIONAL_DOC_TARGET) . checkmk tests 12 | 13 | ## FIXME: maybe we don't need this line 14 | 15 | AM_MAKEINFOFLAGS = -I$(top_srcdir)/doc/example 16 | 17 | ## what to clean 18 | 19 | CLEANFILES = *~\ 20 | $(PACKAGE)-$(VERSION).tar.gz\ 21 | ChangeLog.bak 22 | 23 | ## what additional things to distribute 24 | 25 | include_HEADERS = check_stdint.h 26 | 27 | EXTRA_DIST = check.pc.in $(m4data_DATA) xml/check_unittest.xslt \ 28 | CMakeLists.txt src/CMakeLists.txt tests/CMakeLists.txt lib/CMakeLists.txt \ 29 | checkmk/CMakeLists.txt \ 30 | cmake 31 | 32 | ## install docs 33 | docdir = $(datadir)/doc/$(PACKAGE) 34 | doc_DATA = ChangeLog NEWS README COPYING.LESSER 35 | 36 | ## install check.m4 with AM_PATH_CHECK in it 37 | m4datadir = $(datadir)/aclocal 38 | m4data_DATA = check.m4 39 | 40 | ## install check.pc 41 | pcdatadir = $(libdir)/pkgconfig 42 | pcdata_DATA = check.pc 43 | 44 | DISTCLEANFILES = check_stdint.h 45 | 46 | ACLOCAL_AMFLAGS = -I m4 47 | 48 | README: 49 | fgrep -v "Build Status]" $(top_srcdir)/README.md > $@ 50 | 51 | doc/check_html: 52 | $(MAKE) -C doc check_html 53 | 54 | doc/doxygen: 55 | $(MAKE) -C doc doxygen 56 | 57 | doc/doxygen-devel: 58 | $(MAKE) -C doc doxygen-devel 59 | 60 | # check we can do a clean build, including docs. 61 | # perhaps we should check for out of date (svn st -u) and modified files. 62 | prereleasecheck: doc/check_html doc/doxygen 63 | -$(MAKE) distclean 64 | autoreconf -i && ./configure \ 65 | && ulimit -c 0 && \ 66 | $(MAKE) distcheck 67 | 68 | .PHONY: prereleasecheck 69 | -------------------------------------------------------------------------------- /lib/timer_delete.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | int timer_delete(timer_t timerid CK_ATTRIBUTE_UNUSED) 24 | { 25 | #ifdef HAVE_SETITIMER 26 | /* 27 | * If the system does not have timer_settime() but does have 28 | * setitimer() use that instead of alarm(). 29 | */ 30 | struct itimerval interval; 31 | 32 | /* 33 | * Setting values to '0' results in disabling the running timer. 34 | */ 35 | interval.it_value.tv_sec = 0; 36 | interval.it_value.tv_usec = 0; 37 | interval.it_interval.tv_sec = 0; 38 | interval.it_interval.tv_usec = 0; 39 | 40 | return setitimer(ITIMER_REAL, &interval, NULL); 41 | #else 42 | /* 43 | * There is only one timer, that used by alarm. 44 | * Setting alarm(0) will not set a new alarm, and 45 | * will kill the previous timer. 46 | */ 47 | 48 | alarm(0); 49 | 50 | return 0; 51 | #endif 52 | } 53 | -------------------------------------------------------------------------------- /lib/getline.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | #include 23 | 24 | #define INITIAL_SIZE 16 25 | #define DELIMITER '\n' 26 | 27 | ssize_t getline(char **lineptr, size_t *n, FILE *stream) 28 | { 29 | ssize_t written = 0; 30 | int character; 31 | 32 | if(*lineptr == NULL || *n < INITIAL_SIZE) 33 | { 34 | free(*lineptr); 35 | *lineptr = (char *)malloc(INITIAL_SIZE); 36 | *n = INITIAL_SIZE; 37 | } 38 | 39 | while( (character = fgetc(stream)) != EOF) 40 | { 41 | written += 1; 42 | if(written >= *n) 43 | { 44 | *n = *n * 2; 45 | *lineptr = realloc(*lineptr, *n); 46 | } 47 | 48 | (*lineptr)[written-1] = character; 49 | 50 | if(character == DELIMITER) 51 | { 52 | break; 53 | } 54 | } 55 | 56 | (*lineptr)[written] = '\0'; 57 | 58 | return written; 59 | } 60 | -------------------------------------------------------------------------------- /src/check_str.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef CHECK_STR_H 22 | #define CHECK_STR_H 23 | 24 | #include "../lib/libcompat.h" 25 | 26 | /* Return a string representation of the given TestResult. Return 27 | value has been malloc'd, and must be freed by the caller */ 28 | char *tr_str(TestResult * tr); 29 | 30 | /* Return a string representation of the given TestResult message 31 | without the test id or result type. This is suitable for separate 32 | formatting of the test and the message. Return value has been 33 | malloc'd, and must be freed by the caller */ 34 | char *tr_short_str(TestResult * tr); 35 | 36 | /* Return a string representation of the given SRunner's run 37 | statistics (% passed, num run, passed, errors, failures). Return 38 | value has been malloc'd, and must be freed by the caller 39 | */ 40 | char *sr_stat_str(SRunner * sr); 41 | 42 | char *ck_strdup_printf(const char *fmt, ...) CK_ATTRIBUTE_FORMAT(printf, 1, 2); 43 | 44 | #endif /* CHECK_STR_H */ 45 | -------------------------------------------------------------------------------- /doc/example/tests/check_money.3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include "../src/money.h" 24 | 25 | START_TEST(test_money_create) 26 | { 27 | Money *m; 28 | 29 | m = money_create(5, "USD"); 30 | ck_assert_int_eq(money_amount(m), 5); 31 | ck_assert_str_eq(money_currency(m), "USD"); 32 | money_free(m); 33 | } 34 | END_TEST 35 | 36 | Suite * money_suite(void) 37 | { 38 | Suite *s; 39 | TCase *tc_core; 40 | 41 | s = suite_create("Money"); 42 | 43 | /* Core test case */ 44 | tc_core = tcase_create("Core"); 45 | 46 | tcase_add_test(tc_core, test_money_create); 47 | suite_add_tcase(s, tc_core); 48 | 49 | return s; 50 | } 51 | 52 | int main(void) 53 | { 54 | int number_failed; 55 | Suite *s; 56 | SRunner *sr; 57 | 58 | s = money_suite(); 59 | sr = srunner_create(s); 60 | 61 | srunner_run_all(sr, CK_NORMAL); 62 | number_failed = srunner_ntests_failed(sr); 63 | srunner_free(sr); 64 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 65 | } 66 | -------------------------------------------------------------------------------- /tests/check_check_limit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include "check_check.h" 27 | #include "check_str.h" 28 | 29 | 30 | static SRunner *sr; 31 | 32 | static void limit_setup (void) 33 | { 34 | Suite *s = suite_create("Empty"); 35 | sr = srunner_create(s); 36 | srunner_run_all(sr, CK_VERBOSE); 37 | } 38 | 39 | static void limit_teardown (void) 40 | { 41 | srunner_free(sr); 42 | } 43 | 44 | START_TEST(test_summary) 45 | { 46 | char * string = sr_stat_str(sr); 47 | ck_assert_msg(strcmp(string, 48 | "100%: Checks: 0, Failures: 0, Errors: 0") == 0, 49 | "Bad statistics string for empty suite"); 50 | free(string); 51 | } 52 | END_TEST 53 | 54 | Suite *make_limit_suite (void) 55 | { 56 | Suite *s = suite_create("Limit"); 57 | TCase *tc = tcase_create("Empty"); 58 | 59 | tcase_add_test(tc,test_summary); 60 | tcase_add_unchecked_fixture(tc,limit_setup,limit_teardown); 61 | 62 | suite_add_tcase(s, tc); 63 | 64 | return s; 65 | } 66 | -------------------------------------------------------------------------------- /lib/fpclassify.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2017, bel2125 2 | * 3 | * This library is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU Lesser General Public 5 | * License as published by the Free Software Foundation; either 6 | * version 2.1 of the License, or (at your option) any later version. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with this library; if not, write to the 15 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 16 | * MA 02110-1301, USA. 17 | */ 18 | /* Note: Within "check", this file uses the LGPL license. 19 | * If you need only this file, you may find a MIT licensed version in 20 | * the "floatmagic" repository of the initial author. 21 | */ 22 | 23 | #include "libcompat.h" 24 | 25 | double DOUBLE_ZERO = 0.0; 26 | 27 | #if defined(NEED_fpclassify) 28 | 29 | #if defined(HAVE_STDINT_H) 30 | #include 31 | typedef uint64_t bitfield64; 32 | #elif defined(_MSC_VER) 33 | typedef unsigned __int64 bitfield64; 34 | #else 35 | typedef unsigned long long bitfield64; 36 | #endif 37 | 38 | static bitfield64 ms = 0x8000000000000000; 39 | static bitfield64 me = 0x7FF0000000000000; 40 | static bitfield64 mf = 0x000FFFFFFFFFFFFF; 41 | 42 | int fpclassify(double d) 43 | { 44 | bitfield64 *p = (bitfield64 *)&d; 45 | if ((*p & me) != me) { 46 | /* finite */ 47 | if (*p & mf) { 48 | /* finite and not null */ 49 | if (*p & me) { 50 | return FP_NORMAL; 51 | } 52 | return FP_SUBNORMAL; 53 | } 54 | return FP_ZERO; 55 | } 56 | if (*p & mf) { 57 | return FP_NAN; 58 | } 59 | return FP_INFINITE; 60 | } 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /src/check_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef CHECK_LIST_H 22 | #define CHECK_LIST_H 23 | 24 | typedef struct List List; 25 | 26 | /* Create an empty list */ 27 | List *check_list_create(void); 28 | 29 | /* Is list at end? */ 30 | int check_list_at_end(List * lp); 31 | 32 | /* Position list at front */ 33 | void check_list_front(List * lp); 34 | 35 | /* Add a value to the front of the list, 36 | positioning newly added value as current value. 37 | More expensive than list_add_end, as it uses memmove. */ 38 | void check_list_add_front(List * lp, void *val); 39 | 40 | /* Add a value to the end of the list, 41 | positioning newly added value as current value */ 42 | void check_list_add_end(List * lp, void *val); 43 | 44 | /* Give the value of the current node */ 45 | void *check_list_val(List * lp); 46 | 47 | /* Position the list at the next node */ 48 | void check_list_advance(List * lp); 49 | 50 | /* Free a list, but don't free values */ 51 | void check_list_free(List * lp); 52 | 53 | void check_list_apply(List * lp, void (*fp) (void *)); 54 | 55 | /* Return true if the list contains the value, false otherwise */ 56 | int check_list_contains(List * lp, void *val); 57 | 58 | 59 | #endif /* CHECK_LIST_H */ 60 | -------------------------------------------------------------------------------- /lib/pthread_mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2020 Wander Lairson Costa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | #ifdef HAVE_WIN32_INIT_ONCE 24 | 25 | static int mutex_init(pthread_mutex_t *mutex) 26 | { 27 | BOOL pending; 28 | int ret = 0; 29 | 30 | if (!InitOnceBeginInitialize(&mutex->init, 0, &pending, NULL)) 31 | return -1; 32 | 33 | if (pending) 34 | { 35 | mutex->mutex = CreateMutexW(NULL, FALSE, NULL); 36 | if (!mutex->mutex) 37 | ret = -1; 38 | } 39 | 40 | InitOnceComplete(&mutex->init, 0, NULL); 41 | 42 | return ret; 43 | } 44 | 45 | int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr) 46 | { 47 | InitOnceInitialize(&mutex->init); 48 | return mutex_init(mutex); 49 | } 50 | 51 | int pthread_mutex_destroy(pthread_mutex_t *mutex) 52 | { 53 | return CloseHandle(mutex->mutex) ? 0 : -1; 54 | } 55 | 56 | int pthread_mutex_lock(pthread_mutex_t *mutex) 57 | { 58 | if (mutex_init(mutex) != 0) 59 | return -1; 60 | 61 | return WaitForSingleObject(mutex->mutex, INFINITE) != WAIT_OBJECT_0 62 | ? -1 : 0; 63 | } 64 | 65 | int pthread_mutex_unlock(pthread_mutex_t *mutex) 66 | { 67 | return ReleaseMutex(mutex->mutex) ? 0 : -1; 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /lib/timer_settime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | int timer_settime(timer_t timerid CK_ATTRIBUTE_UNUSED, 24 | int flags CK_ATTRIBUTE_UNUSED, 25 | const struct itimerspec *new_value, 26 | struct itimerspec *old_value CK_ATTRIBUTE_UNUSED) 27 | { 28 | #ifdef HAVE_SETITIMER 29 | /* 30 | * If the system does not have timer_settime() but does have 31 | * setitimer() use that instead of alarm(). 32 | */ 33 | struct itimerval interval; 34 | 35 | interval.it_value.tv_sec = new_value->it_value.tv_sec; 36 | interval.it_value.tv_usec = new_value->it_value.tv_nsec / 1000; 37 | interval.it_interval.tv_sec = new_value->it_interval.tv_sec; 38 | interval.it_interval.tv_usec = new_value->it_interval.tv_nsec / 1000; 39 | 40 | return setitimer(ITIMER_REAL, &interval, NULL); 41 | #else 42 | int seconds = new_value->it_value.tv_sec; 43 | 44 | /* 45 | * As the alarm() call has only second precision, if the caller 46 | * specifies partial seconds, we round up to the nearest second. 47 | */ 48 | if(new_value->it_value.tv_nsec > 0) 49 | { 50 | seconds += 1; 51 | } 52 | 53 | alarm(seconds); 54 | 55 | return 0; 56 | #endif 57 | } 58 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | lib_LTLIBRARIES = libcheck.la 4 | noinst_LTLIBRARIES = libcheckinternal.la 5 | 6 | include_HEADERS = check.h 7 | 8 | EXTRA_DIST = check.h.in 9 | 10 | AM_CFLAGS = @GCOV_CFLAGS@ @PTHREAD_CFLAGS@ $(LIBSUBUNIT_CFLAGS) 11 | 12 | CFILES =\ 13 | check.c \ 14 | check_error.c \ 15 | check_list.c \ 16 | check_log.c \ 17 | check_msg.c \ 18 | check_pack.c \ 19 | check_print.c \ 20 | check_run.c \ 21 | check_str.c 22 | 23 | HFILES =\ 24 | check.h \ 25 | check_error.h \ 26 | check_impl.h \ 27 | check_list.h \ 28 | check_log.h \ 29 | check_msg.h \ 30 | check_pack.h \ 31 | check_print.h \ 32 | check_str.h 33 | 34 | 35 | EXPORT_SYM = exported.sym 36 | $(EXPORT_SYM): check.h.in 37 | ${SED} -n -e 's/^..*CK_EXPORT[[:space:]][[:space:]]*\([[:alnum:]_][[:alnum:]_]*\)..*$$/\1/p' @top_srcdir@/src/check.h.in > $@ 38 | 39 | libcheck_la_DEPENDENCIES= $(EXPORT_SYM) 40 | libcheck_la_LDFLAGS = -no-undefined -export-symbols $(EXPORT_SYM) 41 | libcheck_la_SOURCES = $(CFILES) $(HFILES) 42 | libcheck_la_LIBADD = @GCOV_LIBS@ @PTHREAD_LIBS@ $(LIBSUBUNIT_LIBS) $(top_builddir)/lib/libcompat.la 43 | 44 | libcheckinternal_la_LDFLAGS = -no-undefined 45 | libcheckinternal_la_SOURCES = $(CFILES) $(HFILES) 46 | libcheckinternal_la_LIBADD = @GCOV_LIBS@ @PTHREAD_LIBS@ $(LIBSUBUNIT_LIBS) $(top_builddir)/lib/libcompat.la 47 | 48 | CLEANFILES = *~ *.gcno $(EXPORT_SYM) 49 | 50 | LCOV_INPUT = $(CFILES:%.c=.libs/%.gcda) 51 | LCOV_OUTPUT = lcov.info 52 | LCOV_HTML = lcov_html 53 | LCOV_LCOV = @LCOV@ 54 | LCOV_GENHTML = @GENHTML@ 55 | 56 | lcov: $(LCOV_HTML) 57 | 58 | $(LCOV_INPUT): libcheck.la libcheckinternal.la 59 | @$(MAKE) -C $(top_builddir)/tests check 60 | 61 | $(LCOV_OUTPUT): $(LCOV_INPUT) 62 | $(LCOV_LCOV) --capture --directory . --base-directory . --output-file $@ 63 | 64 | $(LCOV_HTML): $(LCOV_OUTPUT) 65 | -$(RM) -r $@ 66 | LANG=C $(LCOV_GENHTML) --output-directory $@ --title "Check Code Coverage" --show-details $< 67 | @echo "Point a web browser at $(LCOV_HTML)/index.html to see results." 68 | 69 | clean-local: lcov-clean 70 | 71 | .PHONY: lcov-clean 72 | lcov-clean: 73 | -$(RM) -r $(LCOV_HTML) $(LCOV_OUTPUT) 74 | -------------------------------------------------------------------------------- /tests/check_check_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include "check_check.h" 27 | 28 | int main (void) 29 | { 30 | int number_failed; 31 | SRunner *sr; 32 | 33 | fork_setup(); 34 | setup_fixture(); 35 | setup(); 36 | 37 | sr = srunner_create (make_master_suite()); 38 | srunner_add_suite(sr, make_list_suite()); 39 | srunner_add_suite(sr, make_msg_suite()); 40 | srunner_add_suite(sr, make_log_suite()); 41 | srunner_add_suite(sr, make_log_internal_suite()); 42 | srunner_add_suite(sr, make_limit_suite()); 43 | srunner_add_suite(sr, make_fork_suite()); 44 | srunner_add_suite(sr, make_fixture_suite()); 45 | srunner_add_suite(sr, make_pack_suite()); 46 | srunner_add_suite(sr, make_tag_suite()); 47 | 48 | #if defined(HAVE_FORK) && HAVE_FORK==1 49 | srunner_add_suite(sr, make_exit_suite()); 50 | #endif 51 | 52 | srunner_add_suite(sr, make_selective_suite()); 53 | 54 | printf ("Ran %d tests in subordinate suite\n", sub_ntests); 55 | srunner_run_all (sr, CK_VERBOSE); 56 | cleanup(); 57 | fork_teardown(); 58 | teardown_fixture(); 59 | number_failed = srunner_ntests_failed(sr); 60 | srunner_free(sr); 61 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 62 | } 63 | -------------------------------------------------------------------------------- /src/check_pack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef CHECK_PACK_H 22 | #define CHECK_PACK_H 23 | 24 | 25 | enum ck_msg_type 26 | { 27 | CK_MSG_CTX, 28 | CK_MSG_FAIL, 29 | CK_MSG_LOC, 30 | CK_MSG_DURATION, 31 | CK_MSG_LAST 32 | }; 33 | 34 | typedef struct CtxMsg 35 | { 36 | enum ck_result_ctx ctx; 37 | } CtxMsg; 38 | 39 | typedef struct LocMsg 40 | { 41 | int line; 42 | char *file; 43 | } LocMsg; 44 | 45 | typedef struct FailMsg 46 | { 47 | char *msg; 48 | } FailMsg; 49 | 50 | typedef struct DurationMsg 51 | { 52 | int duration; 53 | } DurationMsg; 54 | 55 | typedef union 56 | { 57 | CtxMsg ctx_msg; 58 | FailMsg fail_msg; 59 | LocMsg loc_msg; 60 | DurationMsg duration_msg; 61 | } CheckMsg; 62 | 63 | typedef struct RcvMsg 64 | { 65 | enum ck_result_ctx lastctx; 66 | enum ck_result_ctx failctx; 67 | char *fixture_file; 68 | int fixture_line; 69 | char *test_file; 70 | int test_line; 71 | char *msg; 72 | int duration; 73 | } RcvMsg; 74 | 75 | void rcvmsg_free(RcvMsg * rmsg); 76 | 77 | 78 | int pack(enum ck_msg_type type, char **buf, CheckMsg * msg); 79 | int upack(char *buf, CheckMsg * msg, enum ck_msg_type *type); 80 | 81 | void ppack(FILE * fdes, enum ck_msg_type type, CheckMsg * msg); 82 | RcvMsg *punpack(FILE * fdes); 83 | 84 | #endif /*CHECK_PACK_H */ 85 | -------------------------------------------------------------------------------- /src/check_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef CHECK_LOG_H 22 | #define CHECK_LOG_H 23 | 24 | void log_srunner_start(SRunner * sr); 25 | void log_srunner_end(SRunner * sr); 26 | void log_suite_start(SRunner * sr, Suite * s); 27 | void log_suite_end(SRunner * sr, Suite * s); 28 | void log_test_end(SRunner * sr, TestResult * tr); 29 | void log_test_start(SRunner * sr, TCase * tc, TF * tfun); 30 | 31 | void stdout_lfun(SRunner * sr, FILE * file, enum print_output, 32 | void *obj, enum cl_event evt); 33 | 34 | void lfile_lfun(SRunner * sr, FILE * file, enum print_output, 35 | void *obj, enum cl_event evt); 36 | 37 | void xml_lfun(SRunner * sr, FILE * file, enum print_output, 38 | void *obj, enum cl_event evt); 39 | 40 | void tap_lfun(SRunner * sr, FILE * file, enum print_output, 41 | void *obj, enum cl_event evt); 42 | 43 | void subunit_lfun(SRunner * sr, FILE * file, enum print_output, 44 | void *obj, enum cl_event evt); 45 | 46 | void srunner_register_lfun(SRunner * sr, FILE * lfile, int close, 47 | LFun lfun, enum print_output); 48 | 49 | FILE *srunner_open_lfile(SRunner * sr); 50 | FILE *srunner_open_xmlfile(SRunner * sr); 51 | FILE *srunner_open_tapfile(SRunner * sr); 52 | void srunner_init_logging(SRunner * sr, enum print_output print_mode); 53 | void srunner_end_logging(SRunner * sr); 54 | 55 | #endif /* CHECK_LOG_H */ 56 | -------------------------------------------------------------------------------- /doc/example/cmake/FindCheck.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find the CHECK libraries 2 | # Once done this will define 3 | # 4 | # CHECK_FOUND - system has check 5 | # CHECK_INCLUDE_DIR - the check include directory 6 | # CHECK_LIBRARIES - check library 7 | # 8 | # This configuration file for finding libcheck is originally from 9 | # the opensync project. The originally was downloaded from here: 10 | # opensync.org/browser/branches/3rd-party-cmake-modules/modules/FindCheck.cmake 11 | # 12 | # Copyright (c) 2007 Daniel Gollub 13 | # Copyright (c) 2007 Bjoern Ricks 14 | # 15 | # Redistribution and use is allowed according to the terms of the New 16 | # BSD license. 17 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 18 | 19 | 20 | INCLUDE( FindPkgConfig ) 21 | 22 | # Take care about check.pc settings 23 | PKG_SEARCH_MODULE( CHECK Check ) 24 | 25 | # Look for CHECK include dir and libraries 26 | IF( NOT CHECK_FOUND ) 27 | IF ( CHECK_INSTALL_DIR ) 28 | MESSAGE ( STATUS "Using override CHECK_INSTALL_DIR to find Check" ) 29 | SET ( CHECK_INCLUDE_DIR "${CHECK_INSTALL_DIR}/include" ) 30 | SET ( CHECK_INCLUDE_DIRS "${CHECK_INCLUDE_DIR}" ) 31 | FIND_LIBRARY( CHECK_LIBRARY NAMES check PATHS "${CHECK_INSTALL_DIR}/lib" ) 32 | FIND_LIBRARY( COMPAT_LIBRARY NAMES compat PATHS "${CHECK_INSTALL_DIR}/lib" ) 33 | SET ( CHECK_LIBRARIES "${CHECK_LIBRARY}" "${COMPAT_LIBRARY}" ) 34 | ELSE ( CHECK_INSTALL_DIR ) 35 | FIND_PATH( CHECK_INCLUDE_DIR check.h ) 36 | FIND_LIBRARY( CHECK_LIBRARIES NAMES check ) 37 | ENDIF ( CHECK_INSTALL_DIR ) 38 | 39 | IF ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) 40 | SET( CHECK_FOUND 1 ) 41 | IF ( NOT Check_FIND_QUIETLY ) 42 | MESSAGE ( STATUS "Found CHECK: ${CHECK_LIBRARIES}" ) 43 | ENDIF ( NOT Check_FIND_QUIETLY ) 44 | ELSE ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) 45 | IF ( Check_FIND_REQUIRED ) 46 | MESSAGE( FATAL_ERROR "Could NOT find CHECK" ) 47 | ELSE ( Check_FIND_REQUIRED ) 48 | IF ( NOT Check_FIND_QUIETLY ) 49 | MESSAGE( STATUS "Could NOT find CHECK" ) 50 | ENDIF ( NOT Check_FIND_QUIETLY ) 51 | ENDIF ( Check_FIND_REQUIRED ) 52 | ENDIF ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) 53 | ENDIF( NOT CHECK_FOUND ) 54 | 55 | # Hide advanced variables from CMake GUIs 56 | MARK_AS_ADVANCED( CHECK_INCLUDE_DIR CHECK_LIBRARIES ) 57 | 58 | -------------------------------------------------------------------------------- /src/check_error.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "check_error.h" 31 | 32 | /** 33 | * Storage for setjmp/longjmp context information used in NOFORK mode 34 | */ 35 | jmp_buf error_jmp_buffer; 36 | 37 | 38 | /* FIXME: including a colon at the end is a bad way to indicate an error */ 39 | void eprintf(const char *fmt, const char *file, int line, ...) 40 | { 41 | va_list args; 42 | 43 | fflush(stderr); 44 | 45 | fprintf(stderr, "%s:%d: ", file, line); 46 | va_start(args, line); 47 | vfprintf(stderr, fmt, args); 48 | va_end(args); 49 | 50 | /*include system error information if format ends in colon */ 51 | if(fmt[0] != '\0' && fmt[strlen(fmt) - 1] == ':') 52 | fprintf(stderr, " %s", strerror(errno)); 53 | fprintf(stderr, "\n"); 54 | 55 | exit(2); 56 | } 57 | 58 | void *emalloc(size_t n) 59 | { 60 | void *p; 61 | 62 | p = malloc(n); 63 | if(p == NULL) 64 | eprintf("malloc of " CK_FMT_ZU " bytes failed:", __FILE__, __LINE__ - 2, n); 65 | return p; 66 | } 67 | 68 | void *erealloc(void *ptr, size_t n) 69 | { 70 | void *p; 71 | 72 | p = realloc(ptr, n); 73 | if(p == NULL) 74 | eprintf("realloc of " CK_FMT_ZU " bytes failed:", __FILE__, __LINE__ - 2, n); 75 | return p; 76 | } 77 | -------------------------------------------------------------------------------- /tests/check_check_exit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "check.h" 29 | #include "check_check.h" 30 | 31 | START_TEST(test_early_exit_normal) 32 | { 33 | exit(0); 34 | ck_abort_msg("Should've exitted..."); 35 | } 36 | END_TEST 37 | 38 | START_TEST(test_early_exit_with_allowed_error) 39 | { 40 | exit(-1); 41 | ck_abort_msg("Should've exitted..."); 42 | } 43 | END_TEST 44 | 45 | START_TEST(loop_early_exit_normal) 46 | { 47 | exit(0); 48 | ck_abort_msg("Should've exitted..."); 49 | } 50 | END_TEST 51 | 52 | START_TEST(loop_early_exit_allowed_exit) 53 | { 54 | exit(-2); 55 | ck_abort_msg("Should've exitted..."); 56 | } 57 | END_TEST 58 | 59 | START_TEST(loop_early_exit_signal_segv) 60 | { 61 | raise (SIGSEGV); 62 | ck_abort_msg("Should've exitted..."); 63 | } 64 | END_TEST 65 | 66 | Suite *make_exit_suite(void) 67 | { 68 | Suite *s; 69 | TCase *tc; 70 | 71 | s = suite_create("Exit"); 72 | tc = tcase_create("Core"); 73 | 74 | suite_add_tcase (s, tc); 75 | tcase_add_test(tc,test_early_exit_normal); 76 | tcase_add_exit_test(tc,test_early_exit_with_allowed_error,-1); 77 | tcase_add_loop_test(tc,loop_early_exit_normal,0,5); 78 | tcase_add_loop_exit_test(tc,loop_early_exit_allowed_exit,-2,0,5); 79 | tcase_add_loop_test_raise_signal(tc, loop_early_exit_signal_segv, SIGSEGV, 0, 5); 80 | return s; 81 | } 82 | -------------------------------------------------------------------------------- /tests/check_stress.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | /* note: this test appears pretty useless, so we aren't including it 24 | in the TESTS variable of Makefile.am */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | Suite *s; 32 | TCase *tc; 33 | SRunner *sr; 34 | 35 | START_TEST(test_pass) 36 | { 37 | ck_assert_msg(1,"Shouldn't see this message"); 38 | } 39 | END_TEST 40 | 41 | START_TEST(test_fail) 42 | { 43 | ck_abort_msg("This test fails"); 44 | } 45 | END_TEST 46 | 47 | 48 | static void run (int num_iters) 49 | { 50 | int i; 51 | s = suite_create ("Stress"); 52 | tc = tcase_create ("Stress"); 53 | sr = srunner_create (s); 54 | suite_add_tcase(s, tc); 55 | 56 | for (i = 0; i < num_iters; i++) { 57 | tcase_add_test (tc, test_pass); 58 | tcase_add_test (tc, test_fail); 59 | } 60 | 61 | srunner_run_all(sr, CK_SILENT); 62 | if (srunner_ntests_failed (sr) != num_iters) { 63 | printf ("Error: expected %d failures, got %d\n", 64 | num_iters, srunner_ntests_failed(sr)); 65 | return; 66 | } 67 | 68 | srunner_free(sr); 69 | } 70 | 71 | 72 | int main(void) 73 | { 74 | int i; 75 | time_t t1; 76 | int iters[] = {1, 100, 1000, 2000, 4000, 8000, 10000, 20000, 40000, -1}; 77 | 78 | for (i = 0; iters[i] != -1; i++) { 79 | t1 = time(NULL); 80 | run(iters[i]); 81 | printf ("%d, %d\n", iters[i], (int) difftime(time(NULL), t1)); 82 | } 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /tests/check_nofork.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | Suite *s; 29 | TCase *tc; 30 | SRunner *sr; 31 | 32 | START_TEST(test_nofork_exit) 33 | { 34 | char* s = NULL; 35 | 36 | ck_assert(NULL != s); 37 | 38 | /* this test should not crash in nofork mode */ 39 | ck_assert_str_eq("test", s); 40 | } 41 | END_TEST 42 | 43 | #if !defined(HAVE_FORK) || HAVE_FORK == 0 44 | START_TEST(test_check_fork) 45 | { 46 | ck_assert_int_eq(-1, check_fork()); 47 | } 48 | END_TEST 49 | #endif 50 | 51 | int main(void) 52 | { 53 | s = suite_create("NoFork"); 54 | tc = tcase_create("Exit"); 55 | sr = srunner_create(s); 56 | 57 | suite_add_tcase(s, tc); 58 | tcase_add_test(tc, test_nofork_exit); 59 | 60 | srunner_set_fork_status(sr, CK_NOFORK); 61 | srunner_run_all(sr, CK_MINIMAL); 62 | srunner_free(sr); 63 | 64 | #if !defined(HAVE_FORK) || HAVE_FORK == 0 65 | s = suite_create("NoForkSupport"); 66 | tc = tcase_create("NoFork"); 67 | sr = srunner_create(s); 68 | 69 | /* The following should not fail, but should be ignored */ 70 | srunner_set_fork_status(sr, CK_FORK); 71 | if(srunner_fork_status(sr) != CK_NOFORK) 72 | { 73 | fprintf(stderr, "Call to srunner_set_fork_status() was not ignored\n"); 74 | exit(1); 75 | } 76 | 77 | suite_add_tcase(s, tc); 78 | tcase_add_test(tc, test_check_fork); 79 | srunner_run_all(sr, CK_MINIMAL); 80 | srunner_free(sr); 81 | #endif 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /checkmk/test/multiple_everything/x_output: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT EDIT THIS FILE. Generated by checkmk. 3 | * Edit the original source file "in" instead. 4 | */ 5 | 6 | #include 7 | 8 | #line 1 "in" 9 | /* Multiple everything... */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | void print_message(const char *msg, size_t msgsz) 16 | { 17 | int nc; 18 | 19 | nc = printf("%s", msg); 20 | fail_unless(nc == msgsz, "failed to print completely: %s", 21 | strerror(errno)); 22 | } 23 | 24 | 25 | 26 | START_TEST(hello_world) 27 | { 28 | #line 21 29 | const char msg[] = "Hello, world!\n"; 30 | print_message(msg, sizeof msg - 1); 31 | 32 | } 33 | END_TEST 34 | 35 | START_TEST(neverending_story) 36 | { 37 | #line 25 38 | const char msg[] = "Bastian Balthazar Bux\n"; 39 | print_message(msg, sizeof msg - 1); 40 | 41 | } 42 | END_TEST 43 | 44 | START_TEST(math_problem) 45 | { 46 | #line 31 47 | fail_unless(1 + 1 == 2, "Something's broken..."); 48 | 49 | } 50 | END_TEST 51 | 52 | 53 | START_TEST(more_math) 54 | { 55 | #line 38 56 | fail_unless(2/2 == 1, "Another weird math result"); 57 | 58 | } 59 | END_TEST 60 | 61 | START_TEST(weave) 62 | { 63 | #line 43 64 | int i; 65 | const char msg[] = "###\n"; 66 | 67 | for (i=0; i != 3; ++i) 68 | print_message(row, sizeof row - 1); 69 | } 70 | END_TEST 71 | 72 | int main(void) 73 | { 74 | Suite *s1 = suite_create("A Suite"); 75 | TCase *tc1_1 = tcase_create("A Test Case"); 76 | TCase *tc1_2 = tcase_create("Another Test Case"); 77 | Suite *s2 = suite_create("Another Suite"); 78 | TCase *tc2_1 = tcase_create("A Test Case for Another Suite"); 79 | TCase *tc2_2 = tcase_create("A Basket Case"); 80 | SRunner *sr = srunner_create(s1); 81 | int nf; 82 | 83 | suite_add_tcase(s1, tc1_1); 84 | tcase_add_test(tc1_1, hello_world); 85 | tcase_add_test(tc1_1, neverending_story); 86 | suite_add_tcase(s1, tc1_2); 87 | tcase_add_test(tc1_2, math_problem); 88 | suite_add_tcase(s2, tc2_1); 89 | tcase_add_test(tc2_1, more_math); 90 | suite_add_tcase(s2, tc2_2); 91 | tcase_add_test(tc2_2, weave); 92 | 93 | srunner_add_suite(sr, s2); 94 | 95 | srunner_run_all(sr, CK_ENV); 96 | nf = srunner_ntests_failed(sr); 97 | srunner_free(sr); 98 | 99 | return nf == 0 ? 0 : 1; 100 | } 101 | -------------------------------------------------------------------------------- /tests/check_set_max_msg_size.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | /** 22 | * The purpose of this test is to reduce the maximal assertion message size 23 | * in order to trigger the "Message string too long" error. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "config.h" 31 | #include "check_check.h" 32 | 33 | START_TEST(test_set_max_msg_size) 34 | { 35 | ck_abort_msg("40 characters of an assertion message..."); 36 | } 37 | END_TEST 38 | 39 | 40 | static Suite *make_set_max_msg_size_suite(void) 41 | { 42 | Suite *s = suite_create("Check Set Max Msg Size"); 43 | 44 | TCase *tc_set_max_msg_size = tcase_create("Test Set Max Msg Size"); 45 | 46 | suite_add_tcase (s, tc_set_max_msg_size); 47 | 48 | tcase_add_test (tc_set_max_msg_size, test_set_max_msg_size); 49 | 50 | return s; 51 | } 52 | 53 | int main (int argc, char *argv[]) 54 | { 55 | SRunner *sr; 56 | 57 | if (argc != 2) { 58 | fprintf(stderr, "usage: %s max-msg-size\n", argv[0]); 59 | return EXIT_FAILURE; 60 | } 61 | 62 | /* 63 | * Run the test suite. This is intended to trigger the "Message is too long" error. 64 | * Actual success/failure is determined by examining the output. 65 | */ 66 | check_set_max_msg_size(32); /* 1st call has no effect since */ 67 | check_set_max_msg_size(strtoul(argv[1], NULL, 10)); /* the 2nd call will override it. */ 68 | sr = srunner_create(make_set_max_msg_size_suite()); 69 | srunner_run_all(sr, CK_NORMAL); 70 | srunner_free(sr); 71 | return EXIT_SUCCESS; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Check: a unit test framework for C 3 | # Copyright (C) 2011 Mateusz Loskot 4 | # Copyright (C) 2020 Mikko Koivunalho 5 | # 6 | # This library is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Lesser General Public 8 | # License as published by the Free Software Foundation; either 9 | # version 2.1 of the License, or (at your option) any later version. 10 | # 11 | # This library is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this library; if not, write to the 18 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | # Boston, MA 02111-1307, USA. 20 | # 21 | 22 | 23 | set(SOURCES libcompat.c) 24 | 25 | set(SOURCES ${SOURCES} fpclassify.c) 26 | 27 | if (NOT HAVE_LIBRT) 28 | set(SOURCES ${SOURCES} clock_gettime.c) 29 | set(SOURCES ${SOURCES} timer_create.c) 30 | set(SOURCES ${SOURCES} timer_delete.c) 31 | set(SOURCES ${SOURCES} timer_settime.c) 32 | endif(NOT HAVE_LIBRT) 33 | 34 | if(NOT HAVE_GETLINE) 35 | set(SOURCES ${SOURCES} getline.c) 36 | endif(NOT HAVE_GETLINE) 37 | 38 | if(NOT HAVE_GETTIMEOFDAY) 39 | set(SOURCES ${SOURCES} gettimeofday.c) 40 | endif(NOT HAVE_GETTIMEOFDAY) 41 | 42 | if(NOT HAVE_DECL_LOCALTIME_R) 43 | set(SOURCES ${SOURCES} localtime_r.c) 44 | endif(NOT HAVE_DECL_LOCALTIME_R) 45 | 46 | if(NOT HAVE_MALLOC) 47 | set(SOURCES ${SOURCES} malloc.c) 48 | endif(NOT HAVE_MALLOC) 49 | 50 | if(NOT HAVE_REALLOC) 51 | set(SOURCES ${SOURCES} realloc.c) 52 | endif(NOT HAVE_REALLOC) 53 | 54 | if(NOT HAVE_SNPRINTF) 55 | set(SOURCES ${SOURCES} snprintf.c) 56 | endif(NOT HAVE_SNPRINTF) 57 | 58 | if(NOT HAVE_DECL_STRDUP AND NOT HAVE__STRDUP) 59 | set(SOURCES ${SOURCES} strdup.c) 60 | endif(NOT HAVE_DECL_STRDUP AND NOT HAVE__STRDUP) 61 | 62 | if(NOT HAVE_DECL_STRSIGNAL) 63 | set(SOURCES ${SOURCES} strsignal.c) 64 | endif(NOT HAVE_DECL_STRSIGNAL) 65 | 66 | if(NOT HAVE_DECL_ALARM) 67 | set(SOURCES ${SOURCES} alarm.c) 68 | endif(NOT HAVE_DECL_ALARM) 69 | 70 | if (NOT HAVE_PTHREAD) 71 | set(SOURCES ${SOURCES} pthread_mutex.c) 72 | endif() 73 | 74 | set(HEADERS libcompat.h) 75 | 76 | add_library(compat STATIC ${SOURCES} ${HEADERS}) 77 | 78 | # vim: shiftwidth=2:softtabstop=2:tabstop=2:expandtab:autoindent 79 | 80 | -------------------------------------------------------------------------------- /tests/check_check_log_internal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | /* Tests for log related stuff in check which need non-exported functions. */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "check_check.h" 33 | 34 | 35 | #if ENABLE_SUBUNIT 36 | START_TEST(test_init_logging_subunit) 37 | { 38 | /* init_logging with CK_SUBUNIT sets stdout 39 | * to a subunit function, not any log. 40 | */ 41 | Log * first_log = NULL; 42 | Suite *s = suite_create("Suite"); 43 | SRunner *sr = srunner_create(s); 44 | srunner_init_logging(sr, CK_SUBUNIT); 45 | check_list_front (sr->loglst); 46 | ck_assert_msg (!check_list_at_end(sr->loglst), "No entries in log list"); 47 | first_log = (Log *)check_list_val(sr->loglst); 48 | ck_assert_msg (first_log != NULL, "log is NULL"); 49 | check_list_advance(sr->loglst); 50 | ck_assert_msg(check_list_at_end(sr->loglst), "More than one entry in log list"); 51 | ck_assert_msg(first_log->lfun == subunit_lfun, 52 | "Log function is not the subunit lfun."); 53 | srunner_end_logging(sr); 54 | srunner_free(sr); 55 | } 56 | END_TEST 57 | #endif 58 | 59 | Suite *make_log_internal_suite(void) 60 | { 61 | Suite *s; 62 | 63 | #if ENABLE_SUBUNIT 64 | TCase *tc_core_subunit; 65 | s = suite_create("Log"); 66 | tc_core_subunit = tcase_create("Core SubUnit"); 67 | suite_add_tcase(s, tc_core_subunit); 68 | tcase_add_test(tc_core_subunit, test_init_logging_subunit); 69 | #else 70 | s = suite_create("Log"); 71 | #endif 72 | 73 | return s; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /xml/check_unittest.xslt: -------------------------------------------------------------------------------- 1 | 3 | 4 | 12 | 13 | 14 | 15 | 16 | Test results 17 |

18 | 19 | 20 | 21 |

Unittests

22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | Test suite 32 | 33 | 34 | Path 35 | Filename 36 | Test ID 37 | Iteration 38 | Duration 39 | Description 40 | Message 41 | 42 | 43 | 44 | 45 | Test ran at: 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |
82 |
83 | 84 | 85 | 86 | 87 | 88 | 89 | Test duration: seconds 90 | 91 | 92 |
93 | 94 | -------------------------------------------------------------------------------- /doc/example/README: -------------------------------------------------------------------------------- 1 | This is the "money example" from the Check tutorial. 2 | 3 | This demonstrates using Check along with one of two build systems: 4 | autotools and CMake. 5 | 6 | ======================== 7 | Autotools: 8 | 9 | You need the following programs installed on your system: 10 | -- Autoconf 2.59 11 | -- Automake 1.9.6 12 | -- Libtool 1.5.22 13 | -- Check 0.9.9 14 | 15 | Somewhat earlier versions of these programs might work. 16 | 17 | Then, do as follows: 18 | 19 | $ autoreconf --install 20 | $ ./configure 21 | $ make 22 | $ make check 23 | 24 | Don't do "make install" unless you want to install the money example. 25 | 26 | money.c and money.h are built as a library. src/main.c:main() is a 27 | client of libmoney.la, just as tests/check_money.c:main() is a client 28 | of libmoney.la 29 | 30 | To use the autotools example in another project, start with the following 31 | files: 32 | 33 | example 34 | |--- configure.ac 35 | |--- Makefile.am 36 | |--- src 37 | | |--- Makefile.am 38 | |--- tests 39 | |--- Makefile.am 40 | 41 | Please send bug reports to check-devel AT lists.sourceforge.net. 42 | 43 | ======================== 44 | CMake: 45 | 46 | You need the following programs installed on your system: 47 | -- CMake 2.8 48 | -- Check 0.9.9 49 | -- (pkg-config 0.26 is optional) 50 | 51 | Somewhat earlier versions of these programs might work. 52 | 53 | NOTE: If pkg-config is not installed on the system, and MSVC is being used, 54 | the install location of Check must be inserted manually into the 55 | tests/CMakeLists.txt file, by setting the variable CHECK_INSTALL_DIR 56 | to the install location. Look at the tests/CMakeLists.txt file for 57 | a commented out example. 58 | 59 | Then, do as follows for a Unix-compatible shell: 60 | 61 | $ cmake . 62 | $ make 63 | $ make test 64 | 65 | or the following for MSVC: 66 | 67 | $ cmake -G "NMake Makefiles" . 68 | $ nmake 69 | $ nmake test 70 | 71 | Don't do "make install" or "nmake install" unless you want to install the money example. 72 | 73 | money.c and money.h are built as a library. src/main.c:main() is a 74 | client of libmoney.la, just as tests/check_money.c:main() is a client 75 | of libmoney.la 76 | 77 | To use the CMake example in another project, start with the following files: 78 | 79 | example 80 | |--- CMakeFiles.txt 81 | |--- cmake 82 | | |--- config.h.in 83 | | |--- FindCheck.cmake 84 | |--- src 85 | | |--- CMakeFiles.txt 86 | |--- tests 87 | |--- CMakeFiles.txt 88 | 89 | Please send bug reports to check-devel AT lists.sourceforge.net. 90 | -------------------------------------------------------------------------------- /doc/example/tests/check_money.6.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include "../src/money.h" 24 | 25 | START_TEST(test_money_create) 26 | { 27 | Money *m; 28 | 29 | m = money_create(5, "USD"); 30 | ck_assert_int_eq(money_amount(m), 5); 31 | ck_assert_str_eq(money_currency(m), "USD"); 32 | money_free(m); 33 | } 34 | END_TEST 35 | 36 | START_TEST(test_money_create_neg) 37 | { 38 | Money *m = money_create(-1, "USD"); 39 | 40 | ck_assert_msg(m == NULL, 41 | "NULL should be returned on attempt to create with " 42 | "a negative amount"); 43 | } 44 | END_TEST 45 | 46 | START_TEST(test_money_create_zero) 47 | { 48 | Money *m = money_create(0, "USD"); 49 | 50 | if (money_amount(m) != 0) 51 | { 52 | ck_abort_msg("Zero is a valid amount of money"); 53 | } 54 | } 55 | END_TEST 56 | 57 | Suite * money_suite(void) 58 | { 59 | Suite *s; 60 | TCase *tc_core; 61 | TCase *tc_limits; 62 | 63 | s = suite_create("Money"); 64 | 65 | /* Core test case */ 66 | tc_core = tcase_create("Core"); 67 | 68 | tcase_add_test(tc_core, test_money_create); 69 | suite_add_tcase(s, tc_core); 70 | 71 | /* Limits test case */ 72 | tc_limits = tcase_create("Limits"); 73 | 74 | tcase_add_test(tc_limits, test_money_create_neg); 75 | tcase_add_test(tc_limits, test_money_create_zero); 76 | suite_add_tcase(s, tc_limits); 77 | 78 | return s; 79 | } 80 | 81 | int main(void) 82 | { 83 | int number_failed; 84 | Suite *s; 85 | SRunner *sr; 86 | 87 | s = money_suite(); 88 | sr = srunner_create(s); 89 | 90 | srunner_run_all(sr, CK_NORMAL); 91 | number_failed = srunner_ntests_failed(sr); 92 | srunner_free(sr); 93 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 94 | } 95 | -------------------------------------------------------------------------------- /tests/check_nofork_teardown.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | #include 24 | #include 25 | #include "check.h" 26 | 27 | /** 28 | * This test checks the result if in CK_NOFORK 29 | * mode a unit test fails but a checked teardown 30 | * runs after the failed test. 31 | * 32 | * Previously, the failure would be reported as: 33 | * 34 | * 0%: Checks: 1, Failures: 1, Errors: 0 35 | * (null):-1:S:tc:will_fail:0: Assertion '0' failed 36 | * 37 | * The reason why this happens is this: the end of the 38 | * message sequence coming down the pipe is CK_MSG_LOC 39 | * (location of failing test), CK_MSG_FAIL, CK_MSG_CTX 40 | * (TEARDOWN). It is this final message that confuses 41 | * things, because rcvmsg_update_ctx() updates 42 | * rmsg->lastctx (which likely is the right thing for it 43 | * to do), which is the ctx value used by the first 'if' 44 | * body in construct_test_result() in its call to 45 | * tr_set_loc_by_ctx(). 46 | * 47 | * After the fix, the test failure should be reported 48 | * as: 49 | * 50 | * 0%: Checks: 1, Failures: 1, Errors: 0 51 | * check_nofork_teardown.c:33:F:tc:will_fail:0: Assertion '0' failed 52 | */ 53 | 54 | START_TEST( will_fail ) 55 | { 56 | ck_assert(0); 57 | } 58 | END_TEST 59 | 60 | static void empty_checked_teardown( void ) 61 | { 62 | } 63 | 64 | int main( void ) 65 | { 66 | SRunner *sr = srunner_create( NULL ); 67 | Suite *s = suite_create( "bug-99" ); 68 | TCase *tc = tcase_create( "tc" ); 69 | int result; 70 | 71 | srunner_add_suite( sr, s ); 72 | srunner_set_fork_status( sr, CK_NOFORK ); 73 | suite_add_tcase( s, tc ); 74 | tcase_add_checked_fixture( tc, NULL, empty_checked_teardown ); 75 | tcase_add_test( tc, will_fail ); 76 | 77 | srunner_run_all( sr, CK_ENV ); 78 | result = srunner_ntests_failed( sr ) ? EXIT_FAILURE : EXIT_SUCCESS; 79 | srunner_free( sr ); 80 | 81 | return result; 82 | } 83 | -------------------------------------------------------------------------------- /checkmk/test/argument_ws/in: -------------------------------------------------------------------------------- 1 | #test-exit(0) test1 2 | ck_assert(0 == 0); 3 | #test-exit (1) test2 4 | ck_assert(1 == 0); 5 | #test-exit ( 0) test3 6 | ck_assert(1 == 0); 7 | #test-exit ( +0 ) test4 8 | ck_assert(1 == 0); 9 | #test-exit ( -1 ) test5 10 | ck_assert(1 == 0); 11 | #test-exit ( - 1 ) test6 12 | ck_assert(1 == 0); 13 | #test-exit (- 0 ) test7 14 | ck_assert(1 == 0); 15 | #test-exit ( + 1 ) test8 16 | ck_assert(1 == 0); 17 | 18 | #test-signal(0) test9 19 | ck_assert(0 == 0); 20 | #test-signal (1) test10 21 | ck_assert(1 == 0); 22 | #test-signal ( 0) test11 23 | ck_assert(1 == 0); 24 | #test-signal ( +0 ) test12 25 | ck_assert(1 == 2); 26 | #test-signal ( -1 ) test13 27 | ck_assert(1 == 0); 28 | #test-signal ( - 1 ) test14 29 | ck_assert(1 == 0); 30 | #test-signal (- 0 ) test15 31 | ck_assert(1 == 0); 32 | #test-signal ( + 1 ) test16 33 | ck_assert(1 == 0); 34 | 35 | #test-loop(0,2) test17 36 | ck_assert(0 == 0); 37 | #test-loop (1 ,0) test18 38 | ck_assert(1 == 0); 39 | #test-loop ( 0 , 1) test19 40 | ck_assert(1 == 1); 41 | #test-loop ( +0 , -2) test20 42 | ck_assert(1 == 0); 43 | #test-loop ( -1 ,+ 3) test21 44 | ck_assert(1 == 0); 45 | #test-loop ( - 1, + 2 ) test22 46 | ck_assert(1 == 0); 47 | #test-loop (- 0 , - 2) test23 48 | ck_assert(1 == 0); 49 | #test-loop ( + 1 , - 3 ) test24 50 | ck_assert(1 == 1); 51 | 52 | #test-loop-exit(1,0,2) test25 53 | ck_assert(0 == 1); 54 | #test-loop-exit ( 2,1 ,0) test26 55 | ck_assert(1 == 0); 56 | #test-loop-exit ( 2 ,0 , 1) test27 57 | ck_assert(1 == 0); 58 | #test-loop-exit ( -1 , +0 , -2) test28 59 | ck_assert(1 == 0); 60 | #test-loop-exit ( - 3 , -1 ,+ 3) test29 61 | ck_assert(1 == 1); 62 | #test-loop-exit ( + 0, - 1, + 2 ) test30 63 | ck_assert(1 == 0); 64 | #test-loop-exit (- 4 ,- 0 , - 2) test31 65 | ck_assert(1 == 0); 66 | #test-loop-exit ( +2 , + 1 , - 3 ) test32 67 | ck_assert(1 == 0); 68 | 69 | #test-loop-signal(1,0,2) test33 70 | ck_assert(0 == 0); 71 | #test-loop-signal ( 2,1 ,0) test34 72 | ck_assert(1 == 0); 73 | #test-loop-signal ( 2 ,0 , 1) test35 74 | ck_assert(1 == 1); 75 | #test-loop-signal ( -1 , +0 , -2) test36 76 | ck_assert(1 == 0); 77 | #test-loop-signal ( - 3 , -1 ,+ 3) test37 78 | ck_assert(1 == 0); 79 | #test-loop-signal ( + 0, - 1, + 2 ) test38 80 | ck_assert(1 == 0); 81 | #test-loop-signal (- 4 ,- 0 , - 2) test39 82 | ck_assert(1 == 0); 83 | #test-loop-signal ( +2 , + 1 , - 3 ) test40 84 | ck_assert(1 == 1); -------------------------------------------------------------------------------- /lib/clock_gettime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "libcompat.h" 22 | 23 | #ifdef __APPLE__ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #endif 30 | 31 | #define NANOSECONDS_PER_SECOND 1000000000 32 | 33 | 34 | 35 | int clock_gettime(clockid_t clk_id CK_ATTRIBUTE_UNUSED, struct timespec *ts) 36 | { 37 | 38 | #ifdef __APPLE__ 39 | /* Some versions of macOS and iOS do not have clock_gettime, use 40 | * mach_absolute_time */ 41 | 42 | static mach_timebase_info_data_t sTimebaseInfo; 43 | uint64_t rawTime; 44 | uint64_t nanos; 45 | 46 | rawTime = mach_absolute_time(); 47 | 48 | /* 49 | * OS X has a function to convert abs time to nano seconds: AbsoluteToNanoseconds 50 | * However, the function may not be available as we may not have 51 | * access to CoreServices. Because of this, we convert the abs time 52 | * to nano seconds manually. 53 | */ 54 | 55 | /* 56 | * First grab the time base used on the system, if this is the first 57 | * time we are being called. We can check if the value is uninitialized, 58 | * as the denominator will be zero. 59 | */ 60 | if(sTimebaseInfo.denom == 0) 61 | { 62 | (void)mach_timebase_info(&sTimebaseInfo); 63 | } 64 | 65 | /* 66 | * Do the conversion. We hope that the multiplication doesn't 67 | * overflow; the price you pay for working in fixed point. 68 | */ 69 | nanos = rawTime * sTimebaseInfo.numer / sTimebaseInfo.denom; 70 | 71 | /* 72 | * Fill in the timespec container 73 | */ 74 | ts->tv_sec = nanos / NANOSECONDS_PER_SECOND; 75 | ts->tv_nsec = nanos - (ts->tv_sec * NANOSECONDS_PER_SECOND); 76 | #else 77 | /* 78 | * As there is no function to fall back onto to get the current 79 | * time, zero out the time so the caller will have a sane value. 80 | */ 81 | ts->tv_sec = 0; 82 | ts->tv_nsec = 0; 83 | #endif 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /doc/example/tests/check_money.7.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include "../src/money.h" 24 | 25 | Money *five_dollars; 26 | 27 | void setup(void) 28 | { 29 | five_dollars = money_create(5, "USD"); 30 | } 31 | 32 | void teardown(void) 33 | { 34 | money_free(five_dollars); 35 | } 36 | 37 | START_TEST(test_money_create) 38 | { 39 | ck_assert_int_eq(money_amount(five_dollars), 5); 40 | ck_assert_str_eq(money_currency(five_dollars), "USD"); 41 | } 42 | END_TEST 43 | 44 | START_TEST(test_money_create_neg) 45 | { 46 | Money *m = money_create(-1, "USD"); 47 | 48 | ck_assert_msg(m == NULL, 49 | "NULL should be returned on attempt to create with " 50 | "a negative amount"); 51 | } 52 | END_TEST 53 | 54 | START_TEST(test_money_create_zero) 55 | { 56 | Money *m = money_create(0, "USD"); 57 | 58 | if (money_amount(m) != 0) 59 | { 60 | ck_abort_msg("Zero is a valid amount of money"); 61 | } 62 | } 63 | END_TEST 64 | 65 | Suite * money_suite(void) 66 | { 67 | Suite *s; 68 | TCase *tc_core; 69 | TCase *tc_limits; 70 | 71 | s = suite_create("Money"); 72 | 73 | /* Core test case */ 74 | tc_core = tcase_create("Core"); 75 | 76 | tcase_add_checked_fixture(tc_core, setup, teardown); 77 | tcase_add_test(tc_core, test_money_create); 78 | suite_add_tcase(s, tc_core); 79 | 80 | /* Limits test case */ 81 | tc_limits = tcase_create("Limits"); 82 | 83 | tcase_add_test(tc_limits, test_money_create_neg); 84 | tcase_add_test(tc_limits, test_money_create_zero); 85 | suite_add_tcase(s, tc_limits); 86 | 87 | return s; 88 | } 89 | 90 | int main(void) 91 | { 92 | int number_failed; 93 | Suite *s; 94 | SRunner *sr; 95 | 96 | s = money_suite(); 97 | sr = srunner_create(s); 98 | 99 | srunner_run_all(sr, CK_NORMAL); 100 | number_failed = srunner_ntests_failed(sr); 101 | srunner_free(sr); 102 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 103 | } 104 | -------------------------------------------------------------------------------- /tests/check_thread_stress.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include "../lib/libcompat.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | Suite *s; 28 | TCase *tc; 29 | SRunner *sr; 30 | 31 | #if defined (HAVE_PTHREAD) || defined (HAVE_FORK) 32 | static void * 33 | sendinfo (void *userdata CK_ATTRIBUTE_UNUSED) 34 | { 35 | unsigned int i; 36 | for (i = 0; i < 999; i++) 37 | { 38 | ck_assert_msg (1, "Shouldn't see this message"); 39 | } 40 | return NULL; 41 | } 42 | #endif /* HAVE_PTHREAD || HAVE_FORK */ 43 | 44 | #ifdef HAVE_PTHREAD 45 | START_TEST (test_stress_threads) 46 | { 47 | pthread_t a, b; 48 | pthread_create (&a, NULL, sendinfo, (void *) 0xa); 49 | pthread_create (&b, NULL, sendinfo, (void *) 0xb); 50 | 51 | pthread_join (a, NULL); 52 | pthread_join (b, NULL); 53 | } 54 | END_TEST 55 | #endif /* HAVE_PTHREAD */ 56 | 57 | #if defined(HAVE_FORK) && HAVE_FORK==1 58 | START_TEST (test_stress_forks) 59 | { 60 | pid_t cpid = fork (); 61 | if (cpid == 0) 62 | { 63 | /* child */ 64 | sendinfo ((void *) 0x1); 65 | exit (EXIT_SUCCESS); 66 | } 67 | else 68 | { 69 | /* parent */ 70 | sendinfo ((void *) 0x2); 71 | } 72 | } 73 | END_TEST 74 | #endif /* HAVE_FORK */ 75 | 76 | int 77 | main (void) 78 | { 79 | int number_failed; 80 | s = suite_create ("ForkThreadStress"); 81 | tc = tcase_create ("ForkThreadStress"); 82 | sr = srunner_create (s); 83 | suite_add_tcase (s, tc); 84 | 85 | #ifdef HAVE_PTHREAD 86 | tcase_add_loop_test (tc, test_stress_threads, 0, 100); 87 | #endif /* HAVE_PTHREAD */ 88 | 89 | #if defined(HAVE_FORK) && HAVE_FORK==1 90 | tcase_add_loop_test (tc, test_stress_forks, 0, 100); 91 | #endif /* HAVE_FORK */ 92 | 93 | srunner_run_all (sr, CK_VERBOSE); 94 | number_failed = srunner_ntests_failed (sr); 95 | srunner_free (sr); 96 | 97 | /* hack to give us XFAIL on non-posix platforms */ 98 | #ifndef HAVE_FORK 99 | number_failed++; 100 | #endif /* !HAVE_FORK */ 101 | 102 | return number_failed ? EXIT_FAILURE : EXIT_SUCCESS; 103 | } 104 | -------------------------------------------------------------------------------- /doc/example/tests/check_money.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "../src/money.h" 26 | 27 | Money *five_dollars; 28 | 29 | void setup(void) 30 | { 31 | five_dollars = money_create(5, "USD"); 32 | } 33 | 34 | void teardown(void) 35 | { 36 | money_free(five_dollars); 37 | } 38 | 39 | START_TEST(test_money_create) 40 | { 41 | ck_assert_int_eq(money_amount(five_dollars), 5); 42 | ck_assert_str_eq(money_currency(five_dollars), "USD"); 43 | } 44 | END_TEST 45 | 46 | START_TEST(test_money_create_neg) 47 | { 48 | Money *m = money_create(-1, "USD"); 49 | 50 | ck_assert_msg(m == NULL, 51 | "NULL should be returned on attempt to create with " 52 | "a negative amount"); 53 | } 54 | END_TEST 55 | 56 | START_TEST(test_money_create_zero) 57 | { 58 | Money *m = money_create(0, "USD"); 59 | 60 | if (money_amount(m) != 0) 61 | { 62 | ck_abort_msg("Zero is a valid amount of money"); 63 | } 64 | } 65 | END_TEST 66 | 67 | Suite * money_suite(void) 68 | { 69 | Suite *s; 70 | TCase *tc_core; 71 | TCase *tc_limits; 72 | 73 | s = suite_create("Money"); 74 | 75 | /* Core test case */ 76 | tc_core = tcase_create("Core"); 77 | 78 | tcase_add_checked_fixture(tc_core, setup, teardown); 79 | tcase_add_test(tc_core, test_money_create); 80 | suite_add_tcase(s, tc_core); 81 | 82 | /* Limits test case */ 83 | tc_limits = tcase_create("Limits"); 84 | 85 | tcase_add_test(tc_limits, test_money_create_neg); 86 | tcase_add_test(tc_limits, test_money_create_zero); 87 | suite_add_tcase(s, tc_limits); 88 | 89 | return s; 90 | } 91 | 92 | int main(void) 93 | { 94 | int number_failed; 95 | Suite *s; 96 | SRunner *sr; 97 | 98 | s = money_suite(); 99 | sr = srunner_create(s); 100 | 101 | srunner_run_all(sr, CK_NORMAL); 102 | number_failed = srunner_ntests_failed(sr); 103 | srunner_free(sr); 104 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 105 | } 106 | -------------------------------------------------------------------------------- /doc/man/man3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Check: a unit test framework for C 3 | # Copyright (C) 2020 Jose Fernando Lopez Fernandez 4 | # 5 | # This library is free software; you can redistribute 6 | # it and/or modify it under the terms of the GNU Lesser 7 | # General Public License as published by the Free Software 8 | # Foundation; either version 2.1 of the License, or (at 9 | # your option) any later version. 10 | # 11 | # This library is distributed in the hope that it will 12 | # be useful, but WITHOUT ANY WARRANTY; without even the 13 | # implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | # PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | # License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General 18 | # Public License along with this library; if not, write 19 | # to the Free Software Foundation, Inc., 51 Franklin St, 20 | # Fifth Floor, Boston, MA 02110-1301 USA 21 | # 22 | 23 | # Define the library's section 3 man pages. 24 | # 25 | SET(MAN3_PAGES 26 | suite_create.3 27 | ) 28 | 29 | # Configure all of the section 3 man pages defined above. 30 | # 31 | # This command will process each of the man pages, setting 32 | # the project version and build date automatically. 33 | # 34 | FOREACH(MAN3_PAGE ${MAN3_PAGES}) 35 | # Configure the man pages. 36 | # 37 | # The configuration of each man page involves only the 38 | # addition of the library version number defined in the 39 | # configure.ac file to each man page. 40 | # 41 | CONFIGURE_FILE(${MAN3_PAGE}.in ${MAN3_PAGE} @ONLY) 42 | 43 | # Install Section 3 Man Pages (Library Calls) 44 | # 45 | # This directive describes what, where, how, and when the 46 | # section 3 man pages should be installed. Specifically, the 47 | # ${CMAKE_INSTALL_MANDIR} variable provided by the 48 | # GNUInstallDirs module specifies the system-specific man 49 | # page installation directory, the permissions set the 50 | # desired installed file(s) permissions, the configurations 51 | # directive specifies that this directive applies for both 52 | # Debug and Release configurations, and the component 53 | # directive allows for the installation of only those items 54 | # belonging to the docs component. 55 | # 56 | # For example, to install only the 'docs' component, the 57 | # following command can be used after generating the project 58 | # build files. 59 | # 60 | # $ cmake --install . --component docs 61 | # 62 | # This example assumes the project build files were 63 | # generated in the current working directory. 64 | # 65 | INSTALL( 66 | FILES 67 | ${CMAKE_CURRENT_BINARY_DIR}/${MAN3_PAGE} 68 | DESTINATION 69 | ${CMAKE_INSTALL_MANDIR}/man3 70 | PERMISSIONS 71 | OWNER_READ 72 | OWNER_WRITE 73 | GROUP_READ 74 | WORLD_READ 75 | CONFIGURATIONS 76 | Debug 77 | Release 78 | COMPONENT 79 | docs 80 | OPTIONAL 81 | ) 82 | ENDFOREACH() 83 | -------------------------------------------------------------------------------- /doc/man/man7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Check: a unit test framework for C 3 | # Copyright (C) 2020 Jose Fernando Lopez Fernandez 4 | # 5 | # This library is free software; you can redistribute 6 | # it and/or modify it under the terms of the GNU Lesser 7 | # General Public License as published by the Free Software 8 | # Foundation; either version 2.1 of the License, or (at 9 | # your option) any later version. 10 | # 11 | # This library is distributed in the hope that it will 12 | # be useful, but WITHOUT ANY WARRANTY; without even the 13 | # implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | # PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | # License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General 18 | # Public License along with this library; if not, write 19 | # to the Free Software Foundation, Inc., 51 Franklin St, 20 | # Fifth Floor, Boston, MA 02110-1301 USA 21 | # 22 | 23 | # Define the library's section 7 man pages. 24 | # 25 | SET(MAN7_PAGES 26 | libcheck.7 27 | ) 28 | 29 | # Configure all of the section 7 man pages defined above. 30 | # 31 | # This command will process each of the man pages, setting 32 | # the project version and build date automatically. 33 | # 34 | FOREACH(MAN7_PAGE ${MAN7_PAGES}) 35 | # Configure the man pages. 36 | # 37 | # The configuration of each man page involves only the 38 | # addition of the library version number defined in the 39 | # configure.ac file to each man page. 40 | # 41 | CONFIGURE_FILE(${MAN7_PAGE}.in ${MAN7_PAGE} @ONLY) 42 | 43 | # Install Section 7 Man Pages (Overview, Conventions, ...) 44 | # 45 | # This directive describes what, where, how, and when the 46 | # section 7 man pages should be installed. Specifically, the 47 | # ${CMAKE_INSTALL_MANDIR} variable provided by the 48 | # GNUInstallDirs module specifies the system-specific man 49 | # page installation directory, the permissions set the 50 | # desired installed file(s) permissions, the configurations 51 | # directive specifies that this directive applies for both 52 | # Debug and Release configurations, and the component 53 | # directive allows for the installation of only those items 54 | # belonging to the docs component. 55 | # 56 | # For example, to install only the 'docs' component, the 57 | # following command can be used after generating the project 58 | # build files. 59 | # 60 | # $ cmake --install . --component docs 61 | # 62 | # This example assumes the project build files were 63 | # generated in the current working directory. 64 | # 65 | INSTALL( 66 | FILES 67 | ${CMAKE_CURRENT_BINARY_DIR}/${MAN7_PAGE} 68 | DESTINATION 69 | ${CMAKE_INSTALL_MANDIR}/man7 70 | PERMISSIONS 71 | OWNER_READ 72 | OWNER_WRITE 73 | GROUP_READ 74 | WORLD_READ 75 | CONFIGURATIONS 76 | Debug 77 | Release 78 | COMPONENT 79 | docs 80 | OPTIONAL 81 | ) 82 | ENDFOREACH() 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Check 4 | 5 | [![Linux Build Status](https://github.com/libcheck/check/workflows/linux/badge.svg)](https://github.com/libcheck/check/actions?query=workflow%3Alinux) 6 | [![OSX Build Status](https://github.com/libcheck/check/workflows/osx/badge.svg)](https://github.com/libcheck/check/actions?query=workflow%3Aosx) 7 | [![Windows Build Status](https://github.com/libcheck/check/workflows/windows/badge.svg)](https://github.com/libcheck/check/actions?query=workflow%3Awindows) 8 | 9 |
10 | 11 | ## Table of Contents 12 | * [About](#about) 13 | * [Installing](#installing) 14 | * [Linking](#linking) 15 | * [Packaging](#packaging) 16 | 17 | ## About 18 | 19 | Check is a unit testing framework for C. It features a simple interface 20 | for defining unit tests, putting little in the way of the 21 | developer. Tests are run in a separate address space, so Check can 22 | catch both assertion failures and code errors that cause segmentation 23 | faults or other signals. The output from unit tests can be used within 24 | source code editors and IDEs. 25 | 26 | See https://libcheck.github.io/check for more information, including a 27 | tutorial. The tutorial is also available as `info check`. 28 | 29 | ## Installing 30 | 31 | Check has the following dependencies: 32 | 33 | * [automake](https://www.gnu.org/software/automake/)-1.9.6 (1.11.3 on OS X if you are using /usr/bin/ar) 34 | * [autoconf](https://www.gnu.org/software/autoconf/)-2.59 35 | * [libtool](https://www.gnu.org/software/libtool/)-1.5.22 36 | * [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/)-0.20 37 | * [texinfo](https://www.gnu.org/software/texinfo/)-4.7 (for documentation) 38 | * tetex-bin (or any texinfo-compatible TeX installation, for documentation) 39 | * POSIX [sed](https://en.wikipedia.org/wiki/Sed) 40 | 41 | The versions specified may be higher than those actually needed. 42 | 43 | ### autoconf 44 | 45 | $ autoreconf --install 46 | $ ./configure 47 | $ make 48 | $ make check 49 | $ make install 50 | $ sudo ldconfig 51 | 52 | in this directory to set everything up. autoreconf calls all of the 53 | necessary tools for you, like autoconf, automake, autoheader, etc. If 54 | you ever change something during development, run autoreconf again 55 | (without --install), and it will perform the minimum set of actions 56 | necessary. Check is installed to `/usr/local/lib` by default. ldconfig rebuilds 57 | the linker cache so that newly installed library file is included in the cache. 58 | 59 | ### cmake 60 | 61 | $ mkdir build 62 | $ cd build 63 | $ cmake ../ 64 | $ make 65 | $ CTEST_OUTPUT_ON_FAILURE=1 make test 66 | 67 | ## Linking 68 | 69 | Check uses variadic macros in check.h, and the strict C90 options for 70 | gcc will complain about this. In gcc 4.0 and above you can turn this 71 | off explicitly with `-Wno-variadic-macros`. In a future API it would be 72 | nice to eliminate these macros. 73 | 74 | ## Packaging 75 | 76 | Check is available packaged for the following operating systems: 77 | 78 |
79 | 80 | [![Packaging status](https://repology.org/badge/vertical-allrepos/check.svg)](https://repology.org/project/check/versions) 81 | 82 |
83 | -------------------------------------------------------------------------------- /tests/check_mem_leaks.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | /** 22 | * The purpose of this test is to be used by valgrind to check for 23 | * memory leaks. Each public API that check exports is used at 24 | * least once. Tests which use non-public API, or leak intentionally, 25 | * are not included here. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "config.h" 33 | #include "check_check.h" 34 | 35 | int main (void) 36 | { 37 | int number_failed; 38 | SRunner *sr; 39 | 40 | /* 41 | * First, the sub suite is run. This suite has failures which 42 | * are intentional, as the output of the failures is checked 43 | * in check_check_master.c. However, here we do not check if 44 | * the failures are expected. Instead, we just want to run 45 | * them and see if they leak. Because of this, the result 46 | * of the suite is not checked. 47 | */ 48 | sr = srunner_create(make_sub_suite()); 49 | /* 50 | * Enable all logging types, just in case one of them 51 | * leaks memory. 52 | */ 53 | srunner_set_log (sr, "test_mem_leak.log"); 54 | srunner_set_xml (sr, "test_mem_leak.xml"); 55 | srunner_set_tap (sr, "test_mem_leak.tap"); 56 | srunner_run_all(sr, CK_NORMAL); 57 | srunner_free(sr); 58 | 59 | /* Now, the other suite is run. These are all expected to pass. */ 60 | 61 | /* The following setup is necessary for the fork suite */ 62 | fork_setup(); 63 | 64 | sr = srunner_create (make_log_suite()); 65 | srunner_add_suite(sr, make_fork_suite()); 66 | 67 | #if defined(HAVE_FORK) && HAVE_FORK==1 68 | srunner_add_suite(sr, make_exit_suite()); 69 | #endif 70 | srunner_add_suite(sr, make_tag_suite()); 71 | srunner_add_suite(sr, make_selective_suite()); 72 | 73 | /* 74 | * Enable all logging types, just in case one of them 75 | * leaks memory. 76 | */ 77 | srunner_set_log (sr, "test_mem_leak.log"); 78 | srunner_set_xml (sr, "test_mem_leak.xml"); 79 | srunner_set_tap (sr, "test_mem_leak.tap"); 80 | 81 | srunner_run_all(sr, CK_NORMAL); 82 | 83 | /* Cleanup from the fork suite setup */ 84 | fork_teardown(); 85 | 86 | number_failed = srunner_ntests_failed(sr); 87 | srunner_free(sr); 88 | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 89 | } 90 | 91 | -------------------------------------------------------------------------------- /m4/ax_c_check_flag.m4: -------------------------------------------------------------------------------- 1 | ##### http://autoconf-archive.cryp.to/ax_c_check_flag.html 2 | # 3 | # SYNOPSIS 4 | # 5 | # AX_C_CHECK_FLAG(FLAG-TO-CHECK,[PROLOGUE],[BODY],[ACTION-IF-SUCCESS],[ACTION-IF-FAILURE]) 6 | # 7 | # DESCRIPTION 8 | # 9 | # This macro tests if the C compiler supports the flag FLAG-TO-CHECK. 10 | # If successfull execute ACTION-IF-SUCCESS otherwise 11 | # ACTION-IF-FAILURE. PROLOGUE and BODY are optional and should be 12 | # used as in AC_LANG_PROGRAM macro. 13 | # 14 | # This code is inspired from KDE_CHECK_COMPILER_FLAG macro. Thanks to 15 | # Bogdan Drozdowski for testing and bug fixes. 16 | # 17 | # LAST MODIFICATION 18 | # 19 | # 2007-11-26 20 | # 21 | # COPYLEFT 22 | # 23 | # Copyright (c) 2007 Francesco Salvestrini 24 | # 25 | # This program is free software; you can redistribute it and/or 26 | # modify it under the terms of the GNU General Public License as 27 | # published by the Free Software Foundation; either version 2 of the 28 | # License, or (at your option) any later version. 29 | # 30 | # This program is distributed in the hope that it will be useful, but 31 | # WITHOUT ANY WARRANTY; without even the implied warranty of 32 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 33 | # General Public License for more details. 34 | # 35 | # You should have received a copy of the GNU General Public License 36 | # along with this program; if not, write to the Free Software 37 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 38 | # 02111-1307, USA. 39 | # 40 | # As a special exception, the respective Autoconf Macro's copyright 41 | # owner gives unlimited permission to copy, distribute and modify the 42 | # configure scripts that are the output of Autoconf when processing 43 | # the Macro. You need not follow the terms of the GNU General Public 44 | # License when using or distributing such scripts, even though 45 | # portions of the text of the Macro appear in them. The GNU General 46 | # Public License (GPL) does govern all other use of the material that 47 | # constitutes the Autoconf Macro. 48 | # 49 | # This special exception to the GPL applies to versions of the 50 | # Autoconf Macro released by the Autoconf Macro Archive. When you 51 | # make and distribute a modified version of the Autoconf Macro, you 52 | # may extend this special exception to the GPL to apply to your 53 | # modified version as well. 54 | 55 | AC_DEFUN([AX_C_CHECK_FLAG],[ 56 | AC_PREREQ([2.61]) 57 | AC_REQUIRE([AC_PROG_CC]) 58 | AC_REQUIRE([AC_PROG_SED]) 59 | 60 | flag=`echo "$1" | $SED 'y% .=/+-(){}<>:*,%_______________%'` 61 | 62 | AC_CACHE_CHECK([whether the C compiler accepts the $1 flag], 63 | [ax_cv_c_check_flag_$flag],[ 64 | 65 | AC_LANG_PUSH([C]) 66 | 67 | save_CFLAGS="$CFLAGS" 68 | CFLAGS="$CFLAGS $1" 69 | AC_COMPILE_IFELSE([ 70 | AC_LANG_PROGRAM([$2],[$3]) 71 | ],[ 72 | eval "ax_cv_c_check_flag_$flag=yes" 73 | ],[ 74 | eval "ax_cv_c_check_flag_$flag=no" 75 | ]) 76 | 77 | CFLAGS="$save_CFLAGS" 78 | 79 | AC_LANG_POP 80 | 81 | ]) 82 | 83 | AS_IF([eval "test \"`echo '$ax_cv_c_check_flag_'$flag`\" = yes"],[ 84 | : 85 | $4 86 | ],[ 87 | : 88 | $5 89 | ]) 90 | ]) 91 | -------------------------------------------------------------------------------- /m4/librt_timers.m4: -------------------------------------------------------------------------------- 1 | # HW_HEADER_TIME_H 2 | # ------------------ 3 | # Define HAVE_TIME_H to 1 if is available. 4 | AC_DEFUN([HW_HEADER_TIME_H], 5 | [ 6 | AC_PREREQ([2.60])dnl Older releases should work if AC_CHECK_HEADERS is used. 7 | AC_CHECK_HEADERS_ONCE([time.h]) 8 | ])# HW_HEADER_TIME_H 9 | 10 | # HW_LIBRT_TIMERS 11 | # ----------------- 12 | # Set $hw_cv_librt_timers and $hw_cv_librt_timers_posix to "yes" or "no", 13 | # respectively. If the timer_create() function is available and 14 | # POSIX compliant, then the system's timer_create(), timer_settime(), 15 | # and timer_delete() functions are used. Otherwise, make sure 16 | # the replacement functions will be built. 17 | # 18 | # In the case where we are cross compiling, the POSIX detection of 19 | # the timer_create() function is skipped, and instead the usual check 20 | # for the existence of all the timer_* functions is done using 21 | # AC_REPLACE_FUNCS. 22 | # 23 | # If enable_timer_replacement=true, the replacements is forced to be built. 24 | AC_DEFUN([HW_LIBRT_TIMERS], 25 | [ 26 | AC_PREREQ([2.60])dnl 2.59 should work if some AC_TYPE_* macros are replaced. 27 | AC_REQUIRE([HW_HEADER_TIME_H])dnl Our check evaluates HAVE_TIME_H. 28 | 29 | if test "xtrue" != x"$enable_timer_replacement"; then 30 | AC_CHECK_FUNC([timer_create], 31 | [hw_cv_librt_timers=yes], 32 | [hw_cv_librt_timers=no]) 33 | AS_IF([test "$hw_cv_librt_timers" = yes], 34 | [AC_CACHE_CHECK([if timer_create is supported on the system], 35 | [hw_cv_librt_timers_posix], 36 | [AC_RUN_IFELSE( 37 | [AC_LANG_PROGRAM( 38 | [[#if HAVE_TIME_H 39 | #include 40 | #endif 41 | #include 42 | static int test_timer_create() 43 | { 44 | timer_t timerid; 45 | if(timer_create(CLOCK_REALTIME, NULL, &timerid) != 0) 46 | { 47 | /* 48 | On this system, although the function is available, 49 | no meaningful implementation is provided. 50 | */ 51 | if(errno == ENOSYS) 52 | { 53 | return 1; 54 | } 55 | } 56 | return 0; 57 | }]], 58 | [[return test_timer_create();]])], 59 | [hw_cv_librt_timers_posix=yes], 60 | [hw_cv_librt_timers_posix=no], 61 | [hw_cv_librt_timers_posix=autodetect])])], 62 | [hw_cv_librt_timers_posix=no]) 63 | else 64 | hw_cv_librt_timers_posix=no 65 | fi 66 | 67 | # If the system does not have a POSIX timer_create(), then use 68 | # Check's reimplementation of the timer_* calls 69 | AS_IF([test "$hw_cv_librt_timers_posix" = no], 70 | [_HW_LIBRT_TIMERS_REPLACE]) 71 | 72 | # If we are cross compiling, do the normal check for the 73 | # timer_* calls. 74 | AS_IF([test "$hw_cv_librt_timers_posix" = autodetect], 75 | [AC_REPLACE_FUNCS([timer_create timer_settime timer_delete]) 76 | AC_CHECK_DECLS([timer_create, timer_settime, timer_delete])]) 77 | ])# HW_LIBRT_TIMERS 78 | 79 | # _HW_LIBRT_TIMERS_REPLACE 80 | # ------------------------ 81 | # Arrange for building timer_create.c, timer_settime.c, and 82 | # timer_delete.c. 83 | AC_DEFUN([_HW_LIBRT_TIMERS_REPLACE], 84 | [ 85 | AS_IF([test "x$_hw_cv_librt_timers_replace_done" != xyes], 86 | [AC_LIBOBJ([timer_create]) 87 | AC_LIBOBJ([timer_settime]) 88 | AC_LIBOBJ([timer_delete]) 89 | _hw_cv_librt_timers_replace_done=yes]) 90 | ])# _HW_LIBRT_TIMERS_REPLACE 91 | -------------------------------------------------------------------------------- /tests/check_check.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Check: a unit test framework for C 3 | * Copyright (C) 2001, 2002 Arien Malec 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 | * MA 02110-1301, USA. 19 | */ 20 | 21 | #ifndef CHECK_CHECK_H 22 | #define CHECK_CHECK_H 23 | 24 | #ifndef TIMEOUT_TESTS_ENABLED 25 | #define TIMEOUT_TESTS_ENABLED 1 26 | #endif 27 | 28 | /* 29 | * Certain unit tests are known to leak memory. This 30 | * #define will prevent those unit tests from being built 31 | * if the program is to be used against valgrind. 32 | */ 33 | #ifndef MEMORY_LEAKING_TESTS_ENABLED 34 | #define MEMORY_LEAKING_TESTS_ENABLED 1 35 | #endif 36 | 37 | extern int sub_ntests; 38 | 39 | void fork_setup (void); 40 | void fork_teardown (void); 41 | void setup_fixture(void); 42 | void teardown_fixture (void); 43 | void setup (void); 44 | void cleanup (void); 45 | Suite *make_sub_suite(void); 46 | Suite *make_sub2_suite(void); 47 | Suite *make_master_suite(void); 48 | Suite *make_list_suite(void); 49 | Suite *make_msg_suite(void); 50 | Suite *make_log_suite(void); 51 | Suite *make_log_internal_suite(void); 52 | Suite *make_limit_suite(void); 53 | Suite *make_fork_suite(void); 54 | Suite *make_fixture_suite(void); 55 | Suite *make_pack_suite(void); 56 | Suite *make_exit_suite(void); 57 | Suite *make_selective_suite(void); 58 | Suite *make_tag_suite(void); 59 | 60 | extern int master_tests_lineno[]; 61 | void init_master_tests_lineno(int num_master_tests); 62 | 63 | /** 64 | * Record a test name. 65 | * 66 | * This is used to record the test names of each test in 67 | * check_check_sub.c. This allows the test name to be written 68 | * in the master_tests table in check_check_master.c and have 69 | * it verified at test time. With this data, one can easily 70 | * determine the name of a failed test. 71 | */ 72 | void record_test_name(const char* test_name); 73 | 74 | /** 75 | * Retrieve the next recorded test which was run, or 76 | * NULL if no further tests are recorded. 77 | */ 78 | char* get_next_test_name(FILE * file); 79 | 80 | /** 81 | * Record a line number for a test which is to fail. 82 | * 83 | * This is used to record the failure line numbers for 84 | * all tests in check_check_sub.c. Simply make this 85 | * call right before an assert to record the proper 86 | * line number. The line number is adjusted +1 internally, 87 | * to account for making this call before the failure. 88 | */ 89 | void record_failure_line_num(const int line); 90 | 91 | /** 92 | * Once the failure file numbers have been recorded 93 | * to file and the file has been rewind(), this 94 | * call will extract the next line number from the 95 | * file. 96 | * 97 | * If there are no more lines to read, -1 is returned. 98 | */ 99 | long get_next_failure_line_num(FILE * file); 100 | 101 | #endif /* CHECK_CHECK_H */ 102 | --------------------------------------------------------------------------------