aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/planner-mock.h27
-rw-r--r--tests/state-mock.h12
-rw-r--r--tests/test-actions.cpp12
-rw-r--r--tests/test-clock-watcher.cpp20
-rw-r--r--tests/test-live-actions.cpp7
-rw-r--r--tests/test-menus.cpp10
-rw-r--r--tests/test-planner.cpp21
7 files changed, 64 insertions, 45 deletions
diff --git a/tests/planner-mock.h b/tests/planner-mock.h
index 44d30c7..67e550c 100644
--- a/tests/planner-mock.h
+++ b/tests/planner-mock.h
@@ -20,12 +20,13 @@
#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 {
+#if 0
/**
* \brief Planner which does nothing on its own.
* It requires its client must set its appointments property.
@@ -35,7 +36,31 @@ class MockPlanner: public Planner
public:
MockPlanner() =default;
virtual ~MockPlanner() =default;
+ core::Property<std::vector<Appointment>>& appointments() { return m_appointments; }
+
+private:
+ core::Property<std::vector<Appointment>> m_appointments;
+};
+#endif
+
+/**
+ * \brief #RangePlanner which does nothing on its own.
+ * Its controller must set its appointments property.
+ */
+class MockRangePlanner: public RangePlanner
+{
+public:
+ MockRangePlanner() =default;
+ ~MockRangePlanner() =default;
+ core::Property<std::vector<Appointment>>& appointments() { return m_appointments; }
+
+protected:
+ void rebuild_now(){}
+
+private:
+ core::Property<std::vector<Appointment>> m_appointments;
};
+
} // 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
index 79b8485..2425fe8 100644
--- a/tests/test-clock-watcher.cpp
+++ b/tests/test-clock-watcher.cpp
@@ -35,12 +35,16 @@ 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_watcher.reset(new ClockWatcherImpl(m_state));
+ 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);
});
@@ -52,6 +56,8 @@ protected:
{
m_triggered.clear();
m_watcher.reset();
+ m_upcoming.reset();
+ m_range_planner.reset();
super::TearDown();
}
@@ -108,7 +114,7 @@ TEST_F(ClockWatcherFixture, AppointmentsChanged)
// 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_state->planner->upcoming.set(a);
+ m_range_planner->appointments().set(a);
// Confirm that it got fired
EXPECT_EQ(1, m_triggered.size());
@@ -121,10 +127,10 @@ 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_state->planner->upcoming.set(a);
+ 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.
+ // 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());
@@ -137,7 +143,7 @@ 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_state->planner->upcoming.set(a);
+ m_range_planner->appointments().set(a);
EXPECT_EQ(2, m_triggered.size());
EXPECT_EQ(a[0].uid, m_triggered[0]);
@@ -153,14 +159,14 @@ TEST_F(ClockWatcherFixture, NoDuplicates)
std::vector<Appointment> a;
a.push_back(appointments[0]);
a[0].begin = now;
- m_state->planner->upcoming.set(a);
+ 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_state->planner->upcoming.set(a);
+ 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-live-actions.cpp b/tests/test-live-actions.cpp
index eab8596..ffba4ce 100644
--- a/tests/test-live-actions.cpp
+++ b/tests/test-live-actions.cpp
@@ -295,7 +295,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 +316,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 +357,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..61d1295 100644
--- a/tests/test-menus.cpp
+++ b/tests/test-menus.cpp
@@ -255,7 +255,7 @@ private:
const std::vector<Appointment>& appointments)
{
// 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);
@@ -285,7 +285,7 @@ private:
// 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));
@@ -299,7 +299,7 @@ private:
// 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));
@@ -316,7 +316,7 @@ private:
// 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,7 +332,7 @@ 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));
diff --git a/tests/test-planner.cpp b/tests/test-planner.cpp
index 6f602f4..4694cf5 100644
--- a/tests/test-planner.cpp
+++ b/tests/test-planner.cpp
@@ -37,27 +37,6 @@ using namespace unity::indicator::datetime;
typedef GlibFixture PlannerFixture;
-TEST_F(PlannerFixture, EDS)
-{
- auto tmp = g_date_time_new_now_local();
- const auto now = DateTime(tmp);
- g_date_time_unref(tmp);
-
- std::shared_ptr<Clock> clock(new MockClock(now));
- std::shared_ptr<Timezone> tz(new MockTimezone);
- PlannerEds planner(clock, tz);
- wait_msec(100);
-
- planner.time.set(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);