aboutsummaryrefslogtreecommitdiff
path: root/tests/test-live-actions.cpp
diff options
context:
space:
mode:
authorIain Lane <iain.lane@canonical.com>2015-08-31 22:08:36 +0100
committerIain Lane <iain.lane@canonical.com>2015-08-31 22:08:36 +0100
commit132ac93bbd4141824cfa22f6516366f953fce9a0 (patch)
tree50f5027ae0e7fc39aa96e5fde4eb6ee867c6455a /tests/test-live-actions.cpp
parentad2d17a82ebe369adca6b477d5ecb362e243f585 (diff)
downloadayatana-indicator-datetime-132ac93bbd4141824cfa22f6516366f953fce9a0.tar.gz
ayatana-indicator-datetime-132ac93bbd4141824cfa22f6516366f953fce9a0.tar.bz2
ayatana-indicator-datetime-132ac93bbd4141824cfa22f6516366f953fce9a0.zip
Use timedated's Timezone property instead of watching /etc/timezone
Still need to rename everything to not use "timezone-file"
Diffstat (limited to 'tests/test-live-actions.cpp')
-rw-r--r--tests/test-live-actions.cpp234
1 files changed, 12 insertions, 222 deletions
diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp
index 4f84f25..9c74813 100644
--- a/tests/test-live-actions.cpp
+++ b/tests/test-live-actions.cpp
@@ -17,228 +17,18 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#include <datetime/actions-live.h>
-
-#include "state-mock.h"
-#include "glib-fixture.h"
-
-/***
-****
-***/
-
-using namespace unity::indicator::datetime;
-
-class MockLiveActions: public LiveActions
-{
-public:
- std::string last_cmd;
- std::string last_url;
- explicit MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {}
- ~MockLiveActions() {}
-
-protected:
- void dispatch_url(const std::string& url) override { last_url = url; }
- void execute_command(const std::string& cmd) override { 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();
- }
-};
+#include "timedated-fixture.h"
/***
****
***/
-TEST_F(LiveActionsFixture, HelloWorld)
+TEST_F(TimedateFixture, HelloWorld)
{
EXPECT_TRUE(true);
}
-TEST_F(LiveActionsFixture, SetLocation)
+TEST_F(TimedateFixture, SetLocation)
{
const std::string tzid = "America/Chicago";
const std::string name = "Oklahoma City";
@@ -258,14 +48,14 @@ TEST_F(LiveActionsFixture, SetLocation)
****
***/
-TEST_F(LiveActionsFixture, DesktopOpenAlarmApp)
+TEST_F(TimedateFixture, DesktopOpenAlarmApp)
{
m_actions->desktop_open_alarm_app();
const std::string expected = "evolution -c calendar";
EXPECT_EQ(expected, m_live_actions->last_cmd);
}
-TEST_F(LiveActionsFixture, DesktopOpenAppointment)
+TEST_F(TimedateFixture, DesktopOpenAppointment)
{
Appointment a;
a.uid = "some-uid";
@@ -275,14 +65,14 @@ TEST_F(LiveActionsFixture, DesktopOpenAppointment)
EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);
}
-TEST_F(LiveActionsFixture, DesktopOpenCalendarApp)
+TEST_F(TimedateFixture, DesktopOpenCalendarApp)
{
m_actions->desktop_open_calendar_app(DateTime::NowLocal());
const std::string expected_substr = "evolution \"calendar:///?startdate=";
EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);
}
-TEST_F(LiveActionsFixture, DesktopOpenSettingsApp)
+TEST_F(TimedateFixture, DesktopOpenSettingsApp)
{
m_actions->desktop_open_settings_app();
const std::string expected_substr = "control-center";
@@ -300,13 +90,13 @@ namespace
const std::string calendar_app_url = "appid://com.ubuntu.calendar/calendar/current-user-version";
}
-TEST_F(LiveActionsFixture, PhoneOpenAlarmApp)
+TEST_F(TimedateFixture, PhoneOpenAlarmApp)
{
m_actions->phone_open_alarm_app();
EXPECT_EQ(clock_app_url, m_live_actions->last_url);
}
-TEST_F(LiveActionsFixture, PhoneOpenAppointment)
+TEST_F(TimedateFixture, PhoneOpenAppointment)
{
Appointment a;
@@ -321,14 +111,14 @@ TEST_F(LiveActionsFixture, PhoneOpenAppointment)
EXPECT_EQ(clock_app_url, m_live_actions->last_url);
}
-TEST_F(LiveActionsFixture, PhoneOpenCalendarApp)
+TEST_F(TimedateFixture, PhoneOpenCalendarApp)
{
m_actions->phone_open_calendar_app(DateTime::NowLocal());
const std::string expected = "appid://com.ubuntu.calendar/calendar/current-user-version";
EXPECT_EQ(expected, m_live_actions->last_url);
}
-TEST_F(LiveActionsFixture, PhoneOpenSettingsApp)
+TEST_F(TimedateFixture, PhoneOpenSettingsApp)
{
m_actions->phone_open_settings_app();
const std::string expected = "settings:///system/time-date";
@@ -339,7 +129,7 @@ TEST_F(LiveActionsFixture, PhoneOpenSettingsApp)
****
***/
-TEST_F(LiveActionsFixture, CalendarState)
+TEST_F(TimedateFixture, CalendarState)
{
// init the clock
auto now = DateTime::Local(2014, 1, 1, 0, 0, 0);