I'm having some issues understanding the following behavior of GTest. When I have some members inside the fixture class that are initialized in the initializer list and I use them to initialize another member from the fixture, the following behavior happens.
In the first version the Copy Constructor from B is called and then the Parametrized Constructor of B. In the second version first the Parametrized constructor and then the Copy Constructor is called. My understanding is that the behavior should me similar in the first version and in the second version, however the right behavior is seen only in the second version. If I want to add some members like in the first version how should I do?
class ConfigEndpoint
{
ConfigEndpoint (const B& f_bar0 = B(),
const B& f_bar1 = B(),
const B& f_bar2 = B() )
};
ConfigEndpoint::ConfigEndpoint (const B& f_bar0 = B(),
const B& f_bar1 = B(),
const B& f_bar2 = B() )
: array {f_bar0, f_bar1, f_bar2} {}
Class B has two types of constructors:
// Default one:
B::B()
: m_space(MEMORY),
m_type(32BIT),
m_isConfigured(false)
{}
// Parametrized one:
B::B(int f_barSpace,
int f_barType)
: m_space(f_barSpace),
m_type(f_barType),
m_isConfigured(true)
{}
**//TestFixture -> version 1.**
class CConfigTest : public ::testing::TestWithParam<std::tuple<driverStartAddress, bool>>
{
public:
CConfigTest() :
bar0(MEMORY, 32BIT),
bar1(MEMORY, 32BIT),
bar2(MEMORY, 32BIT),
configEndpoint(bar0,
bar1,
bar2)
{ }
ConfigEndpoint configEndpoint;
const B bar0;
const B bar1;
const B bar2;
};
**//TestFixture -> version 2.**
class CConfigTest : public ::testing::TestWithParam<std::tuple<driverStartAddress, bool>>
{
public:
CConfigTest()
:
configEndpoint( B(MEMORY, 32BIT),
B(MEMORY, 32BIT),
B(MEMORY, 32BIT) )
{ }
ConfigEndpoint configEndpoint;
};