Tests: add StrBufStripAllBut and compare it to stripallbut
[citadel] / libcitadel / tests / stringbuf_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 #include "stringbuf_test.h"
22 #define SHOW_ME_VAPPEND_PRINTF
23 #include "../lib/libcitadel.h"
24
25 int Quiet = 0;
26 /*
27  * Stolen from wc_printf; we need to test that other printf too... 
28  */
29 static void TEST_StrBufAppendPrintf(StrBuf *WBuf, const char *format,...)
30 {
31         va_list arg_ptr;
32
33         if (WBuf == NULL)
34                 return;
35
36         va_start(arg_ptr, format);
37         StrBufVAppendPrintf(WBuf, format, arg_ptr);
38         va_end(arg_ptr);
39 }
40
41 static void TestRevalidateStrBuf(StrBuf *Buf)
42 {
43         CU_ASSERT(strlen(ChrPtr(Buf)) == StrLength(Buf));
44 }
45
46
47 static void TestCreateBuf(void)
48 {
49         StrBuf *Buf;
50         StrBuf *Buf2;
51         long len;
52         long i;
53
54         Buf = NewStrBuf();
55         CU_ASSERT(Buf != NULL);
56         FreeStrBuf(&Buf);
57
58         Buf = NewStrBufPlain(ChrPtr(NULL), StrLength(NULL));
59         CU_ASSERT(Buf != NULL);
60         FreeStrBuf(&Buf);
61
62         /* make it alloc a bigger buffer... */
63         Buf = NewStrBufPlain(NULL, SIZ);
64         CU_ASSERT(Buf != NULL);
65         FreeStrBuf(&Buf);
66
67
68         Buf = NewStrBufDup(NULL);
69         CU_ASSERT(Buf != NULL);
70         StrBufPlain(Buf, "abc", -1);
71         TestRevalidateStrBuf(Buf);
72         StrBufPlain(Buf, HKEY("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"));
73         TestRevalidateStrBuf(Buf);
74         FreeStrBuf(&Buf);
75
76         FlushStrBuf(NULL);
77         FLUSHStrBuf(NULL);
78
79         CU_ASSERT(Buf == NULL);
80         Buf = NewStrBufPlain(HKEY("ABC"));
81         TestRevalidateStrBuf(Buf);
82         CU_ASSERT(StrLength(Buf) == 3);
83         CU_ASSERT_NSTRING_EQUAL("ABC", ChrPtr(Buf), 3);
84
85         len = StrLength(Buf);
86         for (i=0; i< 500; i ++)
87         {
88                 StrBufAppendBufPlain(Buf, HKEY("ABC"), 0);
89                 len += 3;
90                 CU_ASSERT(StrLength(Buf) == len);
91         }       
92         StrBufShrinkToFit(Buf, 1);
93         FlushStrBuf(Buf);
94         CU_ASSERT(StrLength(Buf) == 0);
95         ReAdjustEmptyBuf(Buf, 1, 1);
96         TestRevalidateStrBuf(Buf);
97         FreeStrBuf(&Buf);
98         CU_ASSERT(Buf == NULL);
99         
100         Buf = NewStrBufPlain(HKEY("ABC"));
101         TestRevalidateStrBuf(Buf);
102         len = StrLength(Buf);
103         for (i=0; i< 500; i ++)
104         {
105                 StrBufAppendPrintf(Buf, "%s", "ABC");
106                 len += 3;
107                 CU_ASSERT(StrLength(Buf) == len);               
108         }
109         TestRevalidateStrBuf(Buf);
110         StrBufShrinkToFit(Buf, 1);
111         TestRevalidateStrBuf(Buf);
112         FreeStrBuf(&Buf);
113
114
115         Buf = NewStrBufPlain(HKEY("ABC"));
116         Buf2 = NewStrBufPlain(HKEY("------"));
117         TestRevalidateStrBuf(Buf);
118         len = StrLength(Buf);
119         for (i=0; i< 50; i ++)
120         {
121                 StrBufPrintf(Buf, "%s", ChrPtr(Buf2));
122                 CU_ASSERT(StrLength(Buf) == StrLength(Buf2));           
123
124                 StrBufAppendBufPlain(Buf2, HKEY("ABCDEFG"), 0);
125         }
126         TestRevalidateStrBuf(Buf);
127         StrBufShrinkToFit(Buf, 1);
128         TestRevalidateStrBuf(Buf);
129         FreeStrBuf(&Buf);
130         FreeStrBuf(&Buf2);      
131
132
133         Buf = NewStrBufPlain(HKEY("ABC"));
134         TestRevalidateStrBuf(Buf);
135         len = StrLength(Buf);
136         for (i=0; i< 500; i ++)
137         {
138                 TEST_StrBufAppendPrintf(Buf, "%s", "ABC");
139                 len += 3;
140                 CU_ASSERT(StrLength(Buf) == len);               
141         }
142         TestRevalidateStrBuf(Buf);
143         StrBufShrinkToFit(Buf, 1);
144         TestRevalidateStrBuf(Buf);
145
146
147         Buf2 = NewStrBufDup(Buf);
148         CU_ASSERT(StrLength(Buf) == StrLength(Buf2));           
149         
150         CU_ASSERT_NSTRING_EQUAL(ChrPtr(Buf2), ChrPtr(Buf), StrLength(Buf2));
151         
152         CU_ASSERT(StrBufIsNumber(Buf) == 0);
153
154         FlushStrBuf(Buf2);
155         CU_ASSERT(StrLength(Buf2) == 0);
156
157         FLUSHStrBuf(Buf);
158         CU_ASSERT(StrLength(Buf) == 0);
159
160         HFreeStrBuf(NULL);
161         HFreeStrBuf(Buf2);
162         CU_ASSERT(Buf2 != NULL);
163
164         FreeStrBuf(&Buf);
165         CU_ASSERT(Buf == NULL);
166         
167 }
168
169
170
171
172 static void TestBufNumbers(void)
173 {
174         StrBuf *Buf;
175         StrBuf *Buf2;
176         StrBuf *Buf3;
177         char *ch;
178         int i;
179
180         Buf2 = NewStrBuf();
181         Buf3 = NewStrBufPlain(HKEY("abcd"));
182         Buf = NewStrBufPlain(HKEY("123456"));
183         CU_ASSERT(StrBufIsNumber(Buf) == 1);
184         CU_ASSERT(StrBufIsNumber(NULL) == 0);
185         CU_ASSERT(StrBufIsNumber(Buf2) == 0);
186         CU_ASSERT(StrBufIsNumber(Buf3) == 0);
187
188         CU_ASSERT(StrTol(Buf) == 123456);
189         CU_ASSERT(StrTol(NULL) == 0);
190         CU_ASSERT(StrTol(Buf2) == 0);
191
192         CU_ASSERT(StrToi(Buf) == 123456);
193         CU_ASSERT(StrToi(NULL) == 0);
194         CU_ASSERT(StrToi(Buf2) == 0);
195         ch = SmashStrBuf(NULL);
196         CU_ASSERT(ch == NULL);
197         i = StrLength(Buf);
198         ch = SmashStrBuf(&Buf);
199         CU_ASSERT(strlen(ch) == i);
200         free(ch);
201         FreeStrBuf(&Buf2);
202         FreeStrBuf(&Buf3);
203 }
204
205 static void TestStrBufPeek(void)
206 {
207         StrBuf *Buf;
208         const char *pch;
209
210         Buf = NewStrBufPlain(HKEY("0123456"));
211         pch = ChrPtr(Buf);
212
213         CU_ASSERT(StrBufPeek(NULL, pch + 4, -1, 'A') == -1);
214
215         CU_ASSERT(StrBufPeek(Buf, pch + 4, -1, 'A') == 4);
216         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
217
218         CU_ASSERT(StrBufPeek(Buf, pch - 1, -1, 'A') == -1);
219         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
220
221         CU_ASSERT(StrBufPeek(Buf, pch + 10, -1, 'A') == -1);
222         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
223
224         CU_ASSERT(StrBufPeek(Buf, NULL, -1, 'A') == -1);
225         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
226
227         CU_ASSERT(StrBufPeek(Buf, NULL, 10, 'A') == -1);
228         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123A56");
229
230         CU_ASSERT(StrBufPeek(Buf, NULL, 5, 'A') == 5);
231         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "0123AA6");
232         FreeStrBuf(&Buf);
233 }
234
235 static void TestBufStringManipulation(void)
236 {
237         long len, i = 0;
238         StrBuf *dest = NewStrBuf ();
239         StrBuf *Buf = NewStrBufPlain(HKEY("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"));
240
241         StrBufSub(dest, Buf, -5, i);
242         len = StrLength(Buf);
243         for (i = 0; i < len + 10; i++)
244         {
245                 StrBufSub(dest, Buf, 5, i);
246                 if (i + 5 < len)
247                 {
248                         CU_ASSERT(StrLength(dest) == i);
249                 }
250                 else
251                 {
252                         CU_ASSERT(StrLength(dest) == len - 5);
253                 }
254         }
255         FreeStrBuf(&dest);
256         dest = NewStrBuf ();
257         StrBufSub(dest, Buf, -5, 200);
258
259         StrBufCutLeft(Buf, 5);
260         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
261         CU_ASSERT(StrLength(Buf) == 95);
262
263         StrBufCutRight(Buf, 5);
264         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345");
265         CU_ASSERT(StrLength(Buf) == 90);
266
267         StrBufCutAt(Buf, 80, NULL);
268         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"67890123456789012345678901234567890123456789012345678901234567890123456789012345");
269         CU_ASSERT(StrLength(Buf) == 80);
270
271         StrBufCutAt(Buf, -1, ChrPtr(Buf) + 70);
272         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"6789012345678901234567890123456789012345678901234567890123456789012345");
273         CU_ASSERT(StrLength(Buf) == 70);
274
275
276         StrBufCutAt(Buf, 0, ChrPtr(Buf) + 60);
277         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"678901234567890123456789012345678901234567890123456789012345");
278         CU_ASSERT(StrLength(Buf) == 60);
279
280         StrBufCutAt(Buf, 0, ChrPtr(Buf) + 70);
281         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"678901234567890123456789012345678901234567890123456789012345");
282         CU_ASSERT(StrLength(Buf) == 60);
283
284         StrBufCutAt(Buf, 70, NULL);
285         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"678901234567890123456789012345678901234567890123456789012345");
286         CU_ASSERT(StrLength(Buf) == 60);
287
288
289         StrBufCutLeft(Buf, 70);
290         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"");
291         CU_ASSERT(StrLength(Buf) == 0);
292
293         StrBufPlain(Buf, HKEY("678901234567890123456789012345678901234567890123456789012345"));
294         StrBufCutRight(Buf, 70);
295         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"");
296         CU_ASSERT(StrLength(Buf) == 0);
297
298         FreeStrBuf(&dest);
299         FreeStrBuf(&Buf);
300
301         Buf = NewStrBufPlain(HKEY(" \tabc\t "));
302         StrBufTrim(Buf);
303         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf),"abc");
304         CU_ASSERT(StrLength(Buf) == 3);
305
306         StrBufUpCase(NULL);
307         FlushStrBuf(Buf);
308         StrBufUpCase(Buf);
309         StrBufPlain(Buf, HKEY("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"));
310         StrBufUpCase(Buf);
311
312         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
313
314
315         StrBufLowerCase(NULL);
316         FlushStrBuf(Buf);
317         StrBufLowerCase(Buf);
318         StrBufPlain(Buf, HKEY("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"));
319         StrBufLowerCase(Buf);
320
321         CU_ASSERT_STRING_EQUAL(ChrPtr(Buf), "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789");
322
323
324         FreeStrBuf(&Buf);
325
326 }
327
328 static void NextTokenizerIterateBuf(StrBuf *Buf, int NTokens)
329 {
330         long FoundTokens;
331         const char *pCh = NULL;
332         StrBuf *Buf2;
333         long CountTokens = 0;
334         long HaveNextToken = 0;
335         long HaveNextTokenF = 0;
336
337         TestRevalidateStrBuf(Buf);
338         FoundTokens = StrBufNum_tokens(Buf, ',');
339         if (!Quiet) 
340                 printf("\n\nTemplate: >%s< %d, %ld\n", 
341                        ChrPtr(Buf), 
342                        NTokens, 
343                        FoundTokens);
344
345         CU_ASSERT(FoundTokens == NTokens);
346
347         Buf2 = NewStrBuf();
348         while (HaveNextToken = StrBufHaveNextToken(Buf, &pCh),
349                HaveNextTokenF = StrBufExtract_NextToken(Buf2, Buf, &pCh, ','),
350                (HaveNextTokenF>= 0))
351         {
352                 CountTokens++;
353                 
354                 if (!Quiet) printf("Token: >%s< >%s< %ld:%ld\n", 
355                                    ChrPtr(Buf2), 
356                                    ((pCh != NULL) && (pCh != StrBufNOTNULL))? pCh : "N/A", 
357                                    HaveNextToken, 
358                                    HaveNextTokenF);
359                 TestRevalidateStrBuf(Buf2);
360
361                 CU_ASSERT(HaveNextToken == (HaveNextTokenF >= 0));
362                 
363                 CU_ASSERT(CountTokens <= NTokens);
364         } 
365         CU_ASSERT(HaveNextToken == (HaveNextTokenF >= 0));
366         FreeStrBuf(&Buf2);
367 }
368
369
370
371 static void TestNextTokenizer_EndWithEmpty(void)
372 {
373         StrBuf *Buf;
374
375         Buf = NewStrBufPlain(HKEY("abc,abc, 1, ,,"));
376         NextTokenizerIterateBuf(Buf, 6);
377         FreeStrBuf(&Buf);
378 }
379
380 static void TestNextTokenizer_StartWithEmpty(void)
381 {
382         StrBuf *Buf;
383
384         Buf = NewStrBufPlain(HKEY(",cde,abc, 1, ,,bbb"));
385         NextTokenizerIterateBuf(Buf, 7);
386         FreeStrBuf(&Buf);
387 }
388
389 static void TestNextTokenizer_Empty(void)
390 {
391         StrBuf *Buf;
392
393         Buf = NewStrBufPlain(HKEY(""));
394         NextTokenizerIterateBuf(Buf, 0);
395         FreeStrBuf(&Buf);
396 }
397
398 static void TestNextTokenizer_TwoEmpty(void)
399 {
400         StrBuf *Buf;
401
402         Buf = NewStrBufPlain(HKEY(","));
403         NextTokenizerIterateBuf(Buf, 2);
404         FreeStrBuf(&Buf);
405 }
406
407 static void TestNextTokenizer_One(void)
408 {
409         StrBuf *Buf;
410
411         Buf = NewStrBufPlain(HKEY("one"));
412         NextTokenizerIterateBuf(Buf, 1);
413         FreeStrBuf(&Buf);
414 }
415
416 static void TestNextTokenizer_Sequence(void)
417 {
418         StrBuf *Buf;
419         char *teststring = "40:24524,24662,24673,27869:27935,28393,28426,31247:31258,31731,31749,31761,31778,31782,31801:31803,31813,31904,31915,33708,33935,34619,34672,34720:34723,34766,34835,37594,38854,39235,39942,40030,40142,40520,40815,40907,41201,41578,41781,41954,42292,43110,43565,43801,43998,44180,44241,44295,44401,44561,44635,44798,44861,44946,45022,45137:45148,45166,45179,45707,47114,47141:47157,47194,47314,47349,47386,47489,47496,47534:47543,54460,54601,54637:54652";
420         Buf = NewStrBufPlain(teststring, -1);
421         NextTokenizerIterateBuf(Buf, 67);
422         FreeStrBuf(&Buf);
423 }
424
425
426
427 static void NextLineterateBuf(StrBuf *Buf, int NLines)
428 {
429         int n = 0;
430         const char *pCh = NULL;
431         StrBuf *OneLine;
432         StrBuf *ConcatenatedLines;
433         long CountTokens = 0;
434         
435         TestRevalidateStrBuf(Buf);
436                              
437         OneLine = NewStrBuf();
438         ConcatenatedLines = NewStrBuf();
439
440         if (!Quiet) printf("\n");
441
442         if (StrLength(Buf) > 0) 
443                 do 
444                 {
445                         n = StrBufSipLine(OneLine, Buf, &pCh);
446                         
447                         CountTokens++;
448                         
449                         if (!Quiet) printf("Line: >%s< >%s<\n", 
450                                            ChrPtr(OneLine), 
451                                            ((pCh != NULL) && (pCh != StrBufNOTNULL))? pCh : "N/A");
452                         TestRevalidateStrBuf(OneLine);
453                         CU_ASSERT(CountTokens <= NLines);
454                         StrBufAppendBuf(ConcatenatedLines, OneLine, 0);
455                         
456                         if ((pCh == StrBufNOTNULL) && 
457                             (*(ChrPtr(Buf) + StrLength(Buf) - 1) != '\n'))
458                         {
459                         }
460                         else 
461                                 StrBufAppendBufPlain(ConcatenatedLines, HKEY("\n"), 0);
462                         
463                 } 
464                 while ((pCh != StrBufNOTNULL) &&
465                        (pCh != NULL));
466         
467
468         if (!Quiet) printf("\n\nTemplate: >%s<\n", ChrPtr(Buf));
469         if (!Quiet) printf("\n\nAfter: >%s<\n", ChrPtr(ConcatenatedLines));
470         CU_ASSERT_NSTRING_EQUAL(ChrPtr(ConcatenatedLines), 
471                                 ChrPtr(Buf), 
472                                 StrLength(Buf));
473
474         FreeStrBuf(&OneLine);
475         FreeStrBuf(&ConcatenatedLines);
476 }
477
478
479 static void TestNextLine_Empty(void)
480 {
481         StrBuf *Buf;
482
483         Buf = NewStrBufPlain(HKEY(""));
484         NextLineterateBuf(Buf, 0);
485         FreeStrBuf(&Buf);
486 }
487
488
489 static void TestNextLine_OneLine(void)
490 {
491         StrBuf *Buf;
492
493         Buf = NewStrBufPlain(HKEY("abc\n"));
494         NextLineterateBuf(Buf, 1);
495         FreeStrBuf(&Buf);
496 }
497
498
499 static void TestNextLine_TwoLinesMissingCR(void)
500 {
501         StrBuf *Buf;
502
503         Buf = NewStrBufPlain(HKEY("abc\ncde"));
504         NextLineterateBuf(Buf, 2);
505         FreeStrBuf(&Buf);
506 }
507
508
509 static void TestNextLine_twolines(void)
510 {
511         StrBuf *Buf;
512
513         Buf = NewStrBufPlain(HKEY("abc\ncde\n"));
514         NextLineterateBuf(Buf, 2);
515         FreeStrBuf(&Buf);
516 }
517
518 static void TestNextLine_LongLine(void)
519 {
520         StrBuf *Buf;
521
522         Buf = NewStrBufPlain(HKEY("abcde\n1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n"));
523         NextLineterateBuf(Buf, 2);
524         FreeStrBuf(&Buf);
525 }
526
527
528 static void TestStrBufRemove_token_NotThere(void)
529 {
530 //      StrBuf *Test = NewStrBufPlain(HKEY(" 127.0.0.1"));
531         StrBuf *Test = NewStrBufPlain(HKEY(" 10.122.44.30, 10.122.44.30"));
532         StrBufRemove_token(Test, 0, ',');
533         TestRevalidateStrBuf(Test);
534         FreeStrBuf(&Test);
535 }
536
537
538 static void TestStrBufUrlescAppend(void)
539 {
540         const char *expect = "%20%2B%23%26%3B%60%27%7C%2A%3F%2D%7E%3C%3E%5E%28%29%5B%5D%7B%7D%2F%24%22%5C";
541         StrBuf *In = NewStrBufPlain(HKEY( " +#&;`'|*?-~<>^()[]{}/$\"\\"));
542         StrBuf *Out = NewStrBuf();
543
544         StrBufUrlescAppend (Out, In, NULL);
545         if (!Quiet) printf ("%s<\n%s<\n%s\n", ChrPtr(In), ChrPtr(Out), expect);
546         CU_ASSERT_STRING_EQUAL(ChrPtr(Out), expect);
547         FreeStrBuf(&In);
548         FreeStrBuf(&Out);
549 }
550
551 /*
552 Some samples from the original...
553         CU_ASSERT_EQUAL(10, 10);
554         CU_ASSERT_EQUAL(0, -0);
555         CU_ASSERT_EQUAL(-12, -12);
556         CU_ASSERT_NOT_EQUAL(10, 11);
557         CU_ASSERT_NOT_EQUAL(0, -1);
558         CU_ASSERT_NOT_EQUAL(-12, -11);
559         CU_ASSERT_PTR_EQUAL((void*)0x100, (void*)0x100);
560         CU_ASSERT_PTR_NOT_EQUAL((void*)0x100, (void*)0x101);
561         CU_ASSERT_PTR_NULL(NULL);
562         CU_ASSERT_PTR_NULL(0x0);
563         CU_ASSERT_PTR_NOT_NULL((void*)0x23);
564         CU_ASSERT_STRING_EQUAL(str1, str2);
565         CU_ASSERT_STRING_NOT_EQUAL(str1, str2);
566         CU_ASSERT_NSTRING_EQUAL(str1, str2, strlen(str1));
567         CU_ASSERT_NSTRING_EQUAL(str1, str1, strlen(str1));
568         CU_ASSERT_NSTRING_EQUAL(str1, str1, strlen(str1) + 1);
569         CU_ASSERT_NSTRING_NOT_EQUAL(str1, str2, 3);
570         CU_ASSERT_NSTRING_NOT_EQUAL(str1, str3, strlen(str1) + 1);
571         CU_ASSERT_DOUBLE_EQUAL(10, 10.0001, 0.0001);
572         CU_ASSERT_DOUBLE_EQUAL(10, 10.0001, -0.0001);
573         CU_ASSERT_DOUBLE_EQUAL(-10, -10.0001, 0.0001);
574         CU_ASSERT_DOUBLE_EQUAL(-10, -10.0001, -0.0001);
575         CU_ASSERT_DOUBLE_NOT_EQUAL(10, 10.001, 0.0001);
576         CU_ASSERT_DOUBLE_NOT_EQUAL(10, 10.001, -0.0001);
577         CU_ASSERT_DOUBLE_NOT_EQUAL(-10, -10.001, 0.0001);
578         CU_ASSERT_DOUBLE_NOT_EQUAL(-10, -10.001, -0.0001);
579 */
580
581
582
583
584
585 static void AddStrBufSimpleTests(void)
586 {
587         CU_pSuite pGroup = NULL;
588         CU_pTest pTest = NULL;
589
590         pGroup = CU_add_suite("TestStringBufSimpleAppenders", NULL, NULL);
591         pTest = CU_add_test(pGroup, "testCreateBuf", TestCreateBuf);
592         pTest = CU_add_test(pGroup, "TestBufNumbers", TestBufNumbers);
593         pTest = CU_add_test(pGroup, "TestStrBufPeek", TestStrBufPeek);
594         pTest = CU_add_test(pGroup, "TestBufStringManipulation", TestBufStringManipulation);
595
596
597         pGroup = CU_add_suite("TestStringTokenizer", NULL, NULL);
598         pTest = CU_add_test(pGroup, "testNextTokenizer_EndWithEmpty", TestNextTokenizer_EndWithEmpty);
599         pTest = CU_add_test(pGroup, "testNextTokenizer_StartWithEmpty", TestNextTokenizer_StartWithEmpty);
600         pTest = CU_add_test(pGroup, "testNextTokenizer_StartWithEmpty", TestNextTokenizer_StartWithEmpty);
601         pTest = CU_add_test(pGroup, "testNextTokenizer_Empty", TestNextTokenizer_Empty);
602         pTest = CU_add_test(pGroup, "testNextTokenizer_TwoEmpty", TestNextTokenizer_TwoEmpty);
603         pTest = CU_add_test(pGroup, "testNextTokenizer_One", TestNextTokenizer_One);
604         pTest = CU_add_test(pGroup, "testNextTokenizer_Sequence", TestNextTokenizer_Sequence);
605
606
607         pGroup = CU_add_suite("TestStrBufSipLine", NULL, NULL);
608         pTest = CU_add_test(pGroup, "TestNextLine_Empty", TestNextLine_Empty);
609         pTest = CU_add_test(pGroup, "TestNextLine_OneLine", TestNextLine_OneLine);
610         pTest = CU_add_test(pGroup, "TestNextLine_TwoLinesMissingCR", TestNextLine_TwoLinesMissingCR);
611         pTest = CU_add_test(pGroup, "TestNextLine_twolines", TestNextLine_twolines);
612         pTest = CU_add_test(pGroup, "TestNextLine_LongLine", TestNextLine_LongLine);
613         
614         pGroup = CU_add_suite("TestStrBufRemove_token", NULL, NULL);
615         pTest = CU_add_test(pGroup, "TestStrBufRemove_token_NotThere", TestStrBufRemove_token_NotThere);
616
617         pGroup = CU_add_suite("TestStrBuf_escapers", NULL, NULL);
618         pTest = CU_add_test(pGroup, "TestStrBufUrlescAppend", TestStrBufUrlescAppend);
619 }
620
621
622 int main(int argc, char* argv[])
623 {
624         ///int i;
625         setvbuf(stdout, NULL, _IONBF, 0);
626
627         StartLibCitadel(8);
628         CU_BOOL Run = CU_FALSE ;
629
630         if (argc > 0)
631                 Quiet = 1; // todo: -q ;-)
632 //      for (i=0; i< 100000; i++) {
633         CU_set_output_filename("TestAutomated");
634         if (CU_initialize_registry()) {
635                 printf("\nInitialize of test Registry failed.");
636 //      }
637         
638         Run = CU_TRUE ;
639         AddStrBufSimpleTests();
640         
641         if (CU_TRUE == Run) {
642                 //CU_console_run_tests();
643                 printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
644     
645     ///CU_automated_run_tests();
646         }
647         
648         CU_cleanup_registry();
649         }
650         return 0;
651 }