sl@0: /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/ sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: sl@0: int main (int argc, char **argv) sl@0: { sl@0: FILE *infile; sl@0: char buffer[1024]; sl@0: char **strings; sl@0: char *srcdir = getenv ("srcdir"); sl@0: char *filename; sl@0: const char *locale; sl@0: const char *test; sl@0: const char *expected; sl@0: char *convert; sl@0: char *current_locale = setlocale (LC_CTYPE, NULL); sl@0: gint result = 0; sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL); sl@0: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*__SYMBIAN32__*/ sl@0: sl@0: sl@0: if (!srcdir) sl@0: srcdir = "c:"; sl@0: filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casemap.txt", NULL); sl@0: sl@0: infile = fopen (filename, "r"); sl@0: if (!infile) sl@0: { sl@0: fprintf (stderr, "Failed to open %s\n", filename ); sl@0: g_assert(FALSE && "unicode-caseconv failed"); sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("unicode-caseconv"); sl@0: #endif /* EMULATOR */ sl@0: exit (1); sl@0: } sl@0: sl@0: while (fgets (buffer, sizeof(buffer), infile)) sl@0: { sl@0: if (buffer[0] == '#') sl@0: continue; sl@0: sl@0: strings = g_strsplit (buffer, "\t", -1); sl@0: sl@0: locale = strings[0]; sl@0: sl@0: if (!locale[0]) sl@0: locale = "C"; sl@0: sl@0: if (strcmp (locale, current_locale) != 0) sl@0: { sl@0: setlocale (LC_CTYPE, locale); sl@0: current_locale = setlocale (LC_CTYPE, NULL); sl@0: sl@0: if (strncmp (current_locale, locale, 2) != 0) sl@0: { sl@0: fprintf (stderr, "Cannot set locale to %s, skipping\n", locale); sl@0: goto next; sl@0: } sl@0: } sl@0: sl@0: test = strings[1]; sl@0: sl@0: /* gen-casemap-txt.pl uses an empty string when a single character sl@0: * doesn't have an equivalent in a particular case; since that behavior sl@0: * is nonsense for multicharacter strings, it would make more sense sl@0: * to put the expected result .. the original character unchanged. But sl@0: * for now, we just work around it here and take the empty string to mean sl@0: * "same as original" sl@0: */ sl@0: sl@0: convert = g_utf8_strup (test, -1); sl@0: expected = strings[4][0] ? strings[4] : test; sl@0: if (strcmp (convert, expected) != 0) sl@0: { sl@0: fprintf (stderr, "Failure: toupper(%s) == %s, should have been %s\n", sl@0: test, convert, expected); sl@0: result = 1; sl@0: } sl@0: g_free (convert); sl@0: sl@0: convert = g_utf8_strdown (test, -1); sl@0: expected = strings[2][0] ? strings[2] : test; sl@0: if (strcmp (convert, expected) != 0) sl@0: { sl@0: fprintf (stderr, "Failure: tolower(%s) == %s, should have been %s\n", sl@0: test, convert, expected); sl@0: result = 1; sl@0: } sl@0: g_free (convert); sl@0: sl@0: next: sl@0: g_strfreev (strings); sl@0: } sl@0: sl@0: fclose (infile); sl@0: sl@0: g_free (filename); sl@0: filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casefold.txt", NULL); sl@0: sl@0: infile = fopen (filename, "r"); sl@0: if (!infile) sl@0: { sl@0: fprintf (stderr, "Failed to open %s\n", filename ); sl@0: g_assert(FALSE && "unicode-caseconv failed"); sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("unicode-caseconv"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: exit (1); sl@0: } sl@0: sl@0: while (fgets (buffer, sizeof(buffer), infile)) sl@0: { sl@0: if (buffer[0] == '#') sl@0: continue; sl@0: sl@0: buffer[strlen(buffer) - 1] = '\0'; sl@0: strings = g_strsplit (buffer, "\t", -1); sl@0: sl@0: test = strings[0]; sl@0: sl@0: convert = g_utf8_casefold (test, -1); sl@0: if (strcmp (convert, strings[1]) != 0) sl@0: { sl@0: fprintf (stderr, "Failure: casefold(%s) == '%s', should have been '%s'\n", sl@0: test, convert, strings[1]); sl@0: result = 1; sl@0: } sl@0: g_free (convert); sl@0: sl@0: g_strfreev (strings); sl@0: } sl@0: sl@0: fclose (infile); sl@0: g_free (filename); sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("unicode-caseconv"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return result; sl@0: }