[geary: 5/9] Tests for ComposedEmail.contains_inline_img_src and replace_inline_img_src



commit eaa98883a7dbc8a786df5edf0a3fab5f25096cf5
Author: Chris Heywood <15127-creywood users noreply gitlab gnome org>
Date:   Tue Nov 5 20:34:47 2019 +0100

    Tests for ComposedEmail.contains_inline_img_src and replace_inline_img_src

 test/engine/api/geary-composed-email-test.vala | 53 ++++++++++++++++++++++++++
 test/meson.build                               |  1 +
 test/test-engine.vala                          |  1 +
 3 files changed, 55 insertions(+)
---
diff --git a/test/engine/api/geary-composed-email-test.vala b/test/engine/api/geary-composed-email-test.vala
new file mode 100644
index 00000000..3001beb4
--- /dev/null
+++ b/test/engine/api/geary-composed-email-test.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-2018 Michael Gratton <mike vee net>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+class Geary.ComposedEmailTest: TestCase {
+
+    private const string IMG_CONTAINING_HTML_BODY = "<img src=\"test.png\" />";
+
+    public ComposedEmailTest() {
+        base("Geary.ComposedEmailTest");
+        add_test("contains_inline_img_src", contains_inline_img_src);
+        add_test("replace_inline_img_src", replace_inline_img_src);
+    }
+
+    public void contains_inline_img_src() throws Error {
+        ComposedEmail composed = build_composed_with_img_src();
+        assert_true(composed.contains_inline_img_src("test.png"), "Expected matched image source");
+        assert_false(composed.contains_inline_img_src("missing.png"), "Expected missing image");
+    }
+
+    public void replace_inline_img_src() throws Error {
+        ComposedEmail composed = build_composed_with_img_src();
+        assert_true(composed.replace_inline_img_src("test.png", "updated.png"), "Expected replacement 
success");
+        assert_false(composed.replace_inline_img_src("missing.png", "updated.png"), "Expected replacement 
failure");
+        assert_true(composed.contains_inline_img_src("updated.png"), "Expected new image source");
+
+        assert_true(composed.replace_inline_img_src("updated.png", "1234567.png"), "Expected replacement 
success for same length filename");
+        assert_true(composed.contains_inline_img_src("1234567.png"), "Expected new same length image 
source");
+    }
+
+    private ComposedEmail build_composed_with_img_src() {
+        RFC822.MailboxAddress to = new RFC822.MailboxAddress(
+            "Test", "test example com"
+        );
+        RFC822.MailboxAddress from = new RFC822.MailboxAddress(
+            "Sender", "sender example com"
+        );
+
+        return new Geary.ComposedEmail(
+            new GLib.DateTime.now_local(),
+            new Geary.RFC822.MailboxAddresses.single(from),
+            new Geary.RFC822.MailboxAddresses.single(to),
+            null,
+            null,
+            null,
+            null,
+            IMG_CONTAINING_HTML_BODY
+        );
+    }
+}
diff --git a/test/meson.build b/test/meson.build
index e774d7aa..95c24de8 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -27,6 +27,7 @@ geary_test_engine_sources = [
   'engine/api/geary-engine-test.vala',
   'engine/api/geary-folder-path-test.vala',
   'engine/api/geary-service-information-test.vala',
+  'engine/api/geary-composed-email-test.vala',
   'engine/app/app-conversation-test.vala',
   'engine/app/app-conversation-monitor-test.vala',
   'engine/app/app-conversation-set-test.vala',
diff --git a/test/test-engine.vala b/test/test-engine.vala
index 28e758e1..a8e262fa 100644
--- a/test/test-engine.vala
+++ b/test/test-engine.vala
@@ -76,6 +76,7 @@ int main(string[] args) {
     engine.add_suite(new Geary.RFC822.PartTest().get_suite());
     engine.add_suite(new Geary.RFC822.Utils.Test().get_suite());
     engine.add_suite(new Geary.String.Test().get_suite());
+    engine.add_suite(new Geary.ComposedEmailTest().get_suite());
 
     /*
      * Run the tests


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]