I want to test if my application returns a nullptr unique ptr. I have tried a few things but nothing get through the compiler. I hope someone has already tried and found a way to make this work. Some things i have tried:
std::unique_ptr<SomeClass> some_class_ptr;
CPPUNIT_ASSERT_EQUAL(std::unique_ptr<SomeClass>(), some_class_ptr);
gives: libcppunit/include/cppunit/TestAssert.h|49|error: no match for ‘operator<<’ in ‘ost << x’|
Inside TestAssert.h:
template <class T>
void assertEquals( const T& expected,
const T& actual,
SourceLine sourceLine,
const std::string &message )
{
if ( !assertion_traits<T>::equal(expected,actual) ) // lazy toString conversion...
{
Asserter::failNotEqual( assertion_traits<T>::toString(expected),
assertion_traits<T>::toString(actual),
sourceLine,
message );
}
}
CPPUNIT_ASSERT_EQUAL(nullptr, some_class_ptr);
gives: /tests/SomeTestClass.cpp|432|error: no matching function for call to ‘assertEquals(std::nullptr_t, std::unique_ptr&, CppUnit::SourceLine, const char [1])’|
CPPUNIT_ASSERT_EQUAL(nullptr, some_class_ptr.get());
gives: /tests/SomeTestClass.cpp|432|error: no matching function for call to ‘assertEquals(std::nullptr_t, std::unique_ptr::pointer, CppUnit::SourceLine, const char [1])’|
I think the first one should be the correct one but it is not compiling. Can anyone give me a correct construction for this ?