diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-11-06 20:14:53 -0600 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2012-11-06 20:14:53 -0600 |
commit | 0b63ef0ea8625d713b9f726c8d664fdbeb37481d (patch) | |
tree | fbd3559a9a5d326c2257f3e695a36be340773787 /tests/test-service.cc | |
parent | ccc363f909fc8e2ecc571e83e18c12f46b771c1c (diff) | |
download | ayatana-indicator-session-0b63ef0ea8625d713b9f726c8d664fdbeb37481d.tar.gz ayatana-indicator-session-0b63ef0ea8625d713b9f726c8d664fdbeb37481d.tar.bz2 ayatana-indicator-session-0b63ef0ea8625d713b9f726c8d664fdbeb37481d.zip |
Reimplement test-service s.t. we actually test activating the service via dbus. Drop unneeded Xorg baggage.
Diffstat (limited to 'tests/test-service.cc')
-rw-r--r-- | tests/test-service.cc | 140 |
1 files changed, 120 insertions, 20 deletions
diff --git a/tests/test-service.cc b/tests/test-service.cc index 37ba4a9..dce665c 100644 --- a/tests/test-service.cc +++ b/tests/test-service.cc @@ -17,39 +17,139 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "gtest-dbus-helper.h" +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> + +#include <gtest/gtest.h> + #include "shared-names.h" /*** **** ***/ -/** - * Fixture class for testing indicator-session-service with Google Test. - */ -class SessionServiceTest: public IndicatorServiceTest +#define INDICATOR_SERVICE_OBJECT_PATH "/org/ayatana/indicator/service" +#define INDICATOR_SERVICE_INTERFACE_NAME "org.ayatana.indicator.service" + +class ClientTest : public ::testing::Test { - public: - virtual ~SessionServiceTest() {} - SessionServiceTest(): IndicatorServiceTest(INDICATOR_SESSION_DBUS_NAME, - INDICATOR_SESSION_DBUS_OBJECT, - INDICATOR_SERVICE_PATH) { } - public: - virtual void SetUp() { - wait_seconds(1); - IndicatorServiceTest::SetUp(); + protected: + + GTestDBus * test_dbus; + GDBusConnection * session_bus; + GMainLoop * main_loop; + + virtual void SetUp() + { + test_dbus = NULL; + session_bus = NULL; + main_loop = NULL; + + static bool ran_once_init = false; + if (!ran_once_init) + { + g_type_init(); + g_setenv ("INDICATOR_SERVICE_SHUTDOWN_TIMEOUT", "1000", TRUE); + g_unsetenv ("INDICATOR_ALLOW_NO_WATCHERS"); + g_unsetenv ("INDICATOR_SERVICE_REPLACE_MODE"); + ran_once_init = true; + } + + main_loop = g_main_loop_new (NULL, FALSE); + // pull up a test dbus that's pointed at our test .service file + test_dbus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_debug (G_STRLOC" service dir path is \"%s\"", INDICATOR_SERVICE_DIR); + g_test_dbus_add_service_dir (test_dbus, INDICATOR_SERVICE_DIR); + + // allow the service to exist w/o a sync indicator + g_setenv ("INDICATOR_ALLOW_NO_WATCHERS", "1", TRUE); + + g_test_dbus_up (test_dbus); + g_debug (G_STRLOC" this test bus' address is \"%s\"", g_test_dbus_get_bus_address(test_dbus)); + session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); + g_debug (G_STRLOC" the dbus connection %p unique name is \"%s\"", session_bus, g_dbus_connection_get_unique_name(session_bus)); + g_debug (G_STRLOC" the dbus connection %p refcount is %d", session_bus, G_OBJECT(session_bus)->ref_count); } - virtual void TearDown() { - IndicatorServiceTest::TearDown(); + + // undo SetUp + virtual void TearDown() + { + g_clear_object (&session_bus); + g_debug (G_STRLOC" tearing down the bus"); + g_test_dbus_down (test_dbus); + g_clear_object (&test_dbus); + g_clear_pointer (&main_loop, g_main_loop_unref); + } + + protected: + + void CallIndicatorServiceMethod (const gchar * method) + { + GVariant * response; + + ASSERT_TRUE (session_bus != NULL); + //ASSERT_TRUE (service_proxy != NULL); + //ASSERT_TRUE (ServiceProxyIsOwned ()); + + g_clear_pointer (&response, g_variant_unref); } }; +/*** +**** +***/ /** - * Basic sanity test to see if we can account for all our menuitems. + * This is a basic test to see if we can launch indicator-session-service + * and call its "GetUserRealName" method. The test succeeds if we can launch + * the service, call the method, and get response that equals g_get_real_name(). + * + * (You may be wondering why GetUserRealName() exists at all, instead of clients + * using g_get_real_name(). It's because the former updates itslef when the user + * edits his real name, while the latter returns its cached copy of the old name.) */ -TEST_F(SessionServiceTest, HelloWorld) +TEST_F (ClientTest, TestCanStartService) { - ASSERT_TRUE(true); -} + GError * error; + GVariant * result; + const gchar * name; + error = NULL; + result = g_dbus_connection_call_sync (session_bus, + INDICATOR_SESSION_DBUS_NAME, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE, + "GetUserRealName", + NULL, + G_VARIANT_TYPE("(s)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + EXPECT_TRUE (error == NULL); + ASSERT_TRUE (result != NULL); + + if (error != NULL) + { + g_warning ("GetUserRealName failed: %s", error->message); + g_clear_error (&error); + } + + name = NULL; + g_variant_get (result, "(&s)", &name); + ASSERT_STREQ (g_get_real_name(), name); + g_clear_pointer (&result, g_variant_unref); + + /* call the IndicatorService object's Shutdown() method for a clean shutdown */ + result = g_dbus_connection_call_sync (session_bus, + INDICATOR_SESSION_DBUS_NAME, + "/org/ayatana/indicator/service", + "org.ayatana.indicator.service", + "Shutdown", NULL, + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, NULL); + g_clear_pointer (&result, g_variant_unref); +} |