Home | Libraries | People | FAQ | More |
BOOST_EQUAL(
lhs
, rhs
)
compares the two arguments with operator==
. The diagnostic message is constructed
with operator<<
on the two arguments.
Important | |
---|---|
If you get a strange compile error when using |
BOOST_AUTO_TEST_CASE(example_equal) { // integral types unsigned const u = 1u; int const i = -1; char const A = 'A'; // standard library types providing operator== and operator<< std::string const s = "scooby"; BOOST_REQUIRE_EQUAL(1u, u); BOOST_REQUIRE_EQUAL(-1, i); BOOST_REQUIRE_EQUAL('A', A); BOOST_REQUIRE_EQUAL("scooby", s); }
// custom data structure struct symbol { char const* const name; int value; }; // custom comparison operator static bool operator==(symbol const& lhs, symbol const& rhs) { return lhs.value == rhs.value && std::string(lhs.name) == std::string(rhs.name); } // custom stream insertion operator static std::ostream& operator<<(std::ostream& stream, symbol const& value) { return stream << value.name << ": " << value.value; } BOOST_AUTO_TEST_CASE(example_equal_custom_compare) { symbol const s1 = { "var" , 1 }; symbol const s2 = { "var", 1 }; // If the compiler doesn't collapse multiple constants, then: // s1.name != s2.name; BOOST_REQUIRE_EQUAL(s1, s2); }