2006-08-18 Aaron Bockover <abockover@novell.com>
authorAaron Bockover <abockover@novell.com>
Fri, 18 Aug 2006 10:46:02 +0000 (10:46 -0000)
committerAaron Bockover <abockover@novell.com>
Fri, 18 Aug 2006 10:46:02 +0000 (10:46 -0000)
    * src/gptrarray.c: Implemented g_ptr_array_sort

    * test/ptrarray.c: Added sort test

    * test/driver.c: Added --help; support running N iterations and allow
    selecting which test groups to run; uses the test group table in tests.h

    * test/tests.h: Added group table

    * test/test.h:
    * test/test.c: Using a Group structure and table, removed run_groups
    as we only need run_group now

    * test/slist.h: Removed, not needed, tests/groups defined in tests.h

svn path=/trunk/mono/; revision=63983

eglib/ChangeLog
eglib/src/gptrarray.c
eglib/test/driver.c
eglib/test/ptrarray.c
eglib/test/slist.h [deleted file]
eglib/test/test.c
eglib/test/test.h
eglib/test/tests.h

index 5593912903b0d6df139561a6a948757ea93770ef..3c9665ca9ebbb451dabd1f79ff723e741afcb482 100644 (file)
@@ -1,3 +1,20 @@
+2006-08-18  Aaron Bockover  <abockover@novell.com>
+
+       * src/gptrarray.c: Implemented g_ptr_array_sort
+
+       * test/ptrarray.c: Added sort test
+       
+       * test/driver.c: Added --help; support running N iterations and allow
+       selecting which test groups to run; uses the test group table in tests.h
+       
+       * test/tests.h: Added group table
+       
+       * test/test.h:
+       * test/test.c: Using a Group structure and table, removed run_groups
+       as we only need run_group now
+
+       * test/slist.h: Removed, not needed, tests/groups defined in tests.h
+
 2006-08-18  Miguel de Icaza  <miguel@novell.com>
 
        * src/unicode.c: New file, to host unicode code, it will throw as
@@ -13,6 +30,7 @@
 
        * test/list.c: Tests for GList.
 
+>>>>>>> .r63982
 2006-08-17  Aaron Bockover  <abockover@novell.com>
 
        * src/gptrarray.c: Implemented g_ptr_array_remove and 
index 6f09e7e72b3f09ac7c4fbc03a30d15a70e2f05fe..1a5df1144f18226f96e899059e6efc927ea56b31 100644 (file)
@@ -136,8 +136,8 @@ g_ptr_array_remove_index(GPtrArray *array, guint index)
                        (array->len - index - 1) * sizeof(gpointer));
        }
        
-       array->len -= 1;
-//     array->pdata[array->len - 1] = NULL;
+       array->len--;
+       array->pdata[array->len] = NULL;
 
        return removed_node;
 }
@@ -169,3 +169,17 @@ g_ptr_array_foreach(GPtrArray *array, GFunc func, gpointer user_data)
        }
 }
 
+void
+g_ptr_array_sort(GPtrArray *array, GCompareFunc compare_func)
+{
+       g_return_if_fail(array != NULL);
+       qsort(array->pdata, array->len, sizeof(gpointer), compare_func);
+}
+
+void
+g_ptr_array_sort_with_data(GPtrArray *array, GCompareDataFunc compare_func, 
+       gpointer user_data)
+{
+}
+
+
index ce9f0815cef0a19bbf5ac1a52a2c89fe1b402cb0..784ca864c11ba612d8ea63d2e685699cb09d4a22 100644 (file)
@@ -1,19 +1,77 @@
 #include <stdio.h>
+#include <glib.h>
 
 #include "test.h"
 #include "tests.h"
 
-int main()
+static void print_help(char *s)
 {
-       run_groups(
-               "string",    strutil_tests_init,
-               "hashtable", hashtable_tests_init,
-               "slist",     slist_tests_init,
-               "list",      list_tests_init,
-               "ptrarray",  ptrarray_tests_init,
-               "gstring",   string_tests_init,
-               NULL
-       );
+       gint i;
+       
+       printf("Usage: %s [options] [iterations [test1 test2 ... testN]]\n\n", s);
+       printf(" options are:\n");
+       printf("   --help      show this help\n\n");
+       printf(" iterations:   number of times to run tests\n");
+       printf(" test1..testN  name of test to run (all run by default)\n\n");
+       printf(" available tests:\n");
+
+       for(i = 0; test_groups[i].name != NULL; i++) {
+               printf("   %s\n", test_groups[i].name);
+       }
+
+       printf("\n");
+}
+
+gint main(gint argc, gchar **argv)
+{
+       gint i, j, k, iterations = 1, tests_to_run_count = 0;
+       gchar **tests_to_run = NULL;
+       
+       if(argc > 1) {
+               for(i = 1; i < argc; i++) {
+                       if(strcmp(argv[i], "--help") == 0) {
+                               print_help(argv[0]);
+                               return 1;
+                       }
+               }
+       
+               iterations = atoi(argv[1]);
+               tests_to_run_count = argc - 2;
+
+               if(tests_to_run_count > 0) {
+                       tests_to_run = (gchar **)g_new0(gchar *, tests_to_run_count + 1);
+
+                       for(i = 0; i < tests_to_run_count; i++) {
+                               tests_to_run[i] = argv[i + 2];
+                       }
+
+                       tests_to_run[tests_to_run_count] = NULL;
+               }
+       }
+
+       for(i = 0; i < iterations; i++) {
+               for(j = 0; test_groups[j].name != NULL; j++) {
+                       gboolean run = TRUE;
+                       
+                       if(tests_to_run != NULL) {
+                               run = FALSE;
+                               for(k = 0; tests_to_run[k] != NULL; k++) {
+                                       if(strcmp(tests_to_run[k], test_groups[j].name) == 0) {
+                                               run = TRUE;
+                                               break;
+                                       }
+                               }
+                       }
+                       
+                       if(run) {
+                               run_group(&(test_groups[j]));
+                       }
+               }
+       }
+
+       if(tests_to_run != NULL) {
+               g_free(tests_to_run);
+       }
 
        return 0;
 }
