os/ossrv/glib/tsrc/BC/src/tutf8.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3 *
     4 * This library is free software; you can redistribute it and/or
     5 * modify it under the terms of the GNU Lesser General Public
     6 * License as published by the Free Software Foundation; either
     7 * version 2 of the License, or (at your option) any later version.
     8 *
     9 * This library is distributed in the hope that it will be useful,
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    12 * Lesser General Public License for more details.
    13 *
    14 * You should have received a copy of the GNU Lesser General Public
    15 * License along with this library; if not, write to the
    16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    17 * Boston, MA 02111-1307, USA.
    18 *
    19 * Description:  ?Description
    20 *
    21 */
    22 
    23 
    24 #undef G_DISABLE_ASSERT
    25 #undef G_LOG_DOMAIN
    26 
    27 
    28 #include <stdio.h>
    29 #include <string.h>
    30 #include <glib.h>
    31 #include <fcntl.h>
    32 #include <goption.h>
    33 #include <wchar.h>
    34 
    35 #ifdef SYMBIAN
    36 #include "mrt2_glib2_test.h"
    37 #endif /*SYMBIAN*/
    38 
    39 #define SIZE	30
    40 
    41 void tg_utf8_prev_char()
    42 {
    43 	FILE* fp;
    44 	int i = 0;
    45 	gchar ip[SIZE];
    46 	gchar *g_utf8_prev_char_op;
    47 	gchar *input;
    48 	
    49 	fp = fopen ("c:\\utf8_hindi.txt","r");
    50  	while ( L'\n' != (ip[i] = fgetwc (fp)))
    51  		i++;
    52  	fclose (fp);
    53  	input = &ip[2];
    54  	
    55  	g_utf8_prev_char_op = g_utf8_prev_char (input);
    56 	g_assert ( g_utf8_prev_char_op[0] == 0x15);
    57 }
    58 
    59 void tg_utf8_offset_to_pointer()
    60 {
    61  	FILE *fp;
    62  	int i = 0;
    63 	gchar ip[SIZE];
    64 	gchar *g_utf8_offset_to_pointer_op;
    65 	gchar *input;
    66 	
    67  	fp = fopen ("c:\\utf8_hindi.txt","r");
    68  	while ( L'\n' != (ip[i] = fgetwc (fp)))
    69  		i++;
    70  	fclose (fp);
    71  	
    72  	input = &ip[1];
    73 	g_utf8_offset_to_pointer_op = g_utf8_offset_to_pointer (input ,6);
    74 	g_assert ( g_utf8_offset_to_pointer_op[0] == 0x24);
    75 }
    76 
    77 void tg_utf8_pointer_to_offset()
    78 {
    79  	FILE *fp;
    80  	int i = 0;
    81 	gchar ip[SIZE];
    82 	glong g_utf8_pointer_to_offset_op;
    83 	gchar *input;
    84 	gchar *feed;
    85 	
    86  	fp = fopen ("c:\\utf8_hindi.txt","r");
    87  	while ( L'\n' != (ip[i] = fgetwc (fp)))
    88  		i++;
    89  	fclose (fp);
    90  	
    91  	input = &ip[1];
    92  	feed = &ip[7];
    93 	g_utf8_pointer_to_offset_op = g_utf8_pointer_to_offset (input ,feed);
    94 	g_assert ( g_utf8_pointer_to_offset_op == 6);
    95 }
    96 
    97 void tg_utf8_strncpy()
    98 {
    99  	FILE* fp;
   100 	int i = 0;
   101  	gchar ip[SIZE];
   102  	gchar feed[15];
   103 	unsigned int op[]=
   104 	{
   105 		0x15,0x24,0x1A,0x41,0x30
   106 	};
   107  	fp = fopen ("c:\\utf8_hindi.txt","r");
   108  	while ( L'\n' != (ip[i] = fgetwc (fp)))
   109  		i++;
   110  	fclose (fp);
   111  	
   112 	g_utf8_strncpy (feed ,&ip[1] ,5);
   113 	
   114 	for(i = 0;i < 5;i++)
   115 	{
   116 		g_assert (feed[i] == op[i]);
   117 	}
   118 }
   119 
   120 void tg_utf8_strrchr()
   121 {
   122 	FILE* fp;
   123 	int i = 0;
   124 	gchar ip[SIZE];
   125 	gchar *input;
   126 	gchar *g_utf8_strrchr_op;
   127 	
   128  	fp = fopen ("c:\\utf8_hindi.txt","r");
   129  	while ( L'\n' != (ip[i] = fgetwc (fp)))
   130  		i++;
   131  	fclose (fp);
   132  	
   133  	input = &ip[1];
   134  	g_utf8_strrchr_op = g_utf8_strrchr (input ,-1 , 0x1A);
   135 	g_assert (g_utf8_strrchr_op[1] == 0x41);
   136 }
   137 
   138 void tg_utf8_collate_key_for_filename()
   139 {
   140 	gchar input[] = "ptr.txt";
   141 	gchar *g_utf8_collate_key_for_filename_op;
   142 	g_utf8_collate_key_for_filename_op = g_utf8_collate_key_for_filename (input ,6);
   143 	g_assert (g_utf8_collate_key_for_filename_op[0] == 'A');
   144 }	
   145 
   146 void tg_filename_from_utf8()
   147 {
   148 	FILE* fp;
   149 	int i = 0;
   150 	gchar ip[SIZE];
   151 	gchar *input;
   152 	gsize bytes_read = 0;
   153     gsize bytes_written = 0;
   154     gchar *g_filename_from_utf8_op;
   155     unsigned int op[]=
   156 	{
   157 		0x15,0x24,0x1A,0x41,0x30
   158 	};
   159 	
   160     fp = fopen ("c:\\utf8_hindi.txt","r");
   161  	while ( L'\n' != (ip[i] = fgetwc (fp)))
   162  		i++;
   163  	fclose (fp);
   164 
   165  	input = &ip[1];
   166  	g_filename_from_utf8_op = g_filename_from_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL);
   167 	
   168 	for(i = 0;i < 5;i++)
   169 	{
   170 		g_assert (g_filename_from_utf8_op[i] == op[i]);
   171 	}
   172 }	
   173 
   174 
   175 void tg_filename_to_utf8()
   176 {
   177 	FILE* fp;
   178 	int i = 0;
   179 	gchar ip[SIZE];
   180 	gchar *input;
   181 	gsize bytes_read = 0;
   182     gsize bytes_written = 0;
   183     gchar *g_filename_to_utf8_op;
   184     unsigned int op[]=
   185 	{
   186 		0x15,0x24,0x1A,0x41,0x30
   187 	};
   188 	
   189     fp = fopen ("c:\\utf8_hindi.txt","r");
   190  	while ( L'\n' != (ip[i] = fgetwc (fp)))
   191  		i++;
   192  	fclose (fp);
   193 
   194  	input = &ip[1];
   195  	g_filename_to_utf8_op = g_filename_to_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL);
   196 	
   197 	for(i = 0;i < 5;i++)
   198 	{
   199 		g_assert (g_filename_to_utf8_op[i] == op[i]);
   200 	}
   201 }
   202 	
   203 int main (int argc,char *argv[])
   204 {
   205 
   206 	#ifdef SYMBIAN
   207  
   208  	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);
   209  	#endif /*SYMBIAN*/
   210  	
   211 	tg_utf8_prev_char ();
   212 	tg_utf8_offset_to_pointer();
   213 	tg_utf8_pointer_to_offset();
   214  	tg_utf8_strncpy();
   215  	tg_utf8_strrchr();
   216  	tg_utf8_collate_key_for_filename();
   217  	tg_filename_from_utf8();
   218  	tg_filename_to_utf8();
   219  	#ifdef SYMBIAN
   220   testResultXml("tutf8");
   221 #endif /* EMULATOR */
   222  	return 0;
   223 }