{
const gchar *data;
GBytes *bytes;
+ gsize size;
data = "test";
bytes = g_bytes_new (data, 4);
g_assert (bytes != NULL);
- g_assert (g_bytes_get_data (bytes) != data);
+ g_assert (g_bytes_get_data (bytes, &size) != data);
+ g_assert_cmpuint (size, ==, 4);
g_assert_cmpuint (g_bytes_get_size (bytes), ==, 4);
- g_assert (memcmp (data, g_bytes_get_data (bytes), g_bytes_get_size (bytes)) == 0);
+ g_assert (memcmp (data, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes)) == 0);
g_bytes_unref (bytes);
}
{
gchar *data;
GBytes *bytes;
+ gsize size;
data = g_strdup ("test");
bytes = g_bytes_new_take (data, 4);
g_assert (bytes != NULL);
- g_assert (g_bytes_get_data (bytes) == data);
+ g_assert (g_bytes_get_data (bytes, &size) == data);
+ g_assert_cmpuint (size, ==, 4);
g_assert_cmpuint (g_bytes_get_size (bytes), ==, 4);
g_bytes_unref (bytes);
{
const gchar *data;
GBytes *bytes;
+ gsize size;
data = "test";
bytes = g_bytes_new_static (data, 4);
g_assert (bytes != NULL);
- g_assert (g_bytes_get_data (bytes) == data);
+ g_assert (g_bytes_get_data (bytes, &size) == data);
+ g_assert_cmpuint (size, ==, 4);
g_assert_cmpuint (g_bytes_get_size (bytes), ==, 4);
g_bytes_unref (bytes);
sub = g_bytes_new_from_bytes (bytes, 10, 4);
g_assert (sub != NULL);
- g_assert (g_bytes_get_data (sub) == ((gchar *)g_bytes_get_data (bytes)) + 10);
+ g_assert (g_bytes_get_data (sub, NULL) == ((gchar *)g_bytes_get_data (bytes, NULL)) + 10);
g_assert (g_bytes_get_size (sub) == 4);
g_bytes_unref (bytes);
- g_assert (memcmp (g_bytes_get_data (sub), "wave", 4) == 0);
+ g_assert (memcmp (g_bytes_get_data (sub, NULL), "wave", 4) == 0);
g_bytes_unref (sub);
}
GBytes *bytes;
gchar *data;
gint count = 0;
+ gsize size;
data = "test";
bytes = g_bytes_new_with_free_func (data, 4, on_destroy_increment, &count);
g_assert (bytes != NULL);
g_assert_cmpint (count, ==, 0);
- g_assert (g_bytes_get_data (bytes) == data);
+ g_assert (g_bytes_get_data (bytes, &size) == data);
+ g_assert_cmpuint (size, ==, 4);
g_assert_cmpuint (g_bytes_get_size (bytes), ==, 4);
g_bytes_unref (bytes);
/* Memory transferred: one reference, and allocated with g_malloc */
bytes = g_bytes_new (NYAN, N_NYAN);
- memory = g_bytes_get_data (bytes);
+ memory = g_bytes_get_data (bytes, NULL);
data = g_bytes_unref_to_data (bytes, &size);
g_assert (data == memory);
g_assert_cmpuint (size, ==, N_NYAN);
/* Memory copied: two references */
bytes = g_bytes_new (NYAN, N_NYAN);
bytes = g_bytes_ref (bytes);
- memory = g_bytes_get_data (bytes);
+ memory = g_bytes_get_data (bytes, NULL);
data = g_bytes_unref_to_data (bytes, &size);
g_assert (data != memory);
g_assert_cmpuint (size, ==, N_NYAN);
g_assert (memcmp (data, NYAN, N_NYAN) == 0);
g_free (data);
- g_assert (g_bytes_get_data (bytes) == memory);
+ g_assert (g_bytes_get_data (bytes, &size) == memory);
+ g_assert_cmpuint (size, ==, N_NYAN);
g_assert_cmpuint (g_bytes_get_size (bytes), ==, N_NYAN);
g_bytes_unref (bytes);
}
/* Memory copied: non malloc memory */
bytes = g_bytes_new_static (NYAN, N_NYAN);
- g_assert (g_bytes_get_data (bytes) == NYAN);
+ g_assert (g_bytes_get_data (bytes, NULL) == NYAN);
data = g_bytes_unref_to_data (bytes, &size);
g_assert (data != (gpointer)NYAN);
g_assert_cmpuint (size, ==, N_NYAN);
/* Memory transferred: one reference, and allocated with g_malloc */
bytes = g_bytes_new (NYAN, N_NYAN);
- memory = g_bytes_get_data (bytes);
+ memory = g_bytes_get_data (bytes, NULL);
array = g_bytes_unref_to_array (bytes);
g_assert (array != NULL);
g_assert (array->data == memory);
gconstpointer memory;
GByteArray *array;
GBytes *bytes;
+ gsize size;
/* Memory copied: two references */
bytes = g_bytes_new (NYAN, N_NYAN);
bytes = g_bytes_ref (bytes);
- memory = g_bytes_get_data (bytes);
+ memory = g_bytes_get_data (bytes, NULL);
array = g_bytes_unref_to_array (bytes);
g_assert (array != NULL);
g_assert (array->data != memory);
g_assert_cmpuint (array->len, ==, N_NYAN);
g_assert (memcmp (array->data, NYAN, N_NYAN) == 0);
g_byte_array_unref (array);
- g_assert (g_bytes_get_data (bytes) == memory);
+ g_assert (g_bytes_get_data (bytes, &size) == memory);
+ g_assert_cmpuint (size, ==, N_NYAN);
g_assert_cmpuint (g_bytes_get_size (bytes), ==, N_NYAN);
g_bytes_unref (bytes);
}
/* Memory copied: non malloc memory */
bytes = g_bytes_new_static (NYAN, N_NYAN);
- g_assert (g_bytes_get_data (bytes) == NYAN);
+ g_assert (g_bytes_get_data (bytes, NULL) == NYAN);
array = g_bytes_unref_to_array (bytes);
g_assert (array != NULL);
g_assert (array->data != (gpointer)NYAN);