sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General Public sl@0: * License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: * sl@0: * Description: ?Description sl@0: * sl@0: */ sl@0: sl@0: sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef SYMBIAN sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: #define C2P(c) ((gpointer) ((long) (c))) sl@0: #define GINT_TO_POINTER(i) ((gpointer) (i)) sl@0: #define GPOINTER_TO_INT(p) ((gint) (p)) sl@0: #define TESTPASS 1 sl@0: #define TESTFAIL 0 sl@0: sl@0: //Support for gtree sl@0: static gint my_compare (gconstpointer a,gconstpointer b,gpointer data) sl@0: { sl@0: const char *cha = a; sl@0: const char *chb = b; sl@0: sl@0: return *cha - *chb; sl@0: } sl@0: sl@0: static gint my_traverse (gpointer key,gpointer value,gpointer data) sl@0: { sl@0: char *ch = key; sl@0: char *ch1 = value; sl@0: g_assert (key == value); sl@0: return FALSE; sl@0: } sl@0: sl@0: //Tests for gtree sl@0: void tg_tree_tests () sl@0: { sl@0: sl@0: GTree *tree; sl@0: char chars[62]; sl@0: char c='a'; sl@0: char err='1'; sl@0: gpointer d,op; sl@0: int i,j; sl@0: char del='c'; sl@0: char key='f'; sl@0: char val='z'; sl@0: sl@0: tree = g_tree_new_with_data (my_compare,&c); sl@0: i = 0; sl@0: for (j = 0; j < 26; j++, i++) sl@0: { sl@0: chars[i] = 'A' + j; sl@0: g_tree_insert (tree, &chars[i], &chars[i]); sl@0: } sl@0: sl@0: for (j = 0; j < 26; j++, i++) sl@0: { sl@0: chars[i] = 'a' + j; sl@0: g_tree_insert (tree, &chars[i], &chars[i]); sl@0: } sl@0: sl@0: //Test for g_tree_lookup...srch for value for 'a' sl@0: g_assert(*(gchar*)( g_tree_lookup (tree ,&c)) == 'a'); sl@0: g_assert(g_tree_lookup (tree ,&err) == NULL); sl@0: sl@0: //Test for g_tree_lookup_extended...srch for value for 'a' sl@0: g_assert( g_tree_lookup_extended(tree ,&c ,&d ,&op)); sl@0: g_assert( !g_tree_lookup_extended(tree ,&err ,&d ,&op)); sl@0: sl@0: //Test for g_tree_replace...replace f/f with f/z sl@0: g_tree_replace(tree,&key,&val); sl@0: g_assert(*(gchar*)( g_tree_lookup (tree ,&key)) == 'z'); sl@0: sl@0: //Test for g_tree_steal...remove f/z sl@0: g_assert(g_tree_steal(tree ,&key)); sl@0: sl@0: //Test for g_tree_traverse...logging occurs in the traversal function sl@0: g_tree_traverse(tree,my_traverse,G_IN_ORDER,&del); sl@0: sl@0: } sl@0: sl@0: int main (int argc,char *argv[]) sl@0: { sl@0: sl@0: #ifdef SYMBIAN sl@0: sl@0: 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: #endif /*SYMBIAN*/ sl@0: sl@0: tg_tree_tests(); sl@0: #ifdef SYMBIAN sl@0: testResultXml("ttree"); sl@0: #endif /* EMULATOR */ sl@0: return 0; sl@0: }