aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/name-watch-test.cc44
2 files changed, 44 insertions, 5 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 1e5448d..8e79fd0 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -15,7 +15,8 @@ target_link_libraries(gtest ${GTEST_LIBS})
# Name Watch Test
###########################
-add_executable (name-watch-test name-watch-test.cc)
-target_link_libraries (name-watch-test gtest ${GIO2_LIBRARIES})
+include_directories(${CMAKE_SOURCE_DIR}/src)
+add_executable (name-watch-test name-watch-test.cc ${CMAKE_SOURCE_DIR}/src/bus-watch-namespace.c)
+target_link_libraries (name-watch-test gtest ${SOUNDSERVICE_LIBRARIES})
add_test(name-watch-test name-watch-test)
diff --git a/tests/name-watch-test.cc b/tests/name-watch-test.cc
index b5a1db3..64f681d 100644
--- a/tests/name-watch-test.cc
+++ b/tests/name-watch-test.cc
@@ -2,20 +2,58 @@
#include <gio/gio.h>
#include <gtest/gtest.h>
+extern "C" {
+#include "bus-watch-namespace.h"
+}
+
class NameWatchTest : public ::testing::Test
{
+ private:
+ GTestDBus * testbus = NULL;
+
protected:
virtual void SetUp() {
-
+ testbus = g_test_dbus_new(G_TEST_DBUS_NONE);
+ g_test_dbus_up(testbus);
}
virtual void TearDown() {
-
+ g_test_dbus_down(testbus);
+ g_clear_object(&testbus);
}
};
-TEST_F(NameWatchTest, DummyTest)
+typedef struct {
+ guint appeared;
+ guint vanished;
+} callback_count_t;
+
+static void
+appeared_simple_cb (GDBusConnection * bus, const gchar * name, const gchar * owner, gpointer user_data)
+{
+ callback_count_t * callback_count = static_cast<callback_count_t *>(user_data);
+ callback_count->appeared++;
+}
+
+static void
+vanished_simple_cb (GDBusConnection * bus, const gchar * name, gpointer user_data)
{
+ callback_count_t * callback_count = static_cast<callback_count_t *>(user_data);
+ callback_count->vanished++;
+}
+
+
+TEST_F(NameWatchTest, BaseWatch)
+{
+ callback_count_t callback_count = {0};
+
+ guint ns_watch = bus_watch_namespace(G_BUS_TYPE_SESSION,
+ "com.foo",
+ appeared_simple_cb,
+ vanished_simple_cb,
+ &callback_count,
+ NULL);
+ bus_unwatch_namespace(ns_watch);
}