2 * CUnit - A Unit testing framework library for C.
3 * Copyright (C) 2001 Anil Kumar
5 * This library is open source software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
22 #ifndef CUNIT_AUTOMATED_H_SEEN
23 #define CUNIT_AUTOMATED_H_SEEN
25 #include <CUnit/CUnit.h>
26 #include <CUnit/Basic.h>
27 #include <CUnit/TestDB.h>
30 CU_EXPORT void CU_automated_run_tests(void);
31 CU_EXPORT CU_ErrorCode CU_list_tests_to_file(void);
32 CU_EXPORT void CU_set_output_filename(const char* szFilenameRoot);
35 #endif /* CUNIT_AUTOMATED_H_SEEN */
44 #include "../lib/libcitadel.h"
46 static void TestStripAllBut(void) {
50 char *teststrings[] = {
58 "FSDFSDFSDFSDF<><><>bggt",
59 "FSDFSDFSDF<><eoeo><>bggt",
65 char *strippedstrings[] = {
73 "FSDFSDFSDFSDF<><><>bggt",
74 "FSDFSDFSDF<><eoeo><>bggt",
80 long strippedlens[] = {
96 StrBuf *Test = NewStrBuf();;
98 for (i=0; i<(sizeof(teststrings) / sizeof (char *)); ++i) {
99 strcpy(foo, teststrings[i]);
100 l = stripallbut(foo, '<', '>');
102 CU_ASSERT_STRING_EQUAL(foo, strippedstrings[i]);
103 CU_ASSERT_EQUAL(strlen(foo), strippedlens[i]);
106 StrBufPlain(Test, teststrings[i], -1);
107 StrBufStripAllBut(Test, '<', '>');
109 CU_ASSERT_STRING_EQUAL(ChrPtr(Test), strippedstrings[i]);
110 CU_ASSERT_EQUAL(StrLength(Test), strippedlens[i]);
112 printf("[%s] -> [%s][%s][%s]\n", teststrings[i], foo, ChrPtr(Test), strippedstrings[i]);
118 static void AddStringToolsTests(void)
120 CU_pSuite pGroup = NULL;
121 CU_pTest pTest = NULL;
123 pGroup = CU_add_suite("TestStringTools", NULL, NULL);
124 pTest = CU_add_test(pGroup, "testStripAllBut", TestStripAllBut);
127 int main(int argc, char* argv[])
129 setvbuf(stdout, NULL, _IONBF, 0);
132 CU_set_output_filename("TestAutomated");
133 if (CU_initialize_registry()) {
134 printf("\nInitialize of test Registry failed.");
137 AddStringToolsTests();
139 printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
142 CU_cleanup_registry();