aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-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.cpp20
-rw-r--r--tests/test-live-actions.cpp7
-rw-r--r--tests/test-menus.cpp10
-rw-r--r--tests/test-planner.cpp23
-rw-r--r--tests/timezone-mock.h40
8 files changed, 98 insertions, 50 deletions
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
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 452cbfc..29d86b3 100644
--- a/tests/test-menus.cpp
+++ b/tests/test-menus.cpp
@@ -256,7 +256,7 @@ private:
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);
@@ -287,7 +287,7 @@ private:
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(n_add_event_buttons, g_menu_model_get_n_items(section));
@@ -306,7 +306,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(n_add_event_buttons + 2, g_menu_model_get_n_items(section));
@@ -323,7 +323,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
@@ -339,7 +339,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 1923ba1..8f1590c 100644
--- a/tests/test-planner.cpp
+++ b/tests/test-planner.cpp
@@ -18,12 +18,13 @@
*/
#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>
@@ -36,26 +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));
- PlannerEds planner(clock);
- 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);
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