Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel
[citadel.git] / libcitadel / tests / stripallbut_test.c
1 /*
2  *  CUnit - A Unit testing framework library for C.
3  *  Copyright (C) 2001  Anil Kumar
4  *  
5  *  This library is open source software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Library General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Library General Public License for more details.
14  */
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <stdarg.h>
20
21     
22 #ifndef CUNIT_AUTOMATED_H_SEEN
23 #define CUNIT_AUTOMATED_H_SEEN
24
25 #include <CUnit/CUnit.h>
26 #include <CUnit/Basic.h>
27 #include <CUnit/TestDB.h>
28
29
30 CU_EXPORT void         CU_automated_run_tests(void);
31 CU_EXPORT CU_ErrorCode CU_list_tests_to_file(void);
32 CU_EXPORT void         CU_set_output_filename(const char* szFilenameRoot);
33
34
35 #endif  /*  CUNIT_AUTOMATED_H_SEEN  */
36
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <ctype.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <assert.h>
43
44 #include "../lib/libcitadel.h"
45
46 static void TestStripAllBut(void) {
47         int i;
48         long l;
49
50         char *teststrings[] = {
51                 "Nmm <fghjk> tyutyu",
52                 "Sdd <> ghhjjkk",
53                 "<>",
54                 "",
55                 "Sdd <",
56                 "Df Ghjkl>",
57                 ">< bggt",
58                 "FSDFSDFSDFSDF<><><>bggt",
59                 "FSDFSDFSDF<><eoeo><>bggt",
60                 "Abc<QWER>",
61                 "><",
62                 "Zxcv<dy<<lkj>>>"
63         };
64
65         char *strippedstrings[] = {
66                 "fghjk",
67                 "",
68                 "",
69                 "",
70                 "Sdd <",
71                 "Df Ghjkl>",
72                 ">< bggt",
73                 "FSDFSDFSDFSDF<><><>bggt",
74                 "FSDFSDFSDF<><eoeo><>bggt",
75                 "QWER",
76                 "><",
77                 "lkj"
78         };
79
80         long strippedlens[] = {
81                 5,
82                 0,
83                 0,
84                 0,
85                 5,
86                 9,
87                 7,
88                 23,
89                 24,
90                 4,
91                 2,
92                 3
93         };
94
95         char foo[128];
96
97         for (i=0; i<(sizeof(teststrings) / sizeof (char *)); ++i) {
98                 strcpy(foo, teststrings[i]);
99                 l = stripallbut(foo, '<', '>');
100
101                 CU_ASSERT_STRING_EQUAL(foo, strippedstrings[i]);
102                 CU_ASSERT_EQUAL(strlen(foo), strippedlens[i]);
103         }
104 }
105
106
107
108 static void AddStringToolsTests(void)
109 {
110         CU_pSuite pGroup = NULL;
111         CU_pTest pTest = NULL;
112
113         pGroup = CU_add_suite("TestStringTools", NULL, NULL);
114         pTest = CU_add_test(pGroup, "testStripAllBut", TestStripAllBut);
115 }
116
117 int main(int argc, char* argv[])
118 {
119         setvbuf(stdout, NULL, _IONBF, 0);
120
121         StartLibCitadel(8);
122
123         CU_set_output_filename("TestAutomated");
124         if (CU_initialize_registry()) {
125                 printf("\nInitialize of test Registry failed.");
126                 return 1;
127         }
128         AddStringToolsTests();
129         
130         printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
131     
132                 
133         CU_cleanup_registry();
134         
135         return 0;
136 }