Merge lp:~oif-team/geis/tdd-harness into lp:geis

Proposed by Stephen M. Webb
Status: Merged
Merged at revision: 85
Proposed branch: lp:~oif-team/geis/tdd-harness
Merge into: lp:geis
Diff against target: 229 lines (+174/-1)
7 files modified
.bzrignore (+2/-0)
ChangeLog (+19/-0)
configure.ac (+7/-0)
testsuite/Makefile.am (+1/-1)
testsuite/check/Makefile.am (+32/-0)
testsuite/check/check_geis_internals.c (+26/-0)
testsuite/check/check_instance_table.c (+87/-0)
To merge this branch: bzr merge lp:~oif-team/geis/tdd-harness
Reviewer Review Type Date Requested Status
Henrik Rydberg (community) Approve
Duncan McGreggor (community) Needs Information
Chase Douglas (community) Approve
Review via email: mp+39005@code.launchpad.net

Description of the change

Added unit testing infrastructure.

To post a comment you must log in.
Revision history for this message
Chase Douglas (chasedouglas) wrote :

Me likey!

review: Approve
Revision history for this message
Duncan McGreggor (oubiwann) wrote :

Wait! No! Don't merge yet!

review: Needs Information
Revision history for this message
Duncan McGreggor (oubiwann) wrote :

Okay, so I wanted to get that out right away before it got merged :-) I have some concerns, but first:

AWESOME JOB! Thanks for doing this TDD effort!

However, I really liked CUnit as a framework for unit testing. Suites are cool and useful, and CUnit supports them (with per-suite set-ups/tear-downs).

Can you give the reasons that you chose check as the testing framework?

review: Needs Information
Revision history for this message
Stephen M. Webb (bregma) wrote :

* check also supports suites, including nested suites and per-suite fixture setup/teardown
* cunit is a port of the massive Java JUnit framework, it's a rather overengineered solution to a simple problem
* check forks tests, cunit doesn't -- meaning a single crash causes the entire run to fail instead of reporting errors
* check only emits results, it doesn't come with an embedded gui runner

In short, check is a smaller and lighter yet complete (for our purposes) unit test framework.

Revision history for this message
Henrik Rydberg (rydberg) wrote :

