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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* hgobject.c
* Copyright (C) 2007-2009 Akira TAGOH
*
* Authors:
* Akira TAGOH <akira@tagoh.org>
*
* 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 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <hieroglyph/hgobject.h>
#include <hieroglyph/vm.h>
#include "main.h"
hg_vm_t *vm;
hg_object_t *obj;
void
setup(void)
{
vm = hg_vm_new();
}
void
teardown(void)
{
hg_vm_destroy(vm);
}
/* core object */
TDEF (hg_object_new)
{
gboolean flag;
obj = hg_object_new(vm, 1);
TNUL (obj);
fail_unless(HG_OBJECT_GET_N_OBJECTS (obj) == 1, "The amount of the object is different.");
hg_object_free(vm, obj);
obj = hg_object_new(vm, 10);
TNUL (obj);
fail_unless(HG_OBJECT_GET_N_OBJECTS (obj) == 10, "The amount of the object is different.");
hg_object_free(vm, obj);
/* disable stacktrace */
if (hg_is_stacktrace_enabled)
flag = hg_is_stacktrace_enabled();
hg_use_stacktrace(FALSE);
/* disable warnings */
hg_quiet_warning_messages(TRUE);
obj = hg_object_new(vm, 0);
if (hg_is_stacktrace_enabled)
hg_use_stacktrace(flag);
hg_quiet_warning_messages(FALSE);
fail_unless(obj == NULL, "Not allowed to create empty object");
}
TEND
TDEF (hg_object_sized_new)
{
obj = hg_object_sized_new(vm, 10);
TNUL (obj);
fail_unless(HG_OBJECT_GET_N_OBJECTS (obj) == 1, "The amount of the object is different.");
fail_unless(HG_OBJECT_HEADER (obj)->total_length == hg_n_alignof (hg_n_alignof (sizeof (hg_object_header_t) + sizeof (_hg_object_t)) + 10), "The length of the object is different.");
hg_object_free(vm, obj);
obj = hg_object_sized_new(vm, 0);
TNUL (obj);
fail_unless(HG_OBJECT_GET_N_OBJECTS (obj) == 1, "The amount of the object is different.");
fail_unless(HG_OBJECT_HEADER (obj)->total_length == hg_n_alignof (sizeof (hg_object_header_t) + sizeof (_hg_object_t)), "The length of the object is different.");
hg_object_free(vm, obj);
}
TEND
TDEF (hg_object_dup)
{
hg_object_t *obj2;
obj = hg_object_new(vm, 1);
TNUL (obj);
/* disable warning messages */
hg_quiet_warning_messages(TRUE);
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 == NULL, "Not allowed to duplicate the uninitialized object");
hg_quiet_warning_messages(FALSE);
hg_object_free(vm, obj);
/* null */
obj = hg_object_null_new(vm);
fail_unless(obj != NULL, "Failed to create a null object");
fail_unless(HG_OBJECT_IS_NULL (obj), "Created object isn't a null object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate a null object");
fail_unless(HG_OBJECT_IS_NULL (obj2), "Duplicated object isn't a null object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* integer */
obj = hg_object_integer_new(vm, 123);
fail_unless(obj != NULL, "Failed to create an integer object");
fail_unless(HG_OBJECT_IS_INTEGER (obj), "Created object isn't an integer object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate an integer object");
fail_unless(HG_OBJECT_IS_INTEGER (obj2), "Duplicated object isn't an integer object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* real */
obj = hg_object_real_new(vm, 0.01);
fail_unless(obj != NULL, "Failed to create an real object");
fail_unless(HG_OBJECT_IS_REAL (obj), "Created object isn't an real object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate an real object");
fail_unless(HG_OBJECT_IS_REAL (obj2), "Duplicated object isn't an real object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* name */
obj = hg_object_name_new(vm, "foo", FALSE);
fail_unless(obj != NULL, "Failed to create a name object");
fail_unless(HG_OBJECT_IS_NAME (obj), "Created object isn't a name object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate a name object");
fail_unless(HG_OBJECT_IS_NAME (obj2), "Duplicated object isn't a name object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* name eval */
obj = hg_object_name_new(vm, "foo", TRUE);
fail_unless(obj != NULL, "Failed to create a name(eval) object");
fail_unless(HG_OBJECT_IS_EVAL (obj), "Created object isn't a name(eval) object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate a name object");
fail_unless(HG_OBJECT_IS_EVAL (obj2), "Duplicated object isn't a name(eval) object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* system encoding */
obj = hg_object_system_encoding_new(vm, HG_enc_abs, FALSE);
fail_unless(obj != NULL, "Failed to create a name object");
fail_unless(HG_OBJECT_IS_NAME (obj), "Created object isn't a name object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate a name object");
fail_unless(HG_OBJECT_IS_NAME (obj2), "Duplicated object isn't a name object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* system encoding eval */
obj = hg_object_system_encoding_new(vm, HG_enc_abs, TRUE);
fail_unless(obj != NULL, "Failed to create a name(eval) object");
fail_unless(HG_OBJECT_IS_EVAL (obj), "Created object isn't a name(eval) object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate a name(eval) object");
fail_unless(HG_OBJECT_IS_EVAL (obj2), "Duplicated object isn't a name(eval) object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* boolean */
obj = hg_object_boolean_new(vm, TRUE);
fail_unless(obj != NULL, "Failed to create a boolean object");
fail_unless(HG_OBJECT_IS_BOOLEAN (obj), "Created object isn't a boolean object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate a boolean object");
fail_unless(HG_OBJECT_IS_BOOLEAN (obj2), "Duplicated object isn't a boolean object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* mark */
obj = hg_object_mark_new(vm);
fail_unless(obj != NULL, "Failed to create a mark object");
fail_unless(HG_OBJECT_IS_MARK (obj), "Created object isn't a mark object");
obj2 = hg_object_dup(vm, obj);
fail_unless(obj2 != NULL, "Failed to duplicate a mark object");
fail_unless(HG_OBJECT_IS_MARK (obj2), "Duplicated object isn't a mark object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly duplicated");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
}
TEND
TDEF (hg_object_copy)
{
hg_object_t *obj2;
obj = hg_object_new(vm, 1);
TNUL (obj);
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy an uninitialized object");
hg_object_free(vm, obj);
/* null */
obj = hg_object_null_new(vm);
fail_unless(obj != NULL, "Failed to create a null object");
fail_unless(HG_OBJECT_IS_NULL (obj), "Created object isn't a null object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy a null object");
fail_unless(HG_OBJECT_IS_NULL (obj2), "Copied object isn't a null object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* integer */
obj = hg_object_integer_new(vm, 123);
fail_unless(obj != NULL, "Failed to create an integer object");
fail_unless(HG_OBJECT_IS_INTEGER (obj), "Created object isn't an integer object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy an integer object");
fail_unless(HG_OBJECT_IS_INTEGER (obj2), "Copied object isn't an integer object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* real */
obj = hg_object_real_new(vm, 0.01);
fail_unless(obj != NULL, "Failed to create an real object");
fail_unless(HG_OBJECT_IS_REAL (obj), "Created object isn't an real object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy an real object");
fail_unless(HG_OBJECT_IS_REAL (obj2), "Copied object isn't an real object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* name */
obj = hg_object_name_new(vm, "foo", FALSE);
fail_unless(obj != NULL, "Failed to create a name object");
fail_unless(HG_OBJECT_IS_NAME (obj), "Created object isn't a name object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy a name object");
fail_unless(HG_OBJECT_IS_NAME (obj2), "Copied object isn't a name object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* name eval */
obj = hg_object_name_new(vm, "foo", TRUE);
fail_unless(obj != NULL, "Failed to create a name(eval) object");
fail_unless(HG_OBJECT_IS_EVAL (obj), "Created object isn't a name(eval) object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy a name object");
fail_unless(HG_OBJECT_IS_EVAL (obj2), "Copied object isn't a name(eval) object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* system encoding */
obj = hg_object_system_encoding_new(vm, HG_enc_abs, FALSE);
fail_unless(obj != NULL, "Failed to create a name object");
fail_unless(HG_OBJECT_IS_NAME (obj), "Created object isn't a name object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy a name object");
fail_unless(HG_OBJECT_IS_NAME (obj2), "Copied object isn't a name object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* system encoding eval */
obj = hg_object_system_encoding_new(vm, HG_enc_abs, TRUE);
fail_unless(obj != NULL, "Failed to create a name(eval) object");
fail_unless(HG_OBJECT_IS_EVAL (obj), "Created object isn't a name(eval) object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy a name(eval) object");
fail_unless(HG_OBJECT_IS_EVAL (obj2), "Copied object isn't a name(eval) object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* boolean */
obj = hg_object_boolean_new(vm, TRUE);
fail_unless(obj != NULL, "Failed to create a boolean object");
fail_unless(HG_OBJECT_IS_BOOLEAN (obj), "Created object isn't a boolean object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy a boolean object");
fail_unless(HG_OBJECT_IS_BOOLEAN (obj2), "Copied object isn't a boolean object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
/* mark */
obj = hg_object_mark_new(vm);
fail_unless(obj != NULL, "Failed to create a mark object");
fail_unless(HG_OBJECT_IS_MARK (obj), "Created object isn't a mark object");
obj2 = hg_object_copy(vm, obj);
fail_unless(obj2 != NULL, "Failed to copy a mark object");
fail_unless(HG_OBJECT_IS_MARK (obj2), "Copied object isn't a mark object");
fail_unless(hg_object_compare(obj, obj2), "Object wasn't exactly copied");
hg_object_free(vm, obj);
hg_object_free(vm, obj2);
}
TEND
TDEF (hg_object_compare)
{
/* almost test cases has been done at hg_object_dup/copy */
}
TEND
TDEF (hg_object_dump)
{
g_print("FIXME: %s\n", __FUNCTION__);
}
TEND
/* null object */
TDEF (hg_object_null_new)
{
obj = hg_object_null_new(vm);
fail_unless(obj != NULL, "Failed to create a null object");
fail_unless(HG_OBJECT_IS_NULL (obj), "Created object isn't a null object.");
hg_object_free(vm, obj);
}
TEND
/* integer object */
TDEF (hg_object_integer_new)
{
obj = hg_object_integer_new(vm, 1);
fail_unless(obj != NULL, "Failed to create an integer object");
fail_unless(HG_OBJECT_IS_INTEGER (obj), "Created object isn't an integer object");
fail_unless(HG_OBJECT_INTEGER (obj) == 1, "Object isn't set correctly on creation");
hg_object_free(vm, obj);
obj = hg_object_integer_new(vm, -1);
fail_unless(obj != NULL, "Failed to create an integer object");
fail_unless(HG_OBJECT_IS_INTEGER (obj), "Created object isn't an integer object");
fail_unless(HG_OBJECT_INTEGER (obj) == -1, "Object isn't set correctly on creation");
hg_object_free(vm, obj);
}
TEND
/* real object */
TDEF (hg_object_real_new)
{
obj = hg_object_real_new(vm, 1);
fail_unless(obj != NULL, "Failed to create an real object");
fail_unless(HG_OBJECT_IS_REAL (obj), "Created object isn't an real object");
fail_unless(HG_OBJECT_REAL_IS_EQUAL_TO (obj, 1), "Object isn't set correctly on creation");
hg_object_free(vm, obj);
obj = hg_object_real_new(vm, -1);
fail_unless(obj != NULL, "Failed to create an real object");
fail_unless(HG_OBJECT_IS_REAL (obj), "Created object isn't an real object");
fail_unless(HG_OBJECT_REAL_IS_EQUAL_TO (obj, -1), "Object isn't set correctly on creation");
hg_object_free(vm, obj);
}
TEND
/* name object */
TDEF (hg_object_name_new)
{
obj = hg_object_name_new(vm, "foo", FALSE);
fail_unless(obj != NULL, "Failed to create a name object");
fail_unless(HG_OBJECT_IS_NAME (obj), "Created object isn't a name object");
fail_unless(hg_object_name_compare_with_raw(obj, "foo"), "Object isn't set correctly on creation");
hg_object_free(vm, obj);
obj = hg_object_name_new(vm, "foo", TRUE);
fail_unless(obj != NULL, "Failed to create a name object");
fail_unless(HG_OBJECT_IS_EVAL (obj), "Created object isn't a name object");
fail_unless(hg_object_name_compare_with_raw(obj, "foo"), "Object isn't set correctly on creation");
hg_object_free(vm, obj);
}
TEND
/* system encoding object */
TDEF (hg_object_system_encoding_new)
{
hg_vm_initialize(vm);
obj = hg_object_system_encoding_new(vm, HG_enc_abs, FALSE);
fail_unless(obj != NULL, "Failed to create a system encoding object");
fail_unless(HG_OBJECT_IS_NAME (obj), "Created object isn't a system encoding object");
fail_unless(hg_object_name_compare_with_raw(obj, "abs"), "Object isn't set correctly on creation");
hg_object_free(vm, obj);
obj = hg_object_system_encoding_new(vm, HG_enc_abs, TRUE);
fail_unless(obj != NULL, "Failed to create a system encoding object");
fail_unless(HG_OBJECT_IS_EVAL (obj), "Created object isn't a system encoding object");
fail_unless(hg_object_name_compare_with_raw(obj, "abs"), "Object isn't set correctly on creation");
hg_object_free(vm, obj);
hg_vm_finalize(vm);
}
TEND
/* boolean object */
TDEF (hg_object_boolean_new)
{
obj = hg_object_boolean_new(vm, FALSE);
fail_unless(obj != NULL, "Failed to create a boolean object");
fail_unless(HG_OBJECT_IS_BOOLEAN (obj), "Created object isn't a boolean object");
fail_unless(HG_OBJECT_BOOLEAN (obj) == FALSE, "Object isn't set correctly on creation");
hg_object_free(vm, obj);
obj = hg_object_boolean_new(vm, TRUE);
fail_unless(obj != NULL, "Failed to create a boolean object");
fail_unless(HG_OBJECT_IS_BOOLEAN (obj), "Created object isn't a boolean object");
fail_unless(HG_OBJECT_BOOLEAN (obj) == TRUE, "Object isn't set correctly on creation");
hg_object_free(vm, obj);
}
TEND
/* mark object */
TDEF (hg_object_mark_new)
{
obj = hg_object_mark_new(vm);
fail_unless(obj != NULL, "Failed to create a mark object");
fail_unless(HG_OBJECT_IS_MARK (obj), "Created object isn't a mark object");
hg_object_free(vm, obj);
}
TEND
/************************************************************/
Suite *
hieroglyph_suite(void)
{
Suite *s = suite_create("hg_object_t");
TCase *tc = tcase_create("Generic Functionalities");
tcase_add_checked_fixture(tc, setup, teardown);
T (hg_object_new);
T (hg_object_sized_new);
T (hg_object_dup);
T (hg_object_copy);
T (hg_object_compare);
T (hg_object_dump);
T (hg_object_null_new);
T (hg_object_integer_new);
T (hg_object_real_new);
T (hg_object_name_new);
T (hg_object_system_encoding_new);
T (hg_object_boolean_new);
T (hg_object_mark_new);
suite_add_tcase(s, tc);
return s;
}
|