diff options
author | Akira TAGOH <akira@tagoh.org> | 2007-12-22 08:40:48 +0000 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2007-12-22 08:40:48 +0000 |
commit | 0ff362ceb2747c960b415e9dd07a0a011214b472 (patch) | |
tree | c1be56824a1071c7b33a2b47d6fda59498fa0b2f | |
parent | 3ab27f145c5eb34b5d4aeeba1d6f70c764d27b63 (diff) |
2007-12-22 Akira TAGOH <akira@tagoh.org>
* tests/hgstring.c: Add more testcases.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | hieroglyph/version.h.in | 2 | ||||
-rw-r--r-- | tests/hgstring.c | 71 |
3 files changed, 72 insertions, 5 deletions
@@ -1,3 +1,7 @@ +2007-12-22 Akira TAGOH <akira@tagoh.org> + + * tests/hgstring.c: Add more testcases. + 2007-12-06 Akira TAGOH <akira@tagoh.org> * tests/hgdict.c: Add more testcases. diff --git a/hieroglyph/version.h.in b/hieroglyph/version.h.in index a1cf5d1..7a0e4dd 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 "6e3f98a3-e73f-4213-be79-fd28e8a88566" +#define HIEROGLYPH_UUID "886e7224-54f7-419a-beff-43834dc46659" const char *__hg_rcsid G_GNUC_UNUSED = "$Rev$"; diff --git a/tests/hgstring.c b/tests/hgstring.c index fc33977..8331ef1 100644 --- a/tests/hgstring.c +++ b/tests/hgstring.c @@ -24,7 +24,9 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include <string.h> #include <hieroglyph/hgstring.h> +#include <hieroglyph/hgobject.h> #include <hieroglyph/vm.h> #include "main.h" @@ -47,25 +49,86 @@ teardown(void) /* string object */ TDEF (hg_object_string_new) { - g_print("FIXME: %s\n", __FUNCTION__); + gchar *p; + + obj = hg_object_string_new(vm, "foo"); + + fail_unless(obj != NULL, "Failed to create a string object"); + fail_unless(HG_OBJECT_IS_STRING (obj), "Created object isn't a string object"); + p = HG_OBJECT_STRING_DATA (obj)->string; + fail_unless(p[0] == 'f' && p[1] == 'o' && p[2] == 'o', "Object isn't set correctly on object creation"); + fail_unless(HG_OBJECT_STRING (obj)->real_length == 3, "Object doesn't have an expected length"); + + hg_object_free(vm, obj); } TEND TDEF (hg_object_string_sized_new) { - g_print("FIXME: %s\n", __FUNCTION__); + obj = hg_object_string_sized_new(vm, 10); + + fail_unless(obj != NULL, "Failed to create a string object"); + fail_unless(HG_OBJECT_IS_STRING (obj), "Created object isn't a string object"); + fail_unless(HG_OBJECT_STRING (obj)->length == 10, "Object doesn't have an expected length"); + + hg_object_free(vm, obj); + + obj = hg_object_string_sized_new(vm, 0); + + fail_unless(obj != NULL, "Failed to create a string object"); + fail_unless(HG_OBJECT_IS_STRING (obj), "Created object isn't a string object"); + fail_unless(HG_OBJECT_STRING_DATA (obj)->string == NULL, "Don't have an allocated space"); + fail_unless(HG_OBJECT_STRING (obj)->length == 0, "Object doesn't have an expected length"); + + hg_object_free(vm, obj); } TEND TDEF (hg_object_string_substring_new) { - g_print("FIXME: %s\n", __FUNCTION__); + hg_object_t *obj2; + + obj = hg_object_string_new(vm, "I like a dog"); + + fail_unless(obj != NULL, "Failed to create a string object"); + fail_unless(HG_OBJECT_IS_STRING (obj), "Created object isn't a string object"); + + obj2 = hg_object_string_substring_new(vm, obj, 9, 3); + + fail_unless(obj2 != NULL, "Failed to create a substring."); + fail_unless(HG_OBJECT_IS_STRING (obj2), "Created substring isn't a string object"); + + memcpy(HG_OBJECT_STRING_DATA (obj2)->string, "cat", 3); + fail_unless(strncmp(HG_OBJECT_STRING_DATA (obj)->string, + "I like a cat", + HG_OBJECT_STRING (obj)->real_length) == 0, "Failed to modify through a substring"); + + hg_object_free(vm, obj); } TEND TDEF (hg_object_string_compare) { - g_print("FIXME: %s\n", __FUNCTION__); + hg_object_t *obj2; + + obj = hg_object_string_new(vm, "foo"); + obj2 = hg_object_string_new(vm, "foo"); + + fail_unless(obj != NULL, "Failed to create a string object"); + fail_unless(obj2 != NULL, "Failed to create a string object(2)"); + + fail_unless(hg_object_string_compare(obj, obj2), "Failed to compare the string objects"); + + hg_object_free(vm, obj2); + + obj2 = hg_object_string_new(vm, "bar"); + + fail_unless(obj2 != NULL, "Failed to create a string object(3)"); + + fail_unless(!hg_object_string_compare(obj, obj2), "Have to be different."); + + hg_object_free(vm, obj2); + hg_object_free(vm, obj); } TEND |