--- /dev/null
+# Doxygen configuration generated by Doxywizard version 0.1
+#---------------------------------------------------------------------------
+# General configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME = Check
+PROJECT_NUMBER = 0.6.1
+OUTPUT_DIRECTORY = /home/amalec/check/doc/
+OUTPUT_LANGUAGE = English
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = NO
+EXTRACT_STATIC = YES
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ALWAYS_DETAILED_SEC = NO
+FULL_PATH_NAMES = NO
+STRIP_FROM_PATH =
+INTERNAL_DOCS = NO
+CLASS_DIAGRAMS = YES
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+VERBATIM_HEADERS = YES
+SHOW_INCLUDE_FILES = YES
+JAVADOC_AUTOBRIEF = NO
+INHERIT_DOCS = YES
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+DISTRIBUTE_GROUP_DOC = NO
+TAB_SIZE = 8
+ENABLED_SECTIONS =
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+ALIASES =
+MAX_INITIALIZER_LINES = 30
+OPTIMIZE_OUTPUT_FOR_C = NO
+SHOW_USED_FILES = YES
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = /home/amalec/check/src/check.h
+FILE_PATTERNS =
+RECURSIVE = NO
+EXCLUDE =
+EXCLUDE_PATTERNS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_SOURCE_FILES = NO
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_ALIGN_MEMBERS = YES
+GENERATE_HTMLHELP = NO
+GENERATE_CHI = NO
+BINARY_TOC = NO
+TOC_EXPAND = NO
+DISABLE_INDEX = NO
+ENUM_VALUES_PER_LINE = 4
+GENERATE_TREEVIEW = NO
+TREEVIEW_WIDTH = 250
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = YES
+LATEX_OUTPUT = latex
+COMPACT_LATEX = NO
+PAPER_TYPE = letter
+EXTRA_PACKAGES =
+LATEX_HEADER =
+PDF_HYPERLINKS = NO
+USE_PDFLATEX = NO
+LATEX_BATCHMODE = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = YES
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = YES
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+#---------------------------------------------------------------------------
+# Configuration::addtions related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+HAVE_DOT = NO
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+GRAPHICAL_HIERARCHY = YES
+DOT_PATH =
+MAX_DOT_GRAPH_WIDTH = 1024
+MAX_DOT_GRAPH_HEIGHT = 1024
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+#---------------------------------------------------------------------------
+# Configuration::addtions related to the search engine
+#---------------------------------------------------------------------------
+SEARCHENGINE = NO
+CGI_NAME = search.cgi
+CGI_URL =
+DOC_URL =
+DOC_ABSPATH =
+BIN_ABSPATH = /usr/local/bin/
+EXT_DOC_PATHS =
\begin_inset Quotes erd
\end_inset
- with unit test writing proceeding coding.
+ with unit test writing preceding coding.
This constantly gives us insights into module usage, and also makes sure
we are constantly thinking about how to test our code.
\layout Subsection
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/* Magic values */
+/*! Magic values */
enum {
- CMAXMSG = 100, /* maximum length of a message, including terminating nul */
+ CMAXMSG = 100, /*! maximum length of a message, including terminating nul */
};
/* Core suite/test case types and functions */
-/* opaque type for a test suite */
+/*! opaque type for a test suite */
typedef struct Suite Suite;
-/* opaque type for a test case */
-/* For the moment, test cases can only be run through a suite */
+/*! opaque type for a test case
+ For the moment, test cases can only be run through a suite */
typedef struct TCase TCase;
/* type for a test function */
typedef void (*TFun) (int);
-/* type for a setup/teardown function */
+/*! type for a setup/teardown function */
typedef void (*SFun) (void);
-/* Create a test suite */
+/*! Create a test suite */
Suite *suite_create (char *name);
-/* Free a test suite */
-/* (For the moment, this also frees all contained test cases) */
+/*! Free a test suite
+ (For the moment, this also frees all contained test cases) */
void suite_free (Suite *s);
-/* Create a test case */
+/*! Create a test case */
TCase *tcase_create (char *name);
-/* Free a test case */
-/* (Note that as it stands, one will normally free the contaning suite) */
+/*! Free a test case
+ (Note that as it stands, one will normally free the contaning suite) */
void tcase_free (TCase *tc);
-/* Add a test case to a suite */
+/*! Add a test case to a suite */
void suite_add_tcase (Suite *s, TCase *tc);
-/* Add a test function to a test case */
+/*! Add a test function to a test case
+ (macro version) */
#define tcase_add_test(tc,tf) _tcase_add_test(tc,tf,"" # tf "")
+/*! Add a test function to a test case
+ (function version -- use this when the macro won't work */
void _tcase_add_test (TCase *tc, TFun tf, char *fname);
-/* Add fixture setup/teardown functions to a test case
+/*! Add fixture setup/teardown functions to a test case
Note that setup/teardown functions are not run in a separate
address space, like test functions, and so must not
exit or signal (e.g., segfault) */
/* Internal functions to mark the start and end of a test function */
void tcase_fn_start (int msqid, char *fname, char *file, int line);
-/* Start a unit test with START_TEST(unit_name), end with END_TEST */
-/* One must use braces within a START_/END_ pair to declare new variables */
+/*! Start a unit test with START_TEST(unit_name), end with END_TEST
+ One must use braces within a START_/END_ pair to declare new variables */
#define START_TEST(__testname)\
void __testname (int __msqid)\
{\
#define END_TEST }
-/* Fail the test case unless result is true */
+/*! Fail the test case unless result is true */
#define fail_unless(result,msg) _fail_unless(__msqid,result,__FILE__,__LINE__,msg)
void _fail_unless (int msqid, int result, char *file, int line, char *msg);
-/* Always fail */
+/*! Always fail */
#define fail(msg) _fail_unless(__msqid,0,__FILE__,__LINE__,msg)
-/* Mark the last point reached in a unit test
+/*! Mark the last point reached in a unit test
(useful for tracking down where a segfault, etc. occurs */
#define mark_point() _mark_point(__msqid,__FILE__,__LINE__)
void _mark_point (int msqid, char *file, int line);
/* Suite running functions */
-
+/*! Result of a test */
enum test_result {
- CRPASS,
- CRFAILURE,
- CRERROR
+ CRPASS, /*!< Test passed*/
+ CRFAILURE, /*!< Test completed but failed */
+ CRERROR /*!< Test failed to complete (signal or non-zero early exit) */
};
+/*! Specifies the verbosity of srunner printing */
enum print_verbosity {
- CRSILENT,
- CRMINIMAL,
- CRNORMAL,
- CRVERBOSE,
+ CRSILENT, /*!< No output */
+ CRMINIMAL, /*!< Only summary output */
+ CRNORMAL, /*!< All failed tests */
+ CRVERBOSE, /*!< All tests */
CRLAST
};
-/* Holds state for a running of a test suite */
+/*! Holds state for a running of a test suite */
typedef struct SRunner SRunner;
-/* Opaque type for a test failure */
+/*! Opaque type for a test failure */
typedef struct TestResult TestResult;
/* accessors for tr fields */
-/* Type of result */
+/*! Type of result */
int tr_rtype (TestResult *tr);
-/* Failure message */
+/*! Failure message */
char *tr_msg (TestResult *tr);
-/* Line number at which failure occured */
+/*! Line number at which failure occured */
int tr_lno (TestResult *tr);
-/* File name at which failure occured */
+/*! File name at which failure occured */
char *tr_lfile (TestResult *tr);
-/* Test case in which unit test was run */
+/*! Test case in which unit test was run */
char *tr_tcname (TestResult *tr);
+/*! Creates an SRunner for the given suite */
SRunner *srunner_create (Suite *s);
+/*! Frees an SRunner */
void srunner_free (SRunner *sr);
/* Test running */
+/*! Runs an SRunner, printing results as specified
+ (see enum print_verbosity)*/
void srunner_run_all (SRunner *sr, int print_mode);
/* Next functions are valid only after the suite has been
completely run, of course */
-/* Number of failures in a run suite */
-/* Now includes failures + errors
- TODO: work on terminology */
-int srunner_nfailures (SRunner *sr);
-/* Return an array of failures
+/*! Number of failed tests in a run suite
+ Includes failures + errors */
+int srunner_nfailed_tests (SRunner *sr);
+
+/*! Total number of tests run in a run suite */
+int srunner_ntests_run (SRunner *sr);
+
+/*! Return an array of failures
Number of failures is equal to srunner_nfailures
Memory is alloc'ed and must be freed, but individual
TestResults must not */
/* Printing */
-/* Print a summary report of %passed, #checks, failures */
-void print_summary_report (SRunner *sr);
+/*! Print a summary report of %passed, #checks, failures */
+void srunner_print_summary (SRunner *sr);
-/* Print a detailed report of test results
- print_mode works like with srunner_run_all*/
-void print_results (SRunner *sr, int print_mode);
+/*! Print a detailed report of test results
+ See enum print_verbosity for explaination of print_mode*/
+void srunner_print_results (SRunner *sr, int print_mode);
#endif /* CHECK_H */
static void srunner_run_tcase (SRunner *sr, TCase *tc);
static void srunner_add_failure (SRunner *sr, TestResult *tf);
static TestResult *tfun_run (int msqid, char *tcname, TF *tf);
+static TestResult *receive_result_info (int msqid, int status, char *tcname);
+static void receive_last_loc_info (int msqid, TestResult *tr);
+static void receive_failure_info (int msqid, int status, TestResult *tr);
static List *srunner_resultlst (SRunner *sr);
static void tr_print (TestResult *tr);
srunner_run_tcase (sr, tc);
}
if (print_mode >= CRMINIMAL)
- print_summary_report (sr);
- print_results (sr, print_mode);
+ srunner_print_summary (sr);
+ srunner_print_results (sr, print_mode);
}
static void srunner_add_failure (SRunner *sr, TestResult *tr)
tc->teardown();
}
-static TestResult *receive_failure_info (int msqid, int status, char *tcname)
+static void receive_last_loc_info (int msqid, TestResult *tr)
{
LastLocMsg *lmsg;
- FailureMsg *fmsg;
- TestResult *tr = emalloc (sizeof(TestResult));
-
lmsg = receive_last_loc_msg (msqid);
tr->file = last_loc_file (lmsg);
tr->line = last_loc_line (lmsg);
free (lmsg);
- tr->tcname = tcname;
+}
+
+static void receive_failure_info (int msqid, int status, TestResult *tr)
+{
+ FailureMsg *fmsg;
if (WIFSIGNALED(status)) {
tr->rtype = CRERROR;
tr->msg = signal_msg (WTERMSIG(status));
- return tr;
+ return;
}
if (WIFEXITED(status)) {
} else {
eprintf ("Bad status from wait() call\n");
}
+}
+
+static TestResult *receive_result_info (int msqid, int status, char *tcname)
+{
+ TestResult *tr = emalloc (sizeof(TestResult));
+
+ tr->tcname = tcname;
+ receive_last_loc_info (msqid, tr);
+ receive_failure_info (msqid, status, tr);
return tr;
}
eprintf ("Unable to fork:");
if (pid == 0) {
tfun->fn(msqid);
- exit(0);
+ _exit(EXIT_SUCCESS);
}
(void) wait(&status);
- return receive_failure_info(msqid, status, tcname);
+ return receive_result_info(msqid, status, tcname);
}
/* Printing */
-void print_summary_report (SRunner *sr)
+void srunner_print_summary (SRunner *sr)
{
TestStats *ts = sr->stats;
printf ("%d%%: Checks: %d, Failures: %d, Errors: %d\n",
return;
}
-void print_results (SRunner *sr, int print_mode)
+void srunner_print_results (SRunner *sr, int print_mode)
{
List *resultlst;
if (print_mode < CRNORMAL)
return;
}
-int srunner_nfailures (SRunner *sr)
+int srunner_nfailed_tests (SRunner *sr)
{
return sr->stats->n_failed + sr->stats->n_errors;
}
+int srunner_ntests_run (SRunner *sr)
+{
+ return sr->stats->n_checked;
+}
+
TestResult **srunner_failures (SRunner *sr)
{
int i = 0;
TestResult **trarray;
List *rlst;
- trarray = malloc (sizeof(trarray[0]) * srunner_nfailures(sr));
+ trarray = malloc (sizeof(trarray[0]) * srunner_nfailed_tests(sr));
rlst = srunner_resultlst (sr);
for (list_front(rlst); !list_at_end(rlst); list_advance(rlst)) {
static int non_pass (int val)
{
- return val == CRFAILURE || CRERROR;
+ return val == CRFAILURE || val == CRERROR;
}
EXTRA_DIST=test_output.sh
check_check_SOURCES= \
- check_check.c
+ check_check.h check_check_sub.c check_check_master.c check_check_main.c
check_list_SOURCES=\
check_list.c
noinst_PROGRAMS = check_check check_list check_stress check_check_msg ex_output
EXTRA_DIST = test_output.sh
-check_check_SOURCES = check_check.c
+check_check_SOURCES = check_check.h check_check_sub.c check_check_master.c check_check_main.c
check_list_SOURCES = check_list.c
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
-check_check_OBJECTS = check_check.o
+check_check_OBJECTS = check_check_sub.o check_check_master.o \
+check_check_main.o
check_check_LDADD = $(LDADD)
check_check_DEPENDENCIES = ../src/libcheck.a
check_check_LDFLAGS =
TAR = gtar
GZIP_ENV = --best
-DEP_FILES = .deps/check_check.P .deps/check_check_msg.P \
-.deps/check_list.P .deps/check_stress.P .deps/ex_output.P
+DEP_FILES = .deps/check_check_main.P .deps/check_check_master.P \
+.deps/check_check_msg.P .deps/check_check_sub.P .deps/check_list.P \
+.deps/check_stress.P .deps/ex_output.P
SOURCES = $(check_check_SOURCES) $(check_list_SOURCES) $(check_stress_SOURCES) $(check_check_msg_SOURCES) $(ex_output_SOURCES)
OBJECTS = $(check_check_OBJECTS) $(check_list_OBJECTS) $(check_stress_OBJECTS) $(check_check_msg_OBJECTS) $(ex_output_OBJECTS)
+++ /dev/null
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include "check.h"
-#include "error.h"
-
-void setup (void);
-void cleanup (void);
-Suite *sub_make_suite(void);
-Suite *main_make_suite(void);
-
-START_TEST(test_lno)
-{
- fail("Failure expected"); /*line 15*/
-}
-END_TEST
-
-START_TEST(test_mark_lno)
-{
- mark_point(); /*line 21*/
- exit(1); /*should fail at line 21*/
-}
-END_TEST
-
-START_TEST(test_pass)
-{
- fail_unless (1==1, "This test should pass");
- fail_unless (9999, "This test should pass");
-}
-END_TEST
-
-START_TEST(test_fail)
-{
- fail_unless (1==2, "This test should fail");
-}
-END_TEST
-
-START_TEST(test_segv)
-{
- char arr[1];
- int i = 0;
-
- while (1) {
- arr[i] = 'a';
- i++;
- }
-}
-END_TEST
-
-
-START_TEST(test_fpe)
-{
- raise (SIGFPE);
-}
-END_TEST
-
-START_TEST(test_early_exit)
-{
- exit(1);
-}
-END_TEST
-
-START_TEST(test_null)
-{
- Suite *s;
- TCase *tc;
- SRunner *sr;
-
- s = suite_create(NULL);
- tc = tcase_create(NULL);
- suite_add_tcase (s, NULL);
- tcase_add_test (tc, NULL);
- sr = srunner_create(NULL);
- srunner_run_all (NULL, -1);
- srunner_free (NULL);
- suite_free (NULL);
- fail("Completed properly");
-}
-END_TEST
-
-/* TODO:
- unit test running the same suite in succession */
-
-START_TEST(test_mark_point)
-{
- int i;
- i = 0;
- i++;
- mark_point();
- raise(SIGFPE);
- fail("Shouldn't reach here");
-}
-END_TEST
-
-int nfailures;
-TestResult **trarray;
-
-START_TEST(test_check_nfailures)
-{
- fail_unless (nfailures == 8, "Unexpected number of failures received");
-}
-END_TEST
-
-START_TEST(test_check_failure_msgs)
-{
- int i;
- char *msgar[] = {
- "Failure expected",
- "Early exit with return value 1",
- "Test passed",
- "This test should fail",
- "Received signal 11",
- "Received signal 8",
- "Received signal 8",
- "Early exit with return value 1",
- "Completed properly"};
-
- for (i = 0; i < nfailures; i++) {
- char *msg;
- msg = tr_msg(trarray[i]);
- if (strcmp (msg, msgar[i]) != 0) {
- char *emsg = emalloc (CMAXMSG);
- snprintf (emsg, CMAXMSG,"Expected %s, got %s", msgar[i], msg);
- fail (emsg);
- free (emsg);
- }
- }
-}
-END_TEST
-
-START_TEST(test_check_failure_lnos)
-{
- int i;
- int lnos[] = {
- 15,
- 21,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1,
- -1};
-
- for (i = 0; i < nfailures; i++) {
-
- if (lnos[i] > 0 && tr_lno(trarray[i]) != lnos[i]) {
- char *emsg = emalloc (CMAXMSG);
- snprintf (emsg, CMAXMSG, "Expected lno %d, got %d",
- lnos[i], tr_lno(trarray[i]));
- fail (emsg);
- free (emsg);
- }
- }
-}
-END_TEST
-
-START_TEST(test_check_failure_ftypes)
-{
- int i;
- int ftypes[] = {
- CRFAILURE,
- CRERROR,
- CRPASS,
- CRFAILURE,
- CRERROR,
- CRERROR,
- CRERROR,
- CRERROR,
- CRFAILURE};
-
- for (i = 0; i < nfailures; i++) {
- fail_unless (ftypes[i] == tr_rtype(trarray[i]),
- "Failure type wrong");
- }
-}
-END_TEST
-
-START_TEST(test_check_failure_lfiles)
-{
- int i;
- for (i = 0; i < nfailures; i++) {
-
- fail_unless (strcmp(tr_lfile(trarray[i]), "check_check.c") == 0,
- "Bad file name");
- }
-}
-END_TEST
-
-START_TEST(test_check_failure_tcnames)
-{
- int i;
- for (i = 0; i < nfailures; i++) {
-
- fail_unless (strcmp(tr_tcname(trarray[i]), "Check Servant") == 0,
- "Bad test case name");
- }
-}
-END_TEST
-
-Suite *sub_make_suite(void)
-{
- Suite *s = suite_create("Check Servant");
- TCase *tc_simple = tcase_create("Simple Tests");
- TCase *tc_signal = tcase_create("Signal Tests");
- TCase *tc_limit = tcase_create("Limit Tests");
- suite_add_tcase (s, tc_simple);
- suite_add_tcase (s, tc_signal);
- suite_add_tcase (s, tc_limit);
- tcase_add_test (tc_simple, test_lno);
- tcase_add_test (tc_simple, test_mark_lno);
- tcase_add_test (tc_simple, test_pass);
- tcase_add_test (tc_simple, test_fail);
- tcase_add_test (tc_signal, test_segv);
- tcase_add_test (tc_signal, test_fpe);
- tcase_add_test (tc_signal, test_mark_point);
- tcase_add_test (tc_limit, test_early_exit);
- tcase_add_test (tc_limit, test_null);
- return s;
-}
-
-int test_fixture_val = 0;
-void test_fixture_setup (void)
-{
- test_fixture_val = 1;
-}
-
-START_TEST(test_setup)
-{
- fail_unless (test_fixture_val == 1,
- "Value not setup or changed across tests correctly");
- test_fixture_val = 2;
-}
-END_TEST
-
-void test_fixture_teardown (void)
-{
- test_fixture_val = 3;
-}
-
-START_TEST(test_teardown)
-{
- fail_unless (test_fixture_val == 3, "Value not changed correctly in teardown");
-}
-END_TEST
-
-
-Suite *main_make_suite (void)
-{
- Suite *s;
- TCase *tc_core;
- TCase *tc_fixture;
- TCase *tc_post_teardown;
-
- s = suite_create("Master");
- tc_core = tcase_create("Core Tests");
- tc_fixture = tcase_create("Fixture Setup Tests");
- suite_add_tcase (s, tc_core);
- tcase_add_test (tc_core, test_check_nfailures);
- tcase_add_test (tc_core, test_check_failure_msgs);
- tcase_add_test (tc_core, test_check_failure_lnos);
- tcase_add_test (tc_core, test_check_failure_lfiles);
- tcase_add_test (tc_core, test_check_failure_ftypes);
- tcase_set_fixture(tc_fixture, test_fixture_setup, test_fixture_teardown);
- /* add the test 3 times to make sure we adequately test
- preservation of fixture values across tests, regardless
- of the order in which tests are added to the test case */
- tcase_add_test (tc_fixture, test_setup);
- tcase_add_test (tc_fixture, test_setup);
- tcase_add_test (tc_fixture, test_setup);
- suite_add_tcase (s, tc_fixture);
- tc_post_teardown = tcase_create ("Fixture Teardown Tests");
- tcase_add_test (tc_post_teardown, test_teardown);
- suite_add_tcase (s, tc_post_teardown);
- return s;
-}
-
-int main (void)
-{
- int n;
-
-
- Suite *s;
- SRunner *sr;
- s = main_make_suite();
- sr = srunner_create (s);
-
- setup();
- printf ("Ran %d tests in subordinate suite\n", nfailures);
- srunner_run_all (sr, CRNORMAL);
- cleanup();
- n = srunner_nfailures(sr);
- srunner_free(sr);
- suite_free(s);
- return (n == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-
-void setup (void)
-{
- char *msg;
- Suite *s = sub_make_suite();
- SRunner *sr = srunner_create(s);
- srunner_run_all(sr, CRSILENT);
- trarray = srunner_failures(sr);
- nfailures = srunner_nfailures(sr);
-}
-
-void cleanup (void)
-{
- return;
-}
--- /dev/null
+#ifndef CHECK_CHECK_H
+#define CHECK_CHECK_H
+
+int sub_nfailed;
+int sub_ntests;
+
+void setup (void);
+void cleanup (void);
+Suite *sub_make_suite(void);
+Suite *main_make_suite(void);
+
+#endif /* CHECK_CHECK_H */
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <check.h>
+#include "check_check.h"
+
+int main (void)
+{
+ int n;
+
+
+ Suite *s;
+ SRunner *sr;
+ s = main_make_suite();
+ sr = srunner_create (s);
+
+ setup();
+ printf ("Ran %d tests in subordinate suite\n", sub_nfailed);
+ srunner_run_all (sr, CRNORMAL);
+ cleanup();
+ n = srunner_nfailed_tests(sr);
+ srunner_free(sr);
+ suite_free(s);
+ return (n == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
--- /dev/null
+#include <stdlib.h>
+#include <check.h>
+#include "check_check.h"
+
+
+TestResult **tr_fail_array;
+
+START_TEST(test_check_nfailures)
+{
+ fail_unless (sub_nfailed == 8, "Unexpected number of failures received");
+}
+END_TEST
+
+START_TEST(test_check_ntests_run)
+{
+ fail_unless (sub_ntests == 9, "Unexpected number of tests run");
+}
+END_TEST
+
+START_TEST(test_check_failure_msgs)
+{
+ int i;
+ char *msgar[] = {
+ "Failure expected",
+ "Early exit with return value 1",
+ /* "Test passed", */
+ "This test should fail",
+ "Received signal 11",
+ "Received signal 8",
+ "Received signal 8",
+ "Early exit with return value 1",
+ "Completed properly"};
+
+ for (i = 0; i < sub_nfailed; i++) {
+ char *msg;
+ msg = tr_msg(tr_fail_array[i]);
+ if (strcmp (msg, msgar[i]) != 0) {
+ char *emsg = malloc (CMAXMSG);
+ snprintf (emsg, CMAXMSG,"Expected %s, got %s", msgar[i], msg);
+ fail (emsg);
+ free (emsg);
+ }
+ }
+}
+END_TEST
+
+START_TEST(test_check_failure_lnos)
+{
+ int i;
+ int lnos[] = {
+ 8,
+ 14,
+ -1,
+ -1,
+ -1,
+ -1,
+ -1,
+ -1,
+ -1};
+
+ for (i = 0; i < sub_nfailed; i++) {
+
+ if (lnos[i] > 0 && tr_lno(tr_fail_array[i]) != lnos[i]) {
+ char *emsg = malloc (CMAXMSG);
+ snprintf (emsg, CMAXMSG, "Expected lno %d, got %d",
+ lnos[i], tr_lno(tr_fail_array[i]));
+ fail (emsg);
+ free (emsg);
+ }
+ }
+}
+END_TEST
+
+START_TEST(test_check_failure_ftypes)
+{
+ int i;
+ int ftypes[] = {
+ CRFAILURE,
+ CRERROR,
+ /* CRPASS, */
+ CRFAILURE,
+ CRERROR,
+ CRERROR,
+ CRERROR,
+ CRERROR,
+ CRFAILURE};
+
+ for (i = 0; i < sub_nfailed; i++) {
+ fail_unless (ftypes[i] == tr_rtype(tr_fail_array[i]),
+ "Failure type wrong");
+ }
+}
+END_TEST
+
+START_TEST(test_check_failure_lfiles)
+{
+ int i;
+ for (i = 0; i < sub_nfailed; i++) {
+
+ fail_unless (strcmp(tr_lfile(tr_fail_array[i]), "check_check_sub.c") == 0,
+ "Bad file name");
+ }
+}
+END_TEST
+
+START_TEST(test_check_failure_tcnames)
+{
+ int i;
+ for (i = 0; i < sub_nfailed; i++) {
+
+ fail_unless (strcmp(tr_tcname(tr_fail_array[i]), "Check Servant") == 0,
+ "Bad test case name");
+ }
+}
+END_TEST
+
+int test_fixture_val = 0;
+void test_fixture_setup (void)
+{
+ test_fixture_val = 1;
+}
+
+START_TEST(test_setup)
+{
+ fail_unless (test_fixture_val == 1,
+ "Value not setup or changed across tests correctly");
+ test_fixture_val = 2;
+}
+END_TEST
+
+void test_fixture_teardown (void)
+{
+ test_fixture_val = 3;
+}
+
+START_TEST(test_teardown)
+{
+ fail_unless (test_fixture_val == 3, "Value not changed correctly in teardown");
+}
+END_TEST
+
+
+Suite *main_make_suite (void)
+{
+ Suite *s;
+ TCase *tc_core;
+ TCase *tc_fixture;
+ TCase *tc_post_teardown;
+
+ s = suite_create("Master");
+ tc_core = tcase_create("Core Tests");
+ tc_fixture = tcase_create("Fixture Setup Tests");
+ suite_add_tcase (s, tc_core);
+ tcase_add_test (tc_core, test_check_nfailures);
+ tcase_add_test (tc_core, test_check_ntests_run);
+ tcase_add_test (tc_core, test_check_failure_msgs);
+ tcase_add_test (tc_core, test_check_failure_lnos);
+ tcase_add_test (tc_core, test_check_failure_lfiles);
+ tcase_add_test (tc_core, test_check_failure_ftypes);
+ tcase_set_fixture(tc_fixture, test_fixture_setup, test_fixture_teardown);
+ /* add the test 3 times to make sure we adequately test
+ preservation of fixture values across tests, regardless
+ of the order in which tests are added to the test case */
+ tcase_add_test (tc_fixture, test_setup);
+ tcase_add_test (tc_fixture, test_setup);
+ tcase_add_test (tc_fixture, test_setup);
+ suite_add_tcase (s, tc_fixture);
+ tc_post_teardown = tcase_create ("Fixture Teardown Tests");
+ tcase_add_test (tc_post_teardown, test_teardown);
+ suite_add_tcase (s, tc_post_teardown);
+ return s;
+}
+
+void setup (void)
+{
+ char *msg;
+ Suite *s = sub_make_suite();
+ SRunner *sr = srunner_create(s);
+ srunner_run_all(sr, CRSILENT);
+ tr_fail_array = srunner_failures(sr);
+ sub_nfailed = srunner_nfailed_tests(sr);
+ sub_ntests = srunner_ntests_run(sr);
+}
+
+void cleanup (void)
+{
+ return;
+}
Suite *s = make_suite();
SRunner *sr = srunner_create(s);
srunner_run_all (sr, CRNORMAL);
- n = srunner_nfailures(sr);
+ n = srunner_nfailed_tests(sr);
srunner_free(sr);
suite_free(s);
return (n == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
--- /dev/null
+#include <stdlib.h>
+#include <signal.h>
+#include <check.h>
+#include "check_check.h"
+
+START_TEST(test_lno)
+{
+ fail("Failure expected"); /*line 8*/
+}
+END_TEST
+
+START_TEST(test_mark_lno)
+{
+ mark_point(); /*line 14*/
+ exit(1); /*should fail at line 14*/
+}
+END_TEST
+
+START_TEST(test_pass)
+{
+ fail_unless (1==1, "This test should pass");
+ fail_unless (9999, "This test should pass");
+}
+END_TEST
+
+START_TEST(test_fail)
+{
+ fail_unless (1==2, "This test should fail");
+}
+END_TEST
+
+START_TEST(test_segv)
+{
+ char arr[1];
+ int i = 0;
+
+ while (1) {
+ arr[i] = 'a';
+ i++;
+ }
+}
+END_TEST
+
+
+START_TEST(test_fpe)
+{
+ raise (SIGFPE);
+}
+END_TEST
+
+
+/* TODO:
+ unit test running the same suite in succession */
+
+START_TEST(test_mark_point)
+{
+ int i;
+ i = 0;
+ i++;
+ mark_point();
+ raise(SIGFPE);
+ fail("Shouldn't reach here");
+}
+END_TEST
+
+START_TEST(test_early_exit)
+{
+ exit(1);
+}
+END_TEST
+
+START_TEST(test_null)
+{
+ Suite *s;
+ TCase *tc;
+ SRunner *sr;
+
+ s = suite_create(NULL);
+ tc = tcase_create(NULL);
+ suite_add_tcase (s, NULL);
+ tcase_add_test (tc, NULL);
+ sr = srunner_create(NULL);
+ srunner_run_all (NULL, -1);
+ srunner_free (NULL);
+ suite_free (NULL);
+ fail("Completed properly");
+}
+END_TEST
+
+Suite *sub_make_suite(void)
+{
+ Suite *s = suite_create("Check Servant");
+ TCase *tc_simple = tcase_create("Simple Tests");
+ TCase *tc_signal = tcase_create("Signal Tests");
+ TCase *tc_limit = tcase_create("Limit Tests");
+ suite_add_tcase (s, tc_simple);
+ suite_add_tcase (s, tc_signal);
+ suite_add_tcase (s, tc_limit);
+ tcase_add_test (tc_simple, test_lno);
+ tcase_add_test (tc_simple, test_mark_lno);
+ tcase_add_test (tc_simple, test_pass);
+ tcase_add_test (tc_simple, test_fail);
+ tcase_add_test (tc_signal, test_segv);
+ tcase_add_test (tc_signal, test_fpe);
+ tcase_add_test (tc_signal, test_mark_point);
+ tcase_add_test (tc_limit, test_early_exit);
+ tcase_add_test (tc_limit, test_null);
+ return s;
+}
tcase_add_test (tc, test_free);
srunner_run_all (sr, CRNORMAL);
- return (srunner_nfailures(sr) == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+ return (srunner_nfailed_tests(sr) == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
}
srunner_run_all(sr, CRSILENT);
- if (srunner_nfailures (sr) != num_iters) {
+ if (srunner_nfailed_tests (sr) != num_iters) {
printf ("Error: expected %d failures, got %d\n",
- num_iters, srunner_nfailures(sr));
+ num_iters, srunner_nfailed_tests(sr));
return;
}