index 615eb7d45a12241ceac3a4609adad95d34e93979..b7dd042a5e46f2d6100d9678c47758e5b0bdfcf0 100644 (file)
@@ -197,6 +197,37 @@ char *ptrarray_remove()
        return NULL;
 }
 
+static gint ptrarray_sort_compare(gconstpointer a, gconstpointer b)
+{
+       return strcmp(a, b);
+}
+
+char *ptrarray_sort()
+{
+       GPtrArray *array = g_ptr_array_new();
+       gint i;
+       static const gchar *letters [] = { "A", "B", "C", "D", "E" };
+       
+       g_ptr_array_add(array, "E");
+       g_ptr_array_add(array, "C");
+       g_ptr_array_add(array, "A");
+       g_ptr_array_add(array, "D");
+       g_ptr_array_add(array, "B");
+
+       g_ptr_array_sort(array, ptrarray_sort_compare);
+
+       for(i = 0; i < array->len; i++) {
+               if(strcmp((gchar *)array->pdata[i], letters[i]) != 0) {
+                       return g_strdup_printf("Array out of order, expected %s got %s", 
+                               (gchar *)array->pdata[i], letters[i]);
+               }
+       }
+
+       g_ptr_array_free(array, TRUE);
+       
+       return NULL;
+}
+
 static Test ptrarray_tests [] = {
        {"ptrarray_alloc", ptrarray_alloc},
        {"ptrarray_for_iterate", ptrarray_for_iterate},
@@ -204,6 +235,7 @@ static Test ptrarray_tests [] = {
        {"ptrarray_set_size", ptrarray_set_size},
        {"ptrarray_remove_index", ptrarray_remove_index},
        {"ptrarray_remove", ptrarray_remove},
+       {"ptrarray_sort", ptrarray_sort},
        {NULL, NULL}
 };
 
diff --git a/eglib/test/slist.h b/eglib/test/slist.h
deleted file mode 100644 (file)
index 398be8b..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#include "test.h"
-
-DEFINE_TEST_GROUP_INIT_H(slist_tests_init);
-
index 85d2bd4ba5f1ddf9b62c9ce3763d1917dc0e8946..393a4acb8ecc63ca70d689ae6bd75a8a0eefdc64 100644 (file)
@@ -19,42 +19,15 @@ run_test(Test *test)
 }
 
 void
-run_group(const char *name, LoadGroupHandler group_handler)
+run_group(Group *group)
 {
-       Test *tests = group_handler();
+       Test *tests = group->handler();
        int i;
        
-       printf("[%s]\n", name);
+       printf("[%s]\n", group->name);
 
        for(i = 0; tests[i].name != NULL; i++) {
                run_test(&(tests[i]));
        }
 }
 
-void
-run_groups(const char *first_name, LoadGroupHandler first_group_handler, ...)
-{
-       va_list args;
-       va_start(args, first_group_handler);
-
-       run_group(first_name, first_group_handler);
-       
-       while(1) {
-               const char *name;
-               LoadGroupHandler group_handler;
-
-               if((name = (const char *)va_arg(args, const char **)) == NULL) {
-                       break;
-               }
-               
-               if((group_handler = (LoadGroupHandler)va_arg(args, 
-                       LoadGroupHandler)) == NULL) {
-                       break;
-               }
-
-               run_group(name, group_handler);
-       }
-
-       va_end(args);
-}
-
index 8d69bb500568866976048a0b7bdebb79bf91f5da..3fa7f81e46a15adf2d60354c57abdc840099add9 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 
 typedef struct _Test Test;
+typedef struct _Group Group;
 
 typedef char * (* RunTestHandler)();
 typedef Test * (* LoadGroupHandler)();
@@ -13,9 +14,13 @@ struct _Test {
        RunTestHandler handler;
 };
 
+struct _Group {
+       const char *name;
+       LoadGroupHandler handler;
+};
+
 void run_test(Test *test);
-void run_group(const char *name, LoadGroupHandler group_handler);
-void run_groups(const char *first_name, LoadGroupHandler first_group_handler, ...);
+void run_group(Group *group);
 
 #define DEFINE_TEST_GROUP_INIT(name, table) \
        Test * (name)() { return table; }
index 7d03687e5ab98a21663c59de5b60543c9dbe76a1..c58cb5da920a9b7a4c3fe40839cc05ab29b4683f 100644 (file)
@@ -1,3 +1,5 @@
+#include "test.h"
+
 DEFINE_TEST_GROUP_INIT_H(string_tests_init);
 DEFINE_TEST_GROUP_INIT_H(strutil_tests_init);
 DEFINE_TEST_GROUP_INIT_H(slist_tests_init);
@@ -5,3 +7,13 @@ DEFINE_TEST_GROUP_INIT_H(list_tests_init);
 DEFINE_TEST_GROUP_INIT_H(hashtable_tests_init);
 DEFINE_TEST_GROUP_INIT_H(ptrarray_tests_init);
 
+static Group test_groups [] = {        
+       {"string",    string_tests_init}, 
+       {"strutil",   strutil_tests_init},
+       {"ptrarray",  ptrarray_tests_init},
+       {"slist",     slist_tests_init},
+       {"list",      list_tests_init},
+       {"hashtable", hashtable_tests_init},
+       {NULL, NULL}
+};
+