1 /* GObject introspection: Test cmph hashing
3 * Copyright (C) 2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <glib-object.h>
27 cmph_config_t *config;
28 cmph_io_adapter_t *io;
33 strings = g_strsplit ("foo,bar,baz", ",", -1);
35 io = cmph_io_vector_adapter (strings, g_strv_length (strings));
36 config = cmph_config_new (io);
37 cmph_config_set_algo (config, CMPH_BDZ);
39 c = cmph_new (config);
41 g_assert (size == g_strv_length (strings));
47 assert_hashes_unique (guint n_hashes,
52 for (i = 0; i < n_hashes; i++)
55 for (j = 0; j < n_hashes; j++)
58 g_assert (hashes[i] != hashes[j]);
75 hash = cmph_search (c, "foo", 3);
76 g_assert (hash >= 0 && hash < size);
79 hash = cmph_search (c, "bar", 3);
80 g_assert (hash >= 0 && hash < size);
83 hash = cmph_search (c, "baz", 3);
84 g_assert (hash >= 0 && hash < size);
87 assert_hashes_unique (G_N_ELEMENTS (hashes), &hashes[0]);
91 test_search_packed (void)
101 bufsize = cmph_packed_size (c);
102 buf = g_malloc (bufsize);
105 size = cmph_size (c);
111 hash = cmph_search_packed (buf, "foo", 3);
112 g_assert (hash >= 0 && hash < size);
115 hash = cmph_search_packed (buf, "bar", 3);
116 g_assert (hash >= 0 && hash < size);
119 hash = cmph_search_packed (buf, "baz", 3);
120 g_assert (hash >= 0 && hash < size);
123 assert_hashes_unique (G_N_ELEMENTS (hashes), &hashes[0]);
127 main(int argc, char **argv)
132 g_test_init (&argc, &argv, NULL);
134 g_test_add_func ("/cmph-bdz/search", test_search);
135 g_test_add_func ("/cmph-bdz/search-packed", test_search_packed);