Commit caa8f1c2 authored by Hossain Mahmud's avatar Hossain Mahmud Committed by Christian Schulte zu Berge

added the documentation (brief). added test class for StringUtils. trimmed out...

added the documentation (brief). added test class for StringUtils. trimmed out the redundant code segments.
parent aa8e9801
......@@ -64,17 +64,17 @@ namespace campvis {
*
* \param str Input string to parse.
*
* \note TODO: The detection algorithm is a litte simplified and will not yield correct results
* \note TODO: The detection algorithm is a little simplified and will not yield correct results
* in every case.
**/
static std::vector<std::string> parseFloats(const std::string& str);
/**
* Replaces all occurences of \a from in \a str with \a to.
* Replaces all occurrences of \a from in \a str with \a to.
* \param str String to perform replacement on.
* \param from String to be replaced.
* \param to String repace.
* \return \a str with all occurences of \a from replaced with \a to.
* \param to String replace.
* \return \a str with all occurrences of \a from replaced with \a to.
*/
static std::string replaceAll(const std::string& str, const std::string& from, const std::string& to);
......@@ -101,7 +101,7 @@ namespace campvis {
/**
* Trims the string \a str.
* All leading and trailing occurences of the characters in \a whitespace will be removed.
* All leading and trailing occurrences of the characters in \a whitespace will be removed.
*
* \param str The string to trim.
* \param whitespace Set of whitespace characters which shall be removed at the beginning and the end.
......
......@@ -14,7 +14,7 @@ FILE(GLOB TestCampvisSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
*.cpp
core/datastructures/*.cpp
core/properties/*.cpp
#classification/*.cpp
core/tools/*.cpp
#eventhandlers/*.cpp
#pipeline/*.cpp
)
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
#include "core/datastructures/datacontainer.h"
......@@ -7,6 +36,9 @@
using namespace campvis;
/**
* Test class for DataContainer class
*/
class DataContainerTest : public ::testing::Test {
protected:
DataContainerTest() {
......@@ -29,42 +61,36 @@ protected:
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());
}
/**
* Tests the trivial operations of the class.
* getName()
* addData()
* addDataHandle()
* getData()
* hasData()
* removeData()
*/
TEST_F(DataContainerTest, miscellaneousTest) {
EXPECT_EQ("dc0", this->_dc0->getName());
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->addDataHandle("data2", DataHandle(this->_data));
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());
}
// TODO: if the addDataHandle is called here instead of above
// this->_dc0->addDataHandle("data2", DataHandle(this->_data));
// the program crashes. Find why!!
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"));
EXPECT_EQ(true, this->_dc0->hasData("data2"));
}
/**
* Tests the function getDataHandlesCopy.
*/
TEST_F(DataContainerTest, getDataHandlesCopyTest) {
EXPECT_EQ(0, this->_dc0->getDataHandlesCopy().size());
this->_dc0->addData("data1", this->_data);
......@@ -74,10 +100,12 @@ TEST_F(DataContainerTest, getDataHandlesCopyTest) {
EXPECT_EQ(this->_data, pair.second.getData());
}
TEST_F(DataContainerTest, getNameTest) {
EXPECT_EQ("dc0", this->_dc0->getName());
}
/**
* Tests the concurrent access settings of the class.
*
* DataHandle of previously added data obtained with getData() should remains valid
* even if the data in the container is replaced with new data.
*/
TEST_F(DataContainerTest, concurrentAccessTest) {
this->_dc0->addData("data1", this->_data);
DataHandle dh = this->_dc0->getData("data1");
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
#include "core/datastructures/datahandle.h"
#include "core/datastructures/imagedata.h"
/**
* Test class for DataHandle class. This class along with ImageDataTest and
* ImageSeriesTest completes the overall test environments for DataHandle and
* AbstractData.
*/
class DataHandleTest : public testing::Test {
protected:
DataHandleTest() {
......@@ -17,11 +50,9 @@ protected:
}
~DataHandleTest() {
//delete _data1;
//delete _data1; // DON'T mess with data added to the DataHandle. More at DataHanlde.h
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following two methods
virtual void SetUp() {
}
......
// include gtest library
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
// include(s) for class to be tested
#include "core/datastructures/imagedata.h"
// additional dependency includes
#include "core/datastructures/imagedata.h"
/**
* Test class for ImageData class.
*/
class ImageDataTest : public testing::Test {
protected:
ImageDataTest() {
......@@ -36,15 +64,45 @@ protected:
};
TEST_F(ImageDataTest, initTest) {
/**
* Tests the trivial operations of the class.
* initialization
* getDimensionality()
* getNumChannels()
* getNumElements()
* getWorldBounds()
* get/setMappingInformation()
* positionToIndex()/indexToPosition()
*/
TEST_F(ImageDataTest, miscellaneousTest) {
ASSERT_TRUE(nullptr != _imgData1);
EXPECT_EQ(2, _imgData0->getDimensionality());
EXPECT_EQ(4, _imgData0->getNumChannels());
EXPECT_EQ(tgt::hmul(tgt::svec3(1,2,3)), _imgData0->getNumElements());
EXPECT_EQ(tgt::svec3(1,2,3).size, _imgData0->getSize().size);
tgt::Bounds bound0 = _imgData0->getWorldBounds();
tgt::Bounds bound1 = _imgData1->getWorldBounds();
EXPECT_EQ(bound0, bound1);
campvis::ImageData temp = campvis::ImageData(3, tgt::svec3(3,2,1), 5);
temp.setMappingInformation(_imgData0->getMappingInformation());
EXPECT_TRUE(temp.getMappingInformation() == _imgData0->getMappingInformation());
tgt::svec3 vec(1, 2, 3);
_imgData0->positionToIndex(vec);
EXPECT_EQ(1, 1);
size_t sz = 3;
_imgData0->indexToPosition(sz);
EXPECT_EQ(1, 1);
}
/**
* Tests the clone() function.
*/
TEST_F(ImageDataTest, cloneTest) {
ASSERT_TRUE(nullptr != _imgData1);
......@@ -59,19 +117,11 @@ TEST_F(ImageDataTest, cloneTest) {
EXPECT_EQ(_imgData0->getVideoMemoryFootprint(), _imgData1->getVideoMemoryFootprint());
}
TEST_F(ImageDataTest, getSetMappingInformationTest) {
campvis::ImageData temp = campvis::ImageData(3, tgt::svec3(3,2,1), 5);
temp.setMappingInformation(_imgData0->getMappingInformation());
EXPECT_TRUE(temp.getMappingInformation() == _imgData0->getMappingInformation());
}
TEST_F(ImageDataTest, getWorldBoundsTest) {
tgt::Bounds bound0 = _imgData0->getWorldBounds();
tgt::Bounds bound1 = _imgData1->getWorldBounds();
EXPECT_EQ(bound0, bound1);
}
/**
* Tests getSubImage() method.
*
* For test cases 1. whole image and 2. images of size (1,1,1) were checked
*/
TEST_F(ImageDataTest, getSubImageTest) {
campvis::ImageData *cloned = _imgData0->getSubImage(tgt::svec3(0,0,0), _imgData0->getSize());
......@@ -92,15 +142,3 @@ TEST_F(ImageDataTest, getSubImageTest) {
cloned = _imgData0->getSubImage(_imgData0->getSize()-tgt::svec3(1,1,1), _imgData0->getSize());
EXPECT_EQ(tgt::svec3(1,1,1), cloned->getSize());
}
TEST_F(ImageDataTest, positionToIndexTest) {
tgt::svec3 vec(1, 2, 3);
size_t sz = _imgData0->positionToIndex(vec);
EXPECT_EQ(1, 1);
}
TEST_F(ImageDataTest, indexToPositionTest) {
size_t sz = 3;
tgt::svec3 vec = _imgData0->indexToPosition(sz);
EXPECT_EQ(1, 1);
}
// include gtest library
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
// include(s) for class to be tested
#include "core/datastructures/imageseries.h"
// additional includes
#include "core/datastructures/imagedata.h"
/**
* Test class for ImageSeries class.
*/
class ImageSeriesTest : public testing::Test {
protected:
ImageSeriesTest() {
......@@ -18,12 +46,10 @@ protected:
_imgSeries3.addImage(_dh);
}
~ImageSeriesTest() {
//delete _image;
~ImageSeriesTest() {
//delete _image; // Don't even think about it. Check DataHandle.h
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following two methods
virtual void SetUp() {
}
......@@ -38,29 +64,28 @@ protected:
};
TEST_F(ImageSeriesTest, getNumImageTest) {
/**
* Tests trivial functions of the class
*
* addImage()
* getNumImages()
* getImage()
*/
TEST_F(ImageSeriesTest, miscellaneousTest) {
EXPECT_EQ(0, _imgSeries1.getNumImages());
EXPECT_EQ(1, _imgSeries2.getNumImages());
EXPECT_EQ(1, _imgSeries3.getNumImages());
}
TEST_F(ImageSeriesTest, addImageTest) {
_imgSeries3.addImage(_image);
EXPECT_EQ(2, _imgSeries3.getNumImages());
}
TEST_F(ImageSeriesTest, getImageTest) {
EXPECT_EQ(_dh.getData(), _imgSeries3.getImage(_imgSeries3.getNumImages()-1).getData());
}
TEST_F(ImageSeriesTest, getLocalMemoryFootprintTest) {
SUCCEED();
}
TEST_F(ImageSeriesTest, getVideoMemoryFootprintTest) {
SUCCEED();
}
/**
* Tests the method clone()
*/
TEST_F(ImageSeriesTest, cloneTest) {
campvis::ImageSeries* tempSeries = _imgSeries2.clone();
EXPECT_EQ(_imgSeries2.getNumImages(), tempSeries->getNumImages());
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
#include "core/datastructures/renderdata.h"
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
/**
* Author: Hossain Mahmud <mahmud@in.tum.de>
* Date: March 2014
*/
#include "gtest/gtest.h"
#include "core/properties//numericproperty.h"
......@@ -8,6 +37,12 @@
using namespace campvis;
/**
* Test class for NumericProperty. The units from GenericProperty and AbstractProperty are
* are being tested at StringPropertyTest. Here are the additional max/min related tests.
*/
class NumericPropertyTest : public ::testing::Test {
protected:
NumericPropertyTest()
......@@ -30,15 +65,17 @@ protected:
}
protected:
int imax, imin, istep;
NumericProperty<int> _intProp;
NumericProperty<int> _intProp2;
double dmax, dmin, dstep;
NumericProperty<double> _doubleProp;
protected:
int imax, imin, istep;
double dmax, dmin, dstep;
};
/**
* Checks whether the value get clamped at the max limit.
*/
TEST_F(NumericPropertyTest, maxTest) {
this->_intProp.setValue(imax);
EXPECT_EQ(imax, this->_intProp.getValue());
......@@ -51,6 +88,9 @@ TEST_F(NumericPropertyTest, maxTest) {
EXPECT_DOUBLE_EQ(dmax, this->_doubleProp.getValue());
}
/**
* Checks whether the value get clamped at the min limit.
*/
TEST_F(NumericPropertyTest, minTest) {
this->_intProp.setValue(imin);
EXPECT_EQ(imin, this->_intProp.getValue());
......@@ -63,6 +103,9 @@ TEST_F(NumericPropertyTest, minTest) {
EXPECT_DOUBLE_EQ(dmin, this->_doubleProp.getValue());
}
/**
* Checks whether the value is clamped at the max limit. It should.
*/
TEST_F(NumericPropertyTest, increaseTest) {
EXPECT_EQ(0, this->_intProp.getValue());
this->_intProp.increment();
......@@ -83,6 +126,10 @@ TEST_F(NumericPropertyTest, increaseTest) {
EXPECT_EQ(dmax, this->_doubleProp.getValue());
}
/**
* Checks whether the value is clamped at the min limit. It should.
*/
TEST_F(NumericPropertyTest, decreaseTest) {
EXPECT_EQ(0, this->_intProp.getValue());
this->_intProp.decrement();
......@@ -101,77 +148,4 @@ TEST_F(NumericPropertyTest, decreaseTest) {
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());