os/ossrv/glib/tsrc/BC/src/tunichar.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 <stdlib.h>
    34 
    35 #ifdef SYMBIAN
    36 #include "mrt2_glib2_test.h"
    37 #endif /*SYMBIAN*/
    38 
    39 #define	C2P(c)		((gpointer) ((long) (c)))
    40 #define GINT_TO_POINTER(i)	((gpointer)  (i))
    41 #define GPOINTER_TO_INT(p)	((gint)   (p))
    42 #define TESTPASS	1
    43 #define TESTFAIL	0
    44 
    45 //Test for tg_unichar_type
    46 void tg_unichar_type()
    47 {
    48  	g_assert (g_unichar_type (0x41) == G_UNICODE_UPPERCASE_LETTER);
    49  	g_assert (g_unichar_type (0x63) == G_UNICODE_LOWERCASE_LETTER);
    50  	g_assert (g_unichar_type (0x30) == G_UNICODE_DECIMAL_NUMBER);
    51  	g_assert (g_unichar_type (0x2d) == G_UNICODE_DASH_PUNCTUATION);
    52  	g_assert (g_unichar_type (0x24) == G_UNICODE_CURRENCY_SYMBOL);
    53 }
    54 
    55 //Test for tg_unichar_break_type
    56 void tg_unichar_break_type()
    57 {
    58 
    59 	g_assert (g_unichar_break_type (0x0d) == G_UNICODE_BREAK_CARRIAGE_RETURN);
    60 	g_assert (g_unichar_break_type (0x0a) == G_UNICODE_BREAK_LINE_FEED);
    61 	g_assert (g_unichar_break_type (0x20) == G_UNICODE_BREAK_SPACE);
    62 	g_assert (g_unichar_break_type (0x2d) == G_UNICODE_BREAK_HYPHEN);
    63 	g_assert (g_unichar_break_type (0x21) == G_UNICODE_BREAK_EXCLAMATION);
    64 	g_assert (g_unichar_break_type (0x31) == G_UNICODE_BREAK_NUMERIC);
    65 }
    66 
    67 //Test for g_unichar_get_mirror_char
    68 void tg_unichar_get_mirror_char()
    69 {
    70 	gunichar* res = (gunichar*)malloc (sizeof (gunichar));
    71 	g_assert (g_unichar_get_mirror_char (0x28,res));
    72 	g_assert (g_unichar_get_mirror_char (0x5b,res));
    73 	g_assert (g_unichar_get_mirror_char (0x3c,res));
    74 	g_assert (!g_unichar_get_mirror_char (0x10,res));
    75  	free (res);
    76 }
    77 
    78 
    79 //Test for g_unichar_isdefined
    80 void tg_unichar_isdefined()
    81 {
    82 	g_assert (g_unichar_isdefined (0x5a)); //Valid
    83 	g_assert (!g_unichar_isdefined (0xFFFF)); //Invalid
    84 }
    85 
    86 //Test for g_unichar_istitle
    87 void tg_unichar_istitle()
    88 {
    89 	g_assert(g_unichar_istitle(0x01C5));	//LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON
    90 	g_assert(g_unichar_istitle(0x01C8));	//LATIN CAPITAL LETTER L WITH SMALL LETTER J
    91 	g_assert(g_unichar_istitle(0x01CB)); 	//LATIN CAPITAL LETTER N WITH SMALL LETTER J
    92 	g_assert(g_unichar_istitle(0x01F2)); 	//LATIN CAPITAL LETTER D WITH SMALL LETTER Z
    93 
    94 }
    95 
    96 //Test for g_unichar_iswide
    97 void tg_unichar_iswide()
    98 {
    99 	char ip1 = 'a';
   100 	wchar_t ip2 = 0x1101;
   101 	g_assert(!g_unichar_iswide(ip1));
   102 	g_assert(g_unichar_iswide(ip2));
   103 }
   104 
   105 //Test for g_unichar_totitle
   106 void tg_unichar_totitle()
   107 {
   108 	g_assert(g_unichar_totitle('A')==65);
   109 	g_assert(g_unichar_totitle('a')==65);
   110 }
   111 
   112 void tg_unicode_canonical_ordering()
   113 {
   114 	unsigned int ip[] = 
   115 	{
   116 		0x24,0x28,0x69,0x2c,0x34,0x4a,0x5d
   117 	};
   118 	g_unicode_canonical_ordering (ip ,7);
   119 }
   120 
   121 int main (int argc,char *argv[])
   122 {
   123 
   124 	#ifdef SYMBIAN
   125 
   126  	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);
   127  	#endif /*SYMBIAN*/
   128  	
   129  	tg_unichar_type();
   130 	tg_unichar_break_type();
   131 	tg_unichar_get_mirror_char();
   132 	tg_unichar_isdefined();
   133 	tg_unichar_istitle();
   134 	tg_unichar_iswide();
   135 	tg_unichar_totitle();
   136  	tg_unicode_canonical_ordering();
   137  	#ifdef SYMBIAN
   138   testResultXml("tunichar");
   139 #endif /* EMULATOR */
   140  	return 0;
   141 }