]>
git.ipfire.org Git - thirdparty/squid.git/blob - lib/libTrie/test/trie.cc
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "libTrie/Trie.h"
11 #include "libTrie/TrieCharTransform.h"
20 if (!aTrie
.add ("User-Agent", 10, (void *)1)) {
21 std::cerr
<< "Could not add User-Agent" << std::endl
;
25 if (aTrie
.add ("User-Agent", 10, (void *)2)) {
26 std::cerr
<< "Could add duplicate User-Agent" << std::endl
;
30 if (!aTrie
.add ("Alphabet", 8, (void *)3)) {
31 std::cerr
<< "Could not add Alphabet" << std::endl
;
35 if (!aTrie
.add ("Uprefix", 8, (void *)3)) {
36 std::cerr
<< "Could not add Uprefix" << std::endl
;
40 if (aTrie
.find ("User-Agent", 10) != (void *)1) {
41 std::cerr
<< "Could not find User-Agent" << std::endl
;
45 if (aTrie
.find ("user-agent", 10) == (void *)1) {
46 std::cerr
<< "found user-agent" << std::endl
;
50 if (aTrie
.findPrefix("User-AgentFoo" , 13) != (void *)1) {
51 std::cerr
<< "Could not find User prefix" << std::endl
;
55 if (aTrie
.findPrefix("user-agentFoo" , 13) == (void *)1) {
56 std::cerr
<< "found user prefix" << std::endl
;
64 CaseInsensitiveCheck()
66 Trie
aTrie(new TrieCaseless
);
68 if (!aTrie
.add ("User-Agent", 10, (void *)1)) {
69 std::cerr
<< "Could not add User-Agent" << std::endl
;
73 if (aTrie
.add ("user-agent", 10, (void *)2)) {
74 std::cerr
<< "Could add duplicate User-Agent" << std::endl
;
78 if (!aTrie
.add ("Alphabet", 8, (void *)3)) {
79 std::cerr
<< "Could not add Alphabet" << std::endl
;
83 if (!aTrie
.add ("uprefix", 8, (void *)3)) {
84 std::cerr
<< "Could not add uprefix" << std::endl
;
88 if (aTrie
.find ("User-Agent", 10) != (void *)1) {
89 std::cerr
<< "Could not find User-Agent" << std::endl
;
93 if (aTrie
.find ("user-agent", 10) != (void *)1) {
94 std::cerr
<< "Could not find user-agent" << std::endl
;
98 if (aTrie
.findPrefix("User-AgentFoo" , 13) != (void *)1) {
99 std::cerr
<< "Could not find User prefix" << std::endl
;
103 if (aTrie
.findPrefix("user-agentFoo" , 13) != (void *)1) {
104 std::cerr
<< "Could not find user prefix" << std::endl
;
111 int main (int argc
, char **argv
)
113 if (CaseSensitiveCheck()) {
114 std::cerr
<< "Case sensitive check failure." << std::endl
;
118 if (CaseInsensitiveCheck()) {
119 std::cerr
<< "Case in-sensitive check failure." << std::endl
;