]>
git.ipfire.org Git - thirdparty/squid.git/blob - lib/libTrie/test/trie.cc
2 * Copyright (c) 2002,2003 Robert Collins <rbtcollins@hotmail.com>
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.
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.
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.
21 #include "libTrie/Trie.h"
22 #include "libTrie/TrieCharTransform.h"
33 if (!aTrie
.add ("User-Agent", 10, (void *)1)) {
34 std::cerr
<< "Could not add User-Agent" << std::endl
;
38 if (aTrie
.add ("User-Agent", 10, (void *)2)) {
39 std::cerr
<< "Could add duplicate User-Agent" << std::endl
;
43 if (!aTrie
.add ("Alphabet", 8, (void *)3)) {
44 std::cerr
<< "Could not add Alphabet" << std::endl
;
48 if (!aTrie
.add ("Uprefix", 8, (void *)3)) {
49 std::cerr
<< "Could not add Uprefix" << std::endl
;
53 if (aTrie
.find ("User-Agent", 10) != (void *)1) {
54 std::cerr
<< "Could not find User-Agent" << std::endl
;
58 if (aTrie
.find ("user-agent", 10) == (void *)1) {
59 std::cerr
<< "found user-agent" << std::endl
;
63 if (aTrie
.findPrefix("User-AgentFoo" , 13) != (void *)1) {
64 std::cerr
<< "Could not find User prefix" << std::endl
;
68 if (aTrie
.findPrefix("user-agentFoo" , 13) == (void *)1) {
69 std::cerr
<< "found user prefix" << std::endl
;
77 CaseInsensitiveCheck()
79 Trie
aTrie(new TrieCaseless
);
81 if (!aTrie
.add ("User-Agent", 10, (void *)1)) {
82 std::cerr
<< "Could not add User-Agent" << std::endl
;
86 if (aTrie
.add ("user-agent", 10, (void *)2)) {
87 std::cerr
<< "Could add duplicate User-Agent" << std::endl
;
91 if (!aTrie
.add ("Alphabet", 8, (void *)3)) {
92 std::cerr
<< "Could not add Alphabet" << std::endl
;
96 if (!aTrie
.add ("uprefix", 8, (void *)3)) {
97 std::cerr
<< "Could not add uprefix" << std::endl
;
101 if (aTrie
.find ("User-Agent", 10) != (void *)1) {
102 std::cerr
<< "Could not find User-Agent" << std::endl
;
106 if (aTrie
.find ("user-agent", 10) != (void *)1) {
107 std::cerr
<< "Could not find user-agent" << std::endl
;
111 if (aTrie
.findPrefix("User-AgentFoo" , 13) != (void *)1) {
112 std::cerr
<< "Could not find User prefix" << std::endl
;
116 if (aTrie
.findPrefix("user-agentFoo" , 13) != (void *)1) {
117 std::cerr
<< "Could not find user prefix" << std::endl
;
124 int main (int argc
, char **argv
)
126 if (CaseSensitiveCheck()) {
127 std::cerr
<< "Case sensitive check failure." << std::endl
;
131 if (CaseInsensitiveCheck()) {
132 std::cerr
<< "Case in-sensitive check failure." << std::endl
;