* add simple RFC822 / iconv decoding test
[citadel.git] / libcitadel / tests / stringbuf_conversion.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
25 #include "stringbuf_test.h"
26 #include "../lib/libcitadel.h"
27
28
29 static void TestRevalidateStrBuf(StrBuf *Buf)
30 {
31         CU_ASSERT(strlen(ChrPtr(Buf)) == StrLength(Buf));
32 }
33
34
35
36 /*
37 Some samples from the original...
38         CU_ASSERT_EQUAL(10, 10);
39         CU_ASSERT_EQUAL(0, -0);
40         CU_ASSERT_EQUAL(-12, -12);
41         CU_ASSERT_NOT_EQUAL(10, 11);
42         CU_ASSERT_NOT_EQUAL(0, -1);
43         CU_ASSERT_NOT_EQUAL(-12, -11);
44         CU_ASSERT_PTR_EQUAL((void*)0x100, (void*)0x100);
45         CU_ASSERT_PTR_NOT_EQUAL((void*)0x100, (void*)0x101);
46         CU_ASSERT_PTR_NULL(NULL);
47         CU_ASSERT_PTR_NULL(0x0);
48         CU_ASSERT_PTR_NOT_NULL((void*)0x23);
49         CU_ASSERT_STRING_EQUAL(str1, str2);
50         CU_ASSERT_STRING_NOT_EQUAL(str1, str2);
51         CU_ASSERT_NSTRING_EQUAL(str1, str2, strlen(str1));
52         CU_ASSERT_NSTRING_EQUAL(str1, str1, strlen(str1));
53         CU_ASSERT_NSTRING_EQUAL(str1, str1, strlen(str1) + 1);
54         CU_ASSERT_NSTRING_NOT_EQUAL(str1, str2, 3);
55         CU_ASSERT_NSTRING_NOT_EQUAL(str1, str3, strlen(str1) + 1);
56         CU_ASSERT_DOUBLE_EQUAL(10, 10.0001, 0.0001);
57         CU_ASSERT_DOUBLE_EQUAL(10, 10.0001, -0.0001);
58         CU_ASSERT_DOUBLE_EQUAL(-10, -10.0001, 0.0001);
59         CU_ASSERT_DOUBLE_EQUAL(-10, -10.0001, -0.0001);
60         CU_ASSERT_DOUBLE_NOT_EQUAL(10, 10.001, 0.0001);
61         CU_ASSERT_DOUBLE_NOT_EQUAL(10, 10.001, -0.0001);
62         CU_ASSERT_DOUBLE_NOT_EQUAL(-10, -10.001, 0.0001);
63         CU_ASSERT_DOUBLE_NOT_EQUAL(-10, -10.001, -0.0001);
64 */
65
66 static void TestRFC822Decode(void)
67 {
68         StrBuf *Target;
69         StrBuf *Source;
70         StrBuf *DefaultCharset;
71         StrBuf *FoundCharset;
72         
73         DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
74         FoundCharset = NewStrBuf();
75         Source = NewStrBufPlain(HKEY("=?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?="));
76         Target = NewStrBuf();
77
78         StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
79
80
81         TestRevalidateStrBuf(Target);
82         printf("the ugly multi:>%s<\n", ChrPtr(Target));
83         FreeStrBuf(&Source);
84         FreeStrBuf(&Target);
85         FreeStrBuf(&FoundCharset);
86         FreeStrBuf(&DefaultCharset);
87 }
88
89
90
91 static void AddStrBufSimlpeTests(void)
92 {
93         CU_pSuite pGroup = NULL;
94         CU_pTest pTest = NULL;
95
96         pGroup = CU_add_suite("TestStringBufConversions", NULL, NULL);
97         pTest = CU_add_test(pGroup, "testRFC822Decode", TestRFC822Decode);
98
99
100 }
101
102
103 int main(int argc, char* argv[])
104 {
105         setvbuf(stdout, NULL, _IONBF, 0);
106
107         StartLibCitadel(8);
108         CU_BOOL Run = CU_FALSE ;
109         
110         CU_set_output_filename("TestAutomated");
111         if (CU_initialize_registry()) {
112                 printf("\nInitialize of test Registry failed.");
113         }
114         
115         Run = CU_TRUE ;
116         AddStrBufSimlpeTests();
117         
118         if (CU_TRUE == Run) {
119                 //CU_console_run_tests();
120     printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
121     
122     ///CU_automated_run_tests();
123         }
124         
125         CU_cleanup_registry();
126
127         return 0;
128 }