summaryrefslogtreecommitdiff
path: root/doc/example
diff options
context:
space:
mode:
Diffstat (limited to 'doc/example')
-rw-r--r--doc/example/Makefile.am3
-rw-r--r--doc/example/README24
-rw-r--r--doc/example/configure.ac46
-rw-r--r--doc/example/src/Makefile.am8
-rw-r--r--doc/example/src/main.c12
-rw-r--r--doc/example/src/money.1.c0
-rw-r--r--doc/example/src/money.1.h4
-rw-r--r--doc/example/src/money.2.h11
-rw-r--r--doc/example/src/money.3.c26
-rw-r--r--doc/example/src/money.4.c31
-rw-r--r--doc/example/src/money.5.c41
-rw-r--r--doc/example/src/money.6.c46
-rw-r--r--doc/example/src/money.c46
-rw-r--r--doc/example/src/money.h11
-rw-r--r--doc/example/tests/Makefile.am7
-rw-r--r--doc/example/tests/check_money.1.c5
-rw-r--r--doc/example/tests/check_money.2.c20
-rw-r--r--doc/example/tests/check_money.3.c40
-rw-r--r--doc/example/tests/check_money.6.c63
-rw-r--r--doc/example/tests/check_money.7.c75
-rw-r--r--doc/example/tests/check_money.c75
21 files changed, 594 insertions, 0 deletions
diff --git a/doc/example/Makefile.am b/doc/example/Makefile.am
new file mode 100644
index 0000000..8376833
--- /dev/null
+++ b/doc/example/Makefile.am
@@ -0,0 +1,3 @@
+## Process this file with automake to produce Makefile.in
+
+SUBDIRS = src . tests \ No newline at end of file
diff --git a/doc/example/README b/doc/example/README
new file mode 100644
index 0000000..bc89980
--- /dev/null
+++ b/doc/example/README
@@ -0,0 +1,24 @@
+This is the "money example" from the Check tutorial.
+
+You need the following programs installed on your system:
+ -- Autoconf 2.59
+ -- Automake 1.9.6
+ -- Libtool 1.5.22
+ -- Check 0.9.3
+
+Somewhat earlier versions of these programs might work.
+
+Then, do as follows:
+
+$ autoreconf --install
+$ ./configure
+$ make
+$ make check
+
+Don't do "make install" unless you want to install the money example.
+
+money.c and money.h are built as a library. src/main.c:main() is a
+client of libmoney.la, just as tests/check_money.c:main() is a client
+of libmoney.la
+
+Please send bug reports to check-devel AT lists.sourceforge.net.
diff --git a/doc/example/configure.ac b/doc/example/configure.ac
new file mode 100644
index 0000000..a25417b
--- /dev/null
+++ b/doc/example/configure.ac
@@ -0,0 +1,46 @@
+# Process this file with autoconf to produce a configure script.
+
+# Prelude.
+AC_PREREQ([2.59])
+AC_INIT([Money], [0.3], [check-devel AT 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_LIBTOOL
+
+# 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()
+
+# 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
+
+# Output files
+AC_CONFIG_HEADERS([config.h])
+
+AC_CONFIG_FILES([Makefile
+ src/Makefile
+ tests/Makefile])
+
+AC_OUTPUT
diff --git a/doc/example/src/Makefile.am b/doc/example/src/Makefile.am
new file mode 100644
index 0000000..0ab2add
--- /dev/null
+++ b/doc/example/src/Makefile.am
@@ -0,0 +1,8 @@
+## Process this file with automake to produce Makefile.in
+
+lib_LTLIBRARIES = libmoney.la
+libmoney_la_SOURCES = money.c money.h
+
+bin_PROGRAMS = main
+main_SOURCES = main.c
+main_LDADD = libmoney.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.1.c b/doc/example/src/money.1.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/doc/example/src/money.1.c
diff --git a/doc/example/src/money.1.h b/doc/example/src/money.1.h
new file mode 100644
index 0000000..d1b2094
--- /dev/null
+++ b/doc/example/src/money.1.h
@@ -0,0 +1,4 @@
+#ifndef MONEY_H
+#define MONEY_H
+
+#endif /* MONEY_H */
diff --git a/doc/example/src/money.2.h b/doc/example/src/money.2.h
new file mode 100644
index 0000000..1897415
--- /dev/null
+++ b/doc/example/src/money.2.h
@@ -0,0 +1,11 @@
+#ifndef MONEY_H
+#define MONEY_H
+
+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);
+
+#endif /* MONEY_H */
diff --git a/doc/example/src/money.3.c b/doc/example/src/money.3.c
new file mode 100644
index 0000000..52ac9ea
--- /dev/null
+++ b/doc/example/src/money.3.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include "money.h"
+
+Money *
+money_create (int amount, char *currency)
+{
+ return NULL;
+}
+
+int
+money_amount (Money * m)
+{
+ return 0;
+}
+
+char *
+money_currency (Money * m)
+{
+ return NULL;
+}
+
+void
+money_free (Money * m)
+{
+ return;
+}
diff --git a/doc/example/src/money.4.c b/doc/example/src/money.4.c
new file mode 100644
index 0000000..e925672
--- /dev/null
+++ b/doc/example/src/money.4.c
@@ -0,0 +1,31 @@
+#include <stdlib.h>
+#include "money.h"
+
+struct Money
+{
+ int amount;
+};
+
+Money *
+money_create (int amount, char *currency)
+{
+ return NULL;
+}
+
+int
+money_amount (Money * m)
+{
+ return m->amount;
+}
+
+char *
+money_currency (Money * m)
+{
+ return NULL;
+}
+
+void
+money_free (Money * m)
+{
+ return;
+}
diff --git a/doc/example/src/money.5.c b/doc/example/src/money.5.c
new file mode 100644
index 0000000..64267a9
--- /dev/null
+++ b/doc/example/src/money.5.c
@@ -0,0 +1,41 @@
+#include <stdlib.h>
+#include "money.h"
+
+struct Money
+{
+ int amount;
+ char *currency;
+};
+
+Money *
+money_create (int amount, char *currency)
+{
+ Money *m = malloc (sizeof (Money));
+ if (m == NULL)
+ {
+ return NULL;
+ }
+
+ m->amount = amount;
+ m->currency = currency;
+ return m;
+}
+
+int
+money_amount (Money * m)
+{
+ return m->amount;
+}
+
+char *
+money_currency (Money * m)
+{
+ return m->currency;
+}
+
+void
+money_free (Money * m)
+{
+ free (m);
+ return;
+}
diff --git a/doc/example/src/money.6.c b/doc/example/src/money.6.c
new file mode 100644
index 0000000..47f09bb
--- /dev/null
+++ b/doc/example/src/money.6.c
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+#include "money.h"
+
+struct Money
+{
+ int amount;
+ char *currency;
+};
+
+Money *
+money_create (int amount, char *currency)
+{
+ if (amount < 0)
+ {
+ return NULL;
+ }
+
+ Money *m = malloc (sizeof (Money));
+ if (m == NULL)
+ {
+ return NULL;
+ }
+
+ m->amount = amount;
+ m->currency = currency;
+ return m;
+}
+
+int
+money_amount (Money * m)
+{
+ return m->amount;
+}
+
+char *
+money_currency (Money * m)
+{
+ return m->currency;
+}
+
+void
+money_free (Money * m)
+{
+ free (m);
+ return;
+}
diff --git a/doc/example/src/money.c b/doc/example/src/money.c
new file mode 100644
index 0000000..47f09bb
--- /dev/null
+++ b/doc/example/src/money.c
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+#include "money.h"
+
+struct Money
+{
+ int amount;
+ char *currency;
+};
+
+Money *
+money_create (int amount, char *currency)
+{
+ if (amount < 0)
+ {
+ return NULL;
+ }
+
+ Money *m = malloc (sizeof (Money));
+ if (m == NULL)
+ {
+ return NULL;
+ }
+
+ m->amount = amount;
+ m->currency = currency;
+ return m;
+}
+
+int
+money_amount (Money * m)
+{
+ return m->amount;
+}
+
+char *
+money_currency (Money * m)
+{
+ return m->currency;
+}
+
+void
+money_free (Money * m)
+{
+ free (m);
+ return;
+}
diff --git a/doc/example/src/money.h b/doc/example/src/money.h
new file mode 100644
index 0000000..1897415
--- /dev/null
+++ b/doc/example/src/money.h
@@ -0,0 +1,11 @@
+#ifndef MONEY_H
+#define MONEY_H
+
+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);
+
+#endif /* MONEY_H */
diff --git a/doc/example/tests/Makefile.am b/doc/example/tests/Makefile.am
new file mode 100644
index 0000000..729a610
--- /dev/null
+++ b/doc/example/tests/Makefile.am
@@ -0,0 +1,7 @@
+## Process this file with automake to produce Makefile.in
+
+TESTS = check_money
+check_PROGRAMS = check_money
+check_money_SOURCES = check_money.c $(top_builddir)/src/money.h
+check_money_CFLAGS = @CHECK_CFLAGS@
+check_money_LDADD = $(top_builddir)/src/libmoney.la @CHECK_LIBS@
diff --git a/doc/example/tests/check_money.1.c b/doc/example/tests/check_money.1.c
new file mode 100644
index 0000000..398ec67
--- /dev/null
+++ b/doc/example/tests/check_money.1.c
@@ -0,0 +1,5 @@
+int
+main (void)
+{
+ return 0;
+}
diff --git a/doc/example/tests/check_money.2.c b/doc/example/tests/check_money.2.c
new file mode 100644
index 0000000..7c7c9d4
--- /dev/null
+++ b/doc/example/tests/check_money.2.c
@@ -0,0 +1,20 @@
+#include <check.h>
+#include "../src/money.h"
+
+START_TEST (test_money_create)
+{
+ Money *m;
+ m = money_create (5, "USD");
+ fail_unless (money_amount (m) == 5,
+ "Amount not set correctly on creation");
+ fail_unless (strcmp (money_currency (m), "USD") == 0,
+ "Currency not set correctly on creation");
+ money_free (m);
+}
+END_TEST
+
+int
+main (void)
+{
+ return 0;
+}
diff --git a/doc/example/tests/check_money.3.c b/doc/example/tests/check_money.3.c
new file mode 100644
index 0000000..a19cf8b
--- /dev/null
+++ b/doc/example/tests/check_money.3.c
@@ -0,0 +1,40 @@
+#include <stdlib.h>
+#include <check.h>
+#include "../src/money.h"
+
+START_TEST (test_money_create)
+{
+ Money *m;
+ m = money_create (5, "USD");
+ fail_unless (money_amount (m) == 5,
+ "Amount not set correctly on creation");
+ fail_unless (strcmp (money_currency (m), "USD") == 0,
+ "Currency not set correctly on creation");
+ money_free (m);
+}
+END_TEST
+
+Suite *
+money_suite (void)
+{
+ Suite *s = suite_create ("Money");
+
+ /* Core test case */
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_test (tc_core, test_money_create);
+ suite_add_tcase (s, tc_core);
+
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed;
+ Suite *s = money_suite ();
+ SRunner *sr = srunner_create (s);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/doc/example/tests/check_money.6.c b/doc/example/tests/check_money.6.c
new file mode 100644
index 0000000..f47fc77
--- /dev/null
+++ b/doc/example/tests/check_money.6.c
@@ -0,0 +1,63 @@
+#include <stdlib.h>
+#include <check.h>
+#include "../src/money.h"
+
+START_TEST (test_money_create)
+{
+ Money *m;
+ m = money_create (5, "USD");
+ fail_unless (money_amount (m) == 5,
+ "Amount not set correctly on creation");
+ fail_unless (strcmp (money_currency (m), "USD") == 0,
+ "Currency not set correctly on creation");
+ money_free (m);
+}
+END_TEST
+
+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");
+}
+END_TEST
+
+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");
+}
+END_TEST
+
+Suite *
+money_suite (void)
+{
+ Suite *s = suite_create ("Money");
+
+ /* Core test case */
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_test (tc_core, test_money_create);
+ 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);
+
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed;
+ Suite *s = money_suite ();
+ SRunner *sr = srunner_create (s);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/doc/example/tests/check_money.7.c b/doc/example/tests/check_money.7.c
new file mode 100644
index 0000000..b935998
--- /dev/null
+++ b/doc/example/tests/check_money.7.c
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include <check.h>
+#include "../src/money.h"
+
+Money *five_dollars;
+
+void
+setup (void)
+{
+ five_dollars = money_create (5, "USD");
+}
+
+void
+teardown (void)
+{
+ money_free (five_dollars);
+}
+
+START_TEST (test_money_create)
+{
+ fail_unless (money_amount (five_dollars) == 5,
+ "Amount not set correctly on creation");
+ fail_unless (strcmp (money_currency (five_dollars), "USD") == 0,
+ "Currency not set correctly on creation");
+}
+END_TEST
+
+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");
+}
+END_TEST
+
+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");
+}
+END_TEST
+
+Suite *
+money_suite (void)
+{
+ Suite *s = suite_create ("Money");
+
+ /* Core test case */
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+ tcase_add_test (tc_core, test_money_create);
+ 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);
+
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed;
+ Suite *s = money_suite ();
+ SRunner *sr = srunner_create (s);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/doc/example/tests/check_money.c b/doc/example/tests/check_money.c
new file mode 100644
index 0000000..b935998
--- /dev/null
+++ b/doc/example/tests/check_money.c
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include <check.h>
+#include "../src/money.h"
+
+Money *five_dollars;
+
+void
+setup (void)
+{
+ five_dollars = money_create (5, "USD");
+}
+
+void
+teardown (void)
+{
+ money_free (five_dollars);
+}
+
+START_TEST (test_money_create)
+{
+ fail_unless (money_amount (five_dollars) == 5,
+ "Amount not set correctly on creation");
+ fail_unless (strcmp (money_currency (five_dollars), "USD") == 0,
+ "Currency not set correctly on creation");
+}
+END_TEST
+
+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");
+}
+END_TEST
+
+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");
+}
+END_TEST
+
+Suite *
+money_suite (void)
+{
+ Suite *s = suite_create ("Money");
+
+ /* Core test case */
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+ tcase_add_test (tc_core, test_money_create);
+ 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);
+
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed;
+ Suite *s = money_suite ();
+ SRunner *sr = srunner_create (s);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}