Fix indent.
[libidn.git] / tests / tst_tld.c
blobab6a3ac7dddde2dfd01bb95dabf3506e62a36f43
1 /* tst_tld.c --- Self tests for tld_*().
2 * Copyright (C) 2004 Simon Josefsson.
4 * This file is part of GNU Libidn.
6 * GNU Libidn 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 2 of the License, or
9 * (at your option) any later version.
11 * GNU Libidn 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.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Libidn; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #if HAVE_CONFIG_H
23 # include "config.h"
24 #endif
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <string.h>
31 #include <stringprep.h>
32 #include <tld.h>
34 #include "utils.h"
36 struct tld
38 const char *name;
39 const char *tld;
40 size_t inlen;
41 uint32_t in[100];
42 int rc;
43 int errpos;
46 static const struct tld tld[] = {
48 "Simple valid French domain",
49 "fr",
51 {0x00E0, 0x00E2, 0x00E6},
52 TLD_SUCCESS},
54 "Simple invalid French domain",
55 "fr",
57 {0x00E0, 0x00E2, 0x00E6, 0x4711, 0x0042},
58 TLD_INVALID,
62 void
63 doit (void)
65 size_t i;
66 const Tld_table *tldtable;
67 size_t errpos;
68 int rc;
70 for (i = 0; i < sizeof (tld) / sizeof (tld[0]); i++)
72 if (debug)
73 printf ("TLD entry %d: %s\n", i, tld[i].name);
75 if (debug)
77 printf ("in:\n");
78 ucs4print (tld[i].in, tld[i].inlen);
81 tldtable = tld_default_table (tld[i].tld, NULL);
82 if (tldtable == NULL)
84 fail ("TLD entry %d tld_get_table (%s)\n", i, tld[i].tld);
85 if (debug)
86 printf ("FATAL\n");
87 continue;
90 rc = tld_check_4t (tld[i].in, tld[i].inlen, &errpos, tldtable);
91 if (rc != tld[i].rc)
93 fail ("TLD entry %d failed: %d\n", i, rc);
94 if (debug)
95 printf ("FATAL\n");
96 continue;
99 if (debug)
100 printf ("returned %d expected %d\n", rc, tld[i].rc);
102 if (rc != tld[i].rc)
104 fail ("TLD entry %d failed\n", i);
105 if (debug)
106 printf ("ERROR\n");
108 else if (rc == TLD_INVALID)
110 if (debug)
111 printf ("returned errpos %d expected errpos %d\n",
112 errpos, tld[i].errpos);
114 if (tld[i].errpos != errpos)
116 fail ("TLD entry %d failed because errpos %d != %d\n", i,
117 tld[i].errpos, errpos);
118 if (debug)
119 printf ("ERROR\n");
122 else if (debug)
123 printf ("OK\n");