Commit aa8e9801 authored by Hossain Mahmud's avatar Hossain Mahmud Committed by Christian Schulte zu Berge
Browse files

added DataContainer, StringProperty aka GenericProperty, NumericProperty test...

added DataContainer, StringProperty aka GenericProperty, NumericProperty test code and reorganized the folders
parent 09b1873a
......@@ -7,11 +7,16 @@ MESSAGE(STATUS "Configuring googletest for campvis Modules")
#RESOLVE_MODULE_DEPENDENCIES()
#WRITE_PIPELINE_REGISTRATION("gen_pipelineregistration.h")
FILE(GLOB TestCampvisHeaders
FILE(GLOB TestCampvisHeaders RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.h
)
FILE(GLOB TestCampvisSources
FILE(GLOB TestCampvisSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.cpp
core/datastructures/*.cpp
core/properties/*.cpp
#classification/*.cpp
#eventhandlers/*.cpp
#pipeline/*.cpp
)
# Summary of tuple support for Microsoft Visual Studio:
......@@ -35,6 +40,6 @@ INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CampvisModulesIncludeDirs} ${C
TARGET_LINK_LIBRARIES(test-campvis campvis-modules campvis-core tgt gtest ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs})
IF(CAMPVIS_GROUP_SOURCE_FILES)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisSources ${CampvisHome} "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisHeaders ${CampvisHome} "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisSources ${CampvisHome}/test "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisHeaders ${CampvisHome}/test "")
ENDIF()
#include "gtest/gtest.h"
#include "core/datastructures/datacontainer.h"
#include "core/datastructures/datahandle.h"
#include "core/datastructures/imagedata.h"
using namespace campvis;
class DataContainerTest : public ::testing::Test {
protected:
DataContainerTest() {
this->_data = new ImageData(2, tgt::svec3(1,2,3), 4);
this->_dc0 = new DataContainer("dc0");
}
~DataContainerTest() {
delete this->_dc0;
}
virtual void SetUp() {
}
virtual void TearDown() {
}
protected:
DataContainer *_dc0;
AbstractData * _data;
};
TEST_F(DataContainerTest, addDataTest) {
EXPECT_EQ(nullptr, this->_dc0->getData("data1").getData());
this->_dc0->addData("data1", this->_data);
EXPECT_EQ(this->_data, this->_dc0->getData("data1").getData());
}
TEST_F(DataContainerTest, getDataTest) {
EXPECT_EQ(nullptr, this->_dc0->getData("data1").getData());
this->_dc0->addData("data1", this->_data);
EXPECT_EQ(this->_data, this->_dc0->getData("data1").getData());
}
TEST_F(DataContainerTest, removeDataTest) {
EXPECT_EQ(nullptr, this->_dc0->getData("data1").getData());
this->_dc0->addData("data1", this->_data);
EXPECT_EQ(this->_data, this->_dc0->getData("data1").getData());
this->_dc0->removeData("data1");
EXPECT_EQ(nullptr, this->_dc0->getData("data1").getData());
}
TEST_F(DataContainerTest, addDataHandleTest) {
EXPECT_EQ(nullptr, this->_dc0->getData("data1").getData());
this->_dc0->addDataHandle("data1", DataHandle(this->_data));
EXPECT_EQ(this->_data, this->_dc0->getData("data1").getData());
}
TEST_F(DataContainerTest, hasDataTest) {
EXPECT_EQ(false, this->_dc0->hasData("data1"));
this->_dc0->addDataHandle("data1", DataHandle(this->_data));
EXPECT_EQ(true, this->_dc0->hasData("data1"));
this->_dc0->removeData("data1");
EXPECT_EQ(false, this->_dc0->hasData("data1"));
}
TEST_F(DataContainerTest, getDataHandlesCopyTest) {
EXPECT_EQ(0, this->_dc0->getDataHandlesCopy().size());
this->_dc0->addData("data1", this->_data);
EXPECT_EQ(1, this->_dc0->getDataHandlesCopy().size());
std::pair<std::string, DataHandle> pair = this->_dc0->getDataHandlesCopy()[0];
EXPECT_EQ("data1", pair.first);
EXPECT_EQ(this->_data, pair.second.getData());
}
TEST_F(DataContainerTest, getNameTest) {
EXPECT_EQ("dc0", this->_dc0->getName());
}
TEST_F(DataContainerTest, concurrentAccessTest) {
this->_dc0->addData("data1", this->_data);
DataHandle dh = this->_dc0->getData("data1");
AbstractData *someData = new ImageData(2, tgt::svec3(1,2,3), 4);
this->_dc0->addData("data1", someData);
EXPECT_EQ(someData, this->_dc0->getData("data1").getData());
EXPECT_NE(_data, this->_dc0->getData("data1").getData());
EXPECT_EQ(_data, dh.getData());
}
// include gtest library
#include "gtest/gtest.h"
// include(s) for class to be tested
#include "core/datastructures/datahandle.h"
// additional dependency includes
#include "core/datastructures/imagedata.h"
......
......@@ -50,13 +50,13 @@ TEST_F(ImageSeriesTest, addImageTest) {
}
TEST_F(ImageSeriesTest, getImageTest) {
//EXPECT_EQ(_dh.getData(), &_imgSeries2.getImage(_imgSeries2.getNumImages()-1).getData());
EXPECT_EQ(_dh.getTimestamp(), _imgSeries2.getImage(_imgSeries2.getNumImages()-1).getTimestamp());
EXPECT_EQ(_dh.getData(), _imgSeries3.getImage(_imgSeries3.getNumImages()-1).getData());
}
TEST_F(ImageSeriesTest, getLocalMemoryFootprintTest) {
SUCCEED();
}
TEST_F(ImageSeriesTest, getVideoMemoryFootprintTest) {
SUCCEED();
}
......
#include "gtest/gtest.h"
#include "core/properties//numericproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/abstractproperty.h"
#include "core/pipeline/abstractprocessor.h"
using namespace campvis;
class NumericPropertyTest : public ::testing::Test {
protected:
NumericPropertyTest()
: imax(10), imin(-10), istep(1)
, _intProp("intProp", "title_intProp", 0, -10, 10, 1, AbstractProcessor::INVALID_RESULT)
, _intProp2("intProp2", "title_intProp2", 0, -10, 10, 1, AbstractProcessor::INVALID_RESULT)
, dmax(1), dmin(-1), dstep(0.1)
, _doubleProp("_doubleProp", "title_doubleProp", 0, -1, 1, 0.1, AbstractProcessor::INVALID_RESULT)
{
}
~NumericPropertyTest() {
}
virtual void SetUp() {
}
virtual void TearDown() {
}
protected:
NumericProperty<int> _intProp;
NumericProperty<int> _intProp2;
NumericProperty<double> _doubleProp;
protected:
int imax, imin, istep;
double dmax, dmin, dstep;
};
TEST_F(NumericPropertyTest, maxTest) {
this->_intProp.setValue(imax);
EXPECT_EQ(imax, this->_intProp.getValue());
this->_intProp.setValue(imax + 1);
EXPECT_EQ(imax, this->_intProp.getValue());
this->_doubleProp.setValue(dmax);
EXPECT_DOUBLE_EQ(dmax, this->_doubleProp.getValue());
this->_doubleProp.setValue(dmax + 0.01);
EXPECT_DOUBLE_EQ(dmax, this->_doubleProp.getValue());
}
TEST_F(NumericPropertyTest, minTest) {
this->_intProp.setValue(imin);
EXPECT_EQ(imin, this->_intProp.getValue());
this->_intProp.setValue(imin - 1);
EXPECT_EQ(imin, this->_intProp.getValue());
this->_doubleProp.setValue(dmin);
EXPECT_DOUBLE_EQ(dmin, this->_doubleProp.getValue());
this->_doubleProp.setValue(dmin - 0.01);
EXPECT_DOUBLE_EQ(dmin, this->_doubleProp.getValue());
}
TEST_F(NumericPropertyTest, increaseTest) {
EXPECT_EQ(0, this->_intProp.getValue());
this->_intProp.increment();
EXPECT_EQ(istep, this->_intProp.getValue());
this->_intProp.setValue(imax);
EXPECT_EQ(imax, this->_intProp.getValue());
this->_intProp.increment();
EXPECT_EQ(imax, this->_intProp.getValue());
EXPECT_EQ(0, this->_doubleProp.getValue());
this->_doubleProp.increment();
EXPECT_EQ(dstep, this->_doubleProp.getValue());
this->_doubleProp.setValue(dmax);
EXPECT_EQ(dmax, this->_doubleProp.getValue());
this->_doubleProp.increment();
EXPECT_EQ(dmax, this->_doubleProp.getValue());
}
TEST_F(NumericPropertyTest, decreaseTest) {
EXPECT_EQ(0, this->_intProp.getValue());
this->_intProp.decrement();
EXPECT_EQ(-istep, this->_intProp.getValue());
this->_intProp.setValue(imin);
EXPECT_EQ(imin, this->_intProp.getValue());
this->_intProp.decrement();
EXPECT_EQ(imin, this->_intProp.getValue());
EXPECT_EQ(0, this->_doubleProp.getValue());
this->_doubleProp.decrement();
EXPECT_EQ(-dstep, this->_doubleProp.getValue());
this->_doubleProp.setValue(dmin);
EXPECT_EQ(dmin, this->_doubleProp.getValue());
this->_doubleProp.decrement();
EXPECT_EQ(dmin, this->_doubleProp.getValue());
}
/**
* Other Generic Tests
*/
TEST_F(NumericPropertyTest, getValueTest) {
EXPECT_EQ(0, this->_intProp.getValue());
}
TEST_F(NumericPropertyTest, setValueTest) {
this->_intProp.setValue(5);
EXPECT_EQ(5, this->_intProp.getValue());
}
TEST_F(NumericPropertyTest, addSharedPropertyTest) {
this->_intProp.addSharedProperty(&this->_intProp2);
EXPECT_EQ(this->_intProp.getValue(), this->_intProp2.getValue());
EXPECT_EQ(0, this->_intProp2.getValue());
}
TEST_F(NumericPropertyTest, getSharedPropertiesTest) {
std::set<AbstractProperty*> sharedProps = this->_intProp.getSharedProperties();
EXPECT_EQ(0, sharedProps.size());
this->_intProp.addSharedProperty(&this->_intProp2);
sharedProps = this->_intProp.getSharedProperties();
EXPECT_EQ(1, sharedProps.size());
AbstractProperty *prop = *sharedProps.begin();
EXPECT_EQ(this->_intProp2.getName(), prop->getName());
}
TEST_F(NumericPropertyTest, removeSharedPropertyTest) {
this->_intProp.addSharedProperty(&this->_intProp2);
EXPECT_EQ(this->_intProp.getValue(), this->_intProp2.getValue());
EXPECT_EQ(0, this->_intProp2.getValue());
this->_intProp.removeSharedProperty(&this->_intProp2);
EXPECT_EQ(this->_intProp.getValue(), this->_intProp2.getValue());
EXPECT_EQ(0, this->_intProp2.getValue());
this->_intProp.setValue(1);
EXPECT_EQ(1, this->_intProp.getValue());
EXPECT_EQ(0, this->_intProp2.getValue());
}
TEST_F(NumericPropertyTest, lockTest) {
this->_intProp.addSharedProperty(&this->_intProp2);
this->_intProp.setValue(0);
EXPECT_EQ(this->_intProp.getValue(), this->_intProp2.getValue());
EXPECT_EQ(0, this->_intProp2.getValue());
this->_intProp.lock();
EXPECT_EQ(this->_intProp.getValue(), this->_intProp2.getValue());
EXPECT_EQ(0, this->_intProp2.getValue());
this->_intProp.setValue(1);
EXPECT_EQ(0, this->_intProp.getValue());
EXPECT_EQ(0, this->_intProp2.getValue());
}
TEST_F(NumericPropertyTest, unlockTest) {
this->_intProp.addSharedProperty(&this->_intProp2);
this->_intProp.setValue(0);
this->_intProp.lock();
this->_intProp.setValue(1);
EXPECT_EQ(0, this->_intProp.getValue());
EXPECT_EQ(0, this->_intProp2.getValue());
this->_intProp.unlock();
EXPECT_EQ(1, this->_intProp.getValue());
EXPECT_EQ(1, this->_intProp2.getValue());
}
#include "gtest/gtest.h"
#include "core/properties/genericproperty.h"
#include "core/properties/abstractproperty.h"
#include "core/pipeline/abstractprocessor.h"
using namespace campvis;
class StringPropertyTest : public ::testing::Test {
protected:
StringPropertyTest()
: _strProp1("prop1", "title_prop1", "value1", AbstractProcessor::INVALID_RESULT)
, _strProp2("prop2", "title_prop2", "value2", AbstractProcessor::INVALID_RESULT)
{
}
~StringPropertyTest() {
}
virtual void SetUp() {
}
virtual void TearDown() {
}
protected:
StringProperty _strProp1;
StringProperty _strProp2;
};
TEST_F(StringPropertyTest, getValueTest) {
EXPECT_EQ("value1", this->_strProp1.getValue());
}
TEST_F(StringPropertyTest, setValueTest) {
this->_strProp1.setValue("anotherValue");
EXPECT_EQ("anotherValue", this->_strProp1.getValue());
}
TEST_F(StringPropertyTest, addSharedPropertyTest) {
this->_strProp1.addSharedProperty(&this->_strProp2);
EXPECT_EQ(this->_strProp1.getValue(), this->_strProp2.getValue());
EXPECT_EQ("value1", this->_strProp2.getValue());
}
TEST_F(StringPropertyTest, getSharedPropertiesTest) {
std::set<AbstractProperty*> sharedProps = this->_strProp1.getSharedProperties();
EXPECT_EQ(0, sharedProps.size());
this->_strProp1.addSharedProperty(&this->_strProp2);
sharedProps = this->_strProp1.getSharedProperties();
EXPECT_EQ(1, sharedProps.size());
AbstractProperty *prop = *sharedProps.begin();
EXPECT_EQ(this->_strProp2.getName(), prop->getName());
}
TEST_F(StringPropertyTest, removeSharedPropertyTest) {
this->_strProp1.addSharedProperty(&this->_strProp2);
EXPECT_EQ(this->_strProp1.getValue(), this->_strProp2.getValue());
EXPECT_EQ("value1", this->_strProp2.getValue());
this->_strProp1.removeSharedProperty(&this->_strProp2);
EXPECT_EQ(this->_strProp1.getValue(), this->_strProp2.getValue());
EXPECT_EQ("value1", this->_strProp2.getValue());
this->_strProp1.setValue("someValue");
EXPECT_EQ("someValue", this->_strProp1.getValue());
EXPECT_EQ("value1", this->_strProp2.getValue());
}
TEST_F(StringPropertyTest, lockTest) {
this->_strProp1.addSharedProperty(&this->_strProp2);
this->_strProp1.setValue("oldValue");
EXPECT_EQ(this->_strProp1.getValue(), this->_strProp2.getValue());
EXPECT_EQ("oldValue", this->_strProp2.getValue());
this->_strProp1.lock();
EXPECT_EQ(this->_strProp1.getValue(), this->_strProp2.getValue());
EXPECT_EQ("oldValue", this->_strProp2.getValue());
this->_strProp1.setValue("newValue");
EXPECT_EQ("oldValue", this->_strProp1.getValue());
EXPECT_EQ("oldValue", this->_strProp2.getValue());
}
TEST_F(StringPropertyTest, unlockTest) {
this->_strProp1.addSharedProperty(&this->_strProp2);
this->_strProp1.setValue("oldValue");
this->_strProp1.lock();
this->_strProp1.setValue("newValue");
EXPECT_EQ("oldValue", this->_strProp1.getValue());
EXPECT_EQ("oldValue", this->_strProp2.getValue());
this->_strProp1.unlock();
EXPECT_EQ("newValue", this->_strProp1.getValue());
EXPECT_EQ("newValue", this->_strProp2.getValue());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment