Back to index

libcitadel  8.12
html_to_ascii_test.c
Go to the documentation of this file.
00001 /*
00002  *  CUnit - A Unit testing framework library for C.
00003  *  Copyright (C) 2001  Anil Kumar
00004  *  
00005  *  This library is open source software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  */
00015 
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 #include <string.h>
00019 #include <stdio.h>
00020 #include <unistd.h>
00021 
00022 #include "stringbuf_test.h"
00023 #include "../lib/libcitadel.h"
00024 
00025 
00026 int fromstdin = 0;
00027 int parse_email = 0;
00028 static void TestRevalidateStrBuf(StrBuf *Buf)
00029 {
00030        CU_ASSERT(strlen(ChrPtr(Buf)) == StrLength(Buf));
00031 }
00032 
00033 
00034 
00035 
00036 static void TestRFC822Decode(void)
00037 {
00038        StrBuf *Target;
00039        StrBuf *Source;
00040        StrBuf *DefaultCharset;
00041        StrBuf *FoundCharset;
00042        
00043        DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
00044        FoundCharset = NewStrBuf();
00045        Source = NewStrBufPlain(HKEY("=?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?="));
00046        Target = NewStrBuf();
00047 
00048        StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
00049 
00050 
00051        TestRevalidateStrBuf(Target);
00052        printf("the ugly multi:>%s<\n", ChrPtr(Target));
00053        FreeStrBuf(&Source);
00054        FreeStrBuf(&Target);
00055        FreeStrBuf(&FoundCharset);
00056        FreeStrBuf(&DefaultCharset);
00057 
00058 
00059        DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
00060        FoundCharset = NewStrBuf();
00061        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"));
00062        Target = NewStrBufPlain(NULL, 256);
00063 
00064        StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
00065        TestRevalidateStrBuf(Target);
00066        printf("the ugly multi:>%s<\n", ChrPtr(Target));
00067        FreeStrBuf(&Source);
00068        FreeStrBuf(&Target);
00069        FreeStrBuf(&FoundCharset);
00070        FreeStrBuf(&DefaultCharset);
00071 
00072 }
00073 
00074 
00075 static void TestRFC822DecodeStdin(void)
00076 {
00077        int fdin = 0;// STDIN
00078        const char *Err;
00079        StrBuf *Target;
00080        StrBuf *Source;
00081        StrBuf *DefaultCharset;
00082        StrBuf *FoundCharset;
00083        
00084        DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
00085        FoundCharset = NewStrBuf();
00086        Source = NewStrBuf();
00087 
00088        while (fdin == 0) {
00089 
00090               StrBufTCP_read_line(Source, &fdin, 0, &Err);
00091               Target = NewStrBuf();
00092               
00093               StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
00094               
00095               TestRevalidateStrBuf(Target);
00096               printf("the ugly multi:>%s<\n", ChrPtr(Target));
00097               FreeStrBuf(&Target);
00098        }
00099        FreeStrBuf(&Source);
00100        FreeStrBuf(&FoundCharset);
00101        FreeStrBuf(&DefaultCharset);
00102 }
00103 
00104 
00105 static void TestEncodeEmail(void)
00106 {
00107        StrBuf *Target;
00108        StrBuf *Source;
00109        StrBuf *UserName = NewStrBuf();
00110        StrBuf *EmailAddress = NewStrBuf();
00111        StrBuf *EncBuf = NewStrBuf();
00112        
00113        Source = NewStrBuf();
00114  
00115 //     Source = NewStrBufPlain(HKEY("Art Cancro <ajc@uncensored.citadel.org>, Art Cancro <ajc@uncensored.citadel.org>"));
00116 
00117        Source = NewStrBufPlain(HKEY("\"Alexandra Weiz, Restless GmbH\" <alexandra.weiz@boblbee.de>, \"NetIN\" <editor@netin.co.il>, \" יריב ברקאי, מולטימדי\" <info@immembed.com>"));     
00118        Target = StrBufSanitizeEmailRecipientVector(
00119               Source,
00120               UserName, 
00121               EmailAddress,
00122               EncBuf
00123               );            
00124        
00125        TestRevalidateStrBuf(Target);
00126        printf("the source:>%s<\n", ChrPtr(Source));
00127        printf("the target:>%s<\n", ChrPtr(Target));
00128        FreeStrBuf(&Target);
00129        FreeStrBuf(&UserName);
00130        FreeStrBuf(&EmailAddress);
00131        FreeStrBuf(&EncBuf);
00132 
00133        FreeStrBuf(&Source);
00134 }
00135 
00136 static void TestEncodeEmailSTDIN(void)
00137 {
00138        int fdin = 0;// STDIN
00139        const char *Err;
00140        StrBuf *Target;
00141        StrBuf *Source;
00142        StrBuf *UserName = NewStrBuf();
00143        StrBuf *EmailAddress = NewStrBuf();
00144        StrBuf *EncBuf = NewStrBuf();
00145        
00146        Source = NewStrBuf();
00147 
00148        while (fdin == 0) {
00149 
00150               StrBufTCP_read_line(Source, &fdin, 0, &Err);
00151               printf("the source:>%s<\n", ChrPtr(Source));
00152               Target = StrBufSanitizeEmailRecipientVector(
00153                      Source,
00154                      UserName, 
00155                      EmailAddress,
00156                      EncBuf
00157                      );
00158               
00159               TestRevalidateStrBuf(Target);
00160               printf("the target:>%s<\n", ChrPtr(Target));
00161               FreeStrBuf(&Target);
00162        }
00163        FreeStrBuf(&UserName);
00164        FreeStrBuf(&EmailAddress);
00165        FreeStrBuf(&EncBuf);
00166 
00167        FreeStrBuf(&Source);
00168 }
00169 
00170 
00171 
00172 static void AddStrBufSimlpeTests(void)
00173 {
00174        CU_pSuite pGroup = NULL;
00175        CU_pTest pTest = NULL;
00176 
00177        pGroup = CU_add_suite("TestStringBufConversions", NULL, NULL);
00178        if (!parse_email) {
00179               if (!fromstdin) {
00180                      pTest = CU_add_test(pGroup, "testRFC822Decode", TestRFC822Decode);
00181                      pTest = CU_add_test(pGroup, "testRFC822Decode1", TestRFC822Decode);
00182                      pTest = CU_add_test(pGroup, "testRFC822Decode2", TestRFC822Decode);
00183                      pTest = CU_add_test(pGroup, "testRFC822Decode3", TestRFC822Decode);
00184               }
00185               else
00186                      pTest = CU_add_test(pGroup, "testRFC822DecodeSTDIN", TestRFC822DecodeStdin);
00187        }
00188        else {
00189               if (!fromstdin) {
00190                      pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmail);
00191               }
00192               else
00193                      pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmailSTDIN);
00194        }
00195 
00196 }
00197 
00198 
00199 int main(int argc, char* argv[])
00200 {
00201        int a;
00202 
00203        while ((a = getopt(argc, argv, "@i")) != EOF)
00204               switch (a) {
00205               case '@':
00206                      parse_email = 1;
00207                      break;
00208               case 'i':
00209                      fromstdin = 1;
00210                      
00211                      break;
00212               }
00213 
00214 
00215        setvbuf(stdout, NULL, _IONBF, 0);
00216 
00217        StartLibCitadel(8);
00218        CU_BOOL Run = CU_FALSE ;
00219        
00220        CU_set_output_filename("TestAutomated");
00221        if (CU_initialize_registry()) {
00222               printf("\nInitialize of test Registry failed.");
00223        }
00224        
00225        Run = CU_TRUE ;
00226        AddStrBufSimlpeTests();
00227        
00228        if (CU_TRUE == Run) {
00229               //CU_console_run_tests();
00230               printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
00231     
00233        }
00234        
00235        CU_cleanup_registry();
00236 
00237        return 0;
00238 }