Renamed hash,str to hashtable,string-util
authorAaron Bockover <abockover@novell.com>
Thu, 17 Aug 2006 19:33:29 +0000 (19:33 -0000)
committerAaron Bockover <abockover@novell.com>
Thu, 17 Aug 2006 19:33:29 +0000 (19:33 -0000)
svn path=/trunk/mono/; revision=63938

eglib/test/Makefile.am
eglib/test/hash.c [deleted file]
eglib/test/hashtable.c [new file with mode: 0644]
eglib/test/str.c [deleted file]
eglib/test/string-util.c [new file with mode: 0644]

index 5f544456912d072c65909af49c90427ba313ffd3..db5f73f59f8b00779ed8c19e8192dc9446f583a3 100644 (file)
@@ -1,10 +1,10 @@
 noinst_PROGRAMS = test 
 
-test_SOURCES = \
-       test.c      \
-       driver.c        \
-       hash.c          \
-       str.c           \
+test_SOURCES =    \
+       test.c        \
+       driver.c      \
+       hashtable.c       \
+       string-util.c \
        slist.c
 
 test_CFLAGS = -Wall -Werror -D_FORTIFY_SOURCE=2
diff --git a/eglib/test/hash.c b/eglib/test/hash.c
deleted file mode 100644 (file)
index 4267972..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-#include <stdio.h>
-#include <glib.h>
-#include "test.h"
-
-int foreach_count = 0;
-int foreach_fail = 0;
-
-void foreach (gpointer key, gpointer value, gpointer user_data)
-{
-       foreach_count++;
-       if (GPOINTER_TO_INT (user_data) != 'a')
-               foreach_fail = 1;
-}
-
-char *hash_t1 (void)
-{
-       GHashTable *t = g_hash_table_new (g_str_hash, g_str_equal);
-
-       g_hash_table_insert (t, "hello", "world");
-       g_hash_table_insert (t, "my", "god");
-
-       g_hash_table_foreach (t, foreach, GINT_TO_POINTER('a'));
-       if (foreach_count != 2)
-               return "did not find all keys";
-       if (foreach_fail)
-               return "failed to pass the user-data to foreach";
-       
-       if (!g_hash_table_remove (t, "my"))
-               return "did not find known key";
-       if (g_hash_table_size (t) != 1)
-               return "unexpected size";
-       g_hash_table_insert(t, "hello", "moon");
-       if (strcmp (g_hash_table_lookup (t, "hello"), "moon") != 0)
-               return "did not replace world with moon";
-               
-       if (!g_hash_table_remove (t, "hello"))
-               return "did not find known key";
-       if (g_hash_table_size (t) != 0)
-               return "unexpected size";
-       g_hash_table_destroy (t);
-
-       return NULL;
-}
-
-char *hash_t2 (void)
-{
-       return RESULT("test body not defined");
-}
-
-static Test hashtable_tests [] = {
-       {"hash_t1", hash_t1},
-       {"hash_t2", hash_t2},
-       {NULL, NULL}
-};
-
-DEFINE_TEST_GROUP_INIT(hashtable_tests_init, hashtable_tests)
-
diff --git a/eglib/test/hashtable.c b/eglib/test/hashtable.c
new file mode 100644 (file)
index 0000000..4267972
--- /dev/null
@@ -0,0 +1,57 @@
+#include <stdio.h>
+#include <glib.h>
+#include "test.h"
+
+int foreach_count = 0;
+int foreach_fail = 0;
+
+void foreach (gpointer key, gpointer value, gpointer user_data)
+{
+       foreach_count++;
+       if (GPOINTER_TO_INT (user_data) != 'a')
+               foreach_fail = 1;
+}
+
+char *hash_t1 (void)
+{
+       GHashTable *t = g_hash_table_new (g_str_hash, g_str_equal);
+
+       g_hash_table_insert (t, "hello", "world");
+       g_hash_table_insert (t, "my", "god");
+
+       g_hash_table_foreach (t, foreach, GINT_TO_POINTER('a'));
+       if (foreach_count != 2)
+               return "did not find all keys";
+       if (foreach_fail)
+               return "failed to pass the user-data to foreach";
+       
+       if (!g_hash_table_remove (t, "my"))
+               return "did not find known key";
+       if (g_hash_table_size (t) != 1)
+               return "unexpected size";
+       g_hash_table_insert(t, "hello", "moon");
+       if (strcmp (g_hash_table_lookup (t, "hello"), "moon") != 0)
+               return "did not replace world with moon";
+               
+       if (!g_hash_table_remove (t, "hello"))
+               return "did not find known key";
+       if (g_hash_table_size (t) != 0)
+               return "unexpected size";
+       g_hash_table_destroy (t);
+
+       return NULL;
+}
+
+char *hash_t2 (void)
+{
+       return RESULT("test body not defined");
+}
+
+static Test hashtable_tests [] = {
+       {"hash_t1", hash_t1},
+       {"hash_t2", hash_t2},
+       {NULL, NULL}
+};
+
+DEFINE_TEST_GROUP_INIT(hashtable_tests_init, hashtable_tests)
+
diff --git a/eglib/test/str.c b/eglib/test/str.c
deleted file mode 100644 (file)
index b4f90c4..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-#include <glib.h>
-#include <stdio.h>
-#include "test.h"
-
-/* This test is just to be used with valgrind */
-char *
-test_strfreev ()
-{
-       gchar **array = g_new (gchar *, 4);
-       array [0] = g_strdup ("one");
-       array [1] = g_strdup ("two");
-       array [2] = g_strdup ("three");
-       array [3] = NULL;
-       
-       g_strfreev (array);
-       g_strfreev (NULL);
-
-       return NULL;
-}
-
-char *
-test_concat ()
-{
-       gchar *x = g_strconcat ("Hello", ", ", "world", NULL);
-       if (strcmp (x, "Hello, world") != 0)
-               return g_strdup_printf ("concat failed, got: %s", x);
-       g_free (x);
-       return NULL;
-}
-
-#define sfail(k,p) if (s->str [p] != k) { g_string_free (s,TRUE); return g_strdup_printf ("Got %s, Failed at %d, expected '%c'", s, p, k);}
-
-char *
-test_gstring ()
-{
-       GString *s = g_string_new_len ("My stuff", 2);
-       char *ret;
-       int i;
-
-       if (strcmp (s->str, "My") != 0)
-               return RESULT("Expected only 'My' on the string");
-       g_string_free (s, TRUE);
-
-       s = g_string_new_len ("My\0\0Rest", 6);
-       if (s->str [2] != 0)
-               return RESULT("Null was not copied");
-       if (strcmp (s->str+4, "Re") != 0){
-               return RESULT("Did not find the 'Re' part");
-       }
-
-       g_string_append (s, "lalalalalalalalalalalalalalalalalalalalalalal");
-       if (s->str [2] != 0)
-               return RESULT("Null as not copied");
-       if (strncmp (s->str+4, "Relala", 6) != 0){
-               return g_strdup_printf("Did not copy correctly, got: %s", s->str+4);
-       }
-
-       g_string_free (s, TRUE);
-       s = g_string_new ("");
-       for (i = 0; i < 1024; i++){
-               g_string_append (s, "x");
-       }
-       if (strlen (s->str) != 1024){
-               return g_strdup_printf("Incorrect string size, got: %s %d", s->str, strlen (s->str));
-       }
-       g_string_free (s, TRUE);
-
-       s = g_string_new ("");
-       for (i = 0; i < 1024; i++){
-               g_string_append_c (s, 'x');
-       }
-       if (strlen (s->str) != 1024){
-               return g_strdup_printf("Incorrect string size, got: %s %d\n", s->str, strlen (s->str));
-       }
-       g_string_free (s, TRUE);
-
-       s = g_string_new ("hola");
-       g_string_sprintfa (s, "%s%d", ", bola", 5);
-       if (strcmp (s->str, "hola, bola5") != 0){
-               return g_strdup_printf("Incorrect data, got: %s\n", s->str);
-       }
-       g_string_free (s, TRUE);
-
-       s = g_string_new ("Hola");
-       g_string_printf (s, "Dingus");
-       
-       /* Test that it does not release it */
-       ret = g_string_free (s, FALSE);
-       g_free (ret);
-
-       s = g_string_new_len ("H\000H", 3);
-       g_string_append_len (s, "1\0002", 3);
-       sfail ('H', 0);
-       sfail ( 0, 1);
-       sfail ('H', 2);
-       sfail ('1', 3);
-       sfail ( 0, 4);
-       sfail ('2', 5);
-       g_string_free (s, TRUE);
-       
-       return NULL;
-}
-
-char *
-test_split ()
-{
-       gchar **v = g_strsplit("Hello world, how are we doing today?", " ", 0);
-       int i = 0;
-       
-       if(v == NULL) {
-               return RESULT("split failed, got NULL vector");
-       } else {
-               for(i = 0; v[i] != NULL; i++);
-               if(i != 7) {
-                       return g_strdup_printf("split failed, expected 7 tokens, got %d\n", i);
-               }
-       }
-       
-       g_strfreev(v);
-       return NULL;
-}
-
-char *
-test_strreverse ()
-{
-       gchar *a = g_strdup ("onetwothree");
-       gchar *a_target = "eerhtowteno";
-       gchar *b = g_strdup ("onetwothre");
-       gchar *b_target = "erhtowteno";
-
-       g_strreverse (a);
-       if (strcmp (a, a_target)) {
-               g_free (b);
-               g_free (a);
-               return g_strdup_printf ("strreverse failed. Expecting: '%s' and got '%s'\n", a, a_target);
-       }
-
-       g_strreverse (b);
-       if (strcmp (b, b_target)) {
-               g_free (b);
-               g_free (a);
-               return g_strdup_printf ("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
-       }
-       g_free (b);
-       g_free (a);
-       return NULL;
-}
-
-static Test string_tests [] = {
-       {"g_strfreev", test_strfreev},
-       {"g_strconcat", test_concat},
-       {"GString", test_gstring},
-       {"g_strsplit", test_split},
-       {"g_strreverse", test_strreverse},
-       {NULL, NULL}
-};
-
-DEFINE_TEST_GROUP_INIT(string_tests_init, string_tests)
-
diff --git a/eglib/test/string-util.c b/eglib/test/string-util.c
new file mode 100644 (file)
index 0000000..b4f90c4
--- /dev/null
@@ -0,0 +1,159 @@
+#include <glib.h>
+#include <stdio.h>
+#include "test.h"
+
+/* This test is just to be used with valgrind */
+char *
+test_strfreev ()
+{
+       gchar **array = g_new (gchar *, 4);
+       array [0] = g_strdup ("one");
+       array [1] = g_strdup ("two");
+       array [2] = g_strdup ("three");
+       array [3] = NULL;
+       
+       g_strfreev (array);
+       g_strfreev (NULL);
+
+       return NULL;
+}
+
+char *
+test_concat ()
+{
+       gchar *x = g_strconcat ("Hello", ", ", "world", NULL);
+       if (strcmp (x, "Hello, world") != 0)
+               return g_strdup_printf ("concat failed, got: %s", x);
+       g_free (x);
+       return NULL;
+}
+
+#define sfail(k,p) if (s->str [p] != k) { g_string_free (s,TRUE); return g_strdup_printf ("Got %s, Failed at %d, expected '%c'", s, p, k);}
+
+char *
+test_gstring ()
+{
+       GString *s = g_string_new_len ("My stuff", 2);
+       char *ret;
+       int i;
+
+       if (strcmp (s->str, "My") != 0)
+               return RESULT("Expected only 'My' on the string");
+       g_string_free (s, TRUE);
+
+       s = g_string_new_len ("My\0\0Rest", 6);
+       if (s->str [2] != 0)
+               return RESULT("Null was not copied");
+       if (strcmp (s->str+4, "Re") != 0){
+               return RESULT("Did not find the 'Re' part");
+       }
+
+       g_string_append (s, "lalalalalalalalalalalalalalalalalalalalalalal");
+       if (s->str [2] != 0)
+               return RESULT("Null as not copied");
+       if (strncmp (s->str+4, "Relala", 6) != 0){
+               return g_strdup_printf("Did not copy correctly, got: %s", s->str+4);
+       }
+
+       g_string_free (s, TRUE);
+       s = g_string_new ("");
+       for (i = 0; i < 1024; i++){
+               g_string_append (s, "x");
+       }
+       if (strlen (s->str) != 1024){
+               return g_strdup_printf("Incorrect string size, got: %s %d", s->str, strlen (s->str));
+       }
+       g_string_free (s, TRUE);
+
+       s = g_string_new ("");
+       for (i = 0; i < 1024; i++){
+               g_string_append_c (s, 'x');
+       }
+       if (strlen (s->str) != 1024){
+               return g_strdup_printf("Incorrect string size, got: %s %d\n", s->str, strlen (s->str));
+       }
+       g_string_free (s, TRUE);
+
+       s = g_string_new ("hola");
+       g_string_sprintfa (s, "%s%d", ", bola", 5);
+       if (strcmp (s->str, "hola, bola5") != 0){
+               return g_strdup_printf("Incorrect data, got: %s\n", s->str);
+       }
+       g_string_free (s, TRUE);
+
+       s = g_string_new ("Hola");
+       g_string_printf (s, "Dingus");
+       
+       /* Test that it does not release it */
+       ret = g_string_free (s, FALSE);
+       g_free (ret);
+
+       s = g_string_new_len ("H\000H", 3);
+       g_string_append_len (s, "1\0002", 3);
+       sfail ('H', 0);
+       sfail ( 0, 1);
+       sfail ('H', 2);
+       sfail ('1', 3);
+       sfail ( 0, 4);
+       sfail ('2', 5);
+       g_string_free (s, TRUE);
+       
+       return NULL;
+}
+
+char *
+test_split ()
+{
+       gchar **v = g_strsplit("Hello world, how are we doing today?", " ", 0);
+       int i = 0;
+       
+       if(v == NULL) {
+               return RESULT("split failed, got NULL vector");
+       } else {
+               for(i = 0; v[i] != NULL; i++);
+               if(i != 7) {
+                       return g_strdup_printf("split failed, expected 7 tokens, got %d\n", i);
+               }
+       }
+       
+       g_strfreev(v);
+       return NULL;
+}
+
+char *
+test_strreverse ()
+{
+       gchar *a = g_strdup ("onetwothree");
+       gchar *a_target = "eerhtowteno";
+       gchar *b = g_strdup ("onetwothre");
+       gchar *b_target = "erhtowteno";
+
+       g_strreverse (a);
+       if (strcmp (a, a_target)) {
+               g_free (b);
+               g_free (a);
+               return g_strdup_printf ("strreverse failed. Expecting: '%s' and got '%s'\n", a, a_target);
+       }
+
+       g_strreverse (b);
+       if (strcmp (b, b_target)) {
+               g_free (b);
+               g_free (a);
+               return g_strdup_printf ("strreverse failed. Expecting: '%s' and got '%s'\n", b, b_target);
+       }
+       g_free (b);
+       g_free (a);
+       return NULL;
+}
+
+static Test string_tests [] = {
+       {"g_strfreev", test_strfreev},
+       {"g_strconcat", test_concat},
+       {"GString", test_gstring},
+       {"g_strsplit", test_split},
+       {"g_strreverse", test_strreverse},
+       {NULL, NULL}
+};
+
+DEFINE_TEST_GROUP_INIT(string_tests_init, string_tests)
+