Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.
To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-14 12:10:48 +11:00
|
|
|
/*
|
|
|
|
|
* Copyright 2019 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class Geary.FolderPathTest : TestCase {
|
|
|
|
|
|
2019-01-14 13:17:06 +11:00
|
|
|
|
|
|
|
|
private FolderRoot? root = null;
|
|
|
|
|
|
|
|
|
|
|
Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.
To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-14 12:10:48 +11:00
|
|
|
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);
|
2019-01-14 13:17:06 +11:00
|
|
|
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;
|
Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.
To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-14 12:10:48 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void get_child_from_root() throws GLib.Error {
|
|
|
|
|
assert_string(
|
|
|
|
|
">test",
|
2019-01-14 13:17:06 +11:00
|
|
|
this.root.get_child("test").to_string()
|
Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.
To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-14 12:10:48 +11:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void get_child_from_child() throws GLib.Error {
|
|
|
|
|
assert_string(
|
|
|
|
|
">test1>test2",
|
2019-01-14 13:17:06 +11:00
|
|
|
this.root.get_child("test1").get_child("test2").to_string()
|
Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.
To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-14 12:10:48 +11:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void root_is_root() throws GLib.Error {
|
2019-01-14 13:17:06 +11:00
|
|
|
assert_true(this.root.is_root);
|
Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.
To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-14 12:10:48 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void child_root_is_not_root() throws GLib.Error {
|
2019-01-14 13:17:06 +11:00
|
|
|
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"
|
|
|
|
|
);
|
Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.
To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-14 12:10:48 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|