summaryrefslogtreecommitdiff
path: root/testglib.c
diff options
context:
space:
mode:
authorJosh MacDonald <jmacd@icw.EECS.Berkeley.EDU>1998-06-12 09:38:32 +0000
committerManish Singh <yosh@src.gnome.org>1998-06-12 09:38:32 +0000
commitdf9a49ec3cbb19e58be929548cfba12452c55d83 (patch)
treedaae20dab8506a7890a24b2657c7217d1b769401 /testglib.c
parentf62aace5b0706da62eef4be9052cb71608d97fef (diff)
[Changes from josh to sync with his glib stuff -Yosh]
Fri Jun 12 00:39:28 1998 Josh MacDonald <jmacd@icw.EECS.Berkeley.EDU> * glib.h: add new hash and equal functions g_int_*. complement g_direct_hash with g_direct_equal. * grel.c: new file, GRelations implement tuples of N-N mappings. A comment in glib.h briefly describes the interface. * ghash.c: new function, g_hash_table_size * glib.h: new typedefs, gsize, gssize, gtime. * garray.c: new functions implementing a simplified GArray. This GPtrArray is an array of gpointers and has functions to add and remove elements, much like java.lang.Vector. * garray.c: new functions for the single-byte special case of GArray. The functions g_byte_array* operate on arrays of bytes. Internally, a GArray is used. * testglib.c: tests for g_ptr_array, g_byte_array, and g_relation...
Diffstat (limited to 'testglib.c')
-rw-r--r--testglib.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/testglib.c b/testglib.c
index e96dfb570..45d58dc99 100644
--- a/testglib.c
+++ b/testglib.c
@@ -104,9 +104,14 @@ main (int argc,
gchar *mem[10000], *tmp_string, *tmp_string_2;
gint i, j;
GArray *garray;
+ GPtrArray *gparray;
+ GByteArray *gbarray;
GString *string1, *string2;
GTree *tree;
char chars[62];
+ GRelation *relation;
+ GTuples *tuples;
+ gint data [1024];
g_print ("checking size of gint8...%ld (should be 1)\n", (glong)sizeof (gint8));
g_print ("checking size of gint16...%ld (should be 2)\n", (glong)sizeof (gint16));
@@ -396,6 +401,110 @@ main (int argc,
/* g_debug (argv[0]); */
+ /* Relation tests */
+
+ g_print ("checking relations...");
+
+ relation = g_relation_new (2);
+
+ g_relation_index (relation, 0, g_int_hash, g_int_equal);
+ g_relation_index (relation, 1, g_int_hash, g_int_equal);
+
+ for (i = 0; i < 1024; i += 1)
+ data[i] = i;
+
+ for (i = 1; i < 1023; i += 1)
+ {
+ g_relation_insert (relation, data + i, data + i + 1);
+ g_relation_insert (relation, data + i, data + i - 1);
+ }
+
+ for (i = 2; i < 1022; i += 1)
+ {
+ g_assert (! g_relation_exists (relation, data + i, data + i));
+ g_assert (! g_relation_exists (relation, data + i, data + i + 2));
+ g_assert (! g_relation_exists (relation, data + i, data + i - 2));
+ }
+
+ for (i = 1; i < 1023; i += 1)
+ {
+ g_assert (g_relation_exists (relation, data + i, data + i + 1));
+ g_assert (g_relation_exists (relation, data + i, data + i - 1));
+ }
+
+ for (i = 2; i < 1022; i += 1)
+ {
+ g_assert (g_relation_count (relation, data + i, 0) == 2);
+ g_assert (g_relation_count (relation, data + i, 1) == 2);
+ }
+
+ g_assert (g_relation_count (relation, data, 0) == 0);
+
+ g_assert (g_relation_count (relation, data + 42, 0) == 2);
+ g_assert (g_relation_count (relation, data + 43, 1) == 2);
+ g_assert (g_relation_count (relation, data + 41, 1) == 2);
+ g_relation_delete (relation, data + 42, 0);
+ g_assert (g_relation_count (relation, data + 42, 0) == 0);
+ g_assert (g_relation_count (relation, data + 43, 1) == 1);
+ g_assert (g_relation_count (relation, data + 41, 1) == 1);
+
+ tuples = g_relation_select (relation, data + 200, 0);
+
+ g_assert (tuples->len == 2);
+
+#if 0
+ for (i = 0; i < tuples->len; i += 1)
+ {
+ printf ("%d %d\n",
+ *(gint*) g_tuples_index (tuples, i, 0),
+ *(gint*) g_tuples_index (tuples, i, 1));
+ }
+#endif
+
+ g_assert (g_relation_exists (relation, data + 300, data + 301));
+ g_relation_delete (relation, data + 300, 0);
+ g_assert (!g_relation_exists (relation, data + 300, data + 301));
+
+ g_tuples_destroy (tuples);
+
+ g_relation_destroy (relation);
+
+ relation = NULL;
+
+ g_print ("ok\n");
+
+ g_print ("checking pointer arrays...");
+
+ gparray = g_ptr_array_new ();
+ for (i = 0; i < 10000; i++)
+ g_ptr_array_add (gparray, (void*)i);
+
+ for (i = 0; i < 10000; i++)
+ if (g_ptr_array_index (gparray, i) != (void*)i)
+ g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), (void*)i);
+
+ g_ptr_array_free (gparray, TRUE);
+
+ g_print ("ok\n");
+
+
+ g_print ("checking byte arrays...");
+
+ gbarray = g_byte_array_new ();
+ for (i = 0; i < 10000; i++)
+ g_byte_array_append (gbarray, "abcd", 4);
+
+ for (i = 0; i < 10000; i++)
+ {
+ g_assert (gbarray->data[4*i] == 'a');
+ g_assert (gbarray->data[4*i+1] == 'b');
+ g_assert (gbarray->data[4*i+2] == 'c');
+ g_assert (gbarray->data[4*i+3] == 'd');
+ }
+
+ g_byte_array_free (gbarray, TRUE);
+
+ g_print ("ok\n");
return 0;
}