Back to index

libcitadel  8.12
Functions | Variables
stringbuf_conversion.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "stringbuf_test.h"
#include "../lib/libcitadel.h"

Go to the source code of this file.

Functions

static void TestRevalidateStrBuf (StrBuf *Buf)
static void TestRFC822Decode (void)
static void TestRFC822DecodeStdin (void)
static void TestHTMLEscEncodeStdin (void)
static void TestEscEncodeStdin (void)
static void TestECMAEscEncodeStdin (void)
static void TestHtmlEcmaEscEncodeStdin (void)
static void TestUrlescEncodeStdin (void)
static void TestEncodeEmail (void)
static void TestEncodeEmailSTDIN (void)
static void TestHTML2ASCII_line (void)
static void AddStrBufSimlpeTests (void)
int main (int argc, char *argv[])

Variables

int fromstdin = 0
int parse_email = 0
int parse_html = 0
int OutputEscape = 0
int OutputEscapeAs = 0

Function Documentation

static void AddStrBufSimlpeTests ( void  ) [static]

Definition at line 349 of file stringbuf_conversion.c.

{
       CU_pSuite pGroup = NULL;
       CU_pTest pTest = NULL;

       pGroup = CU_add_suite("TestStringBufConversions", NULL, NULL);
       if (parse_email) {
              if (!fromstdin) {
                     pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmail);
              }
              else
                     pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmailSTDIN);
       }
       else if (parse_html) {
                     pTest = CU_add_test(pGroup, "TestParseHTMLSTDIN", TestHTML2ASCII_line);
       }
       else {
              if (!fromstdin) {
                     pTest = CU_add_test(pGroup, "testRFC822Decode", TestRFC822Decode);
                     pTest = CU_add_test(pGroup, "testRFC822Decode1", TestRFC822Decode);
                     pTest = CU_add_test(pGroup, "testRFC822Decode2", TestRFC822Decode);
                     pTest = CU_add_test(pGroup, "testRFC822Decode3", TestRFC822Decode);
              }
              else
              {
                     if (!OutputEscape)
                            pTest = CU_add_test(pGroup, "testRFC822DecodeSTDIN", TestRFC822DecodeStdin);
                     else switch(OutputEscapeAs)
                          {
                          case 'H':
                                 pTest = CU_add_test(pGroup, "TestHTMLEscEncodeStdin", TestHTMLEscEncodeStdin);
                                 break;
                          case 'X':
                                 pTest = CU_add_test(pGroup, "TestEscEncodeStdin", TestEscEncodeStdin);
                                 break;
                          case 'J':
                                 pTest = CU_add_test(pGroup, "TestECMAEscEncodeStdin", TestECMAEscEncodeStdin);
                                 break;
                          case 'K':
                                 pTest = CU_add_test(pGroup, "TestHtmlEcmaEscEncodeStdin", TestHtmlEcmaEscEncodeStdin);
                                 break;
                          case 'U':
                                 pTest = CU_add_test(pGroup, "TestUrlescEncodeStdin", TestUrlescEncodeStdin);
                                 break;
                          default:
                                 printf("%c not supported!\n", OutputEscapeAs);
                                 CU_ASSERT(1);
                          }
              }
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

CU_automated_run_tests();

Definition at line 403 of file stringbuf_conversion.c.

{
       int a;

       while ((a = getopt(argc, argv, "@iho:")) != EOF)
              switch (a) {
              case 'o':
                     if (optarg)
                     {
                            OutputEscape = 1;
                            OutputEscapeAs = *optarg;
                     }
                     break;
              case 'h':
                     parse_html = 1;
                     break;
              case '@':
                     parse_email = 1;
                     break;
              case 'i':
                     fromstdin = 1;
                     
                     break;
              }


       setvbuf(stdout, NULL, _IONBF, 0);

       StartLibCitadel(8);
       CU_BOOL Run = CU_FALSE ;
       
       CU_set_output_filename("TestAutomated");
       if (CU_initialize_registry()) {
              printf("\nInitialize of test Registry failed.");
       }
       
       Run = CU_TRUE ;
       AddStrBufSimlpeTests();
       
       if (CU_TRUE == Run) {
              //CU_console_run_tests();
              printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
    
       }
       
       CU_cleanup_registry();

       return 0;
}

Here is the call graph for this function:

static void TestECMAEscEncodeStdin ( void  ) [static]

Definition at line 185 of file stringbuf_conversion.c.

{
       int fdin = 0;// STDIN
       const char *Err;
       StrBuf *Target;
       StrBuf *Source;

       Source = NewStrBuf();

       printf("[");
       while (fdin == 0) {

              StrBufTCP_read_line(Source, &fdin, 0, &Err);
              Target = NewStrBuf();
              
              StrECMAEscAppend(Target, Source, NULL);
              
              TestRevalidateStrBuf(Target);
              printf("\"%s\",\n", ChrPtr(Target));
              FreeStrBuf(&Target);
       }
       printf("]\n");
       FreeStrBuf(&Source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestEncodeEmail ( void  ) [static]

Definition at line 259 of file stringbuf_conversion.c.

{
       StrBuf *Target;
       StrBuf *Source;
       StrBuf *UserName = NewStrBuf();
       StrBuf *EmailAddress = NewStrBuf();
       StrBuf *EncBuf = NewStrBuf();
       
       Source = NewStrBuf();
 
//     Source = NewStrBufPlain(HKEY("Art Cancro <ajc@uncensored.citadel.org>, Art Cancro <ajc@uncensored.citadel.org>"));

       Source = NewStrBufPlain(HKEY("\"Alexandra Weiz, Restless GmbH\" <alexandra.weiz@boblbee.de>, \"NetIN\" <editor@netin.co.il>, \" יריב ברקאי, מולטימדי\" <info@immembed.com>"));     
       Target = StrBufSanitizeEmailRecipientVector(
              Source,
              UserName, 
              EmailAddress,
              EncBuf
              );            
       
       TestRevalidateStrBuf(Target);
       printf("the source:>%s<\n", ChrPtr(Source));
       printf("the target:>%s<\n", ChrPtr(Target));
       FreeStrBuf(&Target);
       FreeStrBuf(&UserName);
       FreeStrBuf(&EmailAddress);
       FreeStrBuf(&EncBuf);

       FreeStrBuf(&Source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestEncodeEmailSTDIN ( void  ) [static]

Definition at line 290 of file stringbuf_conversion.c.

{
       int fdin = 0;// STDIN
       const char *Err;
       StrBuf *Target;
       StrBuf *Source;
       StrBuf *UserName = NewStrBuf();
       StrBuf *EmailAddress = NewStrBuf();
       StrBuf *EncBuf = NewStrBuf();
       
       Source = NewStrBuf();

       while (fdin == 0) {

              StrBufTCP_read_line(Source, &fdin, 0, &Err);
              printf("the source:>%s<\n", ChrPtr(Source));
              Target = StrBufSanitizeEmailRecipientVector(
                     Source,
                     UserName, 
                     EmailAddress,
                     EncBuf
                     );
              
              TestRevalidateStrBuf(Target);
              printf("the target:>%s<\n", ChrPtr(Target));
              FreeStrBuf(&Target);
       }
       FreeStrBuf(&UserName);
       FreeStrBuf(&EmailAddress);
       FreeStrBuf(&EncBuf);

       FreeStrBuf(&Source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestEscEncodeStdin ( void  ) [static]

Definition at line 161 of file stringbuf_conversion.c.

{
       int fdin = 0;// STDIN
       const char *Err;
       StrBuf *Target;
       StrBuf *Source;

       Source = NewStrBuf();

       while (fdin == 0) {

              StrBufTCP_read_line(Source, &fdin, 0, &Err);
              Target = NewStrBuf();
              
              StrEscAppend(Target, Source, NULL, 0, 0);
              
              TestRevalidateStrBuf(Target);
              printf("%s\n", ChrPtr(Target));
              FreeStrBuf(&Target);
       }
       FreeStrBuf(&Source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestHTML2ASCII_line ( void  ) [static]

Definition at line 325 of file stringbuf_conversion.c.

{
       int fdin = 0;// STDIN
       const char *Err;
       StrBuf *Source;
       char *Target;

       Source = NewStrBuf();

       while (fdin == 0) {
              
              StrBufTCP_read_line(Source, &fdin, 0, &Err);
              printf("the source:>%s<\n", ChrPtr(Source));
              Target = html_to_ascii(ChrPtr(Source), StrLength(Source), 80, 0);
              
              printf("the target:>%s<\n", Target);
              FlushStrBuf(Source);
              free(Target);
       }

       FreeStrBuf(&Source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestHtmlEcmaEscEncodeStdin ( void  ) [static]

Definition at line 210 of file stringbuf_conversion.c.

{
       int fdin = 0;// STDIN
       const char *Err;
       StrBuf *Target;
       StrBuf *Source;

       Source = NewStrBuf();

       printf("[");
       while (fdin == 0) {

              StrBufTCP_read_line(Source, &fdin, 0, &Err);
              Target = NewStrBuf();
              
              StrHtmlEcmaEscAppend(Target, Source, NULL, 0, 2);
              
              TestRevalidateStrBuf(Target);
              printf("\"%s\",\n", ChrPtr(Target));
              FreeStrBuf(&Target);
       }
       printf("]");
       FreeStrBuf(&Source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestHTMLEscEncodeStdin ( void  ) [static]

Definition at line 138 of file stringbuf_conversion.c.

{
       int fdin = 0;// STDIN
       const char *Err;
       StrBuf *Target;
       StrBuf *Source;

       Source = NewStrBuf();

       while (fdin == 0) {

              StrBufTCP_read_line(Source, &fdin, 0, &Err);
              Target = NewStrBuf();
              
              StrEscAppend(Target, Source, NULL, 0, 2);
              
              TestRevalidateStrBuf(Target);
              printf("%s\n", ChrPtr(Target));
              FreeStrBuf(&Target);
       }
       FreeStrBuf(&Source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestRevalidateStrBuf ( StrBuf Buf) [static]

Definition at line 32 of file stringbuf_conversion.c.

{
       CU_ASSERT(strlen(ChrPtr(Buf)) == StrLength(Buf));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestRFC822Decode ( void  ) [static]

Definition at line 69 of file stringbuf_conversion.c.

{
       StrBuf *Target;
       StrBuf *Source;
       StrBuf *DefaultCharset;
       StrBuf *FoundCharset;
       
       DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
       FoundCharset = NewStrBuf();
       Source = NewStrBufPlain(HKEY("=?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?="));
       Target = NewStrBuf();

       StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);


       TestRevalidateStrBuf(Target);
       printf("the ugly multi:>%s<\n", ChrPtr(Target));
       FreeStrBuf(&Source);
       FreeStrBuf(&Target);
       FreeStrBuf(&FoundCharset);
       FreeStrBuf(&DefaultCharset);


       DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
       FoundCharset = NewStrBuf();
       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"));
       Target = NewStrBufPlain(NULL, 256);

       StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
       TestRevalidateStrBuf(Target);
       printf("the ugly multi:>%s<\n", ChrPtr(Target));
       FreeStrBuf(&Source);
       FreeStrBuf(&Target);
       FreeStrBuf(&FoundCharset);
       FreeStrBuf(&DefaultCharset);

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestRFC822DecodeStdin ( void  ) [static]

Definition at line 108 of file stringbuf_conversion.c.

{
       int fdin = 0;// STDIN
       const char *Err;
       StrBuf *Target;
       StrBuf *Source;
       StrBuf *DefaultCharset;
       StrBuf *FoundCharset;
       
       DefaultCharset = NewStrBufPlain(HKEY("iso-8859-1"));
       FoundCharset = NewStrBuf();
       Source = NewStrBuf();

       while (fdin == 0) {

              StrBufTCP_read_line(Source, &fdin, 0, &Err);
              Target = NewStrBuf();
              
              StrBuf_RFC822_to_Utf8(Target, Source, DefaultCharset, FoundCharset);
              
              TestRevalidateStrBuf(Target);
              printf("the ugly multi:>%s<\n", ChrPtr(Target));
              FreeStrBuf(&Target);
       }
       FreeStrBuf(&Source);
       FreeStrBuf(&FoundCharset);
       FreeStrBuf(&DefaultCharset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestUrlescEncodeStdin ( void  ) [static]

Definition at line 235 of file stringbuf_conversion.c.

{
       int fdin = 0;// STDIN
       const char *Err;
       StrBuf *Target;
       StrBuf *Source;

       Source = NewStrBuf();

       while (fdin == 0) {

              StrBufTCP_read_line(Source, &fdin, 0, &Err);
              Target = NewStrBuf();
              
              StrBufUrlescAppend(Target, Source, NULL);
              
              TestRevalidateStrBuf(Target);
              printf("%s\n", ChrPtr(Target));
              FreeStrBuf(&Target);
       }
       FreeStrBuf(&Source);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int fromstdin = 0

Definition at line 26 of file stringbuf_conversion.c.

int OutputEscape = 0

Definition at line 29 of file stringbuf_conversion.c.

int OutputEscapeAs = 0

Definition at line 30 of file stringbuf_conversion.c.

int parse_email = 0

Definition at line 27 of file stringbuf_conversion.c.

int parse_html = 0

Definition at line 28 of file stringbuf_conversion.c.