3 * CUnit - A Unit testing framework library for C.
4 * Copyright (C) 2001 Anil Kumar
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.
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.
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
27 #include "stringbuf_test.h"
28 #include "../lib/libcitadel.h"
33 static void TestRevalidateStrBuf(StrBuf *Buf)
35 CU_ASSERT(strlen(ChrPtr(Buf)) == StrLength(Buf));
41 Some samples from the original...
42 CU_ASSERT_EQUAL(10, 10);
43 CU_ASSERT_EQUAL(0, -0);
44 CU_ASSERT_EQUAL(-12, -12);
45 CU_ASSERT_NOT_EQUAL(10, 11);
46 CU_ASSERT_NOT_EQUAL(0, -1);
47 CU_ASSERT_NOT_EQUAL(-12, -11);
48 CU_ASSERT_PTR_EQUAL((void*)0x100, (void*)0x100);
49 CU_ASSERT_PTR_NOT_EQUAL((void*)0x100, (void*)0x101);
50 CU_ASSERT_PTR_NULL(NULL);
51 CU_ASSERT_PTR_NULL(0x0);
52 CU_ASSERT_PTR_NOT_NULL((void*)0x23);
53 CU_ASSERT_STRING_EQUAL(str1, str2);
54 CU_ASSERT_STRING_NOT_EQUAL(str1, str2);
55 CU_ASSERT_NSTRING_EQUAL(str1, str2, strlen(str1));
56 CU_ASSERT_NSTRING_EQUAL(str1, str1, strlen(str1));
57 CU_ASSERT_NSTRING_EQUAL(str1, str1, strlen(str1) + 1);
58 CU_ASSERT_NSTRING_NOT_EQUAL(str1, str2, 3);
59 CU_ASSERT_NSTRING_NOT_EQUAL(str1, str3, strlen(str1) + 1);
60 CU_ASSERT_DOUBLE_EQUAL(10, 10.0001, 0.0001);
61 CU_ASSERT_DOUBLE_EQUAL(10, 10.0001, -0.0001);
62 CU_ASSERT_DOUBLE_EQUAL(-10, -10.0001, 0.0001);
63 CU_ASSERT_DOUBLE_EQUAL(-10, -10.0001, -0.0001);
64 CU_ASSERT_DOUBLE_NOT_EQUAL(10, 10.001, 0.0001);
65 CU_ASSERT_DOUBLE_NOT_EQUAL(10, 10.001, -0.0001);
66 CU_ASSERT_DOUBLE_NOT_EQUAL(-10, -10.001, 0.0001);
67 CU_ASSERT_DOUBLE_NOT_EQUAL(-10, -10.001, -0.0001);
70 static void TestRFC822Decode(void)
74 StrBuf *DefaultCharset;
77 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
78 FoundCharset = NewStrBuf();
79 Source = NewStrBufPlain(HKEY("=?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?="));
82 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
85 TestRevalidateStrBuf(Target);
86 printf("the ugly multi:>%s<\n", ChrPtr(Target));
89 FreeStrBuf(&FoundCharset);
90 FreeStrBuf(&DefaultCharset);
93 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
94 FoundCharset = NewStrBuf();
95 Source = NewStrBufPlain(HKEY("\"w.goesgens\" <w.goesgens@aoeuaoeuaoeu.org>, =?ISO-8859-15?Q?Walter_?= =?ISO-8859-15?Q?G=F6aoeus?= <aoeuaoeu@aoe.de>, =?ISO-8859-15?Q?aoeuaoeuh?= =?ISO-8859-15?Q?_G=F6aoeus?= <aoeuoeuaoeu@oeu.de>, aoeuao aoeuaoeu <aoeuaoeuaoeaoe@aoe.de"));
96 Target = NewStrBufPlain(NULL, 256);
98 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
99 TestRevalidateStrBuf(Target);
100 printf("the ugly multi:>%s<\n", ChrPtr(Target));
103 FreeStrBuf(&FoundCharset);
104 FreeStrBuf(&DefaultCharset);
109 static void TestRFC822DecodeStdin(void)
111 int fdin = 0;// STDIN
115 StrBuf *DefaultCharset;
116 StrBuf *FoundCharset;
118 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
119 FoundCharset = NewStrBuf();
120 Source = NewStrBuf();
124 StrBufTCP_read_line(Source, &fdin, 0, &Err);
125 Target = NewStrBuf();
127 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
129 TestRevalidateStrBuf(Target);
130 printf("the ugly multi:>%s<\n", ChrPtr(Target));
134 FreeStrBuf(&FoundCharset);
135 FreeStrBuf(&DefaultCharset);
139 static void TestEncodeEmail(void)
143 StrBuf *UserName = NewStrBuf();
144 StrBuf *EmailAddress = NewStrBuf();
145 StrBuf *EncBuf = NewStrBuf();
147 Source = NewStrBuf();
149 // Source = NewStrBufPlain(HKEY("Art Cancro <ajc@uncensored.citadel.org>, Art Cancro <ajc@uncensored.citadel.org>"));
151 Source = NewStrBufPlain(HKEY("\"Alexandra Weiz, Restless GmbH\" <alexandra.weiz@boblbee.de>, \"NetIN\" <editor@netin.co.il>, \" יריב ברקאי, מולטימדי\" <info@immembed.com>"));
152 Target = StrBufSanitizeEmailRecipientVector(
159 TestRevalidateStrBuf(Target);
160 printf("the source:>%s<\n", ChrPtr(Source));
161 printf("the target:>%s<\n", ChrPtr(Target));
163 FreeStrBuf(&UserName);
164 FreeStrBuf(&EmailAddress);
170 static void TestEncodeEmailSTDIN(void)
172 int fdin = 0;// STDIN
176 StrBuf *UserName = NewStrBuf();
177 StrBuf *EmailAddress = NewStrBuf();
178 StrBuf *EncBuf = NewStrBuf();
180 Source = NewStrBuf();
184 StrBufTCP_read_line(Source, &fdin, 0, &Err);
185 printf("the source:>%s<\n", ChrPtr(Source));
186 Target = StrBufSanitizeEmailRecipientVector(
193 TestRevalidateStrBuf(Target);
194 printf("the target:>%s<\n", ChrPtr(Target));
197 FreeStrBuf(&UserName);
198 FreeStrBuf(&EmailAddress);
206 static void AddStrBufSimlpeTests(void)
208 CU_pSuite pGroup = NULL;
209 CU_pTest pTest = NULL;
211 pGroup = CU_add_suite("TestStringBufConversions", NULL, NULL);
214 pTest = CU_add_test(pGroup, "testRFC822Decode", TestRFC822Decode);
215 pTest = CU_add_test(pGroup, "testRFC822Decode1", TestRFC822Decode);
216 pTest = CU_add_test(pGroup, "testRFC822Decode2", TestRFC822Decode);
217 pTest = CU_add_test(pGroup, "testRFC822Decode3", TestRFC822Decode);
220 pTest = CU_add_test(pGroup, "testRFC822DecodeSTDIN", TestRFC822DecodeStdin);
224 pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmail);
227 pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmailSTDIN);
233 int main(int argc, char* argv[])
237 while ((a = getopt(argc, argv, "@i")) != EOF)
249 setvbuf(stdout, NULL, _IONBF, 0);
252 CU_BOOL Run = CU_FALSE ;
254 CU_set_output_filename("TestAutomated");
255 if (CU_initialize_registry()) {
256 printf("\nInitialize of test Registry failed.");
260 AddStrBufSimlpeTests();
262 if (CU_TRUE == Run) {
263 //CU_console_run_tests();
264 printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
266 ///CU_automated_run_tests();
269 CU_cleanup_registry();