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 static void TestRFC822Decode(void)
45 StrBuf *DefaultCharset;
48 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
49 FoundCharset = NewStrBuf();
50 Source = NewStrBufPlain(HKEY("=?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?="));
53 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
56 TestRevalidateStrBuf(Target);
57 printf("the ugly multi:>%s<\n", ChrPtr(Target));
60 FreeStrBuf(&FoundCharset);
61 FreeStrBuf(&DefaultCharset);
64 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
65 FoundCharset = NewStrBuf();
66 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"));
67 Target = NewStrBufPlain(NULL, 256);
69 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
70 TestRevalidateStrBuf(Target);
71 printf("the ugly multi:>%s<\n", ChrPtr(Target));
74 FreeStrBuf(&FoundCharset);
75 FreeStrBuf(&DefaultCharset);
80 static void TestRFC822DecodeStdin(void)
86 StrBuf *DefaultCharset;
89 DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
90 FoundCharset = NewStrBuf();
95 StrBufTCP_read_line(Source, &fdin, 0, &Err);
98 StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
100 TestRevalidateStrBuf(Target);
101 printf("the ugly multi:>%s<\n", ChrPtr(Target));
105 FreeStrBuf(&FoundCharset);
106 FreeStrBuf(&DefaultCharset);
110 static void TestEncodeEmail(void)
114 StrBuf *UserName = NewStrBuf();
115 StrBuf *EmailAddress = NewStrBuf();
116 StrBuf *EncBuf = NewStrBuf();
118 Source = NewStrBuf();
120 // Source = NewStrBufPlain(HKEY("Art Cancro <ajc@uncensored.citadel.org>, Art Cancro <ajc@uncensored.citadel.org>"));
122 Source = NewStrBufPlain(HKEY("\"Alexandra Weiz, Restless GmbH\" <alexandra.weiz@boblbee.de>, \"NetIN\" <editor@netin.co.il>, \" יריב ברקאי, מולטימדי\" <info@immembed.com>"));
123 Target = StrBufSanitizeEmailRecipientVector(
130 TestRevalidateStrBuf(Target);
131 printf("the source:>%s<\n", ChrPtr(Source));
132 printf("the target:>%s<\n", ChrPtr(Target));
134 FreeStrBuf(&UserName);
135 FreeStrBuf(&EmailAddress);
141 static void TestEncodeEmailSTDIN(void)
143 int fdin = 0;// STDIN
147 StrBuf *UserName = NewStrBuf();
148 StrBuf *EmailAddress = NewStrBuf();
149 StrBuf *EncBuf = NewStrBuf();
151 Source = NewStrBuf();
155 StrBufTCP_read_line(Source, &fdin, 0, &Err);
156 printf("the source:>%s<\n", ChrPtr(Source));
157 Target = StrBufSanitizeEmailRecipientVector(
164 TestRevalidateStrBuf(Target);
165 printf("the target:>%s<\n", ChrPtr(Target));
168 FreeStrBuf(&UserName);
169 FreeStrBuf(&EmailAddress);
177 static void AddStrBufSimlpeTests(void)
179 CU_pSuite pGroup = NULL;
180 CU_pTest pTest = NULL;
182 pGroup = CU_add_suite("TestStringBufConversions", NULL, NULL);
185 pTest = CU_add_test(pGroup, "testRFC822Decode", TestRFC822Decode);
186 pTest = CU_add_test(pGroup, "testRFC822Decode1", TestRFC822Decode);
187 pTest = CU_add_test(pGroup, "testRFC822Decode2", TestRFC822Decode);
188 pTest = CU_add_test(pGroup, "testRFC822Decode3", TestRFC822Decode);
191 pTest = CU_add_test(pGroup, "testRFC822DecodeSTDIN", TestRFC822DecodeStdin);
195 pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmail);
198 pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmailSTDIN);
204 int main(int argc, char* argv[])
208 while ((a = getopt(argc, argv, "@i")) != EOF)
220 setvbuf(stdout, NULL, _IONBF, 0);
223 CU_BOOL Run = CU_FALSE ;
225 CU_set_output_filename("TestAutomated");
226 if (CU_initialize_registry()) {
227 printf("\nInitialize of test Registry failed.");
231 AddStrBufSimlpeTests();
233 if (CU_TRUE == Run) {
234 //CU_console_run_tests();
235 printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
237 ///CU_automated_run_tests();
240 CU_cleanup_registry();