glib/tsrc/glib_nonstif/src/tutf8.c
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 02 Feb 2010 02:01:42 +0200
changeset 0 e4d67989cc36
permissions -rw-r--r--
Revision: 201002 Kit: 201005

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:   ?Description
*
*/



#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN


#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <fcntl.h>
#include <goption.h>

#ifdef __SYMBIAN32__
#include "mrt2_glib2_test.h"
#endif /*__SYMBIAN32__*/

#define SIZE	30

void tg_utf8_prev_char()
{
	FILE* fp;
	int i = 0;
	gchar ip[SIZE];
	gchar *g_utf8_prev_char_op;
	gchar *input;
	
	fp = fopen ("c:\\utf8_hindi.txt","r");
 	while ( L'\n' != (ip[i] = fgetwc (fp)))
 		i++;
 	fclose (fp);
 	input = &ip[2];
 	
 	g_utf8_prev_char_op = g_utf8_prev_char (input);
	g_assert ( g_utf8_prev_char_op[0] == 0x15);
}

void tg_utf8_offset_to_pointer()
{
 	FILE *fp;
 	int i = 0;
	gchar ip[SIZE];
	gchar *g_utf8_offset_to_pointer_op;
	gchar *input;
	
 	fp = fopen ("c:\\utf8_hindi.txt","r");
 	while ( L'\n' != (ip[i] = fgetwc (fp)))
 		i++;
 	fclose (fp);
 	
 	input = &ip[1];
	g_utf8_offset_to_pointer_op = g_utf8_offset_to_pointer (input ,6);
	g_assert ( g_utf8_offset_to_pointer_op[0] == 0x24);
}

void tg_utf8_pointer_to_offset()
{
 	FILE *fp;
 	int i = 0;
	gchar ip[SIZE];
	glong g_utf8_pointer_to_offset_op;
	gchar *input;
	gchar *feed;
	
 	fp = fopen ("c:\\utf8_hindi.txt","r");
 	while ( L'\n' != (ip[i] = fgetwc (fp)))
 		i++;
 	fclose (fp);
 	
 	input = &ip[1];
 	feed = &ip[7];
	g_utf8_pointer_to_offset_op = g_utf8_pointer_to_offset (input ,feed);
	g_assert ( g_utf8_pointer_to_offset_op == 6);
}

void tg_utf8_strncpy()
{
 	FILE* fp;
	int i = 0;
 	gchar ip[SIZE];
 	gchar feed[15];
	unsigned int op[]=
	{
		0x15,0x24,0x1A,0x41,0x30
	};
 	fp = fopen ("c:\\utf8_hindi.txt","r");
 	while ( L'\n' != (ip[i] = fgetwc (fp)))
 		i++;
 	fclose (fp);
 	
	g_utf8_strncpy (feed ,&ip[1] ,5);
	
	for(i = 0;i < 5;i++)
	{
		g_assert (feed[i] == op[i]);
	}
}

void tg_utf8_strrchr()
{
	FILE* fp;
	int i = 0;
	gchar ip[SIZE];
	gchar *input;
	gchar *g_utf8_strrchr_op;
	
 	fp = fopen ("c:\\utf8_hindi.txt","r");
 	while ( L'\n' != (ip[i] = fgetwc (fp)))
 		i++;
 	fclose (fp);
 	
 	input = &ip[1];
 	g_utf8_strrchr_op = g_utf8_strrchr (input ,-1 , 0x1A);
	g_assert (g_utf8_strrchr_op[1] == 0x41);
}

void tg_utf8_collate_key_for_filename()
{
	gchar input[] = "ptr.txt";
	gchar *g_utf8_collate_key_for_filename_op;
	g_utf8_collate_key_for_filename_op = g_utf8_collate_key_for_filename (input ,6);
	g_assert (g_utf8_collate_key_for_filename_op[0] == 'A');
}	

void tg_filename_from_utf8()
{
	FILE* fp;
	int i = 0;
	gchar ip[SIZE];
	gchar *input;
	gsize bytes_read = 0;
    gsize bytes_written = 0;
    gchar *g_filename_from_utf8_op;
    unsigned int op[]=
	{
		0x15,0x24,0x1A,0x41,0x30
	};
	
    fp = fopen ("c:\\utf8_hindi.txt","r");
 	while ( L'\n' != (ip[i] = fgetwc (fp)))
 		i++;
 	fclose (fp);

 	input = &ip[1];
 	g_filename_from_utf8_op = g_filename_from_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL);
	
	for(i = 0;i < 5;i++)
	{
		g_assert (g_filename_from_utf8_op[i] == op[i]);
	}
}	


void tg_filename_to_utf8()
{
	FILE* fp;
	int i = 0;
	gchar ip[SIZE];
	gchar *input;
	gsize bytes_read = 0;
    gsize bytes_written = 0;
    gchar *g_filename_to_utf8_op;
    unsigned int op[]=
	{
		0x15,0x24,0x1A,0x41,0x30
	};
	
    fp = fopen ("c:\\utf8_hindi.txt","r");
 	while ( L'\n' != (ip[i] = fgetwc (fp)))
 		i++;
 	fclose (fp);

 	input = &ip[1];
 	g_filename_to_utf8_op = g_filename_to_utf8 (input ,5 ,&bytes_read ,&bytes_written ,NULL);
	
	for(i = 0;i < 5;i++)
	{
		g_assert (g_filename_to_utf8_op[i] == op[i]);
	}
}
	
int main (int argc,char *argv[])
{

	#ifdef __SYMBIAN32__
 
 	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);
 	#endif /*__SYMBIAN32__*/
 	
	tg_utf8_prev_char ();
	tg_utf8_offset_to_pointer();
	tg_utf8_pointer_to_offset();
 	tg_utf8_strncpy();
 	tg_utf8_strrchr();
 	tg_utf8_collate_key_for_filename();
 	tg_filename_from_utf8();
 	tg_filename_to_utf8();
 	#ifdef __SYMBIAN32__
  testResultXml("tutf8");
#endif /* EMULATOR */
 	return 0;
}