mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Format code using Clang-Format 10 and enforce via CI
Makes the format of the code base uniform.
This commit is contained in:
parent
b5bb500bd2
commit
ee72e8b9d8
97 changed files with 11189 additions and 10842 deletions
|
|
@ -12,37 +12,36 @@
|
|||
#define MOCK_MAKE_TEST_PASS 1
|
||||
|
||||
#if MOCK_MAKE_TEST_PASS
|
||||
#undef BOOST_AUTO_TEST_CASE
|
||||
#define BOOST_AUTO_TEST_CASE(name) BOOST_FIXTURE_TEST_CASE(name, mock::cleanup)
|
||||
# undef BOOST_AUTO_TEST_CASE
|
||||
# define BOOST_AUTO_TEST_CASE(name) BOOST_FIXTURE_TEST_CASE(name, mock::cleanup)
|
||||
#endif
|
||||
|
||||
//[ static_objects_problem
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace
|
||||
namespace {
|
||||
struct my_class
|
||||
{
|
||||
struct my_class
|
||||
{
|
||||
my_class( int i ) : i_( i )
|
||||
{}
|
||||
my_class(int i) : i_(i) {}
|
||||
|
||||
int i_;
|
||||
};
|
||||
int i_;
|
||||
};
|
||||
|
||||
std::ostream& operator<<( std::ostream& os, const my_class* c )
|
||||
{
|
||||
return os << "my_class " << c->i_; // the 'c' pointer must be valid when logging
|
||||
}
|
||||
|
||||
MOCK_FUNCTION( f, 1, void( my_class* ) ) // being static 'f' outlives the test case
|
||||
std::ostream& operator<<(std::ostream& os, const my_class* c)
|
||||
{
|
||||
return os << "my_class " << c->i_; // the 'c' pointer must be valid when logging
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( static_objects_problem )
|
||||
MOCK_FUNCTION(f, 1, void(my_class*)) // being static 'f' outlives the test case
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(static_objects_problem)
|
||||
{
|
||||
my_class c( 42 );
|
||||
MOCK_EXPECT( f ).once().with( &c ); // the set expectation will also outlive the test case and leak into other test cases using 'f'
|
||||
my_class c(42);
|
||||
MOCK_EXPECT(f).once().with(
|
||||
&c); // the set expectation will also outlive the test case and leak into other test cases using 'f'
|
||||
} // the 'c' instance goes out of scope and the '&c' pointer becomes dangling
|
||||
//]
|
||||
|
||||
|
|
@ -51,25 +50,28 @@ struct fixture
|
|||
{
|
||||
~fixture()
|
||||
{
|
||||
mock::reset(); // the use of a fixture ensures the reset will prevent the expectations from leaking into other test cases
|
||||
mock::reset(); // the use of a fixture ensures the reset will prevent the expectations from leaking into other
|
||||
// test cases
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( static_object_partial_solution, fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(static_object_partial_solution, fixture)
|
||||
{
|
||||
my_class c( 42 );
|
||||
MOCK_EXPECT( f ).once().with( &c );
|
||||
f( &c );
|
||||
my_class c(42);
|
||||
MOCK_EXPECT(f).once().with(&c);
|
||||
f(&c);
|
||||
mock::verify(); // verify the expectations before local objects are destroyed and before the fixture resets them
|
||||
}
|
||||
//]
|
||||
|
||||
//[ static_objects_solution
|
||||
BOOST_FIXTURE_TEST_CASE( static_objects_solution, mock::cleanup ) // actually the library includes a ready to use fixture just like the one described
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
static_objects_solution,
|
||||
mock::cleanup) // actually the library includes a ready to use fixture just like the one described
|
||||
{
|
||||
my_class c( 42 );
|
||||
MOCK_EXPECT( f ).once().with( &c );
|
||||
f( &c );
|
||||
my_class c(42);
|
||||
MOCK_EXPECT(f).once().with(&c);
|
||||
f(&c);
|
||||
mock::verify();
|
||||
}
|
||||
//]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue