aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-27 01:26:02 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-27 01:26:02 -0600
commit1c547710eb14d7805e47205f7c62fb7b0d0f3756 (patch)
treeb5181b9eb982bbe601b0a25784bd3fc6d7ca18ef /tests
parenta268daf59f5b3a8ccd99f2b821a4c7cbcca3ccbc (diff)
downloadayatana-indicator-datetime-1c547710eb14d7805e47205f7c62fb7b0d0f3756.tar.gz
ayatana-indicator-datetime-1c547710eb14d7805e47205f7c62fb7b0d0f3756.tar.bz2
ayatana-indicator-datetime-1c547710eb14d7805e47205f7c62fb7b0d0f3756.zip
add unit tests for utils.cpp's get_timezone_name()
Diffstat (limited to 'tests')
-rw-r--r--tests/test-utils.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/tests/test-utils.cpp b/tests/test-utils.cpp
index 2fe6a2e..036c13f 100644
--- a/tests/test-utils.cpp
+++ b/tests/test-utils.cpp
@@ -17,6 +17,7 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
+#include <datetime/settings-shared.h>
#include <datetime/utils.h>
#include <gtest/gtest.h>
@@ -51,24 +52,47 @@ TEST(UtilsTest, SplitSettingsLocation)
}
}
-TEST(UtilsTest, BeautifulTimezoneName)
+namespace
{
struct {
const char* timezone;
const char* location;
const char* expected_name;
- } test_cases[] = {
+ } beautify_timezone_test_cases[] = {
{ "America/Chicago", NULL, "Chicago" },
{ "America/Chicago", "America/Chicago", "Chicago" },
{ "America/Chicago", "America/Chigago Chicago", "Chicago" },
{ "America/Chicago", "America/Chicago Oklahoma City", "Oklahoma City" },
{ "America/Chicago", "Europe/London London", "Chicago" }
};
-
- for(const auto& test_case : test_cases)
+}
+
+TEST(UtilsTest, BeautifulTimezoneName)
+{
+ for(const auto& test_case : beautify_timezone_test_cases)
{
auto name = get_beautified_timezone_name(test_case.timezone, test_case.location);
EXPECT_STREQ(test_case.expected_name, name);
g_free(name);
}
}
+
+
+TEST(UtilsTest, GetTimezonename)
+{
+ // set up a local GSettings
+ g_assert(g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true));
+ g_assert(g_setenv("GSETTINGS_BACKEND", "memory", true));
+ g_debug("SCHEMA_DIR is %s", SCHEMA_DIR);
+ auto settings = g_settings_new(SETTINGS_INTERFACE);
+
+ for(const auto& test_case : beautify_timezone_test_cases)
+ {
+ g_settings_set_string(settings, SETTINGS_TIMEZONE_NAME_S, test_case.location);
+ auto name = get_timezone_name (test_case.timezone, settings);
+ EXPECT_STREQ(test_case.expected_name, name);
+ g_free(name);
+ }
+
+ g_clear_object(&settings);
+}