]>
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"
31 if (!aTrie
.add ("User-Agent", 10, (void *)1)) {
32 std::cerr
<< "Could not add User-Agent" << std::endl
;
36 if (aTrie
.add ("User-Agent", 10, (void *)2)) {
37 std::cerr
<< "Could add duplicate User-Agent" << std::endl
;
41 if (!aTrie
.add ("Alphabet", 8, (void *)3)) {
42 std::cerr
<< "Could not add Alphabet" << std::endl
;
46 if (!aTrie
.add ("Uprefix", 8, (void *)3)) {
47 std::cerr
<< "Could not add Uprefix" << std::endl
;
51 if (aTrie
.find ("User-Agent", 10) != (void *)1) {
52 std::cerr
<< "Could not find User-Agent" << std::endl
;
56 if (aTrie
.find ("user-agent", 10) == (void *)1) {
57 std::cerr
<< "found user-agent" << std::endl
;
61 if (aTrie
.findPrefix("User-AgentFoo" , 13) != (void *)1) {
62 std::cerr
<< "Could not find User prefix" << std::endl
;
66 if (aTrie
.findPrefix("user-agentFoo" , 13) == (void *)1) {
67 std::cerr
<< "found user prefix" << std::endl
;
75 CaseInsensitiveCheck()
77 Trie
aTrie(new TrieCaseless
);
79 if (!aTrie
.add ("User-Agent", 10, (void *)1)) {
80 std::cerr
<< "Could not add User-Agent" << std::endl
;
84 if (aTrie
.add ("user-agent", 10, (void *)2)) {
85 std::cerr
<< "Could add duplicate User-Agent" << std::endl
;
89 if (!aTrie
.add ("Alphabet", 8, (void *)3)) {
90 std::cerr
<< "Could not add Alphabet" << std::endl
;
94 if (!aTrie
.add ("uprefix", 8, (void *)3)) {
95 std::cerr
<< "Could not add uprefix" << std::endl
;
99 if (aTrie
.find ("User-Agent", 10) != (void *)1) {
100 std::cerr
<< "Could not find User-Agent" << std::endl
;
104 if (aTrie
.find ("user-agent", 10) != (void *)1) {
105 std::cerr
<< "Could not find user-agent" << std::endl
;
109 if (aTrie
.findPrefix("User-AgentFoo" , 13) != (void *)1) {
110 std::cerr
<< "Could not find User prefix" << std::endl
;
114 if (aTrie
.findPrefix("user-agentFoo" , 13) != (void *)1) {
115 std::cerr
<< "Could not find user prefix" << std::endl
;
122 int main (int argc
, char **argv
)
124 if (CaseSensitiveCheck()) {
125 std::cerr
<< "Case sensitive check failure." << std::endl
;
129 if (CaseInsensitiveCheck()) {
130 std::cerr
<< "Case in-sensitive check failure." << std::endl
;