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
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 <test name>\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);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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