2 * CUnit - A Unit testing framework library for C.
3 * Copyright (C) 2001 Anil Kumar
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.
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.
22 #include "stringbuf_test.h"
23 #include "../lib/libcitadel.h"
28 static void TestRevalidateStrBuf(StrBuf *Buf)
30 CU_ASSERT(strlen(ChrPtr(Buf)) == StrLength(Buf));
36 static void TestRFC822Decode(void)
40 StrBuf *DefaultCharset;
43 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
44 FoundCharset = NewStrBuf();
45 Source = NewStrBufPlain(HKEY("=?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?="));
48 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
51 TestRevalidateStrBuf(Target);
52 printf("the ugly multi:>%s<\n", ChrPtr(Target));
55 FreeStrBuf(&FoundCharset);
56 FreeStrBuf(&DefaultCharset);
59 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
60 FoundCharset = NewStrBuf();
61 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"));
62 Target = NewStrBufPlain(NULL, 256);
64 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
65 TestRevalidateStrBuf(Target);
66 printf("the ugly multi:>%s<\n", ChrPtr(Target));
69 FreeStrBuf(&FoundCharset);
70 FreeStrBuf(&DefaultCharset);
75 static void TestRFC822DecodeStdin(void)
81 StrBuf *DefaultCharset;
84 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
85 FoundCharset = NewStrBuf();
90 StrBufTCP_read_line(Source, &fdin, 0, &Err);
93 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
95 TestRevalidateStrBuf(Target);
96 printf("the ugly multi:>%s<\n", ChrPtr(Target));
100 FreeStrBuf(&FoundCharset);
101 FreeStrBuf(&DefaultCharset);
105 static void TestEncodeEmail(void)
109 StrBuf *UserName = NewStrBuf();
110 StrBuf *EmailAddress = NewStrBuf();
111 StrBuf *EncBuf = NewStrBuf();
113 Source = NewStrBuf();
115 // Source = NewStrBufPlain(HKEY("Art Cancro <ajc@uncensored.citadel.org>, Art Cancro <ajc@uncensored.citadel.org>"));
117 Source = NewStrBufPlain(HKEY("\"Alexandra Weiz, Restless GmbH\" <alexandra.weiz@boblbee.de>, \"NetIN\" <editor@netin.co.il>, \" יריב ברקאי, מולטימדי\" <info@immembed.com>"));
118 Target = StrBufSanitizeEmailRecipientVector(
125 TestRevalidateStrBuf(Target);
126 printf("the source:>%s<\n", ChrPtr(Source));
127 printf("the target:>%s<\n", ChrPtr(Target));
129 FreeStrBuf(&UserName);
130 FreeStrBuf(&EmailAddress);
136 static void TestEncodeEmailSTDIN(void)
138 int fdin = 0;// STDIN
142 StrBuf *UserName = NewStrBuf();
143 StrBuf *EmailAddress = NewStrBuf();
144 StrBuf *EncBuf = NewStrBuf();
146 Source = NewStrBuf();
150 StrBufTCP_read_line(Source, &fdin, 0, &Err);
151 printf("the source:>%s<\n", ChrPtr(Source));
152 Target = StrBufSanitizeEmailRecipientVector(
159 TestRevalidateStrBuf(Target);
160 printf("the target:>%s<\n", ChrPtr(Target));
163 FreeStrBuf(&UserName);
164 FreeStrBuf(&EmailAddress);
172 static void AddStrBufSimlpeTests(void)
174 CU_pSuite pGroup = NULL;
175 CU_pTest pTest = NULL;
177 pGroup = CU_add_suite("TestStringBufConversions", NULL, NULL);
180 pTest = CU_add_test(pGroup, "testRFC822Decode", TestRFC822Decode);
181 pTest = CU_add_test(pGroup, "testRFC822Decode1", TestRFC822Decode);
182 pTest = CU_add_test(pGroup, "testRFC822Decode2", TestRFC822Decode);
183 pTest = CU_add_test(pGroup, "testRFC822Decode3", TestRFC822Decode);
186 pTest = CU_add_test(pGroup, "testRFC822DecodeSTDIN", TestRFC822DecodeStdin);
190 pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmail);
193 pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmailSTDIN);
199 int main(int argc, char* argv[])
203 while ((a = getopt(argc, argv, "@i")) != EOF)
215 setvbuf(stdout, NULL, _IONBF, 0);
218 CU_BOOL Run = CU_FALSE ;
220 CU_set_output_filename("TestAutomated");
221 if (CU_initialize_registry()) {
222 printf("\nInitialize of test Registry failed.");
226 AddStrBufSimlpeTests();
228 if (CU_TRUE == Run) {
229 //CU_console_run_tests();
230 printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
232 ///CU_automated_run_tests();
235 CU_cleanup_registry();