diff options
Diffstat (limited to 'tests/test-timezone-file.cpp')
-rw-r--r-- | tests/test-timezone-file.cpp | 105 |
1 files changed, 16 insertions, 89 deletions
diff --git a/tests/test-timezone-file.cpp b/tests/test-timezone-file.cpp index 8968429..0ec496d 100644 --- a/tests/test-timezone-file.cpp +++ b/tests/test-timezone-file.cpp @@ -18,129 +18,56 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "glib-fixture.h" +#include "timedated-fixture.h" #include <datetime/timezone-file.h> -//#include <condition_variable> -//#include <mutex> -//#include <queue> -//#include <string> -//#include <thread> -//#include <iostream> -//#include <istream> -//#include <fstream> - #include <cstdio> // fopen() //#include <sys/stat.h> // chmod() #include <unistd.h> // sync() using unity::indicator::datetime::FileTimezone; - -/*** -**** -***/ - -#define TIMEZONE_FILE (SANDBOX"/timezone") - -class TimezoneFixture: public GlibFixture -{ - private: - - typedef GlibFixture super; - - protected: - - void SetUp() override - { - super::SetUp(); - } - - void TearDown() override - { - super::TearDown(); - } - - public: - - /* convenience func to set the timezone file */ - void set_file(const std::string& text) - { - auto fp = fopen(TIMEZONE_FILE, "w+"); - fprintf(fp, "%s\n", text.c_str()); - fclose(fp); - sync(); - } -}; - - -/** - * Test that timezone-file warns, but doesn't crash, if the timezone file doesn't exist - */ -TEST_F(TimezoneFixture, NoFile) -{ - remove(TIMEZONE_FILE); - ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS)); - - FileTimezone tz(TIMEZONE_FILE); - testLogCount(G_LOG_LEVEL_WARNING, 1); -} - - /** * Test that timezone-file picks up the initial value */ -TEST_F(TimezoneFixture, InitialValue) +TEST_F(TimedateFixture, InitialValue) { const std::string expected_timezone = "America/Chicago"; - set_file(expected_timezone); - FileTimezone tz(TIMEZONE_FILE); + set_timezone(expected_timezone); + FileTimezone tz; ASSERT_EQ(expected_timezone, tz.timezone.get()); } - /** - * Test that clearing the timezone results in an empty string + * Test that changing the tz after we are running works. */ -TEST_F(TimezoneFixture, ChangedValue) +TEST_F(TimedateFixture, ChangedValue) { const std::string initial_timezone = "America/Chicago"; const std::string changed_timezone = "America/New_York"; - set_file(initial_timezone); + GMainLoop *l = g_main_loop_new(nullptr, FALSE); - FileTimezone tz(TIMEZONE_FILE); + set_timezone(initial_timezone); + + FileTimezone tz; ASSERT_EQ(initial_timezone, tz.timezone.get()); bool changed = false; - auto connection = tz.timezone.changed().connect( - [&changed, this](const std::string& s){ + tz.timezone.changed().connect( + [&changed, this, l](const std::string& s){ g_message("timezone changed to %s", s.c_str()); changed = true; - g_main_loop_quit(loop); + g_main_loop_quit(l); }); g_idle_add([](gpointer gself){ - static_cast<TimezoneFixture*>(gself)->set_file("America/New_York"); - // static_cast<FileTimezone*>(gtz)->timezone.set("America/New_York"); + static_cast<TimedateFixture*>(gself)->set_timezone("America/New_York"); return G_SOURCE_REMOVE; - }, this);//&tz); + }, this); - g_main_loop_run(loop); + g_main_loop_run(l); ASSERT_TRUE(changed); ASSERT_EQ(changed_timezone, tz.timezone.get()); } - - -/** - * Test that timezone-file picks up the initial value - */ -TEST_F(TimezoneFixture, IgnoreComments) -{ - const std::string comment = "# Created by cloud-init v. 0.7.5 on Thu, 24 Apr 2014 14:03:29 +0000"; - const std::string expected_timezone = "Europe/Berlin"; - set_file(comment + "\n" + expected_timezone); - FileTimezone tz(TIMEZONE_FILE); - ASSERT_EQ(expected_timezone, tz.timezone.get()); -} |