]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/apr-util/test/teststrmatch.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / apr-util / test / teststrmatch.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 "testutil.h"
18
19 #include "apr.h"
20 #include "apr_general.h"
21 #include "apr_strmatch.h"
22 #if APR_HAVE_STDLIB_H
23 #include <stdlib.h>
24 #endif
25 #define APR_WANT_STDIO
26 #define APR_WANT_STRFUNC
27 #include "apr_want.h"
28
29 static void test_str(abts_case *tc, void *data)
30 {
31     apr_pool_t *pool = p;
32     const apr_strmatch_pattern *pattern;
33     const apr_strmatch_pattern *pattern_nocase;
34     const apr_strmatch_pattern *pattern_onechar;
35     const apr_strmatch_pattern *pattern_zero;
36     const char *match = NULL;
37     const char *input1 = "string that contains a patterN...";
38     const char *input2 = "string that contains a pattern...";
39     const char *input3 = "pattern at the start of a string";
40     const char *input4 = "string that ends with a pattern";
41     const char *input5 = "patter\200n not found, negative chars in input";
42     const char *input6 = "patter\200n, negative chars, contains pattern...";
43
44     pattern = apr_strmatch_precompile(pool, "pattern", 1);
45     ABTS_PTR_NOTNULL(tc, pattern);
46  
47     pattern_nocase = apr_strmatch_precompile(pool, "pattern", 0);
48     ABTS_PTR_NOTNULL(tc, pattern_nocase);
49
50     pattern_onechar = apr_strmatch_precompile(pool, "g", 0);
51     ABTS_PTR_NOTNULL(tc, pattern_onechar);
52
53     pattern_zero = apr_strmatch_precompile(pool, "", 0);
54     ABTS_PTR_NOTNULL(tc, pattern_zero);
55
56     match = apr_strmatch(pattern, input1, strlen(input1));
57     ABTS_PTR_EQUAL(tc, NULL, match);
58
59     match = apr_strmatch(pattern, input2, strlen(input2));
60     ABTS_PTR_EQUAL(tc, input2 + 23, match);
61
62     match = apr_strmatch(pattern_onechar, input1, strlen(input1));
63     ABTS_PTR_EQUAL(tc, input1 + 5, match);
64
65     match = apr_strmatch(pattern_zero, input1, strlen(input1));
66     ABTS_PTR_EQUAL(tc, input1, match);
67
68     match = apr_strmatch(pattern_nocase, input1, strlen(input1));
69     ABTS_PTR_EQUAL(tc, input1 + 23, match);
70
71     match = apr_strmatch(pattern, input3, strlen(input3));
72     ABTS_PTR_EQUAL(tc, input3, match);
73
74     match = apr_strmatch(pattern, input4, strlen(input4));
75     ABTS_PTR_EQUAL(tc, input4 + 24, match);
76
77     match = apr_strmatch(pattern, input5, strlen(input5));
78     ABTS_PTR_EQUAL(tc, NULL, match);
79
80     match = apr_strmatch(pattern, input6, strlen(input6));
81     ABTS_PTR_EQUAL(tc, input6 + 35, match);
82 }
83
84 abts_suite *teststrmatch(abts_suite *suite)
85 {
86     suite = ADD_SUITE(suite);
87
88     abts_run_test(suite, test_str, NULL);
89
90     return suite;
91 }
92