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