aboutsummaryrefslogtreecommitdiff
path: root/tests/test-timezone-timedated.cpp
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2021-08-30 01:26:19 +0200
committerRobert Tari <robert@tari.in>2021-08-30 01:26:19 +0200
commit22e66866c7b17fc655479ca911269b86cb80a744 (patch)
treee0aa6e6a8f50fd8451e03efc17b89d8c8c3de781 /tests/test-timezone-timedated.cpp
parent1f8263dedf9b7e6f9e06492bd69f2436e36171a2 (diff)
parent38e5efecbb3154a83a70c1c762802ec7927b3caa (diff)
downloadayatana-indicator-datetime-22e66866c7b17fc655479ca911269b86cb80a744.tar.gz
ayatana-indicator-datetime-22e66866c7b17fc655479ca911269b86cb80a744.tar.bz2
ayatana-indicator-datetime-22e66866c7b17fc655479ca911269b86cb80a744.zip
Merge branch 'tari01-pr/ubports-patches'
Attributes GH PR #46: https://github.com/AyatanaIndicators/ayatana-indicator-datetime/pull/46
Diffstat (limited to 'tests/test-timezone-timedated.cpp')
-rw-r--r--tests/test-timezone-timedated.cpp131
1 files changed, 38 insertions, 93 deletions
diff --git a/tests/test-timezone-timedated.cpp b/tests/test-timezone-timedated.cpp
index 2fdec12..c686c39 100644
--- a/tests/test-timezone-timedated.cpp
+++ b/tests/test-timezone-timedated.cpp
@@ -1,9 +1,5 @@
-
/*
- * Copyright 2013 Canonical Ltd.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
+ * Copyright © 2014-2016 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
@@ -16,127 +12,76 @@
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ * Ted Gould <ted.gould@canonical.com>
*/
#include "timedated-fixture.h"
#include <datetime/timezone-timedated.h>
-using ayatana::indicator::datetime::TimedatedTimezone;
+using namespace ayatana::indicator::datetime;
+
+using TestTimedatedFixture = TimedatedFixture;
/***
****
***/
-#define TIMEZONE_FILE (SANDBOX"/timezone")
-
-class TimezoneFixture: public TimedateFixture
+TEST_F(TestTimedatedFixture, HelloWorld)
{
- private:
-
- typedef TimedateFixture 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)
- {
- g_debug("set_file %s %s", TIMEZONE_FILE, text.c_str());
- auto fp = fopen(TIMEZONE_FILE, "w+");
- fprintf(fp, "%s\n", text.c_str());
- fclose(fp);
- sync();
- }
-};
+}
/**
- * Test that timezone-timedated warns, but doesn't crash, if the timezone file doesn't exist
+ * Test that the tzid is right if timedated isn't available
*/
-TEST_F(TimezoneFixture, NoFile)
+TEST_F(TestTimedatedFixture, DefaultTimezone)
{
- remove(TIMEZONE_FILE);
- ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS));
+ const std::string expected_tzid{"Etc/Utc"};
- expectLogMessage(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "*No such file or directory*");
- TimedatedTimezone tz(TIMEZONE_FILE);
+ TimedatedTimezone tmp {m_bus};
+ EXPECT_TZID(expected_tzid, tmp);
}
/**
- * Test that timezone-timedated gives a default of UTC if the file doesn't exist
+ * Test that the tzid is right if timedated shows BEFORE we start
*/
-TEST_F(TimezoneFixture, DefaultValueNoFile)
+TEST_F(TestTimedatedFixture, Timedate1First)
{
- const std::string expected_timezone = "Etc/Utc";
- remove(TIMEZONE_FILE);
- ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS));
+ const std::string expected_tzid{"America/Chicago"};
- expectLogMessage(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "*No such file or directory*");
- TimedatedTimezone tz(TIMEZONE_FILE);
- ASSERT_EQ(expected_timezone, tz.timezone.get());
+ start_timedate1(expected_tzid);
+ TimedatedTimezone tmp {m_bus};
+ EXPECT_TZID(expected_tzid, tmp);
}
/**
- * Test that timezone-timedated picks up the initial value
+ * Test that the tzid is right if timedated shows AFTER we start
*/
-TEST_F(TimezoneFixture, InitialValue)
+TEST_F(TestTimedatedFixture, Timedate1Last)
{
- const std::string expected_timezone = "America/Chicago";
- set_file(expected_timezone);
- TimedatedTimezone tz(TIMEZONE_FILE);
+ const std::string expected_tzid("America/Los_Angeles");
+
+ TimedatedTimezone tmp {m_bus};
+ start_timedate1(expected_tzid);
+ EXPECT_TZID(expected_tzid, tmp);
}
/**
- * Test that changing the tz after we are running works.
+ * Test that the tzid is right if timedated's property changes
*/
-TEST_F(TimezoneFixture, ChangedValue)
+TEST_F(TestTimedatedFixture, TimezoneChange)
{
- const std::string initial_timezone = "America/Chicago";
- const std::string changed_timezone = "America/New_York";
-
- set_file(initial_timezone);
-
- TimedatedTimezone tz(TIMEZONE_FILE);
- ASSERT_EQ(initial_timezone, tz.timezone.get());
-
- bool changed = false;
- tz.timezone.changed().connect(
- [&changed, this](const std::string& s){
- g_message("timezone changed to %s", s.c_str());
- changed = true;
- g_main_loop_quit(loop);
- });
+ const std::vector<std::string> expected_tzids{"America/Los_Angeles", "America/Chicago", "Etc/Utc"};
- g_idle_add([](gpointer gself){
- static_cast<TimedateFixture*>(gself)->set_timezone("America/New_York");
- return G_SOURCE_REMOVE;
- }, this);
+ TimedatedTimezone tmp {m_bus};
+ start_timedate1("America/New_York");
- g_main_loop_run(loop);
-
- ASSERT_TRUE(changed);
- ASSERT_EQ(changed_timezone, tz.timezone.get());
-}
-
-/**
- * Test that timezone-timedated 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);
- TimedatedTimezone tz(TIMEZONE_FILE);
- ASSERT_EQ(expected_timezone, tz.timezone.get());
+ for(const auto& expected_tzid : expected_tzids)
+ {
+ set_timedate1_timezone(expected_tzid);
+ EXPECT_TZID(expected_tzid, tmp);
+ }
}