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 SYMBIAN 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: char *convert; sl@0: #define true 1 sl@0: #define false 0 sl@0: char passed = true; sl@0: int lines = 0; sl@0: sl@0: sl@0: sl@0: char *current_locale = setlocale (LC_CTYPE, NULL); sl@0: gint result = 0; sl@0: sl@0: #ifdef SYMBIAN 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 /*SYMBIAN*/ sl@0: sl@0: sl@0: if (!srcdir) sl@0: srcdir = "c:"; sl@0: filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casemap.bin", NULL); sl@0: sl@0: infile = fopen (filename, "r"); sl@0: if (!infile) sl@0: { sl@0: g_print("Failed to open %s\n", filename ); sl@0: g_assert(FALSE && "unicode-caseconv failed"); sl@0: sl@0: #ifdef SYMBIAN 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: lines++; 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: g_print("Cannot set locale to %s, skipping\n", locale); sl@0: g_assert(FALSE && "unicode-caseconv failed"); sl@0: goto next; sl@0: } sl@0: } sl@0: sl@0: test = strings[1]; sl@0: sl@0: convert = g_utf8_strup (test, -1); sl@0: if (strcmp (convert, strings[4]) != 0) sl@0: { sl@0: g_print("Failure: strup of line %d of casemap.bin toupper(%s) == %s, should have been %s\n", sl@0: lines,test, convert, strings[4]); sl@0: passed = false; sl@0: //g_assert(FALSE && "unicode-caseconv failed"); sl@0: result = 1; sl@0: } sl@0: g_free (convert); sl@0: sl@0: convert = g_utf8_strdown (test, -1); sl@0: if (strcmp (convert, strings[2]) != 0) sl@0: { sl@0: g_print("Failure: strdown of line %d of casemap.bin tolower(%s) == %s, should have been %s\n", sl@0: lines,test, convert, strings[2]); sl@0: //g_assert(FALSE && "unicode-caseconv failed"); sl@0: passed = false; 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: sl@0: g_assert(passed && "unicode-caseconv failed"); sl@0: passed = true; sl@0: filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "casefold.bin", NULL); sl@0: sl@0: infile = fopen (filename, "r"); sl@0: if (!infile) sl@0: { sl@0: g_print("Failed to open %s\n", filename ); sl@0: g_assert(FALSE && "unicode-caseconv failed"); sl@0: sl@0: #ifdef SYMBIAN sl@0: testResultXml("unicode-caseconv"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: exit (1); sl@0: } sl@0: sl@0: lines = 0; sl@0: while (fgets(buffer, sizeof(buffer), infile)) sl@0: { sl@0: lines++; 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: g_print("Failure: line %d casefold(%s) == '%s', should have been '%s'\n", sl@0: lines,test, convert, strings[1]); sl@0: //g_assert(FALSE && "unicode-caseconv failed"); sl@0: passed = false; 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: sl@0: g_assert(passed && "unicode-caseconv failed"); sl@0: sl@0: #ifdef SYMBIAN sl@0: testResultXml("unicode-caseconv"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return result; sl@0: }