Permalink
Browse files

Lua operations unit tests

  • Loading branch information...
feragon committed Jul 6, 2016
1 parent f0d5dc5 commit 2844b62f0a2fbb4aed4e4311f40ba016f254e0df
Showing with 306 additions and 1 deletion.
  1. +2 −1 unittest/CMakeLists.txt
  2. +304 −0 unittest/ui/testluaoperations.cpp
View
@@ -51,7 +51,8 @@ if(WITH_QTUI)
set(src
${src}
ui/testtoolbar.cpp
ui/testluaui.cpp)
ui/testluaui.cpp
ui/testluaoperations.cpp)
include_directories("${CMAKE_SOURCE_DIR}/lcUI")
include_directories("${CMAKE_SOURCE_DIR}/lcviewerqt")
endif(WITH_QTUI)
@@ -0,0 +1,304 @@
#include <gtest/gtest.h>
#include <QApplication>
#include <luainterface.h>
static int argc = 0;
static char** argv = NULL;
TEST(LuaUIOperationsTest, Move) {
QApplication app(argc, argv);
LuaInterface luaInterface;
auto L = luaInterface.luaState();
luaInterface.hideUI(true);
luaInterface.initLua();
auto mdiArea = LuaIntf::Lua::getGlobal<QMdiArea*>(L, "mdiArea");
if(mdiArea->subWindowList().count() == 0) {
LuaIntf::LuaRef(L, "new_file")();
}
mdiArea->setActiveSubWindow(mdiArea->subWindowList().at(0));
auto mdiChild = dynamic_cast<CadMdiChild*>(mdiArea->activeSubWindow()->widget());
auto storageManager = mdiChild->storageManager();
auto documentCanvas = mdiChild->viewer()->documentCanvas();
lc::entity::Line_CSPtr createdEntity;
std::vector<lc::entity::CADEntity_CSPtr> entities;
entities = storageManager->entityContainer().asVector();
for(auto entity : entities) {
storageManager->removeEntity(entity);
}
EXPECT_EQ(0, storageManager->entityContainer().asVector().size());
LuaIntf::LuaRef(L, "create_line")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100));
EXPECT_EQ(1, storageManager->entityContainer().asVector().size()) << "Line was not created";
documentCanvas->makeSelection(0, 0, 100, 100, false, false);
documentCanvas->closeSelection();
EXPECT_EQ(1, mdiChild->selection().size()) << "Entity not selected";
LuaIntf::LuaRef(L, "move_selected_entities")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100));
entities = storageManager->entityContainer().asVector();
createdEntity = std::dynamic_pointer_cast<const lc::entity::Line>(entities.at(0));
EXPECT_EQ(lc::geo::Coordinate(100, 100), createdEntity->start());
EXPECT_EQ(lc::geo::Coordinate(200, 200), createdEntity->end());
}
TEST(LuaUIOperationsTest, Rotate) {
QApplication app(argc, argv);
LuaInterface luaInterface;
auto L = luaInterface.luaState();
luaInterface.hideUI(true);
luaInterface.initLua();
auto mdiArea = LuaIntf::Lua::getGlobal<QMdiArea*>(L, "mdiArea");
if(mdiArea->subWindowList().count() == 0) {
LuaIntf::LuaRef(L, "new_file")();
}
mdiArea->setActiveSubWindow(mdiArea->subWindowList().at(0));
auto mdiChild = dynamic_cast<CadMdiChild*>(mdiArea->activeSubWindow()->widget());
auto storageManager = mdiChild->storageManager();
auto documentCanvas = mdiChild->viewer()->documentCanvas();
lc::entity::Line_CSPtr createdEntity;
std::vector<lc::entity::CADEntity_CSPtr> entities;
entities = storageManager->entityContainer().asVector();
for(auto entity : entities) {
storageManager->removeEntity(entity);
}
EXPECT_EQ(0, storageManager->entityContainer().asVector().size());
LuaIntf::LuaRef(L, "create_line")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100));
EXPECT_EQ(1, storageManager->entityContainer().asVector().size()) << "Line was not created";
documentCanvas->makeSelection(0, 0, 100, 100, false, false);
documentCanvas->closeSelection();
EXPECT_EQ(1, mdiChild->selection().size()) << "Entity not selected";
LuaIntf::LuaRef(L, "rotate_selected_entities")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 100));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 0));
entities = storageManager->entityContainer().asVector();
createdEntity = std::dynamic_pointer_cast<const lc::entity::Line>(entities.at(0));
EXPECT_EQ(lc::geo::Coordinate(0, 0), createdEntity->start());
EXPECT_EQ(lc::geo::Coordinate(100, -100), createdEntity->end());
}
TEST(LuaUIOperationsTest, Copy) {
QApplication app(argc, argv);
LuaInterface luaInterface;
auto L = luaInterface.luaState();
luaInterface.hideUI(true);
luaInterface.initLua();
auto mdiArea = LuaIntf::Lua::getGlobal<QMdiArea*>(L, "mdiArea");
if(mdiArea->subWindowList().count() == 0) {
LuaIntf::LuaRef(L, "new_file")();
}
mdiArea->setActiveSubWindow(mdiArea->subWindowList().at(0));
auto mdiChild = dynamic_cast<CadMdiChild*>(mdiArea->activeSubWindow()->widget());
auto storageManager = mdiChild->storageManager();
auto documentCanvas = mdiChild->viewer()->documentCanvas();
lc::entity::Line_CSPtr createdEntity;
std::vector<lc::entity::CADEntity_CSPtr> entities;
entities = storageManager->entityContainer().asVector();
for(auto entity : entities) {
storageManager->removeEntity(entity);
}
EXPECT_EQ(0, storageManager->entityContainer().asVector().size());
LuaIntf::LuaRef(L, "create_line")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100));
EXPECT_EQ(1, storageManager->entityContainer().asVector().size()) << "Line was not created";
documentCanvas->makeSelection(0, 0, 100, 100, false, false);
documentCanvas->closeSelection();
EXPECT_EQ(1, mdiChild->selection().size()) << "Entity not selected";
LuaIntf::LuaRef(L, "copy_selected_entities")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100));
entities = storageManager->entityContainer().asVector();
ASSERT_EQ(2, entities.size());
createdEntity = std::dynamic_pointer_cast<const lc::entity::Line>(entities.at(0));
EXPECT_EQ(lc::geo::Coordinate(0, 0), createdEntity->start());
EXPECT_EQ(lc::geo::Coordinate(100, 100), createdEntity->end());
createdEntity = std::dynamic_pointer_cast<const lc::entity::Line>(entities.at(1));
EXPECT_EQ(lc::geo::Coordinate(100, 100), createdEntity->start());
EXPECT_EQ(lc::geo::Coordinate(200, 200), createdEntity->end());
}
TEST(LuaUIOperationsTest, Scale) {
QApplication app(argc, argv);
LuaInterface luaInterface;
auto L = luaInterface.luaState();
luaInterface.hideUI(true);
luaInterface.initLua();
auto mdiArea = LuaIntf::Lua::getGlobal<QMdiArea*>(L, "mdiArea");
if(mdiArea->subWindowList().count() == 0) {
LuaIntf::LuaRef(L, "new_file")();
}
mdiArea->setActiveSubWindow(mdiArea->subWindowList().at(0));
auto mdiChild = dynamic_cast<CadMdiChild*>(mdiArea->activeSubWindow()->widget());
auto storageManager = mdiChild->storageManager();
auto documentCanvas = mdiChild->viewer()->documentCanvas();
lc::entity::Line_CSPtr createdEntity;
std::vector<lc::entity::CADEntity_CSPtr> entities;
entities = storageManager->entityContainer().asVector();
for(auto entity : entities) {
storageManager->removeEntity(entity);
}
EXPECT_EQ(0, storageManager->entityContainer().asVector().size());
LuaIntf::LuaRef(L, "create_line")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100));
EXPECT_EQ(1, storageManager->entityContainer().asVector().size()) << "Line was not created";
documentCanvas->makeSelection(0, 0, 100, 100, false, false);
documentCanvas->closeSelection();
EXPECT_EQ(1, mdiChild->selection().size()) << "Entity not selected";
LuaIntf::LuaRef(L, "scale_selected_entities")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "number")(2);
entities = storageManager->entityContainer().asVector();
createdEntity = std::dynamic_pointer_cast<const lc::entity::Line>(entities.at(0));
EXPECT_EQ(lc::geo::Coordinate(0, 0), createdEntity->start());
EXPECT_EQ(lc::geo::Coordinate(200, 200), createdEntity->end());
}
TEST(LuaUIOperationsTest, Remove) {
QApplication app(argc, argv);
LuaInterface luaInterface;
auto L = luaInterface.luaState();
luaInterface.hideUI(true);
luaInterface.initLua();
auto mdiArea = LuaIntf::Lua::getGlobal<QMdiArea*>(L, "mdiArea");
if(mdiArea->subWindowList().count() == 0) {
LuaIntf::LuaRef(L, "new_file")();
}
mdiArea->setActiveSubWindow(mdiArea->subWindowList().at(0));
auto mdiChild = dynamic_cast<CadMdiChild*>(mdiArea->activeSubWindow()->widget());
auto storageManager = mdiChild->storageManager();
auto documentCanvas = mdiChild->viewer()->documentCanvas();
lc::entity::Line_CSPtr createdEntity;
std::vector<lc::entity::CADEntity_CSPtr> entities;
entities = storageManager->entityContainer().asVector();
for(auto entity : entities) {
storageManager->removeEntity(entity);
}
EXPECT_EQ(0, storageManager->entityContainer().asVector().size());
LuaIntf::LuaRef(L, "create_line")();
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100));
EXPECT_EQ(1, storageManager->entityContainer().asVector().size()) << "Line was not created";
documentCanvas->makeSelection(0, 0, 100, 100, false, false);
documentCanvas->closeSelection();
EXPECT_EQ(1, mdiChild->selection().size()) << "Entity not selected";
LuaIntf::LuaRef(L, "remove_selected_entities")();
EXPECT_EQ(0, storageManager->entityContainer().asVector().size());
}

0 comments on commit 2844b62

Please sign in to comment.