mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Merge pull request #117 from Flamefire/remove-fixture
Improve use of fixture in test_matcher
This commit is contained in:
commit
127d7e4659
3 changed files with 99 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<void(std::string)> 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<void(const char*)> 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)
|
||||
{
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <turtle/matcher.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
template<typename Expected, typename Actual>
|
||||
|
|
@ -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<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)
|
||||
{
|
||||
using mock::detail::multi_matcher;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue