Move panel/common tests into new tests subdirectory

This commit is contained in:
Benjamin Berg 2018-04-06 13:46:47 +02:00
parent c2f601a9d4
commit d2d4980ce8
7 changed files with 26 additions and 22 deletions

View file

@ -1,11 +0,0 @@
# Pretty hostname, tab, display hostname, tab, real hostname
Lennart's PC Lennarts-PC lennarts-pc
Müllers Computer Mullers-Computer mullers-computer
Voran! Voran voran
Es war einmal ein Männlein Es-war-einmal-ein-Mannlein es-war-einmal-ein-mannlein
Jawoll. Ist doch wahr! Jawoll-Ist-doch-wahr jawoll-ist-doch-wahr
レナート localhost localhost
!!! localhost localhost
...zack!!! zack!... zack-zack zack-zack
Bãstien's computer... Foo-bar Bastiens-computer-Foo-bar bastiens-computer-foo-bar
localhost localhost

View file

@ -139,25 +139,3 @@ run_target(
command: script
)
test_unit = 'test-hostname'
sources = files(
'hostname-helper.c',
test_unit + '.c'
)
cflags = [
'-DTEST_SRCDIR="@0@"'.format(meson.current_source_dir()),
'-DTEST_TOPSRCDIR="@0@"'.format(meson.source_root())
]
exe = executable(
test_unit,
sources,
include_directories: top_inc,
dependencies: [ common_deps, libwidgets_dep ],
c_args: cflags
)
test(test_unit, exe)

View file

@ -1,3 +0,0 @@
GNOME GNOME
0123456789abcdefghijklmnopqrstuvwxyz 0123456789abcdefghijklmnopqrstuv
レナート レナート

View file

@ -1,136 +0,0 @@
#include "config.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <locale.h>
#include "hostname-helper.h"
static void
test_hostname (void)
{
char *contents;
char *result;
guint i;
char **lines;
if (g_file_get_contents (TEST_SRCDIR "/hostnames-test.txt", &contents, NULL, NULL) == FALSE) {
g_warning ("Failed to load '%s'", TEST_SRCDIR "/hostnames-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++) {
char *utf8;
char **items;
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 = pretty_hostname_to_static (items[0], FALSE);
if (g_strcmp0 (result, items[2]) != 0) {
g_error ("Result for '%s' doesn't match '%s' (got: '%s')",
utf8, items[2], result);
g_test_fail ();
} else {
g_debug ("Result for '%s' matches '%s'",
utf8, result);
}
g_free (result);
g_free (utf8);
result = pretty_hostname_to_static (items[0], TRUE);
utf8 = g_locale_from_utf8 (items[0], -1, NULL, NULL, NULL);
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);
}
g_free (result);
g_free (utf8);
g_strfreev (items);
}
g_strfreev (lines);
g_free (contents);
}
static void
test_ssid (void)
{
char *contents;
guint i;
char **lines;
if (g_file_get_contents (TEST_SRCDIR "/ssids-test.txt", &contents, NULL, NULL) == FALSE) {
g_warning ("Failed to load '%s'", TEST_SRCDIR "/ssids-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++) {
char *ssid;
char **items;
if (*lines[i] == '#')
continue;
if (*lines[i] == '\0')
break;
items = g_strsplit (lines[i], "\t", -1);
ssid = pretty_hostname_to_ssid (items[0]);
g_assert_cmpstr (ssid, ==, items[1]);
g_free (ssid);
g_strfreev (items);
}
g_strfreev (lines);
g_free (contents);
}
int main (int argc, char **argv)
{
char *locale;
/* Running in some locales will
* break the tests as "ü" will be transliterated to
* "ue" in de_DE, and 'u"' in the C locale.
*
* Work around that by forcing en_US with UTF-8 in
* our tests
* https://bugzilla.gnome.org/show_bug.cgi?id=650342 */
locale = setlocale (LC_ALL, "en_US.UTF-8");
if (locale == NULL) {
g_debug("Missing en_US.UTF-8 locale, ignoring test.");
return 0;
}
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/common/hostname", test_hostname);
g_test_add_func ("/common/ssid", test_ssid);
return g_test_run ();
}