aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-25 16:54:41 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-25 16:54:41 -0600
commit7b09a0ff5652bdca7c8d8e046d2af6a696f94147 (patch)
treea9adbfddde6f0693ab2bb2e01c875cd9929669cf /tests
parentaad7e86a109aeec75b3772cda20478363f966745 (diff)
downloadayatana-indicator-datetime-7b09a0ff5652bdca7c8d8e046d2af6a696f94147.tar.gz
ayatana-indicator-datetime-7b09a0ff5652bdca7c8d8e046d2af6a696f94147.tar.bz2
ayatana-indicator-datetime-7b09a0ff5652bdca7c8d8e046d2af6a696f94147.zip
sync the exported calendar state with the #State backend
Diffstat (limited to 'tests')
-rw-r--r--tests/actions-mock.h8
-rw-r--r--tests/state-mock.h1
-rw-r--r--tests/test-actions.cpp19
-rw-r--r--tests/test-live-actions.cpp114
4 files changed, 127 insertions, 15 deletions
diff --git a/tests/actions-mock.h b/tests/actions-mock.h
index 112900b..da93cb9 100644
--- a/tests/actions-mock.h
+++ b/tests/actions-mock.h
@@ -35,8 +35,7 @@ public:
~MockActions() =default;
enum Action { OpenDesktopSettings, OpenPhoneSettings, OpenPhoneClockApp,
- OpenPlanner, OpenPlannerAt, OpenAppointment,
- SetLocation, SetCalendarDate };
+ OpenPlanner, OpenPlannerAt, OpenAppointment, 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; }
@@ -68,11 +67,6 @@ public:
m_url = url_;
}
- void set_calendar_date(const DateTime& date_time_) {
- m_history.push_back(SetCalendarDate);
- m_date_time = date_time_;
- }
-
private:
std::string m_url;
std::string m_zone;
diff --git a/tests/state-mock.h b/tests/state-mock.h
index 64ab08b..721b82f 100644
--- a/tests/state-mock.h
+++ b/tests/state-mock.h
@@ -38,7 +38,6 @@ public:
planner.reset(new MockPlanner);
planner->time = now;
locations.reset(new Locations);
- calendar_day = now;
}
};
diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp
index 4329608..c30d1fb 100644
--- a/tests/test-actions.cpp
+++ b/tests/test-actions.cpp
@@ -137,18 +137,23 @@ TEST_F(ActionsFixture, SetLocation)
TEST_F(ActionsFixture, SetCalendarDate)
{
+ // confirm that such an action exists
const auto action_name = "calendar";
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 unix = m_state->clock->localtime().to_unix();
- auto v = g_variant_new_int64(unix);
- g_action_group_activate_action(action_group, action_name, v);
- const auto expected_action = MockActions::SetCalendarDate;
- ASSERT_EQ(1, m_mock_actions->history().size());
- EXPECT_EQ(expected_action, m_mock_actions->history()[0]);
- EXPECT_EQ(unix, m_mock_actions->date_time().to_unix());
+ // pick an arbitrary DateTime...
+ auto tmp = g_date_time_new_local(2010, 1, 2, 3, 4, 5);
+ const auto now = DateTime(tmp);
+ g_date_time_unref(tmp);
+
+ // 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());
+ 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());
}
TEST_F(ActionsFixture, OpenAppointment)
diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp
index d3d7720..562b358 100644
--- a/tests/test-live-actions.cpp
+++ b/tests/test-live-actions.cpp
@@ -287,3 +287,117 @@ TEST_F(LiveActionsFixture, OpenPlannerAt)
const std::string expected = now.format("evolution \"calendar:///?startdate=%Y%m%d\"");
EXPECT_EQ(expected, m_live_actions->last_cmd);
}
+
+TEST_F(LiveActionsFixture, CalendarState)
+{
+ // init the clock
+ auto tmp = g_date_time_new_local (2014, 1, 1, 0, 0, 0);
+ const DateTime now (tmp);
+ g_date_time_unref (tmp);
+ m_mock_state->mock_clock->set_localtime (now);
+ m_state->planner->time.set(now);
+
+ ///
+ /// Test the default calendar state.
+ ///
+
+ auto action_group = m_actions->action_group();
+ auto calendar_state = g_action_group_get_action_state (action_group, "calendar");
+ EXPECT_TRUE (calendar_state != nullptr);
+ EXPECT_TRUE (g_variant_is_of_type (calendar_state, G_VARIANT_TYPE_DICTIONARY));
+
+ // there's nothing in the planner yet, so appointment-days should be an empty array
+ auto v = g_variant_lookup_value (calendar_state, "appointment-days", G_VARIANT_TYPE_ARRAY);
+ EXPECT_TRUE (v != nullptr);
+ EXPECT_EQ (0, g_variant_n_children (v));
+ g_clear_pointer (&v, g_variant_unref);
+
+ // 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));
+ g_clear_pointer (&v, g_variant_unref);
+
+ // show-week-numbers should be false because MockSettings defaults everything to 0
+ v = g_variant_lookup_value (calendar_state, "show-week-numbers", G_VARIANT_TYPE_BOOLEAN);
+ EXPECT_TRUE (v != nullptr);
+ EXPECT_FALSE (g_variant_get_boolean (v));
+ g_clear_pointer (&v, g_variant_unref);
+
+ // cleanup this step
+ g_clear_pointer (&calendar_state, g_variant_unref);
+
+
+ ///
+ /// Now add appointments to the planner and confirm that the state keeps in sync
+ ///
+
+ 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;
+ a1.color = "green";
+ a1.summary = "write unit tests";
+ a1.url = "http://www.ubuntu.com/";
+ a1.uid = "D4B57D50247291478ED31DED17FF0A9838DED402";
+ a1.begin = tomorrow_begin;
+ a1.end = tomorrow_end;
+
+ auto next_begin = g_date_time_add_days (tomorrow_begin, 1);
+ auto next_end = g_date_time_add_full (next_begin, 0, 0, 1, 0, 0, -1);
+ Appointment a2;
+ a2.color = "orange";
+ a2.summary = "code review";
+ a2.url = "http://www.ubuntu.com/";
+ a2.uid = "2756ff7de3745bbffd65d2e4779c37c7ca60d843";
+ a2.begin = next_begin;
+ a2.end = next_end;
+
+ m_state->planner->thisMonth.set(std::vector<Appointment>({a1, a2}));
+
+ ///
+ /// Now test the calendar state again.
+ /// The thisMonth field should now contain the appointments we just added.
+ ///
+
+ calendar_state = g_action_group_get_action_state (action_group, "calendar");
+ v = g_variant_lookup_value (calendar_state, "appointment-days", G_VARIANT_TYPE_ARRAY);
+ EXPECT_TRUE (v != nullptr);
+ int i;
+ g_variant_get_child (v, 0, "i", &i);
+ EXPECT_EQ (g_date_time_get_day_of_month(a1.begin.get()), i);
+ g_variant_get_child (v, 1, "i", &i);
+ EXPECT_EQ (g_date_time_get_day_of_month(a2.begin.get()), i);
+ g_clear_pointer(&v, g_variant_unref);
+ g_clear_pointer(&calendar_state, g_variant_unref);
+
+ // cleanup this step
+ g_date_time_unref (next_end);
+ g_date_time_unref (next_begin);
+ g_date_time_unref (tomorrow_end);
+ g_date_time_unref (tomorrow_begin);
+ g_date_time_unref (tomorrow);
+
+ ///
+ /// Confirm that the action state's dictionary
+ /// keeps in sync with settings.show_week_numbers
+ ///
+
+ auto b = m_state->settings->show_week_numbers.get();
+ for (i=0; i<2; i++)
+ {
+ b = !b;
+ m_state->settings->show_week_numbers.set(b);
+
+ calendar_state = g_action_group_get_action_state (action_group, "calendar");
+ v = g_variant_lookup_value (calendar_state, "show-week-numbers", G_VARIANT_TYPE_BOOLEAN);
+ EXPECT_TRUE(v != nullptr);
+ EXPECT_EQ(b, g_variant_get_boolean(v));
+
+ g_clear_pointer(&v, g_variant_unref);
+ g_clear_pointer(&calendar_state, g_variant_unref);
+ }
+}