diff options
Diffstat (limited to 'tests/info')
-rw-r--r-- | tests/info/info-cleanup-test.txt | 8 | ||||
-rw-r--r-- | tests/info/meson.build | 21 | ||||
-rw-r--r-- | tests/info/test-info-cleanup.c | 81 |
3 files changed, 110 insertions, 0 deletions
diff --git a/tests/info/info-cleanup-test.txt b/tests/info/info-cleanup-test.txt new file mode 100644 index 0000000..6dc72a5 --- /dev/null +++ b/tests/info/info-cleanup-test.txt @@ -0,0 +1,8 @@ +Intel(R) Core(TM) i5-4590T CPU @ 2.00GHz Intel® Core™ i5-4590T CPU @ 2.00GHz +Intel(R) Ivybridge Mobile Intel® Ivybridge Mobile +Intel(R) Ivybridge Mobile Intel® Ivybridge Mobile +Gallium 0.4 on AMD KAVERI AMD® Kaveri +AMD KAVERI (DRM 2.48.0 / 4.9.0-0.rc4.git2.2.fc26.x86_64, LLVM3) AMD® Kaveri +AMD KAVERI (DRM 2.48.0 / 4.9.0-0.rc4.git2.2.fc26.x86_64, LLVM3 AMD® Kaveri +Gallium 0.4 on AMD KAVERI (DRM 2.48.0 / 4.9.0-0.rc4.git2.2.fc26.x86_64, LLVM3) AMD® Kaveri +Gallium 0.4 on AMD KAVERI (DRM 2.48.0 / 4.9.0-0.rc4.git2.2.fc26.x86_64, LLVM3 AMD® Kaveri diff --git a/tests/info/meson.build b/tests/info/meson.build new file mode 100644 index 0000000..0f5d7a9 --- /dev/null +++ b/tests/info/meson.build @@ -0,0 +1,21 @@ + +test_units = [ + 'test-info-cleanup' +] + +includes = [top_inc, include_directories('../../panels/info-overview')] +cflags = '-DTEST_SRCDIR="@0@"'.format(meson.current_source_dir()) + +foreach unit: test_units + exe = executable( + unit, + [unit + '.c'], + include_directories : includes, + dependencies : common_deps, + link_with : [info_panel_lib], + c_args : cflags + ) + + test(unit, exe) +endforeach + diff --git a/tests/info/test-info-cleanup.c b/tests/info/test-info-cleanup.c new file mode 100644 index 0000000..3e6bebd --- /dev/null +++ b/tests/info/test-info-cleanup.c @@ -0,0 +1,81 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2010 Red Hat, Inc + * Copyright (C) 2008 William Jon McCann <jmccann@redhat.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, see <http://www.gnu.org/licenses/>. + * + */ + +#include <config.h> + +#include <glib.h> +#include <locale.h> +#include "info-cleanup.h" + +static void +test_info (void) +{ + g_autofree gchar *contents = NULL; + guint i; + g_auto(GStrv) lines = NULL; + + if (g_file_get_contents (TEST_SRCDIR "/info-cleanup-test.txt", &contents, NULL, NULL) == FALSE) { + g_warning ("Failed to load '%s'", TEST_SRCDIR "/info-cleanup-test.txt"); + g_test_fail (); + return; + } + + lines = g_strsplit (contents, "\n", -1); + if (lines == NULL) { + g_warning ("Test file is empty"); + g_test_fail (); + return; + } + + for (i = 0; lines[i] != NULL; i++) { + g_auto(GStrv) items = NULL; + g_autofree gchar *utf8 = NULL; + g_autofree gchar *result = NULL; + + if (*lines[i] == '#') + continue; + if (*lines[i] == '\0') + break; + + items = g_strsplit (lines[i], "\t", -1); + utf8 = g_locale_from_utf8 (items[0], -1, NULL, NULL, NULL); + result = info_cleanup (items[0]); + if (g_strcmp0 (result, items[1]) != 0) { + g_error ("Result for '%s' doesn't match '%s' (got: '%s')", + utf8, items[1], result); + g_test_fail (); + } else { + g_debug ("Result for '%s' matches '%s'", + utf8, result); + } + } +} + +int main (int argc, char **argv) +{ + setlocale (LC_ALL, ""); + g_test_init (&argc, &argv, NULL); + + g_setenv ("G_DEBUG", "fatal_warnings", FALSE); + + g_test_add_func ("/info/info", test_info); + + return g_test_run (); +} |