From dd147887cb70a52dcba1cd26d9bbf7e29545afc4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 7 Sep 2013 09:39:38 -0500 Subject: add preliminary unit tests for utils --- tests/Makefile.am | 6 +++ tests/test-utils.cc | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 tests/test-utils.cc (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index dce6076..6435d75 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -50,3 +50,9 @@ test_indicator_CPPFLAGS = $(TEST_CPPFLAGS) -DSCHEMA_DIR="\"$(top_builddir)/tests ### ### ### + +TESTS += test-utils +check_PROGRAMS += test-utils +test_utils_SOURCES = test-utils.cc $(top_srcdir)/src/utils.c +test_utils_LDADD = $(TEST_LIBS) +test_utils_CPPFLAGS = $(TEST_CPPFLAGS) -DSCHEMA_DIR="\"$(top_builddir)/tests/\"" diff --git a/tests/test-utils.cc b/tests/test-utils.cc new file mode 100644 index 0000000..c757a11 --- /dev/null +++ b/tests/test-utils.cc @@ -0,0 +1,112 @@ +/* +Copyright 2012 Canonical Ltd. + +Authors: + Charles Kerr + +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 +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include + +#include + +#include "utils.h" + +/*** +**** +***/ + +TEST (UtilsTest, SplitSettingsLocation) +{ + guint i; + guint n; + + struct { + 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" }, + { "America/Los_Angeles", "America/Los_Angeles", "Los Angeles" }, + { "America/Los_Angeles ", "America/Los_Angeles", "Los Angeles" }, + { " America/Los_Angeles", "America/Los_Angeles", "Los Angeles" }, + { " America/Los_Angeles ", "America/Los_Angeles", "Los Angeles" }, + { "UTC UTC", "UTC", "UTC" } + }; + + for (i=0, n=G_N_ELEMENTS(test_cases); i