[geary/wip/181-special-folder-dupes: 2/3] Add additional FolderPath unit tests



commit 308cb4c1e4f0a712e1bca4bd81f41b47d3821eeb
Author: Michael Gratton <mike vee net>
Date:   Mon Jan 14 13:17:06 2019 +1100

    Add additional FolderPath unit tests

 test/engine/api/geary-folder-path-test.vala | 175 +++++++++++++++++++++++++++-
 1 file changed, 170 insertions(+), 5 deletions(-)
---
diff --git a/test/engine/api/geary-folder-path-test.vala b/test/engine/api/geary-folder-path-test.vala
index 9cce3dbd..5d3ef675 100644
--- a/test/engine/api/geary-folder-path-test.vala
+++ b/test/engine/api/geary-folder-path-test.vala
@@ -7,35 +7,200 @@
 
 public class Geary.FolderPathTest : TestCase {
 
+
+    private FolderRoot? root = null;
+
+
     public FolderPathTest() {
         base("Geary.FolderPathTest");
         add_test("get_child_from_root", get_child_from_root);
         add_test("get_child_from_child", get_child_from_child);
         add_test("root_is_root", root_is_root);
         add_test("child_is_not_root", root_is_root);
+        add_test("as_list", as_list);
+        add_test("is_top_level", is_top_level);
+        add_test("path_parent", path_parent);
+        add_test("path_equal", path_equal);
+        add_test("path_compare", path_compare);
+        add_test("path_compare_normalised", path_compare_normalised);
+    }
+
+    public override void set_up() {
+        this.root = new FolderRoot(false);
+    }
+
+    public override void tear_down() {
+        this.root = null;
     }
 
     public void get_child_from_root() throws GLib.Error {
         assert_string(
             ">test",
-            new Geary.FolderRoot(false).get_child("test").to_string()
+            this.root.get_child("test").to_string()
         );
     }
 
     public void get_child_from_child() throws GLib.Error {
         assert_string(
             ">test1>test2",
-            new Geary.FolderRoot(false)
-            .get_child("test1").get_child("test2").to_string()
+            this.root.get_child("test1").get_child("test2").to_string()
         );
     }
 
     public void root_is_root() throws GLib.Error {
-        assert_true(new Geary.FolderRoot(false).is_root);
+        assert_true(this.root.is_root);
     }
 
     public void child_root_is_not_root() throws GLib.Error {
-        assert_false(new Geary.FolderRoot(false).get_child("test").is_root);
+        assert_false(this.root.get_child("test").is_root);
+    }
+
+    public void as_list() throws GLib.Error {
+        assert_true(this.root.as_list().size == 1, "Root list");
+        assert_int(
+            2,
+            this.root.get_child("test").as_list().size,
+            "Child list size"
+        );
+        assert_string(
+            "test",
+            this.root.get_child("test").as_list()[1],
+            "Child list contents"
+        );
+    }
+
+    public void is_top_level() throws GLib.Error {
+        assert_false(this.root.is_top_level, "Root is top_level");
+        assert_true(
+            this.root.get_child("test").is_top_level,
+            "Top level is top_level"
+        );
+        assert_false(
+            this.root.get_child("test").get_child("test").is_top_level,
+            "Descendent is top_level"
+        );
+    }
+
+    public void path_parent() throws GLib.Error {
+        assert_null(this.root.get_parent(), "Root parent");
+        assert_string(
+            "",
+            this.root.get_child("test").get_parent().basename,
+            "Root child parent");
+        assert_string(
+            "test1",
+            this.root.get_child("test1").get_child("test2").get_parent().basename,
+            "Child parent");
+    }
+
+    public void path_equal() throws GLib.Error {
+        assert_true(this.root.equal_to(this.root), "Root equality");
+        assert_true(
+            this.root.get_child("test").equal_to(this.root.get_child("test")),
+            "Child equality"
+        );
+        assert_false(
+            this.root.get_child("test1").equal_to(this.root.get_child("test2")),
+            "Child names"
+        );
+        assert_false(
+            this.root.get_child("test1").get_child("test")
+            .equal_to(this.root.get_child("test2").get_child("test")),
+            "Disjoint parents"
+        );
+    }
+
+    public void path_compare() throws GLib.Error {
+        assert_int(0, this.root.compare_to(this.root), "Root equality");
+        assert_int(0,
+            this.root.get_child("test").compare_to(this.root.get_child("test")),
+            "Equal child comparison"
+        );
+
+        assert_int(
+            -1,
+            this.root.get_child("test1").compare_to(this.root.get_child("test2")),
+            "Greater than child comparison"
+        );
+        assert_int(
+            1,
+            this.root.get_child("test2").compare_to(this.root.get_child("test1")),
+            "Less than child comparison"
+        );
+
+        assert_int(
+            -1,
+            this.root.get_child("test1").get_child("test")
+            .compare_to(this.root.get_child("test2").get_child("test")),
+            "Greater than disjoint parents"
+        );
+        assert_int(
+            1,
+            this.root.get_child("test2").get_child("test")
+            .compare_to(this.root.get_child("test1").get_child("test")),
+            "Less than disjoint parents"
+        );
+
+        assert_int(
+            1,
+            this.root.get_child("test1").get_child("test")
+            .compare_to(this.root.get_child("test1")),
+            "Greater than descendant"
+        );
+        assert_int(
+            -1,
+            this.root.get_child("test1")
+            .compare_to(this.root.get_child("test1").get_child("test")),
+            "Less than descendant"
+        );
+    }
+
+    public void path_compare_normalised() throws GLib.Error {
+        assert_int(0, this.root.compare_normalized_ci(this.root), "Root equality");
+        assert_int(0,
+            this.root.get_child("test")
+            .compare_normalized_ci(this.root.get_child("test")),
+            "Equal child comparison"
+        );
+
+        assert_int(
+            -1,
+            this.root.get_child("test1")
+            .compare_normalized_ci(this.root.get_child("test2")),
+            "Greater than child comparison"
+        );
+        assert_int(
+            1,
+            this.root.get_child("test2")
+            .compare_normalized_ci(this.root.get_child("test1")),
+            "Less than child comparison"
+        );
+
+        assert_int(
+            -1,
+            this.root.get_child("test1").get_child("test")
+            .compare_normalized_ci(this.root.get_child("test2").get_child("test")),
+            "Greater than disjoint parents"
+        );
+        assert_int(
+            1,
+            this.root.get_child("test2").get_child("test")
+            .compare_normalized_ci(this.root.get_child("test1").get_child("test")),
+            "Less than disjoint parents"
+        );
+
+        assert_int(
+            1,
+            this.root.get_child("test1").get_child("test")
+            .compare_normalized_ci(this.root.get_child("test1")),
+            "Greater than descendant"
+        );
+        assert_int(
+            -1,
+            this.root.get_child("test1")
+            .compare_normalized_ci(this.root.get_child("test1").get_child("test")),
+            "Less than descendant"
+        );
     }
 
 }


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