1251876Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251876Speter * contributor license agreements.  See the NOTICE file distributed with
3251876Speter * this work for additional information regarding copyright ownership.
4251876Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251876Speter * (the "License"); you may not use this file except in compliance with
6251876Speter * the License.  You may obtain a copy of the License at
7251876Speter *
8251876Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251876Speter *
10251876Speter * Unless required by applicable law or agreed to in writing, software
11251876Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251876Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251876Speter * See the License for the specific language governing permissions and
14251876Speter * limitations under the License.
15251876Speter */
16251876Speter
17251876Speter#include "testutil.h"
18251876Speter
19251876Speter#include "apr.h"
20251876Speter#include "apr_general.h"
21251876Speter#include "apr_strmatch.h"
22251876Speter#if APR_HAVE_STDLIB_H
23251876Speter#include <stdlib.h>
24251876Speter#endif
25251876Speter#define APR_WANT_STDIO
26251876Speter#define APR_WANT_STRFUNC
27251876Speter#include "apr_want.h"
28251876Speter
29251876Speterstatic void test_str(abts_case *tc, void *data)
30251876Speter{
31251876Speter    apr_pool_t *pool = p;
32251876Speter    const apr_strmatch_pattern *pattern;
33251876Speter    const apr_strmatch_pattern *pattern_nocase;
34251876Speter    const apr_strmatch_pattern *pattern_onechar;
35251876Speter    const apr_strmatch_pattern *pattern_zero;
36251876Speter    const char *match = NULL;
37251876Speter    const char *input1 = "string that contains a patterN...";
38251876Speter    const char *input2 = "string that contains a pattern...";
39251876Speter    const char *input3 = "pattern at the start of a string";
40251876Speter    const char *input4 = "string that ends with a pattern";
41251876Speter    const char *input5 = "patter\200n not found, negative chars in input";
42251876Speter    const char *input6 = "patter\200n, negative chars, contains pattern...";
43251876Speter
44251876Speter    pattern = apr_strmatch_precompile(pool, "pattern", 1);
45251876Speter    ABTS_PTR_NOTNULL(tc, pattern);
46251876Speter
47251876Speter    pattern_nocase = apr_strmatch_precompile(pool, "pattern", 0);
48251876Speter    ABTS_PTR_NOTNULL(tc, pattern_nocase);
49251876Speter
50251876Speter    pattern_onechar = apr_strmatch_precompile(pool, "g", 0);
51251876Speter    ABTS_PTR_NOTNULL(tc, pattern_onechar);
52251876Speter
53251876Speter    pattern_zero = apr_strmatch_precompile(pool, "", 0);
54251876Speter    ABTS_PTR_NOTNULL(tc, pattern_zero);
55251876Speter
56251876Speter    match = apr_strmatch(pattern, input1, strlen(input1));
57251876Speter    ABTS_PTR_EQUAL(tc, NULL, match);
58251876Speter
59251876Speter    match = apr_strmatch(pattern, input2, strlen(input2));
60251876Speter    ABTS_PTR_EQUAL(tc, input2 + 23, match);
61251876Speter
62251876Speter    match = apr_strmatch(pattern_onechar, input1, strlen(input1));
63251876Speter    ABTS_PTR_EQUAL(tc, input1 + 5, match);
64251876Speter
65251876Speter    match = apr_strmatch(pattern_zero, input1, strlen(input1));
66251876Speter    ABTS_PTR_EQUAL(tc, input1, match);
67251876Speter
68251876Speter    match = apr_strmatch(pattern_nocase, input1, strlen(input1));
69251876Speter    ABTS_PTR_EQUAL(tc, input1 + 23, match);
70251876Speter
71251876Speter    match = apr_strmatch(pattern, input3, strlen(input3));
72251876Speter    ABTS_PTR_EQUAL(tc, input3, match);
73251876Speter
74251876Speter    match = apr_strmatch(pattern, input4, strlen(input4));
75251876Speter    ABTS_PTR_EQUAL(tc, input4 + 24, match);
76251876Speter
77251876Speter    match = apr_strmatch(pattern, input5, strlen(input5));
78251876Speter    ABTS_PTR_EQUAL(tc, NULL, match);
79251876Speter
80251876Speter    match = apr_strmatch(pattern, input6, strlen(input6));
81251876Speter    ABTS_PTR_EQUAL(tc, input6 + 35, match);
82251876Speter}
83251876Speter
84251876Speterabts_suite *teststrmatch(abts_suite *suite)
85251876Speter{
86251876Speter    suite = ADD_SUITE(suite);
87251876Speter
88251876Speter    abts_run_test(suite, test_str, NULL);
89251876Speter
90251876Speter    return suite;
91251876Speter}
92251876Speter
93