Since both submitting a command no longer requires a cancellable, and it is desirable to avoid sending a queued command that has already been cancelled beforehand, add a new `Command.should_send` Cancellable property to specify if a command should (still) be sent or not, and stop passing a cancellable to ClientSession when submitting commands. Allow call sites to pass in existing cancellable objects, and thus also add it it as a ctor property to the Command class and all subclasses. Lastly, throw a cancelled exception in `wait_until_complete` if send was cancelled so that the caller knows what happened. Remove redundant cancellable argument from `Imap.Client.command_transaction_async` and rename it to `submit_command` to make it more obvious about what it does.
110 lines
3.6 KiB
Vala
110 lines
3.6 KiB
Vala
/*
|
|
* 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.FetchCommandTest : TestCase {
|
|
|
|
|
|
private MessageSet? msg_set = null;
|
|
|
|
|
|
public FetchCommandTest() {
|
|
base("Geary.Imap.FetchCommandTest");
|
|
add_test("list_ctor_single_data_item", list_ctor_single_data_item);
|
|
add_test("list_ctor_single_body_item", list_ctor_single_body_item);
|
|
add_test("list_ctor_multiple_data_item", list_ctor_multiple_data_item);
|
|
add_test("list_ctor_multiple_body_item", list_ctor_multiple_body_item);
|
|
add_test("list_ctor_both", list_ctor_both);
|
|
}
|
|
|
|
public override void set_up() {
|
|
this.msg_set = new MessageSet(new SequenceNumber(1));
|
|
}
|
|
|
|
public void list_ctor_single_data_item() throws GLib.Error {
|
|
Gee.List<FetchDataSpecifier> data_items =
|
|
new Gee.LinkedList<FetchDataSpecifier>();
|
|
data_items.add(FetchDataSpecifier.UID);
|
|
|
|
assert_equal(
|
|
new FetchCommand(this.msg_set, data_items, null, null).to_string(),
|
|
"---- fetch 1 uid"
|
|
);
|
|
}
|
|
|
|
public void list_ctor_single_body_item() throws GLib.Error {
|
|
Gee.List<FetchBodyDataSpecifier?> body_items =
|
|
new Gee.LinkedList<FetchBodyDataSpecifier>();
|
|
body_items.add(
|
|
new FetchBodyDataSpecifier(
|
|
FetchBodyDataSpecifier.SectionPart.TEXT, null, -1, -1, null
|
|
)
|
|
);
|
|
|
|
assert_equal(
|
|
new FetchCommand(this.msg_set, null, body_items, null).to_string(),
|
|
"---- fetch 1 body[text]"
|
|
);
|
|
}
|
|
|
|
public void list_ctor_multiple_data_item() throws GLib.Error {
|
|
Gee.List<FetchDataSpecifier> data_items =
|
|
new Gee.LinkedList<FetchDataSpecifier>();
|
|
data_items.add(FetchDataSpecifier.UID);
|
|
data_items.add(FetchDataSpecifier.BODY);
|
|
|
|
assert_equal(
|
|
new FetchCommand(this.msg_set, data_items, null, null).to_string(),
|
|
"---- fetch 1 (uid body)"
|
|
);
|
|
}
|
|
|
|
public void list_ctor_multiple_body_item() throws GLib.Error {
|
|
Gee.List<FetchBodyDataSpecifier?> body_items =
|
|
new Gee.LinkedList<FetchBodyDataSpecifier>();
|
|
body_items.add(
|
|
new FetchBodyDataSpecifier(
|
|
FetchBodyDataSpecifier.SectionPart.HEADER, null, -1, -1, null
|
|
)
|
|
);
|
|
body_items.add(
|
|
new FetchBodyDataSpecifier(
|
|
FetchBodyDataSpecifier.SectionPart.TEXT, null, -1, -1, null
|
|
)
|
|
);
|
|
|
|
assert_equal(
|
|
new FetchCommand(this.msg_set, null, body_items, null).to_string(),
|
|
"---- fetch 1 (body[header] body[text])"
|
|
);
|
|
}
|
|
|
|
public void list_ctor_both() throws GLib.Error {
|
|
Gee.List<FetchDataSpecifier> data_items =
|
|
new Gee.LinkedList<FetchDataSpecifier>();
|
|
data_items.add(FetchDataSpecifier.UID);
|
|
data_items.add(FetchDataSpecifier.FLAGS);
|
|
|
|
Gee.List<FetchBodyDataSpecifier?> body_items =
|
|
new Gee.LinkedList<FetchBodyDataSpecifier>();
|
|
body_items.add(
|
|
new FetchBodyDataSpecifier(
|
|
FetchBodyDataSpecifier.SectionPart.HEADER, null, -1, -1, null
|
|
)
|
|
);
|
|
body_items.add(
|
|
new FetchBodyDataSpecifier(
|
|
FetchBodyDataSpecifier.SectionPart.TEXT, null, -1, -1, null
|
|
)
|
|
);
|
|
|
|
assert_equal(
|
|
new FetchCommand(this.msg_set, data_items, body_items, null).to_string(),
|
|
"---- fetch 1 (uid flags body[header] body[text])"
|
|
);
|
|
}
|
|
|
|
}
|