upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr-util / test / teststrmatch.c
1 /* Copyright 2002-2005 The Apache Software Foundation or its licensors, as
2  * applicable.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * 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 "apr.h"
18 #include "apr_general.h"
19 #include "apr_strmatch.h"
20 #if APR_HAVE_STDLIB_H
21 #include <stdlib.h>
22 #endif
23 #define APR_WANT_STDIO
24 #define APR_WANT_STRFUNC
25 #include "apr_want.h"
26
27
28 int main (void)
29 {
30     apr_pool_t *pool;
31     const apr_strmatch_pattern *pattern;
32     const apr_strmatch_pattern *pattern_nocase;
33     const apr_strmatch_pattern *pattern_onechar;
34     const apr_strmatch_pattern *pattern_zero;
35     const char *input1 = "string that contains a patterN...";
36     const char *input2 = "string that contains a pattern...";
37     const char *input3 = "pattern at the start of a string";
38     const char *input4 = "string that ends with a pattern";
39     const char *input5 = "patter\200n not found, negative chars in input";
40     const char *input6 = "patter\200n, negative chars, contains pattern...";
41
42     (void) apr_initialize();
43     apr_pool_create(&pool, NULL);
44
45     printf("testing pattern precompilation...");
46     pattern = apr_strmatch_precompile(pool, "pattern", 1);
47     if (!pattern) {
48         printf("FAILED\n");
49         exit(1);
50     }
51     pattern_nocase = apr_strmatch_precompile(pool, "pattern", 0);
52     if (!pattern_nocase) {
53         printf("FAILED\n");
54         exit(1);
55     }
56     pattern_onechar = apr_strmatch_precompile(pool, "g", 0);
57     if (!pattern_onechar) {
58         printf("FAILED\n");
59         exit(1);
60     }
61     pattern_zero = apr_strmatch_precompile(pool, "", 0);
62     if (!pattern_zero) {
63         printf("FAILED\n");
64         exit(1);
65     }
66     printf("OK\n");
67
68     printf("testing invalid match...");
69     if (apr_strmatch(pattern, input1, strlen(input1)) != NULL) {
70         printf("FAILED\n");
71         exit(1);
72     }
73     printf("OK\n");
74
75     printf("testing valid match...");
76     if (apr_strmatch(pattern, input2, strlen(input2)) != input2 + 23) {
77         printf("FAILED\n");
78         exit(1);
79     }
80     printf("OK\n");
81
82     printf("testing single-character match...");
83     if (apr_strmatch(pattern_onechar, input1, strlen(input1)) != input1 + 5) {
84         printf("FAILED\n");
85         exit(1);
86     }
87     printf("OK\n");
88
89     printf("testing zero-length pattern...");
90     if (apr_strmatch(pattern_zero, input1, strlen(input1)) != input1) {
91         printf("FAILED\n");
92         exit(1);
93     }
94     printf("OK\n");
95
96     printf("testing inexact-case match...");
97     if (apr_strmatch(pattern_nocase, input1, strlen(input1)) != input1 + 23) {
98         printf("FAILED\n");
99         exit(1);
100     }
101     printf("OK\n");
102
103     printf("testing match at start of string...");
104     if (apr_strmatch(pattern, input3, strlen(input3)) != input3) {
105         printf("FAILED\n");
106         exit(1);
107     }
108     printf("OK\n");
109
110     printf("testing match at end of string...");
111     if (apr_strmatch(pattern, input4, strlen(input4)) != input4 + 24) {
112         printf("FAILED\n");
113         exit(1);
114     }
115     printf("OK\n");
116
117     printf("testing invalid match with negative chars in input string...");
118     if (apr_strmatch(pattern, input5, strlen(input5)) != NULL) {
119         printf("FAILED\n");
120         exit(1);
121     }
122     printf("OK\n");
123
124     printf("testing valid match with negative chars in input string...");
125     if (apr_strmatch(pattern, input6, strlen(input6)) != input6 + 35) {
126         printf("FAILED\n");
127         exit(1);
128     }
129     printf("OK\n");
130
131     exit(0);
132 }