Add unit test for BOutlineListView.
Change-Id: Icad7e7c659141fae1bb6e52571f001c9f561a446 Reviewed-on: https://review.haiku-os.org/451 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
parent
2f3e1117f9
commit
58a62dd65f
@ -11,6 +11,7 @@
|
|||||||
#include "btextview/TextViewTest.h"
|
#include "btextview/TextViewTest.h"
|
||||||
//#include "bwidthbuffer/WidthBufferTest.h"
|
//#include "bwidthbuffer/WidthBufferTest.h"
|
||||||
#include "GraphicsDefsTest.h"
|
#include "GraphicsDefsTest.h"
|
||||||
|
#include "OutlineListViewTest.h"
|
||||||
|
|
||||||
|
|
||||||
BTestSuite *
|
BTestSuite *
|
||||||
@ -22,6 +23,7 @@ getTestSuite()
|
|||||||
suite->addTest("BAlert", AlertTest::Suite());
|
suite->addTest("BAlert", AlertTest::Suite());
|
||||||
suite->addTest("BBitmap", BitmapTestSuite());
|
suite->addTest("BBitmap", BitmapTestSuite());
|
||||||
suite->addTest("BDeskbar", DeskbarTestSuite());
|
suite->addTest("BDeskbar", DeskbarTestSuite());
|
||||||
|
suite->addTest("BOutlineListView", OutlineListViewTestSuite());
|
||||||
suite->addTest("BPolygon", PolygonTestSuite());
|
suite->addTest("BPolygon", PolygonTestSuite());
|
||||||
suite->addTest("BRegion", RegionTestSuite());
|
suite->addTest("BRegion", RegionTestSuite());
|
||||||
suite->addTest("BTextControl", TextControlTestSuite());
|
suite->addTest("BTextControl", TextControlTestSuite());
|
||||||
|
@ -51,6 +51,7 @@ UnitTestLib libinterfacetest.so
|
|||||||
RegionIntersect.cpp
|
RegionIntersect.cpp
|
||||||
RegionOffsetBy.cpp
|
RegionOffsetBy.cpp
|
||||||
|
|
||||||
|
OutlineListViewTest.cpp
|
||||||
TextControlTest.cpp
|
TextControlTest.cpp
|
||||||
TextViewTest.cpp
|
TextViewTest.cpp
|
||||||
|
|
||||||
|
120
src/tests/kits/interface/OutlineListViewTest.cpp
Normal file
120
src/tests/kits/interface/OutlineListViewTest.cpp
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018, Sean Healy
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <Application.h>
|
||||||
|
#include <Window.h>
|
||||||
|
#include <TestUtils.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include <OutlineListView.h>
|
||||||
|
|
||||||
|
BListItem* gExpected[16];
|
||||||
|
int gIndex = 0;
|
||||||
|
int gCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
BListItem* eachitemunder(BListItem* item, void* arg) {
|
||||||
|
BStringItem* str = (BStringItem*)item;
|
||||||
|
fprintf(stderr, "Item @%d: %s\n", gIndex, str->Text());
|
||||||
|
|
||||||
|
CHK(gIndex < gCount);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(item, gExpected[gIndex]);
|
||||||
|
gIndex++;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class OutlineListViewTest: public TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OutlineListViewTest() {}
|
||||||
|
OutlineListViewTest(std::string name) : TestCase(name) {}
|
||||||
|
|
||||||
|
void EachItemUnder();
|
||||||
|
|
||||||
|
static Test* Suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void OutlineListViewTest::EachItemUnder() {
|
||||||
|
BApplication* app = new BApplication(
|
||||||
|
"application/x-vnd.OutlineListView_EachItemUnder.test");
|
||||||
|
BWindow* window = new BWindow(BRect(50,50,550,550),
|
||||||
|
"OutlineListView_EachItemUnder", B_TITLED_WINDOW,
|
||||||
|
B_QUIT_ON_WINDOW_CLOSE, 0);
|
||||||
|
BOutlineListView* view = new BOutlineListView(BRect(5,5,495,495), "View",
|
||||||
|
B_MULTIPLE_SELECTION_LIST, B_FOLLOW_ALL);
|
||||||
|
window->AddChild(view);
|
||||||
|
|
||||||
|
view->AddItem(new BStringItem("One", 0));
|
||||||
|
view->AddItem(new BStringItem("One-A", 1));
|
||||||
|
view->AddItem(new BStringItem("One-A-1", 2));
|
||||||
|
view->AddItem(new BStringItem("One-B", 1));
|
||||||
|
view->AddItem(new BStringItem("One-C", 1));
|
||||||
|
|
||||||
|
view->AddItem(new BStringItem("Two", 0));
|
||||||
|
view->AddItem(new BStringItem("Two-A", 1));
|
||||||
|
view->AddItem(new BStringItem("Two-A-1", 2));
|
||||||
|
view->AddItem(new BStringItem("Two-B", 1));
|
||||||
|
view->AddItem(new BStringItem("Two-C", 1));
|
||||||
|
|
||||||
|
view->AddItem(new BStringItem("Three", 0));
|
||||||
|
view->AddItem(new BStringItem("Three-A", 1));
|
||||||
|
view->AddItem(new BStringItem("Three-A-1", 2));
|
||||||
|
view->AddItem(new BStringItem("Three-B", 1));
|
||||||
|
view->AddItem(new BStringItem("Three-C", 1));
|
||||||
|
|
||||||
|
// First test is easy
|
||||||
|
gExpected[0] = view->FullListItemAt(6);
|
||||||
|
gExpected[1] = view->FullListItemAt(8);
|
||||||
|
gExpected[2] = view->FullListItemAt(9);
|
||||||
|
gCount = 3;
|
||||||
|
gIndex = 0;
|
||||||
|
|
||||||
|
fprintf(stderr, "Easy test\n");
|
||||||
|
view->EachItemUnder(view->FullListItemAt(5), true, eachitemunder, NULL);
|
||||||
|
|
||||||
|
// Check that collapsing an item does not change the outcome
|
||||||
|
gIndex = 0;
|
||||||
|
view->Collapse(view->FullListItemAt(0));
|
||||||
|
|
||||||
|
fprintf(stderr, "One collapsed\n");
|
||||||
|
view->EachItemUnder(view->FullListItemAt(5), true, eachitemunder, NULL);
|
||||||
|
|
||||||
|
gIndex = 0;
|
||||||
|
view->Collapse(view->FullListItemAt(5));
|
||||||
|
|
||||||
|
fprintf(stderr, "Two collapsed\n");
|
||||||
|
view->EachItemUnder(view->FullListItemAt(5), true, eachitemunder, NULL);
|
||||||
|
|
||||||
|
// Don't actually run anything
|
||||||
|
delete window;
|
||||||
|
delete app;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Test* OutlineListViewTest::Suite()
|
||||||
|
{
|
||||||
|
TestSuite* SuiteOfTests = new TestSuite;
|
||||||
|
|
||||||
|
ADD_TEST4(BOutlineListView, SuiteOfTests, OutlineListViewTest,
|
||||||
|
EachItemUnder);
|
||||||
|
|
||||||
|
return SuiteOfTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CppUnit::Test* OutlineListViewTestSuite()
|
||||||
|
{
|
||||||
|
CppUnit::TestSuite* testSuite = new CppUnit::TestSuite();
|
||||||
|
|
||||||
|
testSuite->addTest(OutlineListViewTest::Suite());
|
||||||
|
|
||||||
|
return testSuite;
|
||||||
|
}
|
8
src/tests/kits/interface/OutlineListViewTest.h
Normal file
8
src/tests/kits/interface/OutlineListViewTest.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef _outlinelistview_test_h_
|
||||||
|
#define _outlinelistview_test_h_
|
||||||
|
|
||||||
|
class CppUnit::Test;
|
||||||
|
|
||||||
|
CppUnit::Test* OutlineListViewTestSuite();
|
||||||
|
|
||||||
|
#endif // _outlinelistview_test_h_
|
Loading…
Reference in New Issue
Block a user