sl@0: /*
sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0: *
sl@0: * This library is free software; you can redistribute it and/or
sl@0: * modify it under the terms of the GNU Lesser General Public
sl@0: * License as published by the Free Software Foundation; either
sl@0: * version 2 of the License, or (at your option) any later version.
sl@0: *
sl@0: * This library is distributed in the hope that it will be useful,
sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
sl@0: * Lesser General Public License for more details.
sl@0: *
sl@0: * You should have received a copy of the GNU Lesser General Public
sl@0: * License along with this library; if not, write to the
sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
sl@0: * Boston, MA 02111-1307, USA.
sl@0: *
sl@0: * Description:  ?Description
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: #undef G_DISABLE_ASSERT
sl@0: #undef G_LOG_DOMAIN
sl@0: 
sl@0: 
sl@0: #include <stdio.h>
sl@0: #include <string.h>
sl@0: #include <glib.h>
sl@0: #include <fcntl.h>
sl@0: #include <goption.h>
sl@0: #include <wchar.h>
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0: #include "mrt2_glib2_test.h"
sl@0: #endif /*SYMBIAN*/
sl@0: 
sl@0: #define SIZE	30
sl@0: 
sl@0: void tg_utf8_prev_char()
sl@0: {
sl@0: 	FILE* fp;
sl@0: 	int i = 0;
sl@0: 	gchar ip[SIZE];
sl@0: 	gchar *g_utf8_prev_char_op;
sl@0: 	gchar *input;
sl@0: 	
sl@0: 	fp = fopen ("c:\\utf8_hindi.txt","r");
sl@0:  	while ( L'\n' != (ip[i] = fgetwc (fp)))
sl@0:  		i++;
sl@0:  	fclose (fp);
sl@0:  	input = &ip[2];
sl@0:  	
sl@0:  	g_utf8_prev_char_op = g_utf8_prev_char (input);
sl@0: 	g_assert ( g_utf8_prev_char_op[0] == 0x15);
sl@0: }
sl@0: 
sl@0: void tg_utf8_offset_to_pointer()
sl@0: {
sl@0:  	FILE *fp;
sl@0:  	int i = 0;
sl@0: 	gchar ip[SIZE];
sl@0: 	gchar *g_utf8_offset_to_pointer_op;
sl@0: 	gchar *input;
sl@0: 	
sl@0:  	fp = fopen ("c:\\utf8_hindi.txt","r");
sl@0:  	while ( L'\n' != (ip[i] = fgetwc (fp)))
sl@0:  		i++;
sl@0:  	fclose (fp);
sl@0:  	
sl@0:  	input = &ip[1];
sl@0: 	g_utf8_offset_to_pointer_op = g_utf8_offset_to_pointer (input ,6);
sl@0: 	g_assert ( g_utf8_offset_to_pointer_op[0] == 0x24);
sl@0: }
sl@0: 
sl@0: void tg_utf8_pointer_to_offset()
sl@0: {
sl@0:  	FILE *fp;
sl@0:  	int i = 0;
sl@0: 	gchar ip[SIZE];
sl@0: 	glong g_utf8_pointer_to_offset_op;
sl@0: 	gchar *input;
sl@0: 	gchar *feed;
sl@0: 	
sl@0:  	fp = fopen ("c:\\utf8_hindi.txt","r");
sl@0:  	while ( L'\n' != (ip[i] = fgetwc (fp)))
sl@0:  		i++;
sl@0:  	fclose (fp);
sl@0:  	
sl@0:  	input = &ip[1];
sl@0:  	feed = &ip[7];
sl@0: 	g_utf8_pointer_to_offset_op = g_utf8_pointer_to_offset (input ,feed);
sl@0: 	g_assert ( g_utf8_pointer_to_offset_op == 6);
sl@0: }
sl@0: 
sl@0: void tg_utf8_strncpy()
sl@0: {
sl@0:  	FILE* fp;
sl@0: 	int i = 0;
sl@0:  	gchar ip[SIZE];
sl@0:  	gchar feed[15];
sl@0: 	unsigned int op[]=
sl@0: 	{
sl@0: 		0x15,0x24,0x1A,0x41,0x30
sl@0: 	};
sl@0:  	fp = fopen ("c:\\utf8_hindi.txt","r");
sl@0:  	while ( L'\n' != (ip[i] = fgetwc (fp)))
sl@0:  		i++;
sl@0:  	fclose (fp);
sl@0:  	
sl@0: 	g_utf8_strncpy (feed ,&ip[1] ,5);
sl@0: 	
sl@0: 	for(i = 0;i < 5;i++)
sl@0: 	{
sl@0: 		g_assert (feed[i] == op[i]);
sl@0: 	}
sl@0: }
sl@0: 
sl@0: void tg_utf8_strrchr()
sl@0: {
sl@0: 	FILE* fp;
sl@0: 	int i = 0;
sl@0: 	gchar ip[SIZE];
sl@0: 	gchar *input;
sl@0: 	gchar *g_utf8_strrchr_op;
sl@0: 	
sl@0:  	fp = fopen ("c:\\utf8_hindi.txt","r");
sl@0:  	while ( L'\n' != (ip[i] = fgetwc (fp)))
sl@0:  		i++;
sl@0:  	fclose (fp);
sl@0:  	
sl@0:  	input = &ip[1];
sl@0:  	g_utf8_strrchr_op = g_utf8_strrchr (input ,-1 , 0x1A);
sl@0: 	g_assert (g_utf8_strrchr_op[1] == 0x41);
sl@0: }
sl@0: 
sl@0: void tg_utf8_collate_key_for_filename()
sl@0: {
sl@0: 	gchar input[] = "ptr.txt";
sl@0: 	gchar *g_utf8_collate_key_for_filename_op;
sl@0: 	g_utf8_collate_key_for_filename_op = g_utf8_collate_key_for_filename (input ,6);
sl@0: 	g_assert (g_utf8_collate_key_for_filename_op[0] == 'A');
sl@0: }	
sl@0: 
sl@0: void tg_filename_from_utf8()
sl@0: {
sl@0: 	FILE* fp;
sl@0: 	int i = 0;
sl@0: 	gchar ip[SIZE];
sl@0: 	gchar *input;
sl@0: 	gsize bytes_read = 0;
sl@0:     gsize bytes_written = 0;
sl@0:     gchar *g_filename_from_utf8_op;
sl@0:     unsigned int op[]=
sl@0: 	{
sl@0: 		0x15,0x24,0x1A,0x41,0x30
sl@0: 	};
sl@0: 	
sl@0:     fp = fopen ("c:\\utf8_hindi.txt","r");
sl@0:  	while ( L'\n' != (ip[i] = fgetwc (fp)))
sl@0:  		i++;
sl@0:  	fclose (fp);
sl@0: 
sl@0:  	input = &ip[1];
sl@0:  	g_filename_from_utf8_op = g_filename_from_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL);
sl@0: 	
sl@0: 	for(i = 0;i < 5;i++)
sl@0: 	{
sl@0: 		g_assert (g_filename_from_utf8_op[i] == op[i]);
sl@0: 	}
sl@0: }	
sl@0: 
sl@0: 
sl@0: void tg_filename_to_utf8()
sl@0: {
sl@0: 	FILE* fp;
sl@0: 	int i = 0;
sl@0: 	gchar ip[SIZE];
sl@0: 	gchar *input;
sl@0: 	gsize bytes_read = 0;
sl@0:     gsize bytes_written = 0;
sl@0:     gchar *g_filename_to_utf8_op;
sl@0:     unsigned int op[]=
sl@0: 	{
sl@0: 		0x15,0x24,0x1A,0x41,0x30
sl@0: 	};
sl@0: 	
sl@0:     fp = fopen ("c:\\utf8_hindi.txt","r");
sl@0:  	while ( L'\n' != (ip[i] = fgetwc (fp)))
sl@0:  		i++;
sl@0:  	fclose (fp);
sl@0: 
sl@0:  	input = &ip[1];
sl@0:  	g_filename_to_utf8_op = g_filename_to_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL);
sl@0: 	
sl@0: 	for(i = 0;i < 5;i++)
sl@0: 	{
sl@0: 		g_assert (g_filename_to_utf8_op[i] == op[i]);
sl@0: 	}
sl@0: }
sl@0: 	
sl@0: int main (int argc,char *argv[])
sl@0: {
sl@0: 
sl@0: 	#ifdef SYMBIAN
sl@0:  
sl@0:  	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:  	#endif /*SYMBIAN*/
sl@0:  	
sl@0: 	tg_utf8_prev_char ();
sl@0: 	tg_utf8_offset_to_pointer();
sl@0: 	tg_utf8_pointer_to_offset();
sl@0:  	tg_utf8_strncpy();
sl@0:  	tg_utf8_strrchr();
sl@0:  	tg_utf8_collate_key_for_filename();
sl@0:  	tg_filename_from_utf8();
sl@0:  	tg_filename_to_utf8();
sl@0:  	#ifdef SYMBIAN
sl@0:   testResultXml("tutf8");
sl@0: #endif /* EMULATOR */
sl@0:  	return 0;
sl@0: }