Back to index

libcitadel  8.12
stripallbut_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 <stdarg.h>
00020 
00021     
00022 #ifndef CUNIT_AUTOMATED_H_SEEN
00023 #define CUNIT_AUTOMATED_H_SEEN
00024 
00025 #include <CUnit/CUnit.h>
00026 #include <CUnit/Basic.h>
00027 #include <CUnit/TestDB.h>
00028 
00029 
00030 CU_EXPORT void         CU_automated_run_tests(void);
00031 CU_EXPORT CU_ErrorCode CU_list_tests_to_file(void);
00032 CU_EXPORT void         CU_set_output_filename(const char* szFilenameRoot);
00033 
00034 
00035 #endif  /*  CUNIT_AUTOMATED_H_SEEN  */
00036 
00037 #include <stdlib.h>
00038 #include <unistd.h>
00039 #include <ctype.h>
00040 #include <stdio.h>
00041 #include <string.h>
00042 #include <assert.h>
00043 
00044 #include "../lib/libcitadel.h"
00045 
00046 static void TestStripAllBut(void) {
00047        int i;
00048        long l;
00049 
00050        char *teststrings[] = {
00051               "Nmm <fghjk> tyutyu",
00052               "Sdd <> ghhjjkk",
00053               "<>",
00054               "",
00055               "Sdd <",
00056               "Df Ghjkl>",
00057               ">< bggt",
00058               "FSDFSDFSDFSDF<><><>bggt",
00059               "FSDFSDFSDF<><eoeo><>bggt",
00060               "Abc<QWER>",
00061               "><",
00062               "Zxcv<dy<<lkj>>>"
00063        };
00064 
00065        char *strippedstrings[] = {
00066               "fghjk",
00067               "",
00068               "",
00069               "",
00070               "Sdd <",
00071               "Df Ghjkl>",
00072               ">< bggt",
00073               "FSDFSDFSDFSDF<><><>bggt",
00074               "FSDFSDFSDF<><eoeo><>bggt",
00075               "QWER",
00076               "><",
00077               "lkj"
00078        };
00079 
00080        long strippedlens[] = {
00081               5,
00082               0,
00083               0,
00084               0,
00085               5,
00086               9,
00087               7,
00088               23,
00089               24,
00090               4,
00091               2,
00092               3
00093        };
00094 
00095        char foo[128];
00096 
00097        for (i=0; i<(sizeof(teststrings) / sizeof (char *)); ++i) {
00098               strcpy(foo, teststrings[i]);
00099               l = stripallbut(foo, '<', '>');
00100 
00101               CU_ASSERT_STRING_EQUAL(foo, strippedstrings[i]);
00102               CU_ASSERT_EQUAL(strlen(foo), strippedlens[i]);
00103        }
00104 }
00105 
00106 
00107 
00108 static void AddStringToolsTests(void)
00109 {
00110        CU_pSuite pGroup = NULL;
00111        CU_pTest pTest = NULL;
00112 
00113        pGroup = CU_add_suite("TestStringTools", NULL, NULL);
00114        pTest = CU_add_test(pGroup, "testStripAllBut", TestStripAllBut);
00115 }
00116 
00117 int main(int argc, char* argv[])
00118 {
00119        setvbuf(stdout, NULL, _IONBF, 0);
00120 
00121        StartLibCitadel(8);
00122 
00123        CU_set_output_filename("TestAutomated");
00124        if (CU_initialize_registry()) {
00125               printf("\nInitialize of test Registry failed.");
00126               return 1;
00127        }
00128        AddStringToolsTests();
00129        
00130        printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
00131     
00132               
00133        CU_cleanup_registry();
00134        
00135        return 0;
00136 }