[msvc] Update csproj files
[mono.git] / eglib / test / driver.c
index e53c7b2bf69be12c778593ae704204e89b76b798..806e8b66d3f2387f45078ae70af458bf19fca5a1 100644 (file)
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-#include <stdio.h>
-#include <glib.h>
-#include <getopt.h>
 
+#include <config.h>
 #include "test.h"
+
+#ifndef DRIVER_EXTERNAL_TESTS
 #include "tests.h"
+#endif
+
+#include <stdio.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+
+#ifndef DRIVER_NAME
+#define DRIVER_NAME "EGlib"
+#endif
 
 typedef struct _StringArray {
        gchar **strings;
@@ -57,6 +70,8 @@ string_array_append(StringArray *array, gchar *string)
        return array;
 }
 
+gint global_passed = 0, global_tests = 0;
+
 static void
 string_array_free(StringArray *array)
 {
@@ -90,7 +105,11 @@ static void print_help(char *s)
        printf("\n");
 }
 
+#ifdef DRIVER_EXTERNAL_MAIN
+gint run_tests_main(gint argc, gchar **argv)
+#else
 gint main(gint argc, gchar **argv)
+#endif
 {
        gint i, j, c, iterations = 1;
        StringArray *tests_to_run = NULL;
@@ -100,7 +119,8 @@ gint main(gint argc, gchar **argv)
        gboolean global_failure = FALSE;
        gboolean no_final_time_labels = FALSE;
        gboolean debug = FALSE;
-       
+
+#if HAVE_GETOPT_H
        static struct option long_options [] = {
                {"help",       no_argument,       0, 'h'},
                {"time",       no_argument,       0, 't'},
@@ -140,6 +160,7 @@ gint main(gint argc, gchar **argv)
 
                tests_to_run = string_array_append(tests_to_run, argv[i]);
        }
+#endif
 
        time_start = get_timestamp();
        
@@ -155,8 +176,8 @@ gint main(gint argc, gchar **argv)
                        for(k = 0; k < tests_to_run->length; k++) {     
                                gchar *user = tests_to_run->strings[k];
                                const gchar *table = test_groups[j].name;
-                               gint user_len = strlen(user);
-                               gint table_len = strlen(table);
+                               size_t user_len = strlen(user);
+                               size_t table_len = strlen(table);
                                
                                if(strncmp(user, table, table_len) == 0) {
                                        if(user_len > table_len && user[table_len] != ':') {
@@ -171,6 +192,7 @@ gint main(gint argc, gchar **argv)
                }
        
                if(run) {
+                       gboolean passed;
                        gchar **split = NULL;
                        
                        if(debug && test_groups[j].handler != fake_tests_init) {
@@ -195,7 +217,7 @@ gint main(gint argc, gchar **argv)
                                }
                        }
                        
-                       gboolean passed = run_group(&(test_groups[j]), 
+                       passed = run_group(&(test_groups[j]), 
                                iterations, quiet, report_time, tests);
 
                        if(tests != NULL) {
@@ -209,8 +231,9 @@ gint main(gint argc, gchar **argv)
        }
        
        if(!quiet) {
+               gdouble pass_percentage = ((gdouble)global_passed / (gdouble)global_tests) * 100.0;
                printf("=============================\n");
-               printf("Overall result: %s\n", global_failure ? "FAILED" : "OK");
+               printf("Overall result: %s : %d / %d (%g%%)\n", global_failure ? "FAILED" : "OK", global_passed, global_tests, pass_percentage);
        }
        
        if(report_time) {
@@ -226,6 +249,7 @@ gint main(gint argc, gchar **argv)
                string_array_free(tests_to_run);
        }
 
-       return 0;
+       return global_tests - global_passed;
 }
 
+