summaryrefslogtreecommitdiff
path: root/test/api/test-blob.c
diff options
context:
space:
mode:
authorjk7744.park <jk7744.park@samsung.com>2015-09-08 22:49:29 +0900
committerjk7744.park <jk7744.park@samsung.com>2015-09-08 22:49:29 +0900
commit3b116dcddafed5f018198863aac3cd81d3c7c7e2 (patch)
tree36e082d5a3d13e03ecb9c18d57834cb3bfa13659 /test/api/test-blob.c
parentb08254dad51328fed58b3c0999a1eb7a25f53efc (diff)
downloadharfbuzz-tizen_2.3.1.tar.gz
harfbuzz-tizen_2.3.1.tar.bz2
harfbuzz-tizen_2.3.1.zip
Diffstat (limited to 'test/api/test-blob.c')
-rw-r--r--test/api/test-blob.c62
1 files changed, 55 insertions, 7 deletions
diff --git a/test/api/test-blob.c b/test/api/test-blob.c
index 5fcb208..f671331 100644
--- a/test/api/test-blob.c
+++ b/test/api/test-blob.c
@@ -53,6 +53,9 @@ test_blob_empty (void)
g_assert (hb_blob_is_immutable (hb_blob_get_empty ()));
g_assert (hb_blob_get_empty () != NULL);
g_assert (hb_blob_get_empty () == hb_blob_create (NULL, 0, HB_MEMORY_MODE_READONLY, NULL, NULL));
+ g_assert (hb_blob_get_empty () == hb_blob_create ("asdf", 0, HB_MEMORY_MODE_READONLY, NULL, NULL));
+ g_assert (hb_blob_get_empty () == hb_blob_create (NULL, -1, HB_MEMORY_MODE_READONLY, NULL, NULL));
+ g_assert (hb_blob_get_empty () == hb_blob_create ("asdfg", -1, HB_MEMORY_MODE_READONLY, NULL, NULL));
blob = hb_blob_get_empty ();
g_assert (blob == hb_blob_get_empty ());
@@ -68,7 +71,7 @@ test_blob_empty (void)
g_assert_cmpint (len, ==, 0);
data_writable = hb_blob_get_data_writable (blob, NULL);
- g_assert (data == NULL);
+ g_assert (data_writable == NULL);
data_writable = hb_blob_get_data_writable (blob, &len);
g_assert (data_writable == NULL);
@@ -262,16 +265,61 @@ static void
test_blob_subblob (fixture_t *fixture, gconstpointer user_data)
{
hb_blob_t *b = fixture->blob;
+ hb_memory_mode_t mm = GPOINTER_TO_INT (user_data);
+ unsigned int len;
+ const char *data;
+ char *data_writable;
+ unsigned int i;
- fixture->len -= 2;
- fixture->data++;
- fixture->blob = hb_blob_create_sub_blob (b, 1, fixture->len);
+ if (mm == HB_MEMORY_MODE_DUPLICATE) {
+ g_assert_cmpint (fixture->freed, ==, 1);
+ fixture->data = (char *) hb_blob_get_data (b, NULL);
+ } else {
+ g_assert_cmpint (fixture->freed, ==, 0);
+ }
+ fixture->blob = hb_blob_create_sub_blob (b, 1, fixture->len - 2);
hb_blob_destroy (b);
+ b = fixture->blob;
+
+ /* A sub-blob is always created READONLY. */
+
+ g_assert (b);
- test_blob (fixture, user_data);
+ len = hb_blob_get_length (b);
+ g_assert_cmpint (len, ==, fixture->len - 2);
+
+ data = hb_blob_get_data (b, &len);
+ g_assert_cmpint (len, ==, fixture->len - 2);
+ g_assert (data == fixture->data + 1);
- fixture->data--;
- fixture->len += 2;
+ data_writable = hb_blob_get_data_writable (b, &len);
+ g_assert_cmpint (len, ==, fixture->len - 2);
+ g_assert (data_writable);
+ if (mm == HB_MEMORY_MODE_READONLY)
+ g_assert (0 == memcmp (data_writable, fixture->data + 1, fixture->len - 2));
+ g_assert (data_writable != data);
+ g_assert_cmpint (fixture->freed, ==, 1);
+
+ data = hb_blob_get_data (b, &len);
+ g_assert_cmpint (len, ==, fixture->len - 2);
+ g_assert (data == data_writable);
+
+ memset (data_writable, 0, fixture->len - 2);
+
+ /* Now, make it immutable and watch get_data_writable() fail */
+
+ g_assert (!hb_blob_is_immutable (b));
+ hb_blob_make_immutable (b);
+ g_assert (hb_blob_is_immutable (b));
+
+ data_writable = hb_blob_get_data_writable (b, &len);
+ g_assert (!data_writable);
+ g_assert_cmpint (len, ==, 0);
+
+ data = hb_blob_get_data (b, &len);
+ g_assert_cmpint (len, ==, fixture->len - 2);
+ for (i = 0; i < len; i++)
+ g_assert ('\0' == data[i]);
}