aboutsummaryrefslogtreecommitdiff
path: root/tests/test-utils.cc
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-16 17:28:37 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-16 17:28:37 -0600
commit4cc19729c540ffba163d5c9a53b9352fe61fe8af (patch)
tree91bddbeda31d8f5e2600e0024127c1f5a2f0f8d2 /tests/test-utils.cc
parenta2b5c79157fa8db36d94786de1b86b756308912d (diff)
downloadayatana-indicator-datetime-4cc19729c540ffba163d5c9a53b9352fe61fe8af.tar.gz
ayatana-indicator-datetime-4cc19729c540ffba163d5c9a53b9352fe61fe8af.tar.bz2
ayatana-indicator-datetime-4cc19729c540ffba163d5c9a53b9352fe61fe8af.zip
in utils.c, make a version of get_timezone_name() that doesn't require a GSettings argument. Update utils tests.
Diffstat (limited to 'tests/test-utils.cc')
-rw-r--r--tests/test-utils.cc79
1 files changed, 24 insertions, 55 deletions
diff --git a/tests/test-utils.cc b/tests/test-utils.cc
index 8246396..2fe6a2e 100644
--- a/tests/test-utils.cc
+++ b/tests/test-utils.cc
@@ -17,22 +17,16 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#include <gtest/gtest.h>
-
-#include <glib-object.h>
-
-#include "utils.h"
+#include <datetime/utils.h>
-/***
-****
-***/
+#include <gtest/gtest.h>
TEST(UtilsTest, SplitSettingsLocation)
{
struct {
- const char * location;
- const char * expected_zone;
- const char * expected_name;
+ const char* location;
+ const char* expected_zone;
+ const char* expected_name;
} test_cases[] = {
{ "America/Chicago Chicago", "America/Chicago", "Chicago" },
{ "America/Chicago Oklahoma City", "America/Chicago", "Oklahoma City" },
@@ -43,63 +37,38 @@ TEST(UtilsTest, SplitSettingsLocation)
{ "UTC UTC", "UTC", "UTC" }
};
- for(guint i=0, n=G_N_ELEMENTS(test_cases); i<n; i++)
+ for(const auto& test_case : test_cases)
{
- char * zone = NULL;
- char * name = NULL;
+ char * zone = nullptr;
+ char * name = nullptr;
- split_settings_location(test_cases[i].location, &zone, &name);
- ASSERT_STREQ(test_cases[i].expected_zone, zone);
- ASSERT_STREQ(test_cases[i].expected_name, name);
+ split_settings_location(test_case.location, &zone, &name);
+ ASSERT_STREQ(test_case.expected_zone, zone);
+ ASSERT_STREQ(test_case.expected_name, name);
g_free(zone);
g_free(name);
}
}
-/***
-****
-***/
-
-#define EM_SPACE "\xE2\x80\x82"
-
-TEST(UtilsTest, GenerateTerseFormatString)
+TEST(UtilsTest, BeautifulTimezoneName)
{
- auto arbitrary_day = g_date_time_new_local(2013, 6, 25, 12, 34, 56);
- auto on_the_hour = g_date_time_new_local(2013, 6, 25, 12, 0, 0);
-
struct {
- GDateTime * now;
- GDateTime * time;
- const char * expected_format_string;
+ const char* timezone;
+ const char* location;
+ const char* expected_name;
} test_cases[] = {
- { g_date_time_ref(arbitrary_day), g_date_time_ref(arbitrary_day), "%l:%M %p" }, /* identical time */
- { g_date_time_ref(arbitrary_day), g_date_time_add_hours(arbitrary_day,1), "%l:%M %p" }, /* later today */
- { g_date_time_ref(arbitrary_day), g_date_time_add_days(arbitrary_day,1), "Tomorrow" EM_SPACE "%l:%M %p" }, /* tomorrow */
- { g_date_time_ref(arbitrary_day), g_date_time_add_days(arbitrary_day,2), "%a" EM_SPACE "%l:%M %p" },
- { g_date_time_ref(arbitrary_day), g_date_time_add_days(arbitrary_day,6), "%a" EM_SPACE "%l:%M %p" },
- { g_date_time_ref(arbitrary_day), g_date_time_add_days(arbitrary_day,7), "%d %b" EM_SPACE "%l:%M %p" }, /* over one week away */
-
- { g_date_time_ref(on_the_hour), g_date_time_ref(on_the_hour), "%l %p" }, /* identical time */
- { g_date_time_ref(on_the_hour), g_date_time_add_hours(on_the_hour,1), "%l %p" }, /* later today */
- { g_date_time_ref(on_the_hour), g_date_time_add_days(on_the_hour,1), "Tomorrow" EM_SPACE "%l %p" }, /* tomorrow */
- { g_date_time_ref(on_the_hour), g_date_time_add_days(on_the_hour,2), "%a" EM_SPACE "%l %p" },
- { g_date_time_ref(on_the_hour), g_date_time_add_days(on_the_hour,6), "%a" EM_SPACE "%l %p" },
- { g_date_time_ref(on_the_hour), g_date_time_add_days(on_the_hour,7), "%d %b" EM_SPACE "%l %p" }, /* over one week away */
+ { "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(guint i=0, n=G_N_ELEMENTS(test_cases); i<n; i++)
+ for(const auto& test_case : test_cases)
{
- auto format_string = generate_terse_format_string_at_time(test_cases[i].now,
- test_cases[i].time);
-
- ASSERT_STREQ(test_cases[i].expected_format_string, format_string);
-
- g_free(format_string);
- g_date_time_unref(test_cases[i].now);
- g_date_time_unref(test_cases[i].time);
+ auto name = get_beautified_timezone_name(test_case.timezone, test_case.location);
+ EXPECT_STREQ(test_case.expected_name, name);
+ g_free(name);
}
-
- g_date_time_unref(arbitrary_day);
- g_date_time_unref(on_the_hour);
}