New upstream release.
[debian/iodine.git] / tests / encoding.c
1 /*
2  * Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include <check.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include "encoding.h"
23 #include "test.h"
24
25 struct tuple
26 {
27         char *a;
28         char *b;
29 } dottests[] = {
30         { "aaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
31           "aaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaa"},
32         { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
33           "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."},
34         { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
35           "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
36         { "abc123", "abc123" },
37         { NULL, NULL }
38 };
39
40 START_TEST(test_inline_dotify)
41 {
42         unsigned i;
43         char temp[1024];
44         char *b;
45
46         i = 0;
47         while (dottests[i].a) {
48                 memset(temp, 0, sizeof(temp));
49                 strcpy(temp, dottests[i].a);
50                 b = temp;
51                 inline_dotify(b, sizeof(temp));
52
53                 fail_unless(strcmp(dottests[i].b, temp) == 0,
54                                 "'%s' != '%s'", temp, dottests[i].b);
55                 i++;
56         }
57 }
58 END_TEST
59
60 START_TEST(test_inline_undotify)
61 {
62         unsigned i;
63         char temp[1024];
64         char *b;
65
66         i = 0;
67         while (dottests[i].a) {
68                 memset(temp, 0, sizeof(temp));
69                 strcpy(temp, dottests[i].b);
70                 b = temp;
71                 inline_undotify(b, sizeof(temp));
72
73                 fail_unless(strcmp(dottests[i].a, temp) == 0,
74                                 "'%s' != '%s'", temp, dottests[i].a);
75                 i++;
76         }
77 }
78 END_TEST
79
80 TCase *
81 test_encoding_create_tests()
82 {
83         TCase *tc;
84
85         tc = tcase_create("Encoding");
86         tcase_add_test(tc, test_inline_dotify);
87         tcase_add_test(tc, test_inline_undotify);
88
89         return tc;
90 }