diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/actions-mock.h | 67 | ||||
-rw-r--r-- | tests/test-actions.cpp | 260 | ||||
-rw-r--r-- | tests/test-exporter.cpp | 13 | ||||
-rw-r--r-- | tests/test-live-actions.cpp | 91 | ||||
-rw-r--r-- | tests/test-menus.cpp | 31 |
5 files changed, 318 insertions, 144 deletions
diff --git a/tests/actions-mock.h b/tests/actions-mock.h index ebd8a4d..77315c0 100644 --- a/tests/actions-mock.h +++ b/tests/actions-mock.h @@ -34,28 +34,54 @@ public: MockActions(std::shared_ptr<State>& state_in): Actions(state_in) {} ~MockActions() =default; - enum Action { OpenDesktopSettings, OpenPhoneSettings, OpenPhoneClockApp, - OpenPlanner, OpenPlannerAt, OpenAppointment, SetLocation }; + enum Action { DesktopOpenAlarmApp, + DesktopOpenAppt, + DesktopOpenCalendarApp, + DesktopOpenSettingsApp, + PhoneOpenAlarmApp, + PhoneOpenAppt, + PhoneOpenCalendarApp, + PhoneOpenSettingsApp, + SetLocation }; + const std::vector<Action>& history() const { return m_history; } const DateTime& date_time() const { return m_date_time; } const std::string& zone() const { return m_zone; } const std::string& name() const { return m_name; } - const std::string& url() const { return m_url; } + const Appointment& appointment() const { return m_appt; } void clear() { m_history.clear(); m_zone.clear(); m_name.clear(); } - void open_desktop_settings() { m_history.push_back(OpenDesktopSettings); } - - void open_phone_settings() { m_history.push_back(OpenPhoneSettings); } - - void open_phone_clock_app() { m_history.push_back(OpenPhoneClockApp); } - - bool can_open_planner() const { return m_can_open_planner; } - - void open_planner() { m_history.push_back(OpenPlanner); } + bool desktop_has_calendar_app() const { + return m_desktop_has_calendar_app; + } + void desktop_open_alarm_app() { + m_history.push_back(DesktopOpenAlarmApp); + } + void desktop_open_appointment(const Appointment& appt) { + m_appt = appt; + m_history.push_back(DesktopOpenAppt); + } + void desktop_open_calendar_app(const DateTime& dt) { + m_date_time = dt; + m_history.push_back(DesktopOpenCalendarApp); + } + void desktop_open_settings_app() { + m_history.push_back(DesktopOpenSettingsApp); + } - void open_planner_at(const DateTime& date_time_) { - m_history.push_back(OpenPlannerAt); - m_date_time = date_time_; + void phone_open_alarm_app() { + m_history.push_back(PhoneOpenAlarmApp); + } + void phone_open_appointment(const Appointment& appt) { + m_appt = appt; + m_history.push_back(PhoneOpenAppt); + } + void phone_open_calendar_app(const DateTime& dt) { + m_date_time = dt; + m_history.push_back(PhoneOpenCalendarApp); + } + void phone_open_settings_app() { + m_history.push_back(PhoneOpenSettingsApp); } void set_location(const std::string& zone_, const std::string& name_) { @@ -64,16 +90,13 @@ public: m_name = name_; } - void open_appointment(const std::string& url_) { - m_history.push_back(OpenAppointment); - m_url = url_; + void set_desktop_has_calendar_app(bool b) { + m_desktop_has_calendar_app = b; } - void set_can_open_planner(bool b) { m_can_open_planner = b; } - private: - bool m_can_open_planner = true; - std::string m_url; + bool m_desktop_has_calendar_app = true; + Appointment m_appt; std::string m_zone; std::string m_name; DateTime m_date_time; diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index d838a52..9f7856c 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -23,7 +23,130 @@ using namespace unity::indicator::datetime; -typedef StateFixture ActionsFixture; +class ActionsFixture: public StateFixture +{ + typedef StateFixture super; + + std::vector<Appointment> build_some_appointments() + { + const auto now = m_state->clock->localtime(); + auto gdt_tomorrow = g_date_time_add_days(now.get(), 1); + const auto tomorrow = DateTime(gdt_tomorrow); + g_date_time_unref(gdt_tomorrow); + + Appointment a1; // an alarm clock appointment + a1.color = "red"; + a1.summary = "Alarm"; + a1.summary = "http://www.example.com/"; + a1.uid = "example"; + a1.has_alarms = true; + a1.begin = a1.end = tomorrow; + + Appointment a2; // a non-alarm appointment + a2.color = "green"; + a2.summary = "Other Text"; + a2.summary = "http://www.monkey.com/"; + a2.uid = "monkey"; + a2.has_alarms = false; + a2.begin = a2.end = tomorrow; + + return std::vector<Appointment>({a1, a2}); + } + +protected: + + virtual void SetUp() + { + super::SetUp(); + } + + virtual void TearDown() + { + super::TearDown(); + } + + void test_action_with_no_args(const char * action_name, + MockActions::Action expected_action) + { + // preconditions + EXPECT_TRUE(m_mock_actions->history().empty()); + auto action_group = m_actions->action_group(); + EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + + // run the test + g_action_group_activate_action(action_group, action_name, nullptr); + + // test the results + EXPECT_EQ(std::vector<MockActions::Action>({expected_action}), + m_mock_actions->history()); + } + + void test_action_with_time_arg(const char * action_name, + MockActions::Action expected_action) + { + // preconditions + EXPECT_TRUE(m_mock_actions->history().empty()); + auto action_group = m_actions->action_group(); + EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + + // activate the action + const auto now = DateTime::NowLocal(); + auto v = g_variant_new_int64(now.to_unix()); + g_action_group_activate_action(action_group, action_name, v); + + // test the results + EXPECT_EQ(std::vector<MockActions::Action>({expected_action}), + m_mock_actions->history()); + EXPECT_EQ(now.format("%F %T"), + m_mock_actions->date_time().format("%F %T")); + } + + void test_action_with_appt_arg(const char * action_name, + MockActions::Action expected_action) + { + /// + /// Test 1: activate an appointment that we know about + /// + + // preconditions + EXPECT_TRUE(m_mock_actions->history().empty()); + auto action_group = m_actions->action_group(); + EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + + // init some appointments to the state + const auto appointments = build_some_appointments(); + m_mock_state->mock_range_planner->appointments().set(appointments); + + // activate the action + auto v = g_variant_new_string(appointments[0].uid.c_str()); + g_action_group_activate_action(action_group, action_name, v); + + // test the results + EXPECT_EQ(std::vector<MockActions::Action>({expected_action}), + m_mock_actions->history()); + EXPECT_EQ(appointments[0], + m_mock_actions->appointment()); + + /// + /// Test 2: activate an appointment we *don't* know about + /// + + // setup + m_mock_actions->clear(); + EXPECT_TRUE(m_mock_actions->history().empty()); + + // activate the action + v = g_variant_new_string("this-uid-is-not-one-that-we-have"); + g_action_group_activate_action(action_group, action_name, v); + + // test the results + EXPECT_TRUE(m_mock_actions->history().empty()); + } +}; + +/*** +**** +***/ TEST_F(ActionsFixture, ActionsExist) { @@ -32,93 +155,81 @@ TEST_F(ActionsFixture, ActionsExist) const char* names[] = { "desktop-header", "calendar", "set-location", - "activate-planner", - "activate-appointment", - "activate-phone-settings", - "activate-phone-clock-app", - "activate-desktop-settings" }; + "desktop.open-appointment", + "desktop.open-alarm-app", + "desktop.open-calendar-app", + "desktop.open-settings-app", + "phone.open-appointment", + "phone.open-alarm-app", + "phone.open-calendar-app", + "phone.open-settings-app" }; + for(const auto& name: names) { EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), name)); } } -TEST_F(ActionsFixture, ActivateDesktopSettings) -{ - const auto action_name = "activate-desktop-settings"; - const auto expected_action = MockActions::OpenDesktopSettings; - - auto action_group = m_actions->action_group(); - auto history = m_mock_actions->history(); - EXPECT_EQ(0, history.size()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); +/*** +**** +***/ - g_action_group_activate_action(action_group, action_name, nullptr); - history = m_mock_actions->history(); - EXPECT_EQ(1, history.size()); - EXPECT_EQ(expected_action, history[0]); +TEST_F(ActionsFixture, DesktopOpenAlarmApp) +{ + test_action_with_no_args("desktop.open-alarm-app", + MockActions::DesktopOpenAlarmApp); } -TEST_F(ActionsFixture, ActivatePhoneSettings) +TEST_F(ActionsFixture, DesktopOpenAppointment) { - const auto action_name = "activate-phone-settings"; - const auto expected_action = MockActions::OpenPhoneSettings; - - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + test_action_with_appt_arg("desktop.open-appointment", + MockActions::DesktopOpenAppt); +} - g_action_group_activate_action(action_group, action_name, nullptr); - auto history = m_mock_actions->history(); - EXPECT_EQ(1, history.size()); - EXPECT_EQ(expected_action, history[0]); +TEST_F(ActionsFixture, DesktopOpenCalendarApp) +{ + test_action_with_time_arg("desktop.open-calendar-app", + MockActions::DesktopOpenCalendarApp); } -TEST_F(ActionsFixture, ActivatePhoneClockApp) +TEST_F(ActionsFixture, DesktopOpenSettingsApp) { - const auto action_name = "activate-phone-clock-app"; - const auto expected_action = MockActions::OpenPhoneClockApp; + test_action_with_no_args("desktop.open-settings-app", + MockActions::DesktopOpenSettingsApp); +} - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); +/*** +**** +***/ - g_action_group_activate_action(action_group, action_name, nullptr); - auto history = m_mock_actions->history(); - EXPECT_EQ(1, history.size()); - EXPECT_EQ(expected_action, history[0]); +TEST_F(ActionsFixture, PhoneOpenAlarmApp) +{ + test_action_with_no_args("phone.open-alarm-app", + MockActions::PhoneOpenAlarmApp); } -TEST_F(ActionsFixture, ActivatePlanner) +TEST_F(ActionsFixture, PhoneOpenAppointment) { - const auto action_name = "activate-planner"; - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); - - const auto expected_action = MockActions::OpenPlanner; - auto v = g_variant_new_int64(0); - g_action_group_activate_action(action_group, action_name, v); - auto history = m_mock_actions->history(); - EXPECT_EQ(1, history.size()); - EXPECT_EQ(expected_action, history[0]); + test_action_with_appt_arg("phone.open-appointment", + MockActions::PhoneOpenAppt); } -TEST_F(ActionsFixture, ActivatePlannerAt) +TEST_F(ActionsFixture, PhoneOpenCalendarApp) { - const auto action_name = "activate-planner"; - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); + test_action_with_time_arg("phone.open-calendar-app", + MockActions::PhoneOpenCalendarApp); +} - const auto now = DateTime::NowLocal(); - auto v = g_variant_new_int64(now.to_unix()); - g_action_group_activate_action(action_group, action_name, v); - const auto a = MockActions::OpenPlannerAt; - EXPECT_EQ(std::vector<MockActions::Action>({a}), m_mock_actions->history()); - EXPECT_EQ(now.to_unix(), m_mock_actions->date_time().to_unix()); +TEST_F(ActionsFixture, PhoneOpenSettingsApp) +{ + test_action_with_no_args("phone.open-settings-app", + MockActions::PhoneOpenSettingsApp); } +/*** +**** +***/ + TEST_F(ActionsFixture, SetLocation) { const auto action_name = "set-location"; @@ -215,26 +326,3 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate) g_clear_pointer(&calendar_state, g_variant_unref); } - - -TEST_F(ActionsFixture, OpenAppointment) -{ - Appointment appt; - appt.uid = "some arbitrary uid"; - appt.url = "http://www.canonical.com/"; - appt.begin = m_state->clock->localtime(); - m_state->calendar_upcoming->appointments().set(std::vector<Appointment>({appt})); - - const auto action_name = "activate-appointment"; - auto action_group = m_actions->action_group(); - EXPECT_TRUE(m_mock_actions->history().empty()); - EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); - - auto v = g_variant_new_string(appt.uid.c_str()); - g_action_group_activate_action(action_group, action_name, v); - const auto a = MockActions::OpenAppointment; - ASSERT_EQ(1, m_mock_actions->history().size()); - ASSERT_EQ(a, m_mock_actions->history()[0]); - EXPECT_EQ(appt.url, m_mock_actions->url()); -} - diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index 104fb4b..a255ef9 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -104,11 +104,14 @@ TEST_F(ExporterFixture, Publish) names.insert(names_strv[i]); // confirm the actions that we expect - EXPECT_EQ(1, names.count("activate-appointment")); - EXPECT_EQ(1, names.count("activate-desktop-settings")); - EXPECT_EQ(1, names.count("activate-phone-clock-app")); - EXPECT_EQ(1, names.count("activate-phone-settings")); - EXPECT_EQ(1, names.count("activate-planner")); + EXPECT_EQ(1, names.count("desktop.open-alarm-app")); + EXPECT_EQ(1, names.count("desktop.open-appointment")); + EXPECT_EQ(1, names.count("desktop.open-calendar-app")); + EXPECT_EQ(1, names.count("desktop.open-settings-app")); + EXPECT_EQ(1, names.count("phone.open-alarm-app")); + EXPECT_EQ(1, names.count("phone.open-appointment")); + EXPECT_EQ(1, names.count("phone.open-calendar-app")); + EXPECT_EQ(1, names.count("phone.open-settings-app")); EXPECT_EQ(1, names.count("calendar")); EXPECT_EQ(1, names.count("desktop_greeter-header")); EXPECT_EQ(1, names.count("desktop-header")); diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index d6ef424..c67b380 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -252,44 +252,95 @@ TEST_F(LiveActionsFixture, SetLocation) EXPECT_EQ(expected, m_state->settings->timezone_name.get()); } -TEST_F(LiveActionsFixture, OpenDesktopSettings) +/*** +**** +***/ + +TEST_F(LiveActionsFixture, 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) +{ + Appointment a; + a.uid = "some-uid"; + a.begin = DateTime::NowLocal(); + m_actions->desktop_open_appointment(a); + const std::string expected_substr = "evolution \"calendar:///?startdate="; + EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); +} + +TEST_F(LiveActionsFixture, 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) { - m_actions->open_desktop_settings(); + m_actions->desktop_open_settings_app(); const std::string expected_substr = "control-center"; EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); } -TEST_F(LiveActionsFixture, OpenPlanner) +/*** +**** +***/ + +namespace { - m_actions->open_planner(); - const std::string expected = "evolution -c calendar"; - EXPECT_EQ(expected, m_live_actions->last_cmd); + 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"; } -TEST_F(LiveActionsFixture, OpenPhoneSettings) +TEST_F(LiveActionsFixture, PhoneOpenAlarmApp) { - m_actions->open_phone_settings(); - const std::string expected = "settings:///system/time-date"; - EXPECT_EQ(expected, m_live_actions->last_url); + m_actions->phone_open_alarm_app(); + EXPECT_EQ(clock_app_url, m_live_actions->last_url); } -TEST_F(LiveActionsFixture, OpenPhoneClockApp) +TEST_F(LiveActionsFixture, PhoneOpenAppointment) { - m_actions->open_phone_clock_app(); - const std::string expected = "appid://com.ubuntu.clock/clock/current-user-version"; + Appointment a; + + a.uid = "some-uid"; + a.begin = DateTime::NowLocal(); + a.has_alarms = false; + m_actions->phone_open_appointment(a); + EXPECT_EQ(calendar_app_url, m_live_actions->last_url); + + a.has_alarms = true; + m_actions->phone_open_appointment(a); + EXPECT_EQ(clock_app_url, m_live_actions->last_url); + + a.url = "appid://blah"; + m_actions->phone_open_appointment(a); + EXPECT_EQ(a.url, m_live_actions->last_url); +} + +TEST_F(LiveActionsFixture, 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, OpenPlannerAt) +TEST_F(LiveActionsFixture, PhoneOpenSettingsApp) { - const auto now = DateTime::NowLocal(); - m_actions->open_planner_at(now); - const auto today_begins = now.add_full(0, 0, 0, -now.hour(), -now.minute(), -now.seconds()); - const auto gmt = today_begins.to_timezone("UTC"); - const auto expected = gmt.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); - EXPECT_EQ(expected, m_live_actions->last_cmd); + m_actions->phone_open_settings_app(); + const std::string expected = "settings:///system/time-date"; + EXPECT_EQ(expected, m_live_actions->last_url); } +/*** +**** +***/ + TEST_F(LiveActionsFixture, CalendarState) { // init the clock diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index 29d86b3..b485037 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -92,7 +92,16 @@ protected: void InspectCalendar(GMenuModel* menu_model, Menu::Profile profile) { gchar* str = nullptr; - const auto actions_expected = (profile == Menu::Desktop) || (profile == Menu::Phone); + + const char * expected_action; + + if (profile == Menu::Desktop) + expected_action = "indicator.desktop.open-calendar-app"; + else if (profile == Menu::Phone) + expected_action = "indicator.phone.open-calendar-app"; + else + expected_action = nullptr; + const auto calendar_expected = ((profile == Menu::Desktop) || (profile == Menu::DesktopGreeter)) && (m_state->settings->show_calendar.get()); @@ -113,8 +122,8 @@ protected: g_clear_pointer(&str, g_free); g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &str); - if (actions_expected) - EXPECT_STREQ("indicator.activate-planner", str); + if (expected_action != nullptr) + EXPECT_STREQ(expected_action, str); else EXPECT_TRUE(str == nullptr); g_clear_pointer(&str, g_free); @@ -131,8 +140,8 @@ protected: g_clear_pointer(&str, g_free); g_menu_model_get_item_attribute(section, 1, "activation-action", "s", &str); - if (actions_expected) - EXPECT_STREQ("indicator.activate-planner", str); + if (expected_action != nullptr) + EXPECT_STREQ(expected_action, str); else EXPECT_TRUE(str == nullptr); g_clear_pointer(&str, g_free); @@ -297,7 +306,7 @@ private: // there should be an "add event" button even if there aren't any appointments gchar* action = nullptr; EXPECT_TRUE(g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)); - const char* expected_action = "activate-planner"; + const char* expected_action = "desktop.open-calendar-app"; EXPECT_EQ(std::string("indicator.")+expected_action, action); EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), expected_action)); g_free(action); @@ -328,7 +337,7 @@ private: // check that there's a "clock app" menuitem even when there are no appointments auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); - const char* expected_action = "activate-phone-clock-app"; + const char* expected_action = "phone.open-alarm-app"; EXPECT_EQ(1, g_menu_model_get_n_items(section)); gchar* action = nullptr; EXPECT_TRUE(g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)); @@ -354,7 +363,7 @@ protected: void InspectAppointments(GMenuModel* menu_model, Menu::Profile profile) { - const auto can_open_planner = m_actions->can_open_planner(); + const auto can_open_planner = m_actions->desktop_has_calendar_app(); switch (profile) { @@ -443,9 +452,9 @@ protected: std::string expected_action; if (profile == Menu::Desktop) - expected_action = "indicator.activate-desktop-settings"; + expected_action = "indicator.desktop.open-settings-app"; else if (profile == Menu::Phone) - expected_action = "indicator.activate-phone-settings"; + expected_action = "indicator.phone.open-settings-app"; // get the Settings section auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); @@ -520,7 +529,7 @@ TEST_F(MenuFixture, Appointments) // toggle can_open_planner() and test the desktop again // to confirm that the "Add Event…" menuitem appears iff // there's a calendar available user-agent - m_mock_actions->set_can_open_planner (!m_actions->can_open_planner()); + m_mock_actions->set_desktop_has_calendar_app (!m_actions->desktop_has_calendar_app()); std::shared_ptr<Menu> menu = m_menu_factory->buildMenu(Menu::Desktop); InspectAppointments(menu->menu_model(), menu->profile()); } |