aboutsummaryrefslogtreecommitdiffstats
path: root/g10/t-mailbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/t-mailbox.c')
-rw-r--r--g10/t-mailbox.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/g10/t-mailbox.c b/g10/t-mailbox.c
new file mode 100644
index 000000000..aa7cf3399
--- /dev/null
+++ b/g10/t-mailbox.c
@@ -0,0 +1,127 @@
+/* t-mailbox.c - Module test for mailbox.c
+ * Copyright (C) 2015 Werner Koch
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gpg.h"
+#include "util.h"
+#include "main.h"
+
+#define pass() do { ; } while(0)
+#define fail(a) do { fprintf (stderr, "%s:%d: test %d failed\n",\
+ __FILE__,__LINE__, (a)); \
+ exit (1); \
+ } while(0)
+
+
+void *
+gcry_malloc (size_t n)
+{
+ return malloc (n);
+}
+
+
+char *
+gcry_strdup (const char *string)
+{
+ return strdup (string);
+}
+
+
+void
+gcry_free (void *a)
+{
+ if (a)
+ free (a);
+}
+
+
+
+static void
+run_test (void)
+{
+ static struct
+ {
+ const char *userid;
+ const char *mbox;
+ } testtbl[] =
+ {
+ { "Werner Koch <[email protected]>", "[email protected]" },
+ { "[email protected] ", NULL },
+ { " [email protected]", NULL },
+ { "Werner Koch (test) <[email protected]>", "[email protected]" },
+ { "Werner Koch <[email protected]> (test)", "[email protected]" },
+ { "Werner Koch <[email protected] (test)", NULL },
+ { "Werner Koch <[email protected] >", NULL },
+ { "Werner Koch <[email protected]", NULL },
+ { "", NULL },
+ { "@", NULL },
+ { "bar <>", NULL },
+ { "<[email protected].>", NULL },
+ { "<[email protected]>", NULL },
+ { "<foo@.>", NULL },
+ { "<@example.org>", NULL },
+ { "<foo@@example.org>", NULL },
+ { "<@[email protected]>", NULL },
+ { "<fo()[email protected]> ()", "fo()[email protected]" },
+ { "<fo()[email protected]> ()", "fo()[email protected]" },
+ { "fo()[email protected]", NULL},
+ { NULL, NULL }
+ };
+ int idx;
+
+ for (idx=0; testtbl[idx].userid; idx++)
+ {
+ char *mbox = mailbox_from_userid (testtbl[idx].userid);
+
+ if (!testtbl[idx].mbox)
+ {
+ if (mbox)
+ fail (idx);
+ }
+ else if (!mbox)
+ fail (idx);
+ else if (strcmp (mbox, testtbl[idx].mbox))
+ fail (idx);
+ }
+}
+
+
+int
+main (int argc, char **argv)
+{
+ (void)argc;
+ (void)argv;
+
+ run_test ();
+
+ return 0;
+}