diff options
author | Robert Marcano <robert@marcanoonline.com> | 2021-04-07 13:48:47 -0400 |
---|---|---|
committer | Robert Marcano <robert@marcanoonline.com> | 2021-04-20 11:39:27 -0400 |
commit | 30bfd9d6dc5805f8be6776640dc5f4e7fc296de9 (patch) | |
tree | 367ca33e96a3e545fed8fee9747a06210a812c78 /tests | |
parent | 7fe06d61c83ac8a3870d822e797975b91b4a056c (diff) | |
download | gnome-desktop-30bfd9d6dc5805f8be6776640dc5f4e7fc296de9.tar.gz |
Fix animated background's starttime hour parsing
The incorrect time had an offset of one hour.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bg-slide-show.c | 101 | ||||
-rw-r--r-- | tests/meson.build | 4 | ||||
-rw-r--r-- | tests/starttime.xml | 21 |
3 files changed, 125 insertions, 1 deletions
diff --git a/tests/bg-slide-show.c b/tests/bg-slide-show.c new file mode 100644 index 00000000..12ab690e --- /dev/null +++ b/tests/bg-slide-show.c @@ -0,0 +1,101 @@ +/* -*- mode: C; c-file-style: "linux"; indent-tabs-mode: t -*- + * + * Copyright (C) 2021 Robert Marcano <robert@marcanoonline.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <glib.h> +#define GNOME_DESKTOP_USE_UNSTABLE_API +#include <libgnome-desktop/gnome-bg-slide-show.h> + +void +test_starttime (void) +{ + GTimeZone *tz; + GDateTime *reference_time, *slide_show_time; + GnomeBGSlideShow *slide_show; + gboolean loaded; + + tz = g_time_zone_new_local (); + /* Load reference time to be compared with the one on the XML file */ + reference_time = g_date_time_new_from_iso8601 ("2021-04-02T13:14:15", tz); + g_assert (reference_time != NULL); + + g_time_zone_unref (tz); + + /* Parsing XML file */ + slide_show = gnome_bg_slide_show_new ("starttime.xml"); + loaded = gnome_bg_slide_show_load (slide_show, NULL); + g_assert (loaded); + + /* Test if the slide show start time is the same that the reference time */ + slide_show_time = g_date_time_new_from_unix_local (gnome_bg_slide_show_get_start_time (slide_show)); + g_assert (g_date_time_compare (reference_time, slide_show_time) == 0); + + g_date_time_unref (reference_time); + g_date_time_unref (slide_show_time); + g_object_unref (slide_show); +} + +static void +test_starttime_subprocess (const char *tz_str) +{ + if (g_test_subprocess ()) { + g_setenv ("TZ", tz_str, TRUE); + tzset (); + test_starttime (); + return; + } + + g_test_trap_subprocess (NULL, 0, 0); + g_test_trap_assert_passed (); +} + +static void +test_starttime_no_dst (void) +{ + test_starttime_subprocess ("C"); +} + +static void +test_starttime_dst (void) +{ + test_starttime_subprocess ("US/Eastern"); +} + +int +main (int argc, + char *argv[]) +{ + const char *basedir; + + g_test_init (&argc, &argv, NULL); + + basedir = g_getenv ("G_TEST_SRCDIR"); + if (basedir == NULL) + basedir = INSTALLED_TEST_DIR; + + /* We need to ensure the process' current working directory + * is the same as the test data in order to load the test + * slide show easily. + */ + chdir (basedir); + + g_test_add_func ("/bg-slide-show/starttime-no-dst", test_starttime_no_dst); + g_test_add_func ("/bg-slide-show/starttime-dst", test_starttime_dst); + + return g_test_run (); +} diff --git a/tests/meson.build b/tests/meson.build index 8333a810..3b4c0666 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -12,6 +12,7 @@ test_env = [ ] test_programs = [ + 'bg-slide-show', 'wall-clock', 'wallclock-reftest', 'languages' @@ -52,7 +53,8 @@ if get_option('installed_tests') 'he_IL.utf8.ref.ui', 'he_IL.utf8.ui', 'ja_JP.utf8.ref.ui', - 'ja_JP.utf8.ui' + 'ja_JP.utf8.ui', + 'starttime.xml' ) install_data(test_data, install_dir: test_execdir) install_data(test_metas, install_dir: test_metadir) diff --git a/tests/starttime.xml b/tests/starttime.xml new file mode 100644 index 00000000..7e7d9693 --- /dev/null +++ b/tests/starttime.xml @@ -0,0 +1,21 @@ +<background> + <starttime> + <year>2021</year> + <month>4</month> + <day>2</day> + <hour>13</hour> + <minute>14</minute> + <second>15</second> + </starttime> + +<static> +<duration>60.0</duration> +<file>start.png</file> +</static> + +<static> +<duration>60.0</duration> +<file>end.png</file> +</static> + +</background> |