[libgweather] tests: Add test for named-timezones codes



commit 2373f56f377d550039456b42d6695ab7e825cf38
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 6 01:41:20 2017 +0100

    tests: Add test for named-timezones codes
    
    This is the first automated test for libgweather, so it is named
    generically to be extended.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791289

 libgweather/meson.build        |    9 +++++
 libgweather/test_libgweather.c |   72 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/libgweather/meson.build b/libgweather/meson.build
index 660e05d..4f8b3d2 100644
--- a/libgweather/meson.build
+++ b/libgweather/meson.build
@@ -103,6 +103,15 @@ executable('test_locations_utc',
   ['test_locations_utc.c'],
   dependencies: libgweather_dep,
   install: false)
+
+test_cargs = ['-DTEST_SRCDIR="@0@/"'.format(meson.current_source_dir())]
+exe = executable('test_libgweather',
+  ['test_libgweather.c'],
+  c_args: test_cargs,
+  dependencies: libgweather_dep,
+  install: false)
+test('test_named_timezones', exe)
+
 #executable('test_metar',
 #  ['test_metar.c', 'weather-metar.c'],
 #  dependencies: libgweather_dep,
diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c
new file mode 100644
index 0000000..6d9f56e
--- /dev/null
+++ b/libgweather/test_libgweather.c
@@ -0,0 +1,72 @@
+/*
+ * (c) 2017 Bastien Nocera <hadess hadess net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301  USA.
+ */
+
+#include "config.h"
+
+#include <locale.h>
+#include <gweather-version.h>
+#include "gweather-location.h"
+
+static void
+test_named_timezones (void)
+{
+    GWeatherLocation *world, **children;
+    guint i;
+
+    world = gweather_location_new_world_for_path (TEST_SRCDIR "../data/Locations.xml");
+    g_assert (world);
+
+    children = gweather_location_get_children (world);
+    for (i = 0; children[i] != NULL; i++) {
+        GWeatherLocationLevel level;
+        const char *code;
+
+        level = gweather_location_get_level (children[i]);
+        if (level != GWEATHER_LOCATION_NAMED_TIMEZONE)
+            continue;
+
+        code = gweather_location_get_code (children[i]);
+        g_assert_nonnull (code);
+        g_assert_true (code[0] == '@');
+    }
+
+    gweather_location_unref (world);
+}
+
+static void
+log_handler (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer user_data)
+{
+       g_test_message ("%s", message);
+}
+
+int
+main (int argc, char *argv[])
+{
+       setlocale (LC_ALL, "");
+
+       g_test_init (&argc, &argv, NULL);
+       g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=";);
+
+       /* We need to handle log messages produced by g_message so they're interpreted correctly by the 
GTester framework */
+       g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, log_handler, 
NULL);
+
+       g_test_add_func ("/weather/named-timezones", test_named_timezones);
+
+       return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]