From 12c6fdc0676521cf5ce6e7b92c9cc2da44a7c3db Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Feb 2016 18:08:13 -0600 Subject: add Settings tests for blacklisting apps' notifications --- tests/test-settings.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests/test-settings.cpp') diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 3af9eab..d18b58a 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -22,6 +22,11 @@ #include #include +extern "C" +{ + #include +} + using namespace ayatana::indicator::datetime; /*** @@ -38,18 +43,26 @@ protected: std::shared_ptr m_live; std::shared_ptr m_settings; GSettings * m_gsettings; + GSettings * m_gsettings_cunh; void SetUp() override { super::SetUp(); m_gsettings = g_settings_new(SETTINGS_INTERFACE); + + if (ayatana_common_utils_is_lomiri()) + { + m_gsettings_cunh = g_settings_new(SETTINGS_CUNH_SCHEMA_ID); + } + m_live.reset(new LiveSettings); m_settings = std::dynamic_pointer_cast(m_live); } void TearDown() override { + g_clear_object(&m_gsettings_cunh); g_clear_object(&m_gsettings); m_settings.reset(); m_live.reset(); @@ -221,3 +234,39 @@ TEST_F(SettingsFixture, Locations) g_strfreev(tmp); EXPECT_EQ(bv, vtmp); } + +TEST_F(SettingsFixture, MutedApps) +{ + const auto key = SETTINGS_CUNH_BLACKLIST_S; + + struct { + std::string pkgname; + std::string appname; + } apps[] = { + { "", "lomiri-system-settings" }, + { "com.lomiri.calendar", "calendar" }, + { "com.lomiri.developer.webapps.webapp-facebook", "webapp-facebook" }, + { "com.lomiri.reminders", "reminders" } + }; + std::set> apps_set; + for (const auto& app : apps) + apps_set.insert(std::make_pair(app.pkgname, app.appname)); + + // test that changing Settings is reflected in the schema + m_settings->muted_apps.set(apps_set); + auto v = g_settings_get_value(m_gsettings_cunh, key); + auto str = g_variant_print(v, true); + EXPECT_STREQ("[('', 'lomiri-system-settings'), ('com.lomiri.calendar', 'calendar'), ('com.lomiri.developer.webapps.webapp-facebook', 'webapp-facebook'), ('com.lomiri.reminders', 'reminders')]", str); + g_clear_pointer(&str, g_free); + + // test that clearing the schema clears the settings + g_settings_reset(m_gsettings_cunh, key); + EXPECT_EQ(0, m_settings->muted_apps.get().size()); + + // test thst setting the schema updates the settings + g_settings_set_value(m_gsettings_cunh, key, v); + EXPECT_EQ(apps_set, m_settings->muted_apps.get()); + + // cleanup + g_clear_pointer(&v, g_variant_unref); +} -- cgit v1.2.3 From 9c7c869ae51fffe7ce560faf0d3d2cecf5743563 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Wed, 22 Jun 2016 15:37:55 -0300 Subject: Update indicator-datetime to work with the new notification settings --- include/datetime/settings-live.h | 12 ++-- include/datetime/settings-shared.h | 9 ++- include/datetime/settings.h | 6 +- src/settings-live.cpp | 115 ++++++++++++++++++++++--------------- src/snap.cpp | 45 ++++++++++----- tests/test-notification.cpp | 26 ++++----- tests/test-settings.cpp | 111 ++++++++++++++--------------------- 7 files changed, 173 insertions(+), 151 deletions(-) (limited to 'tests/test-settings.cpp') diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 330b8e8..4aeaa9b 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -39,9 +39,9 @@ public: private: static void on_changed_ccid(GSettings*, gchar*, gpointer); - static void on_changed_cunh(GSettings*, gchar*, gpointer); + static void on_changed_cal_notification(GSettings*, gchar*, gpointer); void update_key_ccid(const std::string& key); - void update_key_cunh(const std::string& key); + void update_key_cal_notification(const std::string& key); void update_custom_time_format(); void update_locations(); @@ -62,10 +62,14 @@ private: void update_alarm_duration(); void update_alarm_haptic(); void update_snooze_duration(); - void update_muted_apps(); + void update_cal_notification_enabled(); + void update_cal_notification_sounds(); + void update_cal_notification_vibrations(); + void update_cal_notification_bubbles(); + void update_cal_notification_list(); GSettings* m_settings; - GSettings* m_settings_cunh; + GSettings* m_settings_cal_notification; // we've got a raw pointer here, so disable copying LiveSettings(const LiveSettings&) =delete; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index f385e7a..236b8f1 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -51,7 +51,12 @@ TimeFormatMode; #define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback" #define SETTINGS_SNOOZE_DURATION_S "snooze-duration-minutes" -#define SETTINGS_CUNH_SCHEMA_ID "com.lomiri.notifications.hub" -#define SETTINGS_CUNH_BLACKLIST_S "blacklist" +#define SETTINGS_NOTIFY_SCHEMA_ID "com.lomiri.notifications.settings" +#define SETTINGS_NOTIFY_CALENDAR_PATH "/com/lomiri/NotificationSettings/com.lomiri.calendar/calendar/" +#define SETTINGS_NOTIFY_ENABLED_KEY "enable-notifications" +#define SETTINGS_NOTIFY_SOUNDS_KEY "use-sounds-notifications" +#define SETTINGS_NOTIFY_VIBRATIONS_KEY "use-vibrations-notifications" +#define SETTINGS_NOTIFY_BUBBLES_KEY "use-bubbles-notifications" +#define SETTINGS_NOTIFY_LIST_KEY "use-list-notifications" #endif // INDICATOR_DATETIME_SETTINGS_SHARED diff --git a/include/datetime/settings.h b/include/datetime/settings.h index d5e81c6..5ae00f6 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -61,7 +61,11 @@ public: core::Property alarm_volume; core::Property alarm_duration; core::Property snooze_duration; - core::Property>> muted_apps; + core::Property cal_notification_enabled; + core::Property cal_notification_sounds; + core::Property cal_notification_vibrations; + core::Property cal_notification_bubbles; + core::Property cal_notification_list; }; } // namespace datetime diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 6504d7d..f908c05 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -34,7 +34,7 @@ namespace datetime { LiveSettings::~LiveSettings() { - g_clear_object(&m_settings_cunh); + g_clear_object(&m_settings_cal_notification); g_clear_object(&m_settings); } @@ -44,8 +44,8 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) if (ayatana_common_utils_is_lomiri()) { - m_settings_cunh = g_settings_new(SETTINGS_CUNH_SCHEMA_ID); - g_signal_connect (m_settings_cunh, "changed", G_CALLBACK(on_changed_cunh), this); + m_settings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); } // init the Properties from the GSettings backend @@ -68,7 +68,11 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) update_alarm_duration(); update_alarm_haptic(); update_snooze_duration(); - update_muted_apps(); + update_cal_notification_enabled(); + update_cal_notification_sounds(); + update_cal_notification_vibrations(); + update_cal_notification_bubbles(); + update_cal_notification_list(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -76,20 +80,6 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) g_settings_set_string(m_settings, SETTINGS_CUSTOM_TIME_FORMAT_S, value.c_str()); }); - if (ayatana_common_utils_is_lomiri()) - { - muted_apps.changed().connect([this](const std::set>& value){ - GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)")); - for(const auto& app : value){ - const std::string& pkgname {app.first}; - const std::string& appname {app.second}; - g_variant_builder_add(&builder, "(ss)", pkgname.c_str(), appname.c_str()); - } - g_settings_set_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S, g_variant_builder_end(&builder)); - }); - } - locations.changed().connect([this](const std::vector& value){ const int n = value.size(); gchar** strv = g_new0(gchar*, n+1); @@ -166,6 +156,26 @@ LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) snooze_duration.changed().connect([this](unsigned int value){ g_settings_set_uint(m_settings, SETTINGS_SNOOZE_DURATION_S, value); }); + + cal_notification_enabled.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY, value); + }); + + cal_notification_sounds.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY, value); + }); + + cal_notification_vibrations.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY, value); + }); + + cal_notification_bubbles.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY, value); + }); + + cal_notification_list.changed().connect([this](bool value){ + g_settings_set_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY, value); + }); } /*** @@ -189,27 +199,6 @@ void LiveSettings::update_locations() locations.set(l); } -void LiveSettings::update_muted_apps() -{ - if (ayatana_common_utils_is_lomiri()) - { - std::set> apps; - - auto blacklist = g_settings_get_value(m_settings_cunh, SETTINGS_CUNH_BLACKLIST_S); - GVariantIter* iter {nullptr}; - g_variant_get (blacklist, "a(ss)", &iter); - gchar* pkgname; - gchar* appname; - while (g_variant_iter_loop (iter, "(ss)", &pkgname, &appname)) { - apps.insert(std::make_pair(pkgname,appname)); - } - g_variant_iter_free (iter); - g_clear_pointer(&blacklist, g_variant_unref); - - muted_apps.set(apps); - } -} - void LiveSettings::update_show_calendar() { const auto val = g_settings_get_boolean(m_settings, SETTINGS_SHOW_CALENDAR_S); @@ -308,21 +297,55 @@ void LiveSettings::update_snooze_duration() snooze_duration.set(g_settings_get_uint(m_settings, SETTINGS_SNOOZE_DURATION_S)); } +void LiveSettings::update_cal_notification_enabled() +{ + cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); +} + +void LiveSettings::update_cal_notification_sounds() +{ + cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); +} + +void LiveSettings::update_cal_notification_vibrations() +{ + cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); +} + +void LiveSettings::update_cal_notification_bubbles() +{ + cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); +} + +void LiveSettings::update_cal_notification_list() +{ + cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); +} + /*** **** ***/ -void LiveSettings::on_changed_cunh(GSettings* /*settings*/, - gchar* key, - gpointer gself) +void LiveSettings::on_changed_cal_notification(GSettings* /*settings*/, + gchar* key, + gpointer gself) { - static_cast(gself)->update_key_cunh(key); + static_cast(gself)->update_key_cal_notification(key); } -void LiveSettings::update_key_cunh(const std::string& key) + +void LiveSettings::update_key_cal_notification(const std::string& key) { - if (key == SETTINGS_CUNH_BLACKLIST_S) - update_muted_apps(); + if (key == SETTINGS_NOTIFY_ENABLED_KEY) + update_cal_notification_enabled(); + else if (key == SETTINGS_NOTIFY_SOUNDS_KEY) + update_cal_notification_sounds(); + else if (key == SETTINGS_NOTIFY_VIBRATIONS_KEY) + update_cal_notification_vibrations(); + else if (key == SETTINGS_NOTIFY_BUBBLES_KEY) + update_cal_notification_bubbles(); + else if (key == SETTINGS_NOTIFY_LIST_KEY) + update_cal_notification_list(); } /*** diff --git a/src/snap.cpp b/src/snap.cpp index 51d04ae..1e71e7b 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -83,9 +83,9 @@ public: const Alarm& alarm, response_func on_response) { - // If calendar notifications are muted, don't show them - if (!appointment.is_ubuntu_alarm() && calendar_events_are_muted()) { - g_debug("Skipping muted calendar event '%s' notification", appointment.summary.c_str()); + // If calendar notifications are disabled, don't show them + if (!appointment.is_ubuntu_alarm() && !calendar_notifications_are_enabled()) { + g_debug("Skipping disabled calendar event '%s' notification", appointment.summary.c_str()); return; } @@ -96,13 +96,14 @@ public: const bool interactive = appointment.is_ubuntu_alarm() && m_engine->supports_actions(); // force the system to stay awake - auto awake = std::make_shared(m_engine->app_name()); + std::shared_ptr awake; + if (calendar_bubbles_enabled()) { + awake = std::make_shared(m_engine->app_name()); + } // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; - // FIXME: only play sounds for alarms for now, we should itegrate it with - // system settings to decide if we should play sounds for calendar notification or not - if (appointment.is_ubuntu_alarm()) { + if (appointment.is_ubuntu_alarm() || calendar_sounds_enabled()) { // create the sound. const auto role = appointment.is_ubuntu_alarm() ? "alarm" : "alert"; const auto uri = get_alarm_uri(appointment, alarm, m_settings); @@ -113,7 +114,7 @@ public: // create the haptic feedback... std::shared_ptr haptic; - if (should_vibrate()) { + if (should_vibrate() && calendar_vibrations_enabled()) { const auto haptic_mode = m_settings->alarm_haptic.get(); if (haptic_mode == "pulse") haptic = std::make_shared(ain::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm()); @@ -189,15 +190,29 @@ public: private: - bool calendar_events_are_muted() const + bool calendar_notifications_are_enabled() const { - for(const auto& app : m_settings->muted_apps.get()) { - if (app.first == "com.ubuntu.calendar") { - return true; - } - } + return m_settings->cal_notification_enabled.get(); + } + + bool calendar_sounds_enabled() const + { + return m_settings->cal_notification_sounds.get(); + } - return false; + bool calendar_vibrations_enabled() const + { + return m_settings->cal_notification_vibrations.get(); + } + + bool calendar_bubbles_enabled() const + { + return m_settings->cal_notification_bubbles.get(); + } + + bool calendar_list_enabled() const + { + return m_settings->cal_notification_list.get(); } static void on_sound_proxy_ready(GObject* /*source_object*/, GAsyncResult* res, gpointer gself) diff --git a/tests/test-notification.cpp b/tests/test-notification.cpp index 50d7b57..b84c6f8 100644 --- a/tests/test-notification.cpp +++ b/tests/test-notification.cpp @@ -87,18 +87,16 @@ TEST_F(NotificationFixture,Notification) { false, true, false } }; - // combinatorial factor #4: system settings' notifications app blacklist - const std::set> blacklist_calendar { std::make_pair(std::string{"com.lomiri.calendar"}, std::string{"calendar-app"}) }; - const std::set> blacklist_empty; + // combinatorial factor #4: system settings' notifications disabled struct { - std::set> muted_apps; // apps that should not trigger notifications + bool cal_notification_enabled; // calendar app can trigger notifications std::set expected_notify_called; // do we expect the notification to show? std::set expected_vibrate_called; // do we expect the phone to vibrate? - } test_muted_apps[] = { - { blacklist_empty, std::set{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT }, - std::set{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT } }, - { blacklist_calendar, std::set{ Appointment::Type::UBUNTU_ALARM }, - std::set{ Appointment::Type::UBUNTU_ALARM } } + } test_cal_disabled[] = { + { true, std::set{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT }, + std::set{ Appointment::Type::UBUNTU_ALARM, Appointment::Type::EVENT } }, + { false, std::set{ Appointment::Type::UBUNTU_ALARM }, + std::set{ Appointment::Type::UBUNTU_ALARM } } }; for (const auto& test_appt : test_appts) @@ -107,20 +105,20 @@ TEST_F(NotificationFixture,Notification) { for (const auto& test_vibes : test_other_vibrations) { - for (const auto& test_muted : test_muted_apps) + for (const auto& test_disabled : test_cal_disabled) { const bool expected_notify_called = test_appt.expected_notify_called && test_vibes.expected_notify_called - && (test_muted.expected_notify_called.count(test_appt.appt.type) > 0) + && (test_disabled.expected_notify_called.count(test_appt.appt.type) > 0) && test_haptic.expected_notify_called; const bool expected_vibrate_called = test_appt.expected_vibrate_called && test_vibes.expected_vibrate_called - && (test_muted.expected_vibrate_called.count(test_appt.appt.type) > 0) + && (test_disabled.expected_vibrate_called.count(test_appt.appt.type) > 0) && test_haptic.expected_vibrate_called; - // set test case properties: blacklist - settings->muted_apps.set(test_muted.muted_apps); + // set test case properties: cal_notification_enabled + settings->cal_notification_enabled.set(test_disabled.cal_notification_enabled); // set test case properties: haptic mode settings->alarm_haptic.set(test_haptic.haptic_mode); diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index d18b58a..d0ee369 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -43,7 +43,7 @@ protected: std::shared_ptr m_live; std::shared_ptr m_settings; GSettings * m_gsettings; - GSettings * m_gsettings_cunh; + GSettings * m_gsettings_cal_notification; void SetUp() override { @@ -53,7 +53,7 @@ protected: if (ayatana_common_utils_is_lomiri()) { - m_gsettings_cunh = g_settings_new(SETTINGS_CUNH_SCHEMA_ID); + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); } m_live.reset(new LiveSettings); @@ -62,7 +62,7 @@ protected: void TearDown() override { - g_clear_object(&m_gsettings_cunh); + g_clear_object(&m_gsettings_cal_notification); g_clear_object(&m_gsettings); m_settings.reset(); m_live.reset(); @@ -70,62 +70,62 @@ protected: super::TearDown(); } - void TestBoolProperty(core::Property& property, const gchar* key) + void TestBoolProperty(GSettings* gsettings, core::Property& property, const gchar* key) { - EXPECT_EQ(g_settings_get_boolean(m_gsettings, key), property.get()); - g_settings_set_boolean(m_gsettings, key, false); + EXPECT_EQ(g_settings_get_boolean(gsettings, key), property.get()); + g_settings_set_boolean(gsettings, key, false); EXPECT_FALSE(property.get()); - g_settings_set_boolean(m_gsettings, key, true); + g_settings_set_boolean(gsettings, key, true); EXPECT_TRUE(property.get()); property.set(false); - EXPECT_FALSE(g_settings_get_boolean(m_gsettings, key)); + EXPECT_FALSE(g_settings_get_boolean(gsettings, key)); property.set(true); - EXPECT_TRUE(g_settings_get_boolean(m_gsettings, key)); + EXPECT_TRUE(g_settings_get_boolean(gsettings, key)); } - void TestStringProperty(core::Property& property, const gchar* key) + void TestStringProperty(GSettings* gsettings, core::Property& property, const gchar* key) { gchar* tmp; std::string str; - tmp = g_settings_get_string(m_gsettings, key); + tmp = g_settings_get_string(gsettings, key); EXPECT_EQ(tmp, property.get()); g_clear_pointer(&tmp, g_free); str = "a"; - g_settings_set_string(m_gsettings, key, str.c_str()); + g_settings_set_string(gsettings, key, str.c_str()); EXPECT_EQ(str, property.get()); str = "b"; - g_settings_set_string(m_gsettings, key, str.c_str()); + g_settings_set_string(gsettings, key, str.c_str()); EXPECT_EQ(str, property.get()); str = "a"; property.set(str); - tmp = g_settings_get_string(m_gsettings, key); + tmp = g_settings_get_string(gsettings, key); EXPECT_EQ(str, tmp); g_clear_pointer(&tmp, g_free); str = "b"; property.set(str); - tmp = g_settings_get_string(m_gsettings, key); + tmp = g_settings_get_string(gsettings, key); EXPECT_EQ(str, tmp); g_clear_pointer(&tmp, g_free); } - void TestUIntProperty(core::Property& property, const gchar* key) + void TestUIntProperty(GSettings* gsettings, core::Property& property, const gchar* key) { - EXPECT_EQ(g_settings_get_uint(m_gsettings, key), property.get()); + EXPECT_EQ(g_settings_get_uint(gsettings, key), property.get()); unsigned int expected_values[] = { 1, 2, 3 }; // modify GSettings and confirm that the new value is propagated for(const auto& expected_value : expected_values) { - g_settings_set_uint(m_gsettings, key, expected_value); + g_settings_set_uint(gsettings, key, expected_value); EXPECT_EQ(expected_value, property.get()); - EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key)); + EXPECT_EQ(expected_value, g_settings_get_uint(gsettings, key)); } // modify the property and confirm that the new value is propagated @@ -133,7 +133,7 @@ protected: { property.set(expected_value); EXPECT_EQ(expected_value, property.get()); - EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key)); + EXPECT_EQ(expected_value, g_settings_get_uint(gsettings, key)); } } }; @@ -149,31 +149,31 @@ TEST_F(SettingsFixture, HelloWorld) TEST_F(SettingsFixture, BoolProperties) { - TestBoolProperty(m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S); - TestBoolProperty(m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S); - TestBoolProperty(m_settings->show_date, SETTINGS_SHOW_DATE_S); - TestBoolProperty(m_settings->show_day, SETTINGS_SHOW_DAY_S); - TestBoolProperty(m_settings->show_detected_location, SETTINGS_SHOW_DETECTED_S); - TestBoolProperty(m_settings->show_events, SETTINGS_SHOW_EVENTS_S); - TestBoolProperty(m_settings->show_locations, SETTINGS_SHOW_LOCATIONS_S); - TestBoolProperty(m_settings->show_week_numbers, SETTINGS_SHOW_WEEK_NUMBERS_S); - TestBoolProperty(m_settings->show_year, SETTINGS_SHOW_YEAR_S); + TestBoolProperty(m_gsettings, m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S); + TestBoolProperty(m_gsettings, m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S); + TestBoolProperty(m_gsettings, m_settings->show_date, SETTINGS_SHOW_DATE_S); + TestBoolProperty(m_gsettings, m_settings->show_day, SETTINGS_SHOW_DAY_S); + TestBoolProperty(m_gsettings, m_settings->show_detected_location, SETTINGS_SHOW_DETECTED_S); + TestBoolProperty(m_gsettings, m_settings->show_events, SETTINGS_SHOW_EVENTS_S); + TestBoolProperty(m_gsettings, m_settings->show_locations, SETTINGS_SHOW_LOCATIONS_S); + TestBoolProperty(m_gsettings, m_settings->show_week_numbers, SETTINGS_SHOW_WEEK_NUMBERS_S); + TestBoolProperty(m_gsettings, m_settings->show_year, SETTINGS_SHOW_YEAR_S); } TEST_F(SettingsFixture, UIntProperties) { - TestUIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); - TestUIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); - TestUIntProperty(m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S); + TestUIntProperty(m_gsettings, m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); + TestUIntProperty(m_gsettings, m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); + TestUIntProperty(m_gsettings, m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S); } TEST_F(SettingsFixture, StringProperties) { - TestStringProperty(m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S); - TestStringProperty(m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S); - TestStringProperty(m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S); - TestStringProperty(m_settings->calendar_sound, SETTINGS_CALENDAR_SOUND_S); - TestStringProperty(m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S); + TestStringProperty(m_gsettings, m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S); + TestStringProperty(m_gsettings, m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S); + TestStringProperty(m_gsettings, m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S); + TestStringProperty(m_gsettings, m_settings->calendar_sound, SETTINGS_CALENDAR_SOUND_S); + TestStringProperty(m_gsettings, m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S); } TEST_F(SettingsFixture, TimeFormatMode) @@ -237,36 +237,9 @@ TEST_F(SettingsFixture, Locations) TEST_F(SettingsFixture, MutedApps) { - const auto key = SETTINGS_CUNH_BLACKLIST_S; - - struct { - std::string pkgname; - std::string appname; - } apps[] = { - { "", "lomiri-system-settings" }, - { "com.lomiri.calendar", "calendar" }, - { "com.lomiri.developer.webapps.webapp-facebook", "webapp-facebook" }, - { "com.lomiri.reminders", "reminders" } - }; - std::set> apps_set; - for (const auto& app : apps) - apps_set.insert(std::make_pair(app.pkgname, app.appname)); - - // test that changing Settings is reflected in the schema - m_settings->muted_apps.set(apps_set); - auto v = g_settings_get_value(m_gsettings_cunh, key); - auto str = g_variant_print(v, true); - EXPECT_STREQ("[('', 'lomiri-system-settings'), ('com.lomiri.calendar', 'calendar'), ('com.lomiri.developer.webapps.webapp-facebook', 'webapp-facebook'), ('com.lomiri.reminders', 'reminders')]", str); - g_clear_pointer(&str, g_free); - - // test that clearing the schema clears the settings - g_settings_reset(m_gsettings_cunh, key); - EXPECT_EQ(0, m_settings->muted_apps.get().size()); - - // test thst setting the schema updates the settings - g_settings_set_value(m_gsettings_cunh, key, v); - EXPECT_EQ(apps_set, m_settings->muted_apps.get()); - - // cleanup - g_clear_pointer(&v, g_variant_unref); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_enabled, SETTINGS_NOTIFY_ENABLED_KEY); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_sounds, SETTINGS_NOTIFY_SOUNDS_KEY); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_vibrations, SETTINGS_NOTIFY_VIBRATIONS_KEY); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_bubbles, SETTINGS_NOTIFY_BUBBLES_KEY); + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_list, SETTINGS_NOTIFY_LIST_KEY); } -- cgit v1.2.3 From 2203d0b2031b7dc99fe7381a9efac431bc3ad410 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 24 Jun 2016 11:45:30 -0300 Subject: Do not fail tests if schema is not installed --- src/settings-live.cpp | 12 +++++++++--- tests/test-settings.cpp | 10 +++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'tests/test-settings.cpp') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 39d8e18..17c0ef7 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -38,14 +38,20 @@ LiveSettings::~LiveSettings() g_clear_object(&m_settings); } -LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)) +LiveSettings::LiveSettings(): m_settings(g_settings_new(SETTINGS_INTERFACE)), m_gsettings_cal_notification(NULL) { g_signal_connect (m_settings, "changed", G_CALLBACK(on_changed_ccid), this); if (ayatana_common_utils_is_lomiri()) { - m_settings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); - g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + GSettingsSchemaSource *source = g_settings_schema_source_get_default(); + if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + } + + if (m_gsettings_cal_notification) { + g_signal_connect (m_settings_cal_notification, "changed", G_CALLBACK(on_changed_cal_notification), this); + } } // init the Properties from the GSettings backend diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index d0ee369..104750a 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -44,6 +44,7 @@ protected: std::shared_ptr m_settings; GSettings * m_gsettings; GSettings * m_gsettings_cal_notification; + GSettingsSchemaSource *source = g_settings_schema_source_get_default(); void SetUp() override { @@ -53,7 +54,10 @@ protected: if (ayatana_common_utils_is_lomiri()) { - m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + + if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + } } m_live.reset(new LiveSettings); @@ -237,6 +241,10 @@ TEST_F(SettingsFixture, Locations) TEST_F(SettingsFixture, MutedApps) { + if (!m_gsettings_cal_notification) { + return; + } + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_enabled, SETTINGS_NOTIFY_ENABLED_KEY); TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_sounds, SETTINGS_NOTIFY_SOUNDS_KEY); TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_vibrations, SETTINGS_NOTIFY_VIBRATIONS_KEY); -- cgit v1.2.3 From fbef2857a3034d72d2afe9878900979dab3df27d Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 24 Jun 2016 13:46:33 -0300 Subject: Do not fail test if GSettings schema is not installed --- tests/test-settings.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests/test-settings.cpp') diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 104750a..e8af7a0 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -50,7 +50,9 @@ protected: { super::SetUp(); - m_gsettings = g_settings_new(SETTINGS_INTERFACE); + if (g_settings_schema_source_lookup(source, SETTINGS_INTERFACE, true)) { + m_gsettings = g_settings_new(SETTINGS_INTERFACE); + } if (ayatana_common_utils_is_lomiri()) { @@ -153,6 +155,10 @@ TEST_F(SettingsFixture, HelloWorld) TEST_F(SettingsFixture, BoolProperties) { + if (!m_gsettings) { + return; + } + TestBoolProperty(m_gsettings, m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S); TestBoolProperty(m_gsettings, m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S); TestBoolProperty(m_gsettings, m_settings->show_date, SETTINGS_SHOW_DATE_S); @@ -166,6 +172,10 @@ TEST_F(SettingsFixture, BoolProperties) TEST_F(SettingsFixture, UIntProperties) { + if (!m_gsettings) { + return; + } + TestUIntProperty(m_gsettings, m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); TestUIntProperty(m_gsettings, m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); TestUIntProperty(m_gsettings, m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S); @@ -173,6 +183,10 @@ TEST_F(SettingsFixture, UIntProperties) TEST_F(SettingsFixture, StringProperties) { + if (!m_gsettings) { + return; + } + TestStringProperty(m_gsettings, m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S); TestStringProperty(m_gsettings, m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S); TestStringProperty(m_gsettings, m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S); @@ -182,6 +196,10 @@ TEST_F(SettingsFixture, StringProperties) TEST_F(SettingsFixture, TimeFormatMode) { + if (!m_gsettings) { + return; + } + const auto key = SETTINGS_TIME_FORMAT_S; const TimeFormatMode modes[] = { TIME_FORMAT_MODE_LOCALE_DEFAULT, TIME_FORMAT_MODE_12_HOUR, @@ -214,6 +232,10 @@ namespace TEST_F(SettingsFixture, Locations) { + if (!m_gsettings) { + return; + } + const auto key = SETTINGS_LOCATIONS_S; const gchar* astrv[] = {"America/Los_Angeles Oakland", "America/Chicago Oklahoma City", "Europe/London London", nullptr}; -- cgit v1.2.3 From e23f7c25c0e6558d529239db1b034e66220f8d27 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 24 Jun 2016 16:55:50 -0300 Subject: Fix settings test check so we do not fail if GSettings schema is missing --- src/settings-live.cpp | 10 ++++----- tests/test-settings.cpp | 58 +++++++++++++++++++++---------------------------- 2 files changed, 30 insertions(+), 38 deletions(-) (limited to 'tests/test-settings.cpp') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index d1ea91b..8060a08 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -305,7 +305,7 @@ void LiveSettings::update_snooze_duration() void LiveSettings::update_cal_notification_enabled() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); } else { cal_notification_enabled.set(true); @@ -314,7 +314,7 @@ void LiveSettings::update_cal_notification_enabled() void LiveSettings::update_cal_notification_sounds() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); } else { cal_notification_sounds.set(true); @@ -323,7 +323,7 @@ void LiveSettings::update_cal_notification_sounds() void LiveSettings::update_cal_notification_vibrations() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); } else { cal_notification_vibrations.set(true); @@ -332,7 +332,7 @@ void LiveSettings::update_cal_notification_vibrations() void LiveSettings::update_cal_notification_bubbles() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); } else { cal_notification_bubbles.set(true); @@ -341,7 +341,7 @@ void LiveSettings::update_cal_notification_bubbles() void LiveSettings::update_cal_notification_list() { - if (m_settings_cal_notification) { + if (m_settings_cal_notification != NULL) { cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); } else { cal_notification_list.set(true); diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index e8af7a0..f81a929 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -44,26 +44,30 @@ protected: std::shared_ptr m_settings; GSettings * m_gsettings; GSettings * m_gsettings_cal_notification; - GSettingsSchemaSource *source = g_settings_schema_source_get_default(); + GSettingsSchemaSource * source; void SetUp() override { super::SetUp(); + source = g_settings_schema_source_get_default(); + if (g_settings_schema_source_lookup(source, SETTINGS_INTERFACE, true)) { m_gsettings = g_settings_new(SETTINGS_INTERFACE); + } else { + m_gsettings = NULL; } - if (ayatana_common_utils_is_lomiri()) - { - - if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { - m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); - } + if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + } else { + m_gsettings_cal_notification = NULL; } - m_live.reset(new LiveSettings); - m_settings = std::dynamic_pointer_cast(m_live); + if (m_gsettings != NULL) { + m_live.reset(new LiveSettings); + m_settings = std::dynamic_pointer_cast(m_live); + } } void TearDown() override @@ -78,6 +82,10 @@ protected: void TestBoolProperty(GSettings* gsettings, core::Property& property, const gchar* key) { + if (gsettings == NULL) { + return; + } + EXPECT_EQ(g_settings_get_boolean(gsettings, key), property.get()); g_settings_set_boolean(gsettings, key, false); EXPECT_FALSE(property.get()); @@ -92,6 +100,10 @@ protected: void TestStringProperty(GSettings* gsettings, core::Property& property, const gchar* key) { + if (gsettings == NULL) { + return; + } + gchar* tmp; std::string str; @@ -122,6 +134,10 @@ protected: void TestUIntProperty(GSettings* gsettings, core::Property& property, const gchar* key) { + if (gsettings == NULL) { + return; + } + EXPECT_EQ(g_settings_get_uint(gsettings, key), property.get()); unsigned int expected_values[] = { 1, 2, 3 }; @@ -155,10 +171,6 @@ TEST_F(SettingsFixture, HelloWorld) TEST_F(SettingsFixture, BoolProperties) { - if (!m_gsettings) { - return; - } - TestBoolProperty(m_gsettings, m_settings->show_seconds, SETTINGS_SHOW_SECONDS_S); TestBoolProperty(m_gsettings, m_settings->show_calendar, SETTINGS_SHOW_CALENDAR_S); TestBoolProperty(m_gsettings, m_settings->show_date, SETTINGS_SHOW_DATE_S); @@ -172,10 +184,6 @@ TEST_F(SettingsFixture, BoolProperties) TEST_F(SettingsFixture, UIntProperties) { - if (!m_gsettings) { - return; - } - TestUIntProperty(m_gsettings, m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); TestUIntProperty(m_gsettings, m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); TestUIntProperty(m_gsettings, m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S); @@ -183,10 +191,6 @@ TEST_F(SettingsFixture, UIntProperties) TEST_F(SettingsFixture, StringProperties) { - if (!m_gsettings) { - return; - } - TestStringProperty(m_gsettings, m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S); TestStringProperty(m_gsettings, m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S); TestStringProperty(m_gsettings, m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S); @@ -196,10 +200,6 @@ TEST_F(SettingsFixture, StringProperties) TEST_F(SettingsFixture, TimeFormatMode) { - if (!m_gsettings) { - return; - } - const auto key = SETTINGS_TIME_FORMAT_S; const TimeFormatMode modes[] = { TIME_FORMAT_MODE_LOCALE_DEFAULT, TIME_FORMAT_MODE_12_HOUR, @@ -232,10 +232,6 @@ namespace TEST_F(SettingsFixture, Locations) { - if (!m_gsettings) { - return; - } - const auto key = SETTINGS_LOCATIONS_S; const gchar* astrv[] = {"America/Los_Angeles Oakland", "America/Chicago Oklahoma City", "Europe/London London", nullptr}; @@ -263,10 +259,6 @@ TEST_F(SettingsFixture, Locations) TEST_F(SettingsFixture, MutedApps) { - if (!m_gsettings_cal_notification) { - return; - } - TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_enabled, SETTINGS_NOTIFY_ENABLED_KEY); TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_sounds, SETTINGS_NOTIFY_SOUNDS_KEY); TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_vibrations, SETTINGS_NOTIFY_VIBRATIONS_KEY); -- cgit v1.2.3 From 1893e15b2ccb06b72df6bbd522ba8707eccedac1 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Wed, 29 Jun 2016 21:31:01 -0300 Subject: Undo revisions 456/457 --- src/settings-live.cpp | 10 +++++----- tests/test-settings.cpp | 36 +++++++++--------------------------- 2 files changed, 14 insertions(+), 32 deletions(-) (limited to 'tests/test-settings.cpp') diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 8060a08..d1ea91b 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -305,7 +305,7 @@ void LiveSettings::update_snooze_duration() void LiveSettings::update_cal_notification_enabled() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_enabled.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_ENABLED_KEY)); } else { cal_notification_enabled.set(true); @@ -314,7 +314,7 @@ void LiveSettings::update_cal_notification_enabled() void LiveSettings::update_cal_notification_sounds() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_sounds.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_SOUNDS_KEY)); } else { cal_notification_sounds.set(true); @@ -323,7 +323,7 @@ void LiveSettings::update_cal_notification_sounds() void LiveSettings::update_cal_notification_vibrations() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_vibrations.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_VIBRATIONS_KEY)); } else { cal_notification_vibrations.set(true); @@ -332,7 +332,7 @@ void LiveSettings::update_cal_notification_vibrations() void LiveSettings::update_cal_notification_bubbles() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_bubbles.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_BUBBLES_KEY)); } else { cal_notification_bubbles.set(true); @@ -341,7 +341,7 @@ void LiveSettings::update_cal_notification_bubbles() void LiveSettings::update_cal_notification_list() { - if (m_settings_cal_notification != NULL) { + if (m_settings_cal_notification) { cal_notification_list.set(g_settings_get_boolean(m_settings_cal_notification, SETTINGS_NOTIFY_LIST_KEY)); } else { cal_notification_list.set(true); diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index f81a929..55a88b7 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -44,30 +44,20 @@ protected: std::shared_ptr m_settings; GSettings * m_gsettings; GSettings * m_gsettings_cal_notification; - GSettingsSchemaSource * source; + GSettingsSchemaSource *source = g_settings_schema_source_get_default(); void SetUp() override { super::SetUp(); - source = g_settings_schema_source_get_default(); - - if (g_settings_schema_source_lookup(source, SETTINGS_INTERFACE, true)) { - m_gsettings = g_settings_new(SETTINGS_INTERFACE); - } else { - m_gsettings = NULL; - } + m_gsettings = g_settings_new(SETTINGS_INTERFACE); if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { - m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); - } else { - m_gsettings_cal_notification = NULL; + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); } - if (m_gsettings != NULL) { - m_live.reset(new LiveSettings); - m_settings = std::dynamic_pointer_cast(m_live); - } + m_live.reset(new LiveSettings); + m_settings = std::dynamic_pointer_cast(m_live); } void TearDown() override @@ -82,10 +72,6 @@ protected: void TestBoolProperty(GSettings* gsettings, core::Property& property, const gchar* key) { - if (gsettings == NULL) { - return; - } - EXPECT_EQ(g_settings_get_boolean(gsettings, key), property.get()); g_settings_set_boolean(gsettings, key, false); EXPECT_FALSE(property.get()); @@ -100,10 +86,6 @@ protected: void TestStringProperty(GSettings* gsettings, core::Property& property, const gchar* key) { - if (gsettings == NULL) { - return; - } - gchar* tmp; std::string str; @@ -134,10 +116,6 @@ protected: void TestUIntProperty(GSettings* gsettings, core::Property& property, const gchar* key) { - if (gsettings == NULL) { - return; - } - EXPECT_EQ(g_settings_get_uint(gsettings, key), property.get()); unsigned int expected_values[] = { 1, 2, 3 }; @@ -259,6 +237,10 @@ TEST_F(SettingsFixture, Locations) TEST_F(SettingsFixture, MutedApps) { + if (!m_gsettings_cal_notification) { + return; + } + TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_enabled, SETTINGS_NOTIFY_ENABLED_KEY); TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_sounds, SETTINGS_NOTIFY_SOUNDS_KEY); TestBoolProperty(m_gsettings_cal_notification, m_settings->cal_notification_vibrations, SETTINGS_NOTIFY_VIBRATIONS_KEY); -- cgit v1.2.3 From d425e3fadc1bca711c4dd3d5519fd831010ea4d6 Mon Sep 17 00:00:00 2001 From: Arthur Mello Date: Fri, 1 Jul 2016 16:46:40 -0300 Subject: Remove gsettings source call during unit tests Set minimal version for gsettings-ubuntu-touch-schemas package --- tests/test-settings.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'tests/test-settings.cpp') diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 55a88b7..b9658f4 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -42,19 +42,15 @@ protected: std::shared_ptr m_live; std::shared_ptr m_settings; - GSettings * m_gsettings; - GSettings * m_gsettings_cal_notification; - GSettingsSchemaSource *source = g_settings_schema_source_get_default(); + GSettings * m_gsettings {}; + GSettings * m_gsettings_cal_notification {}; void SetUp() override { super::SetUp(); m_gsettings = g_settings_new(SETTINGS_INTERFACE); - - if (g_settings_schema_source_lookup(source, SETTINGS_NOTIFY_SCHEMA_ID, true)) { - m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); - } + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); m_live.reset(new LiveSettings); m_settings = std::dynamic_pointer_cast(m_live); -- cgit v1.2.3 From 217b48352a2591150413c77ca85b6a1ef158e6d5 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 16 Jul 2021 21:52:08 +0200 Subject: Fix failing tests - include/actions-mock.h: Set return value to std::string and return an empty string - include/actions.h: Make open_alarm_app, open_appointment, open_calendar_app and open_settings_app return the uri/command - include/actions-live.h: Make open_alarm_app, open_appointment, open_calendar_app and open_settings_app return the uri/command - src/actions-live.cpp: Make open_alarm_app, open_appointment, open_calendar_app and open_settings_app return the uri/command - tests/test-live-actions.cpp: Drop last_cmd and last_url variables + use return values of actions-live functions for testing + test phone functions on lomiri only - tests/test-live-actions.cpp: test phone functions after setting XDG_CURRENT_DESKTOP - tests/test-settings.cpp: Use SETTINGS_NOTIFY_SCHEMA_ID only if it exists - tests/run-eds-ics-test.sh: Remove return statement - tests/CMakeLists.txt: Enable the timezone unit tests - tests/CMakeLists.txt: Catch race condition while attempting to copy schemas - tests/CMakeLists.txt: Exclude blocking tests on Travis for now - tests/tests-timezones.cpp: Use MockTimezone to construct LiveTimezones + drop section expecting changes after /timezone is modified (not monitored) - tests/test-formater: Change warning to plain message otherwise it can crash the test - .build.yml: Replace libmessaging-menu-dev with ayatana-indicator-messages Git build --- .build.yml | 22 +++++++------- include/datetime/actions-live.h | 8 +++--- include/datetime/actions.h | 8 +++--- src/actions-live.cpp | 57 +++++++++++++++++++++++++----------- tests/CMakeLists.txt | 39 ++++++++++++++----------- tests/actions-mock.h | 16 ++++++++--- tests/run-eds-ics-test.sh | 2 -- tests/test-formatter.cpp | 2 +- tests/test-live-actions.cpp | 64 +++++++++++++++++++++++++++-------------- tests/test-settings.cpp | 18 ++++++++---- tests/test-timezones.cpp | 21 +++----------- 11 files changed, 153 insertions(+), 104 deletions(-) (limited to 'tests/test-settings.cpp') diff --git a/.build.yml b/.build.yml index ee79826..e38f4ae 100644 --- a/.build.yml +++ b/.build.yml @@ -159,14 +159,14 @@ build_scripts: - scan-build $CHECKERS --keep-cc -o html-report make - fi -#after_scripts: -# - if [ ${BUILD_TYPE} == "scripts" ];then -# - XVFB_RUN="$(which xvfb-run || true)" -# - if [ ${DISTRO_NAME} == "debian" ];then -# - if [ -e ./autogen.sh ]; then -# - ${XVFB_RUN} make check -# - elif [ -e ./CMakeLists.txt ]; then -# - ${XVFB_RUN} make test -# - fi -# - fi -# - fi +after_scripts: + - if [ ${BUILD_TYPE} == "scripts" ];then + - XVFB_RUN="$(which xvfb-run || true)" + - if [ ${DISTRO_NAME} == "debian" ];then + - if [ -e ./autogen.sh ]; then + - ${XVFB_RUN} make check + - elif [ -e ./CMakeLists.txt ]; then + - ${XVFB_RUN} make test + - fi + - fi + - fi diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 1eb34ec..136812c 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -40,10 +40,10 @@ public: virtual ~LiveActions() =default; bool desktop_has_calendar_app() const override; - void open_alarm_app() override; - void open_appointment(const Appointment&, const DateTime&) override; - void open_calendar_app(const DateTime&) override; - void open_settings_app() override; + std::string open_alarm_app() override; + std::string open_appointment(const Appointment&, const DateTime&) override; + std::string open_calendar_app(const DateTime&) override; + std::string open_settings_app() override; void set_location(const std::string& zone, const std::string& name) override; diff --git a/include/datetime/actions.h b/include/datetime/actions.h index d866b00..5927967 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -45,10 +45,10 @@ public: virtual bool desktop_has_calendar_app() const =0; - virtual void open_alarm_app() =0; - virtual void open_appointment(const Appointment&, const DateTime&) =0; - virtual void open_calendar_app(const DateTime&) =0; - virtual void open_settings_app() =0; + virtual std::string open_alarm_app() =0; + virtual std::string open_appointment(const Appointment&, const DateTime&) =0; + virtual std::string open_calendar_app(const DateTime&) =0; + virtual std::string open_settings_app() =0; virtual void set_location(const std::string& zone, const std::string& name)=0; diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 5c49bc4..50add68 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -46,52 +46,70 @@ LiveActions::LiveActions(const std::shared_ptr& state_in): **** ***/ -void LiveActions::open_alarm_app() +std::string LiveActions::open_alarm_app() { + std::string sReturn = ""; + if (ayatana_common_utils_is_lomiri()) { - ayatana_common_utils_open_url("alarm://"); + sReturn = "alarm://"; + ayatana_common_utils_open_url(sReturn.c_str()); } else { - ayatana_common_utils_execute_command("evolution -c calendar"); + sReturn = "evolution -c calendar"; + ayatana_common_utils_execute_command(sReturn.c_str()); } + + return sReturn; } -void LiveActions::open_calendar_app(const DateTime& dt) +std::string LiveActions::open_calendar_app(const DateTime& dt) { + std::string sReturn = ""; + if (ayatana_common_utils_is_lomiri()) { const auto utc = dt.to_timezone("UTC"); - auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); - ayatana_common_utils_open_url(cmd.c_str()); + sReturn = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); + ayatana_common_utils_open_url(sReturn.c_str()); } else { const auto utc = dt.start_of_day().to_timezone("UTC"); - auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); - ayatana_common_utils_execute_command(cmd.c_str()); + sReturn = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\""); + ayatana_common_utils_execute_command(sReturn.c_str()); } + + return sReturn; } -void LiveActions::open_settings_app() +std::string LiveActions::open_settings_app() { + std::string sReturn = ""; + if (ayatana_common_utils_is_lomiri()) { - ayatana_common_utils_open_url("settings:///system/time-date"); + sReturn = "settings:///system/time-date"; + ayatana_common_utils_open_url(sReturn.c_str()); } else if (ayatana_common_utils_is_unity()) { - ayatana_common_utils_execute_command("unity-control-center datetime"); + sReturn = "unity-control-center datetime"; + ayatana_common_utils_execute_command(sReturn.c_str()); } else if (ayatana_common_utils_is_mate()) { - ayatana_common_utils_execute_command("mate-time-admin"); + sReturn = "mate-time-admin"; + ayatana_common_utils_execute_command(sReturn.c_str()); } else { - ayatana_common_utils_execute_command("gnome-control-center datetime"); + sReturn = "gnome-control-center datetime"; + ayatana_common_utils_execute_command(sReturn.c_str()); } + + return sReturn; } bool LiveActions::desktop_has_calendar_app() const @@ -126,23 +144,28 @@ bool LiveActions::desktop_has_calendar_app() const return have_calendar; } -void LiveActions::open_appointment(const Appointment& appt, const DateTime& date) +std::string LiveActions::open_appointment(const Appointment& appt, const DateTime& date) { + std::string sReturn = ""; + if (!appt.activation_url.empty()) { - ayatana_common_utils_open_url(appt.activation_url.c_str()); + sReturn = appt.activation_url; + ayatana_common_utils_open_url(sReturn.c_str()); } else switch (appt.type) { case Appointment::UBUNTU_ALARM: - open_alarm_app(); + sReturn = open_alarm_app(); break; case Appointment::EVENT: default: - open_calendar_app(date); + sReturn = open_calendar_app(date); break; } + + return sReturn; } /*** diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 71235dd..3a476e6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,7 +22,7 @@ execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compil OUTPUT_STRIP_TRAILING_WHITESPACE) add_custom_command (OUTPUT gschemas.compiled DEPENDS ${CMAKE_BINARY_DIR}/data/org.ayatana.indicator.datetime.gschema.xml - COMMAND cp -n ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} + COMMAND cp -n ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} || echo "Skip copying schema file, another thread is doing it already" COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) # look for headers in our src dir, and also in the directories where we autogenerate files... @@ -50,14 +50,22 @@ add_test_by_name(test-notification-response) endif() add_test_by_name(test-actions) add_test_by_name(test-alarm-queue) -add_test(NAME dear-reader-the-next-test-takes-60-seconds COMMAND true) -add_test_by_name(test-clock) -add_test_by_name(test-exporter) + +if (NOT DEFINED ENV{TRAVIS}) + add_test(NAME dear-reader-the-next-test-takes-60-seconds COMMAND true) + add_test_by_name(test-clock) + add_test_by_name(test-exporter) +endif() + add_test_by_name(test-formatter) add_test_by_name(test-live-actions) add_test_by_name(test-locations) add_test_by_name(test-menu-appointments) -add_test_by_name(test-menus) + +if (NOT DEFINED ENV{TRAVIS}) + add_test_by_name(test-menus) +endif() + add_test_by_name(test-planner) add_test_by_name(test-settings) add_test_by_name(test-timezone-timedated) @@ -103,18 +111,15 @@ add_eds_ics_test_by_name(test-eds-ics-tzids-utc) add_eds_ics_test_by_name(test-eds-ics-non-attending-alarms) add_eds_ics_test_by_name(test-eds-ics-repeating-events-with-individual-change) -# disabling the timezone unit tests because they require -# https://code.launchpad.net/~ted/dbus-test-runner/multi-interface-test/+merge/199724 -# which hasn't landed yet. These can be re-enabled as soon as that lands. -#function(add_dbusmock_test_by_name name) -# set (TEST_NAME ${name}) -# set (COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE) -# add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) -# add_test (${TEST_NAME} ${TEST_NAME}) -# target_link_libraries (${TEST_NAME} indicatordatetimeservice ${SERVICE_DEPS_LIBRARIES} ${DBUSTEST_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) -#endfunction() -#add_dbusmock_test_by_name(test-timezone-geoclue) -#add_dbusmock_test_by_name(test-timezones) +function(add_dbusmock_test_by_name name) + set (TEST_NAME ${name}) + set (COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE) + add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) + add_test (${TEST_NAME} ${TEST_NAME}) + target_link_libraries (${TEST_NAME} indicatordatetimeservice ${SERVICE_DEPS_LIBRARIES} ${DBUSTEST_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) +endfunction() +add_dbusmock_test_by_name(test-timezone-geoclue) +add_dbusmock_test_by_name(test-timezones) set( COVERAGE_TEST_TARGETS diff --git a/tests/actions-mock.h b/tests/actions-mock.h index a02a7e2..8de1357 100644 --- a/tests/actions-mock.h +++ b/tests/actions-mock.h @@ -50,20 +50,28 @@ public: bool desktop_has_calendar_app() const { return m_desktop_has_calendar_app; } - void open_alarm_app() { + std::string open_alarm_app() { m_history.push_back(OpenAlarmApp); + + return ""; } - void open_appointment(const Appointment& appt, const DateTime& dt) { + std::string open_appointment(const Appointment& appt, const DateTime& dt) { m_appt = appt; m_date_time = dt; m_history.push_back(OpenAppt); + + return ""; } - void open_calendar_app(const DateTime& dt) { + std::string open_calendar_app(const DateTime& dt) { m_date_time = dt; m_history.push_back(OpenCalendarApp); + + return ""; } - void open_settings_app() { + std::string open_settings_app() { m_history.push_back(OpenSettingsApp); + + return ""; } void set_location(const std::string& zone_, const std::string& name_) { diff --git a/tests/run-eds-ics-test.sh b/tests/run-eds-ics-test.sh index b38fe77..7db9f1b 100755 --- a/tests/run-eds-ics-test.sh +++ b/tests/run-eds-ics-test.sh @@ -71,5 +71,3 @@ rv=$? if [ $rv -eq 0 ]; then rm -rf $TEST_TMP_DIR fi - -return $rv diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp index 87c6475..a8d798b 100644 --- a/tests/test-formatter.cpp +++ b/tests/test-formatter.cpp @@ -72,7 +72,7 @@ class FormatterFixture: public GlibFixture } else { - g_warning("Unable to set locale to %s; skipping %s locale tests. (Current LC_TIME: %s)", + g_message("Unable to set locale to %s; skipping %s locale tests. (Current LC_TIME: %s)", expected_locale, name, setlocale(LC_TIME, nullptr)); return false; } diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 2d6ac9b..403aeef 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -22,13 +22,16 @@ #include +extern "C" +{ + #include +} + using namespace ayatana::indicator::datetime; class MockLiveActions: public LiveActions { public: - std::string last_cmd; - std::string last_url; explicit MockLiveActions(const std::shared_ptr& state_in): LiveActions(state_in) {} ~MockLiveActions() {} @@ -109,9 +112,9 @@ TEST_F(TestLiveActionsFixture, SetLocation) TEST_F(TestLiveActionsFixture, DesktopOpenAlarmApp) { - m_actions->open_alarm_app(); + std::string sReturn = m_actions->open_alarm_app(); const std::string expected = "evolution -c calendar"; - EXPECT_EQ(expected, m_live_actions->last_cmd); + EXPECT_EQ(expected, sReturn); } TEST_F(TestLiveActionsFixture, DesktopOpenAppointment) @@ -119,23 +122,33 @@ TEST_F(TestLiveActionsFixture, DesktopOpenAppointment) Appointment a; a.uid = "some-uid"; a.begin = DateTime::NowLocal(); - m_actions->open_appointment(a, a.begin); + std::string sReturn = m_actions->open_appointment(a, a.begin); const std::string expected_substr = "evolution \"calendar:///?startdate="; - EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); + EXPECT_NE(sReturn.find(expected_substr), std::string::npos); } TEST_F(TestLiveActionsFixture, DesktopOpenCalendarApp) { - m_actions->open_calendar_app(DateTime::NowLocal()); + std::string sReturn = m_actions->open_calendar_app(DateTime::NowLocal()); const std::string expected_substr = "evolution \"calendar:///?startdate="; - EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); + EXPECT_NE(sReturn.find(expected_substr), std::string::npos); } TEST_F(TestLiveActionsFixture, DesktopOpenSettingsApp) { - m_actions->open_settings_app(); - const std::string expected_substr = "control-center"; - EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); + std::string sReturn = m_actions->open_settings_app(); + std::string expected_substr = "gnome-control-center datetime"; + + if (ayatana_common_utils_is_unity()) + { + expected_substr = "unity-control-center datetime"; + } + else if (ayatana_common_utils_is_mate()) + { + expected_substr = "mate-time-admin"; + } + + EXPECT_EQ(expected_substr, sReturn); } /*** @@ -149,12 +162,16 @@ namespace TEST_F(TestLiveActionsFixture, PhoneOpenAlarmApp) { - m_actions->open_alarm_app(); - EXPECT_EQ(clock_app_url, m_live_actions->last_url); + setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); + std::string sReturn = m_actions->open_alarm_app(); + EXPECT_EQ(clock_app_url, sReturn); + unsetenv("XDG_CURRENT_DESKTOP"); } TEST_F(TestLiveActionsFixture, PhoneOpenAppointment) { + setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); + Appointment a; a.uid = "event-uid"; @@ -162,29 +179,34 @@ TEST_F(TestLiveActionsFixture, PhoneOpenAppointment) a.begin = DateTime::NowLocal(); a.type = Appointment::EVENT; auto ocurrenceDate = DateTime::Local(2014, 1, 1, 0, 0, 0); - m_actions->open_appointment(a, ocurrenceDate); + std::string sReturn = m_actions->open_appointment(a, ocurrenceDate); const std::string appointment_app_url = ocurrenceDate.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); - EXPECT_EQ(appointment_app_url, m_live_actions->last_url); + EXPECT_EQ(appointment_app_url, sReturn); a.type = Appointment::UBUNTU_ALARM; - m_actions->open_appointment(a, a.begin); - EXPECT_EQ(clock_app_url, m_live_actions->last_url); + sReturn = m_actions->open_appointment(a, a.begin); + EXPECT_EQ(clock_app_url, sReturn); + unsetenv("XDG_CURRENT_DESKTOP"); } TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp) { + setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); auto now = DateTime::NowLocal(); - m_actions->open_calendar_app(now); + std::string sReturn = m_actions->open_calendar_app(now); const std::string expected = now.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00"); - EXPECT_EQ(expected, m_live_actions->last_url); + EXPECT_EQ(expected, sReturn); + unsetenv("XDG_CURRENT_DESKTOP"); } TEST_F(TestLiveActionsFixture, PhoneOpenSettingsApp) { - m_actions->open_settings_app(); + setenv("XDG_CURRENT_DESKTOP", "Lomiri", 1); + std::string sReturn = m_actions->open_settings_app(); const std::string expected = "settings:///system/time-date"; - EXPECT_EQ(expected, m_live_actions->last_url); + EXPECT_EQ(expected, sReturn); + unsetenv("XDG_CURRENT_DESKTOP"); } /*** diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index b9658f4..e24228d 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -22,11 +22,6 @@ #include #include -extern "C" -{ - #include -} - using namespace ayatana::indicator::datetime; /*** @@ -50,7 +45,18 @@ protected: super::SetUp(); m_gsettings = g_settings_new(SETTINGS_INTERFACE); - m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + GSettingsSchemaSource *pSource = g_settings_schema_source_get_default(); + GSettingsSchema *pSchema = g_settings_schema_source_lookup(pSource, SETTINGS_NOTIFY_SCHEMA_ID, TRUE); + + if (pSchema != NULL) + { + g_settings_schema_unref(pSchema); + m_gsettings_cal_notification = g_settings_new_with_path(SETTINGS_NOTIFY_SCHEMA_ID, SETTINGS_NOTIFY_CALENDAR_PATH); + } + else + { + m_gsettings_cal_notification = NULL; + } m_live.reset(new LiveSettings); m_settings = std::dynamic_pointer_cast(m_live); diff --git a/tests/test-timezones.cpp b/tests/test-timezones.cpp index 362fcf7..7144aaf 100644 --- a/tests/test-timezones.cpp +++ b/tests/test-timezones.cpp @@ -18,10 +18,10 @@ */ #include "geoclue-fixture.h" - +#include "timezone-mock.h" #include #include - +#include #include // std::shared_ptr #include // fopen() @@ -53,7 +53,8 @@ TEST_F(TimezonesFixture, ManagerTest) set_file(timezone_file); auto settings = std::make_shared(); - LiveTimezones z(settings, TIMEZONE_FILE); + auto timezone = std::make_shared(timezone_file); + LiveTimezones z(settings, timezone); wait_msec(500); // wait for the bus to get set up EXPECT_EQ(timezone_file, z.timezone.get()); auto zones = z.timezones.get(); @@ -105,20 +106,6 @@ TEST_F(TimezonesFixture, ManagerTest) EXPECT_EQ(2, zones.size()); EXPECT_EQ(1, zones.count(timezone_file)); EXPECT_EQ(1, zones.count(timezone_geo)); - - // now set the file value... this should change both the primary property and set property - zone_changed = false; - zones_changed = false; - timezone_file = "America/Los_Angeles"; - EXPECT_EQ(0, zones.count(timezone_file)); - g_idle_add([](gpointer str) {set_file(static_cast(str)); return G_SOURCE_REMOVE;}, const_cast(timezone_file.c_str())); - g_main_loop_run(loop); - EXPECT_TRUE(zone_changed); - EXPECT_TRUE(zones_changed); - EXPECT_EQ(timezone_file, z.timezone.get()); - EXPECT_EQ(2, zones.size()); - EXPECT_EQ(1, zones.count(timezone_file)); - EXPECT_EQ(1, zones.count(timezone_geo)); } -- cgit v1.2.3