Elements  6.2
A C++ base framework for the Euclid Software.
ElementsExamples/tests/src/GMock/TemplatedDataSourceUser_test.cpp

Example that shows the usage of the EnableGMock.h file.

/*
* @file TemplatedDataSourceUser_test.cpp
*
* @copyright 2012-2020 Euclid Science Ground Segment
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "ElementsExamples/TemplatedDataSourceUser.h" // Access the objects you want to test
#include "ElementsKernel/EnableGMock.h" // initialize the gmock framework
#include "ElementsKernel/Real.h" // isEqual
#include "DataSourceUserTemplatedTypeMock.h" // Access the needed mock objects.
using Elements::Examples::DataSourceUserTemplatedTypeMock;
using testing::Return;
BOOST_AUTO_TEST_SUITE(TemplatedDataSourceUser_test_suite)
BOOST_AUTO_TEST_CASE(sumRecords_test) {
// Setup mock
DataSourceUserTemplatedTypeMock data_source_mock;
EXPECT_CALL(data_source_mock, countRecords()).Times(1).WillOnce(Return(5));
for (size_t index = 0; index < 5; ++index) {
EXPECT_CALL(data_source_mock, getRecordValue(index)).Times(1).WillOnce(Return(static_cast<double>(index) + 1.));
}
// object to test
double result = user.sumRecords<DataSourceUserTemplatedTypeMock>(data_source_mock);
BOOST_CHECK_MESSAGE(Elements::isEqual(result, 15.), "Expected value :" << 15 << " Actual value :" << result);
}
// Ends the test suite
BOOST_AUTO_TEST_SUITE_END()
Elements::isEqual
bool isEqual(const RawType &left, const RawType &right)
Definition: Real.h:347
TemplatedDataSourceUser.h
Elements::Examples::TemplatedDataSourceUser::sumRecords
double sumRecords(const T &data_source)
Compute the sum of the values of the records stored into the provided DataSource.
Elements::Examples::TemplatedDataSourceUser
This class has been created to demonstrate unit testing. It manipulate an object representing a DataS...
Definition: TemplatedDataSourceUser.h:39
Real.h
Floating point comparison implementations.
EnableGMock.h
Google Mock helper classes.