sl@0: /* GLIB - Library of useful routines for C programming
sl@0:  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
sl@0:  * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
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: 
sl@0: /*
sl@0:  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
sl@0:  * file for a list of people on the GLib Team.  See the ChangeLog
sl@0:  * files for a list of changes.  These files are distributed with
sl@0:  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
sl@0:  */
sl@0: 
sl@0: #undef G_DISABLE_ASSERT
sl@0: #undef G_LOG_DOMAIN
sl@0: 
sl@0: #include <stdio.h>
sl@0: #include <string.h>
sl@0: #include "glib.h"
sl@0: 
sl@0: #ifdef SYMBIAN
sl@0: #include "mrt2_glib2_test.h"
sl@0: #endif /*SYMBIAN*/
sl@0: 
sl@0: 
sl@0: int array[10000];
sl@0: gboolean failed = FALSE;
sl@0: 
sl@0: #define	TEST(m,cond)	G_STMT_START { failed = !(cond); \
sl@0: if (failed) \
sl@0:   { assert_failed = TRUE; \
sl@0:   	if (!m) \
sl@0:       g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
sl@0:     else \
sl@0:       g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
sl@0:   } \
sl@0: else \
sl@0:   g_print ("."); fflush (stdout); \
sl@0: } G_STMT_END
sl@0: 
sl@0: #define	C2P(c)		((gpointer) ((long) (c)))
sl@0: #define	P2C(p)		((gchar) ((long) (p)))
sl@0: 
sl@0: #define GLIB_TEST_STRING "el dorado "
sl@0: #define GLIB_TEST_STRING_5 "el do"
sl@0: 
sl@0: typedef struct {
sl@0: 	guint age;
sl@0: 	gchar name[40];
sl@0: } GlibTestInfo;
sl@0: 
sl@0: 
sl@0: 
sl@0: int
sl@0: main (int   argc,
sl@0:       char *argv[])
sl@0: {
sl@0:   gint i;
sl@0:   GRelation *relation;
sl@0:   
sl@0:   GTuples *tuples;
sl@0:   gint data [1024];
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:   g_set_print_handler(mrtPrintHandler);
sl@0:   #endif /*SYMBIAN*/
sl@0: 	  
sl@0: 
sl@0:   relation = g_relation_new (2);
sl@0: 
sl@0:   g_relation_index (relation, 0, g_int_hash, g_int_equal);
sl@0:   g_relation_index (relation, 1, g_int_hash, g_int_equal);
sl@0: 
sl@0:   for (i = 0; i < 1024; i += 1)
sl@0:     data[i] = i;
sl@0: 
sl@0:   for (i = 1; i < 1023; i += 1)
sl@0:     {
sl@0:       g_relation_insert (relation, data + i, data + i + 1);
sl@0:       g_relation_insert (relation, data + i, data + i - 1);
sl@0:     }
sl@0: 
sl@0:   for (i = 2; i < 1022; i += 1)
sl@0:     {
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i));
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i + 2));
sl@0:       g_assert (! g_relation_exists (relation, data + i, data + i - 2));
sl@0:     }
sl@0: 
sl@0:   for (i = 1; i < 1023; i += 1)
sl@0:     {
sl@0:       g_assert (g_relation_exists (relation, data + i, data + i + 1));
sl@0:       g_assert (g_relation_exists (relation, data + i, data + i - 1));
sl@0:     }
sl@0: 
sl@0:   for (i = 2; i < 1022; i += 1)
sl@0:     {
sl@0:       g_assert (g_relation_count (relation, data + i, 0) == 2);
sl@0:       g_assert (g_relation_count (relation, data + i, 1) == 2);
sl@0:     }
sl@0: 
sl@0:   g_assert (g_relation_count (relation, data, 0) == 0);
sl@0: 
sl@0:   g_assert (g_relation_count (relation, data + 42, 0) == 2);
sl@0:   g_assert (g_relation_count (relation, data + 43, 1) == 2);
sl@0:   g_assert (g_relation_count (relation, data + 41, 1) == 2);
sl@0:   g_relation_delete (relation, data + 42, 0);
sl@0:   g_assert (g_relation_count (relation, data + 42, 0) == 0);
sl@0:   g_assert (g_relation_count (relation, data + 43, 1) == 1);
sl@0:   g_assert (g_relation_count (relation, data + 41, 1) == 1);
sl@0: 
sl@0:   tuples = g_relation_select (relation, data + 200, 0);
sl@0: 
sl@0:   g_assert (tuples->len == 2);
sl@0: 
sl@0: #if 0
sl@0:   for (i = 0; i < tuples->len; i += 1)
sl@0:     {
sl@0:       printf ("%d %d\n",
sl@0: 	      *(gint*) g_tuples_index (tuples, i, 0),
sl@0: 	      *(gint*) g_tuples_index (tuples, i, 1));
sl@0:     }
sl@0: #endif
sl@0: 
sl@0:   g_assert (g_relation_exists (relation, data + 300, data + 301));
sl@0:   g_relation_delete (relation, data + 300, 0);
sl@0:   g_assert (!g_relation_exists (relation, data + 300, data + 301));
sl@0: 
sl@0:   g_tuples_destroy (tuples);
sl@0: 
sl@0:   g_relation_destroy (relation);
sl@0: 
sl@0:   relation = NULL;
sl@0: #ifdef SYMBIAN
sl@0:   testResultXml("relation-test");
sl@0: #endif /* EMULATOR */
sl@0:   return 0;
sl@0: }
sl@0: