I am trying to create a test fixture class from a normal class with constructor declaration (with arguments) as shown below:
hello.h
class hello
{
public:
hello(const uint32_t argID, const uint8_t argCommand);
virtual ~hello();
void initialize();
};
where uint32_t is: typedef unsigned int
and uint8_t is: typedef unsigned char
My Test Fixture Class:
helloTestFixture.h
class helloTestFixture:public testing::Test
{
public:
helloTestFixture(/*How to carry out the constructor declaration in this test fixture class corresponding to the above class?*/);
virtual ~helloTestFixture();
hello m_object;
};
TEST_F(helloTestFixture, InitializeCheck) // Test to access the 'intialize' function
{
m_object.initialize();
}
After trying to implement the above code, it gives me the error:
Error C2512: no appropriate default constructor available
I was trying to replicate the constructor constructed in the hello.h file into my hellotestfixture.h file. Any way around for doing that? I have tried implementing it in many ways but no success as of yet. Any suggestions on how to implement this?
After not much of code correction, here's what I've got for you in store: An Answer :)
class hello
{
public:
hello(const uint32_t argID, const uint8_t argCommand);
virtual ~hello();
void initialize();
};
hello::hello(const uint32_t argID, const uint8_t argCommand){/* do nothing*/}
hello::~hello(){/* do nothing*/}
void hello::initialize(){/* do nothing*/}
class helloTestFixture
{
public:
helloTestFixture();
virtual ~helloTestFixture();
hello m_object;
};
helloTestFixture::helloTestFixture():m_object(0,0){/* do nothing */}
helloTestFixture::~helloTestFixture(){/* do nothing */}
int main()
{
helloTestFixture htf;
htf.m_object.initialize();
}
This compiles and runs nicely and hope this answers your question. :)