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