]>
Commit | Line | Data |
---|---|---|
43ae1d95 | 1 | /* |
dc4eb86a | 2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
43ae1d95 | 3 | * |
dc4eb86a AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
43ae1d95 | 7 | */ |
8 | ||
99742866 FC |
9 | #include "squid.h" |
10 | #include "libTrie/Trie.h" | |
11 | #include "libTrie/TrieCharTransform.h" | |
27e059d4 | 12 | |
43ae1d95 | 13 | #include <iostream> |
14 | ||
924f73bc | 15 | bool |
16 | CaseSensitiveCheck() | |
43ae1d95 | 17 | { |
18 | Trie aTrie; | |
19 | ||
20 | if (!aTrie.add ("User-Agent", 10, (void *)1)) { | |
21 | std::cerr << "Could not add User-Agent" << std::endl; | |
22 | return 1; | |
23 | } | |
24 | ||
25 | if (aTrie.add ("User-Agent", 10, (void *)2)) { | |
26 | std::cerr << "Could add duplicate User-Agent" << std::endl; | |
27 | return 1; | |
28 | } | |
29 | ||
30 | if (!aTrie.add ("Alphabet", 8, (void *)3)) { | |
31 | std::cerr << "Could not add Alphabet" << std::endl; | |
32 | return 1; | |
33 | } | |
34 | ||
924f73bc | 35 | if (!aTrie.add ("Uprefix", 8, (void *)3)) { |
36 | std::cerr << "Could not add Uprefix" << std::endl; | |
37 | return 1; | |
38 | } | |
39 | ||
40 | if (aTrie.find ("User-Agent", 10) != (void *)1) { | |
41 | std::cerr << "Could not find User-Agent" << std::endl; | |
42 | return 1; | |
43 | } | |
44 | ||
45 | if (aTrie.find ("user-agent", 10) == (void *)1) { | |
46 | std::cerr << "found user-agent" << std::endl; | |
47 | return 1; | |
48 | } | |
49 | ||
50 | if (aTrie.findPrefix("User-AgentFoo" , 13) != (void *)1) { | |
51 | std::cerr << "Could not find User prefix" << std::endl; | |
52 | return 1; | |
53 | } | |
54 | ||
55 | if (aTrie.findPrefix("user-agentFoo" , 13) == (void *)1) { | |
56 | std::cerr << "found user prefix" << std::endl; | |
57 | return 1; | |
58 | } | |
59 | ||
60 | return 0; | |
61 | } | |
62 | ||
63 | bool | |
64 | CaseInsensitiveCheck() | |
65 | { | |
66 | Trie aTrie(new TrieCaseless); | |
67 | ||
68 | if (!aTrie.add ("User-Agent", 10, (void *)1)) { | |
69 | std::cerr << "Could not add User-Agent" << std::endl; | |
70 | return 1; | |
71 | } | |
72 | ||
73 | if (aTrie.add ("user-agent", 10, (void *)2)) { | |
74 | std::cerr << "Could add duplicate User-Agent" << std::endl; | |
75 | return 1; | |
76 | } | |
77 | ||
78 | if (!aTrie.add ("Alphabet", 8, (void *)3)) { | |
79 | std::cerr << "Could not add Alphabet" << std::endl; | |
80 | return 1; | |
81 | } | |
82 | ||
83 | if (!aTrie.add ("uprefix", 8, (void *)3)) { | |
84 | std::cerr << "Could not add uprefix" << std::endl; | |
85 | return 1; | |
86 | } | |
87 | ||
43ae1d95 | 88 | if (aTrie.find ("User-Agent", 10) != (void *)1) { |
89 | std::cerr << "Could not find User-Agent" << std::endl; | |
90 | return 1; | |
91 | } | |
92 | ||
924f73bc | 93 | if (aTrie.find ("user-agent", 10) != (void *)1) { |
94 | std::cerr << "Could not find user-agent" << std::endl; | |
95 | return 1; | |
96 | } | |
97 | ||
98 | if (aTrie.findPrefix("User-AgentFoo" , 13) != (void *)1) { | |
99 | std::cerr << "Could not find User prefix" << std::endl; | |
100 | return 1; | |
101 | } | |
102 | ||
103 | if (aTrie.findPrefix("user-agentFoo" , 13) != (void *)1) { | |
104 | std::cerr << "Could not find user prefix" << std::endl; | |
105 | return 1; | |
106 | } | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
111 | int main (int argc, char **argv) | |
112 | { | |
113 | if (CaseSensitiveCheck()) { | |
114 | std::cerr << "Case sensitive check failure." << std::endl; | |
115 | return 1; | |
116 | } | |
117 | ||
118 | if (CaseInsensitiveCheck()) { | |
119 | std::cerr << "Case in-sensitive check failure." << std::endl; | |
120 | return 1; | |
121 | } | |
122 | ||
43ae1d95 | 123 | return 0; |
124 | } |