diff options
author | Ted Gould <ted@gould.cx> | 2013-10-28 17:09:05 -0700 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2013-10-28 17:09:05 -0700 |
commit | 26283de417c1c3cb3456f1a893fe339056517d56 (patch) | |
tree | b6851a0f12bbeae649854fb5a4a8a85a54d800f1 /tests | |
parent | 0fa8138427d8469eb2f6a90b0291dbdc4507c8fb (diff) | |
parent | 19ba64b479fd14d5192f0ec3dcc37fe33bde238b (diff) | |
download | ayatana-indicator-datetime-26283de417c1c3cb3456f1a893fe339056517d56.tar.gz ayatana-indicator-datetime-26283de417c1c3cb3456f1a893fe339056517d56.tar.bz2 ayatana-indicator-datetime-26283de417c1c3cb3456f1a893fe339056517d56.zip |
Merge trunk
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rw-r--r-- | tests/Makefile.am.strings | 2 | ||||
-rw-r--r-- | tests/planner-mock.c | 178 | ||||
-rw-r--r-- | tests/planner-mock.h | 58 | ||||
-rw-r--r-- | tests/test-utils.cc | 112 |
5 files changed, 355 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index dce6076..e204378 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 +test_utils_LDADD = $(top_builddir)/src/libindicator-datetime-service.a $(TEST_LIBS) +test_utils_CPPFLAGS = $(TEST_CPPFLAGS) -DSCHEMA_DIR="\"$(top_builddir)/tests/\"" diff --git a/tests/Makefile.am.strings b/tests/Makefile.am.strings index 26a23a8..4a89e8f 100644 --- a/tests/Makefile.am.strings +++ b/tests/Makefile.am.strings @@ -29,7 +29,7 @@ test-space-ellipsis: $(top_srcdir)/po test-ascii-quotes: $(top_srcdir)/po @echo "#!/bin/bash" > $@ @echo "(cd $(top_srcdir)/po && make $(GETTEXT_PACKAGE).pot)" >> $@ - @echo "grep -c -e \"^msgid \\\".*'.*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII apostrophy found in user visible strings\" >&2 && exit 1" >> $@ + @echo "grep -c -e \"^msgid \\\".*'.*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII apostrophe found in user visible strings\" >&2 && exit 1" >> $@ @echo "grep -c -e \"^msgid \\\".*\\\".*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII quote found in user visible strings\" >&2 && exit 1" >> $@ @echo "grep -c -e \"^msgid \\\".*\\\`.*\\\"\" $(top_srcdir)/po/$(GETTEXT_PACKAGE).pot > /dev/null && echo \"ASCII backtick found in user visible strings\" >&2 && exit 1" >> $@ @echo "exit 0" >> $@ diff --git a/tests/planner-mock.c b/tests/planner-mock.c new file mode 100644 index 0000000..e67ad7e --- /dev/null +++ b/tests/planner-mock.c @@ -0,0 +1,178 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "config.h" + +#include "planner-mock.h" + +struct _IndicatorDatetimePlannerMockPriv +{ + gboolean is_configured; +}; + +typedef IndicatorDatetimePlannerMockPriv priv_t; + +G_DEFINE_TYPE (IndicatorDatetimePlannerMock, + indicator_datetime_planner_mock, + INDICATOR_TYPE_DATETIME_PLANNER) + +/*** +**** IndicatorDatetimePlanner virtual funcs +***/ + +static void +my_get_appointments (IndicatorDatetimePlanner * planner, + GDateTime * begin_datetime, + GDateTime * end_datetime G_GNUC_UNUSED, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask * task; + GSList * appointments; + struct IndicatorDatetimeAppt * appt; + struct IndicatorDatetimeAppt * prev; + + task = g_task_new (planner, NULL, callback, user_data); + + /** + *** Build the appointments list + **/ + + appointments = NULL; + + /* add a daily appointment that occurs at the beginning of the next minute */ + appt = g_slice_new0 (struct IndicatorDatetimeAppt); + appt->is_daily = TRUE; + appt->begin = g_date_time_add_seconds (begin_datetime, 60-g_date_time_get_seconds(begin_datetime)); + appt->end = g_date_time_add_minutes (appt->begin, 1); + appt->color = g_strdup ("#00FF00"); + appt->is_event = TRUE; + appt->summary = g_strdup ("Daily alarm"); + appt->uid = g_strdup ("this uid isn't very random."); + appt->has_alarms = TRUE; + appt->url = g_strdup ("alarm:///some-alarm-info-goes-here"); + appointments = g_slist_prepend (appointments, appt); + prev = appt; + + /* and add one for a minute later that has an alarm uri */ + appt = g_slice_new0 (struct IndicatorDatetimeAppt); + appt->is_daily = TRUE; + appt->begin = g_date_time_add_minutes (prev->end, 1); + appt->end = g_date_time_add_minutes (appt->begin, 1); + appt->color = g_strdup ("#0000FF"); + appt->is_event = TRUE; + appt->summary = g_strdup ("Second Daily alarm"); + appt->uid = g_strdup ("this uid isn't very random either."); + appt->has_alarms = FALSE; + appointments = g_slist_prepend (appointments, appt); + + /* done */ + g_task_return_pointer (task, appointments, NULL); + g_object_unref (task); +} + +static GSList * +my_get_appointments_finish (IndicatorDatetimePlanner * self G_GNUC_UNUSED, + GAsyncResult * res, + GError ** error) +{ + return g_task_propagate_pointer (G_TASK(res), error); +} + +static gboolean +my_is_configured (IndicatorDatetimePlanner * planner) +{ + IndicatorDatetimePlannerMock * self; + self = INDICATOR_DATETIME_PLANNER_MOCK (planner); + return self->priv->is_configured; +} + +static void +my_activate (IndicatorDatetimePlanner * self G_GNUC_UNUSED) +{ + g_message ("%s %s", G_STRLOC, G_STRFUNC); +} + +static void +my_activate_time (IndicatorDatetimePlanner * self G_GNUC_UNUSED, + GDateTime * activate_time) +{ + gchar * str = g_date_time_format (activate_time, "%F %T"); + g_message ("%s %s: %s", G_STRLOC, G_STRFUNC, str); + g_free (str); +} + +/*** +**** GObject virtual funcs +***/ + +static void +my_dispose (GObject * o) +{ + G_OBJECT_CLASS (indicator_datetime_planner_mock_parent_class)->dispose (o); +} + +/*** +**** Instantiation +***/ + +static void +indicator_datetime_planner_mock_class_init (IndicatorDatetimePlannerMockClass * klass) +{ + GObjectClass * object_class; + IndicatorDatetimePlannerClass * planner_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->dispose = my_dispose; + + planner_class = INDICATOR_DATETIME_PLANNER_CLASS (klass); + planner_class->is_configured = my_is_configured; + planner_class->activate = my_activate; + planner_class->activate_time = my_activate_time; + planner_class->get_appointments = my_get_appointments; + planner_class->get_appointments_finish = my_get_appointments_finish; + + g_type_class_add_private (klass, sizeof (IndicatorDatetimePlannerMockPriv)); +} + +static void +indicator_datetime_planner_mock_init (IndicatorDatetimePlannerMock * self) +{ + priv_t * p; + + p = G_TYPE_INSTANCE_GET_PRIVATE (self, + INDICATOR_TYPE_DATETIME_PLANNER_MOCK, + IndicatorDatetimePlannerMockPriv); + + p->is_configured = TRUE; + + self->priv = p; +} + +/*** +**** Public +***/ + +IndicatorDatetimePlanner * +indicator_datetime_planner_mock_new (void) +{ + gpointer o = g_object_new (INDICATOR_TYPE_DATETIME_PLANNER_MOCK, NULL); + + return INDICATOR_DATETIME_PLANNER (o); +} diff --git a/tests/planner-mock.h b/tests/planner-mock.h new file mode 100644 index 0000000..8d7d7c2 --- /dev/null +++ b/tests/planner-mock.h @@ -0,0 +1,58 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __INDICATOR_DATETIME_PLANNER_MOCK__H__ +#define __INDICATOR_DATETIME_PLANNER_MOCK__H__ + +#include "planner.h" /* parent class */ + +G_BEGIN_DECLS + +#define INDICATOR_TYPE_DATETIME_PLANNER_MOCK (indicator_datetime_planner_mock_get_type()) +#define INDICATOR_DATETIME_PLANNER_MOCK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), INDICATOR_TYPE_DATETIME_PLANNER_MOCK, IndicatorDatetimePlannerMock)) +#define INDICATOR_DATETIME_PLANNER_MOCK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), INDICATOR_TYPE_DATETIME_PLANNER_MOCK, IndicatorDatetimePlannerMockClass)) +#define INDICATOR_IS_DATETIME_PLANNER_MOCK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), INDICATOR_TYPE_DATETIME_PLANNER_MOCK)) + +typedef struct _IndicatorDatetimePlannerMock IndicatorDatetimePlannerMock; +typedef struct _IndicatorDatetimePlannerMockPriv IndicatorDatetimePlannerMockPriv; +typedef struct _IndicatorDatetimePlannerMockClass IndicatorDatetimePlannerMockClass; + +GType indicator_datetime_planner_mock_get_type (void); + +/** + * An IndicatorDatetimePlanner which uses Evolution Data Server + * to get its list of appointments. + */ +struct _IndicatorDatetimePlannerMock +{ + /*< private >*/ + IndicatorDatetimePlanner parent; + IndicatorDatetimePlannerMockPriv * priv; +}; + +struct _IndicatorDatetimePlannerMockClass +{ + IndicatorDatetimePlannerClass parent_class; +}; + +IndicatorDatetimePlanner * indicator_datetime_planner_mock_new (void); + +G_END_DECLS + +#endif /* __INDICATOR_DATETIME_PLANNER_MOCK__H__ */ diff --git a/tests/test-utils.cc b/tests/test-utils.cc new file mode 100644 index 0000000..d0f277b --- /dev/null +++ b/tests/test-utils.cc @@ -0,0 +1,112 @@ +/* +Copyright 2012 Canonical Ltd. + +Authors: + Charles Kerr <charles.kerr@canonical.com> + +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 <http://www.gnu.org/licenses/>. +*/ + +#include <gtest/gtest.h> + +#include <glib-object.h> + +#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<n; i++) + { + char * zone = NULL; + char * name = NULL; + + 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); + + g_free (zone); + g_free (name); + } +} + +/*** +**** +***/ + +#define EM_SPACE "\xE2\x80\x82" + +TEST (UtilsTest, GenerateTerseFormatString) +{ + guint i; + guint n; + GDateTime * arbitrary_day = g_date_time_new_local (2013, 6, 25, 12, 34, 56); + GDateTime * on_the_hour = g_date_time_new_local (2013, 6, 25, 12, 0, 0); + + struct { + GDateTime * now; + GDateTime * time; + const char * expected_format_string; + } 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 */ + }; + + for (i=0, n=G_N_ELEMENTS(test_cases); i<n; i++) + { + char * format_string; + + 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); + } + + g_date_time_unref (arbitrary_day); + g_date_time_unref (on_the_hour); +} |