|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #undef G_DISABLE_ASSERT |
|
20 #undef G_LOG_DOMAIN |
|
21 |
|
22 |
|
23 #include <stdio.h> |
|
24 #include <string.h> |
|
25 #include <glib.h> |
|
26 #include <fcntl.h> |
|
27 #include <goption.h> |
|
28 |
|
29 #ifdef SYMBIAN |
|
30 #include "mrt2_glib2_test.h" |
|
31 #endif /*SYMBIAN*/ |
|
32 |
|
33 #define SIZE 30 |
|
34 |
|
35 void tg_utf8_prev_char() |
|
36 { |
|
37 FILE* fp; |
|
38 int i = 0; |
|
39 gchar ip[SIZE]; |
|
40 gchar *g_utf8_prev_char_op; |
|
41 gchar *input; |
|
42 |
|
43 fp = fopen ("c:\\utf8_hindi.txt","r"); |
|
44 while ( L'\n' != (ip[i] = fgetwc (fp))) |
|
45 i++; |
|
46 fclose (fp); |
|
47 input = &ip[2]; |
|
48 |
|
49 g_utf8_prev_char_op = g_utf8_prev_char (input); |
|
50 g_assert ( g_utf8_prev_char_op[0] == 0x15); |
|
51 } |
|
52 |
|
53 void tg_utf8_offset_to_pointer() |
|
54 { |
|
55 FILE *fp; |
|
56 int i = 0; |
|
57 gchar ip[SIZE]; |
|
58 gchar *g_utf8_offset_to_pointer_op; |
|
59 gchar *input; |
|
60 |
|
61 fp = fopen ("c:\\utf8_hindi.txt","r"); |
|
62 while ( L'\n' != (ip[i] = fgetwc (fp))) |
|
63 i++; |
|
64 fclose (fp); |
|
65 |
|
66 input = &ip[1]; |
|
67 g_utf8_offset_to_pointer_op = g_utf8_offset_to_pointer (input ,6); |
|
68 g_assert ( g_utf8_offset_to_pointer_op[0] == 0x24); |
|
69 } |
|
70 |
|
71 void tg_utf8_pointer_to_offset() |
|
72 { |
|
73 FILE *fp; |
|
74 int i = 0; |
|
75 gchar ip[SIZE]; |
|
76 glong g_utf8_pointer_to_offset_op; |
|
77 gchar *input; |
|
78 gchar *feed; |
|
79 |
|
80 fp = fopen ("c:\\utf8_hindi.txt","r"); |
|
81 while ( L'\n' != (ip[i] = fgetwc (fp))) |
|
82 i++; |
|
83 fclose (fp); |
|
84 |
|
85 input = &ip[1]; |
|
86 feed = &ip[7]; |
|
87 g_utf8_pointer_to_offset_op = g_utf8_pointer_to_offset (input ,feed); |
|
88 g_assert ( g_utf8_pointer_to_offset_op == 6); |
|
89 } |
|
90 |
|
91 void tg_utf8_strncpy() |
|
92 { |
|
93 FILE* fp; |
|
94 int i = 0; |
|
95 gchar ip[SIZE]; |
|
96 gchar feed[15]; |
|
97 unsigned int op[]= |
|
98 { |
|
99 0x15,0x24,0x1A,0x41,0x30 |
|
100 }; |
|
101 fp = fopen ("c:\\utf8_hindi.txt","r"); |
|
102 while ( L'\n' != (ip[i] = fgetwc (fp))) |
|
103 i++; |
|
104 fclose (fp); |
|
105 |
|
106 g_utf8_strncpy (feed ,&ip[1] ,5); |
|
107 |
|
108 for(i = 0;i < 5;i++) |
|
109 { |
|
110 g_assert (feed[i] == op[i]); |
|
111 } |
|
112 } |
|
113 |
|
114 void tg_utf8_strrchr() |
|
115 { |
|
116 FILE* fp; |
|
117 int i = 0; |
|
118 gchar ip[SIZE]; |
|
119 gchar *input; |
|
120 gchar *g_utf8_strrchr_op; |
|
121 |
|
122 fp = fopen ("c:\\utf8_hindi.txt","r"); |
|
123 while ( L'\n' != (ip[i] = fgetwc (fp))) |
|
124 i++; |
|
125 fclose (fp); |
|
126 |
|
127 input = &ip[1]; |
|
128 g_utf8_strrchr_op = g_utf8_strrchr (input ,-1 , 0x1A); |
|
129 g_assert (g_utf8_strrchr_op[1] == 0x41); |
|
130 } |
|
131 |
|
132 void tg_utf8_collate_key_for_filename() |
|
133 { |
|
134 gchar input[] = "ptr.txt"; |
|
135 gchar *g_utf8_collate_key_for_filename_op; |
|
136 g_utf8_collate_key_for_filename_op = g_utf8_collate_key_for_filename (input ,6); |
|
137 g_assert (g_utf8_collate_key_for_filename_op[0] == 'A'); |
|
138 } |
|
139 |
|
140 void tg_filename_from_utf8() |
|
141 { |
|
142 FILE* fp; |
|
143 int i = 0; |
|
144 gchar ip[SIZE]; |
|
145 gchar *input; |
|
146 gsize bytes_read = 0; |
|
147 gsize bytes_written = 0; |
|
148 gchar *g_filename_from_utf8_op; |
|
149 unsigned int op[]= |
|
150 { |
|
151 0x15,0x24,0x1A,0x41,0x30 |
|
152 }; |
|
153 |
|
154 fp = fopen ("c:\\utf8_hindi.txt","r"); |
|
155 while ( L'\n' != (ip[i] = fgetwc (fp))) |
|
156 i++; |
|
157 fclose (fp); |
|
158 |
|
159 input = &ip[1]; |
|
160 g_filename_from_utf8_op = g_filename_from_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL); |
|
161 |
|
162 for(i = 0;i < 5;i++) |
|
163 { |
|
164 g_assert (g_filename_from_utf8_op[i] == op[i]); |
|
165 } |
|
166 } |
|
167 |
|
168 |
|
169 void tg_filename_to_utf8() |
|
170 { |
|
171 FILE* fp; |
|
172 int i = 0; |
|
173 gchar ip[SIZE]; |
|
174 gchar *input; |
|
175 gsize bytes_read = 0; |
|
176 gsize bytes_written = 0; |
|
177 gchar *g_filename_to_utf8_op; |
|
178 unsigned int op[]= |
|
179 { |
|
180 0x15,0x24,0x1A,0x41,0x30 |
|
181 }; |
|
182 |
|
183 fp = fopen ("c:\\utf8_hindi.txt","r"); |
|
184 while ( L'\n' != (ip[i] = fgetwc (fp))) |
|
185 i++; |
|
186 fclose (fp); |
|
187 |
|
188 input = &ip[1]; |
|
189 g_filename_to_utf8_op = g_filename_to_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL); |
|
190 |
|
191 for(i = 0;i < 5;i++) |
|
192 { |
|
193 g_assert (g_filename_to_utf8_op[i] == op[i]); |
|
194 } |
|
195 } |
|
196 |
|
197 int main (int argc,char *argv[]) |
|
198 { |
|
199 |
|
200 #ifdef SYMBIAN |
|
201 |
|
202 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); |
|
203 #endif /*SYMBIAN*/ |
|
204 |
|
205 tg_utf8_prev_char (); |
|
206 tg_utf8_offset_to_pointer(); |
|
207 tg_utf8_pointer_to_offset(); |
|
208 tg_utf8_strncpy(); |
|
209 tg_utf8_strrchr(); |
|
210 tg_utf8_collate_key_for_filename(); |
|
211 tg_filename_from_utf8(); |
|
212 tg_filename_to_utf8(); |
|
213 #ifdef SYMBIAN |
|
214 testResultXml("tutf8"); |
|
215 #endif /* EMULATOR */ |
|
216 return 0; |
|
217 } |