1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 * GObject introspection: Test typelib hashing
3 *
4 * Copyright (C) 2010 Red Hat, Inc.
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24 #include <glib-object.h>
25 #include "gitypelib-internal.h"
26
27 static void
28 test_build_retrieve (void)
29 {
30 GITypelibHashBuilder *builder;
31 guint32 bufsize;
32 guint8* buf;
33
34 builder = gi_typelib_hash_builder_new ();
35
36 gi_typelib_hash_builder_add_string (builder, "Action", 0);
37 gi_typelib_hash_builder_add_string (builder, "ZLibDecompressor", 42);
38 gi_typelib_hash_builder_add_string (builder, "VolumeMonitor", 9);
39 gi_typelib_hash_builder_add_string (builder, "FileMonitorFlags", 31);
40
41 if (!gi_typelib_hash_builder_prepare (builder))
42 g_assert_not_reached ();
43
44 bufsize = gi_typelib_hash_builder_get_buffer_size (builder);
45
46 buf = g_malloc (bufsize);
47
48 gi_typelib_hash_builder_pack (builder, buf, bufsize);
49
50 gi_typelib_hash_builder_destroy (builder);
51
52 g_assert (gi_typelib_hash_search (buf, "Action", 4) == 0);
53 g_assert (gi_typelib_hash_search (buf, "ZLibDecompressor", 4) == 42);
54 g_assert (gi_typelib_hash_search (buf, "VolumeMonitor", 4) == 9);
55 g_assert (gi_typelib_hash_search (buf, "FileMonitorFlags", 4) == 31);
56 }
57
58 int
59 main(int argc, char **argv)
60 {
61 g_test_init (&argc, &argv, NULL);
62
63 g_test_add_func ("/gthash/build-retrieve", test_build_retrieve);
64
65 return g_test_run ();
66 }
67