]> git.ipfire.org Git - thirdparty/squid.git/blame - lib/libTrie/test/trie.cc
Boilerplate: update acinclude/ and configure.ac copyrights
[thirdparty/squid.git] / lib / libTrie / test / trie.cc
CommitLineData
43ae1d95 1/*
924f73bc 2 * Copyright (c) 2002,2003 Robert Collins <rbtcollins@hotmail.com>
43ae1d95 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.
26ac0430 8 *
43ae1d95 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.
26ac0430 13 *
43ae1d95 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
99742866
FC
20#include "squid.h"
21#include "libTrie/Trie.h"
22#include "libTrie/TrieCharTransform.h"
27e059d4 23
43ae1d95 24#include <iostream>
25
924f73bc 26bool
27CaseSensitiveCheck()
43ae1d95 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
924f73bc 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
74bool
75CaseInsensitiveCheck()
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
43ae1d95 99 if (aTrie.find ("User-Agent", 10) != (void *)1) {
100 std::cerr << "Could not find User-Agent" << std::endl;
101 return 1;
102 }
103
924f73bc 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
122int 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
43ae1d95 134 return 0;
135}