diff options
author | Werner Koch <[email protected]> | 2015-02-24 16:43:57 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2015-02-24 16:46:22 +0000 |
commit | 93fa3d5c1760f3fee5412fb29d58fbd60db16ea9 (patch) | |
tree | b89b401ea5231a9300aca6a9f299d693c36923bd /g10/t-mailbox.c | |
parent | common: Add another test case to zb32.c (diff) | |
download | gnupg-93fa3d5c1760f3fee5412fb29d58fbd60db16ea9.tar.gz gnupg-93fa3d5c1760f3fee5412fb29d58fbd60db16ea9.zip |
gpg: Add function to extract the mailbox.
* g10/misc.c (has_invalid_email_chars, is_valid_mailbox)
(is_valid_user_id): Move to ...
* g10/mailbox.c: new file.
(string_has_ctrl_or_space, has_dotdot_after_at): New.
(has_invalid_email_chars): New.
* g10/t-mailbox.c: New.
* g10/Makefile.am (module_tests): Add t-mailbox.
(t_mailbox_SOURCES, t_mailbox_LDADD): New.
--
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/t-mailbox.c')
-rw-r--r-- | g10/t-mailbox.c | 127 |
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]>", "[email protected]" }, + { "[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]>", "[email protected]" }, + { "<[email protected]>", "[email protected]" }, + { "<[email protected]>", "[email protected]" }, + { "<[email protected]>", "[email protected]" }, + { "<[email protected]>", "[email protected]" }, + { "<[email protected].>", NULL }, + { "<[email protected]>", NULL }, + { "<foo@.>", NULL }, + { "<@example.org>", NULL }, + { "<foo@@example.org>", NULL }, + { "<@[email protected]>", NULL }, + { "<[email protected]> ()", "[email protected]" }, + { "<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; +} |