2 * Copyright © 2018 Ebrahim Byagowi
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27 /* Unit tests for hb-map.h */
33 hb_map_t *empty = hb_map_get_empty ();
35 g_assert (hb_map_is_empty (empty));
36 g_assert (!hb_map_allocation_successful (empty));
37 hb_map_destroy (empty);
40 g_assert (hb_map_allocation_successful (m));
41 g_assert (hb_map_is_empty (m));
43 hb_map_set (m, 213, 223);
44 hb_map_set (m, 643, 675);
45 g_assert_cmpint (hb_map_get_population (m), ==, 2);
47 g_assert_cmpint (hb_map_get (m, 213), ==, 223);
48 g_assert (!hb_map_has (m, 123));
49 g_assert (hb_map_has (m, 213));
52 g_assert (!hb_map_has (m, 213));
54 g_assert_cmpint (hb_map_get (m, 643), ==, 675);
55 hb_map_set (m, 237, 673);
56 g_assert (hb_map_has (m, 237));
58 g_assert (!hb_map_has (m, 237));
59 g_assert (!hb_map_has (m, 643));
60 g_assert_cmpint (hb_map_get_population (m), ==, 0);
66 test_map_userdata (void)
68 hb_map_t *m = hb_map_create ();
70 hb_user_data_key_t key[2];
71 int *data = (int *) malloc (sizeof (int));
74 hb_map_set_user_data (m, &key[0], data, free, TRUE);
75 g_assert_cmpint (*((int *) hb_map_get_user_data (m, &key[0])), ==, 3123);
77 data2 = (int *) malloc (sizeof (int));
79 hb_map_set_user_data (m, &key[0], data2, free, FALSE);
80 g_assert_cmpint (*((int *) hb_map_get_user_data (m, &key[0])), ==, 3123);
81 hb_map_set_user_data (m, &key[0], data2, free, TRUE);
82 g_assert_cmpint (*((int *) hb_map_get_user_data (m, &key[0])), ==, 6343);
88 test_map_refcount (void)
90 hb_map_t *m = hb_map_create ();
92 hb_map_set (m, 213, 223);
93 g_assert_cmpint (hb_map_get (m, 213), ==, 223);
95 m2 = hb_map_reference (m);
98 /* We copied its reference so it is still usable after one destroy */
99 g_assert (hb_map_has (m, 213));
100 g_assert (hb_map_has (m2, 213));
104 /* Now you can't access them anymore */
108 main (int argc, char **argv)
110 hb_test_init (&argc, &argv);
112 hb_test_add (test_map_basic);
113 hb_test_add (test_map_userdata);
114 hb_test_add (test_map_refcount);
116 return hb_test_run();