]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/libTrie/test/trie.cc
Merged from trunk
[thirdparty/squid.git] / lib / libTrie / test / trie.cc
1 /*
2 * Copyright (c) 2002,2003 Robert Collins <rbtcollins@hotmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
17 *
18 */
19
20 #include "squid.h"
21 #include "libTrie/Trie.h"
22 #include "libTrie/TrieCharTransform.h"
23
24 #if HAVE_IOSTREAM
25 #include <iostream>
26 #endif
27
28 bool
29 CaseSensitiveCheck()
30 {
31 Trie aTrie;
32
33 if (!aTrie.add ("User-Agent", 10, (void *)1)) {
34 std::cerr << "Could not add User-Agent" << std::endl;
35 return 1;
36 }
37
38 if (aTrie.add ("User-Agent", 10, (void *)2)) {
39 std::cerr << "Could add duplicate User-Agent" << std::endl;
40 return 1;
41 }
42
43 if (!aTrie.add ("Alphabet", 8, (void *)3)) {
44 std::cerr << "Could not add Alphabet" << std::endl;
45 return 1;
46 }
47
48 if (!aTrie.add ("Uprefix", 8, (void *)3)) {
49 std::cerr << "Could not add Uprefix" << std::endl;
50 return 1;
51 }
52
53 if (aTrie.find ("User-Agent", 10) != (void *)1) {
54 std::cerr << "Could not find User-Agent" << std::endl;
55 return 1;
56 }
57
58 if (aTrie.find ("user-agent", 10) == (void *)1) {
59 std::cerr << "found user-agent" << std::endl;
60 return 1;
61 }
62
63 if (aTrie.findPrefix("User-AgentFoo" , 13) != (void *)1) {
64 std::cerr << "Could not find User prefix" << std::endl;
65 return 1;
66 }
67
68 if (aTrie.findPrefix("user-agentFoo" , 13) == (void *)1) {
69 std::cerr << "found user prefix" << std::endl;
70 return 1;
71 }
72
73 return 0;
74 }
75
76 bool
77 CaseInsensitiveCheck()
78 {
79 Trie aTrie(new TrieCaseless);
80
81 if (!aTrie.add ("User-Agent", 10, (void *)1)) {
82 std::cerr << "Could not add User-Agent" << std::endl;
83 return 1;
84 }
85
86 if (aTrie.add ("user-agent", 10, (void *)2)) {
87 std::cerr << "Could add duplicate User-Agent" << std::endl;
88 return 1;
89 }
90
91 if (!aTrie.add ("Alphabet", 8, (void *)3)) {
92 std::cerr << "Could not add Alphabet" << std::endl;
93 return 1;
94 }
95
96 if (!aTrie.add ("uprefix", 8, (void *)3)) {
97 std::cerr << "Could not add uprefix" << std::endl;
98 return 1;
99 }
100
101 if (aTrie.find ("User-Agent", 10) != (void *)1) {
102 std::cerr << "Could not find User-Agent" << std::endl;
103 return 1;
104 }
105
106 if (aTrie.find ("user-agent", 10) != (void *)1) {
107 std::cerr << "Could not find user-agent" << std::endl;
108 return 1;
109 }
110
111 if (aTrie.findPrefix("User-AgentFoo" , 13) != (void *)1) {
112 std::cerr << "Could not find User prefix" << std::endl;
113 return 1;
114 }
115
116 if (aTrie.findPrefix("user-agentFoo" , 13) != (void *)1) {
117 std::cerr << "Could not find user prefix" << std::endl;
118 return 1;
119 }
120
121 return 0;
122 }
123
124 int main (int argc, char **argv)
125 {
126 if (CaseSensitiveCheck()) {
127 std::cerr << "Case sensitive check failure." << std::endl;
128 return 1;
129 }
130
131 if (CaseInsensitiveCheck()) {
132 std::cerr << "Case in-sensitive check failure." << std::endl;
133 return 1;
134 }
135
136 return 0;
137 }