Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel
[citadel.git] / libcitadel / tests / stripallbut_test.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <ctype.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <assert.h>
7
8 #include "../lib/libcitadel.h"
9
10 main() {
11         int i;
12         long l;
13
14         char *teststrings[] = {
15                 "Nmm <fghjk> tyutyu",
16                 "Sdd <> ghhjjkk",
17                 "<>",
18                 "",
19                 "Sdd <",
20                 "Df Ghjkl>",
21                 ">< bggt",
22                 "FSDFSDFSDFSDF<><><>bggt",
23                 "FSDFSDFSDF<><eoeo><>bggt",
24                 "Abc<QWER>",
25                 "><",
26                 "Zxcv<dy<<lkj>>>"
27         };
28
29         char *strippedstrings[] = {
30                 "fghjk",
31                 "",
32                 "",
33                 "",
34                 "Sdd <",
35                 "Df Ghjkl>",
36                 ">< bggt",
37                 "FSDFSDFSDFSDF<><><>bggt",
38                 "FSDFSDFSDF<><eoeo><>bggt",
39                 "QWER",
40                 "><",
41                 "lkj"
42         };
43
44         long strippedlens[] = {
45                 5,
46                 0,
47                 0,
48                 0,
49                 5,
50                 9,
51                 7,
52                 23,
53                 24,
54                 4,
55                 2,
56                 3
57         };
58
59         char foo[128];
60
61         for (i=0; i<(sizeof(teststrings) / sizeof (char *)); ++i) {
62                 printf("Testing stripallbut()\n");
63                 strcpy(foo, teststrings[i]);
64                 l = stripallbut(foo, '<', '>');
65
66                 assert(!strcmp(foo, strippedstrings[i]));
67                 assert(strlen(foo) == strippedlens[i]);
68         }
69
70         exit(0);
71 }