From 64e8fb3e5decc954aa939b566b32043f7a33a5a3 Mon Sep 17 00:00:00 2001 From: cpickett Date: Fri, 13 Oct 2006 03:30:47 +0000 Subject: [PATCH] * Rewrite Makefiles to accomodate new example structure git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@289 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- doc/example/Makefile.am | 12 +----- doc/example/configure.ac | 52 ++++++++++++++++++-------- doc/example/src/Makefile.am | 8 ++++ doc/example/src/main.c | 12 ++++++ doc/example/src/money.c | 19 ++++++---- doc/example/src/money.h | 8 ++-- doc/example/tests/Makefile.am | 5 +++ doc/example/tests/check_money.c | 66 ++++++++++++++++++--------------- 8 files changed, 115 insertions(+), 67 deletions(-) create mode 100644 doc/example/src/Makefile.am create mode 100644 doc/example/src/main.c create mode 100644 doc/example/tests/Makefile.am diff --git a/doc/example/Makefile.am b/doc/example/Makefile.am index b8156f7..8376833 100644 --- a/doc/example/Makefile.am +++ b/doc/example/Makefile.am @@ -1,13 +1,3 @@ ## Process this file with automake to produce Makefile.in -TESTS=check_money - -noinst_PROGRAMS=check_money - -check_money_SOURCES=\ - money.h\ - money.c\ - check_money.c - -check_money_INCLUDES = @CHECK_CFLAGS@ -check_money_LDADD = @CHECK_LIBS@ +SUBDIRS = src . tests \ No newline at end of file diff --git a/doc/example/configure.ac b/doc/example/configure.ac index fa48537..60b33bd 100644 --- a/doc/example/configure.ac +++ b/doc/example/configure.ac @@ -1,23 +1,45 @@ -dnl Process this file with autoconf to produce a configure script. -AC_INIT(money.h) -AM_INIT_AUTOMAKE(money,0.2) +# Process this file with autoconf to produce a configure script. -dnl Checks for programs. -AC_PROG_AWK +# Prelude. +AC_PREREQ([2.59]) +AC_INIT([Money], [0.3], [check-devel@lists.sourceforge.net]) + +# unique source file --- primitive safety check +AC_CONFIG_SRCDIR([src/money.c]) + +# place to put some extra build scripts installed +AC_CONFIG_AUX_DIR([build-aux]) + +# fairly severe build strictness +# change foreign to gnu or gnits to comply with gnu standards +AM_INIT_AUTOMAKE([-Wall -Werror foreign 1.9.6]) + +# Checks for programs. AC_PROG_CC -AC_PROG_INSTALL -AC_PROG_LN_S -dnl This macro is defined in check.m4 and tests if check.h and libcheck.a -dnl can be found. It sets CHECK_CFLAGS and CHECK_LIBS accordingly. -dnl AM_PATH_CHECK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) +# Checks for libraries. + +# This macro is defined in check.m4 and tests if check.h and +# libcheck.a are installed in your system. It sets CHECK_CFLAGS and +# CHECK_LIBS accordingly. +# AM_PATH_CHECK([MINIMUM-VERSION, +# [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) AM_PATH_CHECK() -dnl Checks for header files. -AM_CONFIG_HEADER(config.h) +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([stdlib.h]) + +# Checks for typedefs, structures, and compiler characteristics. + +# Checks for library functions. +AC_FUNC_MALLOC -dnl Checks for typedefs, structures, and compiler characteristics. +# Output files +AC_CONFIG_HEADERS([config.h]) -dnl Checks for library functions. +AC_CONFIG_FILES([Makefile + src/Makefile + tests/Makefile]) -AC_OUTPUT(Makefile) +AC_OUTPUT diff --git a/doc/example/src/Makefile.am b/doc/example/src/Makefile.am new file mode 100644 index 0000000..58938f4 --- /dev/null +++ b/doc/example/src/Makefile.am @@ -0,0 +1,8 @@ +## Process this file with automake to produce Makefile.in + +lib_LTLIBRARIES = money.la +money_SOURCES = money.c money.h + +bin_PROGRAMS = main +main_SOURCES = main.c +main_LDADD = money.la diff --git a/doc/example/src/main.c b/doc/example/src/main.c new file mode 100644 index 0000000..caeae4a --- /dev/null +++ b/doc/example/src/main.c @@ -0,0 +1,12 @@ +#include "money.h" + +/* only main should be in this file, to make all other functions in + the prograble testable by Check. in order to test main(), use a + whole program testing framework like Autotest. +*/ + +int +main (void) +{ + return 0; +} diff --git a/doc/example/src/money.c b/doc/example/src/money.c index 45282f4..b551e96 100644 --- a/doc/example/src/money.c +++ b/doc/example/src/money.c @@ -1,14 +1,16 @@ #include #include "money.h" -struct Money { +struct Money +{ int amount; char *currency; }; -Money *money_create(int amount, char *currency) +Money * +money_create (int amount, char *currency) { - Money *m = malloc (sizeof(Money)); + Money *m = malloc (sizeof (Money)); if (m == NULL) return NULL; m->amount = amount; @@ -16,17 +18,20 @@ Money *money_create(int amount, char *currency) return m; } -int money_amount (Money *m) +int +money_amount (Money * m) { return m->amount; } -char *money_currency (Money *m) +char * +money_currency (Money * m) { return m->currency; } -void money_free(Money *m) +void +money_free (Money * m) { - free(m); + free (m); } diff --git a/doc/example/src/money.h b/doc/example/src/money.h index 720e32a..1897415 100644 --- a/doc/example/src/money.h +++ b/doc/example/src/money.h @@ -3,9 +3,9 @@ typedef struct Money Money; -Money *money_create(int amount, char *currency); -int money_amount (Money *m); -char *money_currency (Money *m); -void money_free(Money *m); +Money *money_create (int amount, char *currency); +int money_amount (Money * m); +char *money_currency (Money * m); +void money_free (Money * m); #endif /* MONEY_H */ diff --git a/doc/example/tests/Makefile.am b/doc/example/tests/Makefile.am new file mode 100644 index 0000000..35bc176 --- /dev/null +++ b/doc/example/tests/Makefile.am @@ -0,0 +1,5 @@ +TESTS=check_money +noinst_PROGRAMS=check_money +check_money_SOURCES= check_money.c +check_money_INCLUDES = @CHECK_CFLAGS@ +check_money_LDADD = @CHECK_LIBS@ $(top_builddir)/src/money.la diff --git a/doc/example/tests/check_money.c b/doc/example/tests/check_money.c index 531d2ff..4444660 100644 --- a/doc/example/tests/check_money.c +++ b/doc/example/tests/check_money.c @@ -3,62 +3,68 @@ #include "money.h" Money *five_dollars; -void setup (void) +void +setup (void) { - five_dollars = money_create(5, "USD"); + five_dollars = money_create (5, "USD"); } -void teardown (void) +void +teardown (void) { money_free (five_dollars); } - -START_TEST(test_create) +START_TEST (test_money_create) { - fail_unless (money_amount(five_dollars) == 5, + fail_unless (money_amount (five_dollars) == 5, "Amount not set correctly on creation"); - fail_unless (strcmp(money_currency(five_dollars),"USD") == 0, + fail_unless (strcmp (money_currency (five_dollars), "USD") == 0, "Currency not set correctly on creation"); } END_TEST -START_TEST(test_neg_create) +START_TEST (test_money_create_neg) { - Money *m = money_create(-1, "USD"); - fail_unless (m == NULL, "NULL should be returned on attempt to create with a negative amount"); + Money *m = money_create (-1, "USD"); + fail_unless (m == NULL, + "NULL should be returned on attempt to create with a negative amount"); } END_TEST -START_TEST(test_zero_create) +START_TEST (test_money_create_zero) { - Money *m = money_create(0, "USD"); - fail_unless (money_amount(m) == 0, - "Zero is a valid amount of money"); + Money *m = money_create (0, "USD"); + fail_unless (money_amount (m) == 0, "Zero is a valid amount of money"); } -END_TEST +END_TEST -Suite *money_suite (void) +Suite * money_suite (void) { - Suite *s = suite_create("Money"); - TCase *tc_core = tcase_create("Core"); - TCase *tc_limits = tcase_create("Limits"); + Suite *s = suite_create ("Money"); + + /* Core test case */ + TCase *tc_core = tcase_create ("Core"); + tcase_add_test (tc_core, test_money_create); + tcase_add_checked_fixture (tc_core, setup, teardown); suite_add_tcase (s, tc_core); + + /* Limits test case */ + TCase *tc_limits = tcase_create ("Limits"); + tcase_add_test (tc_limits, test_money_create_neg); + tcase_add_test (tc_limits, test_money_create_zero); suite_add_tcase (s, tc_limits); - tcase_add_test (tc_core, test_create); - tcase_add_checked_fixture (tc_core, setup, teardown); - tcase_add_test (tc_limits, test_neg_create); - tcase_add_test (tc_limits, test_zero_create); return s; } -int main (void) +int +main (void) { - int nf; - Suite *s = money_suite(); - SRunner *sr = srunner_create(s); + int number_failed; + Suite *s = money_suite (); + SRunner *sr = srunner_create (s); srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed(sr); - srunner_free(sr); - return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.40.0