Re: [PATCH 1/2] Add Google Inc. to AUTHORS as a contributor.
[notmuch-archives.git] / 76 / af8aa8ee10b202790bf8829bb1f2468f083b91
1 Return-Path: <jeff@ocjtech.us>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 5E9AE431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 13:33:29 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id V6HSIGDrb8o1 for <notmuch@notmuchmail.org>;\r
11         Sat, 28 Nov 2009 13:33:28 -0800 (PST)\r
12 Received: from mail-yx0-f187.google.com (mail-yx0-f187.google.com\r
13         [209.85.210.187])\r
14         by olra.theworths.org (Postfix) with ESMTP id D9412431FAE\r
15         for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 13:33:27 -0800 (PST)\r
16 Received: by yxe17 with SMTP id 17so2481049yxe.33\r
17         for <notmuch@notmuchmail.org>; Sat, 28 Nov 2009 13:33:27 -0800 (PST)\r
18 Received: by 10.91.63.8 with SMTP id q8mr3710078agk.60.1259444007390;\r
19         Sat, 28 Nov 2009 13:33:27 -0800 (PST)\r
20 Received: from max1.ocjtech.us ([69.57.47.215])\r
21         by mx.google.com with ESMTPS id 39sm1344364yxd.9.2009.11.28.13.33.25\r
22         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
23         Sat, 28 Nov 2009 13:33:26 -0800 (PST)\r
24 Received: from localhost ([127.0.0.1] helo=localhost.localdomain)\r
25         by max1.ocjtech.us with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69)\r
26         (envelope-from <jeff@ocjtech.us>)\r
27         id 1NEUuy-00080O-Cy; Sat, 28 Nov 2009 15:33:24 -0600\r
28 From: "Jeffrey C. Ollie" <jeff@ocjtech.us>\r
29 To: Not Much Mail <notmuch@notmuchmail.org>\r
30 Date: Sat, 28 Nov 2009 15:33:14 -0600\r
31 Message-Id: <1259443994-30734-1-git-send-email-jeff@ocjtech.us>\r
32 X-Mailer: git-send-email 1.6.5.2\r
33 In-Reply-To: <1259432420-27684-1-git-send-email-jeff@ocjtech.us>\r
34 References: <1259432420-27684-1-git-send-email-jeff@ocjtech.us>\r
35 Subject: [notmuch] [PATCH v3] Add the beginnings of a test suite.\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.12\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Sat, 28 Nov 2009 21:33:29 -0000\r
49 \r
50 This is the beginning of a test suite.  It uses the Check[1] unit\r
51 testing framework to handle the testing.  There are basic tests of the\r
52 SHA1 and tag manipulation routines, obviously many more will need to\r
53 be added.\r
54 \r
55 Run "make check" from the toplevel directory to build and run the\r
56 checks.\r
57 \r
58 [1] http://check.sourceforge.net/\r
59 \r
60 Signed-off-by: Jeffrey C. Ollie <jeff@ocjtech.us>\r
61 ---\r
62  .gitignore                  |    1 +\r
63  Makefile                    |    1 +\r
64  Makefile.local              |    3 ++\r
65  checks/Makefile.local       |   14 +++++++\r
66  checks/notmuch-check-sha1.c |   76 ++++++++++++++++++++++++++++++++++++++\r
67  checks/notmuch-check-tags.c |   84 +++++++++++++++++++++++++++++++++++++++++++\r
68  checks/notmuch-check.c      |   40 ++++++++++++++++++++\r
69  checks/notmuch-check.h      |   24 ++++++++++++\r
70  configure                   |    8 ++++\r
71  9 files changed, 251 insertions(+), 0 deletions(-)\r
72  create mode 100644 checks/Makefile.local\r
73  create mode 100644 checks/notmuch-check-sha1.c\r
74  create mode 100644 checks/notmuch-check-tags.c\r
75  create mode 100644 checks/notmuch-check.c\r
76  create mode 100644 checks/notmuch-check.h\r
77 \r
78 diff --git a/.gitignore b/.gitignore\r
79 index 8794354..bd542d9 100644\r
80 --- a/.gitignore\r
81 +++ b/.gitignore\r
82 @@ -8,3 +8,4 @@ notmuch.1.gz\r
83  *~\r
84  .*.swp\r
85  *.elc\r
86 +checks/check\r
87 diff --git a/Makefile b/Makefile\r
88 index 2cd1b1b..1a4c8db 100644\r
89 --- a/Makefile\r
90 +++ b/Makefile\r
91 @@ -33,6 +33,7 @@ override LDFLAGS += \\r
92  # Include our local Makefile.local first so that its first target is default\r
93  include Makefile.local\r
94  include lib/Makefile.local\r
95 +include checks/Makefile.local\r
96  \r
97  # And get user settings from the output of configure\r
98  include Makefile.config\r
99 diff --git a/Makefile.local b/Makefile.local\r
100 index 1744747..f6ffd00 100644\r
101 --- a/Makefile.local\r
102 +++ b/Makefile.local\r
103 @@ -47,5 +47,8 @@ install-emacs: install emacs\r
104         install -m0644 notmuch.el $(DESTDIR)$(emacs_lispdir)\r
105         install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)\r
106  \r
107 +check: checks/check\r
108 +       checks/check\r
109 +\r
110  SRCS  := $(SRCS) $(notmuch_client_srcs)\r
111  CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc notmuch.1.gz\r
112 diff --git a/checks/Makefile.local b/checks/Makefile.local\r
113 new file mode 100644\r
114 index 0000000..57797ea\r
115 --- /dev/null\r
116 +++ b/checks/Makefile.local\r
117 @@ -0,0 +1,14 @@\r
118 +dir=checks\r
119 +extra_cflags += -I$(dir)\r
120 +\r
121 +check_c_srcs =                 \\r
122 +       $(dir)/notmuch-check.c          \\r
123 +       $(dir)/notmuch-check-sha1.c     \\r
124 +       $(dir)/notmuch-check-tags.c\r
125 +\r
126 +check_modules = $(check_c_srcs:.c=.o)\r
127 +$(dir)/check: $(check_modules)\r
128 +       $(call quiet,CXX) $^ $(LDFLAGS) -o $@ lib/notmuch.a -lcheck\r
129 +\r
130 +SRCS  := $(SRCS) $(check_c_srcs)\r
131 +CLEAN := $(CLEAN) $(check_modules) $(dir)/check\r
132 diff --git a/checks/notmuch-check-sha1.c b/checks/notmuch-check-sha1.c\r
133 new file mode 100644\r
134 index 0000000..c93fc6f\r
135 --- /dev/null\r
136 +++ b/checks/notmuch-check-sha1.c\r
137 @@ -0,0 +1,76 @@\r
138 +/* notmuch - Not much of an email program, (just index and search)\r
139 + *\r
140 + * Copyright © 2009 Jeffrey C. Ollie\r
141 + *\r
142 + * This program is free software: you can redistribute it and/or modify\r
143 + * it under the terms of the GNU General Public License as published by\r
144 + * the Free Software Foundation, either version 3 of the License, or\r
145 + * (at your option) any later version.\r
146 + *\r
147 + * This program is distributed in the hope that it will be useful,\r
148 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
149 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
150 + * GNU General Public License for more details.\r
151 + *\r
152 + * You should have received a copy of the GNU General Public License\r
153 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
154 + *\r
155 + * Authors: Jeffrey C. Ollie <jeff@ocjtech.us>\r
156 + */\r
157 +\r
158 +#include <check.h>\r
159 +#include <string.h>\r
160 +\r
161 +#include "notmuch-private.h"\r
162 +#include "notmuch-check.h"\r
163 +\r
164 +START_TEST (test_sha1_of_string)\r
165 +{\r
166 +   char *result;\r
167 +\r
168 +   result = notmuch_sha1_of_string("abcdefghi");\r
169 +   fail_if(strcmp("e1435dfb334ec81f2bdd5b0aa45969586e7681c0", result) != 0,\r
170 +          "SHA1 results for notmuch_sha1_of_string do not match");\r
171 +}\r
172 +END_TEST\r
173 +\r
174 +START_TEST (test_sha1_of_file)\r
175 +{\r
176 +   char filename[20] = "";\r
177 +   char *result;\r
178 +   int fd;\r
179 +   int i;\r
180 +\r
181 +   strncpy (filename, "/tmp/notmuch.XXXXXX", sizeof (filename));\r
182 +   fd = mkstemp (filename);\r
183 +\r
184 +   fail_if (fd == -1,\r
185 +           "Unable to create temporary file for SHA1 test");\r
186 +\r
187 +   for (i = 0; i < 13993; i++)\r
188 +      (void) write(fd, "\0", 1);\r
189 +\r
190 +   close(fd);\r
191 +\r
192 +   result = notmuch_sha1_of_file(filename);\r
193 +\r
194 +   unlink(filename);\r
195 +\r
196 +   fail_if (strcmp ("db38f0e9aa8eb5bcd0d73f3d1ed84d71712cc0ab", result) != 0,\r
197 +           "SHA1 results for notmuch_sha1_of_file do not match");\r
198 +}\r
199 +END_TEST\r
200 +\r
201 +Suite *\r
202 +notmuch_sha1_suite (void)\r
203 +{\r
204 +   Suite *s = suite_create ("NotMuch SHA1");\r
205 +   \r
206 +   /* SHA1 test cases */\r
207 +   TCase *tc_sha1 = tcase_create ("SHA1");\r
208 +   tcase_add_test (tc_sha1, test_sha1_of_string);\r
209 +   tcase_add_test (tc_sha1, test_sha1_of_file);\r
210 +   suite_add_tcase (s, tc_sha1);\r
211 +\r
212 +   return s;\r
213 +}\r
214 diff --git a/checks/notmuch-check-tags.c b/checks/notmuch-check-tags.c\r
215 new file mode 100644\r
216 index 0000000..5a3b5c7\r
217 --- /dev/null\r
218 +++ b/checks/notmuch-check-tags.c\r
219 @@ -0,0 +1,84 @@\r
220 +/* notmuch - Not much of an email program, (just index and search)\r
221 + *\r
222 + * Copyright © 2009 Jeffrey C. Ollie\r
223 + *\r
224 + * This program is free software: you can redistribute it and/or modify\r
225 + * it under the terms of the GNU General Public License as published by\r
226 + * the Free Software Foundation, either version 3 of the License, or\r
227 + * (at your option) any later version.\r
228 + *\r
229 + * This program is distributed in the hope that it will be useful,\r
230 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
231 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
232 + * GNU General Public License for more details.\r
233 + *\r
234 + * You should have received a copy of the GNU General Public License\r
235 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
236 + *\r
237 + * Authors: Jeffrey C. Ollie <jeff@ocjtech.us>\r
238 + */\r
239 +\r
240 +#include <check.h>\r
241 +#include <string.h>\r
242 +#include <unistd.h>\r
243 +\r
244 +#include "notmuch-private.h"\r
245 +#include "notmuch-check.h"\r
246 +\r
247 +START_TEST (test_tags_create)\r
248 +{\r
249 +   notmuch_tags_t *tags;\r
250 +\r
251 +   tags = _notmuch_tags_create(NULL);\r
252 +\r
253 +   fail_if (tags == NULL,\r
254 +           "No tags structure was able to be allocated");\r
255 +\r
256 +   fail_if (notmuch_tags_has_more (tags),\r
257 +           "Tags shouldn't have anything in it yet");\r
258 +\r
259 +   fail_unless (notmuch_tags_get (tags) == NULL,\r
260 +               "Shouldn't be able to get anything out of an empty tag set.");\r
261 +\r
262 +   notmuch_tags_destroy (tags);\r
263 +}\r
264 +END_TEST\r
265 +\r
266 +START_TEST (test_tags_sorting)\r
267 +{\r
268 +   notmuch_tags_t *tags;\r
269 +   char tag1[] = "1";\r
270 +   char tag2[] = "2";\r
271 +\r
272 +   tags = _notmuch_tags_create(NULL);\r
273 +\r
274 +   _notmuch_tags_add_tag(tags, tag2);\r
275 +   _notmuch_tags_add_tag(tags, tag1);\r
276 +\r
277 +   _notmuch_tags_prepare_iterator(tags);\r
278 +\r
279 +   fail_unless(strcmp (tag1, notmuch_tags_get(tags)) == 0,\r
280 +              "Tags failed to be sorted properly.");\r
281 +\r
282 +   notmuch_tags_advance (tags);\r
283 +\r
284 +   fail_unless(strcmp (tag2, notmuch_tags_get(tags)) == 0,\r
285 +              "Tags failed to be sorted properly.");\r
286 +\r
287 +   notmuch_tags_destroy (tags);\r
288 +}\r
289 +END_TEST\r
290 +\r
291 +Suite *\r
292 +notmuch_tags_suite (void)\r
293 +{\r
294 +   Suite *s = suite_create ("NotMuch Tags");\r
295 +   \r
296 +   /* Tags test cases */\r
297 +   TCase *tc_tags = tcase_create ("Tags");\r
298 +   tcase_add_test (tc_tags, test_tags_create);\r
299 +   tcase_add_test (tc_tags, test_tags_sorting);\r
300 +   suite_add_tcase (s, tc_tags);\r
301 +\r
302 +   return s;\r
303 +}\r
304 diff --git a/checks/notmuch-check.c b/checks/notmuch-check.c\r
305 new file mode 100644\r
306 index 0000000..378a391\r
307 --- /dev/null\r
308 +++ b/checks/notmuch-check.c\r
309 @@ -0,0 +1,40 @@\r
310 +/* notmuch - Not much of an email program, (just index and search)\r
311 + *\r
312 + * Copyright © 2009 Jeffrey C. Ollie\r
313 + *\r
314 + * This program is free software: you can redistribute it and/or modify\r
315 + * it under the terms of the GNU General Public License as published by\r
316 + * the Free Software Foundation, either version 3 of the License, or\r
317 + * (at your option) any later version.\r
318 + *\r
319 + * This program is distributed in the hope that it will be useful,\r
320 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
321 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
322 + * GNU General Public License for more details.\r
323 + *\r
324 + * You should have received a copy of the GNU General Public License\r
325 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
326 + *\r
327 + * Authors: Jeffrey C. Ollie <jeff@ocjtech.us>\r
328 + */\r
329 +\r
330 +#include <check.h>\r
331 +\r
332 +#include "notmuch-private.h"\r
333 +#include "notmuch-check.h"\r
334 +\r
335 +int\r
336 +main (void)\r
337 +{\r
338 +   int number_failed;\r
339 +\r
340 +   SRunner *sr = srunner_create (NULL);\r
341 +   srunner_add_suite (sr, notmuch_sha1_suite ());\r
342 +   srunner_add_suite (sr, notmuch_tags_suite ());\r
343 +\r
344 +   srunner_run_all (sr, CK_VERBOSE);\r
345 +   number_failed = srunner_ntests_failed (sr);\r
346 +   srunner_free (sr);\r
347 +\r
348 +   return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\r
349 +}\r
350 diff --git a/checks/notmuch-check.h b/checks/notmuch-check.h\r
351 new file mode 100644\r
352 index 0000000..f2ef07a\r
353 --- /dev/null\r
354 +++ b/checks/notmuch-check.h\r
355 @@ -0,0 +1,24 @@\r
356 +/* notmuch - Not much of an email program, (just index and search)\r
357 + *\r
358 + * Copyright © 2009 Jeffrey C. Ollie\r
359 + *\r
360 + * This program is free software: you can redistribute it and/or modify\r
361 + * it under the terms of the GNU General Public License as published by\r
362 + * the Free Software Foundation, either version 3 of the License, or\r
363 + * (at your option) any later version.\r
364 + *\r
365 + * This program is distributed in the hope that it will be useful,\r
366 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
367 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
368 + * GNU General Public License for more details.\r
369 + *\r
370 + * You should have received a copy of the GNU General Public License\r
371 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
372 + *\r
373 + * Authors: Jeffrey C. Ollie <jeff@ocjtech.us>\r
374 + */\r
375 +\r
376 +#include <check.h>\r
377 +\r
378 +Suite *notmuch_sha1_suite (void);\r
379 +Suite *notmuch_tags_suite (void);\r
380 diff --git a/configure b/configure\r
381 index e55f067..9e76f09 100755\r
382 --- a/configure\r
383 +++ b/configure\r
384 @@ -61,6 +61,14 @@ else\r
385      have_valgrind=\r
386  fi\r
387  \r
388 +if pkg-config --exists check > /dev/null 2>&1; then\r
389 +    echo "Checking for the Check unit test framework... Yes."\r
390 +    have_check=1\r
391 +else\r
392 +    echo "Checking for the Check unit test framework... No."\r
393 +    have_check=\r
394 +fi\r
395 +\r
396  if [ $errors -gt 0 ]; then\r
397      cat <<EOF\r
398  \r
399 -- \r
400 1.6.5.2\r
401 \r