You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rb...@apache.org on 2004/03/11 03:42:35 UTC
cvs commit: apr-util/test CuTest.c CuTest.h test_aprutil.h testall.c .cvsignore Makefile.in testuuid.c
rbb 2004/03/10 18:42:34
Modified: test .cvsignore Makefile.in testuuid.c
Added: test CuTest.c CuTest.h test_aprutil.h testall.c
Log:
Add the test framework from APR to APR-util, and port testuuid to the
new framework.
Revision Changes Path
1.10 +1 -1 apr-util/test/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/apr-util/test/.cvsignore,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- .cvsignore 28 May 2003 04:45:46 -0000 1.9
+++ .cvsignore 11 Mar 2004 02:42:34 -0000 1.10
@@ -13,7 +13,7 @@
testreslist
testrmm
testuri
-testuuid
teststrmatch
testdate
testxml
+testall
1.39 +5 -5 apr-util/test/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr-util/test/Makefile.in,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- Makefile.in 16 Feb 2004 15:54:50 -0000 1.38
+++ Makefile.in 11 Mar 2004 02:42:34 -0000 1.39
@@ -61,11 +61,6 @@
teststrmatch: $(teststrmatch_OBJECTS) $(teststrmatch_LDADD)
$(LINK) $(APRUTIL_LDFLAGS) $(teststrmatch_OBJECTS) $(teststrmatch_LDADD) $(PROGRAM_DEPENDENCIES)
-testuuid_OBJECTS = testuuid.lo
-testuuid_LDADD = $(TARGET_LIB_PATH)
-testuuid: $(testuuid_OBJECTS) $(testuuid_LDADD)
- $(LINK) $(APRUTIL_LDFLAGS) $(testuuid_OBJECTS) $(testuuid_LDADD) $(PROGRAM_DEPENDENCIES)
-
testreslist_OBJECTS = testreslist.lo
testreslist_LDADD = $(TARGET_LIB_PATH)
testreslist: $(testreslist_OBJECTS) $(testreslist_LDADD)
@@ -85,4 +80,9 @@
testpass_LDADD = $(TARGET_LIB_PATH)
testpass: $(testpass_OBJECTS) $(testpass_LDADD)
$(LINK) $(APRUTIL_LDFLAGS) $(testpass_OBJECTS) $(testpass_LDADD) $(PROGRAM_DEPENDENCIES)
+
+testall_OBJECTS = testall.lo testuuid.lo CuTest.lo
+testall_LDADD = $(TARGET_LIB_PATH)
+testall: $(testall_OBJECTS) $(testall_LDADD)
+ $(LINK) $(APRUTIL_LDFLAGS) $(testall_OBJECTS) $(testall_LDADD) $(PROGRAM_DEPENDENCIES)
1.4 +21 -23 apr-util/test/testuuid.c
Index: testuuid.c
===================================================================
RCS file: /home/cvs/apr-util/test/testuuid.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- testuuid.c 13 Feb 2004 09:55:26 -0000 1.3
+++ testuuid.c 11 Mar 2004 02:42:34 -0000 1.4
@@ -13,45 +13,43 @@
* limitations under the License.
*/
-#include <stdio.h>
-#include <stdlib.h>
-
+#include "test_aprutil.h"
#include "apr_general.h"
#include "apr_uuid.h"
-
-int main(int argc, char **argv)
+static void test_uuid_parse(CuTest *tc)
{
apr_uuid_t uuid;
apr_uuid_t uuid2;
char buf[APR_UUID_FORMATTED_LENGTH + 1];
- int retcode = 0;
-
- apr_initialize();
- atexit(apr_terminate);
apr_uuid_get(&uuid);
apr_uuid_format(buf, &uuid);
- printf("UUID: %s\n", buf);
apr_uuid_parse(&uuid2, buf);
- if (memcmp(&uuid, &uuid2, sizeof(uuid)) == 0)
- printf("Parse appears to work.\n");
- else {
- printf("ERROR: parse produced a different UUID.\n");
- retcode = 1;
- }
+ CuAssert(tc, "parse produced a different UUID",
+ memcmp(&uuid, &uuid2, sizeof(uuid)) == 0);
+}
- apr_uuid_format(buf, &uuid2);
- printf("parsed/reformatted UUID: %s\n", buf);
+static void test_gen2(CuTest *tc)
+{
+ apr_uuid_t uuid;
+ apr_uuid_t uuid2;
/* generate two of them quickly */
apr_uuid_get(&uuid);
apr_uuid_get(&uuid2);
- apr_uuid_format(buf, &uuid);
- printf("UUID 1: %s\n", buf);
- apr_uuid_format(buf, &uuid2);
- printf("UUID 2: %s\n", buf);
- return retcode;
+ CuAssert(tc, "generated the same UUID twice",
+ memcmp(&uuid, &uuid2, sizeof(uuid)) != 0);
+}
+
+CuSuite *testuuid(void)
+{
+ CuSuite *suite = CuSuiteNew("UUID");
+
+ SUITE_ADD_TEST(suite, test_uuid_parse);
+ SUITE_ADD_TEST(suite, test_gen2);
+
+ return suite;
}
1.1 apr-util/test/CuTest.c
Index: CuTest.c
===================================================================
/*
* Copyright (c) 2002-2006 Asim Jalis
*
* This library is released under the zlib/libpng license as described at
*
* http://www.opensource.org/licenses/zlib-license.html
*
* Here is the statement of the license:
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*/
/*
* This file has been modified from the original distribution.
*/
#include <assert.h>
#include <setjmp.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "CuTest.h"
static int verbose = 0;
void CuInit(int argc, char *argv[])
{
int i;
/* Windows doesn't have getopt, so we have to fake it. We can't use
* apr_getopt, because CuTest is meant to be a stand-alone test suite
*/
for (i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-v")) {
verbose = 1;
}
}
}
/*-------------------------------------------------------------------------*
* CuStr
*-------------------------------------------------------------------------*/
char* CuStrAlloc(int size)
{
char* new = (char*) malloc( sizeof(char) * (size) );
return new;
}
char* CuStrCopy(const char* old)
{
int len = strlen(old);
char* new = CuStrAlloc(len + 1);
strcpy(new, old);
return new;
}
/*-------------------------------------------------------------------------*
* CuString
*-------------------------------------------------------------------------*/
void CuStringInit(CuString* str)
{
str->length = 0;
str->size = STRING_MAX;
str->buffer = (char*) malloc(sizeof(char) * str->size);
str->buffer[0] = '\0';
}
CuString* CuStringNew(void)
{
CuString* str = (CuString*) malloc(sizeof(CuString));
str->length = 0;
str->size = STRING_MAX;
str->buffer = (char*) malloc(sizeof(char) * str->size);
str->buffer[0] = '\0';
return str;
}
void CuStringResize(CuString* str, int newSize)
{
str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
str->size = newSize;
}
void CuStringAppend(CuString* str, const char* text)
{
int length = strlen(text);
if (str->length + length + 1 >= str->size)
CuStringResize(str, str->length + length + 1 + STRING_INC);
str->length += length;
strcat(str->buffer, text);
}
void CuStringAppendChar(CuString* str, char ch)
{
char text[2];
text[0] = ch;
text[1] = '\0';
CuStringAppend(str, text);
}
void CuStringAppendFormat(CuString* str, const char* format, ...)
{
va_list argp;
char buf[HUGE_STRING_LEN];
va_start(argp, format);
vsprintf(buf, format, argp);
va_end(argp);
CuStringAppend(str, buf);
}
void CuStringRead(CuString *str, char *path)
{
path = strdup(str->buffer);
}
/*-------------------------------------------------------------------------*
* CuTest
*-------------------------------------------------------------------------*/
void CuTestInit(CuTest* t, char* name, TestFunction function)
{
t->name = CuStrCopy(name);
t->notimpl = 0;
t->failed = 0;
t->ran = 0;
t->message = NULL;
t->function = function;
t->jumpBuf = NULL;
}
CuTest* CuTestNew(char* name, TestFunction function)
{
CuTest* tc = CU_ALLOC(CuTest);
CuTestInit(tc, name, function);
return tc;
}
void CuNotImpl(CuTest* tc, const char* message)
{
CuString* newstr = CuStringNew();
CuStringAppend(newstr, message);
CuStringAppend(newstr, " not implemented on this platform");
tc->notimpl = 1;
tc->message = CuStrCopy(newstr->buffer);
if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
}
void CuFail(CuTest* tc, const char* message)
{
tc->failed = 1;
tc->message = CuStrCopy(message);
if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
}
void CuAssert(CuTest* tc, const char* message, int condition)
{
if (condition) return;
CuFail(tc, message);
}
void CuAssertTrue(CuTest* tc, int condition)
{
if (condition) return;
CuFail(tc, "assert failed");
}
void CuAssertStrNEquals(CuTest* tc, const char* expected, const char* actual,
int n)
{
CuString* message;
if (strncmp(expected, actual, n) == 0) return;
message = CuStringNew();
CuStringAppend(message, "expected\n---->\n");
CuStringAppend(message, expected);
CuStringAppend(message, "\n<----\nbut saw\n---->\n");
CuStringAppend(message, actual);
CuStringAppend(message, "\n<----");
CuFail(tc, message->buffer);
}
void CuAssertStrEquals(CuTest* tc, const char* expected, const char* actual)
{
CuString* message;
if (strcmp(expected, actual) == 0) return;
message = CuStringNew();
CuStringAppend(message, "expected\n---->\n");
CuStringAppend(message, expected);
CuStringAppend(message, "\n<----\nbut saw\n---->\n");
CuStringAppend(message, actual);
CuStringAppend(message, "\n<----");
CuFail(tc, message->buffer);
}
void CuAssertIntEquals(CuTest* tc, int expected, int actual)
{
char buf[STRING_MAX];
if (expected == actual) return;
sprintf(buf, "expected <%d> but was <%d>", expected, actual);
CuFail(tc, buf);
}
void CuAssertPtrEquals(CuTest* tc, const void* expected, const void* actual)
{
char buf[STRING_MAX];
if (expected == actual) return;
sprintf(buf, "expected pointer <%p> but was <%p>", expected, actual);
CuFail(tc, buf);
}
void CuAssertPtrNotNull(CuTest* tc, const void* pointer)
{
char buf[STRING_MAX];
if (pointer != NULL ) return;
sprintf(buf, "null pointer unexpected, but was <%p>", pointer);
CuFail(tc, buf);
}
void CuTestRun(CuTest* tc)
{
jmp_buf buf;
tc->jumpBuf = &buf;
if (setjmp(buf) == 0)
{
tc->ran = 1;
(tc->function)(tc);
}
tc->jumpBuf = 0;
}
/*-------------------------------------------------------------------------*
* CuSuite
*-------------------------------------------------------------------------*/
void CuSuiteInit(CuSuite* testSuite, char *name)
{
testSuite->name = strdup(name);
testSuite->count = 0;
testSuite->failCount = 0;
testSuite->notimplCount = 0;
}
CuSuite* CuSuiteNew(char *name)
{
CuSuite* testSuite = CU_ALLOC(CuSuite);
CuSuiteInit(testSuite, name);
return testSuite;
}
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase)
{
assert(testSuite->count < MAX_TEST_CASES);
testSuite->list[testSuite->count] = testCase;
testSuite->count++;
}
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2)
{
int i;
for (i = 0 ; i < testSuite2->count ; ++i)
{
CuTest* testCase = testSuite2->list[i];
CuSuiteAdd(testSuite, testCase);
}
}
void CuSuiteRun(CuSuite* testSuite)
{
int i;
for (i = 0 ; i < testSuite->count ; ++i)
{
CuTest* testCase = testSuite->list[i];
CuTestRun(testCase);
if (testCase->failed) { testSuite->failCount += 1; }
if (testCase->notimpl) { testSuite->notimplCount += 1; }
}
}
void CuSuiteSummary(CuSuite* testSuite, CuString* summary)
{
int i;
for (i = 0 ; i < testSuite->count ; ++i)
{
CuTest* testCase = testSuite->list[i];
CuStringAppend(summary, testCase->failed ? "F" :
testCase->notimpl ? "N": ".");
}
CuStringAppend(summary, "\n");
}
void CuSuiteOverView(CuSuite* testSuite, CuString* details)
{
CuStringAppendFormat(details, "%d %s run: %d passed, %d failed, "
"%d not implemented.\n",
testSuite->count,
testSuite->count == 1 ? "test" : "tests",
testSuite->count - testSuite->failCount -
testSuite->notimplCount,
testSuite->failCount, testSuite->notimplCount);
}
void CuSuiteDetails(CuSuite* testSuite, CuString* details)
{
int i;
int failCount = 0;
if (testSuite->failCount != 0 && verbose)
{
CuStringAppendFormat(details, "\nFailed tests in %s:\n", testSuite->name);
for (i = 0 ; i < testSuite->count ; ++i)
{
CuTest* testCase = testSuite->list[i];
if (testCase->failed)
{
failCount++;
CuStringAppendFormat(details, "%d) %s: %s\n",
failCount, testCase->name, testCase->message);
}
}
}
if (testSuite->notimplCount != 0 && verbose)
{
CuStringAppendFormat(details, "\nNot Implemented tests in %s:\n", testSuite->name);
for (i = 0 ; i < testSuite->count ; ++i)
{
CuTest* testCase = testSuite->list[i];
if (testCase->notimpl)
{
failCount++;
CuStringAppendFormat(details, "%d) %s: %s\n",
failCount, testCase->name, testCase->message);
}
}
}
}
/*-------------------------------------------------------------------------*
* CuSuiteList
*-------------------------------------------------------------------------*/
CuSuiteList* CuSuiteListNew(char *name)
{
CuSuiteList* testSuite = CU_ALLOC(CuSuiteList);
testSuite->name = strdup(name);
testSuite->count = 0;
return testSuite;
}
void CuSuiteListAdd(CuSuiteList *suites, CuSuite *origsuite)
{
assert(suites->count < MAX_TEST_CASES);
suites->list[suites->count] = origsuite;
suites->count++;
}
void CuSuiteListRun(CuSuiteList* testSuite)
{
int i;
for (i = 0 ; i < testSuite->count ; ++i)
{
CuSuite* testCase = testSuite->list[i];
CuSuiteRun(testCase);
}
}
static const char *genspaces(int i)
{
char *str = malloc((i + 1) * sizeof(char));
memset(str, ' ', i);
str[i] = '\0';
return str;
}
void CuSuiteListRunWithSummary(CuSuiteList* testSuite)
{
int i;
printf("%s:\n", testSuite->name);
for (i = 0 ; i < testSuite->count ; ++i)
{
CuSuite* testCase = testSuite->list[i];
CuString *str = CuStringNew();
printf(" %s:%s", testCase->name,
genspaces(21 - strlen(testCase->name)));
fflush(stdout);
CuSuiteRun(testCase);
CuSuiteSummary(testCase, str);
printf(" %s", str->buffer);
}
printf("\n");
}
void CuSuiteListSummary(CuSuiteList* testSuite, CuString* summary)
{
int i;
CuStringAppendFormat(summary, "%s:\n", testSuite->name);
for (i = 0 ; i < testSuite->count ; ++i)
{
CuSuite* testCase = testSuite->list[i];
CuString *str = CuStringNew();
CuSuiteSummary(testCase, str);
CuStringAppend(summary, " ");
CuStringAppend(summary, str->buffer);
}
CuStringAppend(summary, "\n");
}
int CuSuiteListDetails(CuSuiteList* testSuite, CuString* details)
{
int i;
int failCount = 0;
int notImplCount = 0;
int count = 0;
for (i = 0 ; i < testSuite->count ; ++i)
{
failCount += testSuite->list[i]->failCount;
notImplCount += testSuite->list[i]->notimplCount;
count += testSuite->list[i]->count;
}
CuStringAppendFormat(details, "%d %s run: %d passed, %d failed, "
"%d not implemented.\n",
count,
count == 1 ? "test" : "tests",
count - failCount - notImplCount,
failCount, notImplCount);
if (failCount != 0 && verbose)
{
for (i = 0 ; i < testSuite->count ; ++i)
{
CuString *str = CuStringNew();
CuSuite* testCase = testSuite->list[i];
if (testCase->failCount)
{
CuSuiteDetails(testCase, str);
CuStringAppend(details, str->buffer);
}
}
}
if (notImplCount != 0 && verbose)
{
for (i = 0 ; i < testSuite->count ; ++i)
{
CuString *str = CuStringNew();
CuSuite* testCase = testSuite->list[i];
if (testCase->notimplCount)
{
CuSuiteDetails(testCase, str);
CuStringAppend(details, str->buffer);
}
}
}
return failCount;
}
1.1 apr-util/test/CuTest.h
Index: CuTest.h
===================================================================
/*
* Copyright (c) 2002-2006 Asim Jalis
*
* This library is released under the zlib/libpng license as described at
*
* http://www.opensource.org/licenses/zlib-license.html
*
* Here is the statement of the license:
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*/
/*
* This file has been modified from the original distribution.
*/
#ifndef CU_TEST_H
#define CU_TEST_H
#include <setjmp.h>
#include <stdarg.h>
/* CuString */
char* CuStrAlloc(int size);
char* CuStrCopy(const char* old);
#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
#define HUGE_STRING_LEN 8192
#define STRING_MAX 256
#define STRING_INC 256
typedef struct
{
int length;
int size;
char* buffer;
} CuString;
void CuStringInit(CuString* str);
CuString* CuStringNew(void);
void CuStringRead(CuString* str, char* path);
void CuStringAppend(CuString* str, const char* text);
void CuStringAppendChar(CuString* str, char ch);
void CuStringAppendFormat(CuString* str, const char* format, ...);
void CuStringResize(CuString* str, int newSize);
/* CuTest */
typedef struct CuTest CuTest;
typedef void (*TestFunction)(CuTest *);
struct CuTest
{
char* name;
TestFunction function;
int notimpl;
int failed;
int ran;
char* message;
jmp_buf *jumpBuf;
};
void CuInit(int argc, char *argv[]);
void CuTestInit(CuTest* t, char* name, TestFunction function);
CuTest* CuTestNew(char* name, TestFunction function);
void CuFail(CuTest* tc, const char* message);
void CuNotImpl(CuTest* tc, const char* message);
void CuAssert(CuTest* tc, const char* message, int condition);
void CuAssertTrue(CuTest* tc, int condition);
void CuAssertStrEquals(CuTest* tc, const char* expected, const char* actual);
void CuAssertStrNEquals(CuTest* tc, const char* expected, const char* actual,
int n);
void CuAssertIntEquals(CuTest* tc, int expected, int actual);
void CuAssertPtrEquals(CuTest* tc, const void* expected, const void* actual);
void CuAssertPtrNotNull(CuTest* tc, const void* pointer);
void CuTestRun(CuTest* tc);
/* CuSuite */
#define MAX_TEST_CASES 1024
#define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST))
typedef struct
{
char *name;
int count;
CuTest* list[MAX_TEST_CASES];
int failCount;
int notimplCount;
} CuSuite;
void CuSuiteInit(CuSuite* testSuite, char* name);
CuSuite* CuSuiteNew(char* name);
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase);
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2);
void CuSuiteRun(CuSuite* testSuite);
void CuSuiteSummary(CuSuite* testSuite, CuString* summary);
void CuSuiteOverView(CuSuite* testSuite, CuString* details);
void CuSuiteDetails(CuSuite* testSuite, CuString* details);
typedef struct
{
char *name;
int count;
CuSuite* list[MAX_TEST_CASES];
} CuSuiteList;
CuSuiteList* CuSuiteListNew(char* name);
void CuSuiteListAdd(CuSuiteList* testSuite, CuSuite *testCase);
void CuSuiteListRun(CuSuiteList* testSuite);
void CuSuiteListRunWithSummary(CuSuiteList* testSuite);
void CuSuiteListSummary(CuSuiteList* testSuite, CuString* summary);
/* Print details of test suite results; returns total number of
* tests which failed. */
int CuSuiteListDetails(CuSuiteList* testSuite, CuString* details);
#endif /* CU_TEST_H */
1.1 apr-util/test/test_aprutil.h
Index: test_aprutil.h
===================================================================
/* Copyright 2000-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef APR_TEST_INCLUDES
#define APR_TEST_INCLUDES
#include "CuTest.h"
#include "apr_pools.h"
/* Some simple functions to make the test apps easier to write and
* a bit more consistent...
*/
extern apr_pool_t *p;
CuSuite *getsuite(void);
CuSuite *testuuid(void);
/* Assert that RV is an APR_SUCCESS value; else fail giving strerror
* for RV and CONTEXT message. */
void apr_assert_success(CuTest* tc, const char *context, apr_status_t rv);
#endif /* APR_TEST_INCLUDES */
1.1 apr-util/test/testall.c
Index: testall.c
===================================================================
/* Copyright 2000-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include "test_aprutil.h"
/* Top-level pool which can be used by tests. */
apr_pool_t *p;
void apr_assert_success(CuTest* tc, const char* context, apr_status_t rv)
{
if (rv == APR_ENOTIMPL) {
CuNotImpl(tc, context);
}
if (rv != APR_SUCCESS) {
char buf[STRING_MAX], ebuf[128];
sprintf(buf, "%s (%d): %s\n", context, rv,
apr_strerror(rv, ebuf, sizeof ebuf));
CuFail(tc, buf);
}
}
static const struct testlist {
const char *testname;
CuSuite *(*func)(void);
} tests[] = {
{"testuuid", testuuid},
{"LastTest", NULL}
};
int main(int argc, char *argv[])
{
CuSuiteList *alltests = NULL;
CuString *output = CuStringNew();
int i;
int exclude = 0;
int list_provided = 0;
apr_initialize();
atexit(apr_terminate);
CuInit(argc, argv);
apr_pool_create(&p, NULL);
/* see if we're in exclude mode, see if list of testcases provided */
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-v")) {
continue;
}
if (!strcmp(argv[i], "-x")) {
exclude = 1;
continue;
}
if (!strcmp(argv[i], "-l")) {
for (i = 0; tests[i].func != NULL; i++) {
printf("%s\n", tests[i].testname);
}
exit(0);
}
if (argv[i][0] == '-') {
fprintf(stderr, "invalid option: `%s'\n", argv[i]);
exit(1);
}
list_provided = 1;
}
if (!list_provided) {
/* add everything */
alltests = CuSuiteListNew("All APR-UTIL Tests");
for (i = 0; tests[i].func != NULL; i++) {
CuSuiteListAdd(alltests, tests[i].func());
}
}
else if (exclude) {
/* add everything but the tests listed */
alltests = CuSuiteListNew("Partial APR-UTIL Tests");
for (i = 0; tests[i].func != NULL; i++) {
int this_test_excluded = 0;
int j;
for (j = 1; j < argc && !this_test_excluded; j++) {
if (!strcmp(argv[j], tests[i].testname)) {
this_test_excluded = 1;
}
}
if (!this_test_excluded) {
CuSuiteListAdd(alltests, tests[i].func());
}
}
}
else {
/* add only the tests listed */
alltests = CuSuiteListNew("Partial APR-UTIL Tests");
for (i = 1; i < argc; i++) {
int j;
int found = 0;
if (argv[i][0] == '-') {
continue;
}
for (j = 0; tests[j].func != NULL; j++) {
if (!strcmp(argv[i], tests[j].testname)) {
CuSuiteListAdd(alltests, tests[j].func());
found = 1;
}
}
if (!found) {
fprintf(stderr, "invalid test name: `%s'\n", argv[i]);
exit(1);
}
}
}
CuSuiteListRunWithSummary(alltests);
i = CuSuiteListDetails(alltests, output);
printf("%s\n", output->buffer);
return i > 0 ? 1 : 0;
}