Set the path on the image for purple_image_new_from_file, update/add some tests

Thu, 08 Jun 2017 22:51:50 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 08 Jun 2017 22:51:50 -0500
changeset 38568
9463c7db20fa
parent 38567
277d8f0ec6f8
child 38569
e9f92dd1f2f4

Set the path on the image for purple_image_new_from_file, update/add some tests

libpurple/image.c file | annotate | diff | comparison | revisions
libpurple/tests/test_image.c file | annotate | diff | comparison | revisions
--- a/libpurple/image.c	Mon Jun 05 20:51:11 2017 -0500
+++ b/libpurple/image.c	Thu Jun 08 22:51:50 2017 -0500
@@ -197,7 +197,12 @@
 
 	bytes = g_bytes_new_take(contents, length);
 
-	image = purple_image_new_from_bytes(bytes);
+	image = g_object_new(
+		PURPLE_TYPE_IMAGE,
+		"contents", bytes,
+		"path", path,
+		NULL
+	);
 
 	g_bytes_unref(bytes);
 
--- a/libpurple/tests/test_image.c	Mon Jun 05 20:51:11 2017 -0500
+++ b/libpurple/tests/test_image.c	Thu Jun 08 22:51:50 2017 -0500
@@ -57,6 +57,7 @@
 _test_image(PurpleImage *image,
             const guint8 *edata,
             gsize elen,
+            const gchar *path,
             const gchar *ext,
             const gchar *mimetype)
 {
@@ -71,12 +72,42 @@
 	g_assert_cmpmem(adata, alen, edata, elen);
 	g_bytes_unref(bytes);
 
+	/* if the caller provided a path, check it, otherwise just make sure we
+	 * have something.
+	 */
+	if(path != NULL) {
+		g_assert_cmpstr(purple_image_get_path(image), ==, path);
+	} else {
+		g_assert_cmpstr(purple_image_get_path(image), !=, "");
+	}
+
 	g_assert_cmpstr(purple_image_get_extension(image), ==, ext);
 	g_assert_cmpstr(purple_image_get_mimetype(image), ==, mimetype);
 
 	g_object_unref(G_OBJECT(image));
 }
 
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+test_image_new_from_bytes(void) {
+	GBytes *bytes = g_bytes_new(test_image_data, test_image_data_len);
+	PurpleImage *image = purple_image_new_from_bytes(bytes);
+
+	_test_image(
+		image,
+		g_bytes_get_data(bytes, NULL),
+		g_bytes_get_size(bytes),
+		NULL,
+		"png",
+		"image/png"
+	);
+
+	g_bytes_unref(bytes);
+}
+
+
 static void
 test_image_new_from_data(void) {
 	PurpleImage *image = purple_image_new_from_data(
@@ -88,6 +119,7 @@
 		image,
 		test_image_data,
 		test_image_data_len,
+		NULL,
 		"png",
 		"image/png"
 	);
@@ -106,16 +138,18 @@
 	g_assert_no_error(error);
 
 	g_file_get_contents(path, &edata, &elen, &error);
-	g_free(path);
 	g_assert_no_error(error);
 
 	_test_image(
 		image,
 		(guint8 *)edata,
 		elen,
+		path,
 		"png",
 		"image/png"
 	);
+
+	g_free(path);
 }
 
 /******************************************************************************
@@ -125,6 +159,7 @@
 main(gint argc, gchar **argv) {
 	g_test_init(&argc, &argv, NULL);
 
+	g_test_add_func("/image/new-from-bytes", test_image_new_from_bytes);
 	g_test_add_func("/image/new-from-data", test_image_new_from_data);
 	g_test_add_func("/image/new-from-file", test_image_new_from_file);
 

mercurial