os/ossrv/glib/tsrc/BC/src/tutf8.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tsrc/BC/src/tutf8.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,223 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.6 +*
     1.7 +* This library is free software; you can redistribute it and/or
     1.8 +* modify it under the terms of the GNU Lesser General Public
     1.9 +* License as published by the Free Software Foundation; either
    1.10 +* version 2 of the License, or (at your option) any later version.
    1.11 +*
    1.12 +* This library is distributed in the hope that it will be useful,
    1.13 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 +* Lesser General Public License for more details.
    1.16 +*
    1.17 +* You should have received a copy of the GNU Lesser General Public
    1.18 +* License along with this library; if not, write to the
    1.19 +* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1.20 +* Boston, MA 02111-1307, USA.
    1.21 +*
    1.22 +* Description:  ?Description
    1.23 +*
    1.24 +*/
    1.25 +
    1.26 +
    1.27 +#undef G_DISABLE_ASSERT
    1.28 +#undef G_LOG_DOMAIN
    1.29 +
    1.30 +
    1.31 +#include <stdio.h>
    1.32 +#include <string.h>
    1.33 +#include <glib.h>
    1.34 +#include <fcntl.h>
    1.35 +#include <goption.h>
    1.36 +#include <wchar.h>
    1.37 +
    1.38 +#ifdef SYMBIAN
    1.39 +#include "mrt2_glib2_test.h"
    1.40 +#endif /*SYMBIAN*/
    1.41 +
    1.42 +#define SIZE	30
    1.43 +
    1.44 +void tg_utf8_prev_char()
    1.45 +{
    1.46 +	FILE* fp;
    1.47 +	int i = 0;
    1.48 +	gchar ip[SIZE];
    1.49 +	gchar *g_utf8_prev_char_op;
    1.50 +	gchar *input;
    1.51 +	
    1.52 +	fp = fopen ("c:\\utf8_hindi.txt","r");
    1.53 + 	while ( L'\n' != (ip[i] = fgetwc (fp)))
    1.54 + 		i++;
    1.55 + 	fclose (fp);
    1.56 + 	input = &ip[2];
    1.57 + 	
    1.58 + 	g_utf8_prev_char_op = g_utf8_prev_char (input);
    1.59 +	g_assert ( g_utf8_prev_char_op[0] == 0x15);
    1.60 +}
    1.61 +
    1.62 +void tg_utf8_offset_to_pointer()
    1.63 +{
    1.64 + 	FILE *fp;
    1.65 + 	int i = 0;
    1.66 +	gchar ip[SIZE];
    1.67 +	gchar *g_utf8_offset_to_pointer_op;
    1.68 +	gchar *input;
    1.69 +	
    1.70 + 	fp = fopen ("c:\\utf8_hindi.txt","r");
    1.71 + 	while ( L'\n' != (ip[i] = fgetwc (fp)))
    1.72 + 		i++;
    1.73 + 	fclose (fp);
    1.74 + 	
    1.75 + 	input = &ip[1];
    1.76 +	g_utf8_offset_to_pointer_op = g_utf8_offset_to_pointer (input ,6);
    1.77 +	g_assert ( g_utf8_offset_to_pointer_op[0] == 0x24);
    1.78 +}
    1.79 +
    1.80 +void tg_utf8_pointer_to_offset()
    1.81 +{
    1.82 + 	FILE *fp;
    1.83 + 	int i = 0;
    1.84 +	gchar ip[SIZE];
    1.85 +	glong g_utf8_pointer_to_offset_op;
    1.86 +	gchar *input;
    1.87 +	gchar *feed;
    1.88 +	
    1.89 + 	fp = fopen ("c:\\utf8_hindi.txt","r");
    1.90 + 	while ( L'\n' != (ip[i] = fgetwc (fp)))
    1.91 + 		i++;
    1.92 + 	fclose (fp);
    1.93 + 	
    1.94 + 	input = &ip[1];
    1.95 + 	feed = &ip[7];
    1.96 +	g_utf8_pointer_to_offset_op = g_utf8_pointer_to_offset (input ,feed);
    1.97 +	g_assert ( g_utf8_pointer_to_offset_op == 6);
    1.98 +}
    1.99 +
   1.100 +void tg_utf8_strncpy()
   1.101 +{
   1.102 + 	FILE* fp;
   1.103 +	int i = 0;
   1.104 + 	gchar ip[SIZE];
   1.105 + 	gchar feed[15];
   1.106 +	unsigned int op[]=
   1.107 +	{
   1.108 +		0x15,0x24,0x1A,0x41,0x30
   1.109 +	};
   1.110 + 	fp = fopen ("c:\\utf8_hindi.txt","r");
   1.111 + 	while ( L'\n' != (ip[i] = fgetwc (fp)))
   1.112 + 		i++;
   1.113 + 	fclose (fp);
   1.114 + 	
   1.115 +	g_utf8_strncpy (feed ,&ip[1] ,5);
   1.116 +	
   1.117 +	for(i = 0;i < 5;i++)
   1.118 +	{
   1.119 +		g_assert (feed[i] == op[i]);
   1.120 +	}
   1.121 +}
   1.122 +
   1.123 +void tg_utf8_strrchr()
   1.124 +{
   1.125 +	FILE* fp;
   1.126 +	int i = 0;
   1.127 +	gchar ip[SIZE];
   1.128 +	gchar *input;
   1.129 +	gchar *g_utf8_strrchr_op;
   1.130 +	
   1.131 + 	fp = fopen ("c:\\utf8_hindi.txt","r");
   1.132 + 	while ( L'\n' != (ip[i] = fgetwc (fp)))
   1.133 + 		i++;
   1.134 + 	fclose (fp);
   1.135 + 	
   1.136 + 	input = &ip[1];
   1.137 + 	g_utf8_strrchr_op = g_utf8_strrchr (input ,-1 , 0x1A);
   1.138 +	g_assert (g_utf8_strrchr_op[1] == 0x41);
   1.139 +}
   1.140 +
   1.141 +void tg_utf8_collate_key_for_filename()
   1.142 +{
   1.143 +	gchar input[] = "ptr.txt";
   1.144 +	gchar *g_utf8_collate_key_for_filename_op;
   1.145 +	g_utf8_collate_key_for_filename_op = g_utf8_collate_key_for_filename (input ,6);
   1.146 +	g_assert (g_utf8_collate_key_for_filename_op[0] == 'A');
   1.147 +}	
   1.148 +
   1.149 +void tg_filename_from_utf8()
   1.150 +{
   1.151 +	FILE* fp;
   1.152 +	int i = 0;
   1.153 +	gchar ip[SIZE];
   1.154 +	gchar *input;
   1.155 +	gsize bytes_read = 0;
   1.156 +    gsize bytes_written = 0;
   1.157 +    gchar *g_filename_from_utf8_op;
   1.158 +    unsigned int op[]=
   1.159 +	{
   1.160 +		0x15,0x24,0x1A,0x41,0x30
   1.161 +	};
   1.162 +	
   1.163 +    fp = fopen ("c:\\utf8_hindi.txt","r");
   1.164 + 	while ( L'\n' != (ip[i] = fgetwc (fp)))
   1.165 + 		i++;
   1.166 + 	fclose (fp);
   1.167 +
   1.168 + 	input = &ip[1];
   1.169 + 	g_filename_from_utf8_op = g_filename_from_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL);
   1.170 +	
   1.171 +	for(i = 0;i < 5;i++)
   1.172 +	{
   1.173 +		g_assert (g_filename_from_utf8_op[i] == op[i]);
   1.174 +	}
   1.175 +}	
   1.176 +
   1.177 +
   1.178 +void tg_filename_to_utf8()
   1.179 +{
   1.180 +	FILE* fp;
   1.181 +	int i = 0;
   1.182 +	gchar ip[SIZE];
   1.183 +	gchar *input;
   1.184 +	gsize bytes_read = 0;
   1.185 +    gsize bytes_written = 0;
   1.186 +    gchar *g_filename_to_utf8_op;
   1.187 +    unsigned int op[]=
   1.188 +	{
   1.189 +		0x15,0x24,0x1A,0x41,0x30
   1.190 +	};
   1.191 +	
   1.192 +    fp = fopen ("c:\\utf8_hindi.txt","r");
   1.193 + 	while ( L'\n' != (ip[i] = fgetwc (fp)))
   1.194 + 		i++;
   1.195 + 	fclose (fp);
   1.196 +
   1.197 + 	input = &ip[1];
   1.198 + 	g_filename_to_utf8_op = g_filename_to_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL);
   1.199 +	
   1.200 +	for(i = 0;i < 5;i++)
   1.201 +	{
   1.202 +		g_assert (g_filename_to_utf8_op[i] == op[i]);
   1.203 +	}
   1.204 +}
   1.205 +	
   1.206 +int main (int argc,char *argv[])
   1.207 +{
   1.208 +
   1.209 +	#ifdef SYMBIAN
   1.210 + 
   1.211 + 	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);
   1.212 + 	#endif /*SYMBIAN*/
   1.213 + 	
   1.214 +	tg_utf8_prev_char ();
   1.215 +	tg_utf8_offset_to_pointer();
   1.216 +	tg_utf8_pointer_to_offset();
   1.217 + 	tg_utf8_strncpy();
   1.218 + 	tg_utf8_strrchr();
   1.219 + 	tg_utf8_collate_key_for_filename();
   1.220 + 	tg_filename_from_utf8();
   1.221 + 	tg_filename_to_utf8();
   1.222 + 	#ifdef SYMBIAN
   1.223 +  testResultXml("tutf8");
   1.224 +#endif /* EMULATOR */
   1.225 + 	return 0;
   1.226 +}
   1.227 \ No newline at end of file