diff --git a/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp index 5492dfb1a0..b65f42e41d 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp @@ -29,6 +29,20 @@ enum { }; +struct test_info { + const char* name; + Test* (*create)(); +}; + +const test_info kTestInfos[] = { + { "box", BoxTest::CreateTest }, + { "button", ButtonTest::CreateTest }, + { "checkbox", CheckBoxTest::CreateTest }, + { "listview", ListViewTest::CreateTest }, + { NULL, NULL } +}; + + // helpful operator BPoint operator+(const BPoint& p, const BSize& size) @@ -258,29 +272,45 @@ private: }; +static void +print_test_list(bool error) +{ + FILE* out = (error ? stderr : stdout); + + fprintf(out, "available tests:\n"); + + for (int32 i = 0; kTestInfos[i].name; i++) + fprintf(out, " %s\n", kTestInfos[i].name); +} + + int main(int argc, const char* const* argv) { // get test name - const char* testName = "button"; - if (argc >= 2) - testName = argv[1]; + const char* testName; + if (argc < 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + print_test_list(true); + exit(1); + } + testName = argv[1]; // create app BApplication app("application/x-vnd.haiku.widget-layout-test"); - // create test - Test* test; - if (strcmp(testName, "box") == 0) { - test = new BoxTest; - } else if (strcmp(testName, "button") == 0) { - test = new ButtonTest; - } else if (strcmp(testName, "checkbox") == 0) { - test = new CheckBoxTest; - } else if (strcmp(testName, "listview") == 0) { - test = new ListViewTest; - } else { + // find and create the test + Test* test = NULL; + for (int32 i = 0; kTestInfos[i].name; i++) { + if (strcmp(testName, kTestInfos[i].name) == 0) { + test = (kTestInfos[i].create)(); + break; + } + } + + if (!test) { fprintf(stderr, "Error: Invalid test name: \"%s\"\n", testName); + print_test_list(true); exit(1); } diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/BoxTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/tests/BoxTest.cpp index f4c13b2d63..564774e7a2 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/BoxTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/BoxTest.cpp @@ -77,6 +77,14 @@ BoxTest::~BoxTest() } +// CreateTest +Test* +BoxTest::CreateTest() +{ + return new BoxTest; +} + + // ActivateTest void BoxTest::ActivateTest(View* controls) diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/BoxTest.h b/src/tests/kits/interface/layout/widget_layout_test/tests/BoxTest.h index ac81993777..b141ac6550 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/BoxTest.h +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/BoxTest.h @@ -19,6 +19,8 @@ public: BoxTest(); virtual ~BoxTest(); + static Test* CreateTest(); + virtual void ActivateTest(View* controls); virtual void DectivateTest(); diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/ButtonTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/tests/ButtonTest.cpp index 050a0c03ec..f067ecd438 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/ButtonTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/ButtonTest.cpp @@ -27,6 +27,14 @@ ButtonTest::~ButtonTest() } +// CreateTest +Test* +ButtonTest::CreateTest() +{ + return new ButtonTest; +} + + // ActivateTest void ButtonTest::ActivateTest(View* controls) diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/ButtonTest.h b/src/tests/kits/interface/layout/widget_layout_test/tests/ButtonTest.h index 30b958e07b..4a813ecde9 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/ButtonTest.h +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/ButtonTest.h @@ -17,6 +17,7 @@ public: ButtonTest(); virtual ~ButtonTest(); + static Test* CreateTest(); virtual void ActivateTest(View* controls); virtual void DectivateTest(); diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/CheckBoxTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/tests/CheckBoxTest.cpp index e5ec317738..34682b25b7 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/CheckBoxTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/CheckBoxTest.cpp @@ -27,6 +27,14 @@ CheckBoxTest::~CheckBoxTest() } +// CreateTest +Test* +CheckBoxTest::CreateTest() +{ + return new CheckBoxTest; +} + + // ActivateTest void CheckBoxTest::ActivateTest(View* controls) diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/CheckBoxTest.h b/src/tests/kits/interface/layout/widget_layout_test/tests/CheckBoxTest.h index e42f0e386a..4af900519e 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/CheckBoxTest.h +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/CheckBoxTest.h @@ -17,6 +17,8 @@ public: CheckBoxTest(); virtual ~CheckBoxTest(); + static Test* CreateTest(); + virtual void ActivateTest(View* controls); virtual void DectivateTest(); diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/ListViewTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/tests/ListViewTest.cpp index 318ad12aca..91796b5f2a 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/ListViewTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/ListViewTest.cpp @@ -22,3 +22,12 @@ ListViewTest::ListViewTest() fListView->AddItem(new BStringItem(itemText.String())); } } + + +Test* +ListViewTest::CreateTest() +{ + return new ListViewTest; +} + + diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/ListViewTest.h b/src/tests/kits/interface/layout/widget_layout_test/tests/ListViewTest.h index 513335830d..6c475cd594 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/ListViewTest.h +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/ListViewTest.h @@ -16,6 +16,8 @@ class ListViewTest : public Test { public: ListViewTest(); + static Test* CreateTest(); + private: BListView* fListView; };