2018-07-20 13:35:26 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright 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.Imap.MailboxSpecifierTest : TestCase {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MailboxSpecifierTest() {
|
|
|
|
|
base("Geary.Imap.MailboxSpecifierTest");
|
|
|
|
|
add_test("to_parameter", to_parameter);
|
|
|
|
|
add_test("from_parameter", from_parameter);
|
2018-09-25 23:33:12 +10:00
|
|
|
add_test("from_folder_path", from_folder_path);
|
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
|
|
|
add_test("folder_path_is_inbox", folder_path_is_inbox);
|
2018-07-20 13:35:26 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void to_parameter() throws Error {
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
|
|
|
|
new MailboxSpecifier("test").to_parameter().to_string(),
|
|
|
|
|
"test"
|
2018-07-20 13:35:26 +10:00
|
|
|
);
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
|
|
|
|
new MailboxSpecifier("foo/bar").to_parameter().to_string(),
|
|
|
|
|
"foo/bar"
|
2018-07-20 13:35:26 +10:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// The param won't be quoted or escaped since
|
|
|
|
|
// QuotedStringParameter doesn't actually handle that, so just
|
|
|
|
|
// check that it is correct type
|
|
|
|
|
Parameter quoted = new MailboxSpecifier("""foo\bar""").to_parameter();
|
|
|
|
|
assert_true(quoted is QuotedStringParameter, "Backslash was not quoted");
|
|
|
|
|
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
|
|
|
|
new MailboxSpecifier("olé").to_parameter().to_string(),
|
|
|
|
|
"ol&AOk-"
|
2018-07-20 13:35:26 +10:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void from_parameter() throws Error {
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
2018-07-20 13:35:26 +10:00
|
|
|
new MailboxSpecifier.from_parameter(
|
2020-05-09 16:04:22 +10:00
|
|
|
new UnquotedStringParameter("test")
|
|
|
|
|
).name,
|
|
|
|
|
"test"
|
2018-07-20 13:35:26 +10:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// This won't be quoted or escaped since QuotedStringParameter
|
|
|
|
|
// doesn't actually handle that.
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
2018-07-20 13:35:26 +10:00
|
|
|
new MailboxSpecifier.from_parameter(
|
2020-05-09 16:04:22 +10:00
|
|
|
new QuotedStringParameter("""foo\bar""")
|
|
|
|
|
).name,
|
|
|
|
|
"foo\\bar"
|
2018-07-20 13:35:26 +10:00
|
|
|
);
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
2018-07-20 13:35:26 +10:00
|
|
|
new MailboxSpecifier.from_parameter(
|
2020-05-09 16:04:22 +10:00
|
|
|
new UnquotedStringParameter("ol&AOk-")
|
|
|
|
|
).name,
|
|
|
|
|
"olé"
|
2018-07-20 13:35:26 +10:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 23:33:12 +10:00
|
|
|
public void from_folder_path() throws Error {
|
2019-04-14 20:55:42 +10:00
|
|
|
FolderRoot root = new FolderRoot("#test");
|
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
|
|
|
MailboxSpecifier inbox = new MailboxSpecifier("Inbox");
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
2018-09-25 23:33:12 +10:00
|
|
|
new MailboxSpecifier.from_folder_path(
|
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
|
|
|
root.get_child("Foo"), inbox, "$"
|
2020-05-09 16:04:22 +10:00
|
|
|
).name,
|
|
|
|
|
"Foo"
|
2018-09-25 23:33:12 +10:00
|
|
|
);
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
2018-09-25 23:33:12 +10:00
|
|
|
new MailboxSpecifier.from_folder_path(
|
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
|
|
|
root.get_child("Foo").get_child("Bar"), inbox, "$"
|
2020-05-09 16:04:22 +10:00
|
|
|
).name,
|
|
|
|
|
"Foo$Bar"
|
2018-09-25 23:33:12 +10:00
|
|
|
);
|
2020-05-09 16:04:22 +10:00
|
|
|
assert_equal(
|
2018-09-25 23:33:12 +10:00
|
|
|
new MailboxSpecifier.from_folder_path(
|
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
|
|
|
root.get_child(MailboxSpecifier.CANONICAL_INBOX_NAME),
|
|
|
|
|
inbox,
|
2018-09-25 23:33:12 +10:00
|
|
|
"$"
|
2020-05-09 16:04:22 +10:00
|
|
|
).name,
|
|
|
|
|
"Inbox"
|
2018-09-25 23:33:12 +10:00
|
|
|
);
|
|
|
|
|
|
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
|
|
|
try {
|
2018-09-25 23:33:12 +10:00
|
|
|
new MailboxSpecifier.from_folder_path(
|
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
|
|
|
root.get_child(""), inbox, "$"
|
|
|
|
|
);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
} catch (GLib.Error err) {
|
|
|
|
|
// all good
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2018-09-25 23:33:12 +10:00
|
|
|
new MailboxSpecifier.from_folder_path(
|
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
|
|
|
root.get_child("test").get_child(""), inbox, "$"
|
|
|
|
|
);
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
} catch (GLib.Error err) {
|
|
|
|
|
// all good
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
new MailboxSpecifier.from_folder_path(root, inbox, "$");
|
|
|
|
|
assert_not_reached();
|
|
|
|
|
} catch (GLib.Error err) {
|
|
|
|
|
// all good
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void folder_path_is_inbox() throws GLib.Error {
|
2019-04-14 20:55:42 +10:00
|
|
|
FolderRoot root = new FolderRoot("#test");
|
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
|
|
|
assert_true(
|
|
|
|
|
MailboxSpecifier.folder_path_is_inbox(root.get_child("Inbox"))
|
2018-09-25 23:33:12 +10:00
|
|
|
);
|
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
|
|
|
assert_true(
|
|
|
|
|
MailboxSpecifier.folder_path_is_inbox(root.get_child("inbox"))
|
|
|
|
|
);
|
|
|
|
|
assert_true(
|
|
|
|
|
MailboxSpecifier.folder_path_is_inbox(root.get_child("INBOX"))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert_false(
|
|
|
|
|
MailboxSpecifier.folder_path_is_inbox(root)
|
|
|
|
|
);
|
|
|
|
|
assert_false(
|
|
|
|
|
MailboxSpecifier.folder_path_is_inbox(root.get_child("blah"))
|
|
|
|
|
);
|
|
|
|
|
assert_false(
|
|
|
|
|
MailboxSpecifier.folder_path_is_inbox(
|
|
|
|
|
root.get_child("blah").get_child("Inbox")
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
assert_false(
|
|
|
|
|
MailboxSpecifier.folder_path_is_inbox(
|
|
|
|
|
root.get_child("Inbox").get_child("Inbox")
|
|
|
|
|
)
|
2018-09-25 23:33:12 +10:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-20 13:35:26 +10:00
|
|
|
}
|