summaryrefslogtreecommitdiff
path: root/tests/testhashmap.c
blob: 9f826edf598152596116f0589e4c570c766da351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* testhashmap.c generated by valac 0.18.0, the Vala compiler
 * generated from testhashmap.vala, do not modify */

/* testhashmap.vala
 *
 * Copyright (C) 2008  Jürg Billeter
 * Copyright (C) 2009  Didier Villevalois, Julien Peeters
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Julien Peeters <contact@julienpeeters.fr>
 */

#include <glib.h>
#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>


#define GEE_TYPE_TEST_CASE (gee_test_case_get_type ())
#define GEE_TEST_CASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEE_TYPE_TEST_CASE, GeeTestCase))
#define GEE_TEST_CASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEE_TYPE_TEST_CASE, GeeTestCaseClass))
#define GEE_IS_TEST_CASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEE_TYPE_TEST_CASE))
#define GEE_IS_TEST_CASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEE_TYPE_TEST_CASE))
#define GEE_TEST_CASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEE_TYPE_TEST_CASE, GeeTestCaseClass))

typedef struct _GeeTestCase GeeTestCase;
typedef struct _GeeTestCaseClass GeeTestCaseClass;
typedef struct _GeeTestCasePrivate GeeTestCasePrivate;

#define TYPE_MAP_TESTS (map_tests_get_type ())
#define MAP_TESTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAP_TESTS, MapTests))
#define MAP_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAP_TESTS, MapTestsClass))
#define IS_MAP_TESTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAP_TESTS))
#define IS_MAP_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAP_TESTS))
#define MAP_TESTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAP_TESTS, MapTestsClass))

typedef struct _MapTests MapTests;
typedef struct _MapTestsClass MapTestsClass;
typedef struct _MapTestsPrivate MapTestsPrivate;

#define TYPE_HASH_MAP_TESTS (hash_map_tests_get_type ())
#define HASH_MAP_TESTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_HASH_MAP_TESTS, HashMapTests))
#define HASH_MAP_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_HASH_MAP_TESTS, HashMapTestsClass))
#define IS_HASH_MAP_TESTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_HASH_MAP_TESTS))
#define IS_HASH_MAP_TESTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_HASH_MAP_TESTS))
#define HASH_MAP_TESTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_HASH_MAP_TESTS, HashMapTestsClass))

typedef struct _HashMapTests HashMapTests;
typedef struct _HashMapTestsClass HashMapTestsClass;
typedef struct _HashMapTestsPrivate HashMapTestsPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GeeTestCase {
	GObject parent_instance;
	GeeTestCasePrivate * priv;
};

struct _GeeTestCaseClass {
	GObjectClass parent_class;
	void (*set_up) (GeeTestCase* self);
	void (*tear_down) (GeeTestCase* self);
};

struct _MapTests {
	GeeTestCase parent_instance;
	MapTestsPrivate * priv;
	GeeMap* test_map;
};

struct _MapTestsClass {
	GeeTestCaseClass parent_class;
};

struct _HashMapTests {
	MapTests parent_instance;
	HashMapTestsPrivate * priv;
};

struct _HashMapTestsClass {
	MapTestsClass parent_class;
};

typedef void (*GeeTestCaseTestMethod) (void* user_data);

static gpointer hash_map_tests_parent_class = NULL;

GType gee_test_case_get_type (void) G_GNUC_CONST;
GType map_tests_get_type (void) G_GNUC_CONST;
GType hash_map_tests_get_type (void) G_GNUC_CONST;
enum  {
	HASH_MAP_TESTS_DUMMY_PROPERTY
};
HashMapTests* hash_map_tests_new (void);
HashMapTests* hash_map_tests_construct (GType object_type);
MapTests* map_tests_construct (GType object_type, const gchar* name);
void gee_test_case_add_test (GeeTestCase* self, const gchar* name, GeeTestCaseTestMethod test, void* test_target);
void hash_map_tests_test_selected_functions (HashMapTests* self);
static void _hash_map_tests_test_selected_functions_gee_test_case_test_method (gpointer self);
void hash_map_tests_test_gobject_properties (HashMapTests* self);
static void _hash_map_tests_test_gobject_properties_gee_test_case_test_method (gpointer self);
static void hash_map_tests_real_set_up (GeeTestCase* base);
static void hash_map_tests_real_tear_down (GeeTestCase* base);


static void _hash_map_tests_test_selected_functions_gee_test_case_test_method (gpointer self) {
	hash_map_tests_test_selected_functions (self);
}


static void _hash_map_tests_test_gobject_properties_gee_test_case_test_method (gpointer self) {
	hash_map_tests_test_gobject_properties (self);
}


HashMapTests* hash_map_tests_construct (GType object_type) {
	HashMapTests * self = NULL;
	self = (HashMapTests*) map_tests_construct (object_type, "HashMap");
	gee_test_case_add_test ((GeeTestCase*) self, "[HashMap] selected functions", _hash_map_tests_test_selected_functions_gee_test_case_test_method, self);
	gee_test_case_add_test ((GeeTestCase*) self, "[HashMap] GObject properties", _hash_map_tests_test_gobject_properties_gee_test_case_test_method, self);
	return self;
}


HashMapTests* hash_map_tests_new (void) {
	return hash_map_tests_construct (TYPE_HASH_MAP_TESTS);
}


static void hash_map_tests_real_set_up (GeeTestCase* base) {
	HashMapTests * self;
	GeeHashMap* _tmp0_;
	self = (HashMapTests*) base;
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL);
	_g_object_unref0 (((MapTests*) self)->test_map);
	((MapTests*) self)->test_map = (GeeMap*) _tmp0_;
}


