removed StartLibCitadel()
[citadel.git] / libcitadel / tests / stringbuf_conversion.c
index e2841624219376af3479fca21e4a607ff2beb6fc..c73ece4d273d9489bd647d0391880d1897dabdf0 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  *  CUnit - A Unit testing framework library for C.
  *  Copyright (C) 2001  Anil Kumar
  *  
- *  This library is free software; you can redistribute it and/or
+ *  This library is open source software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
  *  License as published by the Free Software Foundation; either
  *  version 2 of the License, or (at your option) any later version.
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  *  Library General Public License for more details.
- *
- *  You should have received a copy of the GNU Library General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include <stdio.h>
 
 int fromstdin = 0;
 int parse_email = 0;
+int parse_html = 0;
+int OutputEscape = 0;
+int OutputEscapeAs = 0;
+
 static void TestRevalidateStrBuf(StrBuf *Buf)
 {
        CU_ASSERT(strlen(ChrPtr(Buf)) == StrLength(Buf));
@@ -136,6 +135,127 @@ static void TestRFC822DecodeStdin(void)
 }
 
 
+static void TestHTMLEscEncodeStdin(void)
+{
+       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);
+}
+
+static void TestEscEncodeStdin(void)
+{
+       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);
+}
+
+
+static void TestECMAEscEncodeStdin(void)
+{
+       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);
+}
+
+static void TestHtmlEcmaEscEncodeStdin(void)
+{
+       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);
+}
+
+static void TestUrlescEncodeStdin(void)
+{
+       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);
+}
+
+
 static void TestEncodeEmail(void)
 {
        StrBuf *Target;
@@ -201,6 +321,56 @@ static void TestEncodeEmailSTDIN(void)
        FreeStrBuf(&Source);
 }
 
+static void StrBufRFC2047encodeMessageStdin(void)
+{
+       int fdin = 0;// STDIN
+       const char *Err;
+       StrBuf *Target;
+       StrBuf *Source;
+       StrBuf *Src;
+
+       Source = NewStrBuf();
+       Src = NewStrBuf();
+
+       printf("[");
+       while (fdin == 0) {
+
+               StrBufTCP_read_line(Source, &fdin, 0, &Err);
+               StrBufAppendBuf(Src, Source, 0);
+               StrBufAppendBufPlain(Src, HKEY("\n"), 0);
+                               
+       }
+
+       Target = StrBufRFC2047encodeMessage(Src);
+
+       printf("Target: \n%s\n", ChrPtr(Target));
+       FreeStrBuf(&Source);
+       FreeStrBuf(&Src);
+       FreeStrBuf(&Target);
+}
+
+static void TestHTML2ASCII_line(void)
+{
+       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);
+               
+               printf("the target:>%s<\n", Target);
+               FlushStrBuf(Source);
+               free(Target);
+       }
+
+       FreeStrBuf(&Source);
+}
 
 
 static void AddStrBufSimlpeTests(void)
@@ -209,22 +379,52 @@ static void AddStrBufSimlpeTests(void)
        CU_pTest pTest = NULL;
 
        pGroup = CU_add_suite("TestStringBufConversions", NULL, NULL);
-       if (!parse_email) {
+       if (parse_email) {
                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);
+                       pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmail);
                }
                else
-                       pTest = CU_add_test(pGroup, "testRFC822DecodeSTDIN", TestRFC822DecodeStdin);
+                       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, "TestParseEmailSTDIN", TestEncodeEmail);
+                       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
-                       pTest = CU_add_test(pGroup, "TestParseEmailSTDIN", TestEncodeEmailSTDIN);
+               {
+                       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;
+                            case 'R':
+                                    pTest = CU_add_test(pGroup, "StrBufRFC2047encodeMessageStdin", StrBufRFC2047encodeMessageStdin);
+                                    break;
+                            default:
+                                    printf("%c not supported!\n", OutputEscapeAs);
+                                    CU_ASSERT(1);
+                            }
+               }
        }
 
 }
@@ -234,8 +434,18 @@ int main(int argc, char* argv[])
 {
        int a;
 
-       while ((a = getopt(argc, argv, "@i")) != EOF)
+       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;
@@ -248,7 +458,6 @@ int main(int argc, char* argv[])
 
        setvbuf(stdout, NULL, _IONBF, 0);
 
-       StartLibCitadel(8);
        CU_BOOL Run = CU_FALSE ;
        
        CU_set_output_filename("TestAutomated");