X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=libcitadel%2Ftests%2Fstripallbut_test.c;h=22ecf7305eb5907677325d4cb5fb0d488d3f4bf1;hb=b826c3117bb7ddf1386a4811cb2eb47ea4e1097c;hp=2e1d0cff0c52d605bf9bee592d53eb19ac691575;hpb=6d5f6d1b055eb2ac1cb9adf601672ad9f153a6f1;p=citadel.git diff --git a/libcitadel/tests/stripallbut_test.c b/libcitadel/tests/stripallbut_test.c index 2e1d0cff0..22ecf7305 100644 --- a/libcitadel/tests/stripallbut_test.c +++ b/libcitadel/tests/stripallbut_test.c @@ -1,3 +1,39 @@ +/* + * CUnit - A Unit testing framework library for C. + * Copyright (C) 2001 Anil Kumar + * + * 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. + * + * This library is distributed in the hope that it will be useful, + * 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. + */ + +#include +#include +#include +#include + + +#ifndef CUNIT_AUTOMATED_H_SEEN +#define CUNIT_AUTOMATED_H_SEEN + +#include +#include +#include + + +CU_EXPORT void CU_automated_run_tests(void); +CU_EXPORT CU_ErrorCode CU_list_tests_to_file(void); +CU_EXPORT void CU_set_output_filename(const char* szFilenameRoot); + + +#endif /* CUNIT_AUTOMATED_H_SEEN */ + #include #include #include @@ -7,7 +43,7 @@ #include "../lib/libcitadel.h" -main() { +static void TestStripAllBut(void) { int i; long l; @@ -57,15 +93,53 @@ main() { }; char foo[128]; + StrBuf *Test = NewStrBuf();; for (i=0; i<(sizeof(teststrings) / sizeof (char *)); ++i) { - printf("Testing stripallbut()\n"); strcpy(foo, teststrings[i]); l = stripallbut(foo, '<', '>'); - assert(!strcmp(foo, strippedstrings[i])); - assert(strlen(foo) == strippedlens[i]); + CU_ASSERT_STRING_EQUAL(foo, strippedstrings[i]); + CU_ASSERT_EQUAL(strlen(foo), strippedlens[i]); + + + StrBufPlain(Test, teststrings[i], -1); + StrBufStripAllBut(Test, '<', '>'); + + CU_ASSERT_STRING_EQUAL(ChrPtr(Test), strippedstrings[i]); + CU_ASSERT_EQUAL(StrLength(Test), strippedlens[i]); + + printf("[%s] -> [%s][%s][%s]\n", teststrings[i], foo, ChrPtr(Test), strippedstrings[i]); } +} + + - exit(0); +static void AddStringToolsTests(void) +{ + CU_pSuite pGroup = NULL; + CU_pTest pTest = NULL; + + pGroup = CU_add_suite("TestStringTools", NULL, NULL); + pTest = CU_add_test(pGroup, "testStripAllBut", TestStripAllBut); +} + +int main(int argc, char* argv[]) +{ + setvbuf(stdout, NULL, _IONBF, 0); + + + CU_set_output_filename("TestAutomated"); + if (CU_initialize_registry()) { + printf("\nInitialize of test Registry failed."); + return 1; + } + AddStringToolsTests(); + + printf("\nTests completed with return value %d.\n", CU_basic_run_tests()); + + + CU_cleanup_registry(); + + return 0; }