upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / test / testall.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 #include "test_apr.h"
21
22 /* Top-level pool which can be used by tests. */
23 apr_pool_t *p;
24
25 void apr_assert_success(CuTest* tc, const char* context, apr_status_t rv)
26 {
27     if (rv == APR_ENOTIMPL) {
28         CuNotImpl(tc, context);
29     }
30
31     if (rv != APR_SUCCESS) {
32         char buf[STRING_MAX], ebuf[128];
33         sprintf(buf, "%s (%d): %s\n", context, rv,
34                 apr_strerror(rv, ebuf, sizeof ebuf));
35         CuFail(tc, buf);
36     }
37 }
38
39 static const struct testlist {
40     const char *testname;
41     CuSuite *(*func)(void);
42 } tests[] = {
43     {"teststr", teststr},
44     {"testtime", testtime},
45     {"testvsn", testvsn},
46     {"testipsub", testipsub},
47     {"testmmap", testmmap},
48     {"testud", testud},
49     {"testtable", testtable},
50     {"testhash", testhash},
51     {"testsleep", testsleep},
52     {"testpool", testpool},
53     {"testfmt", testfmt},
54     {"testfile", testfile},
55     {"testfileinfo", testfileinfo},
56     {"testpipe", testpipe},
57     {"testdup", testdup},
58     {"testdir", testdir},
59     {"testrand", testrand},
60     {"testdso", testdso},
61     {"testoc", testoc},
62     {"testsockets", testsockets},
63     {"testsockopt", testsockopt},
64     {"testproc", testproc},
65     {"testprocmutex", testprocmutex},
66     {"testpoll", testpoll},
67     {"testlock", testlock},
68     {"testthread", testthread},
69     {"testargs", testgetopt},
70     {"testnames", testnames},
71     {"testuser", testuser},
72     {"testpath", testpath},
73     {"testenv", testenv},
74     {"LastTest", NULL}
75 };
76
77 int main(int argc, char *argv[])
78 {
79     CuSuiteList *alltests = NULL;
80     CuString *output = CuStringNew();
81     int i;
82     int exclude = 0;
83     int list_provided = 0;
84
85     apr_initialize();
86     atexit(apr_terminate);
87
88     CuInit(argc, argv);
89
90     apr_pool_create(&p, NULL);
91
92     /* see if we're in exclude mode, see if list of testcases provided */
93     for (i = 1; i < argc; i++) {
94         if (!strcmp(argv[i], "-v")) {
95             continue;
96         }
97         if (!strcmp(argv[i], "-x")) {
98             exclude = 1;
99             continue;
100         }
101         if (!strcmp(argv[i], "-l")) {
102             for (i = 0; tests[i].func != NULL; i++) {
103                 printf("%s\n", tests[i].testname);
104             }
105             exit(0);
106         }
107         if (argv[i][0] == '-') {
108             fprintf(stderr, "invalid option: `%s'\n", argv[i]);
109             exit(1);
110         }
111         list_provided = 1;
112     }
113
114     if (!list_provided) {
115         /* add everything */
116         alltests = CuSuiteListNew("All APR Tests");
117         for (i = 0; tests[i].func != NULL; i++) {
118             CuSuiteListAdd(alltests, tests[i].func());
119         }
120     }
121     else if (exclude) {
122         /* add everything but the tests listed */
123         alltests = CuSuiteListNew("Partial APR Tests");
124         for (i = 0; tests[i].func != NULL; i++) {
125             int this_test_excluded = 0;
126             int j;
127
128             for (j = 1; j < argc && !this_test_excluded; j++) {
129                 if (!strcmp(argv[j], tests[i].testname)) {
130                     this_test_excluded = 1;
131                 }
132             }
133             if (!this_test_excluded) {
134                 CuSuiteListAdd(alltests, tests[i].func());
135             }
136         }
137     }
138     else {
139         /* add only the tests listed */
140         alltests = CuSuiteListNew("Partial APR Tests");
141         for (i = 1; i < argc; i++) {
142             int j;
143             int found = 0;
144
145             if (argv[i][0] == '-') {
146                 continue;
147             }
148             for (j = 0; tests[j].func != NULL; j++) {
149                 if (!strcmp(argv[i], tests[j].testname)) {
150                     CuSuiteListAdd(alltests, tests[j].func());
151                     found = 1;
152                 }
153             }
154             if (!found) {
155                 fprintf(stderr, "invalid test name: `%s'\n", argv[i]);
156                 exit(1);
157             }
158         }
159     }
160     
161     CuSuiteListRunWithSummary(alltests);
162     i = CuSuiteListDetails(alltests, output);
163     printf("%s\n", output->buffer);
164
165     return i > 0 ? 1 : 0;
166 }
167