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