Permalink
Browse files

Unit tests

  • Loading branch information...
feragon committed May 31, 2016
1 parent 7375701 commit 92c165799e2bb3b610ce660b590f20ea7c1ef2d4
Showing with 243 additions and 2 deletions.
  1. +3 −2 unittest/CMakeLists.txt
  2. +1 −0 unittest/main.cpp
  3. +239 −0 unittest/testselection.h
View
@@ -23,8 +23,9 @@ set(hdrs
entitytest.h
code.h
testmath.h
)
testselection.h)
include_directories("${CMAKE_SOURCE_DIR}/lckernel")
include_directories("${CMAKE_SOURCE_DIR}/lcviewernoqt")
add_executable(lcunittest ${src} ${hdrs} testintersect.h)
target_link_libraries(lcunittest lckernel gtest ${CMAKE_THREAD_LIBS_INIT} ${LOG4CXX_LIBRARIES})
target_link_libraries(lcunittest lckernel lcviewernoqt gtest ${CMAKE_THREAD_LIBS_INIT} ${LOG4CXX_LIBRARIES})
View
@@ -5,6 +5,7 @@
#include "testgeocircle.h"
#include "testgeoarc.h"
#include "testintersect.h"
#include "testselection.h"
using namespace std;
using namespace lc;
View
@@ -0,0 +1,239 @@
#include <gtest/gtest.h>
#include "documentcanvas.h"
#include <cad/dochelpers/documentimpl.h>
#include <cad/dochelpers/storagemanagerimpl.h>
#include <cad/operations/builder.h>
#include <cad/operations/documentoperation.h>
#include <cad/meta/layer.h>
#include <cad/operations/layerops.h>
#include <cad/primitive/line.h>
#include "drawitems/lcvdrawitem.h"
#pragma once
TEST(SelectionTest, NormalSelection) {
auto storageManager = std::make_shared<lc::StorageManagerImpl>();
auto document = std::make_shared<DocumentImpl>(storageManager);
auto docCanvas = std::make_shared<LCViewer::DocumentCanvas>(document);
auto layer = std::make_shared<Layer>("0", Color(1., 1., 1., 1.));
std::shared_ptr<lc::operation::AddLayer> al = std::make_shared<lc::operation::AddLayer>(document, layer);
al->execute();
auto builder = std::make_shared<operation::Builder>(document);
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(0,0,0), lc::geo::Coordinate(0, 10, 0), layer));
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(10,0,0), lc::geo::Coordinate(10, 10, 0), layer));
builder->execute();
docCanvas->makeSelection(0, 0, 5, 10, true, false);
docCanvas->closeSelection();
EXPECT_EQ(1, docCanvas->selection().asVector().size());
unsigned int i = 0;
docCanvas->entityContainer().each<LCViewer::LCVDrawItem>([&](LCViewer::LCVDrawItem_SPtr di) {
if(di->selected() == true) {
i++;
}
});
EXPECT_TRUE(i == docCanvas->selection().asVector().size());
}
TEST(SelectionTest, IntersectionSelection) {
auto storageManager = std::make_shared<lc::StorageManagerImpl>();
auto document = std::make_shared<DocumentImpl>(storageManager);
auto docCanvas = std::make_shared<LCViewer::DocumentCanvas>(document);
auto layer = std::make_shared<Layer>("0", Color(1., 1., 1., 1.));
std::shared_ptr<lc::operation::AddLayer> al = std::make_shared<lc::operation::AddLayer>(document, layer);
al->execute();
auto builder = std::make_shared<operation::Builder>(document);
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(0,0,0), lc::geo::Coordinate(0, 10, 0), layer));
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(10,0,0), lc::geo::Coordinate(10, 10, 0), layer));
builder->execute();
docCanvas->makeSelection(0, 0, 5, 5, false, false);
docCanvas->closeSelection();
EXPECT_EQ(1, docCanvas->selection().asVector().size());
unsigned int i = 0;
docCanvas->entityContainer().each<LCViewer::LCVDrawItem>([&](LCViewer::LCVDrawItem_SPtr di) {
if(di->selected() == true) {
i++;
}
});
EXPECT_TRUE(i == docCanvas->selection().asVector().size());
}
TEST(SelectionTest, AddToSelection) {
auto storageManager = std::make_shared<lc::StorageManagerImpl>();
auto document = std::make_shared<DocumentImpl>(storageManager);
auto docCanvas = std::make_shared<LCViewer::DocumentCanvas>(document);
auto layer = std::make_shared<Layer>("0", Color(1., 1., 1., 1.));
std::shared_ptr<lc::operation::AddLayer> al = std::make_shared<lc::operation::AddLayer>(document, layer);
al->execute();
auto builder = std::make_shared<operation::Builder>(document);
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(0,0,0), lc::geo::Coordinate(0, 10, 0), layer));
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(10,0,0), lc::geo::Coordinate(10, 10, 0), layer));
builder->execute();
docCanvas->makeSelection(0, 0, 1, 1, false, false);
docCanvas->closeSelection();
docCanvas->makeSelection(9, 0, 1, 1, false, true);
docCanvas->closeSelection();
EXPECT_EQ(2, docCanvas->selection().asVector().size());
unsigned int i = 0;
docCanvas->entityContainer().each<LCViewer::LCVDrawItem>([&](LCViewer::LCVDrawItem_SPtr di) {
if(di->selected() == true) {
i++;
}
});
EXPECT_TRUE(i == docCanvas->selection().asVector().size());
}
TEST(SelectionTest, Reselect) {
auto storageManager = std::make_shared<lc::StorageManagerImpl>();
auto document = std::make_shared<DocumentImpl>(storageManager);
auto docCanvas = std::make_shared<LCViewer::DocumentCanvas>(document);
auto layer = std::make_shared<Layer>("0", Color(1., 1., 1., 1.));
std::shared_ptr<lc::operation::AddLayer> al = std::make_shared<lc::operation::AddLayer>(document, layer);
al->execute();
auto builder = std::make_shared<operation::Builder>(document);
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(0,0,0), lc::geo::Coordinate(0, 10, 0), layer));
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(10,0,0), lc::geo::Coordinate(10, 10, 0), layer));
builder->execute();
docCanvas->makeSelection(0, 0, 10, 1, false, false);
docCanvas->closeSelection();
docCanvas->makeSelection(9, 0, 1, 1, false, true);
docCanvas->closeSelection();
EXPECT_EQ(1, docCanvas->selection().asVector().size());
unsigned int i = 0;
docCanvas->entityContainer().each<LCViewer::LCVDrawItem>([&](LCViewer::LCVDrawItem_SPtr di) {
if(di->selected() == true) {
i++;
}
});
EXPECT_TRUE(i == docCanvas->selection().asVector().size());
}
TEST(SelectionTest, ClearSelection) {
auto storageManager = std::make_shared<lc::StorageManagerImpl>();
auto document = std::make_shared<DocumentImpl>(storageManager);
auto docCanvas = std::make_shared<LCViewer::DocumentCanvas>(document);
auto layer = std::make_shared<Layer>("0", Color(1., 1., 1., 1.));
std::shared_ptr<lc::operation::AddLayer> al = std::make_shared<lc::operation::AddLayer>(document, layer);
al->execute();
auto builder = std::make_shared<operation::Builder>(document);
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(0,0,0), lc::geo::Coordinate(0, 10, 0), layer));
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(10,0,0), lc::geo::Coordinate(10, 10, 0), layer));
builder->execute();
docCanvas->makeSelection(0, 0, 1, 1, false, false);
docCanvas->closeSelection();
docCanvas->makeSelection(9, 0, 1, 1, false, false);
docCanvas->closeSelection();
EXPECT_EQ(1, docCanvas->selection().asVector().size());
unsigned int i = 0;
docCanvas->entityContainer().each<LCViewer::LCVDrawItem>([&](LCViewer::LCVDrawItem_SPtr di) {
if(di->selected() == true) {
i++;
}
});
EXPECT_TRUE(i == docCanvas->selection().asVector().size());
}
TEST(SelectionTest, Deselect) {
auto storageManager = std::make_shared<lc::StorageManagerImpl>();
auto document = std::make_shared<DocumentImpl>(storageManager);
auto docCanvas = std::make_shared<LCViewer::DocumentCanvas>(document);
auto layer = std::make_shared<Layer>("0", Color(1., 1., 1., 1.));
std::shared_ptr<lc::operation::AddLayer> al = std::make_shared<lc::operation::AddLayer>(document, layer);
al->execute();
auto builder = std::make_shared<operation::Builder>(document);
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(0,0,0), lc::geo::Coordinate(0, 10, 0), layer));
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(10,0,0), lc::geo::Coordinate(10, 10, 0), layer));
builder->execute();
docCanvas->makeSelection(0, 0, 1, 1, false, false);
docCanvas->makeSelection(-1, -1, 0, 0, false, false);
docCanvas->closeSelection();
EXPECT_EQ(0, docCanvas->selection().asVector().size());
unsigned int i = 0;
docCanvas->entityContainer().each<LCViewer::LCVDrawItem>([&](LCViewer::LCVDrawItem_SPtr di) {
if(di->selected() == true) {
i++;
}
});
EXPECT_TRUE(i == docCanvas->selection().asVector().size());
}
TEST(SelectionTest, DeselectAddTo) {
auto storageManager = std::make_shared<lc::StorageManagerImpl>();
auto document = std::make_shared<DocumentImpl>(storageManager);
auto docCanvas = std::make_shared<LCViewer::DocumentCanvas>(document);
auto layer = std::make_shared<Layer>("0", Color(1., 1., 1., 1.));
std::shared_ptr<lc::operation::AddLayer> al = std::make_shared<lc::operation::AddLayer>(document, layer);
al->execute();
auto builder = std::make_shared<operation::Builder>(document);
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(0,0,0), lc::geo::Coordinate(0, 10, 0), layer));
builder->append(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(10,0,0), lc::geo::Coordinate(10, 10, 0), layer));
builder->execute();
docCanvas->makeSelection(0, 0, 1, 1, false, false);
docCanvas->closeSelection();
docCanvas->makeSelection(9, 0, 1, 1, false, true);
docCanvas->makeSelection(11, 0, 0, 0, false, true);
docCanvas->closeSelection();
EXPECT_EQ(1, docCanvas->selection().asVector().size());
unsigned int i = 0;
docCanvas->entityContainer().each<LCViewer::LCVDrawItem>([&](LCViewer::LCVDrawItem_SPtr di) {
if(di->selected() == true) {
i++;
}
});
EXPECT_TRUE(i == docCanvas->selection().asVector().size());
}

0 comments on commit 92c1657

Please sign in to comment.