Debian Codegraph @

glib/girepository/tests/gthash.c

raw
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 <stdint.h>
25 #include <glib-object.h>
26 #include "gitypelib-internal.h"
27
28 static void
29 test_build_retrieve (void)
30 {
31 GITypelibHashBuilder *builder;
32 uint32_t bufsize;
33 uint8_t* buf;
34
35 builder = gi_typelib_hash_builder_new ();
36
37 gi_typelib_hash_builder_add_string (builder, "Action", 0);
38 gi_typelib_hash_builder_add_string (builder, "ZLibDecompressor", 42);
39 gi_typelib_hash_builder_add_string (builder, "VolumeMonitor", 9);
40 gi_typelib_hash_builder_add_string (builder, "FileMonitorFlags", 31);
41
42 g_assert_true (gi_typelib_hash_builder_prepare (builder));
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_cmpuint (gi_typelib_hash_search (buf, "Action", 4), ==, 0);
53 g_assert_cmpuint (gi_typelib_hash_search (buf, "ZLibDecompressor", 4), ==, 42);
54 g_assert_cmpuint (gi_typelib_hash_search (buf, "VolumeMonitor", 4), ==, 9);
55 g_assert_cmpuint (gi_typelib_hash_search (buf, "FileMonitorFlags", 4), ==, 31);
56
57 g_free (buf);
58 }
59
60 int
61 main(int argc, char **argv)
62 {
63 g_test_init (&argc, &argv, NULL);
64
65 g_test_add_func ("/gthash/build-retrieve", test_build_retrieve);
66
67 return g_test_run ();
68 }
69