os/ossrv/glib/tsrc/BC/src/ttree.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tsrc/BC/src/ttree.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,122 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.6 +*
     1.7 +* This library is free software; you can redistribute it and/or
     1.8 +* modify it under the terms of the GNU Lesser General Public
     1.9 +* License as published by the Free Software Foundation; either
    1.10 +* version 2 of the License, or (at your option) any later version.
    1.11 +*
    1.12 +* This library is distributed in the hope that it will be useful,
    1.13 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 +* Lesser General Public License for more details.
    1.16 +*
    1.17 +* You should have received a copy of the GNU Lesser General Public
    1.18 +* License along with this library; if not, write to the
    1.19 +* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    1.20 +* Boston, MA 02111-1307, USA.
    1.21 +*
    1.22 +* Description:  ?Description
    1.23 +*
    1.24 +*/
    1.25 +
    1.26 +
    1.27 +#undef G_DISABLE_ASSERT
    1.28 +#undef G_LOG_DOMAIN
    1.29 +
    1.30 +
    1.31 +#include <stdio.h>
    1.32 +#include <string.h>
    1.33 +#include <glib.h>
    1.34 +#include <fcntl.h>
    1.35 +#include <goption.h>
    1.36 +
    1.37 +#ifdef SYMBIAN
    1.38 +#include "mrt2_glib2_test.h"
    1.39 +#endif /*SYMBIAN*/
    1.40 +
    1.41 +#define	C2P(c)		((gpointer) ((long) (c)))
    1.42 +#define GINT_TO_POINTER(i)	((gpointer)  (i))
    1.43 +#define GPOINTER_TO_INT(p)	((gint)   (p))
    1.44 +#define TESTPASS	1
    1.45 +#define TESTFAIL	0
    1.46 +
    1.47 +//Support for gtree
    1.48 +static gint my_compare (gconstpointer a,gconstpointer b,gpointer data)
    1.49 +{
    1.50 +  const char *cha = a;
    1.51 +  const char *chb = b;
    1.52 +
    1.53 +  return *cha - *chb;
    1.54 +}
    1.55 +
    1.56 +static gint my_traverse (gpointer key,gpointer value,gpointer data)
    1.57 +{
    1.58 +  char *ch = key;
    1.59 +  char *ch1 = value;
    1.60 +  g_assert (key == value);
    1.61 +  return FALSE;
    1.62 +}
    1.63 +
    1.64 +//Tests for gtree
    1.65 +void tg_tree_tests ()
    1.66 +{
    1.67 +
    1.68 +	GTree *tree;
    1.69 +	char chars[62];
    1.70 +	char c='a';
    1.71 +	char err='1';
    1.72 +	gpointer d,op;
    1.73 +	int i,j;
    1.74 +	char del='c';
    1.75 +	char key='f';
    1.76 +	char val='z';
    1.77 +		
    1.78 +  	tree = g_tree_new_with_data (my_compare,&c);
    1.79 +  	i = 0;
    1.80 +	for (j = 0; j < 26; j++, i++)
    1.81 +    {
    1.82 +      chars[i] = 'A' + j;
    1.83 +      g_tree_insert (tree, &chars[i], &chars[i]);
    1.84 +    }
    1.85 +    
    1.86 +    for (j = 0; j < 26; j++, i++)
    1.87 +    {
    1.88 +      chars[i] = 'a' + j;
    1.89 +      g_tree_insert (tree, &chars[i], &chars[i]);
    1.90 +    }
    1.91 +    
    1.92 +    //Test for g_tree_lookup...srch for value for 'a'
    1.93 +	g_assert(*(gchar*)( g_tree_lookup (tree ,&c)) == 'a');
    1.94 +	g_assert(g_tree_lookup (tree ,&err) == NULL);
    1.95 +
    1.96 +	//Test for g_tree_lookup_extended...srch for value for 'a'
    1.97 +	g_assert( g_tree_lookup_extended(tree ,&c ,&d ,&op));
    1.98 +	g_assert( !g_tree_lookup_extended(tree ,&err ,&d ,&op));
    1.99 +
   1.100 +	//Test for g_tree_replace...replace f/f with f/z
   1.101 +	g_tree_replace(tree,&key,&val);
   1.102 +	g_assert(*(gchar*)( g_tree_lookup (tree ,&key)) == 'z');
   1.103 +
   1.104 +	//Test for g_tree_steal...remove f/z
   1.105 +	g_assert(g_tree_steal(tree ,&key));
   1.106 +	
   1.107 +	//Test for g_tree_traverse...logging occurs in the traversal function
   1.108 +	g_tree_traverse(tree,my_traverse,G_IN_ORDER,&del);
   1.109 +
   1.110 +}
   1.111 +
   1.112 +int main (int argc,char *argv[])
   1.113 +{
   1.114 +
   1.115 +	#ifdef SYMBIAN
   1.116 + 
   1.117 + 	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);
   1.118 + 	#endif /*SYMBIAN*/
   1.119 + 	
   1.120 + 	tg_tree_tests();
   1.121 + #ifdef SYMBIAN
   1.122 +  testResultXml("ttree");
   1.123 +#endif /* EMULATOR */
   1.124 + 	return 0;
   1.125 +}
   1.126 \ No newline at end of file