Split test running up into test-engine and test-client.

This allows us to compile the engine tests against the internal VAPI, so
we can unit test internal classes.

* CMakeLists.txt: Add top-level targets test-engine-run and
  test-client-run that execute the respective test binaries. Make
  the tests target depend on them and make them depend on their
  binaries.

* Makefile.in: Add test-client and test-engin targets for convenience.

* src/CMakeLists.txt: Make the right invocation of valac to generate a
  correct geary-engine-internal.vapi. Make gsettings schema generation
  depend on geary-client so it exists for test-client if the main binary
  hasn't been built.

* test/CMakeLists.txt: Split everything up into to builds, one for
  test-engine and the other for test-client. Use geary-engine-internal
  when building test-engine for access to internal classes and members.

* test/engine/util-idle-manager-test.vala,
  test/engine/util-timeout-manager-test.vala: Use Glib MainContext rather
  than the GTK main loop for pumping events so the test cases compile
  without GTK.

* test/test-engine.vala, test/test-client.vala: New main source file for
  test binaries based on old main.vala.
This commit is contained in:
Michael James Gratton 2017-11-23 09:35:51 +11:00
parent df887170c0
commit 878b9aacae
8 changed files with 132 additions and 49 deletions

View file

@ -157,9 +157,15 @@ include(GlibCompileResourcesSupport)
# Unit tests.
#
# We don't use CMake's enable_testing/add_test built-ins because they
# use ctest. It's not called "test" because that is cmake reserved.
add_custom_target(tests geary-test)
add_dependencies(tests geary-test)
# use ctest. It's not called "test" because that is cmake
# reserved.
add_custom_target(tests)
add_custom_target(test-engine-run COMMAND test-engine)
add_custom_target(test-client-run COMMAND test-client)
add_dependencies(tests test-engine-run test-client-run)
add_dependencies(test-engine-run test-engine)
add_dependencies(test-client-run test-client)
#
# Uninstall target

View file

@ -45,6 +45,14 @@ tests:
test:
@$(MAKE) -C $(BUILD_DIR) tests
.PHONY: test-engine
test-engine:
@$(MAKE) -C $(BUILD_DIR) $@-run
.PHONY: test-client
test-client:
@$(MAKE) -C $(BUILD_DIR) $@-run
.PHONY: dist
dist: tests
@$(MAKE) -C $(BUILD_DIR) dist

View file

