diff options
author | Robert Tari <robert@tari.in> | 2021-08-30 01:26:19 +0200 |
---|---|---|
committer | Robert Tari <robert@tari.in> | 2021-08-30 01:26:19 +0200 |
commit | 22e66866c7b17fc655479ca911269b86cb80a744 (patch) | |
tree | e0aa6e6a8f50fd8451e03efc17b89d8c8c3de781 /tests/test-live-actions.cpp | |
parent | 1f8263dedf9b7e6f9e06492bd69f2436e36171a2 (diff) | |
parent | 38e5efecbb3154a83a70c1c762802ec7927b3caa (diff) | |
download | ayatana-indicator-datetime-22e66866c7b17fc655479ca911269b86cb80a744.tar.gz ayatana-indicator-datetime-22e66866c7b17fc655479ca911269b86cb80a744.tar.bz2 ayatana-indicator-datetime-22e66866c7b17fc655479ca911269b86cb80a744.zip |
Merge branch 'tari01-pr/ubports-patches'
Attributes GH PR #46: https://github.com/AyatanaIndicators/ayatana-indicator-datetime/pull/46
Diffstat (limited to 'tests/test-live-actions.cpp')
-rw-r--r-- | tests/test-live-actions.cpp | 124 |
1 files changed, 91 insertions, 33 deletions
diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 9f17001..2d6ac9b 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -17,18 +17,72 @@ * Charles Kerr <charles.kerr@canonical.com> */ +#include "state-mock.h" #include "timedated-fixture.h" +#include <datetime/actions-live.h> + +using namespace ayatana::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() {} +}; + +class TestLiveActionsFixture: public TimedatedFixture +{ +private: + + using super = TimedatedFixture; + +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; + + void SetUp() override + { + super::SetUp(); + + // 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); + + // start the timedate1 dbusmock + start_timedate1("Etc/Utc"); + } + + void TearDown() override + { + m_actions.reset(); + m_live_actions.reset(); + m_state.reset(); + m_mock_state.reset(); + + super::TearDown(); + } +}; + /*** **** ***/ -TEST_F(TimedateFixture, HelloWorld) +TEST_F(TestLiveActionsFixture, HelloWorld) { EXPECT_TRUE(true); } -TEST_F(TimedateFixture, SetLocation) +TEST_F(TestLiveActionsFixture, SetLocation) { const std::string tzid = "America/Chicago"; const std::string name = "Oklahoma City"; @@ -36,49 +90,50 @@ TEST_F(TimedateFixture, SetLocation) EXPECT_NE(expected, m_state->settings->timezone_name.get()); - m_actions->set_location(tzid, name); + std::string new_name; m_state->settings->timezone_name.changed().connect( - [this](const std::string&){ - g_main_loop_quit(loop); - }); - g_main_loop_run(loop); - EXPECT_EQ(attempted_tzid, tzid); - wait_msec(); + [&new_name](const std::string& n){new_name = n;} + ); + + m_actions->set_location(tzid, name); + EXPECT_TRUE(wait_for([&new_name](){return !new_name.empty();})); + EXPECT_EQ(expected, new_name); EXPECT_EQ(expected, m_state->settings->timezone_name.get()); + EXPECT_EQ(tzid, get_timedate1_timezone()); } /*** **** ***/ -TEST_F(TimedateFixture, DesktopOpenAlarmApp) +TEST_F(TestLiveActionsFixture, DesktopOpenAlarmApp) { - m_actions->desktop_open_alarm_app(); + m_actions->open_alarm_app(); const std::string expected = "evolution -c calendar"; EXPECT_EQ(expected, m_live_actions->last_cmd); } -TEST_F(TimedateFixture, DesktopOpenAppointment) +TEST_F(TestLiveActionsFixture, DesktopOpenAppointment) { Appointment a; a.uid = "some-uid"; a.begin = DateTime::NowLocal(); - m_actions->desktop_open_appointment(a); + m_actions->open_appointment(a, a.begin); const std::string expected_substr = "evolution \"calendar:///?startdate="; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } -TEST_F(TimedateFixture, DesktopOpenCalendarApp) +TEST_F(TestLiveActionsFixture, DesktopOpenCalendarApp) { - m_actions->desktop_open_calendar_app(DateTime::NowLocal()); + m_actions->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(TimedateFixture, DesktopOpenSettingsApp) +TEST_F(TestLiveActionsFixture, DesktopOpenSettingsApp) { - m_actions->desktop_open_settings_app(); + m_actions->open_settings_app(); const std::string expected_substr = "control-center"; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } @@ -89,42 +144,45 @@ TEST_F(TimedateFixture, DesktopOpenSettingsApp) namespace { - const std::string clock_app_url = "appid://com.ubuntu.clock/clock/current-user-version"; - - const std::string calendar_app_url = "appid://com.ubuntu.calendar/calendar/current-user-version"; + const std::string clock_app_url = "alarm://"; } -TEST_F(TimedateFixture, PhoneOpenAlarmApp) +TEST_F(TestLiveActionsFixture, PhoneOpenAlarmApp) { - m_actions->phone_open_alarm_app(); + m_actions->open_alarm_app(); EXPECT_EQ(clock_app_url, m_live_actions->last_url); } -TEST_F(TimedateFixture, PhoneOpenAppointment) +TEST_F(TestLiveActionsFixture, PhoneOpenAppointment) { Appointment a; - a.uid = "some-uid"; + a.uid = "event-uid"; + a.source_uid = "source-uid"; a.begin = DateTime::NowLocal(); a.type = Appointment::EVENT; - m_actions->phone_open_appointment(a); - EXPECT_EQ(calendar_app_url, m_live_actions->last_url); + auto ocurrenceDate = DateTime::Local(2014, 1, 1, 0, 0, 0); + m_actions->open_appointment(a, ocurrenceDate); + const std::string appointment_app_url = ocurrenceDate.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); + EXPECT_EQ(appointment_app_url, m_live_actions->last_url); a.type = Appointment::UBUNTU_ALARM; - m_actions->phone_open_appointment(a); + m_actions->open_appointment(a, a.begin); EXPECT_EQ(clock_app_url, m_live_actions->last_url); } -TEST_F(TimedateFixture, PhoneOpenCalendarApp) +TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp) { - m_actions->phone_open_calendar_app(DateTime::NowLocal()); - const std::string expected = "appid://com.ubuntu.calendar/calendar/current-user-version"; + auto now = DateTime::NowLocal(); + m_actions->open_calendar_app(now); + const std::string expected = now.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); EXPECT_EQ(expected, m_live_actions->last_url); } -TEST_F(TimedateFixture, PhoneOpenSettingsApp) + +TEST_F(TestLiveActionsFixture, PhoneOpenSettingsApp) { - m_actions->phone_open_settings_app(); + m_actions->open_settings_app(); const std::string expected = "settings:///system/time-date"; EXPECT_EQ(expected, m_live_actions->last_url); } @@ -133,7 +191,7 @@ TEST_F(TimedateFixture, PhoneOpenSettingsApp) **** ***/ -TEST_F(TimedateFixture, CalendarState) +TEST_F(TestLiveActionsFixture, CalendarState) { // init the clock auto now = DateTime::Local(2014, 1, 1, 0, 0, 0); |