From ee64bb2698adfe27e55615a8856b0e2c78ad8469 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 14 Jan 2014 23:07:10 -0600 Subject: Function: add fully-tested ActionGroups, per-profile Menus, state object. Form: Add code annotations/comments. Remove dead code. Use Mir style guide. Todo: GSettings toggles, sync with new dbus-test-runner API, get GNOME Panel building again --- src/actions.cpp | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 src/actions.cpp (limited to 'src/actions.cpp') diff --git a/src/actions.cpp b/src/actions.cpp new file mode 100644 index 0000000..4efe950 --- /dev/null +++ b/src/actions.cpp @@ -0,0 +1,215 @@ +/* + * Copyright 2013 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 . + * + * Authors: + * Charles Kerr + */ + +#include +#include // split_settings_location() + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +namespace +{ + +void on_desktop_settings_activated(GSimpleAction * /*action*/, + GVariant * /*param*/, + gpointer gself) +{ + static_cast(gself)->open_desktop_settings(); +} + +void on_phone_settings_activated(GSimpleAction * /*action*/, + GVariant * /*param*/, + gpointer gself) +{ + static_cast(gself)->open_phone_settings(); +} + +void on_phone_clock_activated(GSimpleAction * /*action*/, + GVariant * /*param*/, + gpointer gself) +{ + static_cast(gself)->open_phone_clock_app(); +} + +void on_activate_appointment(GSimpleAction * /*action*/, + GVariant * param, + gpointer gself) +{ + const auto uid = g_variant_get_string(param, nullptr); + auto self = static_cast(gself); + + g_return_if_fail(uid && *uid); + + // find url of the upcoming appointment with this uid + for (auto& appt : self->state()->planner->upcoming.get()) + { + if (appt.uid == uid) + { + const auto url = appt.url; + g_debug("%s: uid[%s] -> url[%s]", G_STRFUNC, uid, url.c_str()); + self->open_appointment(url); + break; + } + } +} + +void on_activate_planner(GSimpleAction * /*action*/, + GVariant * param, + gpointer gself) +{ + const auto at = g_variant_get_int64(param); + auto self = static_cast(gself); + + if (at) + { + auto gdt = g_date_time_new_from_unix_local(at); + self->open_planner_at(DateTime(gdt)); + g_date_time_unref(gdt); + } + else // no time specified... + { + self->open_planner(); + } +} + +void on_set_location(GSimpleAction * /*action*/, + GVariant * param, + gpointer gself) +{ + char * zone; + char * name; + split_settings_location(g_variant_get_string(param, nullptr), &zone, &name); + static_cast(gself)->set_location(zone, name); + g_free(name); + g_free(zone); +} + +static void on_calendar_activated(GSimpleAction * /*action*/, + GVariant * state, + gpointer gself) +{ + const time_t t = g_variant_get_int64(state); + + g_return_if_fail(t != 0); + + static_cast(gself)->set_calendar_date(DateTime(t)); +} + +GVariant* create_default_header_state() +{ + GVariantBuilder b; + g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(&b, "{sv}", "accessible-desc", g_variant_new_string("accessible-desc")); + g_variant_builder_add(&b, "{sv}", "label", g_variant_new_string("label")); + g_variant_builder_add(&b, "{sv}", "title", g_variant_new_string("title")); + g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean(true)); + return g_variant_builder_end(&b); +} + +GVariant* create_calendar_state(std::shared_ptr& state) +{ + gboolean days[32] = { 0 }; + for(const auto& appt : state->planner->thisMonth.get()) + days[appt.begin.day_of_month()] = true; + + GVariantBuilder day_builder; + g_variant_builder_init(&day_builder, G_VARIANT_TYPE("ai")); + for (int i=0; icalendar_day.get().to_unix()); + g_variant_builder_add(&dict_builder, "{sv}", key, v); + + key = "show-week-numbers"; + v = g_variant_new_boolean(state->show_week_numbers.get()); + g_variant_builder_add(&dict_builder, "{sv}", key, v); + + return g_variant_builder_end(&dict_builder); +} +} // anonymous namespace + +/*** +**** +***/ + +Actions::Actions(std::shared_ptr& state): + m_state(state), + m_actions(g_simple_action_group_new()) +{ + GActionEntry entries[] = { + { "activate-desktop-settings", on_desktop_settings_activated }, + { "activate-phone-settings", on_phone_settings_activated }, + { "activate-phone-clock-app", on_phone_clock_activated }, + { "activate-appointment", on_activate_appointment, "s", nullptr }, + { "activate-planner", on_activate_planner, "x", nullptr }, + { "set-location", on_set_location, "s" } + }; + + g_action_map_add_action_entries(G_ACTION_MAP(m_actions), + entries, + G_N_ELEMENTS(entries), + this); + + // add the header actions + auto gam = G_ACTION_MAP(m_actions); + auto v = create_default_header_state(); + auto a = g_simple_action_new_stateful("desktop-header", nullptr, v); + g_action_map_add_action(gam, G_ACTION(a)); + a = g_simple_action_new_stateful("desktop-greeter-header", nullptr, v); + g_action_map_add_action(gam, G_ACTION(a)); + a = g_simple_action_new_stateful("phone-header", nullptr, v); + g_action_map_add_action(gam, G_ACTION(a)); + a = g_simple_action_new_stateful("phone-greeter-header", nullptr, v); + g_action_map_add_action(gam, G_ACTION(a)); + + // add the calendar action + v = create_calendar_state(state); + a = g_simple_action_new_stateful("calendar", G_VARIANT_TYPE_INT64, v); + g_action_map_add_action(gam, G_ACTION(a)); + g_signal_connect(a, "activate", G_CALLBACK(on_calendar_activated), this); + //m_calendar_action = a; + + // FIXME: rebuild the calendar state when show-week-number changes +} + +Actions::~Actions() +{ + g_clear_object(&m_actions); +} + +} // namespace datetime +} // namespace indicator +} // namespace unity -- cgit v1.2.3 From a2b5c79157fa8db36d94786de1b86b756308912d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 16:45:40 -0600 Subject: Plug the Settings object into the State container s.t. menus and actions can update themselves when the user's settings change. --- include/datetime/state.h | 14 +++++++------- src/actions.cpp | 4 ++-- src/menu.cpp | 20 +++++--------------- tests/test-menus.cc | 4 ++-- 4 files changed, 16 insertions(+), 26 deletions(-) (limited to 'src/actions.cpp') diff --git a/include/datetime/state.h b/include/datetime/state.h index a82bb4b..e735b6f 100644 --- a/include/datetime/state.h +++ b/include/datetime/state.h @@ -21,9 +21,10 @@ #define INDICATOR_DATETIME_STATE_H #include -#include -#include #include +#include +#include +#include #include @@ -47,18 +48,17 @@ namespace datetime { * @see Clock * @see Planner * @see Locations + * @see Settings */ struct State { - std::shared_ptr timezones; std::shared_ptr clock; - std::shared_ptr planner; std::shared_ptr locations; + std::shared_ptr planner; + std::shared_ptr settings; + std::shared_ptr timezones; - core::Property show_events; - core::Property show_clock; core::Property calendar_day; - core::Property show_week_numbers; }; } // namespace datetime diff --git a/src/actions.cpp b/src/actions.cpp index 4efe950..52ee1eb 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -154,12 +154,12 @@ GVariant* create_calendar_state(std::shared_ptr& state) g_variant_builder_add(&dict_builder, "{sv}", key, v); key = "show-week-numbers"; - v = g_variant_new_boolean(state->show_week_numbers.get()); + v = g_variant_new_boolean(state->settings->show_week_numbers.get()); g_variant_builder_add(&dict_builder, "{sv}", key, v); return g_variant_builder_end(&dict_builder); } -} // anonymous namespace +} // unnamed namespace /*** **** diff --git a/src/menu.cpp b/src/menu.cpp index 76306cc..c81f185 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -69,11 +69,11 @@ protected: update_section(Appointments); // uses formatter.getRelativeFormat() update_section(Locations); // uses formatter.getRelativeFormat() }); - m_state->show_clock.changed().connect([this](bool){ + m_state->settings->show_clock.changed().connect([this](bool){ update_header(); // update header's label update_section(Locations); // locations' relative time may have changed }); - m_state->show_events.changed().connect([this](bool){ + m_state->settings->show_events.changed().connect([this](bool){ update_section(Appointments); // showing events got toggled }); m_state->planner->upcoming.changed().connect([this](const std::vector&){ @@ -261,7 +261,7 @@ private: { auto menu = g_menu_new(); - if (((profile==Phone) || (profile==Desktop)) && m_state->show_events.get()) + if (((profile==Phone) || (profile==Desktop)) && m_state->settings->show_events.get()) { add_appointments (menu, profile); @@ -363,14 +363,14 @@ protected: std::shared_ptr& state_, std::shared_ptr& actions_): MenuImpl(profile_, name_, state_, actions_, - std::shared_ptr(new DesktopFormatter(state_->clock))) + std::shared_ptr(new DesktopFormatter(state_->clock, state_->settings))) { update_header(); } GVariant* create_header_state() { - const auto visible = m_state->show_clock.get(); + const auto visible = m_state->settings->show_clock.get(); const auto title = _("Date and Time"); auto label = g_variant_new_string(m_formatter->header.get().c_str()); @@ -472,32 +472,22 @@ std::shared_ptr MenuFactory::buildMenu(Menu::Profile profile) { std::shared_ptr menu; - m_state->show_clock.set (true); // FIXME - - //std::shared_ptr state(new State); - //state->clock = clock; - //state->planner = planner; - //state->locations = locations; switch (profile) { case Menu::Desktop: - m_state->show_events.set(true); // FIXME menu.reset(new DesktopMenu(m_state, m_actions)); break; case Menu::DesktopGreeter: - m_state->show_events.set(true); // FIXME menu.reset(new DesktopGreeterMenu(m_state, m_actions)); break; case Menu::Phone: - m_state->show_events.set(true); // FIXME menu.reset(new PhoneMenu(m_state, m_actions)); break; case Menu::PhoneGreeter: - m_state->show_events.set(false); // FIXME menu.reset(new PhoneGreeterMenu(m_state, m_actions)); break; diff --git a/tests/test-menus.cc b/tests/test-menus.cc index 88e4706..0f86b0d 100644 --- a/tests/test-menus.cc +++ b/tests/test-menus.cc @@ -170,7 +170,7 @@ protected: auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); // there shouldn't be any menuitems when "show events" is false - m_state->show_events.set(false); + m_state->settings->show_events.set(false); wait_msec(); auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); EXPECT_EQ(0, g_menu_model_get_n_items(section)); @@ -179,7 +179,7 @@ protected: // when "show_events" is true, // there should be an "add event" button even if there aren't any appointments std::vector appointments; - m_state->show_events.set(true); + m_state->settings->show_events.set(true); m_state->planner->upcoming.set(appointments); wait_msec(); section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); -- cgit v1.2.3 From 2e9d3bb48946ccebf49cff64ab5de67e5714e1e3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 21:23:57 -0600 Subject: get timezone, clock tests running again with Settings & State --- include/datetime/actions-live.h | 7 +- include/datetime/actions.h | 2 +- src/actions-live.cpp | 9 +-- src/actions.cpp | 6 +- tests/geoclue-fixture.h | 48 +++++++----- tests/test-clock.cc | 168 +++++++++------------------------------- tests/test-dbus-fixture.h | 14 ++-- tests/test-timezones.cc | 21 ++--- 8 files changed, 91 insertions(+), 184 deletions(-) (limited to 'src/actions.cpp') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 2059a4d..3d04660 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,15 +36,14 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(std::shared_ptr& state): Actions(state) {} + LiveActions(const std::shared_ptr& state): Actions(state) {} ~LiveActions() =default; void open_desktop_settings(); void open_phone_settings(); - void open_phone_clock(); - void open_phone_planner(); + void open_phone_clock_app(); + void open_planner(); void open_planner_at(const DateTime&); - void open_calendar_at(const DateTime&); void open_appointment(const std::string& uid); void set_location(const std::string& zone, const std::string& name); void set_calendar_date(const DateTime&); diff --git a/include/datetime/actions.h b/include/datetime/actions.h index ed45c3c..a4c6017 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -51,7 +51,7 @@ public: std::shared_ptr state() { return m_state; } protected: - Actions(std::shared_ptr& state); + Actions(const std::shared_ptr& state); virtual ~Actions(); private: diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 08e1466..c699aff 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -39,12 +39,12 @@ void LiveActions::open_phone_settings() g_message("%s", G_STRFUNC); } -void LiveActions::open_phone_clock() +void LiveActions::open_phone_clock_app() { g_message("%s", G_STRFUNC); } -void LiveActions::open_phone_planner() +void LiveActions::open_planner() { g_message("%s", G_STRFUNC); } @@ -54,11 +54,6 @@ void LiveActions::open_planner_at(const DateTime&) g_message("%s", G_STRFUNC); } -void LiveActions::open_calendar_at(const DateTime&) -{ - g_message("%s", G_STRFUNC); -} - void LiveActions::open_appointment(const std::string& uid) { g_message("%s - %s", G_STRFUNC, uid.c_str()); diff --git a/src/actions.cpp b/src/actions.cpp index 52ee1eb..0df7d53 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -130,7 +130,7 @@ GVariant* create_default_header_state() return g_variant_builder_end(&b); } -GVariant* create_calendar_state(std::shared_ptr& state) +GVariant* create_calendar_state(const std::shared_ptr& state) { gboolean days[32] = { 0 }; for(const auto& appt : state->planner->thisMonth.get()) @@ -138,7 +138,7 @@ GVariant* create_calendar_state(std::shared_ptr& state) GVariantBuilder day_builder; g_variant_builder_init(&day_builder, G_VARIANT_TYPE("ai")); - for (int i=0; i& state) **** ***/ -Actions::Actions(std::shared_ptr& state): +Actions::Actions(const std::shared_ptr& state): m_state(state), m_actions(g_simple_action_group_new()) { diff --git a/tests/geoclue-fixture.h b/tests/geoclue-fixture.h index 890204a..7e29018 100644 --- a/tests/geoclue-fixture.h +++ b/tests/geoclue-fixture.h @@ -33,8 +33,10 @@ class GeoclueFixture : public GlibFixture DbusTestService * service = nullptr; DbusTestDbusMock * mock = nullptr; - DbusTestDbusMockObject * obj_master = nullptr; - DbusTestDbusMockObject * obj_client = nullptr; + DbusTestDbusMockObject * obj_geo = nullptr; + DbusTestDbusMockObject * obj_geo_m = nullptr; + DbusTestDbusMockObject * obj_geo_mc = nullptr; + DbusTestDbusMockObject * obj_geo_addr = nullptr; const std::string timezone_1 = "America/Denver"; void SetUp () @@ -42,25 +44,31 @@ class GeoclueFixture : public GlibFixture super::SetUp(); GError * error = nullptr; - const gchar * const client_path = "/org/freedesktop/Geoclue/Master/client0"; + const auto master_path = "/org/freedesktop/Geoclue/Master"; + const auto client_path = "/org/freedesktop/Geoclue/Master/client0"; GString * gstr = g_string_new (nullptr); service = dbus_test_service_new (nullptr); mock = dbus_test_dbus_mock_new ("org.freedesktop.Geoclue.Master"); - obj_master = dbus_test_dbus_mock_get_object (mock, - "/org/freedesktop/Geoclue/Master", - "org.freedesktop.Geoclue.Master", - nullptr); + auto interface = "org.freedesktop.Geoclue.Master"; + obj_geo_m = dbus_test_dbus_mock_get_object (mock, master_path, interface, nullptr); g_string_printf (gstr, "ret = '%s'", client_path); - dbus_test_dbus_mock_object_add_method (mock, obj_master, nullptr, "Create", nullptr, G_VARIANT_TYPE_OBJECT_PATH, gstr->str, &error); + dbus_test_dbus_mock_object_add_method (mock, obj_geo_m, "Create", nullptr, G_VARIANT_TYPE_OBJECT_PATH, gstr->str, &error); - obj_client = dbus_test_dbus_mock_get_object (mock, client_path, "org.freedesktop.Geoclue.MasterClient", nullptr); - dbus_test_dbus_mock_object_add_method (mock, obj_client, nullptr, "SetRequirements", G_VARIANT_TYPE("(iibi)"), nullptr, "", &error); - dbus_test_dbus_mock_object_add_method (mock, obj_client, nullptr, "AddressStart", nullptr, nullptr, "", &error); - dbus_test_dbus_mock_object_add_method (mock, obj_client, "org.freedesktop.Geoclue", "AddReference", nullptr, nullptr, "", &error); + interface = "org.freedesktop.Geoclue.MasterClient"; + obj_geo_mc = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr); + dbus_test_dbus_mock_object_add_method (mock, obj_geo_mc, "SetRequirements", G_VARIANT_TYPE("(iibi)"), nullptr, "", &error); + dbus_test_dbus_mock_object_add_method (mock, obj_geo_mc, "AddressStart", nullptr, nullptr, "", &error); + + interface = "org.freedesktop.Geoclue"; + obj_geo = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr); + dbus_test_dbus_mock_object_add_method (mock, obj_geo, "AddReference", nullptr, nullptr, "", &error); g_string_printf (gstr, "ret = (1385238033, {'timezone': '%s'}, (3, 0.0, 0.0))", timezone_1.c_str()); - dbus_test_dbus_mock_object_add_method (mock, obj_client, "org.freedesktop.Geoclue.Address", "GetAddress", nullptr, G_VARIANT_TYPE("(ia{ss}(idd))"), gstr->str, &error); + + interface = "org.freedesktop.Geoclue.Address"; + obj_geo_addr = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr); + dbus_test_dbus_mock_object_add_method (mock, obj_geo_addr, "GetAddress", nullptr, G_VARIANT_TYPE("(ia{ss}(idd))"), gstr->str, &error); dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); dbus_test_service_start_tasks(service); @@ -101,11 +109,11 @@ private: struct EmitAddressChangedData { DbusTestDbusMock * mock = nullptr; - DbusTestDbusMockObject * obj_client = nullptr; + DbusTestDbusMockObject * obj_geo_addr = nullptr; std::string timezone; - EmitAddressChangedData(DbusTestDbusMock * mock_, - DbusTestDbusMockObject * obj_client_, - const std::string& timezone_): mock(mock_), obj_client(obj_client_), timezone(timezone_) {} + EmitAddressChangedData(DbusTestDbusMock* mock_, + DbusTestDbusMockObject* obj_geo_addr_, + const std::string& timezone_): mock(mock_), obj_geo_addr(obj_geo_addr_), timezone(timezone_) {} }; static gboolean emit_address_changed_idle (gpointer gdata) @@ -114,8 +122,8 @@ private: auto fmt = g_strdup_printf ("(1385238033, {'timezone': '%s'}, (3, 0.0, 0.0))", data->timezone.c_str()); GError * error = nullptr; - dbus_test_dbus_mock_object_emit_signal(data->mock, data->obj_client, - "org.freedesktop.Geoclue.Address", + dbus_test_dbus_mock_object_emit_signal(data->mock, data->obj_geo_addr, + //"org.freedesktop.Geoclue.Address", "AddressChanged", G_VARIANT_TYPE("(ia{ss}(idd))"), g_variant_new_parsed (fmt), @@ -135,7 +143,7 @@ public: void setGeoclueTimezoneOnIdle (const std::string& newZone) { - g_timeout_add (50, emit_address_changed_idle, new EmitAddressChangedData(mock, obj_client, newZone.c_str())); + g_timeout_add (50, emit_address_changed_idle, new EmitAddressChangedData(mock, obj_geo_addr, newZone.c_str())); } }; diff --git a/tests/test-clock.cc b/tests/test-clock.cc index 7d3a35e..142ccad 100644 --- a/tests/test-clock.cc +++ b/tests/test-clock.cc @@ -20,95 +20,56 @@ #include #include -#include "glib-fixture.h" +#include "test-dbus-fixture.h" /*** **** ***/ -using unity::indicator::datetime::Clock; -using unity::indicator::datetime::LiveClock; -using unity::indicator::datetime::Timezones; +using namespace unity::indicator::datetime; -class ClockFixture: public GlibFixture +class ClockFixture: public TestDBusFixture { private: - - typedef GlibFixture super; - - static void - on_bus_opened(GObject* /*object*/, GAsyncResult* res, gpointer gself) - { - auto self = static_cast(gself); - - GError * err = 0; - self->system_bus = g_bus_get_finish(res, &err); - g_assert_no_error(err); - - g_main_loop_quit(self->loop); - } - - static void - on_bus_closed(GObject* /*object*/, GAsyncResult* res, gpointer gself) - { - auto self = static_cast(gself); - - GError * err = 0; - g_dbus_connection_close_finish(self->system_bus, res, &err); - g_assert_no_error(err); - - g_main_loop_quit(self->loop); - } - - protected: - - GTestDBus * test_dbus; - GDBusConnection * system_bus; - - virtual void SetUp() - { - super::SetUp(); - - // pull up a test dbus - test_dbus = g_test_dbus_new(G_TEST_DBUS_NONE); - g_test_dbus_up(test_dbus); - const char * address = g_test_dbus_get_bus_address(test_dbus); - g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, TRUE); - g_debug("test_dbus's address is %s", address); - - // wait for the GDBusConnection before returning - g_bus_get(G_BUS_TYPE_SYSTEM, nullptr, on_bus_opened, this); - g_main_loop_run(loop); - } - - virtual void TearDown() - { - // close the system bus - g_dbus_connection_close(system_bus, nullptr, on_bus_closed, this); - g_main_loop_run(loop); - g_clear_object(&system_bus); - - // tear down the test dbus - g_test_dbus_down(test_dbus); - g_clear_object(&test_dbus); - - super::TearDown(); - } + typedef TestDBusFixture super; public: - void emitPrepareForSleep() { g_dbus_connection_emit_signal(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr), - NULL, - "/org/freedesktop/login1", // object path - "org.freedesktop.login1.Manager", // interface - "PrepareForSleep", // signal name - g_variant_new("(b)", FALSE), - NULL); + NULL, + "/org/freedesktop/login1", // object path + "org.freedesktop.login1.Manager", // interface + "PrepareForSleep", // signal name + g_variant_new("(b)", FALSE), + NULL); } }; +/** + * Confirm that normal time passing doesn't trigger a skew event. + * that idling changing the clock's time triggers a skew event + */ +TEST_F(ClockFixture, IdleDoesNotTriggerSkew) +{ + std::shared_ptr zones(new Timezones); + zones->timezone.set("America/New_York"); + LiveClock clock(zones); + wait_msec(500); // wait for the bus to set up + + bool skewed = false; + clock.skewDetected.connect([&skewed](){ + skewed = true; + g_warn_if_reached(); + return G_SOURCE_REMOVE; + }); + + const unsigned int intervalSec = 3; + clock.skewTestIntervalSec.set(intervalSec); + wait_msec(intervalSec * 2.5 * 1000); + EXPECT_FALSE(skewed); +} + /*** **** ***/ @@ -120,37 +81,6 @@ TEST_F(ClockFixture, HelloFixture) std::shared_ptr zones(new Timezones); zones->timezone.set("America/New_York"); LiveClock clock(zones); - -#if 0 - GTimeZone * tz_nyc = g_time_zone_new(file_timezone.c_str()); - GDateTime * now_nyc = g_date_time_new_now(tz_nyc); - GDateTime * now = clock.localtime(); - EXPECT_EQ(g_date_time_get_utc_offset(now_nyc), g_date_time_get_utc_offset(now)); - EXPECT_LE(abs(g_date_time_difference(now_nyc,now)), G_USEC_PER_SEC); - g_date_time_unref(now); - g_date_time_unref(now_nyc); - g_time_zone_unref(tz_nyc); - - /// change the timezones! - clock.skewDetected.connect([this](){ - g_main_loop_quit(loop); - }); - file_timezone = "America/Los_Angeles"; - g_idle_add([](gpointer str){ - set_file(static_cast(str)); - return G_SOURCE_REMOVE; - }, const_cast(file_timezone.c_str())); - g_main_loop_run(loop); - - GTimeZone * tz_la = g_time_zone_new(file_timezone.c_str()); - GDateTime * now_la = g_date_time_new_now(tz_la); - now = clock.localtime(); - EXPECT_EQ(g_date_time_get_utc_offset(now_la), g_date_time_get_utc_offset(now)); - EXPECT_LE(abs(g_date_time_difference(now_la,now)), G_USEC_PER_SEC); - g_date_time_unref(now); - g_date_time_unref(now_la); - g_time_zone_unref(tz_la); -#endif } @@ -159,10 +89,6 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew) std::shared_ptr zones(new Timezones); zones->timezone.set("America/New_York"); LiveClock clock(zones); - //std::string file_timezone = "America/New_York"; - //set_file(file_timezone); - //std::shared_ptr detector(new TimezoneDetector(TIMEZONE_FILE)); - //LiveClock clock(detector); auto tz_nyc = g_time_zone_new("America/New_York"); auto now_nyc = g_date_time_new_now(tz_nyc); @@ -213,30 +139,6 @@ TEST_F(ClockFixture, SleepTriggersSkew) return G_SOURCE_REMOVE; }, this); - wait_msec(1000); + g_main_loop_run(loop); EXPECT_TRUE(skewed); } - -/** - * Confirm that normal time passing doesn't trigger a skew event. - * that idling changing the clock's time triggers a skew event - */ -TEST_F(ClockFixture, IdleDoesNotTriggerSkew) -{ - std::shared_ptr zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); - wait_msec(500); // wait for the bus to set up - - bool skewed = false; - clock.skewDetected.connect([&skewed](){ - skewed = true; - g_warn_if_reached(); - return G_SOURCE_REMOVE; - }); - - const unsigned int intervalSec = 4; - clock.skewTestIntervalSec.set(intervalSec); - wait_msec(intervalSec * 2.5 * 1000); - EXPECT_FALSE(skewed); -} diff --git a/tests/test-dbus-fixture.h b/tests/test-dbus-fixture.h index fc7ab5a..db06be2 100644 --- a/tests/test-dbus-fixture.h +++ b/tests/test-dbus-fixture.h @@ -86,15 +86,17 @@ class TestDBusFixture: public GlibFixture virtual void TearDown () { + wait_msec(); + // close the system bus - g_dbus_connection_close (system_bus, nullptr, on_bus_closed, this); - g_main_loop_run (loop); - g_clear_object (&system_bus); + g_dbus_connection_close(system_bus, nullptr, on_bus_closed, this); + g_main_loop_run(loop); + g_clear_object(&system_bus); // tear down the test dbus - g_test_dbus_down (test_dbus); - g_clear_object (&test_dbus); + g_test_dbus_down(test_dbus); + g_clear_object(&test_dbus); - super::TearDown (); + super::TearDown(); } }; diff --git a/tests/test-timezones.cc b/tests/test-timezones.cc index d3c8e3a..3f02761 100644 --- a/tests/test-timezones.cc +++ b/tests/test-timezones.cc @@ -19,12 +19,15 @@ #include "geoclue-fixture.h" +#include #include +#include // std::shared_ptr + #include // fopen() #include // sync() -using unity::indicator::datetime::LiveTimezones; +using namespace unity::indicator::datetime; typedef GeoclueFixture TimezonesFixture; @@ -49,7 +52,8 @@ TEST_F(TimezonesFixture, ManagerTest) std::string timezone_geo = "America/Denver"; set_file(timezone_file); - LiveTimezones z(TIMEZONE_FILE); + std::shared_ptr settings(new Settings); + LiveTimezones z(settings, TIMEZONE_FILE); wait_msec(500); // wait for the bus to get set up EXPECT_EQ(timezone_file, z.timezone.get()); auto zones = z.timezones.get(); @@ -71,13 +75,13 @@ TEST_F(TimezonesFixture, ManagerTest) g_main_loop_quit(loop); }); - g_idle_add([](gpointer gz) { - auto az = static_cast(gz); - g_message("geolocation was %d", (int)az->geolocationEnabled.get()); + g_idle_add([](gpointer s_in) { + auto s = static_cast(s_in); + g_message("geolocation was %d", (int)s->show_detected_location.get()); g_message("turning geolocation on"); - az->geolocationEnabled.set(true); + s->show_detected_location.set(true); return G_SOURCE_REMOVE; - }, &z); + }, settings.get()); // turn on geoclue during the idle... this should add timezone_1 to the 'timezones' property g_main_loop_run(loop); @@ -115,9 +119,6 @@ TEST_F(TimezonesFixture, ManagerTest) EXPECT_EQ(2, zones.size()); EXPECT_EQ(1, zones.count(timezone_file)); EXPECT_EQ(1, zones.count(timezone_geo)); - - - } -- cgit v1.2.3 From 039c43dc5d0bee82c69c4ef8beee246940570096 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 10:01:57 -0600 Subject: fix r325 regression found by test-menus --- src/actions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/actions.cpp') diff --git a/src/actions.cpp b/src/actions.cpp index 0df7d53..1d80c99 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -188,11 +188,11 @@ Actions::Actions(const std::shared_ptr& state): auto v = create_default_header_state(); auto a = g_simple_action_new_stateful("desktop-header", nullptr, v); g_action_map_add_action(gam, G_ACTION(a)); - a = g_simple_action_new_stateful("desktop-greeter-header", nullptr, v); + a = g_simple_action_new_stateful("desktop_greeter-header", nullptr, v); g_action_map_add_action(gam, G_ACTION(a)); a = g_simple_action_new_stateful("phone-header", nullptr, v); g_action_map_add_action(gam, G_ACTION(a)); - a = g_simple_action_new_stateful("phone-greeter-header", nullptr, v); + a = g_simple_action_new_stateful("phone_greeter-header", nullptr, v); g_action_map_add_action(gam, G_ACTION(a)); // add the calendar action -- cgit v1.2.3 From 7b09a0ff5652bdca7c8d8e046d2af6a696f94147 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 25 Jan 2014 16:54:41 -0600 Subject: sync the exported calendar state with the #State backend --- include/datetime/actions.h | 4 +- include/datetime/state.h | 2 - src/actions-live.cpp | 5 -- src/actions.cpp | 30 +++++++++++- src/state-live.cpp | 1 - tests/actions-mock.h | 8 +--- tests/state-mock.h | 1 - tests/test-actions.cpp | 19 +++++--- tests/test-live-actions.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 157 insertions(+), 27 deletions(-) (limited to 'src/actions.cpp') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 18286dc..3686b95 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -49,8 +49,7 @@ public: virtual void open_planner_at(const DateTime&) =0; virtual void open_appointment(const std::string& uid) =0; virtual void set_location(const std::string& zone, const std::string& name)=0; - virtual void set_calendar_date(const DateTime&) =0; - + void set_calendar_date(const DateTime&); GActionGroup* action_group() { return G_ACTION_GROUP(m_actions); } std::shared_ptr state() { return m_state; } @@ -61,6 +60,7 @@ protected: private: std::shared_ptr m_state; GSimpleActionGroup* m_actions = nullptr; + void update_calendar_state(); // we've got raw pointers in here, so disable copying Actions(const Actions&) =delete; diff --git a/include/datetime/state.h b/include/datetime/state.h index b14908e..414be32 100644 --- a/include/datetime/state.h +++ b/include/datetime/state.h @@ -66,8 +66,6 @@ struct State /** \brief Configuration options that modify the view */ std::shared_ptr settings; - - core::Property calendar_day; }; } // namespace datetime diff --git a/src/actions-live.cpp b/src/actions-live.cpp index e4f5e9f..d5f7180 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -96,11 +96,6 @@ void LiveActions::open_appointment(const std::string& uid) } } -void LiveActions::set_calendar_date(const DateTime& dt) -{ - state()->calendar_day.set(dt); -} - /*** **** ***/ diff --git a/src/actions.cpp b/src/actions.cpp index 1d80c99..a6a7c0b 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -150,7 +150,7 @@ GVariant* create_calendar_state(const std::shared_ptr& state) g_variant_builder_add(&dict_builder, "{sv}", key, v); key = "calendar-day"; - v = g_variant_new_int64(state->calendar_day.get().to_unix()); + v = g_variant_new_int64(state->planner->time.get().to_unix()); g_variant_builder_add(&dict_builder, "{sv}", key, v); key = "show-week-numbers"; @@ -200,7 +200,20 @@ Actions::Actions(const std::shared_ptr& state): a = g_simple_action_new_stateful("calendar", G_VARIANT_TYPE_INT64, v); g_action_map_add_action(gam, G_ACTION(a)); g_signal_connect(a, "activate", G_CALLBACK(on_calendar_activated), this); - //m_calendar_action = a; + + /// + /// Keep our GActionGroup's action's states in sync with m_state + /// + + m_state->planner->time.changed().connect([this](const DateTime&){ + update_calendar_state(); + }); + m_state->planner->thisMonth.changed().connect([this](const std::vector&){ + update_calendar_state(); + }); + m_state->settings->show_week_numbers.changed().connect([this](bool){ + update_calendar_state(); + }); // FIXME: rebuild the calendar state when show-week-number changes } @@ -210,6 +223,19 @@ Actions::~Actions() g_clear_object(&m_actions); } +void Actions::update_calendar_state() +{ + g_action_group_change_action_state(action_group(), + "calendar", + create_calendar_state(m_state)); +} + +void Actions::set_calendar_date(const DateTime& date) +{ + m_state->planner->time.set(date); +} + + } // namespace datetime } // namespace indicator } // namespace unity diff --git a/src/state-live.cpp b/src/state-live.cpp index 8ee663b..fe1e6cd 100644 --- a/src/state-live.cpp +++ b/src/state-live.cpp @@ -45,7 +45,6 @@ LiveState::LiveState() locations.reset(new SettingsLocations(live_settings, live_timezones)); planner.reset(new PlannerEds); planner->time = clock->localtime(); - calendar_day = clock->localtime(); } /*** 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& 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({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); + } +} -- cgit v1.2.3 From f07f97ef53522abdce52cf3c7b583c0d6d47aa40 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 29 Jan 2014 12:50:59 -0600 Subject: sync with lp:~larsu/indicator-datetime/reset-date and add corresponding unit tests. --- src/actions.cpp | 20 ++++++++++++++++--- src/menu.cpp | 2 ++ tests/test-actions.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) (limited to 'src/actions.cpp') diff --git a/src/actions.cpp b/src/actions.cpp index a6a7c0b..acf8fd4 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -108,9 +108,22 @@ void on_set_location(GSimpleAction * /*action*/, g_free(zone); } -static void on_calendar_activated(GSimpleAction * /*action*/, - GVariant * state, - gpointer gself) +void on_calendar_active_changed(GSimpleAction * /*action*/, + GVariant * state, + gpointer gself) +{ + // reset the date when the menu is shown + if (g_variant_get_boolean(state)) + { + auto self = static_cast(gself); + + self->set_calendar_date(self->state()->clock->localtime()); + } +} + +void on_calendar_activated(GSimpleAction * /*action*/, + GVariant * state, + gpointer gself) { const time_t t = g_variant_get_int64(state); @@ -175,6 +188,7 @@ Actions::Actions(const std::shared_ptr& state): { "activate-phone-clock-app", on_phone_clock_activated }, { "activate-appointment", on_activate_appointment, "s", nullptr }, { "activate-planner", on_activate_planner, "x", nullptr }, + { "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed }, { "set-location", on_set_location, "s" } }; diff --git a/src/menu.cpp b/src/menu.cpp index 390a06f..b0ba79d 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -204,6 +204,8 @@ private: auto header = g_menu_item_new(nullptr, detailed_action.c_str()); g_menu_item_set_attribute(header, "x-canonical-type", "s", "com.canonical.indicator.root"); + g_menu_item_set_attribute(header, "submenu-action", "s", + "indicator.calendar-active"); g_menu_item_set_submenu(header, G_MENU_MODEL(m_submenu)); g_object_unref(m_submenu); diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index c30d1fb..1865cfd 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -156,6 +156,60 @@ TEST_F(ActionsFixture, SetCalendarDate) EXPECT_EQ (now, m_state->planner->time.get()); } +TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate) +{ + // Confirm that the GActions exist + auto action_group = m_actions->action_group(); + EXPECT_TRUE(g_action_group_has_action(action_group, "calendar")); + EXPECT_TRUE(g_action_group_has_action(action_group, "calendar-active")); + + /// + /// Prerequisite for the test: move calendar-date away from today + /// + + // move calendar-date a week into the future... + 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_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(now, m_state->clock->localtime()); + 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)); + auto v = g_variant_lookup_value(calendar_state, "calendar-day", G_VARIANT_TYPE_INT64); + EXPECT_TRUE(v != nullptr); + EXPECT_EQ(next_week_unix, g_variant_get_int64(v)); + g_clear_pointer(&v, g_variant_unref); + g_clear_pointer(&calendar_state, g_variant_unref); + + /// + /// Now the actual test. + /// We set the state of 'calendar-active' to true, which should reset the calendar date. + /// This is so the calendar always starts on today's date when the indicator's menu is pulled down. + /// + + // change the state... + 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, m_state->clock->localtime()); + 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)); + v = g_variant_lookup_value(calendar_state, "calendar-day", G_VARIANT_TYPE_INT64); + EXPECT_TRUE(v != nullptr); + EXPECT_EQ(now.to_unix(), g_variant_get_int64(v)); + g_clear_pointer(&v, g_variant_unref); + g_clear_pointer(&calendar_state, g_variant_unref); + +} + + TEST_F(ActionsFixture, OpenAppointment) { Appointment appt; -- cgit v1.2.3 From d2caa37e18191c31d866dd3042b676c135bae50d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 12:45:50 -0600 Subject: as per review, don't inline getters --- include/datetime/actions.h | 4 ++-- include/datetime/locations.h | 4 ++-- include/datetime/menu.h | 8 ++++---- src/actions.cpp | 11 +++++++++++ src/locations.cpp | 10 ++++++++++ src/menu.cpp | 26 ++++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 8 deletions(-) (limited to 'src/actions.cpp') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 3686b95..6817b4c 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -50,8 +50,8 @@ public: virtual void open_appointment(const std::string& uid) =0; virtual void set_location(const std::string& zone, const std::string& name)=0; void set_calendar_date(const DateTime&); - GActionGroup* action_group() { return G_ACTION_GROUP(m_actions); } - std::shared_ptr state() { return m_state; } + GActionGroup* action_group(); + std::shared_ptr state(); protected: Actions(const std::shared_ptr& state); diff --git a/include/datetime/locations.h b/include/datetime/locations.h index ee67615..fc776bb 100644 --- a/include/datetime/locations.h +++ b/include/datetime/locations.h @@ -39,9 +39,9 @@ namespace datetime { class Location { public: - const std::string& zone() const { return m_zone; } + const std::string& zone() const; - const std::string& name() const { return m_name; } + const std::string& name() const; bool operator== (const Location& that) const { diff --git a/include/datetime/menu.h b/include/datetime/menu.h index fcd709f..f097b02 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -43,9 +43,9 @@ class Menu public: enum Profile { Desktop, DesktopGreeter, Phone, PhoneGreeter, NUM_PROFILES }; enum Section { Calendar, Appointments, Locations, Settings, NUM_SECTIONS }; - const std::string& name() const { return m_name; } - Profile profile() const { return m_profile; } - GMenuModel* menu_model() { return G_MENU_MODEL(m_menu); } + const std::string& name() const; + Profile profile() const; + GMenuModel* menu_model(); protected: Menu (Profile profile_in, const std::string& name_in): m_profile(profile_in), m_name(name_in) {} @@ -72,7 +72,7 @@ class MenuFactory public: MenuFactory (std::shared_ptr& actions, std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); - std::shared_ptr state() { return m_state; } + std::shared_ptr state(); private: std::shared_ptr m_actions; diff --git a/src/actions.cpp b/src/actions.cpp index acf8fd4..6ee3896 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -249,6 +249,17 @@ void Actions::set_calendar_date(const DateTime& date) m_state->planner->time.set(date); } +GActionGroup* Actions::action_group() +{ + return G_ACTION_GROUP(m_actions); +} + +std::shared_ptr Actions::state() +{ + return m_state; +} + + } // namespace datetime } // namespace indicator diff --git a/src/locations.cpp b/src/locations.cpp index d6ab73a..8d1a086 100644 --- a/src/locations.cpp +++ b/src/locations.cpp @@ -25,6 +25,16 @@ namespace unity { namespace indicator { namespace datetime { +const std::string& Location::zone() const +{ + return m_zone; +} + +const std::string& Location::name() const +{ + return m_name; +} + Location::Location(const std::string& zone_, const std::string& name_): m_zone(zone_), m_name(name_) diff --git a/src/menu.cpp b/src/menu.cpp index d0756cc..4bb4fb6 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -35,6 +35,27 @@ namespace datetime { ***** ****/ +const std::string& Menu::name() const +{ + return m_name; +} + +Menu::Profile Menu::profile() const +{ + return m_profile; +} + +GMenuModel* Menu::menu_model() +{ + return G_MENU_MODEL(m_menu); +} + + +/**** +***** +****/ + + #define FALLBACK_ALARM_CLOCK_ICON_NAME "clock" #define CALENDAR_ICON_NAME "calendar" @@ -531,6 +552,11 @@ MenuFactory::MenuFactory(std::shared_ptr& actions_, { } +std::shared_ptr MenuFactory::state() +{ + return m_state; +} + std::shared_ptr MenuFactory::buildMenu(Menu::Profile profile) { -- cgit v1.2.3 From b56293e7b4fb4b253da17119ad153990744dac3b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:17:11 -0600 Subject: as per review, constify getters where possible. This isn't always possible due to system APIs asking for non-const pointers. --- include/datetime/actions.h | 2 +- include/datetime/menu.h | 1 - src/actions.cpp | 6 +++--- src/menu.cpp | 5 ----- 4 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src/actions.cpp') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 6817b4c..99e78f5 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -51,7 +51,7 @@ public: virtual void set_location(const std::string& zone, const std::string& name)=0; void set_calendar_date(const DateTime&); GActionGroup* action_group(); - std::shared_ptr state(); + const std::shared_ptr state() const; protected: Actions(const std::shared_ptr& state); diff --git a/include/datetime/menu.h b/include/datetime/menu.h index 526cd9f..5821e33 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -72,7 +72,6 @@ class MenuFactory public: MenuFactory (std::shared_ptr& actions, std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); - std::shared_ptr state(); private: std::shared_ptr m_actions; diff --git a/src/actions.cpp b/src/actions.cpp index 6ee3896..cdeb77f 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -65,7 +65,7 @@ void on_activate_appointment(GSimpleAction * /*action*/, g_return_if_fail(uid && *uid); // find url of the upcoming appointment with this uid - for (auto& appt : self->state()->planner->upcoming.get()) + for (const auto& appt : self->state()->planner->upcoming.get()) { if (appt.uid == uid) { @@ -146,7 +146,7 @@ GVariant* create_default_header_state() GVariant* create_calendar_state(const std::shared_ptr& state) { gboolean days[32] = { 0 }; - for(const auto& appt : state->planner->thisMonth.get()) + for (const auto& appt : state->planner->thisMonth.get()) days[appt.begin.day_of_month()] = true; GVariantBuilder day_builder; @@ -254,7 +254,7 @@ GActionGroup* Actions::action_group() return G_ACTION_GROUP(m_actions); } -std::shared_ptr Actions::state() +const std::shared_ptr Actions::state() const { return m_state; } diff --git a/src/menu.cpp b/src/menu.cpp index b263520..696ed2b 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -558,11 +558,6 @@ MenuFactory::MenuFactory(std::shared_ptr& actions_, { } -std::shared_ptr MenuFactory::state() -{ - return m_state; -} - std::shared_ptr MenuFactory::buildMenu(Menu::Profile profile) { -- cgit v1.2.3 From a7a09a5ca5012fb1c48f259d2587542316e7349b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 18:33:14 -0600 Subject: copyediting: as per review, use name_of_thing() instead of get_name_of_thing() or getNameOfThing() --- include/datetime/clock-mock.h | 4 ++-- include/datetime/clock.h | 10 +++++----- include/datetime/formatter.h | 12 ++++++------ include/datetime/planner.h | 6 +++--- src/actions.cpp | 4 ++-- src/clock-live.cpp | 6 +++--- src/clock.cpp | 22 +++++++++++----------- src/formatter-desktop.cpp | 4 ++-- src/formatter.cpp | 12 ++++++------ src/menu.cpp | 14 +++++++------- src/planner-eds.cpp | 2 +- tests/test-clock.cpp | 8 ++++---- tests/test-formatter.cpp | 10 +++++----- tests/test-live-actions.cpp | 4 ++-- tests/test-planner.cpp | 6 +++--- 15 files changed, 62 insertions(+), 62 deletions(-) (limited to 'src/actions.cpp') diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h index 27926ff..fb9b52f 100644 --- a/include/datetime/clock-mock.h +++ b/include/datetime/clock-mock.h @@ -45,9 +45,9 @@ public: const auto old = m_localtime; m_localtime = dt; if (!DateTime::is_same_minute(old, m_localtime)) - minuteChanged(); + minute_changed(); if (!DateTime::is_same_day(old, m_localtime)) - dateChanged(); + date_changed(); } private: diff --git a/include/datetime/clock.h b/include/datetime/clock.h index 4a9db8f..1d488d1 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -43,20 +43,20 @@ public: virtual DateTime localtime() const =0; /** \brief A signal which fires when the clock's minute changes */ - core::Signal<> minuteChanged; + core::Signal<> minute_changed; /** \brief A signal which fires when the clock's date changes */ - core::Signal<> dateChanged; + core::Signal<> date_changed; protected: Clock(); - /** \brief Compares old and new times, emits minuteChanged() or dateChanged() signals if appropriate */ + /** \brief Compares old and new times, emits minute_changed() or date_changed() signals if appropriate */ void maybe_emit (const DateTime& a, const DateTime& b); private: - static void onSystemBusReady(GObject*, GAsyncResult*, gpointer); - static void onPrepareForSleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); + static void on_system_bus_ready(GObject*, GAsyncResult*, gpointer); + static void on_prepare_for_sleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); GCancellable * m_cancellable = nullptr; GDBusConnection * m_system_bus = nullptr; diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index f323858..0d695e2 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -69,27 +69,27 @@ class Formatter public: /** \brief The time format string for the menu header */ - core::Property headerFormat; + core::Property header_format; - /** \brief The time string for the menu header. (eg, the headerFormat + the clock's time */ + /** \brief The time string for the menu header. (eg, the header_format + the clock's time */ core::Property header; /** \brief Signal to denote when the relativeFormat has changed. When this is emitted, clients will want to rebuild their menuitems that contain relative time strings (ie, the Appointments and Locations menuitems) */ - core::Signal<> relativeFormatChanged; + core::Signal<> relative_format_changed; /** \brief Generate a relative time format for some time (or time range) from the current clock's value. For example, a full-day interval starting at the end of the current clock's day yields "Tomorrow" */ - std::string getRelativeFormat(GDateTime* then, GDateTime* then_end=nullptr) const; + std::string relative_format(GDateTime* then, GDateTime* then_end=nullptr) const; protected: Formatter(const std::shared_ptr&); virtual ~Formatter(); - static const char* getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds); + static const char* default_header_time_format(bool twelvehour, bool show_seconds); private: @@ -127,7 +127,7 @@ class PhoneFormatter: public Formatter { public: PhoneFormatter(const std::shared_ptr& clock): Formatter(clock) { - headerFormat.set(getDefaultHeaderTimeFormat(is_locale_12h(), false)); + header_format.set(default_header_time_format(is_locale_12h(), false)); } }; diff --git a/include/datetime/planner.h b/include/datetime/planner.h index a8f9941..376a31f 100644 --- a/include/datetime/planner.h +++ b/include/datetime/planner.h @@ -43,9 +43,9 @@ public: virtual ~Planner() =default; /** - * \brief Timestamp used to determine the appointments in the `upcoming' and `thisMonth' properties. + * \brief Timestamp used to determine the appointments in the `upcoming' and `this_month' properties. * Setting this value will cause the planner to re-query its backend and - * update the `upcoming' and `thisMonth' properties. + * update the `upcoming' and `this_month' properties. */ core::Property time; @@ -57,7 +57,7 @@ public: /** * \brief The appointments that occur in the same month as the time property */ - core::Property> thisMonth; + core::Property> this_month; protected: Planner() =default; diff --git a/src/actions.cpp b/src/actions.cpp index cdeb77f..d6fa698 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -146,7 +146,7 @@ GVariant* create_default_header_state() GVariant* create_calendar_state(const std::shared_ptr& state) { gboolean days[32] = { 0 }; - for (const auto& appt : state->planner->thisMonth.get()) + for (const auto& appt : state->planner->this_month.get()) days[appt.begin.day_of_month()] = true; GVariantBuilder day_builder; @@ -222,7 +222,7 @@ Actions::Actions(const std::shared_ptr& state): m_state->planner->time.changed().connect([this](const DateTime&){ update_calendar_state(); }); - m_state->planner->thisMonth.changed().connect([this](const std::vector&){ + m_state->planner->this_month.changed().connect([this](const std::vector&){ update_calendar_state(); }); m_state->settings->show_week_numbers.changed().connect([this](bool){ diff --git a/src/clock-live.cpp b/src/clock-live.cpp index 7c9db40..21a18a3 100644 --- a/src/clock-live.cpp +++ b/src/clock-live.cpp @@ -95,7 +95,7 @@ private: { g_clear_pointer(&m_timezone, g_time_zone_unref); m_timezone = g_time_zone_new(str.c_str()); - m_owner.minuteChanged(); + m_owner.minute_changed(); } /*** @@ -109,9 +109,9 @@ private: // maybe emit change signals const auto now = localtime(); if (!DateTime::is_same_minute(m_prev_datetime, now)) - m_owner.minuteChanged(); + m_owner.minute_changed(); if (!DateTime::is_same_day(m_prev_datetime, now)) - m_owner.dateChanged(); + m_owner.date_changed(); // queue up a timer to fire at the next minute m_prev_datetime = now; diff --git a/src/clock.cpp b/src/clock.cpp index d5293cc..f41a0cc 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -33,7 +33,7 @@ namespace datetime { Clock::Clock(): m_cancellable(g_cancellable_new()) { - g_bus_get(G_BUS_TYPE_SYSTEM, m_cancellable, onSystemBusReady, this); + g_bus_get(G_BUS_TYPE_SYSTEM, m_cancellable, on_system_bus_ready, this); } Clock::~Clock() @@ -48,7 +48,7 @@ Clock::~Clock() } void -Clock::onSystemBusReady(GObject*, GAsyncResult * res, gpointer gself) +Clock::on_system_bus_ready(GObject*, GAsyncResult * res, gpointer gself) { GDBusConnection * system_bus; @@ -66,22 +66,22 @@ Clock::onSystemBusReady(GObject*, GAsyncResult * res, gpointer gself) "/org/freedesktop/login1", // object path nullptr, // arg0 G_DBUS_SIGNAL_FLAGS_NONE, - onPrepareForSleep, + on_prepare_for_sleep, self, nullptr); } } void -Clock::onPrepareForSleep(GDBusConnection* /*connection*/, - const gchar* /*sender_name*/, - const gchar* /*object_path*/, - const gchar* /*interface_name*/, - const gchar* /*signal_name*/, - GVariant* /*parameters*/, - gpointer gself) +Clock::on_prepare_for_sleep(GDBusConnection* /*connection*/, + const gchar* /*sender_name*/, + const gchar* /*object_path*/, + const gchar* /*interface_name*/, + const gchar* /*signal_name*/, + GVariant* /*parameters*/, + gpointer gself) { - static_cast(gself)->minuteChanged(); + static_cast(gself)->minute_changed(); } /*** diff --git a/src/formatter-desktop.cpp b/src/formatter-desktop.cpp index 9a098c6..336d2d3 100644 --- a/src/formatter-desktop.cpp +++ b/src/formatter-desktop.cpp @@ -81,7 +81,7 @@ DesktopFormatter::DesktopFormatter(const std::shared_ptr& clock_ void DesktopFormatter::rebuildHeaderFormat() { - headerFormat.set(getHeaderLabelFormatString()); + header_format.set(getHeaderLabelFormatString()); } std::string DesktopFormatter::getHeaderLabelFormatString() const @@ -126,7 +126,7 @@ const gchar* DesktopFormatter::getFullTimeFormatString() const break; } - return getDefaultHeaderTimeFormat(twelvehour, show_seconds); + return default_header_time_format(twelvehour, show_seconds); } const gchar* DesktopFormatter::getDateFormat(bool show_day, bool show_date, bool show_year) const diff --git a/src/formatter.cpp b/src/formatter.cpp index 638eac4..9aa9bbb 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -122,8 +122,8 @@ public: m_owner(owner), m_clock(clock) { - m_owner->headerFormat.changed().connect([this](const std::string& /*fmt*/){update_header();}); - m_clock->minuteChanged.connect([this](){update_header();}); + m_owner->header_format.changed().connect([this](const std::string& /*fmt*/){update_header();}); + m_clock->minute_changed.connect([this](){update_header();}); update_header(); restartRelativeTimer(); @@ -149,7 +149,7 @@ private: void update_header() { // update the header property - const auto fmt = m_owner->headerFormat.get(); + const auto fmt = m_owner->header_format.get(); const auto str = m_clock->localtime().format(fmt); m_owner->header.set(str); @@ -197,7 +197,7 @@ private: static gboolean onRelativeTimer(gpointer gself) { auto self = static_cast(gself); - self->m_owner->relativeFormatChanged(); + self->m_owner->relative_format_changed(); self->restartRelativeTimer(); return G_SOURCE_REMOVE; } @@ -225,7 +225,7 @@ Formatter::~Formatter() } const char* -Formatter::getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds) +Formatter::default_header_time_format(bool twelvehour, bool show_seconds) { const char* fmt; @@ -250,7 +250,7 @@ Formatter::getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds) ***/ std::string -Formatter::getRelativeFormat(GDateTime* then_begin, GDateTime* then_end) const +Formatter::relative_format(GDateTime* then_begin, GDateTime* then_end) const { auto cstr = generate_full_format_string_at_time (p->m_clock->localtime().get(), then_begin, then_end); const std::string ret = cstr; diff --git a/src/menu.cpp b/src/menu.cpp index e92d398..91f7dd2 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -90,12 +90,12 @@ protected: m_formatter->header.changed().connect([this](const std::string&){ update_header(); }); - m_formatter->headerFormat.changed().connect([this](const std::string&){ + m_formatter->header_format.changed().connect([this](const std::string&){ update_section(Locations); // need to update x-canonical-time-format }); - m_formatter->relativeFormatChanged.connect([this](){ - update_section(Appointments); // uses formatter.getRelativeFormat() - update_section(Locations); // uses formatter.getRelativeFormat() + m_formatter->relative_format_changed.connect([this](){ + update_section(Appointments); // uses formatter.relative_format() + update_section(Locations); // uses formatter.relative_format() }); m_state->settings->show_clock.changed().connect([this](bool){ update_header(); // update header's label @@ -110,7 +110,7 @@ protected: m_state->planner->upcoming.changed().connect([this](const std::vector&){ update_section(Appointments); // "upcoming" is the list of Appointments we show }); - m_state->clock->dateChanged.connect([this](){ + m_state->clock->date_changed.connect([this](){ update_section(Calendar); // need to update the Date menuitem update_section(Locations); // locations' relative time may have changed }); @@ -305,7 +305,7 @@ private: GDateTime* begin = appt.begin(); GDateTime* end = appt.end(); - auto fmt = m_formatter->getRelativeFormat(begin, end); + auto fmt = m_formatter->relative_format(begin, end); auto unix_time = g_date_time_to_unix(begin); auto menu_item = g_menu_item_new (appt.summary.c_str(), nullptr); @@ -380,7 +380,7 @@ private: const auto& zone = location.zone(); const auto& name = location.name(); const auto zone_now = now.to_timezone(zone); - const auto fmt = m_formatter->getRelativeFormat(zone_now.get()); + const auto fmt = m_formatter->relative_format(zone_now.get()); auto detailed_action = g_strdup_printf("indicator.set-location::%s %s", zone.c_str(), name.c_str()); auto i = g_menu_item_new (name.c_str(), detailed_action); g_menu_item_set_attribute(i, "x-canonical-type", "s", "com.canonical.indicator.location"); diff --git a/src/planner-eds.cpp b/src/planner-eds.cpp index 98cfe0a..cb42d6e 100644 --- a/src/planner-eds.cpp +++ b/src/planner-eds.cpp @@ -227,7 +227,7 @@ private: { getAppointments(begin, end, [this](const std::vector& appointments) { g_debug("got %d appointments in this calendar month", (int)appointments.size()); - m_owner.thisMonth.set(appointments); + m_owner.this_month.set(appointments); }); } g_clear_pointer(&begin, g_date_time_unref); diff --git a/tests/test-clock.cpp b/tests/test-clock.cpp index 4271374..4287e1c 100644 --- a/tests/test-clock.cpp +++ b/tests/test-clock.cpp @@ -54,12 +54,12 @@ TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute) LiveClock clock(zones); wait_msec(500); // wait for the bus to set up - // count how many times clock.minuteChanged() is emitted over the next minute + // count how many times clock.minute_changed() is emitted over the next minute const DateTime now = clock.localtime(); const auto gnow = now.get(); auto gthen = g_date_time_add_minutes(gnow, 1); int count = 0; - clock.minuteChanged.connect([&count](){count++;}); + clock.minute_changed.connect([&count](){count++;}); const auto msec = g_date_time_difference(gthen,gnow) / 1000; wait_msec(msec); EXPECT_EQ(1, count); @@ -95,7 +95,7 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew) g_time_zone_unref(tz_nyc); /// change the timezones! - clock.minuteChanged.connect([this](){ + clock.minute_changed.connect([this](){ g_main_loop_quit(loop); }); g_idle_add([](gpointer gs){ @@ -124,7 +124,7 @@ TEST_F(ClockFixture, SleepTriggersSkew) wait_msec(500); // wait for the bus to set up bool skewed = false; - clock.minuteChanged.connect([&skewed, this](){ + clock.minute_changed.connect([&skewed, this](){ skewed = true; g_main_loop_quit(loop); return G_SOURCE_REMOVE; diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp index 9950453..01df4f2 100644 --- a/tests/test-formatter.cpp +++ b/tests/test-formatter.cpp @@ -97,7 +97,7 @@ TEST_F(FormatterFixture, TestPhoneHeader) if(Set24hLocale()) { PhoneFormatter formatter(clock); - EXPECT_EQ(std::string("%H:%M"), formatter.headerFormat.get()); + EXPECT_EQ(std::string("%H:%M"), formatter.header_format.get()); EXPECT_EQ(std::string("18:30"), formatter.header.get()); } @@ -105,7 +105,7 @@ TEST_F(FormatterFixture, TestPhoneHeader) if(Set12hLocale()) { PhoneFormatter formatter(clock); - EXPECT_EQ(std::string("%l:%M %p"), formatter.headerFormat.get()); + EXPECT_EQ(std::string("%l:%M %p"), formatter.header_format.get()); EXPECT_EQ(std::string(" 6:30 PM"), formatter.header.get()); } } @@ -156,7 +156,7 @@ TEST_F(FormatterFixture, TestDesktopHeader) m_settings->show_date.set(test_case.show_date); m_settings->show_year.set(test_case.show_year); - ASSERT_STREQ(test_case.expected_format_string, f.headerFormat.get().c_str()); + ASSERT_STREQ(test_case.expected_format_string, f.header_format.get().c_str()); } } } @@ -196,7 +196,7 @@ TEST_F(FormatterFixture, TestUpcomingTimes) std::shared_ptr clock (new MockClock(DateTime(test_case.now))); DesktopFormatter f(clock, m_settings); - const auto fmt = f.getRelativeFormat(test_case.then); + const auto fmt = f.relative_format(test_case.then); ASSERT_EQ(test_case.expected_format_string, fmt); g_clear_pointer(&test_case.now, g_date_time_unref); @@ -239,7 +239,7 @@ TEST_F(FormatterFixture, TestEventTimes) std::shared_ptr clock(new MockClock(DateTime(test_case.now))); DesktopFormatter f(clock, m_settings); - const auto fmt = f.getRelativeFormat(test_case.then, test_case.then_end); + const auto fmt = f.relative_format(test_case.then, test_case.then_end); ASSERT_STREQ(test_case.expected_format_string, fmt.c_str()); g_clear_pointer(&test_case.now, g_date_time_unref); diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 562b358..eab8596 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -356,11 +356,11 @@ TEST_F(LiveActionsFixture, CalendarState) a2.begin = next_begin; a2.end = next_end; - m_state->planner->thisMonth.set(std::vector({a1, a2})); + m_state->planner->this_month.set(std::vector({a1, a2})); /// /// Now test the calendar state again. - /// The thisMonth field should now contain the appointments we just added. + /// The this_month field should now contain the appointments we just added. /// calendar_state = g_action_group_get_action_state (action_group, "calendar"); diff --git a/tests/test-planner.cpp b/tests/test-planner.cpp index 3072aea..b476ee8 100644 --- a/tests/test-planner.cpp +++ b/tests/test-planner.cpp @@ -47,9 +47,9 @@ TEST_F(PlannerFixture, EDS) planner.time.set(DateTime(now)); wait_msec(2500); - std::vector thisMonth = planner.thisMonth.get(); - std::cerr << thisMonth.size() << " appointments this month" << std::endl; - for(const auto& a : thisMonth) + std::vector 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; } -- cgit v1.2.3