@ -626,15 +626,20 @@ set(VALAC_OPTIONS
${EXTRA_VALA_OPTIONS}
)
# Engine (static library used for building apps and unit test)
# Engine - static library used for building apps and unit tests
#
# See Vala Bug 731322 about the specifics of the arguments used below
# to generate the internal VAPI and header.
#################################################
vala_precompile(ENGINE_VALA_C geary-engine
${ENGINE_SRC}
PACKAGES
${ENGINE_PACKAGES}
GENERATE_VAPI
geary-engine
OPTIONS
--header=geary-engine.h
--vapi=geary-engine.vapi
--internal-header=geary-engine-internal.h
--internal-vapi=geary-engine-internal.vapi
${VALAC_OPTIONS}
)
@ -713,6 +718,12 @@ OPTIONS
${VALAC_OPTIONS}
)
# GSettings
# This needs to be here and not in desktop/CMakeLists.txt in order for Geary to run in the build
# directory
include(GSettings)
add_schemas(geary-client ${GSETTINGS_DIR} ${CMAKE_INSTALL_PREFIX})
add_executable(geary ${GEARY_VALA_C} ${RESOURCES_C})
target_link_libraries(geary ${DEPS_LIBRARIES} geary-client)
install(TARGETS geary RUNTIME DESTINATION bin)
@ -724,12 +735,6 @@ add_custom_command(
${CMAKE_COMMAND} -E copy geary ${CMAKE_BINARY_DIR}/
)
# GSettings
# This needs to be here and not in desktop/CMakeLists.txt in order for Geary to run in the build
# directory
include(GSettings)
add_schemas(geary ${GSETTINGS_DIR} ${CMAKE_INSTALL_PREFIX})
# Client web process extension library
#################################################
vala_precompile(WEB_PROCESS_VALA_C geary-web-process

View file

@ -2,8 +2,8 @@
# Copyright 2016 Software Freedom Conservancy Inc.
# Copyright 2016 Michael Gratton <mike@vee.net>
set(TEST_SRC
main.vala
set(TEST_ENGINE_SRC
test-engine.vala
testcase.vala # Based on same file in libgee, courtesy Julien Peeters
engine/api/geary-attachment-test.vala
@ -21,6 +21,11 @@ set(TEST_SRC
engine/util-inet-test.vala
engine/util-js-test.vala
engine/util-timeout-manager-test.vala
)
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
@ -50,15 +55,19 @@ pkg_check_modules(DEPS REQUIRED
libxml-2.0
)
set(TEST_PACKAGES
geary-client
geary-engine
set(TEST_ENGINE_PACKAGES
gee-0.8
gio-2.0
glib-2.0
gmime-2.6
gtk+-3.0
javascriptcore-4.0
libunwind
libxml-2.0
sqlite3
)
set(TEST_CLIENT_PACKAGES
gtk+-3.0
libsoup-2.4
webkit2gtk-4.0
)
@ -74,6 +83,7 @@ set(CFLAGS
include_directories(${CMAKE_BINARY_DIR}/src)
set(LIB_PATHS ${DEPS_LIBRARY_DIRS})
link_directories(${LIB_PATHS})
add_definitions(${CFLAGS})
@ -93,14 +103,30 @@ set(VALAC_OPTIONS
${EXTRA_VALA_OPTIONS}
)
vala_precompile(TEST_VALA_C geary-test
${TEST_SRC}
vala_precompile(TEST_ENGINE_VALA_C test-engine
${TEST_ENGINE_SRC}
PACKAGES
${TEST_PACKAGES}
geary-engine-internal
${TEST_ENGINE_PACKAGES}
OPTIONS
${VALAC_OPTIONS}
)
vala_precompile(TEST_CLIENT_VALA_C test-client
${TEST_CLIENT_SRC}
PACKAGES
geary-client
geary-engine
${TEST_ENGINE_PACKAGES}
${TEST_CLIENT_PACKAGES}
OPTIONS
${VALAC_OPTIONS}
)
# Exclude from all so tests aren't built by default
add_executable(geary-test EXCLUDE_FROM_ALL ${TEST_VALA_C} ${RESOURCES_C})
target_link_libraries(geary-test ${DEPS_LIBRARIES} geary-client geary-engine)
add_executable(test-engine EXCLUDE_FROM_ALL ${TEST_ENGINE_VALA_C})
target_link_libraries(test-engine ${DEPS_LIBRARIES} geary-engine)
# 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)

View file

@ -29,10 +29,10 @@ class Geary.IdleManagerTest : Gee.TestCase {
test.schedule();
// There should be at least one event pending
assert(Gtk.events_pending());
assert(this.main_loop.pending());
// Execute the idle function
Gtk.main_iteration();
this.main_loop.iteration(true);
assert(did_run);
}

View file

@ -39,7 +39,7 @@ class Geary.TimeoutManagerTest : Gee.TestCase {
timer.start();
while (test.is_running && timer.elapsed() < SECONDS_EPSILON) {
Gtk.main_iteration();
this.main_loop.iteration(true);
}
assert_epsilon(timer.elapsed(), 1.0, SECONDS_EPSILON);
@ -53,7 +53,7 @@ class Geary.TimeoutManagerTest : Gee.TestCase {
timer.start();
while (test.is_running && timer.elapsed() < 100 + MILLISECONDS_EPSILON) {
Gtk.main_iteration();
this.main_loop.iteration(true);
}
assert_epsilon(timer.elapsed(), 0.1, MILLISECONDS_EPSILON);
@ -69,7 +69,7 @@ class Geary.TimeoutManagerTest : Gee.TestCase {
timer.start();
while (count < 2 && timer.elapsed() < SECONDS_EPSILON * 2) {
Gtk.main_iteration();
this.main_loop.iteration(true);
}
timer.stop();

View file

@ -1,5 +1,5 @@
/*
* Copyright 2016 Michael Gratton <mike@vee.net>
* Copyright 2016-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.
@ -35,30 +35,11 @@ int main(string[] args) {
* Hook up all tests into appropriate suites
*/
TestSuite engine = new TestSuite("engine");
engine.add_suite(new Geary.AttachmentTest().get_suite());
engine.add_suite(new Geary.EngineTest().get_suite());
engine.add_suite(new Geary.HTML.UtilTest().get_suite());
engine.add_suite(new Geary.IdleManagerTest().get_suite());
engine.add_suite(new Geary.Imap.DeserializerTest().get_suite());
engine.add_suite(new Geary.Imap.CreateCommandTest().get_suite());
engine.add_suite(new Geary.Imap.NamespaceResponseTest().get_suite());
engine.add_suite(new Geary.Inet.Test().get_suite());
engine.add_suite(new Geary.JS.Test().get_suite());
engine.add_suite(new Geary.Mime.ContentTypeTest().get_suite());
engine.add_suite(new Geary.RFC822.MailboxAddressTest().get_suite());
engine.add_suite(new Geary.RFC822.MessageTest().get_suite());
engine.add_suite(new Geary.RFC822.MessageDataTest().get_suite());
engine.add_suite(new Geary.RFC822.Utils.Test().get_suite());
engine.add_suite(new Geary.TimeoutManagerTest().get_suite());
TestSuite client = new TestSuite("client");
// Keep this before other ClientWebView based tests since it tests
// WebContext init
client.add_suite(new ClientWebViewTest().get_suite());
client.add_suite(new ComposerWebViewTest().get_suite());
client.add_suite(new ConfigurationTest().get_suite());
@ -72,7 +53,6 @@ int main(string[] args) {
* Run the tests
*/
TestSuite root = TestSuite.get_root();
root.add_suite(engine);
root.add_suite(client);
root.add_suite(js);

58
test/test-engine.vala Normal file
View file

@ -0,0 +1,58 @@
/*
* Copyright 2016-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.
*/
int main(string[] args) {
/*
* Initialise all the things.
*/
Test.init(ref args);
Geary.RFC822.init();
Geary.HTML.init();
Geary.Logging.init();
/*
* Hook up all tests into appropriate suites
*/
TestSuite engine = new TestSuite("engine");
engine.add_suite(new Geary.AttachmentTest().get_suite());
engine.add_suite(new Geary.EngineTest().get_suite());
engine.add_suite(new Geary.HTML.UtilTest().get_suite());
engine.add_suite(new Geary.IdleManagerTest().get_suite());
engine.add_suite(new Geary.Imap.DeserializerTest().get_suite());
engine.add_suite(new Geary.Imap.CreateCommandTest().get_suite());
engine.add_suite(new Geary.Imap.NamespaceResponseTest().get_suite());
engine.add_suite(new Geary.Inet.Test().get_suite());
engine.add_suite(new Geary.JS.Test().get_suite());
engine.add_suite(new Geary.Mime.ContentTypeTest().get_suite());
engine.add_suite(new Geary.RFC822.MailboxAddressTest().get_suite());
engine.add_suite(new Geary.RFC822.MessageTest().get_suite());
engine.add_suite(new Geary.RFC822.MessageDataTest().get_suite());
engine.add_suite(new Geary.RFC822.Utils.Test().get_suite());
engine.add_suite(new Geary.TimeoutManagerTest().get_suite());
/*
* Run the tests
*/
TestSuite root = TestSuite.get_root();
root.add_suite(engine);
MainLoop loop = new MainLoop ();
int ret = -1;
Idle.add(() => {
ret = Test.run();
loop.quit();
return false;
});
loop.run();
return ret;
}