| | varnish-cache/lib/libvarnishapi/vsl_glob_test.c |
0 |
|
/*- |
1 |
|
* Copyright (c) 2013 Varnish Software AS |
2 |
|
* All rights reserved. |
3 |
|
* |
4 |
|
* Author: Martin Blix Grydeland <martin@varnish-software.com> |
5 |
|
* |
6 |
|
* SPDX-License-Identifier: BSD-2-Clause |
7 |
|
* |
8 |
|
* Redistribution and use in source and binary forms, with or without |
9 |
|
* modification, are permitted provided that the following conditions |
10 |
|
* are met: |
11 |
|
* 1. Redistributions of source code must retain the above copyright |
12 |
|
* notice, this list of conditions and the following disclaimer. |
13 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
14 |
|
* notice, this list of conditions and the following disclaimer in the |
15 |
|
* documentation and/or other materials provided with the distribution. |
16 |
|
* |
17 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
18 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
19 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
20 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
21 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
22 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
23 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
24 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
25 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
26 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
27 |
|
* SUCH DAMAGE. |
28 |
|
* |
29 |
|
* Test what VSL_Name2Tag and VSL_Glob2Tags produces |
30 |
|
*/ |
31 |
|
|
32 |
|
#ifndef __FLEXELINT__ |
33 |
|
|
34 |
|
#include <fnmatch.h> |
35 |
|
#include <stdint.h> |
36 |
|
#include <stdio.h> |
37 |
|
#include <stdlib.h> |
38 |
|
#include <string.h> |
39 |
|
|
40 |
|
#include "vapi/vsl.h" |
41 |
|
#include "vdef.h" |
42 |
|
#include "vas.h" |
43 |
|
|
44 |
|
#ifndef FNM_CASEFOLD |
45 |
|
# define FNM_CASEFOLD FNM_IGNORECASE |
46 |
|
#endif |
47 |
|
|
48 |
|
static void |
49 |
2450 |
cb(int tag, void *priv) |
50 |
|
{ |
51 |
2450 |
printf("\t%d (%s)\n", tag, VSL_tags[tag]); |
52 |
2450 |
if (priv != NULL) |
53 |
1694 |
assert(!fnmatch(priv, VSL_tags[tag], FNM_CASEFOLD)); |
54 |
2450 |
} |
55 |
|
|
56 |
|
static int |
57 |
140 |
tst_one_glob(const char *p) |
58 |
|
{ |
59 |
|
int i; |
60 |
|
|
61 |
140 |
printf("Test <%s>\n", p); |
62 |
140 |
i = VSL_Glob2Tags(p, -1, cb, TRUST_ME(p)); |
63 |
140 |
printf(" -> %d\n", i); |
64 |
140 |
return (i); |
65 |
|
} |
66 |
|
|
67 |
|
int |
68 |
56 |
main(int argc, char * const *argv) |
69 |
|
{ |
70 |
|
int i, j; |
71 |
|
|
72 |
56 |
if (argc == 1) { |
73 |
14 |
i = tst_one_glob("Req*"); |
74 |
14 |
assert(i == 10); |
75 |
14 |
j = tst_one_glob("reQ*"); |
76 |
14 |
assert(i == j); |
77 |
14 |
assert(tst_one_glob("*Header") > 0); |
78 |
14 |
assert(tst_one_glob("Req*eader") == 1); |
79 |
14 |
assert(tst_one_glob("xyz*y") == -1); |
80 |
14 |
assert(tst_one_glob("*") > 0); |
81 |
14 |
assert(tst_one_glob("a*b*c") == -3); |
82 |
14 |
assert(tst_one_glob("**") == -3); |
83 |
14 |
assert(tst_one_glob("_") == -1); |
84 |
14 |
assert(tst_one_glob("") == -1); |
85 |
14 |
assert(VSL_Glob2Tags("", 0, cb, NULL) == -1); |
86 |
|
|
87 |
14 |
assert(VSL_List2Tags("Req*,Resp*",-1,cb,NULL) > 0); |
88 |
14 |
assert(VSL_List2Tags(",,,",-1,cb,NULL) == -1); |
89 |
14 |
assert(VSL_List2Tags("xyzzy,,xyzzy",-1,cb,NULL) == -1); |
90 |
14 |
return (0); |
91 |
|
} |
92 |
42 |
if (argc != 2) { |
93 |
14 |
fprintf(stderr, "vsl_glob_test <tagname/glob>\n"); |
94 |
14 |
exit(1); |
95 |
|
} |
96 |
|
|
97 |
28 |
i = VSL_Name2Tag(argv[1], -1); |
98 |
28 |
printf("VSL_Name2Tag returns %d", i); |
99 |
28 |
if (i >= 0) |
100 |
0 |
printf(" (%s)", VSL_tags[i]); |
101 |
28 |
printf("\n"); |
102 |
|
|
103 |
28 |
printf("VSL_Glob2Tags:\n"); |
104 |
28 |
i = VSL_Glob2Tags(argv[1], -1, cb, NULL); |
105 |
28 |
printf("VSL_Glob2Tags returns %d\n", i); |
106 |
|
|
107 |
28 |
printf("VSL_List2Tags:\n"); |
108 |
28 |
i = VSL_List2Tags(argv[1], -1, cb, NULL); |
109 |
28 |
printf("VSL_List2Tags returns %d\n", i); |
110 |
|
|
111 |
28 |
return (0); |
112 |
42 |
} |
113 |
|
|
114 |
|
#endif // __FLEXELINT__ |