Small is good. Light is good. Complete is good. Code looks good. All is good. :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2010-08-12 15:43:49 +0000
3+++ .bzrignore 2010-10-21 01:06:04 +0000
4@@ -29,4 +29,6 @@
5 libtool
6 Makefile
7 stamp-*
8+testsuite/check/check_geis_internals
9+testsuite/check/*.log
10 testsuite/geistest/geistest
11
12=== modified file 'ChangeLog'
13--- ChangeLog 2010-10-18 14:15:01 +0000
14+++ ChangeLog 2010-10-21 01:06:04 +0000
15@@ -1,3 +1,22 @@
16+2010-10-20 Stephen M. Webb <stephen.webb@canonical.com>
17+
18+ Added unit tests for internal geis_instance_table.
19+
20+ * testsuite/check/check_instance_table.c: new file
21+ * testsuite/check/Makefile.am (check_geis_internals_SOURCES): added it
22+ (MOSTLYCLEANFILES): new target to clean up unit test logs
23+ * testsuite/check/check_geis_internals.c (main): added unit test suite
24+
25+2010-10-20 Stephen M. Webb <stephen.webb@canonical.com>
26+
27+ Added unit test infrastructure based on 'check'.
28+
29+ * testsuite/check/Makefile.am: new file
30+ * testsuite/check/check_geis_internals.c: new file
31+ * testsuite/Makefile.am (SUBDIRS): added check target
32+ * configure.ac: added new stanza for detecting check package
33+ (AC_CONFIG_FILES): added testsuite/check/Makefile
34+
35 2010-10-18 Stephen M. Webb <stephen.webb@canonical.com>
36
37 Added configury check for xcb-proto package >= 1.6 (LP: #661946).
38
39=== modified file 'configure.ac'
40--- configure.ac 2010-10-18 14:15:01 +0000
41+++ configure.ac 2010-10-21 01:06:04 +0000
42@@ -54,6 +54,12 @@
43 AC_DEFINE([GEIS_DSO_PRIVATE],[1],[symbol visibility is supported])
44 fi
45
46+# Check for TDD tools
47+PKG_CHECK_MODULES([CHECK], [check >= 0.9.8],
48+ [have_check=yes],
49+ AC_MSG_WARN([package 'check' not found: unit testing disabled]))
50+AM_CONDITIONAL([HAVE_CHECK],[test "x$have_check" = xyes])
51+
52
53 AC_CONFIG_FILES([Makefile
54 libutouch-geis.pc
55@@ -62,5 +68,6 @@
56 libutouch-geis-xcb/Makefile
57 libutouch-geis-xcb/xcb_gesture.xml
58 testsuite/Makefile
59+ testsuite/check/Makefile
60 testsuite/geistest/Makefile])
61 AC_OUTPUT
62
63=== modified file 'testsuite/Makefile.am'
64--- testsuite/Makefile.am 2010-07-26 01:40:31 +0000
65+++ testsuite/Makefile.am 2010-10-21 01:06:04 +0000
66@@ -1,1 +1,1 @@
67-SUBDIRS = geistest
68+SUBDIRS = check geistest
69
70=== added directory 'testsuite/check'
71=== added file 'testsuite/check/Makefile.am'
72--- testsuite/check/Makefile.am 1970-01-01 00:00:00 +0000
73+++ testsuite/check/Makefile.am 2010-10-21 01:06:04 +0000
74@@ -0,0 +1,32 @@
75+#
76+# @file testsuite/check/Makefile.am
77+# @brief automake recipe for the geis testsuite unit testing directory
78+#
79+
80+if HAVE_CHECK
81+ test_targets = check_geis_internals
82+else
83+ test_targets =
84+endif
85+
86+TESTS = $(test_targets)
87+
88+check_PROGRAMS = $(test_targets)
89+
90+check_geis_internals_SOURCES = \
91+ check_instance_table.c \
92+ check_geis_internals.c
93+
94+check_geis_internals_CFLAGS = \
95+ -I$(top_srcdir) \
96+ $(CHECK_CFLAGS)
97+
98+check_geis_internals_LDADD = \
99+ $(top_builddir)/libutouch-geis-xcb/.libs/libutouch-geis.a \
100+ $(X11XCB_LIBS) \
101+ $(XCB_LIBS) \
102+ $(XI2_LIBS) \
103+ $(CHECK_LIBS)
104+
105+MOSTLYCLEANFILES = geis_internals.log
106+
107
108=== added file 'testsuite/check/check_geis_internals.c'
109--- testsuite/check/check_geis_internals.c 1970-01-01 00:00:00 +0000
110+++ testsuite/check/check_geis_internals.c 2010-10-21 01:06:04 +0000
111@@ -0,0 +1,26 @@
112+/**
113+ * test driver for unit testing of geis internals
114+ */
115+#include <check.h>
116+
117+extern Suite *make_instance_table_suite();
118+
119+
120+int
121+main(int argc, char* argv[])
122+{
123+ int num_failed = 0;
124+
125+ Suite *s = suite_create("\"geis internals\"");
126+
127+ SRunner *sr = srunner_create(s);
128+ srunner_add_suite(sr, make_instance_table_suite());
129+
130+ srunner_set_log(sr, "geis_internals.log");
131+ srunner_run_all(sr, CK_NORMAL);
132+ num_failed = srunner_ntests_failed(sr);
133+
134+ srunner_free(sr);
135+
136+ return !(num_failed == 0);
137+}
138
139=== added file 'testsuite/check/check_instance_table.c'
140--- testsuite/check/check_instance_table.c 1970-01-01 00:00:00 +0000
141+++ testsuite/check/check_instance_table.c 2010-10-21 01:06:04 +0000
142@@ -0,0 +1,87 @@
143+/**
144+ * unit tests for the geis_instance_table module
145+ */
146+#include <check.h>
147+
148+#include "libutouch-geis-xcb/geis_instance.h"
149+#include "libutouch-geis-xcb/geis_instance_table.h"
150+
151+/* fixtures */
152+static GeisInstanceTable fixture_table;
153+static GeisInstance fixture_instance;
154+static const uint32_t fixture_window_id = 0x32;
155+
156+/* fixture setup */
157+static void
158+construct_table()
159+{
160+ fixture_table = geis_instance_table_new(1);
161+ fixture_instance = geis_instance_new(fixture_window_id);
162+}
163+
164+/* fixture teardown */
165+static void
166+destroy_table()
167+{
168+ geis_instance_free(fixture_instance);
169+ geis_instance_table_free(fixture_table);
170+}
171+
172+/* verify table construction/destruction */
173+START_TEST(construction)
174+{
175+ GeisInstanceTable table = geis_instance_table_new(1);
176+ fail_unless(table != NULL, "failed to create instance_table");
177+ geis_instance_table_free(table);
178+}
179+END_TEST
180+
181+
182+/* verify table insertion */
183+START_TEST(insertion)
184+{
185+ geis_instance_table_add(fixture_table, fixture_instance);
186+}
187+END_TEST
188+
189+
190+/* verify table find operation (positive results) */
191+START_TEST(find_success)
192+{
193+ geis_instance_table_add(fixture_table, fixture_instance);
194+ GeisInstance instance = geis_instance_table_get(fixture_table, fixture_window_id);
195+ fail_if(instance == NULL, "expected instance not found");
196+ fail_unless(geis_instance_get_window_id(instance) == fixture_window_id);
197+}
198+END_TEST
199+
200+
201+/* verify table find operation (negative results) */
202+START_TEST(find_fail)
203+{
204+ GeisInstance instance = geis_instance_table_get(fixture_table, 0x5a);
205+ fail_unless(instance == NULL, "unexpected instance found");
206+}
207+END_TEST
208+
209+
210+/* boilerplate */
211+Suite *
212+make_instance_table_suite()
213+{
214+ Suite *s = suite_create("geis_instance_table");
215+
216+ TCase *create = tcase_create("table-creation");
217+ tcase_add_test(create, construction);
218+ suite_add_tcase(s, create);
219+
220+ TCase *usage = tcase_create("table-usage");
221+ tcase_add_checked_fixture(usage, construct_table, destroy_table);
222+ tcase_add_test(usage, insertion);
223+ tcase_add_test(usage, find_success);
224+ tcase_add_test(usage, find_fail);
225+ suite_add_tcase(s, usage);
226+
227+ return s;
228+}
229+

Subscribers

People subscribed via source and target branches

to all changes: