First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
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.
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.
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.
19 * Description: ?Description
24 #undef G_DISABLE_ASSERT
33 #include <glib/gprintf.h>
37 #include "mrt2_glib2_test.h"
40 #define C2P(c) ((gpointer) ((long) (c)))
41 #define GINT_TO_POINTER(i) ((gpointer) (i))
42 #define GPOINTER_TO_INT(p) ((gint) (p))
50 gchar string1[]="aabbccdd";
51 gchar string2[]="aabbccdd";
56 //Testing for a valid char available in the string
57 //The invalid chars must be replaced
59 teststring1=g_strcanon (string1, valid, 'x');
60 g_assert(!strcmp(teststring1,"xxxxccxx"));
62 //Testing for a valid char not-available in the string
63 //All the chars must be replaced
65 teststring2=g_strcanon(string2,valid,'x');
66 g_assert(!strcmp(teststring2,"xxxxxxxx"));
69 //Test for g_strcasecmp
72 gint strcasecmp_eq,strcasecmp_gr8,strcasecmp_less;
73 //Testing for equal strings,zero must be returned
74 strcasecmp_eq=g_strcasecmp ("abcd123","abcd123");
75 g_assert(strcasecmp_eq==0);
77 //Testing for un-equal strings,left greater,positive value must be returned
78 strcasecmp_gr8=g_strcasecmp ("abcd123","abcd");
79 g_assert(strcasecmp_gr8>0);
81 //Testing for un-equal strings,right greater,negative value must be returned
82 strcasecmp_less=g_strcasecmp ("abcd","abcd123");
83 g_assert(strcasecmp_less<0);
90 gchar input[]="ABCDef";
91 gchar* upperToLower=g_strdown(input);
92 g_assert(!strcmp(upperToLower,"abcdef"));
95 //Test for g_string_append_c
96 void tg_string_append_c()
98 GString* obj=(GString*)malloc(sizeof(GString));
102 obj->allocated_len=10;
103 obj=g_string_append_c(obj,'e');
104 g_assert(!strcmp((obj->str),"abcde"));
107 //Test for g_string_ascii_down
108 void tg_string_ascii_down()
110 GString* obj=(GString*)malloc(sizeof(GString));
111 gchar ip[]="ABc12DeF";
114 obj->allocated_len=10;
115 obj=g_string_ascii_down(obj);
116 g_assert(!strcmp((obj->str),"abc12def"));
119 //Test for g_string_ascii_up
120 void tg_string_ascii_up()
122 GString* obj=(GString*)malloc(sizeof(GString));
123 gchar ip[]="ABc12DeF";
126 obj->allocated_len=10;
127 obj=g_string_ascii_up(obj);
128 g_assert(!strcmp((obj->str),"ABC12DEF"));
131 //Test for g_string_down
132 void tg_string_down()
134 GString* obj=(GString*)malloc(sizeof(GString));
135 gchar ip[]="ABc12DeF";
138 obj->allocated_len=10;
139 obj=g_string_down(obj);
140 g_assert(!strcmp((obj->str),"abc12def"));
143 //Test for g_string_hash
144 void tg_string_hash()
146 GString* obj=(GString*)malloc(sizeof(GString));
147 guint g_string_hash_result1,g_string_hash_result2;
148 guint g_string_hash_result3,g_string_hash_result4;
151 obj->allocated_len=10;
154 obj->len=strlen(ip1);
155 g_string_hash_result1=g_string_hash(obj);
156 g_string_hash_result2=g_string_hash(obj);
157 g_assert(g_string_hash_result1==g_string_hash_result2);
160 obj->len=strlen(ip2);
161 g_string_hash_result3=g_string_hash(obj);
162 g_string_hash_result4=g_string_hash(obj);
163 g_assert(g_string_hash_result3==g_string_hash_result4);
165 g_assert(g_string_hash_result1 != g_string_hash_result3);
170 //Test for g_string_prepend_c
171 void tg_string_prepend_c()
173 GString* obj=(GString*)malloc(sizeof(GString));
177 obj->allocated_len=10;
178 obj=g_string_prepend_c(obj,'e');
179 g_assert(!strcmp((obj->str),"eabcd"));
183 //Test for g_string_up
186 GString* obj=(GString*)malloc(sizeof(GString));
187 gchar ip[]="ABc12DeF";
190 obj->allocated_len=10;
191 obj=g_string_up(obj);
192 g_assert(!strcmp((obj->str),"ABC12DEF"));
196 //Test for g_string_prepend_unichar
197 void tg_string_prepend_unichar()
199 GString* obj=(GString*)malloc(sizeof(GString));
203 obj->allocated_len=10;
204 obj=g_string_prepend_unichar(obj,'e');
205 g_assert(!strcmp((obj->str),"eabcd"));
208 //Test for g_strip_context
209 void tg_strip_context()
211 gchar msgid[]="abc|defgh";
212 gchar msgval[]="abc|defgh";
214 op=g_strip_context(msgid,msgid);
215 g_assert(!strcmp(op,"defgh"));
224 gchar* op=g_strjoin(sep,a,b,NULL);
225 g_assert(!strcmp(op,"abc#&#def"));
229 //Test for g_strncasecmp
230 void tg_strncasecmp()
232 gint strncasecmp_eq,strncasecmp_gr8,strncasecmp_less;
233 //Testing for equal strings,zero must be returned
234 strncasecmp_eq=g_strncasecmp ("abcd123","abcd123",10);
235 g_assert(strncasecmp_eq==0);
237 //Testing for un-equal strings,left greater,positive value must be returned
238 strncasecmp_gr8=g_strncasecmp ("abcd123","abcd",4);
239 g_assert(strncasecmp_gr8==0);
241 //Testing for un-equal strings,right greater,negative value must be returned
242 strncasecmp_less=g_strncasecmp ("abcd","abcd123",6);
243 g_assert(strncasecmp_less<0);
248 //Test for g_strnfill
253 gchar* strnfill_buf_null;
254 gchar* strnfill_buf=g_strnfill(size,fill);
255 g_assert(!strcmp(strnfill_buf,"xxxxxxxxxx"));
258 strnfill_buf_null=g_strnfill(size,fill);
259 g_assert(!strcmp(strnfill_buf_null,""));
263 //Test for g_strreverse
266 gchar ip[]="abCdeF123";
267 gchar* strreverse_op=g_strreverse(ip);
268 g_assert(!strcmp(strreverse_op,"321FedCba"));
276 gchar ip[]="Abc12deF";
277 gchar* strup=g_strup(ip);
278 g_assert(!strcmp(strup,"ABC12DEF"));
282 //Test for g_pattern_match_string
283 void tg_pattern_match_string()
285 gchar pattern_str[]="abcdefghijklmnopqrstuvwxyz";
286 gchar match_str_pos[]="abcdefghijklmnopqrstuvwxyz"; //Proper a-z
287 gchar match_str_neg[]="abcdefghjiklmnopqrstuvwxyz"; //i and j interchanged
289 GPatternSpec* spec=g_pattern_spec_new(pattern_str);
290 g_assert(g_pattern_match_string(spec,match_str_pos));
291 g_assert(!g_pattern_match_string(spec,match_str_neg));
295 //Called by g_printf_string_upper_bound for a va-list
296 void test_arg_string_upper_bound(gchar* fmt,...)
300 g_assert(g_printf_string_upper_bound(fmt,ap)==27);
303 //Test for g_printf_string_upper_bound
304 void tg_printf_string_upper_bound()
306 test_arg_string_upper_bound("%d\n%s\t%f",9999999,"Abcd#%@",999.999999);
313 gchar sprintf_converted[100];
314 gint sprintf_return_val=g_sprintf(sprintf_converted,"%d%s%f",9999999,"Abcd#%@",999.999999);
315 g_assert(sprintf_return_val==24);
320 int main (int argc,char *argv[])
324 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);
330 tg_string_append_c();
331 tg_string_ascii_down();
332 tg_string_ascii_up();
335 tg_string_prepend_c();
336 tg_string_prepend_unichar();
344 tg_pattern_match_string();
345 tg_printf_string_upper_bound();
349 testResultXml("tgstring");
350 #endif /* EMULATOR */