diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 6 | ||||
-rw-r--r-- | tests/manual | 22 | ||||
-rw-r--r-- | tests/manual-test-snap.cpp | 22 | ||||
-rw-r--r-- | tests/test-exporter.cpp | 95 | ||||
-rw-r--r-- | tests/test-menus.cpp | 2 | ||||
-rw-r--r-- | tests/test-settings.cpp | 46 |
6 files changed, 152 insertions, 41 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fe6d7eb..958e1cc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,15 +21,17 @@ execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compil OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE) add_custom_command (OUTPUT gschemas.compiled - DEPENDS ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.datetime.gschema.xml - COMMAND cp -f ${CMAKE_SOURCE_DIR}/data/*gschema.xml ${SCHEMA_DIR} + DEPENDS ${CMAKE_BINARY_DIR}/data/com.canonical.indicator.datetime.gschema.xml + COMMAND cp -f ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) # look for headers in our src dir, and also in the directories where we autogenerate files... include_directories (${CMAKE_SOURCE_DIR}/src) +include_directories (${CMAKE_BINARY_DIR}/src) include_directories (${CMAKE_CURRENT_BINARY_DIR}) include_directories (${DBUSTEST_INCLUDE_DIRS}) + add_definitions (-DSANDBOX="${CMAKE_CURRENT_BINARY_DIR}") diff --git a/tests/manual b/tests/manual index 17b4778..ecbcebb 100644 --- a/tests/manual +++ b/tests/manual @@ -22,3 +22,25 @@ Test-case indicator-datetime/unity8-items-check <dd>The menu is populated with items</dd> </dl> +Test-case indicator-datetime/new-alarm-wakeup +<dl> + <dt>Create and save an upcoming alarm in ubuntu-clock-app</dt> + <dt>Unplug the phone from any USB connection and put it to sleep</dt> + <dd>Confirm that the alarm sounds on time even if the phone is asleep. + (Note: if in doubt about sleep you can see in the syslog whether the + device actually suspended or whether the suspend was aborted)</dd> +</dl> + +Test-case indicator-datetime/edited-alarm-wakeup +<dl> + <dt>Edit an alarm that's already passed. (see previous test)</dt> + <dt>Unplug the phone from any USB connection and put it to sleep</dt> + <dd>Confirm that the alarm sounds on time even if the phone is asleep. + (Note: if in doubt about sleep you can see in the syslog whether the + device actually suspended or whether the suspend was aborted)</dd> +</dl> + +<strong> + If all actions produce the expected results listed, please <a href="results#add_result">submit</a> a 'passed' result. + If an action fails, or produces an unexpected result, please <a href="results#add_result">submit</a> a 'failed' result and <a href="../../buginstructions">file a bug</a>. Please be sure to include the bug number when you <a href="results#add_result">submit</a> your result</strong>. + diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 90dbe08..cc24a67 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -41,10 +41,29 @@ namespace g_main_loop_quit(static_cast<GMainLoop*>(gloop)); return G_SOURCE_REMOVE; }; + + int volume = 50; + + GOptionEntry entries[] = + { + { "volume", 'v', 0, G_OPTION_ARG_INT, &volume, "Volume level [1..100]", "volume" }, + { NULL } + }; } -int main() +int main(int argc, const char* argv[]) { + GError* error = nullptr; + GOptionContext* context = g_option_context_new(nullptr); + g_option_context_add_main_entries(context, entries, nullptr); + if (!g_option_context_parse(context, &argc, (gchar***)&argv, &error)) + { + g_print("option parsing failed: %s\n", error->message); + exit(1); + } + g_option_context_free(context); + volume = CLAMP(volume, 1, 100); + Appointment a; a.color = "green"; a.summary = "Alarm"; @@ -74,6 +93,7 @@ int main() g_debug("SCHEMA_DIR is %s", SCHEMA_DIR); auto settings = std::make_shared<LiveSettings>(); + settings->alarm_volume.set(volume); auto timezones = std::make_shared<LiveTimezones>(settings, TIMEZONE_FILE); auto clock = std::make_shared<LiveClock>(timezones); Snap snap (clock, settings); diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index a255ef9..e947740 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -21,6 +21,8 @@ #include "state-mock.h" #include "glib-fixture.h" +#include "dbus-alarm-properties.h" + #include <datetime/actions.h> #include <datetime/dbus-shared.h> #include <datetime/exporter.h> @@ -76,13 +78,14 @@ TEST_F(ExporterFixture, Publish) { std::shared_ptr<State> state(new MockState); std::shared_ptr<Actions> actions(new MockActions(state)); + std::shared_ptr<Settings> settings(new Settings); std::vector<std::shared_ptr<Menu>> menus; MenuFactory menu_factory (actions, state); for(int i=0; i<Menu::NUM_PROFILES; i++) menus.push_back(menu_factory.buildMenu(Menu::Profile(i))); - Exporter exporter; + Exporter exporter(settings); exporter.publish(actions, menus); wait_msec(); @@ -122,7 +125,7 @@ TEST_F(ExporterFixture, Publish) // try closing the connection prematurely // to test Exporter's name-lost signal bool name_lost = false; - exporter.name_lost.connect([this,&name_lost](){ + exporter.name_lost().connect([this,&name_lost](){ name_lost = true; g_main_loop_quit(loop); }); @@ -135,3 +138,91 @@ TEST_F(ExporterFixture, Publish) g_clear_object(&exported); g_clear_object(&connection); } + +TEST_F(ExporterFixture, AlarmProperties) +{ + /*** + **** Set up the exporter + ***/ + + std::shared_ptr<State> state(new MockState); + std::shared_ptr<Actions> actions(new MockActions(state)); + std::shared_ptr<Settings> settings(new Settings); + std::vector<std::shared_ptr<Menu>> menus; + + MenuFactory menu_factory (actions, state); + for(int i=0; i<Menu::NUM_PROFILES; i++) + menus.push_back(menu_factory.buildMenu(Menu::Profile(i))); + + Exporter exporter(settings); + exporter.publish(actions, menus); + wait_msec(); + + /*** + **** Set up the proxy + ***/ + + auto on_proxy_ready = [](GObject*, GAsyncResult* res, gpointer gproxy){ + GError* error = nullptr; + *reinterpret_cast<DatetimeAlarmProperties**>(gproxy) = datetime_alarm_properties_proxy_new_for_bus_finish(res, &error); + EXPECT_TRUE(error == nullptr); + }; + + DatetimeAlarmProperties* proxy = nullptr; + datetime_alarm_properties_proxy_new_for_bus(G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + BUS_NAME, + BUS_PATH"/AlarmProperties", + nullptr, + on_proxy_ready, + &proxy); + wait_msec(100); + ASSERT_TRUE(proxy != nullptr); + + /*** + **** Try changing the Settings -- do the DBus properties change to match it? + ***/ + + auto expected_volume = 1; + int expected_duration = 60; + const char * expected_sound = "/tmp/foo.wav"; + settings->alarm_volume.set(expected_volume); + settings->alarm_duration.set(expected_duration); + settings->alarm_sound.set(expected_sound); + wait_msec(); + + static constexpr const char* const SOUND_PROP {"default-sound"}; + static constexpr const char* const VOLUME_PROP {"default-volume"}; + static constexpr const char* const DURATION_PROP {"duration"}; + + char* sound = nullptr; + int volume = -1; + int duration = -1; + g_object_get(proxy, SOUND_PROP, &sound, + VOLUME_PROP, &volume, + DURATION_PROP, &duration, + nullptr); + EXPECT_STREQ(expected_sound, sound); + EXPECT_EQ(expected_volume, volume); + EXPECT_EQ(expected_duration, duration); + + /*** + **** Try chaning the DBus properties -- do the Settings change to match it? + ***/ + + expected_volume = 100; + expected_duration = 30; + expected_sound = "/tmp/bar.wav"; + g_object_set(proxy, SOUND_PROP, expected_sound, + VOLUME_PROP, expected_volume, + DURATION_PROP, expected_duration, + nullptr); + wait_msec(); + + EXPECT_STREQ(expected_sound, settings->alarm_sound.get().c_str()); + EXPECT_EQ(expected_volume, settings->alarm_volume.get()); + EXPECT_EQ(expected_duration, settings->alarm_duration.get()); + + // cleanup + g_clear_object(&proxy); +} diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index b485037..f5f8df2 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -484,7 +484,7 @@ TEST_F(MenuFixture, HelloWorld) EXPECT_EQ(Menu::NUM_PROFILES, m_menus.size()); for (int i=0; i<Menu::NUM_PROFILES; i++) { - EXPECT_TRUE(m_menus[i] != false); + EXPECT_TRUE(m_menus[i].get() != nullptr); EXPECT_TRUE(m_menus[i]->menu_model() != nullptr); EXPECT_EQ(i, m_menus[i]->profile()); } diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 2b500b2..44a0252 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -101,26 +101,26 @@ protected: g_clear_pointer(&tmp, g_free); } - void TestIntProperty(core::Property<int>& property, const gchar* key) + void TestUIntProperty(core::Property<unsigned int>& property, const gchar* key) { - EXPECT_EQ(g_settings_get_int(m_gsettings, key), property.get()); + EXPECT_EQ(g_settings_get_uint(m_gsettings, key), property.get()); - int expected_values[] = { 1, 2, 3 }; + unsigned int expected_values[] = { 1, 2, 3 }; // modify GSettings and confirm that the new value is propagated - for(const int& expected_value : expected_values) + for(const auto& expected_value : expected_values) { - g_settings_set_int(m_gsettings, key, expected_value); + g_settings_set_uint(m_gsettings, key, expected_value); EXPECT_EQ(expected_value, property.get()); - EXPECT_EQ(expected_value, g_settings_get_int(m_gsettings, key)); + EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key)); } // modify the property and confirm that the new value is propagated - for(const int& expected_value : expected_values) + for(const auto& expected_value : expected_values) { property.set(expected_value); EXPECT_EQ(expected_value, property.get()); - EXPECT_EQ(expected_value, g_settings_get_int(m_gsettings, key)); + EXPECT_EQ(expected_value, g_settings_get_uint(m_gsettings, key)); } } }; @@ -148,9 +148,10 @@ TEST_F(SettingsFixture, BoolProperties) TestBoolProperty(m_settings->show_year, SETTINGS_SHOW_YEAR_S); } -TEST_F(SettingsFixture, IntProperties) +TEST_F(SettingsFixture, UIntProperties) { - TestIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); + TestUIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); + TestUIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); } TEST_F(SettingsFixture, StringProperties) @@ -181,31 +182,6 @@ TEST_F(SettingsFixture, TimeFormatMode) } } -TEST_F(SettingsFixture, AlarmVolume) -{ - const auto key = SETTINGS_ALARM_VOLUME_S; - const AlarmVolume volumes[] = { ALARM_VOLUME_VERY_QUIET, - ALARM_VOLUME_QUIET, - ALARM_VOLUME_NORMAL, - ALARM_VOLUME_LOUD, - ALARM_VOLUME_VERY_LOUD }; - - for(const auto& val : volumes) - { - g_settings_set_enum(m_gsettings, key, val); - EXPECT_EQ(val, m_settings->alarm_volume.get()); - EXPECT_EQ(val, g_settings_get_enum(m_gsettings, key)); - } - - for(const auto& val : volumes) - { - m_settings->alarm_volume.set(val); - EXPECT_EQ(val, m_settings->alarm_volume.get()); - EXPECT_EQ(val, g_settings_get_enum(m_gsettings, key)); - } -} - - namespace { std::vector<std::string> strv_to_vector(const gchar** strv) |