static void hash_map_tests_real_tear_down (GeeTestCase* base) {
	HashMapTests * self;
	self = (HashMapTests*) base;
	_g_object_unref0 (((MapTests*) self)->test_map);
	((MapTests*) self)->test_map = NULL;
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


void hash_map_tests_test_selected_functions (HashMapTests* self) {
	GeeMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GeeHashMap* test_hash_map;
	GHashFunc _tmp2_;
	GHashFunc _tmp3_;
	GHashFunc _tmp4_;
	GEqualFunc _tmp5_;
	GEqualFunc _tmp6_;
	GEqualFunc _tmp7_;
	GEqualFunc _tmp8_;
	GEqualFunc _tmp9_;
	GEqualFunc _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ((MapTests*) self)->test_map;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, GEE_TYPE_HASH_MAP) ? ((GeeHashMap*) _tmp0_) : NULL);
	test_hash_map = _tmp1_;
	_vala_assert (test_hash_map != NULL, "test_hash_map != null");
	_tmp2_ = gee_hash_map_get_key_hash_func (test_hash_map);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_str_hash;
	_vala_assert (_tmp3_ == _tmp4_, "test_hash_map.key_hash_func == str_hash");
	_tmp5_ = gee_hash_map_get_key_equal_func (test_hash_map);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_str_equal;
	_vala_assert (_tmp6_ == _tmp7_, "test_hash_map.key_equal_func == str_equal");
	_tmp8_ = gee_hash_map_get_value_equal_func (test_hash_map);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_str_equal;
	_vala_assert (_tmp9_ == _tmp10_, "test_hash_map.value_equal_func == str_equal");
	_g_object_unref0 (test_hash_map);
}


void hash_map_tests_test_gobject_properties (HashMapTests* self) {
	GeeMap* _tmp0_;
	GeeHashMap* _tmp1_;
	GeeHashMap* test_hash_map;
	GValue value = {0};
	GValue _tmp2_ = {0};
	GValue _tmp3_;
	void* _tmp4_ = NULL;
	GHashFunc _tmp5_;
	GHashFunc _tmp6_;
	GValue _tmp7_ = {0};
	GValue _tmp8_;
	void* _tmp9_ = NULL;
	GEqualFunc _tmp10_;
	GEqualFunc _tmp11_;
	GValue _tmp12_ = {0};
	GValue _tmp13_;
	void* _tmp14_ = NULL;
	GEqualFunc _tmp15_;
	GEqualFunc _tmp16_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ((MapTests*) self)->test_map;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, GEE_TYPE_HASH_MAP) ? ((GeeHashMap*) _tmp0_) : NULL);
	test_hash_map = _tmp1_;
	_vala_assert (test_hash_map != NULL, "test_hash_map != null");
	g_value_init (&_tmp2_, G_TYPE_POINTER);
	G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
	value = _tmp2_;
	_tmp3_ = value;
	g_object_get_property ((GObject*) test_hash_map, "key-hash-func", &value);
	_tmp4_ = g_value_get_pointer (&value);
	_tmp5_ = gee_hash_map_get_key_hash_func (test_hash_map);
	_tmp6_ = _tmp5_;
	_vala_assert (_tmp4_ == ((void*) _tmp6_), "value.get_pointer () == (void*) test_hash_map.key_hash_func");
	g_value_unset (&value);
	g_value_init (&_tmp7_, G_TYPE_POINTER);
	G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
	value = _tmp7_;
	_tmp8_ = value;
	g_object_get_property ((GObject*) test_hash_map, "key-equal-func", &value);
	_tmp9_ = g_value_get_pointer (&value);
	_tmp10_ = gee_hash_map_get_key_equal_func (test_hash_map);
	_tmp11_ = _tmp10_;
	_vala_assert (_tmp9_ == ((void*) _tmp11_), "value.get_pointer () == (void*) test_hash_map.key_equal_func");
	g_value_unset (&value);
	g_value_init (&_tmp12_, G_TYPE_POINTER);
	G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
	value = _tmp12_;
	_tmp13_ = value;
	g_object_get_property ((GObject*) test_hash_map, "value-equal-func", &value);
	_tmp14_ = g_value_get_pointer (&value);
	_tmp15_ = gee_hash_map_get_value_equal_func (test_hash_map);
	_tmp16_ = _tmp15_;
	_vala_assert (_tmp14_ == ((void*) _tmp16_), "value.get_pointer () == (void*) test_hash_map.value_equal_func");
	g_value_unset (&value);
	G_IS_VALUE (&value) ? (g_value_unset (&value), NULL) : NULL;
	_g_object_unref0 (test_hash_map);
}


static void hash_map_tests_class_init (HashMapTestsClass * klass) {
	hash_map_tests_parent_class = g_type_class_peek_parent (klass);
	GEE_TEST_CASE_CLASS (klass)->set_up = hash_map_tests_real_set_up;
	GEE_TEST_CASE_CLASS (klass)->tear_down = hash_map_tests_real_tear_down;
}


static void hash_map_tests_instance_init (HashMapTests * self) {
}


GType hash_map_tests_get_type (void) {
	static volatile gsize hash_map_tests_type_id__volatile = 0;
	if (g_once_init_enter (&hash_map_tests_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (HashMapTestsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) hash_map_tests_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (HashMapTests), 0, (GInstanceInitFunc) hash_map_tests_instance_init, NULL };
		GType hash_map_tests_type_id;
		hash_map_tests_type_id = g_type_register_static (TYPE_MAP_TESTS, "HashMapTests", &g_define_type_info, 0);
		g_once_init_leave (&hash_map_tests_type_id__volatile, hash_map_tests_type_id);
	}
	return hash_map_tests_type_id__volatile;
}