diff options
author | Milan Crha <mcrha@redhat.com> | 2021-03-08 17:35:33 +0100 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2021-03-08 17:38:21 +0100 |
commit | eae4e9b5268c841d8f9b667e7d9bb592f11ac496 (patch) | |
tree | 7f04f7c171d38d7f24d7a81e9fd0fa8f34e5d4c4 /tests | |
parent | 971f66f32bed943b48818713b870ae54ae49ddcb (diff) | |
download | evolution-data-server-eae4e9b5268c841d8f9b667e7d9bb592f11ac496.tar.gz |
I#309 - EContact: Inline locally stored image does not retain its mime type
This broke with commit 0394a3bd9cd0b0cbf3a9bc1eac70f5a4849f6df6 for the file
backend, because the EContact's e_contact_inline_local_photos() could not
decipher the original MIME type from the file extension.
Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/309
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libebook/client/test-book-client-photo-is-uri.c | 39 | ||||
-rw-r--r-- | tests/libebook/data/vcards/logo-1.vcf | 2 | ||||
-rw-r--r-- | tests/libebook/data/vcards/photo-1.vcf | 2 | ||||
-rw-r--r-- | tests/libedata-book/test-book-meta-backend.c | 6 |
4 files changed, 41 insertions, 8 deletions
diff --git a/tests/libebook/client/test-book-client-photo-is-uri.c b/tests/libebook/client/test-book-client-photo-is-uri.c index 077e15cd0..0fb7a4fd6 100644 --- a/tests/libebook/client/test-book-client-photo-is-uri.c +++ b/tests/libebook/client/test-book-client-photo-is-uri.c @@ -65,6 +65,8 @@ print_contact (EContact *contact) g_assert (photo != NULL); g_assert (photo->type == E_CONTACT_PHOTO_TYPE_URI); g_print ("Test passed with photo uri: %s\n", photo->data.uri); + + e_contact_photo_free (photo); } static void @@ -139,6 +141,9 @@ give_james_brown_micheal_jacksons_face (EBookClient *book) if (!e_book_client_modify_contact_sync (book, james, E_BOOK_OPERATION_FLAG_NONE, NULL, &error)) g_error ("Failed to modify contact with cross referenced photo: %s", error->message); + + g_object_unref (micheal); + g_object_unref (james); } static void @@ -160,7 +165,7 @@ update_contact_inline (EBookClient *book, photo = e_contact_photo_new (); photo->type = E_CONTACT_PHOTO_TYPE_INLINED; - photo->data.inlined.mime_type = NULL; + photo->data.inlined.mime_type = g_strdup ("image/png"); photo->data.inlined.data = data; photo->data.inlined.length = length; @@ -171,6 +176,8 @@ update_contact_inline (EBookClient *book, if (!e_book_client_modify_contact_sync (book, contact, E_BOOK_OPERATION_FLAG_NONE, NULL, &error)) g_error ("Failed to modify contact with inline photo data: %s", error->message); + + g_object_unref (contact); } /* This assertion is made a couple of times in the view-complete @@ -180,13 +187,14 @@ static void assert_uri_exists (EBookClient *book, const gchar *uid) { - EContact *contact; + EContact *contact; EContactPhoto *photo; - const gchar *filename; - GError *error = NULL; + gchar *filename; + gboolean success; + GError *error = NULL; if (!e_book_client_get_contact_sync (book, uid, &contact, NULL, &error)) - g_error ("Unable to get contact: %s", error->message); + g_error ("Unable to get contact: %s", error->message); g_assert (contact); @@ -199,6 +207,21 @@ assert_uri_exists (EBookClient *book, /* The file should absolutely exist at this point */ g_assert (g_file_test (filename, G_FILE_TEST_EXISTS)); + + e_contact_photo_free (photo); + + success = e_contact_inline_local_photos (contact, &error); + g_assert_no_error (error); + g_assert (success); + + photo = e_contact_get (contact, E_CONTACT_PHOTO); + g_assert (photo); + g_assert (photo->type == E_CONTACT_PHOTO_TYPE_INLINED); + g_assert_cmpstr (e_contact_photo_get_mime_type (photo), ==, "image/png"); + + e_contact_photo_free (photo); + g_object_unref (contact); + g_free (filename); } static void @@ -284,7 +307,7 @@ add_contact_inline (EBookClient *book) photo = e_contact_photo_new (); photo->type = E_CONTACT_PHOTO_TYPE_INLINED; - photo->data.inlined.mime_type = NULL; + photo->data.inlined.mime_type = g_strdup ("image/png"); photo->data.inlined.data = data; photo->data.inlined.length = length; @@ -298,6 +321,8 @@ add_contact_inline (EBookClient *book) g_error ("Failed to add contact"); micheal_jackson_uid = e_contact_get (contact, E_CONTACT_UID); + + g_object_unref (contact); } static void @@ -322,6 +347,8 @@ add_contact_uri (EBookClient *book) g_error ("Failed to add contact"); james_brown_uid = e_contact_get (contact, E_CONTACT_UID); + + g_object_unref (contact); } static void diff --git a/tests/libebook/data/vcards/logo-1.vcf b/tests/libebook/data/vcards/logo-1.vcf index ad1de8c66..b6cd77277 100644 --- a/tests/libebook/data/vcards/logo-1.vcf +++ b/tests/libebook/data/vcards/logo-1.vcf @@ -3,7 +3,7 @@ VERSION:3.0 UID:logo-1 FN:logo N:;logo;;; -LOGO;TYPE="X-EVOLUTION-UNKNOWN";ENCODING=b:/9j/4AAQSkZJRgABAQEASABIAAD/2wB +LOGO;TYPE="PNG";ENCODING=b:/9j/4AAQSkZJRgABAQEASABIAAD/2wB DABYPEBMQDhYTEhMYFxYaIDYjIB4eIEIvMic2TkVSUU1FTEpWYXxpVlx1XUpMbJNtdYCEi4yLV GiZo5eHonyIi4b/2wBDARcYGCAcID8jIz+GWUxZhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoa GhoaGhoaGhoaGhoaGhoaGhoaGhoaGhob/wgARCABAAEADAREAAhEBAxEB/8QAFgABAQEAAAAAA diff --git a/tests/libebook/data/vcards/photo-1.vcf b/tests/libebook/data/vcards/photo-1.vcf index 4bf5bcec3..d32816503 100644 --- a/tests/libebook/data/vcards/photo-1.vcf +++ b/tests/libebook/data/vcards/photo-1.vcf @@ -3,7 +3,7 @@ VERSION:3.0 UID:photo-1 FN:photo N:;photo;;; -PHOTO;TYPE="X-EVOLUTION-UNKNOWN";ENCODING=b:iVBORw0KGgoAAAANSUhEUgAAAEAAAAB +PHOTO;TYPE="jpeg";ENCODING=b:iVBORw0KGgoAAAANSUhEUgAAAEAAAAB ACAIAAAAlC+aJAAAKo0lEQVRo3n1aW7LcuA4j6OzkLujufxOzgu5gPsQHIHdNqpKc03bbEh8gC Ar//98/D74Pvonvk98nvw++mZ8Hf5/8PPk38XnwffLz4Jv5/ZN+Jz5P/n3wOR/q1cSnn/b9U8/ /PPlNfP9gb8j8ngU8+X3wyX7yfPd8+Of83DdnnlV9E0QQgQBi/oD9ExlxLiACCJCBiGAE++Pg+ diff --git a/tests/libedata-book/test-book-meta-backend.c b/tests/libedata-book/test-book-meta-backend.c index aae2e654c..b3fdddd6e 100644 --- a/tests/libedata-book/test-book-meta-backend.c +++ b/tests/libedata-book/test-book-meta-backend.c @@ -697,6 +697,7 @@ test_one_photo (EBookMetaBackend *meta_backend, gchar *new_content = NULL; gsize orig_len = 0, new_len = 0; gchar *filename; + gchar *mime_type; gboolean success; GError *error = NULL; @@ -715,6 +716,9 @@ test_one_photo (EBookMetaBackend *meta_backend, g_assert_nonnull (orig_content); g_assert_cmpint (orig_len, >, 0); + mime_type = g_strdup (e_contact_photo_get_mime_type (photo)); + g_assert_nonnull (mime_type); + orig_content = g_memdup (orig_content, (guint) orig_len); e_contact_photo_free (photo); @@ -754,9 +758,11 @@ test_one_photo (EBookMetaBackend *meta_backend, new_content = (gchar *) e_contact_photo_get_inlined (photo, &new_len); g_assert_nonnull (new_content); g_assert_cmpmem (orig_content, orig_len, new_content, new_len); + g_assert_cmpstr (mime_type, ==, e_contact_photo_get_mime_type (photo)); e_contact_photo_free (photo); g_free (orig_content); + g_free (mime_type); /* Also try with remote URI, which should be left as is */ photo = e_contact_photo_new (); |