Added static factory method to all test classes and improved the program

invocation (e.g. it list what tests are available now).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21383 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-06-10 17:27:34 +00:00
parent aa9303f41e
commit 651a825f3e
9 changed files with 84 additions and 14 deletions

View File

@ -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 // helpful operator
BPoint BPoint
operator+(const BPoint& p, const BSize& size) 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 int
main(int argc, const char* const* argv) main(int argc, const char* const* argv)
{ {
// get test name // get test name
const char* testName = "button"; const char* testName;
if (argc >= 2) if (argc < 2) {
testName = argv[1]; fprintf(stderr, "Usage: %s <test name>\n", argv[0]);
print_test_list(true);
exit(1);
}
testName = argv[1];
// create app // create app
BApplication app("application/x-vnd.haiku.widget-layout-test"); BApplication app("application/x-vnd.haiku.widget-layout-test");
// create test // find and create the test
Test* test; Test* test = NULL;
if (strcmp(testName, "box") == 0) { for (int32 i = 0; kTestInfos[i].name; i++) {
test = new BoxTest; if (strcmp(testName, kTestInfos[i].name) == 0) {
} else if (strcmp(testName, "button") == 0) { test = (kTestInfos[i].create)();
test = new ButtonTest; break;
} else if (strcmp(testName, "checkbox") == 0) { }
test = new CheckBoxTest; }
} else if (strcmp(testName, "listview") == 0) {
test = new ListViewTest; if (!test) {
} else {
fprintf(stderr, "Error: Invalid test name: \"%s\"\n", testName); fprintf(stderr, "Error: Invalid test name: \"%s\"\n", testName);
print_test_list(true);
exit(1); exit(1);
} }

View File

@ -77,6 +77,14 @@ BoxTest::~BoxTest()
} }
// CreateTest
Test*
BoxTest::CreateTest()
{
return new BoxTest;
}
// ActivateTest // ActivateTest
void void
BoxTest::ActivateTest(View* controls) BoxTest::ActivateTest(View* controls)

View File

@ -19,6 +19,8 @@ public:
BoxTest(); BoxTest();
virtual ~BoxTest(); virtual ~BoxTest();
static Test* CreateTest();
virtual void ActivateTest(View* controls); virtual void ActivateTest(View* controls);
virtual void DectivateTest(); virtual void DectivateTest();

View File

@ -27,6 +27,14 @@ ButtonTest::~ButtonTest()
} }
// CreateTest
Test*
ButtonTest::CreateTest()
{
return new ButtonTest;
}
// ActivateTest // ActivateTest
void void
ButtonTest::ActivateTest(View* controls) ButtonTest::ActivateTest(View* controls)

View File

@ -17,6 +17,7 @@ public:
ButtonTest(); ButtonTest();
virtual ~ButtonTest(); virtual ~ButtonTest();
static Test* CreateTest();
virtual void ActivateTest(View* controls); virtual void ActivateTest(View* controls);
virtual void DectivateTest(); virtual void DectivateTest();

View File

@ -27,6 +27,14 @@ CheckBoxTest::~CheckBoxTest()
} }
// CreateTest
Test*
CheckBoxTest::CreateTest()
{
return new CheckBoxTest;
}
// ActivateTest // ActivateTest
void void
CheckBoxTest::ActivateTest(View* controls) CheckBoxTest::ActivateTest(View* controls)

View File

@ -17,6 +17,8 @@ public:
CheckBoxTest(); CheckBoxTest();
virtual ~CheckBoxTest(); virtual ~CheckBoxTest();
static Test* CreateTest();
virtual void ActivateTest(View* controls); virtual void ActivateTest(View* controls);
virtual void DectivateTest(); virtual void DectivateTest();

View File

@ -22,3 +22,12 @@ ListViewTest::ListViewTest()
fListView->AddItem(new BStringItem(itemText.String())); fListView->AddItem(new BStringItem(itemText.String()));
} }
} }
Test*
ListViewTest::CreateTest()
{
return new ListViewTest;
}

View File

@ -16,6 +16,8 @@ class ListViewTest : public Test {
public: public:
ListViewTest(); ListViewTest();
static Test* CreateTest();
private: private:
BListView* fListView; BListView* fListView;
}; };