Enlightenment CVS committal Author : dj2 Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/bin Modified Files: Ewl_Test2.h main.c Log Message: - start framework for unit tests =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/bin/Ewl_Test2.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- Ewl_Test2.h 3 Mar 2006 02:53:02 -0000 1.1 +++ Ewl_Test2.h 9 Mar 2006 05:45:14 -0000 1.2 @@ -29,6 +29,14 @@ void *handle; Ewl_Test_Type type; int (*func)(Ewl_Container *con); + Ecore_List *unit_tests; +}; + +typedef struct Ewl_Unit_Test Ewl_Unit_Test; +struct Ewl_Unit_Test +{ + const char *name; + int (*func)(char *buf, int len); }; #endif =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/bin/main.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- main.c 8 Mar 2006 15:57:10 -0000 1.7 +++ main.c 9 Mar 2006 05:45:14 -0000 1.8 @@ -18,6 +18,7 @@ static void run_test_boxed(Ewl_Widget *w, void *ev, void *data); static void run_window_test(Ewl_Test *test, int width, int height); +static void run_unit_tests(Ewl_Test *test); static int create_main_test_window(Ewl_Container *win); static void fill_source_text(Ewl_Test *text); @@ -29,7 +30,7 @@ int main(int argc, char **argv) { - int i; + int i, unit_test = 0, ran_test = 0; /* initialize the ewl library */ if (!ewl_init(&argc, argv)) @@ -54,6 +55,8 @@ ewl_test_print_tests(); exit(0); } + else if (!strncmp(argv[i], "-unit", 5)) + unit_test = 1; /* see if this thing was a test to run */ ecore_list_goto_first(tests); @@ -61,14 +64,19 @@ { if (!strcasecmp(argv[i], t->name)) { - run_window_test(t, 0, 0); + if (unit_test) + run_unit_tests(t); + else + run_window_test(t, 0, 0); + + ran_test ++; break; } } } /* no passed in tests, run the main test app */ - if (window_count < 1) + if (!ran_test) { Ewl_Test test; @@ -110,6 +118,9 @@ { Ewl_Widget *win, *box; + /* nothing to do if there is no ui test */ + if (!test->func) return; + win = ewl_window_new(); ewl_window_title_set(EWL_WINDOW(win), test->name); ewl_window_name_set(EWL_WINDOW(win), test->name); @@ -130,6 +141,27 @@ } static void +run_unit_tests(Ewl_Test *test) +{ + Ewl_Unit_Test *t; + char buf[1024]; + + /* no unit tests, nothign to do */ + if (!test->unit_tests) return; + + ecore_list_goto_first(test->unit_tests); + while ((t = ecore_list_next(test->unit_tests))) + { + int ret; + + printf("Running %s: ", t->name); + ret = t->func(buf, sizeof(buf)); + printf("%s %s", (ret ? "passed" : "failed"), buf); + buf[0] = '\0'; + } +} + +static void run_test_boxed(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__, void *data) { @@ -138,6 +170,9 @@ t = data; + /* nothing to do if no ui test */ + if (!t->func) return; + c = ewl_widget_name_find("execute_box"); ewl_container_reset(EWL_CONTAINER(c)); t->func(EWL_CONTAINER(c)); @@ -198,6 +233,7 @@ { void (*func_info)(Ewl_Test *test); + /* the UI test info */ func_info = dlsym(handle, "test_info"); if (func_info) { @@ -288,6 +324,12 @@ ewl_widget_name_set(o, "execute_box"); ewl_widget_show(o); + o = ewl_vbox_new(); + ewl_container_child_append(EWL_CONTAINER(note), o); + ewl_notebook_page_tab_text_set(EWL_NOTEBOOK(note), o, "Unit Tests"); + ewl_widget_name_set(o, "unit_test_box"); + ewl_widget_show(o); + o = ewl_text_new(); ewl_container_child_append(EWL_CONTAINER(note), o); ewl_notebook_page_tab_text_set(EWL_NOTEBOOK(note), o, "Tutorial"); ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs