Commit 15748cef authored by Michael Gratton's avatar Michael Gratton 🤞

Tidy up unit test infrastructure and mock classes.

* test/api/*.vala: Renamed files that contained mock objects to *-mock.vala,
  not *-test.vala.

* test/testcase.vala: Renamed to test-case.vala for consistency, remove
  TestCase class from Gee package since that's really not true. Clean up
  code for consistency.

* test/meson.build, test/CMakeLists.txt: Split TestCase compilation out
  into a separate test lib.
parent 50f73ff2
......@@ -2,17 +2,26 @@
# Copyright 2016 Software Freedom Conservancy Inc.
# Copyright 2016 Michael Gratton <mike@vee.net>
set(TEST_LIB_SRC
test-case.vala
)
set(TEST_ENGINE_SRC
test-engine.vala
testcase.vala # Based on same file in libgee, courtesy Julien Peeters
engine/api/geary-account-test.vala
# These should be included in the test lib sources, but we can't
# since that would make the test lib depend on geary-engine.vapi,
# and the engine test sute needs to depend
# geary-engine_internal.vapi, which leads to duplicate symbols when
# linking
engine/api/geary-account-mock.vala
engine/api/geary-email-identifier-mock.vala
engine/api/geary-email-properties-mock.vala
engine/api/geary-folder-mock.vala
engine/api/geary-folder-path-mock.vala
engine/api/geary-attachment-test.vala
engine/api/geary-engine-test.vala
engine/api/geary-email-identifier-test.vala
engine/api/geary-email-properties-test.vala
engine/api/geary-folder-test.vala
engine/api/geary-folder-path-test.vala
engine/app/app-conversation-test.vala
engine/app/app-conversation-set-test.vala
engine/imap/command/imap-create-command-test.vala
......@@ -35,7 +44,6 @@ set(TEST_ENGINE_SRC
set(TEST_CLIENT_SRC
test-client.vala
testcase.vala # Based on same file in libgee, courtesy Julien Peeters
client/application/geary-configuration-test.vala
client/components/client-web-view-test.vala
......@@ -65,6 +73,12 @@ pkg_check_modules(DEPS REQUIRED
libxml-2.0
)
set(TEST_LIB_PACKAGES
gee-0.8
gio-2.0
glib-2.0
)
set(TEST_ENGINE_PACKAGES
gee-0.8
gio-2.0
......@@ -102,6 +116,7 @@ set_property(SOURCE ${RESOURCES_C} PROPERTY GENERATED TRUE)
set(VALAC_OPTIONS
--vapidir=${CMAKE_BINARY_DIR}/src
--vapidir=${CMAKE_BINARY_DIR}/test
--vapidir=${CMAKE_SOURCE_DIR}/bindings/vapi
--metadatadir=${CMAKE_SOURCE_DIR}/bindings/metadata
--target-glib=${TARGET_GLIB}
......@@ -113,10 +128,23 @@ set(VALAC_OPTIONS
${EXTRA_VALA_OPTIONS}
)
vala_precompile(TEST_LIB_VALA_C test-lib
${TEST_LIB_SRC}
PACKAGES
${TEST_LIB_PACKAGES}
OPTIONS
--header=test-lib.h
--vapi=test-lib.vapi
${VALAC_OPTIONS}
)
add_library(test-lib STATIC ${TEST_LIB_VALA_C})
vala_precompile(TEST_ENGINE_VALA_C test-engine
${TEST_ENGINE_SRC}
PACKAGES
geary-engine-internal
test-lib
${TEST_ENGINE_PACKAGES}
OPTIONS
${VALAC_OPTIONS}
......@@ -127,6 +155,7 @@ vala_precompile(TEST_CLIENT_VALA_C test-client
PACKAGES
geary-client
geary-engine
test-lib
${TEST_ENGINE_PACKAGES}
${TEST_CLIENT_PACKAGES}
OPTIONS
......@@ -135,8 +164,8 @@ OPTIONS
# Exclude from all so tests aren't built by default
add_executable(test-engine EXCLUDE_FROM_ALL ${TEST_ENGINE_VALA_C})
target_link_libraries(test-engine ${DEPS_LIBRARIES} geary-engine)
target_link_libraries(test-engine ${DEPS_LIBRARIES} geary-engine test-lib)
# Exclude from all so tests aren't built by default
add_executable(test-client EXCLUDE_FROM_ALL ${TEST_CLIENT_VALA_C} ${RESOURCES_C})
target_link_libraries(test-client ${DEPS_LIBRARIES} geary-client geary-engine)
target_link_libraries(test-client ${DEPS_LIBRARIES} geary-client geary-engine test-lib)
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class ConfigurationTest : Gee.TestCase {
class ConfigurationTest : TestCase {
private Configuration test_config = null;
......
......@@ -8,7 +8,7 @@
// Defined by CMake build script.
extern const string _BUILD_ROOT_DIR;
public abstract class ClientWebViewTestCase<V> : Gee.TestCase {
public abstract class ClientWebViewTestCase<V> : TestCase {
protected V? test_view = null;
protected Configuration? config = null;
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
public class ClientWebViewTest : Gee.TestCase {
public class ClientWebViewTest : TestCase {
public ClientWebViewTest() {
base("ClientWebViewTest");
......
......@@ -8,7 +8,7 @@
// Defined by CMake build script.
extern const string _SOURCE_ROOT_DIR;
class Geary.AttachmentTest : Gee.TestCase {
class Geary.AttachmentTest : TestCase {
private const string ATTACHMENT_ID = "test-id";
private const string CONTENT_TYPE = "image/png";
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.EngineTest : Gee.TestCase {
class Geary.EngineTest : TestCase {
private Engine? engine = null;
private File? tmp = null;
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.App.ConversationSetTest : Gee.TestCase {
class Geary.App.ConversationSetTest : TestCase {
ConversationSet? test = null;
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.App.ConversationTest : Gee.TestCase {
class Geary.App.ConversationTest : TestCase {
Conversation? test = null;
......
......@@ -9,7 +9,7 @@ errordomain AccountProcessorTestError {
TEST;
}
public class Geary.ImapEngine.AccountProcessorTest : Gee.TestCase {
public class Geary.ImapEngine.AccountProcessorTest : TestCase {
public class TestOperation : AccountOperation {
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.Imap.CreateCommandTest : Gee.TestCase {
class Geary.Imap.CreateCommandTest : TestCase {
public CreateCommandTest() {
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.Imap.NamespaceResponseTest : Gee.TestCase {
class Geary.Imap.NamespaceResponseTest : TestCase {
public NamespaceResponseTest() {
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.Imap.DeserializerTest : Gee.TestCase {
class Geary.Imap.DeserializerTest : TestCase {
protected enum Expect { MESSAGE, EOS, DESER_FAIL; }
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.Mime.ContentTypeTest : Gee.TestCase {
class Geary.Mime.ContentTypeTest : TestCase {
public ContentTypeTest() {
base("Geary.Mime.ContentTypeTest");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.RFC822.MailboxAddressTest : Gee.TestCase {
class Geary.RFC822.MailboxAddressTest : TestCase {
public MailboxAddressTest() {
base("Geary.RFC822.MailboxAddressTest");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.RFC822.MailboxAddressesTest : Gee.TestCase {
class Geary.RFC822.MailboxAddressesTest : TestCase {
public MailboxAddressesTest() {
base("Geary.RFC822.MailboxAddressesTest");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.RFC822.MessageDataTest : Gee.TestCase {
class Geary.RFC822.MessageDataTest : TestCase {
public MessageDataTest() {
base("Geary.RFC822.MessageDataTest");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.RFC822.MessageTest : Gee.TestCase {
class Geary.RFC822.MessageTest : TestCase {
public MessageTest() {
base("Geary.RFC822.MessageTest");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.RFC822.Utils.Test : Gee.TestCase {
class Geary.RFC822.Utils.Test : TestCase {
public Test() {
base("Geary.RFC822.Utils.Test");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.HTML.UtilTest : Gee.TestCase {
class Geary.HTML.UtilTest : TestCase {
public UtilTest() {
base("Geary.HTML.Util");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.IdleManagerTest : Gee.TestCase {
class Geary.IdleManagerTest : TestCase {
public IdleManagerTest() {
base("Geary.IdleManagerTest");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.Inet.Test : Gee.TestCase {
class Geary.Inet.Test : TestCase {
public Test() {
base("Geary.Inet.Test");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
public class Geary.JS.Test : Gee.TestCase {
public class Geary.JS.Test : TestCase {
public Test() {
base("Geary.JS.Test");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.String.Test : Gee.TestCase {
class Geary.String.Test : TestCase {
public Test() {
base("Geary.String.Test");
......
......@@ -5,7 +5,7 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class Geary.TimeoutManagerTest : Gee.TestCase {
class Geary.TimeoutManagerTest : TestCase {
// add_seconds seems to vary wildly, so needs a large epsilon
private const double SECONDS_EPSILON = 1.8;
......
geary_test_lib_sources = [
'test-case.vala',
]
geary_test_engine_sources = [
'test-engine.vala',
'testcase.vala',
'engine/api/geary-account-test.vala',
# These should be included in the test lib sources, but we can't
# since that would make the test lib depend on geary-engine.vapi,
# and the engine test sute needs to depend
# geary-engine_internal.vapi, which leads to duplicate symbols when
# linking
'engine/api/geary-account-mock.vala',
'engine/api/geary-email-identifier-mock.vala',
'engine/api/geary-email-properties-mock.vala',
'engine/api/geary-folder-mock.vala',
'engine/api/geary-folder-path-mock.vala',
'engine/api/geary-attachment-test.vala',
'engine/api/geary-engine-test.vala',
'engine/api/geary-email-identifier-test.vala',
'engine/api/geary-email-properties-test.vala',
'engine/api/geary-folder-test.vala',
'engine/api/geary-folder-path-test.vala',
'engine/app/app-conversation-test.vala',
'engine/app/app-conversation-set-test.vala',
'engine/imap/command/imap-create-command-test.vala',
......@@ -31,7 +40,6 @@ geary_test_engine_sources = [
geary_test_client_sources = [
'test-client.vala',
'testcase.vala',
'client/application/geary-configuration-test.vala',
'client/components/client-web-view-test.vala',
......@@ -46,30 +54,33 @@ geary_test_client_sources = [
geary_resources
]
geary_test_engine_dependencies = [
geary_engine_internal_dep,
geary_test_lib_dependencies = [
gee,
gio,
glib,
gmime,
javascriptcoregtk,
libunwind,
libxml,
sqlite,
glib
]
geary_test_engine_dependencies = [
geary_engine_internal_dep
]
geary_test_engine_dependencies += geary_engine_dependencies
geary_test_client_dependencies = [
geary_client_dep,
geary_engine_dep,
gee,
gmime,
gtk,
libsoup,
webkit2gtk,
geary_client_dep
]
geary_test_client_dependencies += geary_client_dependencies
geary_test_lib = static_library('geary-test-lib',
geary_test_lib_sources,
dependencies: geary_test_lib_dependencies,
include_directories: config_h_dir,
vala_args: geary_vala_options,
c_args: geary_c_options,
)
geary_test_engine_bin = executable('geary-test-engine',
geary_test_engine_sources,
link_with: geary_test_lib,
dependencies: geary_test_engine_dependencies,
include_directories: config_h_dir,
vala_args: geary_vala_options,
......@@ -79,6 +90,7 @@ geary_test_engine_bin = executable('geary-test-engine',
geary_test_client_bin = executable('geary-test-client',
geary_test_client_sources,
dependencies: geary_test_client_dependencies,
link_with: geary_test_lib,
include_directories: config_h_dir,
vala_args: geary_vala_options,
c_args: geary_c_options,
......
/* testcase.vala
*
/*
* Copyright (C) 2009 Julien Peeters
* Copyright (C) 2017 Michael Gratton
*
......@@ -22,7 +21,7 @@
* Michael Gratton <mike@vee.net>
*/
public abstract class Gee.TestCase : Object {
public abstract class TestCase : Object {
protected MainContext main_loop = MainContext.default();
......@@ -32,18 +31,22 @@ public abstract class Gee.TestCase : Object {
public delegate void TestMethod() throws Error;
public TestCase (string name) {
this.suite = new GLib.TestSuite (name);
public TestCase(string name) {
this.suite = new GLib.TestSuite(name);
}
public void add_test (string name, owned TestMethod test) {
var adaptor = new Adaptor (name, (owned)test, this);
public void add_test(string name, owned TestMethod test) {
var adaptor = new Adaptor(name, (owned) test, this);
this.adaptors += adaptor;
this.suite.add (new GLib.TestCase (adaptor.name,
adaptor.set_up,
adaptor.run,
adaptor.tear_down ));
this.suite.add(
new GLib.TestCase(
adaptor.name,
adaptor.set_up,
adaptor.run,
adaptor.tear_down
)
);
}
public virtual void set_up() throws Error {
......@@ -52,7 +55,7 @@ public abstract class Gee.TestCase : Object {
public virtual void tear_down() throws Error {
}
public GLib.TestSuite get_suite () {
public GLib.TestSuite get_suite() {
return this.suite;
}
......@@ -73,16 +76,16 @@ public abstract class Gee.TestCase : Object {
}
private class Adaptor {
[CCode (notify = false)]
public string name { get; private set; }
private TestMethod test;
private TestCase test_case;
public Adaptor (string name,
owned TestMethod test,
TestCase test_case) {
public Adaptor(string name,
owned TestMethod test,
TestCase test_case) {
this.name = name;
this.test = (owned)test;
this.test = (owned) test;
this.test_case = test_case;
}
......@@ -96,7 +99,7 @@ public abstract class Gee.TestCase : Object {
public void run(void* fixture) {
try {
this.test ();
this.test();
} catch (Error err) {
assert_no_error(err);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment