Unit test nullptr C-style strings

Added unit tests for the cases of matching and serializing C-style strings (char*) that are nullptr.

(As of this revision, these new tests correctly fail, except for the test of mock::equal; fix to follow.)
This commit is contained in:
Alex Smith 2023-01-02 17:30:54 +00:00
parent 0dd0dfa15f
commit 528761b180
3 changed files with 26 additions and 1 deletions

View file

@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(ref_to_int_and_int_can_be_compared)
namespace {
struct fixture
{
fixture() : text("same text"), actual(text.c_str())
fixture() : text("same text"), actual(text.c_str()), null_str(nullptr)
{
const char* static_string = "same text";
BOOST_REQUIRE(actual != static_string);
@ -44,6 +44,7 @@ struct fixture
}
std::string text;
const char* actual;
const char* null_str;
};
} // namespace
@ -75,6 +76,13 @@ BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_std_string_can_be_compared, fixtu
BOOST_CHECK(!match(std::string("different text"), actual));
}
BOOST_FIXTURE_TEST_CASE(null_const_char_pointers_can_be_compared, fixture)
{
BOOST_CHECK(match(null_str, null_str));
BOOST_CHECK(!match(null_str, "non-null string"));
BOOST_CHECK(!match("non-null string", null_str));
}
namespace {
template<typename T>
std::string serialize(const T& t)