]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/libTrie/test/trie.cc
Cleanup: un-wrap C++ header includes
[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 #include <iostream>
25
26 bool
27 CaseSensitiveCheck()
28 {
29 Trie aTrie;
30
31 if (!aTrie.add ("User-Agent", 10, (void *)1)) {
32 std::cerr << "Could not add User-Agent" << std::endl;
33 return 1;
34 }
35
36 if (aTrie.add ("User-Agent", 10, (void *)2)) {
37 std::cerr << "Could add duplicate User-Agent" << std::endl;
38 return 1;
39 }
40
41 if (!aTrie.add ("Alphabet", 8, (void *)3)) {
42 std::cerr << "Could not add Alphabet" << std::endl;
43 return 1;
44 }
45
46 if (!aTrie.add ("Uprefix", 8, (void *)3)) {
47 std::cerr << "Could not add Uprefix" << std::endl;
48 return 1;
49 }
50
51 if (aTrie.find ("User-Agent", 10) != (void *)1) {
52 std::cerr << "Could not find User-Agent" << std::endl;
53 return 1;
54 }
55
56 if (aTrie.find ("user-agent", 10) == (void *)1) {
57 std::cerr << "found user-agent" << std::endl;
58 return 1;
59 }
60
61 if (aTrie.findPrefix("User-AgentFoo" , 13) != (void *)1) {
62 std::cerr << "Could not find User prefix" << std::endl;
63 return 1;
64 }
65
66 if (aTrie.findPrefix("user-agentFoo" , 13) == (void *)1) {
67 std::cerr << "found user prefix" << std::endl;
68 return 1;
69 }
70
71 return 0;
72 }
73
74 bool
75 CaseInsensitiveCheck()
76 {
77 Trie aTrie(new TrieCaseless);
78
79 if (!aTrie.add ("User-Agent", 10, (void *)1)) {
80 std::cerr << "Could not add User-Agent" << std::endl;
81 return 1;
82 }
83
84 if (aTrie.add ("user-agent", 10, (void *)2)) {
85 std::cerr << "Could add duplicate User-Agent" << std::endl;
86 return 1;
87 }
88
89 if (!aTrie.add ("Alphabet", 8, (void *)3)) {
90 std::cerr << "Could not add Alphabet" << std::endl;
91 return 1;
92 }
93
94 if (!aTrie.add ("uprefix", 8, (void *)3)) {
95 std::cerr << "Could not add uprefix" << std::endl;
96 return 1;
97 }
98
99 if (aTrie.find ("User-Agent", 10) != (void *)1) {
100 std::cerr << "Could not find User-Agent" << std::endl;
101 return 1;
102 }
103
104 if (aTrie.find ("user-agent", 10) != (void *)1) {
105 std::cerr << "Could not find user-agent" << std::endl;
106 return 1;
107 }
108
109 if (aTrie.findPrefix("User-AgentFoo" , 13) != (void *)1) {
110 std::cerr << "Could not find User prefix" << std::endl;
111 return 1;
112 }
113
114 if (aTrie.findPrefix("user-agentFoo" , 13) != (void *)1) {
115 std::cerr << "Could not find user prefix" << std::endl;
116 return 1;
117 }
118
119 return 0;
120 }
121
122 int main (int argc, char **argv)
123 {
124 if (CaseSensitiveCheck()) {
125 std::cerr << "Case sensitive check failure." << std::endl;
126 return 1;
127 }
128
129 if (CaseInsensitiveCheck()) {
130 std::cerr << "Case in-sensitive check failure." << std::endl;
131 return 1;
132 }
133
134 return 0;
135 }