aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/actions-mock.h5
-rw-r--r--tests/geoclue-fixture.h2
-rw-r--r--tests/manual24
-rw-r--r--tests/manual-test-snap.cpp63
-rw-r--r--tests/planner-mock.h24
-rw-r--r--tests/state-mock.h12
-rw-r--r--tests/test-actions.cpp12
-rw-r--r--tests/test-clock-watcher.cpp172
-rw-r--r--tests/test-clock.cpp4
-rw-r--r--tests/test-live-actions.cpp11
-rw-r--r--tests/test-menus.cpp62
-rw-r--r--tests/test-planner.cpp23
-rw-r--r--tests/test-settings.cpp4
-rw-r--r--tests/test-utils.cpp2
-rw-r--r--tests/timezone-mock.h40
16 files changed, 398 insertions, 67 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3dcd151..7d590c9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -42,6 +42,7 @@ function(add_test_by_name name)
endfunction()
add_test_by_name(test-actions)
add_test_by_name(test-clock)
+add_test_by_name(test-clock-watcher)
add_test_by_name(test-exporter)
add_test_by_name(test-formatter)
add_test_by_name(test-live-actions)
@@ -52,6 +53,10 @@ add_test_by_name(test-settings)
add_test_by_name(test-timezone-file)
add_test_by_name(test-utils)
+set (TEST_NAME manual-test-snap)
+add_executable (${TEST_NAME} ${TEST_NAME}.cpp)
+add_dependencies (${TEST_NAME} libindicatordatetimeservice)
+target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS})
# disabling the timezone unit tests because they require
# https://code.launchpad.net/~ted/dbus-test-runner/multi-interface-test/+merge/199724
diff --git a/tests/actions-mock.h b/tests/actions-mock.h
index da93cb9..ebd8a4d 100644
--- a/tests/actions-mock.h
+++ b/tests/actions-mock.h
@@ -49,6 +49,8 @@ public:
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); }
void open_planner_at(const DateTime& date_time_) {
@@ -67,7 +69,10 @@ public:
m_url = url_;
}
+ void set_can_open_planner(bool b) { m_can_open_planner = b; }
+
private:
+ bool m_can_open_planner = true;
std::string m_url;
std::string m_zone;
std::string m_name;
diff --git a/tests/geoclue-fixture.h b/tests/geoclue-fixture.h
index 7e29018..0c597d3 100644
--- a/tests/geoclue-fixture.h
+++ b/tests/geoclue-fixture.h
@@ -95,7 +95,7 @@ class GeoclueFixture : public GlibFixture
// I've looked and can't find where this extra ref is coming from.
// is there an unbalanced ref to the bus in the test harness?!
- while (bus != NULL)
+ while (bus != nullptr)
{
g_object_unref (bus);
wait_msec (1000);
diff --git a/tests/manual b/tests/manual
new file mode 100644
index 0000000..17b4778
--- /dev/null
+++ b/tests/manual
@@ -0,0 +1,24 @@
+
+Test-case indicator-datetime/unity7-items-check
+<dl>
+ <dt>Log in to a Unity 7 user session</dt>
+ <dt>Go to the panel and click on the DateTime indicator</dt>
+ <dd>Ensure there are items in the menu</dd>
+</dl>
+
+Test-case indicator-datetime/unity7-greeter-items-check
+<dl>
+ <dt>Start a system and wait for the greeter or logout of the current user session</dt>
+ <dt>Go to the panel and click on the DateTime indicator</dt>
+ <dd>Ensure there are items in the menu</dd>
+</dl>
+
+Test-case indicator-datetime/unity8-items-check
+<dl>
+ <dt>Login to a user session running Unity 8</dt>
+ <dt>Pull down the top panel until it sticks open</dt>
+ <dt>Navigate through the tabs until "Upcoming" is shown</dt>
+ <dd>Upcoming is at the top of the menu</dd>
+ <dd>The menu is populated with items</dd>
+</dl>
+
diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp
new file mode 100644
index 0000000..51556cd
--- /dev/null
+++ b/tests/manual-test-snap.cpp
@@ -0,0 +1,63 @@
+
+/*
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * 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/>.
+ */
+
+#include <datetime/appointment.h>
+#include <datetime/snap.h>
+
+#include <glib.h>
+
+using namespace unity::indicator::datetime;
+
+/***
+****
+***/
+
+int main()
+{
+ Appointment a;
+ a.color = "green";
+ a.summary = "Alarm";
+ a.url = "alarm:///hello-world";
+ a.uid = "D4B57D50247291478ED31DED17FF0A9838DED402";
+ a.is_event = false;
+ a.is_daily = false;
+ a.has_alarms = true;
+ auto begin = g_date_time_new_local(2014,12,25,0,0,0);
+ auto end = g_date_time_add_full(begin,0,0,1,0,0,-1);
+ a.begin = begin;
+ a.end = end;
+ g_date_time_unref(end);
+ g_date_time_unref(begin);
+
+ auto loop = g_main_loop_new(nullptr, false);
+ auto show = [loop](const Appointment& appt){
+ g_message("You clicked 'show' for appt url '%s'", appt.url.c_str());
+ g_main_loop_quit(loop);
+ };
+ auto dismiss = [loop](const Appointment&){
+ g_message("You clicked 'dismiss'");
+ g_main_loop_quit(loop);
+ };
+
+ Snap snap;
+ snap(a, show, dismiss);
+ g_main_loop_run(loop);
+ return 0;
+}
diff --git a/tests/planner-mock.h b/tests/planner-mock.h
index 44d30c7..53109cf 100644
--- a/tests/planner-mock.h
+++ b/tests/planner-mock.h
@@ -20,22 +20,34 @@
#ifndef INDICATOR_DATETIME_PLANNER_MOCK_H
#define INDICATOR_DATETIME_PLANNER_MOCK_H
-#include <datetime/planner.h>
+#include <datetime/planner-range.h>
namespace unity {
namespace indicator {
namespace datetime {
/**
- * \brief Planner which does nothing on its own.
- * It requires its client must set its appointments property.
+ * \brief #RangePlanner which does nothing on its own.
+ * Its controller must set its appointments property.
*/
-class MockPlanner: public Planner
+class MockRangePlanner: public RangePlanner
{
public:
- MockPlanner() =default;
- virtual ~MockPlanner() =default;
+ MockRangePlanner():
+ m_range(std::pair<DateTime,DateTime>(DateTime::NowLocal(), DateTime::NowLocal()))
+ {
+ }
+
+ ~MockRangePlanner() =default;
+
+ core::Property<std::vector<Appointment>>& appointments() { return m_appointments; }
+ core::Property<std::pair<DateTime,DateTime>>& range() { return m_range; }
+
+private:
+ core::Property<std::vector<Appointment>> m_appointments;
+ core::Property<std::pair<DateTime,DateTime>> m_range;
};
+
} // namespace datetime
} // namespace indicator
diff --git a/tests/state-mock.h b/tests/state-mock.h
index 721b82f..792c60d 100644
--- a/tests/state-mock.h
+++ b/tests/state-mock.h
@@ -28,15 +28,21 @@ class MockState: public State
{
public:
std::shared_ptr<MockClock> mock_clock;
+ std::shared_ptr<MockRangePlanner> mock_range_planner;
MockState()
{
const DateTime now = DateTime::NowLocal();
mock_clock.reset(new MockClock(now));
- settings.reset(new Settings);
clock = std::dynamic_pointer_cast<Clock>(mock_clock);
- planner.reset(new MockPlanner);
- planner->time = now;
+
+ settings.reset(new Settings);
+
+ mock_range_planner.reset(new MockRangePlanner);
+ auto range_planner = std::dynamic_pointer_cast<RangePlanner>(mock_range_planner);
+ calendar_month.reset(new MonthPlanner(range_planner, now));
+ calendar_upcoming.reset(new UpcomingPlanner(range_planner, now));
+
locations.reset(new Locations);
}
};
diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp
index 1865cfd..5d1efd5 100644
--- a/tests/test-actions.cpp
+++ b/tests/test-actions.cpp
@@ -150,10 +150,10 @@ TEST_F(ActionsFixture, SetCalendarDate)
// confirm that Planner.time gets changed to that date when we
// activate the 'calendar' action with that date's time_t as the arg
- EXPECT_NE (now, m_state->planner->time.get());
+ EXPECT_NE (now, m_state->calendar_month->month().get());
auto v = g_variant_new_int64(now.to_unix());
g_action_group_activate_action (action_group, action_name, v);
- EXPECT_EQ (now, m_state->planner->time.get());
+ EXPECT_EQ (now, m_state->calendar_month->month().get());
}
TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate)
@@ -171,11 +171,12 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate)
const auto now = m_state->clock->localtime();
auto next_week = g_date_time_add_weeks(now.get(), 1);
const auto next_week_unix = g_date_time_to_unix(next_week);
+ g_date_time_unref(next_week);
g_action_group_activate_action (action_group, "calendar", g_variant_new_int64(next_week_unix));
// confirm the planner and calendar action state moved a week into the future
// but that m_state->clock is unchanged
- EXPECT_EQ(next_week_unix, m_state->planner->time.get().to_unix());
+ EXPECT_EQ(next_week_unix, m_state->calendar_month->month().get().to_unix());
EXPECT_EQ(now, m_state->clock->localtime());
auto calendar_state = g_action_group_get_action_state(action_group, "calendar");
EXPECT_TRUE(calendar_state != nullptr);
@@ -196,7 +197,7 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate)
g_action_group_change_action_state(action_group, "calendar-active", g_variant_new_boolean(true));
// confirm the planner and calendar action state were reset back to m_state->clock's time
- EXPECT_EQ(now.to_unix(), m_state->planner->time.get().to_unix());
+ EXPECT_EQ(now.to_unix(), m_state->calendar_month->month().get().to_unix());
EXPECT_EQ(now, m_state->clock->localtime());
calendar_state = g_action_group_get_action_state(action_group, "calendar");
EXPECT_TRUE(calendar_state != nullptr);
@@ -215,7 +216,8 @@ TEST_F(ActionsFixture, OpenAppointment)
Appointment appt;
appt.uid = "some arbitrary uid";
appt.url = "http://www.canonical.com/";
- m_state->planner->upcoming.set(std::vector<Appointment>({appt}));
+ 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();
diff --git a/tests/test-clock-watcher.cpp b/tests/test-clock-watcher.cpp
new file mode 100644
index 0000000..2425fe8
--- /dev/null
+++ b/tests/test-clock-watcher.cpp
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2014 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/clock-watcher.h>
+
+#include <gtest/gtest.h>
+
+#include "state-fixture.h"
+
+using namespace unity::indicator::datetime;
+
+class ClockWatcherFixture: public StateFixture
+{
+private:
+
+ typedef StateFixture super;
+
+protected:
+
+ std::vector<std::string> m_triggered;
+ std::unique_ptr<ClockWatcher> m_watcher;
+ std::shared_ptr<RangePlanner> m_range_planner;
+ std::shared_ptr<UpcomingPlanner> m_upcoming;
+
+ void SetUp()
+ {
+ super::SetUp();
+
+ m_range_planner.reset(new MockRangePlanner);
+ m_upcoming.reset(new UpcomingPlanner(m_range_planner, m_state->clock->localtime()));
+ m_watcher.reset(new ClockWatcherImpl(m_state->clock, m_upcoming));
+ m_watcher->alarm_reached().connect([this](const Appointment& appt){
+ m_triggered.push_back(appt.uid);
+ });
+
+ EXPECT_TRUE(m_triggered.empty());
+ }
+
+ void TearDown()
+ {
+ m_triggered.clear();
+ m_watcher.reset();
+ m_upcoming.reset();
+ m_range_planner.reset();
+
+ super::TearDown();
+ }
+
+ std::vector<Appointment> build_some_appointments()
+ {
+ const auto now = m_state->clock->localtime();
+ auto tomorrow = g_date_time_add_days (now.get(), 1);
+ auto tomorrow_begin = g_date_time_add_full (tomorrow, 0, 0, 0,
+ -g_date_time_get_hour(tomorrow),
+ -g_date_time_get_minute(tomorrow),
+ -g_date_time_get_seconds(tomorrow));
+ auto tomorrow_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1);
+
+ 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 = tomorrow_begin;
+ a1.end = tomorrow_end;
+
+ auto ubermorgen_begin = g_date_time_add_days (tomorrow, 1);
+ auto ubermorgen_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1);
+
+ 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 = ubermorgen_begin;
+ a2.end = ubermorgen_end;
+
+ // cleanup
+ g_date_time_unref(ubermorgen_end);
+ g_date_time_unref(ubermorgen_begin);
+ g_date_time_unref(tomorrow_end);
+ g_date_time_unref(tomorrow_begin);
+ g_date_time_unref(tomorrow);
+
+ return std::vector<Appointment>({a1, a2});
+ }
+};
+
+/***
+****
+***/
+
+TEST_F(ClockWatcherFixture, AppointmentsChanged)
+{
+ // Add some appointments to the planner.
+ // One of these matches our state's localtime, so that should get triggered.
+ std::vector<Appointment> a = build_some_appointments();
+ a[0].begin = m_state->clock->localtime();
+ m_range_planner->appointments().set(a);
+
+ // Confirm that it got fired
+ EXPECT_EQ(1, m_triggered.size());
+ EXPECT_EQ(a[0].uid, m_triggered[0]);
+}
+
+
+TEST_F(ClockWatcherFixture, TimeChanged)
+{
+ // Add some appointments to the planner.
+ // Neither of these match the state's localtime, so nothing should be triggered.
+ std::vector<Appointment> a = build_some_appointments();
+ m_range_planner->appointments().set(a);
+ EXPECT_TRUE(m_triggered.empty());
+
+ // Set the state's clock to a time that matches one of the appointments().
+ // That appointment should get triggered.
+ m_mock_state->mock_clock->set_localtime(a[1].begin);
+ EXPECT_EQ(1, m_triggered.size());
+ EXPECT_EQ(a[1].uid, m_triggered[0]);
+}
+
+
+TEST_F(ClockWatcherFixture, MoreThanOne)
+{
+ const auto now = m_state->clock->localtime();
+ std::vector<Appointment> a = build_some_appointments();
+ a[0].begin = a[1].begin = now;
+ m_range_planner->appointments().set(a);
+
+ EXPECT_EQ(2, m_triggered.size());
+ EXPECT_EQ(a[0].uid, m_triggered[0]);
+ EXPECT_EQ(a[1].uid, m_triggered[1]);
+}
+
+
+TEST_F(ClockWatcherFixture, NoDuplicates)
+{
+ // Setup: add an appointment that gets triggered.
+ const auto now = m_state->clock->localtime();
+ const std::vector<Appointment> appointments = build_some_appointments();
+ std::vector<Appointment> a;
+ a.push_back(appointments[0]);
+ a[0].begin = now;
+ m_range_planner->appointments().set(a);
+ EXPECT_EQ(1, m_triggered.size());
+ EXPECT_EQ(a[0].uid, m_triggered[0]);
+
+ // Now change the appointment vector by adding one to it.
+ // Confirm that the ClockWatcher doesn't re-trigger a[0]
+ a.push_back(appointments[1]);
+ m_range_planner->appointments().set(a);
+ EXPECT_EQ(1, m_triggered.size());
+ EXPECT_EQ(a[0].uid, m_triggered[0]);
+}
diff --git a/tests/test-clock.cpp b/tests/test-clock.cpp
index 4287e1c..a4924b3 100644
--- a/tests/test-clock.cpp
+++ b/tests/test-clock.cpp
@@ -37,12 +37,12 @@ class ClockFixture: public TestDBusFixture
void emitPrepareForSleep()
{
g_dbus_connection_emit_signal(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr),
- NULL,
+ nullptr,
"/org/freedesktop/login1", // object path
"org.freedesktop.login1.Manager", // interface
"PrepareForSleep", // signal name
g_variant_new("(b)", FALSE),
- NULL);
+ nullptr);
}
};
diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp
index eab8596..d6ef424 100644
--- a/tests/test-live-actions.cpp
+++ b/tests/test-live-actions.cpp
@@ -284,7 +284,9 @@ 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\"");
+ 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);
}
@@ -295,7 +297,8 @@ TEST_F(LiveActionsFixture, CalendarState)
const DateTime now (tmp);
g_date_time_unref (tmp);
m_mock_state->mock_clock->set_localtime (now);
- m_state->planner->time.set(now);
+ m_state->calendar_month->month().set(now);
+ //m_state->planner->time.set(now);
///
/// Test the default calendar state.
@@ -315,7 +318,7 @@ TEST_F(LiveActionsFixture, CalendarState)
// calendar-day should be in sync with m_state->calendar_day
v = g_variant_lookup_value (calendar_state, "calendar-day", G_VARIANT_TYPE_INT64);
EXPECT_TRUE (v != nullptr);
- EXPECT_EQ (m_state->planner->time.get().to_unix(), g_variant_get_int64(v));
+ EXPECT_EQ (m_state->calendar_month->month().get().to_unix(), g_variant_get_int64(v));
g_clear_pointer (&v, g_variant_unref);
// show-week-numbers should be false because MockSettings defaults everything to 0
@@ -356,7 +359,7 @@ TEST_F(LiveActionsFixture, CalendarState)
a2.begin = next_begin;
a2.end = next_end;
- m_state->planner->this_month.set(std::vector<Appointment>({a1, a2}));
+ m_state->calendar_month->appointments().set(std::vector<Appointment>({a1, a2}));
///
/// Now test the calendar state again.
diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp
index 73d6036..29d86b3 100644
--- a/tests/test-menus.cpp
+++ b/tests/test-menus.cpp
@@ -252,15 +252,17 @@ private:
void InspectAppointmentMenuItems(GMenuModel* section,
int first_appt_index,
- const std::vector<Appointment>& appointments)
+ const std::vector<Appointment>& appointments,
+ bool can_open_planner)
{
// try adding a few appointments and see if the menu updates itself
- m_state->planner->upcoming.set(appointments);
+ m_state->calendar_upcoming->appointments().set(appointments);
wait_msec(); // wait a moment for the menu to update
//auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU);
//auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION);
- EXPECT_EQ(appointments.size()+1, g_menu_model_get_n_items(section));
+ const int n_add_event_buttons = can_open_planner ? 1 : 0;
+ EXPECT_EQ(n_add_event_buttons + appointments.size(), g_menu_model_get_n_items(section));
for (int i=0, n=appointments.size(); i<n; i++)
InspectAppointmentMenuItem(section, first_appt_index+i, appointments[i]);
@@ -269,8 +271,10 @@ private:
//g_clear_object(&submenu);
}
- void InspectDesktopAppointments(GMenuModel* menu_model)
+ void InspectDesktopAppointments(GMenuModel* menu_model, bool can_open_planner)
{
+ const int n_add_event_buttons = can_open_planner ? 1 : 0;
+
// get the Appointments section
auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU);
@@ -281,42 +285,45 @@ private:
EXPECT_EQ(0, g_menu_model_get_n_items(section));
g_clear_object(&section);
- // when "show_events" is true,
- // there should be an "add event" button even if there aren't any appointments
std::vector<Appointment> appointments;
m_state->settings->show_events.set(true);
- m_state->planner->upcoming.set(appointments);
+ m_state->calendar_upcoming->appointments().set(appointments);
wait_msec();
section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION);
- 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));
- const char* expected_action = "activate-planner";
- EXPECT_EQ(std::string("indicator.")+expected_action, action);
- EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), expected_action));
- g_free(action);
+ EXPECT_EQ(n_add_event_buttons, g_menu_model_get_n_items(section));
+ if (can_open_planner)
+ {
+ // when "show_events" is true,
+ // 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";
+ EXPECT_EQ(std::string("indicator.")+expected_action, action);
+ EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), expected_action));
+ g_free(action);
+ }
g_clear_object(&section);
// try adding a few appointments and see if the menu updates itself
appointments = build_some_appointments();
- m_state->planner->upcoming.set(appointments);
+ m_state->calendar_upcoming->appointments().set(appointments);
wait_msec(); // wait a moment for the menu to update
section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION);
- EXPECT_EQ(3, g_menu_model_get_n_items(section));
- InspectAppointmentMenuItems(section, 0, appointments);
+ EXPECT_EQ(n_add_event_buttons + 2, g_menu_model_get_n_items(section));
+ InspectAppointmentMenuItems(section, 0, appointments, can_open_planner);
g_clear_object(&section);
// cleanup
g_clear_object(&submenu);
}
- void InspectPhoneAppointments(GMenuModel* menu_model)
+ void InspectPhoneAppointments(GMenuModel* menu_model, bool can_open_planner)
{
auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU);
// clear all the appointments
std::vector<Appointment> appointments;
- m_state->planner->upcoming.set(appointments);
+ m_state->calendar_upcoming->appointments().set(appointments);
wait_msec(); // wait a moment for the menu to update
// check that there's a "clock app" menuitem even when there are no appointments
@@ -332,11 +339,11 @@ private:
// add some appointments and test them
appointments = build_some_appointments();
- m_state->planner->upcoming.set(appointments);
+ m_state->calendar_upcoming->appointments().set(appointments);
wait_msec(); // wait a moment for the menu to update
section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION);
EXPECT_EQ(3, g_menu_model_get_n_items(section));
- InspectAppointmentMenuItems(section, 1, appointments);
+ InspectAppointmentMenuItems(section, 1, appointments, can_open_planner);
g_clear_object(&section);
// cleanup
@@ -347,10 +354,12 @@ protected:
void InspectAppointments(GMenuModel* menu_model, Menu::Profile profile)
{
+ const auto can_open_planner = m_actions->can_open_planner();
+
switch (profile)
{
case Menu::Desktop:
- InspectDesktopAppointments(menu_model);
+ InspectDesktopAppointments(menu_model, can_open_planner);
break;
case Menu::DesktopGreeter:
@@ -358,7 +367,7 @@ protected:
break;
case Menu::Phone:
- InspectPhoneAppointments(menu_model);
+ InspectPhoneAppointments(menu_model, can_open_planner);
break;
case Menu::PhoneGreeter:
@@ -507,6 +516,13 @@ TEST_F(MenuFixture, Appointments)
{
for(auto& menu : m_menus)
InspectAppointments(menu->menu_model(), menu->profile());
+
+ // 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());
+ std::shared_ptr<Menu> menu = m_menu_factory->buildMenu(Menu::Desktop);
+ InspectAppointments(menu->menu_model(), menu->profile());
}
TEST_F(MenuFixture, Locations)
diff --git a/tests/test-planner.cpp b/tests/test-planner.cpp
index b476ee8..8f1590c 100644
--- a/tests/test-planner.cpp
+++ b/tests/test-planner.cpp
@@ -18,19 +18,18 @@
*/
#include "glib-fixture.h"
+#include "timezone-mock.h"
#include <datetime/appointment.h>
#include <datetime/clock-mock.h>
#include <datetime/date-time.h>
#include <datetime/planner.h>
-#include <datetime/planner-eds.h>
+#include <datetime/planner-range.h>
#include <langinfo.h>
#include <locale.h>
-using unity::indicator::datetime::Appointment;
-using unity::indicator::datetime::DateTime;
-using unity::indicator::datetime::PlannerEds;
+using namespace unity::indicator::datetime;
/***
****
@@ -38,22 +37,6 @@ using unity::indicator::datetime::PlannerEds;
typedef GlibFixture PlannerFixture;
-TEST_F(PlannerFixture, EDS)
-{
- PlannerEds planner;
- wait_msec(100);
-
- auto now = g_date_time_new_now_local();
- planner.time.set(DateTime(now));
- wait_msec(2500);
-
- std::vector<Appointment> this_month = planner.this_month.get();
- std::cerr << this_month.size() << " appointments this month" << std::endl;
- for(const auto& a : this_month)
- std::cerr << a.summary << std::endl;
-}
-
-
TEST_F(PlannerFixture, HelloWorld)
{
auto halloween = g_date_time_new_local(2020, 10, 31, 18, 30, 59);
diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp
index 980e7fa..707247d 100644
--- a/tests/test-settings.cpp
+++ b/tests/test-settings.cpp
@@ -167,8 +167,8 @@ TEST_F(SettingsFixture, Locations)
{
const auto key = SETTINGS_LOCATIONS_S;
- const gchar* astrv[] = {"America/Los_Angeles Oakland", "America/Chicago Oklahoma City", "Europe/London London", NULL};
- const gchar* bstrv[] = {"America/Denver", "Europe/London London", "Europe/Berlin Berlin", NULL};
+ const gchar* astrv[] = {"America/Los_Angeles Oakland", "America/Chicago Oklahoma City", "Europe/London London", nullptr};
+ const gchar* bstrv[] = {"America/Denver", "Europe/London London", "Europe/Berlin Berlin", nullptr};
const std::vector<std::string> av = strv_to_vector(astrv);
const std::vector<std::string> bv = strv_to_vector(bstrv);
diff --git a/tests/test-utils.cpp b/tests/test-utils.cpp
index 036c13f..97f07ed 100644
--- a/tests/test-utils.cpp
+++ b/tests/test-utils.cpp
@@ -59,7 +59,7 @@ namespace
const char* location;
const char* expected_name;
} beautify_timezone_test_cases[] = {
- { "America/Chicago", NULL, "Chicago" },
+ { "America/Chicago", nullptr, "Chicago" },
{ "America/Chicago", "America/Chicago", "Chicago" },
{ "America/Chicago", "America/Chigago Chicago", "Chicago" },
{ "America/Chicago", "America/Chicago Oklahoma City", "Oklahoma City" },
diff --git a/tests/timezone-mock.h b/tests/timezone-mock.h
new file mode 100644
index 0000000..67584cb
--- /dev/null
+++ b/tests/timezone-mock.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2014 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_DATETIME_TIMEZONE_MOCK_H
+#define INDICATOR_DATETIME_TIMEZONE_MOCK_H
+
+#include <datetime/timezone.h>
+
+namespace unity {
+namespace indicator {
+namespace datetime {
+
+class MockTimezone: public Timezone
+{
+public:
+ MockTimezone() =default;
+ ~MockTimezone() =default;
+};
+
+} // namespace datetime
+} // namespace indicator
+} // namespace unity
+
+#endif // INDICATOR_DATETIME_TIMEZONE_MOCK_H