[geary] Split test running up into test-engine and test-client.



commit 878b9aacaeaa0b55fefc2b0129e2a111f622aef4
Author: Michael James Gratton <mike vee net>
Date:   Thu Nov 23 09:35:51 2017 +1100

    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.

 CMakeLists.txt                             |   12 +++-
 Makefile.in                                |    8 +++
 src/CMakeLists.txt                         |   23 +++++---
 test/CMakeLists.txt                        |   48 ++++++++++++----
 test/engine/util-idle-manager-test.vala    |    4 +-
 test/engine/util-timeout-manager-test.vala |    6 +-
 test/main.vala                             |   88 ----------------------------
 test/test-client.vala                      |   68 +++++++++++++++++++++
 test/test-engine.vala                      |   58 ++++++++++++++++++
 9 files changed, 199 insertions(+), 116 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 67bfeb7..0620bca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
diff --git a/Makefile.in b/Makefile.in
index 7d4b808..27e09bb 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -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
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ecfbcb0..681dd57 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index e962195..7affa70 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -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
+    geary-engine-internal
+    ${TEST_ENGINE_PACKAGES}
+OPTIONS
+    ${VALAC_OPTIONS}
+)
+
+vala_precompile(TEST_CLIENT_VALA_C test-client
+    ${TEST_CLIENT_SRC}
 PACKAGES
-    ${TEST_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)
diff --git a/test/engine/util-idle-manager-test.vala b/test/engine/util-idle-manager-test.vala
index c0bfa22..1af857b 100644
--- a/test/engine/util-idle-manager-test.vala
+++ b/test/engine/util-idle-manager-test.vala
@@ -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);
     }
diff --git a/test/engine/util-timeout-manager-test.vala b/test/engine/util-timeout-manager-test.vala
index ae439e9..8f2d040 100644
--- a/test/engine/util-timeout-manager-test.vala
+++ b/test/engine/util-timeout-manager-test.vala
@@ -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();
 
diff --git a/test/test-client.vala b/test/test-client.vala
new file mode 100644
index 0000000..06352e8
--- /dev/null
+++ b/test/test-client.vala
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+// Defined by CMake build script.
+extern const string _GSETTINGS_DIR;
+
+int main(string[] args) {
+    /*
+     * Set env vars right up front to avoid weird bugs
+     */
+
+    // Use the memory GSettings DB so we a) always start with default
+    // values, and b) don't persist any changes made during a test
+    Environment.set_variable("GSETTINGS_BACKEND", "memory", true);
+
+    // Let GSettings know where to find the dev schema
+    Environment.set_variable("GSETTINGS_SCHEMA_DIR", _GSETTINGS_DIR, true);
+
+    /*
+     * Initialise all the things.
+     */
+
+    Gtk.init(ref args);
+    Test.init(ref args);
+
+    Geary.RFC822.init();
+    Geary.HTML.init();
+    Geary.Logging.init();
+
+    /*
+     * Hook up all tests into appropriate suites
+     */
+
+    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());
+
+    TestSuite js = new TestSuite("js");
+
+    js.add_suite(new ClientPageStateTest().get_suite());
+    js.add_suite(new ComposerPageStateTest().get_suite());
+    js.add_suite(new ConversationPageStateTest().get_suite());
+
+    /*
+     * Run the tests
+     */
+    TestSuite root = TestSuite.get_root();
+    root.add_suite(client);
+    root.add_suite(js);
+
+    int ret = -1;
+    Idle.add(() => {
+            ret = Test.run();
+            Gtk.main_quit();
+            return false;
+        });
+
+    Gtk.main();
+    return ret;
+}
diff --git a/test/test-engine.vala b/test/test-engine.vala
new file mode 100644
index 0000000..b30c7a2
--- /dev/null
+++ b/test/test-engine.vala
@@ -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;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]