160107Sobrien/* Licensed to the Apache Software Foundation (ASF) under one or more 243334Syokota * contributor license agreements. See the NOTICE file distributed with 343334Syokota * this work for additional information regarding copyright ownership. 443334Syokota * The ASF licenses this file to You under the Apache License, Version 2.0 543334Syokota * (the "License"); you may not use this file except in compliance with 643334Syokota * the License. You may obtain a copy of the License at 743334Syokota * 843334Syokota * http://www.apache.org/licenses/LICENSE-2.0 943334Syokota * 1043334Syokota * Unless required by applicable law or agreed to in writing, software 1143334Syokota * distributed under the License is distributed on an "AS IS" BASIS, 1243334Syokota * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1343334Syokota * See the License for the specific language governing permissions and 1443334Syokota * limitations under the License. 1543334Syokota */ 1643334Syokota 1743334Syokota#include "testutil.h" 1843334Syokota 1943334Syokota#include "apr.h" 2043334Syokota#include "apr_general.h" 2143334Syokota#include "apr_strmatch.h" 2243334Syokota#if APR_HAVE_STDLIB_H 2343334Syokota#include <stdlib.h> 2443334Syokota#endif 2543334Syokota#define APR_WANT_STDIO 2643334Syokota#define APR_WANT_STRFUNC 2743334Syokota#include "apr_want.h" 2843334Syokota 2943334Syokotastatic void test_str(abts_case *tc, void *data) 3043334Syokota{ 3143334Syokota apr_pool_t *pool = p; 3243334Syokota const apr_strmatch_pattern *pattern; 3343334Syokota const apr_strmatch_pattern *pattern_nocase; 3443334Syokota const apr_strmatch_pattern *pattern_onechar; 3543334Syokota const apr_strmatch_pattern *pattern_zero; 3643334Syokota const char *match = NULL; 3743334Syokota const char *input1 = "string that contains a patterN..."; 3843334Syokota const char *input2 = "string that contains a pattern..."; 3943334Syokota const char *input3 = "pattern at the start of a string"; 4043334Syokota const char *input4 = "string that ends with a pattern"; 4143334Syokota const char *input5 = "patter\200n not found, negative chars in input"; 4243334Syokota const char *input6 = "patter\200n, negative chars, contains pattern..."; 4343334Syokota 4443334Syokota pattern = apr_strmatch_precompile(pool, "pattern", 1); 4543334Syokota ABTS_PTR_NOTNULL(tc, pattern); 4643334Syokota 4743334Syokota pattern_nocase = apr_strmatch_precompile(pool, "pattern", 0); 4843334Syokota ABTS_PTR_NOTNULL(tc, pattern_nocase); 4943334Syokota 5043334Syokota pattern_onechar = apr_strmatch_precompile(pool, "g", 0); 5143334Syokota ABTS_PTR_NOTNULL(tc, pattern_onechar); 5243334Syokota 5343334Syokota pattern_zero = apr_strmatch_precompile(pool, "", 0); 5443334Syokota ABTS_PTR_NOTNULL(tc, pattern_zero); 5543334Syokota 5643334Syokota match = apr_strmatch(pattern, input1, strlen(input1)); 5743334Syokota ABTS_PTR_EQUAL(tc, NULL, match); 5843334Syokota 5943334Syokota match = apr_strmatch(pattern, input2, strlen(input2)); 6043334Syokota ABTS_PTR_EQUAL(tc, input2 + 23, match); 6143334Syokota 6243334Syokota match = apr_strmatch(pattern_onechar, input1, strlen(input1)); 6343334Syokota ABTS_PTR_EQUAL(tc, input1 + 5, match); 6443334Syokota 6543334Syokota match = apr_strmatch(pattern_zero, input1, strlen(input1)); 6643334Syokota ABTS_PTR_EQUAL(tc, input1, match); 6743334Syokota 6843334Syokota match = apr_strmatch(pattern_nocase, input1, strlen(input1)); 6943334Syokota ABTS_PTR_EQUAL(tc, input1 + 23, match); 7043334Syokota 7143334Syokota match = apr_strmatch(pattern, input3, strlen(input3)); 7243334Syokota ABTS_PTR_EQUAL(tc, input3, match); 7343334Syokota 7443334Syokota match = apr_strmatch(pattern, input4, strlen(input4)); 7543334Syokota ABTS_PTR_EQUAL(tc, input4 + 24, match); 7643334Syokota 7743334Syokota match = apr_strmatch(pattern, input5, strlen(input5)); 7843334Syokota ABTS_PTR_EQUAL(tc, NULL, match); 7943334Syokota 8043334Syokota match = apr_strmatch(pattern, input6, strlen(input6)); 8143334Syokota ABTS_PTR_EQUAL(tc, input6 + 35, match); 8243334Syokota} 8343334Syokota 8443334Syokotaabts_suite *teststrmatch(abts_suite *suite) 8543334Syokota{ 8643334Syokota suite = ADD_SUITE(suite); 8743334Syokota 8843334Syokota abts_run_test(suite, test_str, NULL); 8943334Syokota 9043334Syokota return suite; 9143334Syokota} 9243334Syokota 9343334Syokota