Update contrib.
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.
25 #undef G_DISABLE_ASSERT
32 #include <glib/gprintf.h>
35 #include "mrt2_glib2_test.h"
48 garray = g_array_new (FALSE,FALSE,sizeof(gint));
50 g_array_append_val(garray,a);
51 g_array_append_val(garray,a);
52 g_array_append_val(garray,a);
54 g_array_insert_vals(garray,0,b,3);
56 g_assert (g_array_index (garray, gint, 0) == 4);
57 g_assert (g_array_index (garray, gint, 1) == 5);
58 g_assert (g_array_index (garray, gint, 2) == 6);
60 g_array_free(garray,TRUE);
64 void g_ascii_strdown_test()
68 str1 = g_ascii_strdown(str,4);
69 g_assert(str1[0] == 'a');
70 g_assert(str1[1] == 'b');
71 g_assert(str1[2] == 'c');
72 g_assert(str1[3] == 'd');
75 void g_ascii_strup_test()
79 str1 = g_ascii_strup(str,4);
80 g_assert(str1[0] == 'A');
81 g_assert(str1[1] == 'B');
82 g_assert(str1[2] == 'C');
83 g_assert(str1[3] == 'D');
89 char *teststring = "testing";
91 fp = fopen("c:\\test.txt","w");
94 g_assert(g_fprintf(fp,"%s",teststring) == strlen(teststring));
99 void g_application_name_test()
101 gchar *app_name = "Test App";
102 g_set_application_name(app_name);
103 g_assert(!strcmp(g_get_application_name(),app_name));
106 void g_listenv_test()
115 void g_direct_equal_test()
120 g_assert(g_direct_equal(i,j));
122 g_assert(!g_direct_equal(i,j));
125 void g_direct_hash_test()
131 g_assert(g_direct_hash(i) == j);
134 void g_bit_nth_lsf_test()
138 // 15 is 00000000 ........ 1111. Therefore the position of first 1 should be 0
139 g_assert(g_bit_nth_lsf(mask,-1) == 0);
142 void g_bit_nth_msf_test()
146 // 15 is 00000000 ........ 1111. Therefore the position of last 1 should be 3
147 g_assert(g_bit_nth_msf(mask,-1) == 3);
150 void g_basename_test()
152 const gchar *filename;
153 filename = g_basename("c:\\test\\test.txt");
154 g_assert(!strcmp(filename,"test.txt"));
168 void g_bit_storage_test()
170 g_assert(g_bit_storage(8) == 4);
173 void g_filename_display_basename_test()
175 g_assert(!strcmp(g_filename_display_basename("c:/test/test.txt"),"test.txt"));
178 void g_find_program_in_path_test()
180 char *program_name = g_find_program_in_path("misc_test.exe");
189 j = g_atomic_int_get(&i);
193 q = g_atomic_pointer_get(&p);
201 GError err,*err_copy = NULL;
204 err.message = "test";
205 err_copy = g_error_copy(&err);
206 g_assert(err_copy->code == 5 && err_copy->code == 5 && !strcmp(err_copy->message,"test"));
207 g_error_free(err_copy);
209 err_copy = g_error_new_literal(err.domain,err.code,"test is %s");
210 g_assert(err_copy->code == 5 && err_copy->code == 5 && !strcmp(err_copy->message,"test is %s"));
211 g_error_free(err_copy);
216 my_hash (gconstpointer key)
218 return (guint) *((const gint*) key);
222 my_hash_equal (gconstpointer a,
225 return *((const gint*) a) == *((const gint*) b);
228 static gboolean find_first (gpointer key,
233 gint *test = user_data;
234 return (*v == *test);
237 gboolean func(gpointer key,gpointer value,gpointer user_data)
239 gint *key1 = (int *)key;
240 gint *value1 = (int *)value;
241 gint *user_data1 = (int *)user_data;
242 if(*key1 == *user_data1 && *value1 == *user_data1)
250 GHashTable *hash_table;
257 hash_table = g_hash_table_new (my_hash, my_hash_equal);
258 for (i = 0; i < 10; i++)
261 g_hash_table_insert (hash_table, &array[i], &array[i]);
264 g_assert(g_hash_table_steal(hash_table,&value));
266 pvalue = g_hash_table_find (hash_table, find_first, &value);
268 //checks if g_hash_table_steal worked or not
269 g_assert(pvalue == NULL);
273 pvalue = g_hash_table_find (hash_table, find_first, &value);
275 count = g_hash_table_foreach_steal(hash_table,func,&value);
277 pvalue = g_hash_table_find (hash_table, find_first, &value);
279 g_assert(count == 1 && pvalue == NULL);
283 void check_version_test()
285 const char *x = glib_check_version(2,8,3);
293 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);
297 g_ascii_strup_test();
298 g_ascii_strdown_test();
300 g_application_name_test();
302 g_direct_equal_test();
303 g_direct_hash_test();
304 g_bit_nth_lsf_test();
305 g_bit_nth_msf_test();
308 g_bit_storage_test();
309 g_filename_display_basename_test();
310 g_find_program_in_path_test();
314 check_version_test();
317 testResultXml("misc_test");
318 #endif /* EMULATOR */