diff options
author | Akira TAGOH <akira@tagoh.org> | 2007-12-06 12:48:41 +0000 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2007-12-06 12:48:41 +0000 |
commit | 3ab27f145c5eb34b5d4aeeba1d6f70c764d27b63 (patch) | |
tree | c2e7525fb723dcfd94f1b0101c53791f3b499d6d | |
parent | bd089e360818c0482830c481184a554cb2f4c5a0 (diff) |
2007-12-06 Akira TAGOH <akira@tagoh.org>
* tests/hgdict.c: Add more testcases.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | hieroglyph/version.h.in | 2 | ||||
-rw-r--r-- | tests/hgdict.c | 243 |
3 files changed, 244 insertions, 5 deletions
@@ -1,3 +1,7 @@ +2007-12-06 Akira TAGOH <akira@tagoh.org> + + * tests/hgdict.c: Add more testcases. + 2007-12-03 Akira TAGOH <akira@tagoh.org> * hieroglyph/hgobject.h (HG_OBJECT_REAL_IS_EQUAL_TO): new macro. diff --git a/hieroglyph/version.h.in b/hieroglyph/version.h.in index bd7c07b..a1cf5d1 100644 --- a/hieroglyph/version.h.in +++ b/hieroglyph/version.h.in @@ -30,7 +30,7 @@ G_BEGIN_DECLS #define HIEROGLYPH_VERSION "@VERSION@" -#define HIEROGLYPH_UUID "8fd615c0-a15f-4055-9ebe-b041fac5a25e" +#define HIEROGLYPH_UUID "6e3f98a3-e73f-4213-be79-fd28e8a88566" const char *__hg_rcsid G_GNUC_UNUSED = "$Rev$"; diff --git a/tests/hgdict.c b/tests/hgdict.c index 14026a0..84f1db2 100644 --- a/tests/hgdict.c +++ b/tests/hgdict.c @@ -200,25 +200,260 @@ TEND TDEF (hg_object_dict_insert_without_consistency) { - g_print("FIXME: %s\n", __FUNCTION__); + hg_object_t *obj1, *obj1_; + gboolean allocmode = hg_vm_get_current_allocation_mode(vm); + + /* objects allocated from the global pool */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + + /* Insert object allocated in the local pool to the global object */ + hg_vm_set_current_allocation_mode(vm, FALSE); + + obj1 = hg_object_name_new(vm, "bool2", FALSE); + obj1_ = hg_object_boolean_new(vm, TRUE); + TNUL (obj1); + TNUL (obj1_); + fail_unless(hg_object_dict_insert_without_consistency(obj, obj1, obj1_), "Failed to insert the local object into the global object."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* objects allocated from the local pool */ + hg_vm_set_current_allocation_mode(vm, FALSE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + fail_unless(!HG_OBJECT_ATTR_IS_GLOBAL (obj), "Object wasn't allocated from the local pool."); + + /* Insert object allocated in the global pool to the local object */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj1 = hg_object_name_new(vm, "bool2", FALSE); + obj1_ = hg_object_boolean_new(vm, TRUE); + TNUL (obj1); + TNUL (obj1_); + fail_unless(HG_OBJECT_ATTR_IS_GLOBAL (obj1), "Object wasn't allocated from the global pool."); + fail_unless(HG_OBJECT_ATTR_IS_GLOBAL (obj1_), "Object wasn't allocated from the global pool."); + fail_unless(hg_object_dict_insert_without_consistency(obj, obj1, obj1_), "Failed to insert the global object into the local object."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* recover the allocation mode */ + hg_vm_set_current_allocation_mode(vm, allocmode); } TEND TDEF (hg_object_dict_replace) { - g_print("FIXME: %s\n", __FUNCTION__); + hg_object_t *obj1, *obj1_, *obj2, *obj2_, *obj3, *obj3_, *obj4, *obj4_, *obj_; + gboolean allocmode = hg_vm_get_current_allocation_mode(vm); + + /* objects allocated from the global pool */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + + obj1 = hg_object_name_new(vm, "name", FALSE); + obj1_ = hg_object_name_new(vm, "bar", FALSE); + obj2 = hg_object_name_new(vm, "int", FALSE); + obj2_ = hg_object_integer_new(vm, 10); + TNUL (obj1); + TNUL (obj1_); + TNUL (obj2); + TNUL (obj2_); + + fail_unless(hg_object_dict_insert(obj, obj1, obj1_), "Failed to insert an object (named)"); + fail_unless(hg_object_dict_insert(obj, obj2, obj2_), "Failed to insert an object (int)"); + + fail_unless((obj_ = hg_object_dict_lookup(obj, obj1)) != NULL, "Failed to look up the object (named)"); + fail_unless(hg_object_compare(obj1_, obj_), "Failed to compare the object after looking up (named)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj2)) != NULL, "Failed to look up the object (int)"); + fail_unless(hg_object_compare(obj2_, obj_), "Failed to compare the object after looking up (int)"); + + obj3 = hg_object_name_new(vm, "name", FALSE); + obj3_ = hg_object_name_new(vm, "foo", FALSE); + TNUL (obj3); + TNUL (obj3_); + fail_unless(hg_object_dict_replace(obj, obj3, obj3_), "Failed to replace an object (named)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj3)) != NULL, "Failed to look up the object (named)"); + fail_unless(hg_object_compare(obj3_, obj_), "Failed to compare the object after looking up (named)"); + + /* Insert object allocated in the local pool to the global object */ + hg_vm_set_current_allocation_mode(vm, FALSE); + + obj4 = hg_object_name_new(vm, "name", FALSE); + obj4_ = hg_object_name_new(vm, "baz", FALSE); + TNUL (obj4); + TNUL (obj4_); + fail_unless(!hg_object_dict_replace(obj, obj4, obj4_), "Have to fail replacing the local object into the global object."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj4_); + hg_object_free(vm, obj4); + hg_object_free(vm, obj3_); + hg_object_free(vm, obj3); + hg_object_free(vm, obj2_); + hg_object_free(vm, obj2); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* objects allocated from the local pool */ + hg_vm_set_current_allocation_mode(vm, FALSE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + fail_unless(!HG_OBJECT_ATTR_IS_GLOBAL (obj), "Object wasn't allocated from the local pool."); + + obj1 = hg_object_name_new(vm, "name", FALSE); + obj1_ = hg_object_name_new(vm, "bar", FALSE); + obj2 = hg_object_name_new(vm, "int", FALSE); + obj2_ = hg_object_integer_new(vm, 10); + TNUL (obj1); + TNUL (obj1_); + TNUL (obj2); + TNUL (obj2_); + + fail_unless(hg_object_dict_insert(obj, obj1, obj1_), "Failed to insert an object (named)"); + fail_unless(hg_object_dict_insert(obj, obj2, obj2_), "Failed to insert an object (int)"); + + fail_unless((obj_ = hg_object_dict_lookup(obj, obj1)) != NULL, "Failed to look up the object (named)"); + fail_unless(hg_object_compare(obj1_, obj_), "Failed to compare the object after looking up (named)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj2)) != NULL, "Failed to look up the object (int)"); + fail_unless(hg_object_compare(obj2_, obj_), "Failed to compare the object after looking up (int)"); + + obj3 = hg_object_name_new(vm, "name", FALSE); + obj3_ = hg_object_name_new(vm, "foo", FALSE); + TNUL (obj3); + TNUL (obj3_); + fail_unless(hg_object_dict_replace(obj, obj3, obj3_), "Failed to replace an object (named)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj3)) != NULL, "Failed to look up the object (named)"); + fail_unless(hg_object_compare(obj3_, obj_), "Failed to compare the object after looking up (named)"); + + /* Insert object allocated in the global pool to the local object */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj4 = hg_object_name_new(vm, "name", FALSE); + obj4_ = hg_object_name_new(vm, "baz", FALSE); + TNUL (obj4); + TNUL (obj4_); + fail_unless(HG_OBJECT_ATTR_IS_GLOBAL (obj4), "Object wasn't allocated from the global pool."); + fail_unless(HG_OBJECT_ATTR_IS_GLOBAL (obj4_), "Object wasn't allocated from the global pool."); + fail_unless(hg_object_dict_replace(obj, obj4, obj4_), "Don't have to fail inserting the global object into the local object."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj4_); + hg_object_free(vm, obj4); + hg_object_free(vm, obj3_); + hg_object_free(vm, obj3); + hg_object_free(vm, obj2_); + hg_object_free(vm, obj2); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* recover the allocation mode */ + hg_vm_set_current_allocation_mode(vm, allocmode); } TEND TDEF (hg_object_dict_replace_without_consistency) { - g_print("FIXME: %s\n", __FUNCTION__); + hg_object_t *obj1, *obj1_; + gboolean allocmode = hg_vm_get_current_allocation_mode(vm); + + /* objects allocated from the global pool */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + + /* Insert object allocated in the local pool to the global object */ + hg_vm_set_current_allocation_mode(vm, FALSE); + + obj1 = hg_object_name_new(vm, "bool2", FALSE); + obj1_ = hg_object_name_new(vm, "foo", FALSE); + TNUL (obj1); + TNUL (obj1_); + fail_unless(hg_object_dict_replace_without_consistency(obj, obj1, obj1_), "Failed to insert the local object into the global object."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* objects allocated from the local pool */ + hg_vm_set_current_allocation_mode(vm, FALSE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + fail_unless(!HG_OBJECT_ATTR_IS_GLOBAL (obj), "Object wasn't allocated from the local pool."); + + /* Insert object allocated in the global pool to the local object */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj1 = hg_object_name_new(vm, "bool2", FALSE); + obj1_ = hg_object_boolean_new(vm, TRUE); + TNUL (obj1); + TNUL (obj1_); + fail_unless(HG_OBJECT_ATTR_IS_GLOBAL (obj1), "Object wasn't allocated from the global pool."); + fail_unless(HG_OBJECT_ATTR_IS_GLOBAL (obj1_), "Object wasn't allocated from the global pool."); + fail_unless(hg_object_dict_replace_without_consistency(obj, obj1, obj1_), "Failed to insert the global object into the local object."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* recover the allocation mode */ + hg_vm_set_current_allocation_mode(vm, allocmode); } TEND TDEF (hg_object_dict_remove) { - g_print("FIXME: %s\n", __FUNCTION__); + hg_object_t *obj1, *obj1_, *obj2, *obj2_, *obj3, *obj_; + gboolean allocmode = hg_vm_get_current_allocation_mode(vm); + + /* objects allocated from the global pool */ + hg_vm_set_current_allocation_mode(vm, TRUE); + + obj = hg_object_dict_new(vm, 10); + TNUL (obj); + + obj1 = hg_object_name_new(vm, "bool", FALSE); + obj1_ = hg_object_boolean_new(vm, TRUE); + obj2 = hg_object_name_new(vm, "int", FALSE); + obj2_ = hg_object_integer_new(vm, 10); + TNUL (obj1); + TNUL (obj1_); + TNUL (obj2); + TNUL (obj2_); + + fail_unless(hg_object_dict_insert(obj, obj1, obj1_), "Failed to insert an object (bool)"); + fail_unless(hg_object_dict_insert(obj, obj2, obj2_), "Failed to insert an object (int)"); + + fail_unless((obj_ = hg_object_dict_lookup(obj, obj1)) != NULL, "Failed to look up the object (bool)"); + fail_unless(hg_object_compare(obj1_, obj_), "Failed to compare the object after looking up (bool)"); + fail_unless((obj_ = hg_object_dict_lookup(obj, obj2)) != NULL, "Failed to look up the object (int)"); + fail_unless(hg_object_compare(obj2_, obj_), "Failed to compare the object after looking up (int)"); + + obj3 = hg_object_name_new(vm, "int", FALSE); + fail_unless(hg_object_dict_remove(obj, obj3), "Failed to remove the key from the dict."); + fail_unless(hg_object_dict_lookup(obj, obj3) == NULL, "There are still data in the dict."); + + hg_object_free(vm, obj); + hg_object_free(vm, obj3); + hg_object_free(vm, obj2_); + hg_object_free(vm, obj2); + hg_object_free(vm, obj1_); + hg_object_free(vm, obj1); + + /* recover the allocation mode */ + hg_vm_set_current_allocation_mode(vm, allocmode); } TEND |