2011-05-13 15:48:45 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <locale.h>
|
|
|
|
|
|
|
|
#include "hostname-helper.h"
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
guint i;
|
2011-05-17 15:19:46 +01:00
|
|
|
char *contents;
|
|
|
|
char **lines;
|
2011-05-13 15:48:45 +01:00
|
|
|
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
|
2011-05-17 15:19:46 +01:00
|
|
|
if (g_file_get_contents (argv[1], &contents, NULL, NULL) == FALSE) {
|
|
|
|
g_warning ("Failed to load '%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
lines = g_strsplit (contents, "\n", -1);
|
|
|
|
if (lines == NULL) {
|
|
|
|
g_warning ("Test file is empty");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; lines[i] != NULL; i++) {
|
|
|
|
char *utf8;
|
|
|
|
char **items;
|
2011-05-13 15:48:45 +01:00
|
|
|
|
2011-05-17 15:19:46 +01:00
|
|
|
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)
|
2011-05-13 15:48:45 +01:00
|
|
|
g_error ("Result for '%s' doesn't match '%s' (got: '%s')",
|
2011-05-17 15:19:46 +01:00
|
|
|
utf8, items[2], result);
|
2011-05-13 15:48:45 +01:00
|
|
|
else
|
|
|
|
g_debug ("Result for '%s' matches '%s'",
|
2011-05-17 15:19:46 +01:00
|
|
|
utf8, result);
|
2011-05-13 15:48:45 +01:00
|
|
|
g_free (result);
|
2011-05-17 15:19:46 +01:00
|
|
|
g_free (utf8);
|
2011-05-13 15:48:45 +01:00
|
|
|
|
2011-05-17 15:19:46 +01:00
|
|
|
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)
|
2011-05-13 15:48:45 +01:00
|
|
|
g_error ("Result for '%s' doesn't match '%s' (got: '%s')",
|
2011-05-17 15:19:46 +01:00
|
|
|
utf8, items[1], result);
|
2011-05-13 15:48:45 +01:00
|
|
|
else
|
|
|
|
g_debug ("Result for '%s' matches '%s'",
|
2011-05-17 15:19:46 +01:00
|
|
|
utf8, result);
|
2011-05-13 15:48:45 +01:00
|
|
|
g_free (result);
|
2011-05-17 15:19:46 +01:00
|
|
|
g_free (utf8);
|
|
|
|
|
|
|
|
g_strfreev (items);
|
2011-05-13 15:48:45 +01:00
|
|
|
}
|
|
|
|
|
2011-05-17 15:19:46 +01:00
|
|
|
g_strfreev (lines);
|
|
|
|
|
2011-05-13 15:48:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|