Sat, 05 Apr 2014 11:21:35 +0200
Fix style warnings
|
35771
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
1 | /* |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
2 | * Purple |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
3 | * |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
5 | * numerous to list here. Please refer to the COPYRIGHT file distributed |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
6 | * with this source distribution |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
7 | * |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or (at |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
11 | * your option) any later version. |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
12 | * |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, but |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
16 | * General Public License for more details. |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
17 | * |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
21 | */ |
|
d9f3612faf8d
Fix style warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35756
diff
changeset
|
22 | |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
23 | #include <string.h> |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
24 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
25 | #include "tests.h" |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
26 | #include "../trie.h" |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
27 | |
|
35756
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
28 | static gint find_sum; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
29 | |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
30 | static gboolean |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
31 | test_trie_replace_cb(GString *out, const gchar *word, gpointer word_data, |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
32 | gpointer user_data) |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
33 | { |
|
35665
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
34 | /* the "test" word for the test_trie_replace test */ |
|
35697
4ac2ddeee1ca
Fix two more warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
35 | if ((gintptr)word_data == 0x1001) |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
36 | return FALSE; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
37 | |
|
35697
4ac2ddeee1ca
Fix two more warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
38 | g_string_append_printf(out, "[%d:%x]", |
|
4ac2ddeee1ca
Fix two more warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
39 | (int)(gintptr)user_data, (int)(gintptr)word_data); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
40 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
41 | return TRUE; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
42 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
43 | |
|
35756
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
44 | static gboolean |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
45 | test_trie_find_cb(const gchar *word, gpointer word_data, |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
46 | gpointer user_data) |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
47 | { |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
48 | if ((gintptr)word_data == 0x7004) |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
49 | return FALSE; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
50 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
51 | find_sum += (gintptr)word_data; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
52 | find_sum -= (gintptr)user_data * 0x1000; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
53 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
54 | return TRUE; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
55 | } |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
56 | |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
57 | START_TEST(test_trie_replace) |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
58 | { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
59 | PurpleTrie *trie; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
60 | const gchar *in; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
61 | gchar *out; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
62 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
63 | trie = purple_trie_new(); |
|
35729
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
64 | purple_trie_set_reset_on_match(trie, FALSE); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
65 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
66 | purple_trie_add(trie, "test", (gpointer)0x1001); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
67 | purple_trie_add(trie, "testing", (gpointer)0x1002); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
68 | purple_trie_add(trie, "overtested", (gpointer)0x1003); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
69 | purple_trie_add(trie, "trie", (gpointer)0x1004); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
70 | purple_trie_add(trie, "tree", (gpointer)0x1005); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
71 | purple_trie_add(trie, "implement", (gpointer)0x1006); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
72 | purple_trie_add(trie, "implementation", (gpointer)0x1007); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
73 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
74 | in = "Alice is testing her trie implementation, " |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
75 | "but she's far away from making test tree overtested"; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
76 | |
|
35665
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
77 | out = purple_trie_replace(trie, in, test_trie_replace_cb, (gpointer)1); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
78 | |
|
35665
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
79 | assert_string_equal("Alice is [1:1002] her [1:1004] [1:1006]ation," |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
80 | " but she's far away from making test [1:1005] [1:1003]", out); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
81 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
82 | g_object_unref(trie); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
83 | g_free(out); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
84 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
85 | END_TEST |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
86 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
87 | START_TEST(test_trie_replace_whole) |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
88 | { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
89 | PurpleTrie *trie; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
90 | const gchar *in; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
91 | gchar *out; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
92 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
93 | trie = purple_trie_new(); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
94 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
95 | purple_trie_add(trie, "test", (gpointer)0x2002); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
96 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
97 | in = "test"; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
98 | |
|
35665
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
99 | out = purple_trie_replace(trie, in, test_trie_replace_cb, (gpointer)2); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
100 | |
|
35665
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
101 | assert_string_equal("[2:2002]", out); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
102 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
103 | g_object_unref(trie); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
104 | g_free(out); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
105 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
106 | END_TEST |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
107 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
108 | START_TEST(test_trie_replace_inner) |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
109 | { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
110 | PurpleTrie *trie; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
111 | const gchar *in; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
112 | gchar *out; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
113 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
114 | trie = purple_trie_new(); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
115 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
116 | purple_trie_add(trie, "est", (gpointer)0x3001); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
117 | purple_trie_add(trie, "tester", (gpointer)0x3002); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
118 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
119 | in = "the test!"; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
120 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
121 | out = purple_trie_replace(trie, in, test_trie_replace_cb, (gpointer)3); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
122 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
123 | assert_string_equal("the t[3:3001]!", out); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
124 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
125 | g_object_unref(trie); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
126 | g_free(out); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
127 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
128 | END_TEST |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
129 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
130 | START_TEST(test_trie_replace_empty) |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
131 | { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
132 | PurpleTrie *trie; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
133 | const gchar *in; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
134 | gchar *out; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
135 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
136 | trie = purple_trie_new(); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
137 | |
|
35664
4a2cf3314f4b
The empty word case was a bad idea
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35663
diff
changeset
|
138 | purple_trie_add(trie, "test", (gpointer)0x4001); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
139 | |
|
35664
4a2cf3314f4b
The empty word case was a bad idea
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35663
diff
changeset
|
140 | in = ""; |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
141 | |
|
35665
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
142 | out = purple_trie_replace(trie, in, test_trie_replace_cb, (gpointer)4); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
143 | |
|
35664
4a2cf3314f4b
The empty word case was a bad idea
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35663
diff
changeset
|
144 | assert_string_equal("", out); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
145 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
146 | g_object_unref(trie); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
147 | g_free(out); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
148 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
149 | END_TEST |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
150 | |
|
35665
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
151 | START_TEST(test_trie_multi_replace) |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
152 | { |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
153 | PurpleTrie *trie1, *trie2, *trie3; |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
154 | GSList *tries = NULL; |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
155 | const gchar *in; |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
156 | gchar *out; |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
157 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
158 | trie1 = purple_trie_new(); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
159 | trie2 = purple_trie_new(); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
160 | trie3 = purple_trie_new(); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
161 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
162 | /* appending is not efficient, but we have only 3 elements */ |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
163 | tries = g_slist_append(tries, trie1); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
164 | tries = g_slist_append(tries, trie2); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
165 | tries = g_slist_append(tries, trie3); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
166 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
167 | purple_trie_add(trie1, "test", (gpointer)0x5011); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
168 | purple_trie_add(trie1, "trie1", (gpointer)0x5012); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
169 | purple_trie_add(trie1, "Alice", (gpointer)0x5013); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
170 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
171 | purple_trie_add(trie2, "test", (gpointer)0x5021); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
172 | purple_trie_add(trie2, "trie2", (gpointer)0x5022); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
173 | purple_trie_add(trie2, "example", (gpointer)0x5023); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
174 | purple_trie_add(trie2, "Ali", (gpointer)0x5024); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
175 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
176 | /* "tester" without last (accepting) letter of "test" */ |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
177 | purple_trie_add(trie3, "teser", (gpointer)0x5031); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
178 | purple_trie_add(trie3, "trie3", (gpointer)0x5032); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
179 | purple_trie_add(trie3, "tester", (gpointer)0x5033); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
180 | purple_trie_add(trie3, "example", (gpointer)0x5034); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
181 | purple_trie_add(trie3, "Al", (gpointer)0x5035); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
182 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
183 | in = "test tester trie trie1 trie2 trie3 example Alice"; |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
184 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
185 | out = purple_trie_multi_replace(tries, in, |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
186 | test_trie_replace_cb, (gpointer)5); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
187 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
188 | assert_string_equal("[5:5011] [5:5011]er trie [5:5012] [5:5022] " |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
189 | "[5:5032] [5:5023] [5:5035]ice", out); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
190 | |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
191 | g_slist_free_full(tries, g_object_unref); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
192 | g_free(out); |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
193 | } |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
194 | END_TEST |
|
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
195 | |
|
35729
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
196 | START_TEST(test_trie_remove) |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
197 | { |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
198 | PurpleTrie *trie; |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
199 | const gchar *in; |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
200 | gchar *out; |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
201 | |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
202 | trie = purple_trie_new(); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
203 | |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
204 | purple_trie_add(trie, "alice", (gpointer)0x6001); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
205 | purple_trie_add(trie, "bob", (gpointer)0x6002); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
206 | purple_trie_add(trie, "cherry", (gpointer)0x6003); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
207 | |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
208 | purple_trie_remove(trie, "bob"); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
209 | |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
210 | in = "alice bob cherry"; |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
211 | |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
212 | out = purple_trie_replace(trie, in, test_trie_replace_cb, (gpointer)6); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
213 | |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
214 | assert_string_equal("[6:6001] bob [6:6003]", out); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
215 | |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
216 | g_object_unref(trie); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
217 | g_free(out); |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
218 | } |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
219 | END_TEST |
|
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
220 | |
|
35756
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
221 | START_TEST(test_trie_find) |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
222 | { |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
223 | PurpleTrie *trie; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
224 | const gchar *in; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
225 | gint out; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
226 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
227 | trie = purple_trie_new(); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
228 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
229 | purple_trie_add(trie, "alice", (gpointer)0x7001); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
230 | purple_trie_add(trie, "bob", (gpointer)0x7002); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
231 | purple_trie_add(trie, "cherry", (gpointer)0x7003); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
232 | purple_trie_add(trie, "al", (gpointer)0x7004); /* not accepted */ |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
233 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
234 | in = "test alice bob test cherry alice"; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
235 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
236 | find_sum = 0; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
237 | out = purple_trie_find(trie, in, test_trie_find_cb, (gpointer)7); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
238 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
239 | assert_int_equal(4, out); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
240 | assert_int_equal(2*1 + 2 + 3, find_sum); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
241 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
242 | g_object_unref(trie); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
243 | } |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
244 | END_TEST |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
245 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
246 | START_TEST(test_trie_find_reset) |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
247 | { |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
248 | PurpleTrie *trie; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
249 | const gchar *in; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
250 | gint out; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
251 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
252 | trie = purple_trie_new(); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
253 | purple_trie_set_reset_on_match(trie, TRUE); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
254 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
255 | purple_trie_add(trie, "alice", (gpointer)0x8001); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
256 | purple_trie_add(trie, "ali", (gpointer)0x8002); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
257 | purple_trie_add(trie, "al", (gpointer)0x8003); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
258 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
259 | in = "al ali alice"; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
260 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
261 | find_sum = 0; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
262 | out = purple_trie_find(trie, in, test_trie_find_cb, (gpointer)8); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
263 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
264 | assert_int_equal(3, out); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
265 | assert_int_equal(3 * 3, find_sum); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
266 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
267 | g_object_unref(trie); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
268 | } |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
269 | END_TEST |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
270 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
271 | START_TEST(test_trie_find_noreset) |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
272 | { |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
273 | PurpleTrie *trie; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
274 | const gchar *in; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
275 | gint out; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
276 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
277 | trie = purple_trie_new(); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
278 | purple_trie_set_reset_on_match(trie, FALSE); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
279 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
280 | purple_trie_add(trie, "alice", (gpointer)0x9001); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
281 | purple_trie_add(trie, "ali", (gpointer)0x9002); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
282 | purple_trie_add(trie, "al", (gpointer)0x9003); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
283 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
284 | in = "al ali alice"; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
285 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
286 | find_sum = 0; |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
287 | out = purple_trie_find(trie, in, test_trie_find_cb, (gpointer)9); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
288 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
289 | assert_int_equal(6, out); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
290 | assert_int_equal(3*3 + 2*2 + 1, find_sum); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
291 | |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
292 | g_object_unref(trie); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
293 | } |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
294 | END_TEST |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
295 | |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
296 | Suite * |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
297 | purple_trie_suite(void) |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
298 | { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
299 | Suite *s = suite_create("PurpleTrie class"); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
300 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
301 | TCase *tc = tcase_create("trie"); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
302 | tcase_add_test(tc, test_trie_replace); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
303 | tcase_add_test(tc, test_trie_replace_whole); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
304 | tcase_add_test(tc, test_trie_replace_inner); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
305 | tcase_add_test(tc, test_trie_replace_empty); |
|
35665
f1310093e434
Implement and test multi-trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35664
diff
changeset
|
306 | tcase_add_test(tc, test_trie_multi_replace); |
|
35729
27c5683767c8
MemoryPool: fix invalid read, Trie: test tweaks
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35665
diff
changeset
|
307 | tcase_add_test(tc, test_trie_remove); |
|
35756
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
308 | tcase_add_test(tc, test_trie_find); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
309 | tcase_add_test(tc, test_trie_find_reset); |
|
fe6aba70046e
Custom smileys: make it possible to find them by prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35733
diff
changeset
|
310 | tcase_add_test(tc, test_trie_find_noreset); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
311 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
312 | suite_add_tcase(s, tc); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
313 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
314 | return s; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
315 | } |