+#undef G_DISABLE_ASSERT
+#undef G_LOG_DOMAIN
+
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
static gint exit_status = 0;
-void
+static void
croak (char *format, ...)
{
va_list va;
exit (1);
}
-void
+static void
fail (char *format, ...)
{
va_list va;
const gchar *end;
gboolean is_valid = g_utf8_validate (utf8, -1, &end);
GError *error = NULL;
- gint items_read, items_written;
+ glong items_read, items_written;
switch (status)
{
gunichar2 *utf16_from_utf8;
gunichar2 *utf16_from_ucs4;
gunichar *ucs4_result;
- gint bytes_written;
+ gsize bytes_written;
gint n_chars;
gchar *utf8_result;
- if (!(utf16_expected_tmp = (gunichar2 *)g_convert (utf8, -1, "UTF-16", "UTF-8",
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define TARGET "UTF-16LE"
+#else
+#define TARGET "UTF-16"
+#endif
+
+ if (!(utf16_expected_tmp = (gunichar2 *)g_convert (utf8, -1, TARGET, "UTF-8",
NULL, &bytes_written, NULL)))
{
fail ("line %d: could not convert to UTF-16 via g_convert\n", line);
}
else if (utf16_expected_tmp[0] == 0xfffe) /* ANTI-BOM */
{
- fail ("line %d: conversion via iconv to \"UTF-16\" is not native-endian\n");
+ fail ("line %d: conversion via iconv to \"UTF-16\" is not native-endian\n", line);
return;
}
else
int
main (int argc, char **argv)
{
- gchar *srcdir = getenv ("srcdir");
gchar *testfile;
gchar *contents;
GError *error = NULL;
GArray *ucs4;
Status status = VALID; /* Quiet GCC */
- if (!srcdir)
- srcdir = ".";
-
- testfile = g_strconcat (srcdir, "/", "utf8.txt", NULL);
-
+ g_test_init (&argc, &argv, NULL);
+
+ testfile = g_test_build_filename (G_TEST_DIST, "utf8.txt", NULL);
+
g_file_get_contents (testfile, &contents, NULL, &error);
if (error)
croak ("Cannot open utf8.txt: %s", error->message);
p++;
end = p;
- while (*end && *end != '\n')
+ while (*end && (*end != '\r' && *end != '\n'))
end++;
- if (!*p || *p == '#' || *p == '\n')
+ if (!*p || *p == '#' || *p == '\r' || *p == '\n')
goto next_line;
tmp = g_strstrip (g_strndup (p, end - p));
next_line:
p = end;
+ if (*p && *p == '\r')
+ p++;
if (*p && *p == '\n')
p++;
line++;
}
- return 0;
+ g_free (testfile);
+ g_array_free (ucs4, TRUE);
+ g_free (contents);
+ return exit_status;
}