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