mirror of https://github.com/axmolengine/axmol.git
Merge pull request #11351 from WenhaiLin/v3-autotest
Test automation support:
This commit is contained in:
commit
c022b7d615
|
@ -29,6 +29,8 @@
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
USING_NS_CC_EXT;
|
USING_NS_CC_EXT;
|
||||||
|
|
||||||
|
#define TABEL_LABEL_TAG 1024
|
||||||
|
|
||||||
TestBase::TestBase()
|
TestBase::TestBase()
|
||||||
: _parentTest(nullptr)
|
: _parentTest(nullptr)
|
||||||
, _isTestList(false)
|
, _isTestList(false)
|
||||||
|
@ -51,6 +53,78 @@ void TestBase::backsUpOneLevel()
|
||||||
}
|
}
|
||||||
|
|
||||||
//TestList
|
//TestList
|
||||||
|
class TestCustomTableView : public TableView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static TestCustomTableView* create(TableViewDataSource* dataSource, Size size)
|
||||||
|
{
|
||||||
|
auto table = new (std::nothrow) TestCustomTableView();
|
||||||
|
table->initWithViewSize(size, nullptr);
|
||||||
|
table->autorelease();
|
||||||
|
table->setDataSource(dataSource);
|
||||||
|
table->_updateCellPositions();
|
||||||
|
table->_updateContentSize();
|
||||||
|
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void onTouchEnded(Touch *touch, Event *event) override
|
||||||
|
{
|
||||||
|
if (!this->isVisible())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_touchedCell)
|
||||||
|
{
|
||||||
|
auto label = (Label*)_touchedCell->getChildByTag(TABEL_LABEL_TAG);
|
||||||
|
|
||||||
|
Rect bbox = label->getBoundingBox();
|
||||||
|
bbox.origin = _touchedCell->convertToWorldSpace(bbox.origin);
|
||||||
|
|
||||||
|
if (bbox.containsPoint(touch->getLocation()) && _tableViewDelegate != nullptr)
|
||||||
|
{
|
||||||
|
_tableViewDelegate->tableCellUnhighlight(this, _touchedCell);
|
||||||
|
_tableViewDelegate->tableCellTouched(this, _touchedCell);
|
||||||
|
}
|
||||||
|
|
||||||
|
_touchedCell = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScrollView::onTouchEnded(touch, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onMouseScroll(Event *event)
|
||||||
|
{
|
||||||
|
auto mouseEvent = static_cast<EventMouse*>(event);
|
||||||
|
float moveY = mouseEvent->getScrollY() * 20;
|
||||||
|
|
||||||
|
auto minOffset = this->minContainerOffset();
|
||||||
|
auto maxOffset = this->maxContainerOffset();
|
||||||
|
|
||||||
|
auto offset = this->getContentOffset();
|
||||||
|
offset.y += moveY;
|
||||||
|
|
||||||
|
if (offset.y < minOffset.y)
|
||||||
|
{
|
||||||
|
offset.y = minOffset.y;
|
||||||
|
}
|
||||||
|
else if (offset.y > maxOffset.y)
|
||||||
|
{
|
||||||
|
offset.y = maxOffset.y;
|
||||||
|
}
|
||||||
|
this->setContentOffset(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TestCustomTableView()
|
||||||
|
{
|
||||||
|
auto mouseListener = EventListenerMouse::create();
|
||||||
|
mouseListener->onMouseScroll = CC_CALLBACK_1(TestCustomTableView::onMouseScroll, this);
|
||||||
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TestList::TestList()
|
TestList::TestList()
|
||||||
{
|
{
|
||||||
_isTestList = true;
|
_isTestList = true;
|
||||||
|
@ -74,7 +148,7 @@ void TestList::runThisTest()
|
||||||
auto visibleSize = director->getVisibleSize();
|
auto visibleSize = director->getVisibleSize();
|
||||||
auto origin = director->getVisibleOrigin();
|
auto origin = director->getVisibleOrigin();
|
||||||
|
|
||||||
TableView* tableView = TableView::create(this, Size(400,visibleSize.height));
|
auto tableView = TestCustomTableView::create(this, Size(400, visibleSize.height));
|
||||||
tableView->setPosition(origin.x + (visibleSize.width - 400) / 2, origin.y);
|
tableView->setPosition(origin.x + (visibleSize.width - 400) / 2, origin.y);
|
||||||
tableView->setDirection(ScrollView::Direction::VERTICAL);
|
tableView->setDirection(ScrollView::Direction::VERTICAL);
|
||||||
tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
|
tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
|
||||||
|
@ -163,13 +237,13 @@ TableViewCell* TestList::tableCellAtIndex(TableView *table, ssize_t idx)
|
||||||
{
|
{
|
||||||
cell = TableViewCell::create();
|
cell = TableViewCell::create();
|
||||||
auto label = Label::createWithTTF(_childTestNames[idx], "fonts/arial.ttf", 20.0f);
|
auto label = Label::createWithTTF(_childTestNames[idx], "fonts/arial.ttf", 20.0f);
|
||||||
label->setTag(1024);
|
label->setTag(TABEL_LABEL_TAG);
|
||||||
label->setPosition(200, 15);
|
label->setPosition(200, 15);
|
||||||
cell->addChild(label);
|
cell->addChild(label);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto label = (Label*)cell->getChildByTag(1024);
|
auto label = (Label*)cell->getChildByTag(TABEL_LABEL_TAG);
|
||||||
label->setString(_childTestNames[idx]);
|
label->setString(_childTestNames[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue