From 93a32f0cc1d5d585ad88358dd8385f86580394fe Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Feb 2016 18:16:11 -0600 Subject: in test-snap, move new tests to bottom to avoid confusing diff --- tests/test-snap.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'tests') diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index 97e51b3..f06e4da 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -548,6 +548,77 @@ TEST_F(SnapFixture, ForceScreen) **** ***/ +/** + * A DefaultSoundBuilder wrapper which remembers the parameters of the last sound created. + */ +class TestSoundBuilder: public uin::SoundBuilder +{ +public: + TestSoundBuilder() =default; + ~TestSoundBuilder() =default; + + virtual std::shared_ptr create(const std::string& role, const std::string& uri, unsigned int volume, bool loop) override { + m_role = role; + m_uri = uri; + m_volume = volume; + m_loop = loop; + return m_impl.create(role, uri, volume, loop); + } + + const std::string& role() { return m_role; } + const std::string& uri() { return m_uri; } + unsigned int volume() { return m_volume; } + bool loop() { return m_loop; } + +private: + std::string m_role; + std::string m_uri; + unsigned int m_volume; + bool m_loop; + uin::DefaultSoundBuilder m_impl; +}; + +std::string path_to_uri(const std::string& path) +{ + auto file = g_file_new_for_path(path.c_str()); + auto uri_cstr = g_file_get_uri(file); + std::string uri = uri_cstr; + g_free(uri_cstr); + g_clear_pointer(&file, g_object_unref); + return uri; +} + +TEST_F(SnapFixture,DefaultSounds) +{ + auto settings = std::make_shared(); + auto ne = std::make_shared(APP_NAME); + auto sb = std::make_shared(); + auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);}; + + const struct { + Appointment appointment; + std::string expected_role; + std::string expected_uri; + } test_cases[] = { + { ualarm, "alarm", path_to_uri(ALARM_DEFAULT_SOUND) }, + { appt, "alert", path_to_uri(CALENDAR_DEFAULT_SOUND) } + }; + + auto snap = create_snap(ne, sb, settings); + + for(const auto& test_case : test_cases) + { + (*snap)(test_case.appointment, test_case.appointment.alarms.front(), func, func); + wait_msec(100); + EXPECT_EQ(test_case.expected_uri, sb->uri()); + EXPECT_EQ(test_case.expected_role, sb->role()); + } +} + +/*** +**** +***/ + TEST_F(SnapFixture,Notification) { auto settings = std::make_shared(); -- cgit v1.2.3