[svn-upgrade] Integrating new upstream version, iodine (0.4.1)
[debian/iodine.git] / tests / encoding.c
1 /*
2  * Copyright (c) 2006-2007 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           "aaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.a"},
32         { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 
33           "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."},
34         { "abc123", "abc123" },
35         { NULL, NULL }
36 };
37
38 START_TEST(test_inline_dotify)
39 {
40         unsigned i;
41         char temp[1024];
42         char *b;
43
44         i = 0;
45         while (dottests[i].a) {
46                 memset(temp, 0, sizeof(temp));
47                 strcpy(temp, dottests[i].a);
48                 b = temp;
49                 inline_dotify(b, sizeof(temp));
50
51                 fail_unless(strcmp(dottests[i].b, temp) == 0,
52                                 va_str("'%s' != '%s'", temp, dottests[i].b));
53                 i++;
54         }
55 }
56 END_TEST
57
58 START_TEST(test_inline_undotify)
59 {
60         unsigned i;
61         char temp[1024];
62         char *b;
63
64         i = 0;
65         while (dottests[i].a) {
66                 memset(temp, 0, sizeof(temp));
67                 strcpy(temp, dottests[i].b);
68                 b = temp;
69                 inline_undotify(b, sizeof(temp));
70
71                 fail_unless(strcmp(dottests[i].a, temp) == 0,
72                                 va_str("'%s' != '%s'", temp, dottests[i].a));
73                 i++;
74         }
75 }
76 END_TEST
77
78 TCase *
79 test_encoding_create_tests()
80 {
81         TCase *tc;
82
83         tc = tcase_create("Encoding");
84         tcase_add_test(tc, test_inline_dotify);
85         tcase_add_test(tc, test_inline_undotify);
86
87         return tc;
88 }