Initial packaging for Tizen
[profile/ivi/gobject-introspection.git] / girepository / gthash-test.c
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  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include <glib-object.h>
23 #include "gitypelib-internal.h"
24
25 static void
26 test_build_retrieve (void)
27 {
28   GITypelibHashBuilder *builder;
29   guint32 bufsize;
30   guint8* buf;
31
32   builder = _gi_typelib_hash_builder_new ();
33
34   _gi_typelib_hash_builder_add_string (builder, "Action", 0);
35   _gi_typelib_hash_builder_add_string (builder, "ZLibDecompressor", 42);
36   _gi_typelib_hash_builder_add_string (builder, "VolumeMonitor", 9);
37   _gi_typelib_hash_builder_add_string (builder, "FileMonitorFlags", 31);
38
39   if (!_gi_typelib_hash_builder_prepare (builder))
40     g_assert_not_reached ();
41
42   bufsize = _gi_typelib_hash_builder_get_buffer_size (builder);
43
44   buf = g_malloc (bufsize);
45
46   _gi_typelib_hash_builder_pack (builder, buf, bufsize);
47
48   _gi_typelib_hash_builder_destroy (builder);
49
50   g_assert (_gi_typelib_hash_search (buf, "Action") == 0);
51   g_assert (_gi_typelib_hash_search (buf, "ZLibDecompressor") == 42);
52   g_assert (_gi_typelib_hash_search (buf, "VolumeMonitor") == 9);
53   g_assert (_gi_typelib_hash_search (buf, "FileMonitorFlags") == 31);
54 }
55
56 int
57 main(int argc, char **argv)
58 {
59   g_type_init ();
60   g_test_init (&argc, &argv, NULL);
61
62   g_test_add_func ("/gthash/build-retrieve", test_build_retrieve);
63
64   return g_test_run ();
65 }
66