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: sl@0: #ifdef SYMBIAN sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: typedef struct { sl@0: const char *key; sl@0: const char *str; sl@0: } Line; sl@0: sl@0: sl@0: int sl@0: compare_collate (const void *a, const void *b) sl@0: { sl@0: const Line *line_a = a; sl@0: const Line *line_b = b; sl@0: sl@0: return g_utf8_collate (line_a->str, line_b->str); sl@0: } sl@0: sl@0: int sl@0: compare_key (const void *a, const void *b) sl@0: { sl@0: const Line *line_a = a; sl@0: const Line *line_b = b; sl@0: sl@0: return strcmp (line_a->key, line_b->key); sl@0: } sl@0: sl@0: gchar* sorted_res_arr[15] = sl@0: { sl@0: "ABC", sl@0: "Bart", sl@0: "BART", sl@0: "Bartlett", sl@0: "CA", sl@0: "can", sl@0: "Canada", sl@0: "CBS", sl@0: "NBC", sl@0: "next", sl@0: "NeXT", sl@0: "west", sl@0: "West", sl@0: "western", sl@0: NULL sl@0: }; sl@0: sl@0: int main (int argc, char **argv) sl@0: { sl@0: GIOChannel *in; sl@0: GError *error = NULL; sl@0: gchar *srcdir = getenv ("srcdir"); sl@0: gchar *testfile; sl@0: GArray *line_array; sl@0: guint i; sl@0: sl@0: #ifdef SYMBIAN 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: line_array = g_array_new (FALSE, FALSE, sizeof(Line)); sl@0: sl@0: if (!srcdir) sl@0: srcdir = "c:"; sl@0: sl@0: testfile = g_strconcat (srcdir, G_DIR_SEPARATOR_S "casecollate.txt", NULL); sl@0: sl@0: in = g_io_channel_new_file (testfile, "r", &error); sl@0: if (!in) sl@0: { sl@0: g_print("Cannot open %s: %s\n", testfile, error->message); sl@0: sl@0: g_assert(FALSE && "unicode-collate failed"); sl@0: sl@0: #ifdef SYMBIAN sl@0: testResultXml("unicode-collate"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 1; sl@0: } sl@0: sl@0: while (TRUE) sl@0: { sl@0: gsize term_pos; sl@0: gchar *str; sl@0: Line line; sl@0: gint keylen; sl@0: gint strlen; sl@0: sl@0: if (g_io_channel_read_line (in, &str, NULL, &term_pos, &error) != G_IO_STATUS_NORMAL) sl@0: break; sl@0: sl@0: str[term_pos] = '\0'; sl@0: sl@0: line.key = g_utf8_collate_key (str, -1); sl@0: line.str = str; sl@0: sl@0: g_array_append_val (line_array, line); sl@0: } sl@0: sl@0: if (error) sl@0: { sl@0: g_print("Error reading test file, %s\n", error->message); sl@0: sl@0: g_assert(FALSE && "unicode-collate failed"); sl@0: sl@0: #ifdef SYMBIAN sl@0: testResultXml("unicode-collate"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 1; sl@0: } sl@0: sl@0: qsort (line_array->data, line_array->len, sizeof (Line), compare_collate); sl@0: for (i = 0; i < line_array->len; i++) sl@0: { sl@0: if(strcmp(sorted_res_arr[i], g_array_index (line_array, Line, i).str)) sl@0: { sl@0: g_assert(FALSE && "compare_collate failed\n"); sl@0: sl@0: } sl@0: } sl@0: sl@0: qsort (line_array->data, line_array->len, sizeof (Line), compare_key); sl@0: for (i = 0; i < line_array->len; i++) sl@0: { sl@0: if(strcmp(sorted_res_arr[i], g_array_index (line_array, Line, i).str)) sl@0: { sl@0: g_assert(FALSE && "compare_key failed\n"); sl@0: } sl@0: } sl@0: sl@0: g_io_channel_unref (in); sl@0: sl@0: #ifdef SYMBIAN sl@0: testResultXml("unicode-collate"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 0; sl@0: }