Line data Source code
1 : /* t-mbox-util.c - Module test for mbox-util.c
2 : * Copyright (C) 2015 Werner Koch
3 : *
4 : * This file is part of GnuPG.
5 : *
6 : * GnuPG is free software; you can redistribute it and/or modify
7 : * it under the terms of the GNU General Public License as published by
8 : * the Free Software Foundation; either version 3 of the License, or
9 : * (at your option) any later version.
10 : *
11 : * GnuPG is distributed in the hope that it will be useful,
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : * GNU General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public License
17 : * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : #include <config.h>
21 : #include <stdio.h>
22 : #include <stdlib.h>
23 : #include <string.h>
24 :
25 : #include "util.h"
26 : #include "mbox-util.h"
27 :
28 : #define pass() do { ; } while(0)
29 : #define fail(a) do { fprintf (stderr, "%s:%d: test %d failed\n",\
30 : __FILE__,__LINE__, (a)); \
31 : exit (1); \
32 : } while(0)
33 :
34 :
35 : static void
36 1 : run_test (void)
37 : {
38 : static struct
39 : {
40 : const char *userid;
41 : const char *mbox;
42 : } testtbl[] =
43 : {
44 : { "Werner Koch <wk@gnupg.org>", "wk@gnupg.org" },
45 : { "<wk@gnupg.org>", "wk@gnupg.org" },
46 : { "wk@gnupg.org", "wk@gnupg.org" },
47 : { "wk@gnupg.org ", NULL },
48 : { " wk@gnupg.org", NULL },
49 : { "Werner Koch (test) <wk@gnupg.org>", "wk@gnupg.org" },
50 : { "Werner Koch <wk@gnupg.org> (test)", "wk@gnupg.org" },
51 : { "Werner Koch <wk@gnupg.org (test)", NULL },
52 : { "Werner Koch <wk@gnupg.org >", NULL },
53 : { "Werner Koch <wk@gnupg.org", NULL },
54 : { "", NULL },
55 : { "@", NULL },
56 : { "bar <>", NULL },
57 : { "<foo@example.org>", "foo@example.org" },
58 : { "<foo.@example.org>", "foo.@example.org" },
59 : { "<.foo.@example.org>", ".foo.@example.org" },
60 : { "<foo..@example.org>", "foo..@example.org" },
61 : { "<foo..bar@example.org>", "foo..bar@example.org" },
62 : { "<foo@example.org.>", NULL },
63 : { "<foo@example..org>", NULL },
64 : { "<foo@.>", NULL },
65 : { "<@example.org>", NULL },
66 : { "<foo@@example.org>", NULL },
67 : { "<@foo@example.org>", NULL },
68 : { "<foo@example.org> ()", "foo@example.org" },
69 : { "<fo()o@example.org> ()", "fo()o@example.org" },
70 : { "<fo()o@example.org> ()", "fo()o@example.org" },
71 : { "fo()o@example.org", NULL},
72 : { "Mr. Foo <foo@example.org><bar@example.net>", "foo@example.org"},
73 : { NULL, NULL }
74 : };
75 : int idx;
76 :
77 30 : for (idx=0; testtbl[idx].userid; idx++)
78 : {
79 29 : char *mbox = mailbox_from_userid (testtbl[idx].userid);
80 :
81 29 : if (!testtbl[idx].mbox)
82 : {
83 15 : if (mbox)
84 0 : fail (idx);
85 : }
86 14 : else if (!mbox)
87 0 : fail (idx);
88 14 : else if (strcmp (mbox, testtbl[idx].mbox))
89 0 : fail (idx);
90 : }
91 1 : }
92 :
93 :
94 : int
95 1 : main (int argc, char **argv)
96 : {
97 : (void)argc;
98 : (void)argv;
99 :
100 1 : run_test ();
101 :
102 1 : return 0;
103 : }
|