aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-22 09:06:01 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-22 09:06:01 -0600
commitdd41db685c518acab1c8e3676f4292f66e4d0476 (patch)
tree1611bc63d0a8f18d6786a084069eb662a5b159ea
parent9415a7cea370352141ec4e1cd140137e9215fded (diff)
downloadayatana-indicator-datetime-dd41db685c518acab1c8e3676f4292f66e4d0476.tar.gz
ayatana-indicator-datetime-dd41db685c518acab1c8e3676f4292f66e4d0476.tar.bz2
ayatana-indicator-datetime-dd41db685c518acab1c8e3676f4292f66e4d0476.zip
copyediting: rename the test/ directory's .cc files to .cpp for consistency with src/
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/test-actions.cpp (renamed from tests/test-actions.cc)0
-rw-r--r--tests/test-clock.cpp (renamed from tests/test-clock.cc)0
-rw-r--r--tests/test-exporter.cpp (renamed from tests/test-exporter.cc)0
-rw-r--r--tests/test-formatter.cpp (renamed from tests/test-formatter.cc)0
-rw-r--r--tests/test-live-actions.cpp289
-rw-r--r--tests/test-locations.cpp (renamed from tests/test-locations.cc)0
-rw-r--r--tests/test-menus.cpp (renamed from tests/test-menus.cc)0
-rw-r--r--tests/test-planner.cpp (renamed from tests/test-planner.cc)0
-rw-r--r--tests/test-settings.cpp (renamed from tests/test-settings.cc)0
-rw-r--r--tests/test-timezone-file.cpp (renamed from tests/test-timezone-file.cc)0
-rw-r--r--tests/test-timezone-geoclue.cpp (renamed from tests/test-timezone-geoclue.cc)0
-rw-r--r--tests/test-timezones.cpp (renamed from tests/test-timezones.cc)0
-rw-r--r--tests/test-utils.cpp (renamed from tests/test-utils.cc)0
14 files changed, 291 insertions, 2 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c8dd6aa..c909e0e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -35,7 +35,7 @@ add_definitions (-DSANDBOX="${CMAKE_CURRENT_BINARY_DIR}")
function(add_test_by_name name)
set (TEST_NAME ${name})
- add_executable (${TEST_NAME} ${TEST_NAME}.cc)
+ add_executable (${TEST_NAME} ${TEST_NAME}.cpp)
add_test (${TEST_NAME} ${TEST_NAME})
add_dependencies (${TEST_NAME} libindicatordatetimeservice)
target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS})
@@ -55,7 +55,7 @@ add_test_by_name(test-utils)
function(add_dbusmock_test_by_name name)
set (TEST_NAME ${name})
- add_executable (${TEST_NAME} ${TEST_NAME}.cc)
+ add_executable (${TEST_NAME} ${TEST_NAME}.cpp)
add_test (${TEST_NAME} ${TEST_NAME})
add_dependencies (${TEST_NAME} libindicatordatetimeservice)
target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${DBUSTEST_LIBRARIES} ${GTEST_LIBS})
diff --git a/tests/test-actions.cc b/tests/test-actions.cpp
index 4329608..4329608 100644
--- a/tests/test-actions.cc
+++ b/tests/test-actions.cpp
diff --git a/tests/test-clock.cc b/tests/test-clock.cpp
index 142ccad..142ccad 100644
--- a/tests/test-clock.cc
+++ b/tests/test-clock.cpp
diff --git a/tests/test-exporter.cc b/tests/test-exporter.cpp
index ea62cd3..ea62cd3 100644
--- a/tests/test-exporter.cc
+++ b/tests/test-exporter.cpp
diff --git a/tests/test-formatter.cc b/tests/test-formatter.cpp
index 9950453..9950453 100644
--- a/tests/test-formatter.cc
+++ b/tests/test-formatter.cpp
diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp
new file mode 100644
index 0000000..d3d7720
--- /dev/null
+++ b/tests/test-live-actions.cpp
@@ -0,0 +1,289 @@
+/*
+ * Copyright 2013 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 <datetime/actions-live.h>
+
+#include "state-mock.h"
+#include "glib-fixture.h"
+
+/***
+****
+***/
+
+class MockLiveActions: public LiveActions
+{
+public:
+ std::string last_cmd;
+ std::string last_url;
+ MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {}
+ virtual ~MockLiveActions() {}
+
+protected:
+ void dispatch_url(const std::string& url) { last_url = url; }
+ void execute_command(const std::string& cmd) { last_cmd = cmd; }
+};
+
+/***
+****
+***/
+
+using namespace unity::indicator::datetime;
+
+class LiveActionsFixture: public GlibFixture
+{
+private:
+
+ typedef GlibFixture super;
+
+ static void on_bus_acquired(GDBusConnection* conn,
+ const gchar* name,
+ gpointer gself)
+ {
+ auto self = static_cast<LiveActionsFixture*>(gself);
+ g_debug("bus acquired: %s, connection is %p", name, conn);
+
+ // Set up a mock GSD.
+ // All it really does is wait for calls to GetDevice and
+ // returns the get_devices_retval variant
+ static const GDBusInterfaceVTable vtable = {
+ timedate1_handle_method_call,
+ nullptr, /* GetProperty */
+ nullptr, /* SetProperty */
+ };
+
+ self->connection = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(conn)));
+
+ GError* error = nullptr;
+ self->object_register_id = g_dbus_connection_register_object(
+ conn,
+ "/org/freedesktop/timedate1",
+ self->node_info->interfaces[0],
+ &vtable,
+ self,
+ nullptr,
+ &error);
+ g_assert_no_error(error);
+ }
+
+ static void on_name_acquired(GDBusConnection* /*conn*/,
+ const gchar* /*name*/,
+ gpointer gself)
+ {
+ auto self = static_cast<LiveActionsFixture*>(gself);
+ self->name_acquired = true;
+ g_main_loop_quit(self->loop);
+ }
+
+ static void on_name_lost(GDBusConnection* /*conn*/,
+ const gchar* /*name*/,
+ gpointer gself)
+ {
+ auto self = static_cast<LiveActionsFixture*>(gself);
+ self->name_acquired = false;
+ }
+
+ static void on_bus_closed(GObject* /*object*/,
+ GAsyncResult* res,
+ gpointer gself)
+ {
+ auto self = static_cast<LiveActionsFixture*>(gself);
+ GError* err = nullptr;
+ g_dbus_connection_close_finish(self->connection, res, &err);
+ g_assert_no_error(err);
+ g_main_loop_quit(self->loop);
+ }
+
+ static void
+ timedate1_handle_method_call(GDBusConnection * /*connection*/,
+ const gchar * /*sender*/,
+ const gchar * /*object_path*/,
+ const gchar * /*interface_name*/,
+ const gchar * method_name,
+ GVariant * parameters,
+ GDBusMethodInvocation * invocation,
+ gpointer gself)
+ {
+ g_assert(!g_strcmp0(method_name, "SetTimezone"));
+ g_assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE_TUPLE));
+ g_assert(2 == g_variant_n_children(parameters));
+
+ auto child = g_variant_get_child_value(parameters, 0);
+ g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING));
+ auto self = static_cast<LiveActionsFixture*>(gself);
+ self->attempted_tzid = g_variant_get_string(child, nullptr);
+ g_variant_unref(child);
+
+ g_dbus_method_invocation_return_value(invocation, nullptr);
+ g_main_loop_quit(self->loop);
+ }
+
+protected:
+
+ std::shared_ptr<MockState> m_mock_state;
+ std::shared_ptr<State> m_state;
+ std::shared_ptr<MockLiveActions> m_live_actions;
+ std::shared_ptr<Actions> m_actions;
+
+ bool name_acquired;
+ std::string attempted_tzid;
+
+ GTestDBus* bus;
+ guint own_name;
+ GDBusConnection* connection;
+ GDBusNodeInfo* node_info;
+ int object_register_id;
+
+ void SetUp()
+ {
+ super::SetUp();
+
+ name_acquired = false;
+ attempted_tzid.clear();
+ connection = nullptr;
+ node_info = nullptr;
+ object_register_id = 0;
+ own_name = 0;
+
+ // bring up the test bus
+ bus = g_test_dbus_new(G_TEST_DBUS_NONE);
+ g_test_dbus_up(bus);
+ const auto address = g_test_dbus_get_bus_address(bus);
+ g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, true);
+ g_setenv("DBUS_SESSION_BUS_ADDRESS", address, true);
+ g_debug("test_dbus's address is %s", address);
+
+ // parse the org.freedesktop.timedate1 interface
+ const gchar introspection_xml[] =
+ "<node>"
+ " <interface name='org.freedesktop.timedate1'>"
+ " <method name='SetTimezone'>"
+ " <arg name='timezone' type='s' direction='in'/>"
+ " <arg name='user_interaction' type='b' direction='in'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+ node_info = g_dbus_node_info_new_for_xml(introspection_xml, nullptr);
+ ASSERT_TRUE(node_info != nullptr);
+ ASSERT_TRUE(node_info->interfaces != nullptr);
+ ASSERT_TRUE(node_info->interfaces[0] != nullptr);
+ ASSERT_TRUE(node_info->interfaces[1] == nullptr);
+ ASSERT_STREQ("org.freedesktop.timedate1", node_info->interfaces[0]->name);
+
+ // own the bus
+ own_name = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+ "org.freedesktop.timedate1",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus_acquired, on_name_acquired, on_name_lost,
+ this, nullptr);
+ ASSERT_TRUE(object_register_id == 0);
+ ASSERT_FALSE(name_acquired);
+ ASSERT_TRUE(connection == nullptr);
+ g_main_loop_run(loop);
+ ASSERT_TRUE(object_register_id != 0);
+ ASSERT_TRUE(name_acquired);
+ ASSERT_TRUE(G_IS_DBUS_CONNECTION(connection));
+
+ // create the State and Actions
+ m_mock_state.reset(new MockState);
+ m_mock_state->settings.reset(new Settings);
+ m_state = std::dynamic_pointer_cast<State>(m_mock_state);
+ m_live_actions.reset(new MockLiveActions(m_state));
+ m_actions = std::dynamic_pointer_cast<Actions>(m_live_actions);
+ }
+
+ void TearDown()
+ {
+ m_actions.reset();
+ m_live_actions.reset();
+ m_state.reset();
+ m_mock_state.reset();
+
+ g_dbus_connection_unregister_object(connection, object_register_id);
+ g_dbus_node_info_unref(node_info);
+ g_bus_unown_name(own_name);
+ g_dbus_connection_close(connection, nullptr, on_bus_closed, this);
+ g_main_loop_run(loop);
+ g_clear_object(&connection);
+ g_test_dbus_down(bus);
+ g_clear_object(&bus);
+
+ super::TearDown();
+ }
+};
+
+/***
+****
+***/
+
+TEST_F(LiveActionsFixture, HelloWorld)
+{
+ EXPECT_TRUE(true);
+}
+
+TEST_F(LiveActionsFixture, SetLocation)
+{
+ const std::string tzid = "America/Chicago";
+ const std::string name = "Oklahoma City";
+ const std::string expected = tzid + " " + name;
+
+ EXPECT_NE(expected, m_state->settings->timezone_name.get());
+
+ m_actions->set_location(tzid, name);
+ g_main_loop_run(loop);
+ EXPECT_EQ(attempted_tzid, tzid);
+ wait_msec();
+
+ EXPECT_EQ(expected, m_state->settings->timezone_name.get());
+}
+
+TEST_F(LiveActionsFixture, OpenDesktopSettings)
+{
+ m_actions->open_desktop_settings();
+ const std::string expected_substr = "control-center";
+ EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);
+}
+
+TEST_F(LiveActionsFixture, OpenPlanner)
+{
+ m_actions->open_planner();
+ const std::string expected = "evolution -c calendar";
+ EXPECT_EQ(expected, m_live_actions->last_cmd);
+}
+
+TEST_F(LiveActionsFixture, OpenPhoneSettings)
+{
+ m_actions->open_phone_settings();
+ const std::string expected = "settings:///system/time-date";
+ EXPECT_EQ(expected, m_live_actions->last_url);
+}
+
+TEST_F(LiveActionsFixture, OpenPhoneClockApp)
+{
+ m_actions->open_phone_clock_app();
+ const std::string expected = "appid://com.ubuntu.clock/clock/current-user-version";
+ EXPECT_EQ(expected, m_live_actions->last_url);
+}
+
+TEST_F(LiveActionsFixture, OpenPlannerAt)
+{
+ const auto now = DateTime::NowLocal();
+ m_actions->open_planner_at(now);
+ const std::string expected = now.format("evolution \"calendar:///?startdate=%Y%m%d\"");
+ EXPECT_EQ(expected, m_live_actions->last_cmd);
+}
diff --git a/tests/test-locations.cc b/tests/test-locations.cpp
index 65adbc7..65adbc7 100644
--- a/tests/test-locations.cc
+++ b/tests/test-locations.cpp
diff --git a/tests/test-menus.cc b/tests/test-menus.cpp
index fe1e86e..fe1e86e 100644
--- a/tests/test-menus.cc
+++ b/tests/test-menus.cpp
diff --git a/tests/test-planner.cc b/tests/test-planner.cpp
index 3072aea..3072aea 100644
--- a/tests/test-planner.cc
+++ b/tests/test-planner.cpp
diff --git a/tests/test-settings.cc b/tests/test-settings.cpp
index 9e52197..9e52197 100644
--- a/tests/test-settings.cc
+++ b/tests/test-settings.cpp
diff --git a/tests/test-timezone-file.cc b/tests/test-timezone-file.cpp
index 453b353..453b353 100644
--- a/tests/test-timezone-file.cc
+++ b/tests/test-timezone-file.cpp
diff --git a/tests/test-timezone-geoclue.cc b/tests/test-timezone-geoclue.cpp
index 4bf08a7..4bf08a7 100644
--- a/tests/test-timezone-geoclue.cc
+++ b/tests/test-timezone-geoclue.cpp
diff --git a/tests/test-timezones.cc b/tests/test-timezones.cpp
index 3f02761..3f02761 100644
--- a/tests/test-timezones.cc
+++ b/tests/test-timezones.cpp
diff --git a/tests/test-utils.cc b/tests/test-utils.cpp
index 2fe6a2e..2fe6a2e 100644
--- a/tests/test-utils.cc
+++ b/tests/test-utils.cpp