aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt11
-rw-r--r--tests/sound-player-mock.c94
-rw-r--r--tests/sound-player-mock.h75
3 files changed, 178 insertions, 2 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 566132e..41e48cd 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -9,6 +9,13 @@ include_directories (SYSTEM ${DBUSTEST_INCLUDE_DIRS})
# add warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${C_WARNING_ARGS}")
+# build the mocks
+set(MOCK_LIB "indicatorpowerservicemocks")
+set(MOCK_SOURCES sound-player-mock.c)
+set_source_files_properties(${MOCK_SOURCES}
+ PROPERTIES COMPILE_FLAGS "${C_WARNING_ARGS} -g -std=c99")
+add_library(${MOCK_LIB} STATIC ${MOCK_SOURCES})
+
# build the necessary schemas
set_directory_properties (PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES gschemas.compiled)
@@ -50,8 +57,8 @@ function(add_test_by_name name)
add_executable (${TEST_NAME} ${TEST_NAME}.cc)
target_link_options(${TEST_NAME} PRIVATE -no-pie)
add_test (${TEST_NAME} ${TEST_NAME})
- add_dependencies (${TEST_NAME} ayatanaindicatorpowerservice gschemas-compiled)
- target_link_libraries (${TEST_NAME} ayatanaindicatorpowerservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS} ${URLDISPATCHER_LIBRARIES} ${GMOCK_LIBRARIES})
+ add_dependencies (${TEST_NAME} ${MOCK_LIB} ayatanaindicatorpowerservice gschemas-compiled)
+ target_link_libraries (${TEST_NAME} ${MOCK_LIB} ayatanaindicatorpowerservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS} ${URLDISPATCHER_LIBRARIES} ${GMOCK_LIBRARIES})
endfunction()
add_test_by_name(test-notify)
add_test(NAME dear-reader-the-next-test-takes-80-seconds COMMAND true)
diff --git a/tests/sound-player-mock.c b/tests/sound-player-mock.c
new file mode 100644
index 0000000..35c3b57
--- /dev/null
+++ b/tests/sound-player-mock.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2016 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#include "sound-player.h"
+#include "sound-player-mock.h"
+
+enum
+{
+ SIGNAL_URI_PLAYED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+/***
+**** GObject boilerplate
+***/
+
+static void indicator_power_sound_player_interface_init (
+ IndicatorPowerSoundPlayerInterface * iface);
+
+G_DEFINE_TYPE_WITH_CODE (
+ IndicatorPowerSoundPlayerMock,
+ indicator_power_sound_player_mock,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_SOUND_PLAYER,
+ indicator_power_sound_player_interface_init))
+
+/***
+**** IndicatorPowerSoundPlayer virtual functions
+***/
+
+static void
+my_play_uri (IndicatorPowerSoundPlayer * self, const gchar * uri)
+{
+ g_signal_emit (self, signals[SIGNAL_URI_PLAYED], 0, uri, NULL);
+}
+
+/***
+**** Instantiation
+***/
+
+static void
+indicator_power_sound_player_mock_class_init (IndicatorPowerSoundPlayerMockClass * klass G_GNUC_UNUSED)
+{
+ signals[SIGNAL_URI_PLAYED] = g_signal_new (
+ "uri-played",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (IndicatorPowerSoundPlayerMockClass, uri_played),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+}
+
+static void
+indicator_power_sound_player_interface_init (IndicatorPowerSoundPlayerInterface * iface)
+{
+ iface->play_uri = my_play_uri;
+}
+
+static void
+indicator_power_sound_player_mock_init (IndicatorPowerSoundPlayerMock * self G_GNUC_UNUSED)
+{
+}
+
+/***
+**** Public API
+***/
+
+IndicatorPowerSoundPlayer *
+indicator_power_sound_player_mock_new (void)
+{
+ gpointer o = g_object_new (INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK, NULL);
+
+ return INDICATOR_POWER_SOUND_PLAYER (o);
+}
+
diff --git a/tests/sound-player-mock.h b/tests/sound-player-mock.h
new file mode 100644
index 0000000..f844924
--- /dev/null
+++ b/tests/sound-player-mock.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#ifndef __INDICATOR_POWER_SOUND_PLAYER_MOCK__H__
+#define __INDICATOR_POWER_SOUND_PLAYER_MOCK__H__
+
+#include <glib-object.h> /* parent class */
+
+#include "sound-player.h"
+
+G_BEGIN_DECLS
+
+#define INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK \
+ (indicator_power_sound_player_mock_get_type())
+
+#define INDICATOR_POWER_SOUND_PLAYER_MOCK(o) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((o), \
+ INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK, \
+ IndicatorPowerSoundPlayerMock))
+
+#define INDICATOR_POWER_SOUND_PLAYER_MOCK_GET_CLASS(o) \
+ (G_TYPE_INSTANCE_GET_CLASS ((o), \
+ INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK, \
+ IndicatorPowerSoundPlayerMockClass))
+
+#define INDICATOR_IS_POWER_SOUND_PLAYER_MOCK(o) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((o), \
+ INDICATOR_TYPE_POWER_SOUND_PLAYER_MOCK))
+
+typedef struct _IndicatorPowerSoundPlayerMock
+ IndicatorPowerSoundPlayerMock;
+typedef struct _IndicatorPowerSoundPlayerMockPriv
+ IndicatorPowerSoundPlayerMockPriv;
+typedef struct _IndicatorPowerSoundPlayerMockClass
+ IndicatorPowerSoundPlayerMockClass;
+
+/**
+ * An IndicatorPowerSoundPlayer which gets its devices from Mock.
+ */
+struct _IndicatorPowerSoundPlayerMock
+{
+ GObject parent_instance;
+};
+
+struct _IndicatorPowerSoundPlayerMockClass
+{
+ GObjectClass parent_class;
+
+ /* signals */
+ void (*uri_played) (IndicatorPowerSoundPlayer * self, const gchar* uri);
+};
+
+GType indicator_power_sound_player_mock_get_type (void);
+
+IndicatorPowerSoundPlayer * indicator_power_sound_player_mock_new (void);
+
+G_END_DECLS
+
+#endif /* __INDICATOR_POWER_SOUND_PLAYER_MOCK__H__ */