diff --git a/appveyor.yml b/appveyor.yml index 40f4560..eb4515a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,6 +33,10 @@ environment: CMAKE: true install: + - appveyor-retry powershell Invoke-WebRequest http://www.oasis-open.org/docbook/xml/4.2/docbook-xml-4.2.zip -OutFile docbook-xml.zip + - appveyor-retry powershell Invoke-WebRequest https://github.com/docbook/xslt10-stylesheets/releases/download/release/1.79.2/docbook-xsl-1.79.2.zip -OutFile docbook-xsl.zip + - 7z x -oC:\Boost\share\docbook-xml docbook-xml.zip + - 7z x -oC:\Boost\share docbook-xsl.zip - mkdir %APPVEYOR_BUILD_FOLDER%\bin - cd %APPVEYOR_BUILD_FOLDER%\bin - appveyor-retry powershell Invoke-WebRequest ftp://ftp.zlatkovic.com/libxml/iconv-1.9.2.win32.zip -OutFile iconv.zip diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index bd640a2..59ed333 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -158,6 +158,56 @@ BOOST_FIXTURE_TEST_CASE(triggering_several_once_expectations_is_valid, mock_erro } } +BOOST_FIXTURE_TEST_CASE(string_likes_are_matched, mock_error_fixture) +{ + const char* c_string = "value"; + const char c_string2[] = "value"; + BOOST_REQUIRE(c_string != c_string2); // Different pointers + const std::string string = c_string; + { + mock::detail::function f; + + f.expect().once().with(string); + f(string); + BOOST_TEST(f.verify()); + + f.reset(); + f.expect().once().with(c_string); + f(string); + BOOST_TEST(f.verify()); + + f.reset(); + f.expect().once().with(c_string2); + f(string); + BOOST_TEST(f.verify()); + + CHECK_CALLS(3); + } + { + mock::detail::function f; + + f.expect().once().with(c_string); + f(c_string); + BOOST_TEST(f.verify()); + + f.reset(); + f.expect().once().with(c_string); + f(c_string2); + BOOST_TEST(f.verify()); + + f.reset(); + f.expect().once().with(c_string2); + f(c_string); + BOOST_TEST(f.verify()); + + f.reset(); + f.expect().once().with(string); + f(c_string); + BOOST_TEST(f.verify()); + CHECK_CALLS(4); + } +} + BOOST_FIXTURE_TEST_CASE(triggering_a_once_expectation_calls_unexpected_call_error_after_one_call, mock_error_fixture) { { diff --git a/test/test_matcher.cpp b/test/test_matcher.cpp index 547ecaa..5a53cb3 100644 --- a/test/test_matcher.cpp +++ b/test/test_matcher.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace { template @@ -36,23 +37,27 @@ 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") { - const char* static_string = "same text"; - BOOST_REQUIRE(actual != static_string); - BOOST_REQUIRE(actual == std::string(static_string)); + // Get a pointer to unique memory containing "same text" + actual = text.c_str(); } - std::string text; const char* actual; + +private: + std::string text; }; } // namespace BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_pointer_can_be_compared, fixture) { const char* expected = "same text"; + BOOST_REQUIRE(expected != actual); + BOOST_REQUIRE(std::string(expected) == actual); + BOOST_CHECK(match(expected, actual)); const char* unexpected = "different text"; - BOOST_CHECK(!match(actual, unexpected)); + BOOST_CHECK(!match(unexpected, actual)); } BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_string_literal_can_be_compared, fixture) @@ -63,16 +68,19 @@ BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_string_literal_can_be_compared, f BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_array_can_be_compared, fixture) { - const char expected[10] = "same text"; + const char expected[] = "same text"; + BOOST_REQUIRE(expected != actual); BOOST_CHECK(match(expected, actual)); - const char unexpected[15] = "different text"; + const char unexpected[] = "different text"; BOOST_CHECK(!match(unexpected, actual)); } BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_std_string_can_be_compared, fixture) { BOOST_CHECK(match(std::string("same text"), actual)); + BOOST_CHECK(match(actual, std::string("same text"))); BOOST_CHECK(!match(std::string("different text"), actual)); + BOOST_CHECK(!match(actual, std::string("different text"))); } BOOST_AUTO_TEST_CASE(null_const_char_pointers_can_be_compared) @@ -113,6 +121,11 @@ struct custom_constraint } bool operator()(int actual) { return actual == expected_; } }; + +bool custom_constraint_func(int) +{ + return false; +} } // namespace BOOST_AUTO_TEST_CASE(single_matcher_serializes) @@ -125,6 +138,30 @@ BOOST_AUTO_TEST_CASE(single_matcher_serializes) 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("foo")) == "\"foo\""); + BOOST_TEST(serialize(single_matcher("foo")) == "\"foo\""); + BOOST_TEST(serialize(single_matcher("foo")) == "\"foo\""); + BOOST_TEST(serialize(single_matcher("foo")) == "\"foo\""); + BOOST_TEST(serialize(single_matcher("foo")) == "\"foo\""); + BOOST_TEST(serialize(single_matcher("foo")) == "\"foo\""); + BOOST_TEST(serialize(single_matcher("foo")) == "\"foo\""); + // Mixed types + BOOST_TEST(serialize(single_matcher("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(custom_constraint_func)) == "?"); + BOOST_TEST(serialize(single_matcher(custom_constraint_func)) == "?"); + // Mixed types + BOOST_TEST(serialize(single_matcher(custom_constraint_func, 2)) == "?, 2"); +} + BOOST_AUTO_TEST_CASE(multi_matcher_serializes) { using mock::detail::multi_matcher;