Add test for serializing a string or functor matcher

This commit is contained in:
Alexander Grund 2023-01-07 12:06:44 +01:00
parent 9f5a8131ae
commit f191de5a5a
No known key found for this signature in database
GPG key ID: AA48A0760367A42B

View file

@ -121,6 +121,11 @@ struct custom_constraint
} }
bool operator()(int actual) { return actual == expected_; } bool operator()(int actual) { return actual == expected_; }
}; };
bool custom_constraint_func(int)
{
return false;
}
} // namespace } // namespace
BOOST_AUTO_TEST_CASE(single_matcher_serializes) BOOST_AUTO_TEST_CASE(single_matcher_serializes)
@ -133,6 +138,30 @@ BOOST_AUTO_TEST_CASE(single_matcher_serializes)
1, 2, custom_constraint(), 4, 5)) == "1, 2, custom42, 4, 5"); 1, 2, custom_constraint(), 4, 5)) == "1, 2, custom42, 4, 5");
} }
BOOST_AUTO_TEST_CASE(string_matcher_serializes)
{
using mock::detail::single_matcher;
BOOST_TEST(serialize(single_matcher<void(const char*), const char*>("foo")) == "\"foo\"");
BOOST_TEST(serialize(single_matcher<void(const std::string&), const char*>("foo")) == "\"foo\"");
BOOST_TEST(serialize(single_matcher<void(const char*), const std::string&>("foo")) == "\"foo\"");
BOOST_TEST(serialize(single_matcher<void(const std::string&), const std::string&>("foo")) == "\"foo\"");
BOOST_TEST(serialize(single_matcher<void(std::string), const char*>("foo")) == "\"foo\"");
BOOST_TEST(serialize(single_matcher<void(const char*), std::string>("foo")) == "\"foo\"");
BOOST_TEST(serialize(single_matcher<void(std::string), std::string>("foo")) == "\"foo\"");
// Mixed types
BOOST_TEST(serialize(single_matcher<void(const char*, int), const char*, int>("bar", 2)) == "\"bar\", 2");
}
BOOST_AUTO_TEST_CASE(functor_matcher_serializes)
{
using mock::detail::single_matcher;
using Functor = decltype(custom_constraint_func);
BOOST_TEST(serialize(single_matcher<void(Functor), int>(custom_constraint_func)) == "?");
BOOST_TEST(serialize(single_matcher<void(Functor), short>(custom_constraint_func)) == "?");
// Mixed types
BOOST_TEST(serialize(single_matcher<void(Functor, int), short, int>(custom_constraint_func, 2)) == "?, 2");
}
BOOST_AUTO_TEST_CASE(multi_matcher_serializes) BOOST_AUTO_TEST_CASE(multi_matcher_serializes)
{ {
using mock::detail::multi_matcher; using mock::detail::multi_matcher;