Instead of passing in user config and data base dirs to the Engine from the app, then pulling them out from the engine again from the app, just store them in AccountManager, since that's where they are needed. * src/client/accounts/account-manager.vala (AccountManager): Store user config and data base dirs directly rather than getting them from the engine. Split account directory creation out into a separate method so they aren't re-made every time the config is saved. * src/engine/api/geary-engine.vala (Engine): Remove user config and data dir properties and open_async args. Update call sites and unit tests. * src/client/application/geary-controller.vala (GearyController): Chase AccountManager and Engine API changes. Ensure account dirs are created when an new account is added. * src/engine/api/geary-account-information.vala (AccountInformation): Explicitly track copies rather relying on account dirs being null. Don't require dirs be set in the default ctor, since they won't be known, provide a method for updating them later on instead.
175 lines
4.9 KiB
Vala
175 lines
4.9 KiB
Vala
/*
|
|
* Copyright 2017 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.
|
|
*/
|
|
|
|
errordomain AccountProcessorTestError {
|
|
TEST;
|
|
}
|
|
|
|
public class Geary.ImapEngine.AccountProcessorTest : TestCase {
|
|
|
|
|
|
public class TestOperation : AccountOperation {
|
|
|
|
public bool throw_error = false;
|
|
public bool wait_for_cancel = false;
|
|
public bool execute_called = false;
|
|
|
|
private Nonblocking.Spinlock spinlock = new Nonblocking.Spinlock();
|
|
|
|
internal TestOperation(Geary.Account account) {
|
|
base(account);
|
|
}
|
|
|
|
public override async void execute(Cancellable cancellable)
|
|
throws Error {
|
|
print("Test op/");
|
|
this.execute_called = true;
|
|
if (this.wait_for_cancel) {
|
|
yield this.spinlock.wait_async(cancellable);
|
|
}
|
|
if (this.throw_error) {
|
|
throw new AccountProcessorTestError.TEST("Failed");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class OtherOperation : TestOperation {
|
|
|
|
internal OtherOperation(Geary.Account account) {
|
|
base(account);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private AccountProcessor? processor = null;
|
|
private Geary.Account? account = null;
|
|
private Geary.AccountInformation? info = null;
|
|
private uint succeeded;
|
|
private uint failed;
|
|
private uint completed;
|
|
|
|
|
|
public AccountProcessorTest() {
|
|
base("Geary.ImapEngine.AccountProcessorTest");
|
|
add_test("success", success);
|
|
add_test("failure", failure);
|
|
add_test("duplicate", duplicate);
|
|
add_test("stop", stop);
|
|
|
|
// XXX this has to be here instead of in set_up for some
|
|
// reason...
|
|
this.processor = new AccountProcessor("processor");
|
|
}
|
|
|
|
public override void set_up() {
|
|
this.info = new Geary.AccountInformation(
|
|
"test-info",
|
|
new MockServiceInformation(),
|
|
new MockServiceInformation()
|
|
);
|
|
this.account = new Geary.MockAccount("test-account", this.info);
|
|
|
|
this.succeeded = 0;
|
|
this.failed = 0;
|
|
this.completed = 0;
|
|
}
|
|
|
|
public void success() throws Error {
|
|
TestOperation op = setup_operation(new TestOperation(this.account));
|
|
|
|
this.processor.enqueue(op);
|
|
assert(this.processor.waiting == 1);
|
|
|
|
execute_all();
|
|
|
|
assert(op.execute_called);
|
|
assert(this.succeeded == 1);
|
|
assert(this.failed == 0);
|
|
assert(this.completed == 1);
|
|
}
|
|
|
|
public void failure() throws Error {
|
|
TestOperation op = setup_operation(new TestOperation(this.account));
|
|
op.throw_error = true;
|
|
|
|
AccountOperation? error_op = null;
|
|
Error? error = null;
|
|
this.processor.operation_error.connect((proc, op, err) => {
|
|
error_op = op;
|
|
error = err;
|
|
});
|
|
|
|
this.processor.enqueue(op);
|
|
execute_all();
|
|
|
|
assert(this.succeeded == 0);
|
|
assert(this.failed == 1);
|
|
assert(this.completed == 1);
|
|
assert(error_op == op);
|
|
assert(error is AccountProcessorTestError.TEST);
|
|
}
|
|
|
|
public void duplicate() throws Error {
|
|
TestOperation op1 = setup_operation(new TestOperation(this.account));
|
|
TestOperation op2 = setup_operation(new TestOperation(this.account));
|
|
TestOperation op3 = setup_operation(new OtherOperation(this.account));
|
|
|
|
this.processor.enqueue(op1);
|
|
this.processor.enqueue(op2);
|
|
assert(this.processor.waiting == 1);
|
|
|
|
this.processor.enqueue(op3);
|
|
assert(this.processor.waiting == 2);
|
|
}
|
|
|
|
public void stop() throws Error {
|
|
TestOperation op1 = setup_operation(new TestOperation(this.account));
|
|
op1.wait_for_cancel = true;
|
|
TestOperation op2 = setup_operation(new OtherOperation(this.account));
|
|
|
|
this.processor.enqueue(op1);
|
|
this.processor.enqueue(op2);
|
|
|
|
while (!this.processor.is_executing) {
|
|
this.main_loop.iteration(true);
|
|
}
|
|
|
|
this.processor.stop();
|
|
|
|
while (this.main_loop.pending()) {
|
|
this.main_loop.iteration(true);
|
|
}
|
|
|
|
assert(!this.processor.is_executing);
|
|
assert(this.processor.waiting == 0);
|
|
assert(this.succeeded == 0);
|
|
assert(this.failed == 1);
|
|
assert(this.completed == 1);
|
|
}
|
|
|
|
private TestOperation setup_operation(TestOperation op) {
|
|
op.succeeded.connect(() => {
|
|
this.succeeded++;
|
|
});
|
|
op.failed.connect(() => {
|
|
this.failed++;
|
|
});
|
|
op.completed.connect(() => {
|
|
this.completed++;
|
|
});
|
|
return op;
|
|
}
|
|
|
|
private void execute_all() {
|
|
while (this.processor.is_executing || this.processor.waiting > 0) {
|
|
this.main_loop.iteration(true);
|
|
}
|
|
}
|
|
}
|