os/ossrv/glib/tsrc/BC/src/unichar_test.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
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:
    20 *
    21 */
    22 
    23 
    24 
    25 #undef G_DISABLE_ASSERT
    26 #undef G_LOG_DOMAIN
    27 
    28 #include <stdio.h>
    29 #include <string.h>
    30 #include "glib.h"
    31 #include <stdlib.h>
    32 #include <glib/gprintf.h>
    33 
    34 #ifdef SYMBIAN
    35 #include "mrt2_glib2_test.h"
    36 #endif /*SYMBIAN*/
    37 
    38 
    39 
    40 gboolean res;
    41 
    42 void g_unichar_digit_value_test()
    43 {
    44 	gunichar str='a';
    45 	gunichar dig='7';
    46 	   int i;
    47     i=g_unichar_digit_value(str);
    48     if(i!=-1)
    49 	{
    50 		g_printf("g_unichar_digit_value failed,str ='a' \n");
    51 		g_assert(FALSE && "g_unichar_digit_value failed str ='a'\n");
    52 	}
    53     
    54     i=g_unichar_digit_value(dig);
    55     if(i!=7 || i==-1)
    56 	{
    57 		g_print("g_unichar_digit_value failed,str ='7' \n");
    58 		g_assert(FALSE && "g_unichar_digit_value failed str ='7'\n");
    59 	}
    60  
    61 }
    62 
    63 void g_unichar_isalnum_test()
    64 {
    65 	gunichar str='8';
    66    	res=g_unichar_isalnum(str);
    67     if(res!=TRUE)
    68 	{
    69 		g_print("g_unichar_isalnum failed,str ='8' \n");
    70 		g_assert(FALSE && "g_unichar_isalnum failed\n");
    71 	}
    72  
    73 }
    74 
    75 void g_unichar_iscntrl_test()
    76 {
    77 	gunichar str ='\n';
    78 	res=g_unichar_iscntrl(str);
    79 	if(res!=TRUE)
    80 	{
    81 		g_print("g_unichar_iscntrl failed,str ='\n' \n");
    82 		g_assert(FALSE && "g_unichar_iscntrl failed\n");
    83 	}
    84 	//g_assert(res==TRUE);
    85 	str='a';
    86 	res=g_unichar_iscntrl(str);
    87 	if(res==TRUE)
    88 	{
    89 		g_print("g_unichar_iscntrl failed , str ='a'\n");
    90 		g_assert(FALSE && "g_unichar_iscntrl failed\n");
    91 	}
    92 	//g_assert(g_unichar_iscntrl(str)==FALSE);
    93 }
    94 
    95 
    96 
    97 void g_unichar_isdigit_test()
    98 {
    99 	gunichar str ='6';
   100 	res=g_unichar_isdigit(str);
   101 	if(res!=TRUE)
   102 	{
   103 		g_print("g_unichar_isdigit failed,str ='\n' \n");
   104 		g_assert(FALSE && "g_unichar_isdigit failed\n");
   105 	}
   106 	//g_assert(res==TRUE);
   107 	str='a';
   108 	res=g_unichar_isdigit(str);
   109 	if(res==TRUE)
   110 	{
   111 		g_print("g_unichar_iscntrl failed , str ='a'\n");
   112 		g_assert(FALSE && "g_unichar_iscntrl failed\n");
   113 	}
   114 	//g_assert(g_unichar_iscntrl(str)==FALSE);
   115 }
   116 
   117 
   118 void g_unichar_islower_test()
   119 {
   120 	gunichar str ='a';
   121 	res=g_unichar_islower(str);
   122 	if(res!=TRUE)
   123 	{
   124 		g_print("g_unichar_islower failed,str ='\n' \n");
   125 		g_assert(FALSE && "g_unichar_islower failed\n");
   126 	}
   127 	//g_assert(res==TRUE);
   128 	str='A';
   129 	res=g_unichar_islower(str);
   130 	if(res==TRUE)
   131 	{
   132 		g_print("g_unichar_islower failed , str ='a'\n");
   133 		g_assert(FALSE && "g_unichar_islower failed\n");
   134 	}
   135 }
   136 
   137 void g_unichar_ispunct_test()
   138 {
   139 	gunichar str ='!';
   140 	res=g_unichar_ispunct(str);
   141 	if(res!=TRUE)
   142 	{
   143 		g_print("g_unichar_ispunct failed,str ='\n' \n");
   144 		g_assert(FALSE && "g_unichar_ispunct failed\n");
   145 	}
   146 	//g_assert(res==TRUE);
   147 	str='A';
   148 	res=g_unichar_ispunct(str);
   149 	if(res==TRUE)
   150 	{
   151 		g_print("g_unichar_ispunct failed , str ='a'\n");
   152 		g_assert(FALSE && "g_unichar_ispunct failed\n");
   153 	}
   154 }
   155 
   156 
   157 void g_unichar_isupper_test()
   158 {
   159 	gunichar str ='A';
   160 	res=g_unichar_isupper(str);
   161 	if(res!=TRUE)
   162 	{
   163 		g_print("g_unichar_isupper failed '\n' \n");
   164 		g_assert(FALSE && "g_unichar_isupper failed\n");
   165 	}
   166 	//g_assert(res==TRUE);
   167 	str='a';
   168 	res=g_unichar_isupper(str);
   169 	if(res==TRUE)
   170 	{
   171 		g_print("g_unichar_isupper failed \n");
   172 		g_assert(FALSE && "g_unichar_isupper failed\n");
   173 	}
   174 }
   175 
   176 void g_unichar_isxdigit_test()
   177 {
   178 	gunichar str ='e';
   179 	res=g_unichar_isxdigit(str);
   180 	if(res!=TRUE)
   181 	{
   182 		g_print("g_unichar_isxdigit failed '\n' \n");
   183 		g_assert(FALSE && "g_unichar_isxdigit failed\n");
   184 	}
   185 	//g_assert(res==TRUE);
   186 	str='k';
   187 	res=g_unichar_isxdigit(str);
   188 	if(res==TRUE)
   189 	{
   190 		g_print("g_unichar_isxdigit failed \n");
   191 		g_assert(FALSE && "g_unichar_isxdigit failed\n");
   192 	}
   193 }
   194 
   195 void g_unichar_xdigit_value_test()
   196 {
   197 	int i;
   198 	gunichar str ='e';
   199     i=g_unichar_xdigit_value(str);
   200 	if(i!=14 || i==-1)
   201 	{
   202 		g_print("g_unichar_xdigit_value failed  \n");
   203 		g_assert(FALSE && "g_unichar_xdigit_value failed\n");
   204 	}
   205 	
   206 	str='4';
   207 	i=g_unichar_xdigit_value(str);
   208 	if(i!=4 || i==-1)
   209 	{
   210 		g_print("g_unichar_xdigit_value failed  \n");
   211 		g_assert(FALSE && "g_unichar_xdigit_value failed\n");
   212 	}
   213 	
   214 	
   215 	//g_assert(res==TRUE);
   216 	str='k';
   217 	i=g_unichar_xdigit_value(str);
   218 	if(i!=-1)
   219 	{
   220 		g_print("g_unichar_xdigit_value failed \n");
   221 		g_assert(FALSE && "g_unichar_xdigit_value failed\n");
   222 	}
   223 }
   224 
   225 
   226 void g_unichar_isgraph_test()
   227 {
   228 	gunichar str ='e';
   229     res=g_unichar_isgraph(str);
   230 	if(res!=TRUE)
   231 	{
   232 		g_print("g_unichar_isgraph failed '\n' \n");
   233 		g_assert(FALSE && "g_unichar_isgraph failed\n");
   234 	}
   235 	//g_assert(res==TRUE);
   236 	str=' ';
   237 	res=g_unichar_isgraph(str);
   238 	if(res==TRUE)
   239 	{
   240 		g_print("g_unichar_isgraph failed \n");
   241 		g_assert(FALSE && "g_unichar_isgraph failed\n");
   242 	}
   243 }
   244 
   245 void g_unichar_isspace_test()
   246 {
   247 	gunichar str ='\t';
   248     res=g_unichar_isspace(str);
   249 	if(res!=TRUE)
   250 	{
   251 		g_print("g_unichar_isspace failed '\n' \n");
   252 		g_assert(FALSE && "g_unichar_isspace failed\n");
   253 	}
   254 	//g_assert(res==TRUE);
   255 	str='5';
   256 	res=g_unichar_isspace(str);
   257 	if(res==TRUE)
   258 	{
   259 		g_print("g_unichar_isspace failed \n");
   260 		g_assert(FALSE && "g_unichar_isspace failed\n");
   261 	}
   262 }
   263 
   264 void g_unichar_isprint_test()
   265 {
   266 	gunichar str1=' ';
   267 	gboolean res1;
   268 	gunichar str2='a';
   269 	res=g_unichar_isprint(str1);
   270 	res1=g_unichar_isprint(str2);
   271 	if(res!=TRUE || res1!=TRUE)
   272 	{
   273 		g_print("g_unichar_isprint failed\n");
   274 		g_assert(FALSE && "g_unichar_isprint failed\n");
   275 	}
   276 	str1='\t';
   277 	res=g_unichar_isprint(str1);
   278 	if (res==TRUE)
   279 	{
   280 	    g_print("g_unichar_isprint failed\n");
   281 		g_assert(FALSE && "g_unichar_isprint failed\n");
   282 		
   283 	}
   284 
   285 }
   286 
   287 
   288 int main (int   argc,
   289       char *argv[])
   290 {
   291 	#ifdef SYMBIAN
   292 	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);
   293 	#endif /*SYMBIAN*/
   294 	
   295 	g_unichar_digit_value_test();
   296 	g_unichar_isalnum_test();
   297 	g_unichar_iscntrl_test();
   298 	g_unichar_islower_test();
   299 	g_unichar_isupper_test();
   300 	g_unichar_isxdigit_test();	
   301 	g_unichar_xdigit_value_test();
   302 	g_unichar_isgraph_test();
   303 	g_unichar_ispunct_test();
   304 	g_unichar_isspace_test();
   305 	g_unichar_isdigit_test();
   306 	g_unichar_isprint_test();
   307 
   308 
   309 	#ifdef SYMBIAN
   310   	testResultXml("unichar_test");
   311   	#endif /* EMULATOR */
   312 	
   313 	return 0;
   314 }