`GLib.TestSuite` is a special type of object, as it doesn't actually
have an associated copy function or a reference/unreference function.
In practice, that actually means there's no way to actually have 2
strong references to such an object, or to copy it somehow. Due to the
way GObject properties in Vala work, that means you can't really use
them either.
Ever since vala commit 5f0a146f65, this got reflected properly in the
internally maintained GLib VAPI (as people were experiencing double
frees otherwise), but it was added only conditionally for GLib 2.70 or
later. In practice, that means you only get vala compiler issues if you
(impliclty) set `--target-glib=2.70` (or a later version).
To fix this for vala-unit and our own Geary tests, this commit changes
the `ValaUnit.TestCase` class to only allow "stealing" the strong
reference to the `GLib.TestSuite`, rather than somehowing allowing
people to hold a weak reference, and by also making it a protected field
rather than a property.
Since this changes the API of ValaUnit, we also bump the version. In
general though, I hope people aren't using ValaUnit externally, since
these types of API/ABI breaks can happen with Vala libraries.
Link: 5f0a146f65
114 lines
2.7 KiB
Vala
114 lines
2.7 KiB
Vala
/*
|
|
* 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.
|
|
*/
|
|
|
|
|
|
// 5s is too short for some SMTP servers
|
|
private const int TIMEOUT = 10;
|
|
|
|
|
|
public struct Integration.Configuration {
|
|
|
|
Geary.Protocol type;
|
|
Geary.ServiceProvider provider;
|
|
Geary.ServiceInformation service;
|
|
Geary.Endpoint target;
|
|
Geary.Credentials credentials;
|
|
|
|
}
|
|
|
|
|
|
int main(string[] args) {
|
|
/*
|
|
* Initialise all the things.
|
|
*/
|
|
|
|
// Ensure things like e.g. GLib's formatting routines uses a
|
|
// UTF-8-based locale rather ASCII
|
|
GLib.Intl.setlocale(LocaleCategory.ALL, "C.UTF-8");
|
|
|
|
Test.init(ref args);
|
|
|
|
Geary.RFC822.init();
|
|
Geary.HTML.init();
|
|
Geary.Logging.init();
|
|
Geary.Logging.log_to(stderr);
|
|
GLib.Log.set_writer_func(Geary.Logging.default_log_writer);
|
|
|
|
Integration.Configuration config = load_config(args);
|
|
|
|
/*
|
|
* Hook up all tests into appropriate suites
|
|
*/
|
|
|
|
TestSuite integration = new TestSuite("integration");
|
|
|
|
switch (config.type) {
|
|
case IMAP:
|
|
integration.add_suite(new Integration.Imap.ClientSession(config).steal_suite());
|
|
break;
|
|
|
|
case SMTP:
|
|
integration.add_suite(new Integration.Smtp.ClientSession(config).steal_suite());
|
|
break;
|
|
}
|
|
|
|
/*
|
|
* Run the tests
|
|
*/
|
|
unowned TestSuite root = TestSuite.get_root();
|
|
root.add_suite((owned) integration);
|
|
|
|
MainLoop loop = new MainLoop();
|
|
|
|
int ret = -1;
|
|
Idle.add(() => {
|
|
ret = Test.run();
|
|
loop.quit();
|
|
return false;
|
|
});
|
|
|
|
loop.run();
|
|
return ret;
|
|
}
|
|
|
|
private Integration.Configuration load_config(string[] args) {
|
|
int i = 1;
|
|
try {
|
|
Geary.Protocol type = Geary.Protocol.for_value(args[i++]);
|
|
Geary.ServiceProvider provider = Geary.ServiceProvider.for_value(
|
|
args[i++]
|
|
);
|
|
Geary.ServiceInformation service = new Geary.ServiceInformation(
|
|
type, provider
|
|
);
|
|
|
|
if (provider == OTHER) {
|
|
service.host = args[i++];
|
|
service.port = service.get_default_port();
|
|
}
|
|
|
|
Geary.Credentials credentials = new Geary.Credentials(
|
|
PASSWORD, args[i++], args[i++]
|
|
);
|
|
|
|
provider.set_service_defaults(service);
|
|
|
|
Geary.Endpoint target = new Geary.Endpoint(
|
|
new NetworkAddress(service.host, service.port),
|
|
service.transport_security,
|
|
TIMEOUT
|
|
);
|
|
|
|
return { type, provider, service, target, credentials };
|
|
} catch (GLib.Error err) {
|
|
error(
|
|
"Error loading config: %s",
|
|
(new Geary.ErrorContext(err)).format_full_error()
|
|
);
|
|
}
|
|
|
|
}
|