sl@0
|
1 |
/* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
|
sl@0
|
2 |
#undef G_DISABLE_ASSERT
|
sl@0
|
3 |
#undef G_LOG_DOMAIN
|
sl@0
|
4 |
|
sl@0
|
5 |
#include <glib.h>
|
sl@0
|
6 |
#include <stdio.h>
|
sl@0
|
7 |
#include <stdlib.h>
|
sl@0
|
8 |
#include <string.h>
|
sl@0
|
9 |
|
sl@0
|
10 |
#ifdef SYMBIAN
|
sl@0
|
11 |
#include "mrt2_glib2_test.h"
|
sl@0
|
12 |
#endif /*SYMBIAN*/
|
sl@0
|
13 |
|
sl@0
|
14 |
typedef struct {
|
sl@0
|
15 |
const char *key;
|
sl@0
|
16 |
const char *str;
|
sl@0
|
17 |
} Line;
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
int
|
sl@0
|
21 |
compare_collate (const void *a, const void *b)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
const Line *line_a = a;
|
sl@0
|
24 |
const Line *line_b = b;
|
sl@0
|
25 |
|
sl@0
|
26 |
return g_utf8_collate (line_a->str, line_b->str);
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
int
|
sl@0
|
30 |
compare_key (const void *a, const void *b)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
const Line *line_a = a;
|
sl@0
|
33 |
const Line *line_b = b;
|
sl@0
|
34 |
|
sl@0
|
35 |
return strcmp (line_a->key, line_b->key);
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
gchar* sorted_res_arr[15] =
|
sl@0
|
39 |
{
|
sl@0
|
40 |
"ABC",
|
sl@0
|
41 |
"Bart",
|
sl@0
|
42 |
"BART",
|
sl@0
|
43 |
"Bartlett",
|
sl@0
|
44 |
"CA",
|
sl@0
|
45 |
"can",
|
sl@0
|
46 |
"Canada",
|
sl@0
|
47 |
"CBS",
|
sl@0
|
48 |
"NBC",
|
sl@0
|
49 |
"next",
|
sl@0
|
50 |
"NeXT",
|
sl@0
|
51 |
"west",
|
sl@0
|
52 |
"West",
|
sl@0
|
53 |
"western",
|
sl@0
|
54 |
NULL
|
sl@0
|
55 |
};
|
sl@0
|
56 |
|
sl@0
|
57 |
int main (int argc, char **argv)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
GIOChannel *in;
|
sl@0
|
60 |
GError *error = NULL;
|
sl@0
|
61 |
gchar *srcdir = getenv ("srcdir");
|
sl@0
|
62 |
gchar *testfile;
|
sl@0
|
63 |
GArray *line_array;
|
sl@0
|
64 |
guint i;
|
sl@0
|
65 |
|
sl@0
|
66 |
#ifdef SYMBIAN
|
sl@0
|
67 |
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
|
68 |
g_set_print_handler(mrtPrintHandler);
|
sl@0
|
69 |
#endif /*SYMBIAN*/
|
sl@0
|
70 |
|
sl@0
|
71 |
line_array = g_array_new (FALSE, FALSE, sizeof(Line));
|
sl@0
|
72 |
|
sl@0
|
73 |
if (!srcdir)
|
sl@0
|
74 |
srcdir = "c:";
|
sl@0
|
75 |
|
sl@0
|
76 |
testfile = g_strconcat (srcdir, G_DIR_SEPARATOR_S "casecollate.txt", NULL);
|
sl@0
|
77 |
|
sl@0
|
78 |
in = g_io_channel_new_file (testfile, "r", &error);
|
sl@0
|
79 |
if (!in)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
g_print("Cannot open %s: %s\n", testfile, error->message);
|
sl@0
|
82 |
|
sl@0
|
83 |
g_assert(FALSE && "unicode-collate failed");
|
sl@0
|
84 |
|
sl@0
|
85 |
#ifdef SYMBIAN
|
sl@0
|
86 |
testResultXml("unicode-collate");
|
sl@0
|
87 |
#endif /* EMULATOR */
|
sl@0
|
88 |
|
sl@0
|
89 |
return 1;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
while (TRUE)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
gsize term_pos;
|
sl@0
|
95 |
gchar *str;
|
sl@0
|
96 |
Line line;
|
sl@0
|
97 |
gint keylen;
|
sl@0
|
98 |
gint strlen;
|
sl@0
|
99 |
|
sl@0
|
100 |
if (g_io_channel_read_line (in, &str, NULL, &term_pos, &error) != G_IO_STATUS_NORMAL)
|
sl@0
|
101 |
break;
|
sl@0
|
102 |
|
sl@0
|
103 |
str[term_pos] = '\0';
|
sl@0
|
104 |
|
sl@0
|
105 |
line.key = g_utf8_collate_key (str, -1);
|
sl@0
|
106 |
line.str = str;
|
sl@0
|
107 |
|
sl@0
|
108 |
g_array_append_val (line_array, line);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
if (error)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
g_print("Error reading test file, %s\n", error->message);
|
sl@0
|
114 |
|
sl@0
|
115 |
g_assert(FALSE && "unicode-collate failed");
|
sl@0
|
116 |
|
sl@0
|
117 |
#ifdef SYMBIAN
|
sl@0
|
118 |
testResultXml("unicode-collate");
|
sl@0
|
119 |
#endif /* EMULATOR */
|
sl@0
|
120 |
|
sl@0
|
121 |
return 1;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
qsort (line_array->data, line_array->len, sizeof (Line), compare_collate);
|
sl@0
|
125 |
for (i = 0; i < line_array->len; i++)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
if(strcmp(sorted_res_arr[i], g_array_index (line_array, Line, i).str))
|
sl@0
|
128 |
{
|
sl@0
|
129 |
g_assert(FALSE && "compare_collate failed\n");
|
sl@0
|
130 |
|
sl@0
|
131 |
}
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
qsort (line_array->data, line_array->len, sizeof (Line), compare_key);
|
sl@0
|
135 |
for (i = 0; i < line_array->len; i++)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
if(strcmp(sorted_res_arr[i], g_array_index (line_array, Line, i).str))
|
sl@0
|
138 |
{
|
sl@0
|
139 |
g_assert(FALSE && "compare_key failed\n");
|
sl@0
|
140 |
}
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
g_io_channel_unref (in);
|
sl@0
|
144 |
|
sl@0
|
145 |
#ifdef SYMBIAN
|
sl@0
|
146 |
testResultXml("unicode-collate");
|
sl@0
|
147 |
#endif /* EMULATOR */
|
sl@0
|
148 |
|
sl@0
|
149 |
return 0;
|
sl@0
|
150 |
}
|