24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

datacontainertest.cpp 3.74 KB
Newer Older
1 2 3 4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, 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"

#include "core/datastructures/datahandle.h"
#include "core/datastructures/imagedata.h"

using namespace campvis;

/**
 * Test class for DataContainer class
 */
class DataContainerTest : public ::testing::Test {
protected:
    DataContainerTest() {
45
        this->_data = new ImageData(2, cgt::svec3(1,2,1), 4);
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        this->_dc0 = new DataContainer("dc0");
    }

    ~DataContainerTest() {
        delete this->_dc0;
    }

    virtual void SetUp() {
    }

    virtual void TearDown() {
    }

protected:
    DataContainer *_dc0;
    AbstractData * _data;
};

/**
 * Tests the trivial operations of the class.
 * getName()
 * addData()
 * addDataHandle()
 * getData()
 * hasData()
 * removeData()
 */
TEST_F(DataContainerTest, miscellaneousTest) {
    EXPECT_EQ("dc0", this->_dc0->getName());

76
    ASSERT_TRUE(nullptr == this->_dc0->getData("data1").getData());
77
    this->_dc0->addData("data1", this->_data);
78
    ASSERT_TRUE(this->_data == this->_dc0->getData("data1").getData());
79 80 81
    this->_dc0->addDataHandle("data2", DataHandle(this->_data));

    this->_dc0->removeData("data1");
82
    ASSERT_TRUE(nullptr == this->_dc0->getData("data1").getData());
83 84 85 86 87 88 89 90 91 92 93 94 95
    EXPECT_FALSE(this->_dc0->hasData("data1"));
    EXPECT_TRUE(this->_dc0->hasData("data2"));
}

/**
 * Tests the function getDataHandlesCopy.
 */
TEST_F(DataContainerTest, getDataHandlesCopyTest) {
    EXPECT_EQ(0U, this->_dc0->getDataHandlesCopy().size());
    this->_dc0->addData("data1", this->_data);
    EXPECT_EQ(1U, this->_dc0->getDataHandlesCopy().size());
    std::pair<std::string, DataHandle> pair = this->_dc0->getDataHandlesCopy()[0];
    EXPECT_EQ("data1", pair.first);
96
    ASSERT_TRUE(this->_data == pair.second.getData());
97 98 99 100 101 102 103 104 105 106 107
}

/**
 * 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");
108
    AbstractData *someData = new ImageData(2, cgt::svec3(1,2,1), 4);
109 110
    this->_dc0->addData("data1", someData);

111 112 113
    ASSERT_TRUE(someData == this->_dc0->getData("data1").getData());
    ASSERT_FALSE(_data == this->_dc0->getData("data1").getData());
    ASSERT_TRUE(_data == dh.getData());
114
}