mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Merge pull request #107 from Flamefire/clang-format
Format code using Clang-Format 10 and enforce via CI
This commit is contained in:
commit
3dda0bf328
97 changed files with 11189 additions and 10842 deletions
162
.clang-format
Normal file
162
.clang-format
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Mozilla
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: false
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: true
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: AfterColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: true
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 2
|
||||
Cpp11BracedListStyle: false
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '<turtle/'
|
||||
Priority: 10
|
||||
SortPriority: 0
|
||||
- Regex: '<boost/'
|
||||
Priority: 20
|
||||
SortPriority: 0
|
||||
- Regex: '^<'
|
||||
Priority: 30
|
||||
SortPriority: 0
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: true
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: Inner
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: false
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PointerAlignment: Left
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: Never
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
Standard: c++14
|
||||
StatementMacros:
|
||||
- MOCK_BASE_CLASS
|
||||
- MOCK_CLASS
|
||||
- MOCK_CONSTRUCTOR
|
||||
- MOCK_CONSTRUCTOR_TPL
|
||||
- MOCK_CONST_CONVERSION_OPERATOR
|
||||
- MOCK_CONST_CONVERSION_OPERATOR_TPL
|
||||
- MOCK_CONST_METHOD
|
||||
- MOCK_CONST_METHOD_EXT
|
||||
- MOCK_CONST_METHOD_EXT_TPL
|
||||
- MOCK_CONST_METHOD_TPL
|
||||
- MOCK_CONVERSION_OPERATOR
|
||||
- MOCK_DESTRUCTOR
|
||||
- MOCK_METHOD
|
||||
- MOCK_METHOD_EXT
|
||||
- MOCK_METHOD_EXT_TPL
|
||||
- MOCK_METHOD_TPL
|
||||
- MOCK_NON_CONST_CONVERSION_OPERATOR
|
||||
- MOCK_NON_CONST_CONVERSION_OPERATOR_TPL
|
||||
- MOCK_NON_CONST_METHOD
|
||||
- MOCK_NON_CONST_METHOD_EXT
|
||||
- MOCK_NON_CONST_METHOD_EXT_TPL
|
||||
- MOCK_NON_CONST_METHOD_TPL
|
||||
- MOCK_STATIC_METHOD
|
||||
- MOCK_STATIC_METHOD_TPL
|
||||
TabWidth: 4
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
|
|
@ -23,6 +23,15 @@ env:
|
|||
DOCBOOK_DTD_DIR: /usr/share/xml/docbook/schema/dtd/4.2
|
||||
|
||||
jobs:
|
||||
Formatting:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Formatting
|
||||
uses: DoozyX/clang-format-lint-action@v0.13
|
||||
with:
|
||||
clangFormatVersion: 10
|
||||
|
||||
posix:
|
||||
defaults:
|
||||
run:
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
class calculator
|
||||
{
|
||||
view& v;
|
||||
|
||||
public:
|
||||
calculator(view& v) : v(v) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
//[ mock_stream_user_type
|
||||
namespace user_namespace
|
||||
{
|
||||
namespace user_namespace {
|
||||
struct user_type
|
||||
{};
|
||||
|
||||
|
|
@ -24,11 +23,10 @@ namespace user_namespace
|
|||
{
|
||||
return s << "user_type";
|
||||
}
|
||||
}
|
||||
} // namespace user_namespace
|
||||
//]
|
||||
|
||||
namespace custom_constraint_free_function_test
|
||||
{
|
||||
namespace custom_constraint_free_function_test {
|
||||
//[ custom_constraint_free_function
|
||||
bool custom_constraint(int actual)
|
||||
{
|
||||
|
|
@ -45,22 +43,15 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_free_function )
|
|||
c.add(41, 1);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace custom_constraint_free_function_test
|
||||
|
||||
namespace custom_constraint_functor_test
|
||||
{
|
||||
namespace custom_constraint_functor_test {
|
||||
//[ custom_constraint_functor
|
||||
struct custom_constraint
|
||||
{
|
||||
friend bool operator==( int actual, const custom_constraint& )
|
||||
{
|
||||
return actual == 42;
|
||||
}
|
||||
friend bool operator==(int actual, const custom_constraint&) { return actual == 42; }
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const custom_constraint& )
|
||||
{
|
||||
return s << "_ == 42";
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const custom_constraint&) { return s << "_ == 42"; }
|
||||
};
|
||||
//]
|
||||
|
||||
|
|
@ -73,16 +64,13 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_custom_constraint )
|
|||
c.add(41, 1);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace custom_constraint_functor_test
|
||||
|
||||
//[ near_constraint
|
||||
template<typename Expected>
|
||||
struct near_constraint
|
||||
{
|
||||
near_constraint( Expected expected, Expected threshold )
|
||||
: expected_( expected )
|
||||
, threshold_( threshold )
|
||||
{}
|
||||
near_constraint(Expected expected, Expected threshold) : expected_(expected), threshold_(threshold) {}
|
||||
|
||||
template<typename Actual>
|
||||
bool operator()(Actual actual) const
|
||||
|
|
@ -92,8 +80,7 @@ struct near_constraint
|
|||
|
||||
friend std::ostream& operator<<(std::ostream& s, const near_constraint& c)
|
||||
{
|
||||
return s << "near( " << mock::format( c.expected_ )
|
||||
<< ", " << mock::format( c.threshold_ ) << " )";
|
||||
return s << "near( " << mock::format(c.expected_) << ", " << mock::format(c.threshold_) << " )";
|
||||
}
|
||||
|
||||
Expected expected_, threshold_;
|
||||
|
|
@ -106,8 +93,7 @@ mock::constraint< near_constraint< Expected > > near( Expected expected, Expecte
|
|||
}
|
||||
//]
|
||||
|
||||
namespace near_constraint_test
|
||||
{
|
||||
namespace near_constraint_test {
|
||||
//[ near_constraint_test
|
||||
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two_plus_or_minus_one_near)
|
||||
{
|
||||
|
|
@ -117,10 +103,9 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one_near )
|
|||
c.add(41, 1);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace near_constraint_test
|
||||
|
||||
namespace near_constraint_cref_test
|
||||
{
|
||||
namespace near_constraint_cref_test {
|
||||
//[ near_constraint_cref_test
|
||||
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two_plus_or_minus_one_near_cref)
|
||||
{
|
||||
|
|
@ -135,14 +120,12 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one_near_cre
|
|||
//]
|
||||
|
||||
// Example of a "strong type" float
|
||||
struct float_wrapper{
|
||||
struct float_wrapper
|
||||
{
|
||||
float value;
|
||||
float_wrapper(float value) : value(value) {}
|
||||
operator float() const { return value; }
|
||||
friend std::ostream& operator<<( std::ostream& s, const float_wrapper& f)
|
||||
{
|
||||
return s << f.value;
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const float_wrapper& f) { return s << f.value; }
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(near_constraint_works_with_with_float_wrapper_and_cref)
|
||||
|
|
@ -160,7 +143,7 @@ BOOST_AUTO_TEST_CASE( near_constraint_works_with_with_float_wrapper_and_cref )
|
|||
c.add(0, 0);
|
||||
c.add(41, 1);
|
||||
}
|
||||
}
|
||||
} // namespace near_constraint_cref_test
|
||||
|
||||
#undef MOCK_MAX_ARGS
|
||||
//[ max_args
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
std::function<void()> error_handler_abort;
|
||||
std::function<void(const char*, int)> error_handler_pass;
|
||||
|
|
@ -24,10 +24,7 @@ struct configurable_mock_error
|
|||
return Result();
|
||||
}
|
||||
|
||||
static void pass( const char* file, int line )
|
||||
{
|
||||
error_handler_pass(file, line);
|
||||
}
|
||||
static void pass(const char* file, int line) { error_handler_pass(file, line); }
|
||||
|
||||
template<typename Context>
|
||||
static void call(const Context& context, const char* file, int line)
|
||||
|
|
@ -50,8 +47,8 @@ struct configurable_mock_error
|
|||
#define MOCK_USE_BOOST_TEST
|
||||
|
||||
//[ prerequisite
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
//]
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
|
|
@ -69,8 +66,7 @@ struct Fixture
|
|||
|
||||
BOOST_FIXTURE_TEST_SUITE(GettingStarted, Fixture)
|
||||
|
||||
namespace phases
|
||||
{
|
||||
namespace phases {
|
||||
//[ phases
|
||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
||||
{
|
||||
|
|
@ -80,10 +76,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
|||
c.add(0, 0); // exercise object under test
|
||||
} // verify mock objects
|
||||
//]
|
||||
}
|
||||
} // namespace phases
|
||||
|
||||
namespace verify_reset
|
||||
{
|
||||
namespace verify_reset {
|
||||
//[ verify_reset
|
||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero_reset)
|
||||
{
|
||||
|
|
@ -99,10 +94,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero_reset )
|
|||
mock::reset(); // reset all expectations for all existing mock objects
|
||||
} // automatically verify all expectations are fulfilled for all mock objects going out of scope
|
||||
//]
|
||||
}
|
||||
} // namespace verify_reset
|
||||
|
||||
namespace expectations
|
||||
{
|
||||
namespace expectations {
|
||||
//[ expectations
|
||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero_expect)
|
||||
{
|
||||
|
|
@ -113,10 +107,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero_expect )
|
|||
c.add(0, 0);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace expectations
|
||||
|
||||
namespace sequence
|
||||
{
|
||||
namespace sequence {
|
||||
//[ sequence
|
||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero_then_1_plus_0_is_1)
|
||||
{
|
||||
|
|
@ -129,10 +122,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero_then_1_plus_0_is_1 )
|
|||
c.add(1, 0);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace sequence
|
||||
|
||||
namespace several_sequences
|
||||
{
|
||||
namespace several_sequences {
|
||||
//[ several_sequences
|
||||
BOOST_AUTO_TEST_CASE(add_several_numbers_in_sequences)
|
||||
{
|
||||
|
|
@ -148,11 +140,10 @@ BOOST_AUTO_TEST_CASE( add_several_numbers_in_sequences )
|
|||
c.add(2, 0);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace several_sequences
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
namespace action
|
||||
{
|
||||
namespace action {
|
||||
//[ action_view
|
||||
class view
|
||||
{
|
||||
|
|
@ -169,6 +160,7 @@ MOCK_BASE_CLASS( mock_view, view )
|
|||
class calculator
|
||||
{
|
||||
view& v;
|
||||
|
||||
public:
|
||||
calculator(view& v) : v(v) {}
|
||||
|
||||
|
|
@ -180,13 +172,8 @@ struct CatchFailureFixture: Fixture
|
|||
static bool aborted;
|
||||
static std::string fail_msg;
|
||||
|
||||
static void abort()
|
||||
{
|
||||
aborted = true;
|
||||
}
|
||||
static void fail( const std::string& message, const std::string&, const char* = "", int = 0 ){
|
||||
fail_msg = message;
|
||||
}
|
||||
static void abort() { aborted = true; }
|
||||
static void fail(const std::string& message, const std::string&, const char* = "", int = 0) { fail_msg = message; }
|
||||
CatchFailureFixture()
|
||||
{
|
||||
error_handler_abort = abort;
|
||||
|
|
@ -201,10 +188,9 @@ struct CatchFailureFixture: Fixture
|
|||
bool CatchFailureFixture::aborted = false;
|
||||
std::string CatchFailureFixture::fail_msg;
|
||||
|
||||
struct AssertMissingAction: CatchFailureFixture{
|
||||
void teardown(){
|
||||
assert_failure("missing action");
|
||||
}
|
||||
struct AssertMissingAction : CatchFailureFixture
|
||||
{
|
||||
void teardown() { assert_failure("missing action"); }
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(MissingReturnActionSuite, AssertMissingAction)
|
||||
|
|
@ -217,6 +203,6 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero_with_action )
|
|||
c.add(0, 0);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace action
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
//[ limitations_const_parameter_warning_problem
|
||||
class base
|
||||
{
|
||||
|
|
@ -18,10 +17,9 @@ namespace
|
|||
virtual void method(const int) = 0;
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace limitations_const_parameter_warning_explanation
|
||||
{
|
||||
namespace limitations_const_parameter_warning_explanation {
|
||||
//[ limitations_const_parameter_warning_explanation
|
||||
class derived : public base
|
||||
{
|
||||
|
|
@ -29,24 +27,19 @@ namespace limitations_const_parameter_warning_explanation
|
|||
virtual void method(const int);
|
||||
};
|
||||
|
||||
void derived::method( int )
|
||||
{}
|
||||
void derived::method(int) {}
|
||||
//]
|
||||
}
|
||||
} // namespace limitations_const_parameter_warning_explanation
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
//[ limitations_const_parameter_warning_solution
|
||||
MOCK_BASE_CLASS(mock_base, base)
|
||||
{
|
||||
void method( const int i )
|
||||
{
|
||||
method_stub( i );
|
||||
}
|
||||
void method(const int i) { method_stub(i); }
|
||||
MOCK_METHOD(method_stub, 1, void(int), method)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(check_method_stub_is_called)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
//[ limitations_literal_zero_problem
|
||||
class base
|
||||
{
|
||||
|
|
@ -23,7 +22,7 @@ namespace
|
|||
MOCK_METHOD(method, 1)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(literal_zero)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
//[ limitations_non_virtual_method_problem
|
||||
class base
|
||||
|
|
|
|||
|
|
@ -6,18 +6,23 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
//[ limitations_protected_private_method_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
void call(){ method_1(); method_2(); }
|
||||
void call()
|
||||
{
|
||||
method_1();
|
||||
method_2();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void method_1() = 0;
|
||||
|
||||
private:
|
||||
virtual void method_2() = 0;
|
||||
};
|
||||
|
|
@ -30,7 +35,7 @@ namespace
|
|||
MOCK_METHOD(method_2, 0, void())
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mocked_methods_are_called)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
//[ limitations_template_base_class_method_problem
|
||||
template<typename T>
|
||||
class base
|
||||
|
|
@ -29,7 +28,7 @@ namespace
|
|||
MOCK_METHOD(method, 0, void())
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(call_method_from_templated_class)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace limitations_template_method_problem
|
||||
{
|
||||
namespace limitations_template_method_problem {
|
||||
//[ limitations_template_method_problem
|
||||
class concept_class
|
||||
{
|
||||
|
|
@ -42,10 +41,9 @@ BOOST_AUTO_TEST_CASE(mocked_templated_methods_are_called)
|
|||
MOCK_EXPECT(b.method_string).once().with(mock::equal(std::string("string")));
|
||||
function_under_test(b);
|
||||
}
|
||||
}
|
||||
} // namespace limitations_template_method_problem
|
||||
|
||||
namespace limitations_template_method_problem_2
|
||||
{
|
||||
namespace limitations_template_method_problem_2 {
|
||||
//[ limitations_template_method_problem_2
|
||||
class concept_class
|
||||
{
|
||||
|
|
@ -94,4 +92,4 @@ BOOST_AUTO_TEST_CASE(dispatch_methods_are_called)
|
|||
MOCK_EXPECT(b.create_string).once().returns("");
|
||||
function_under_test(b);
|
||||
}
|
||||
}
|
||||
} // namespace limitations_template_method_problem_2
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
//[ limitations_throw_specifier_problem
|
||||
struct base_class
|
||||
{
|
||||
|
|
@ -23,14 +22,11 @@ namespace
|
|||
//[ limitations_throw_specifier_solution
|
||||
MOCK_BASE_CLASS(mock_class, base_class)
|
||||
{
|
||||
void method() throw() override
|
||||
{
|
||||
method_proxy();
|
||||
}
|
||||
void method() throw() override { method_proxy(); }
|
||||
MOCK_METHOD(method_proxy, 0, void(), method)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(call_method_proxy)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
#ifndef MOCK_VIEW
|
||||
#define MOCK_VIEW
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
#include "view.hpp"
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
//[ mock_view
|
||||
MOCK_BASE_CLASS(mock_view, view) // declare a 'mock_view' class implementing 'view'
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace simple
|
||||
{
|
||||
namespace simple {
|
||||
//[ simple_calculator
|
||||
class calculator
|
||||
{
|
||||
|
|
@ -21,7 +20,10 @@ public:
|
|||
};
|
||||
//]
|
||||
|
||||
int calculator::add( int a, int b ){ return a + b; }
|
||||
int calculator::add(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
//[ simple_zero_plus_zero_is_zero
|
||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
||||
|
|
@ -30,17 +32,14 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
|||
BOOST_CHECK_EQUAL(0, c.add(0, 0));
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace simple
|
||||
|
||||
namespace without_mock_object
|
||||
{
|
||||
namespace without_mock_object {
|
||||
//[ my_view
|
||||
class my_view : public view
|
||||
{
|
||||
public:
|
||||
my_view()
|
||||
: called( false )
|
||||
{}
|
||||
my_view() : called(false) {}
|
||||
virtual void display(int result)
|
||||
{
|
||||
called = true;
|
||||
|
|
@ -61,17 +60,17 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero_without_mock_object )
|
|||
BOOST_CHECK_EQUAL(0, v.value);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace without_mock_object
|
||||
|
||||
namespace with_mock_object
|
||||
{
|
||||
namespace with_mock_object {
|
||||
//[ zero_plus_zero_is_zero_with_mock_object
|
||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero_with_mock_object)
|
||||
{
|
||||
mock_view v;
|
||||
calculator c(v);
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ); // expect the 'display' method to be called once (and only once) with a parameter value equal to 0
|
||||
MOCK_EXPECT(v.display).once().with(
|
||||
0); // expect the 'display' method to be called once (and only once) with a parameter value equal to 0
|
||||
c.add(0, 0);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace with_mock_object
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ async_call_problem
|
||||
namespace mock_test
|
||||
{
|
||||
namespace mock_test {
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
|
|
@ -18,16 +17,16 @@ namespace mock_test
|
|||
class my_class
|
||||
{
|
||||
base_class& b;
|
||||
|
||||
public:
|
||||
explicit my_class(base_class&);
|
||||
|
||||
void flush(); // repetitively calling this method will in turn call base_class::method at some point
|
||||
};
|
||||
}
|
||||
} // namespace mock_test
|
||||
//]
|
||||
|
||||
namespace mock_test
|
||||
{
|
||||
namespace mock_test {
|
||||
my_class::my_class(base_class& b) : b(b) {}
|
||||
void my_class::flush()
|
||||
{
|
||||
|
|
@ -35,15 +34,14 @@ namespace mock_test
|
|||
if(--counter == 0)
|
||||
b.method();
|
||||
}
|
||||
}
|
||||
} // namespace mock_test
|
||||
|
||||
//[ async_call_solution
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace mock_test
|
||||
{
|
||||
namespace mock_test {
|
||||
template<typename F>
|
||||
void check(bool& condition, F flush, int attempts = 100, int sleep = 100)
|
||||
{
|
||||
|
|
@ -69,6 +67,6 @@ BOOST_AUTO_TEST_CASE( method_is_called )
|
|||
check(done, [&c]() { c.flush(); }); // just wait on done, flushing from time to time
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace mock_test
|
||||
|
||||
//]
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@ static void someFunctor(int newValue);
|
|||
};
|
||||
|
||||
// the function will call 'method' with a functor to be applied
|
||||
void function(base_class& c) { c.method(someFunctor); }
|
||||
void function(base_class& c)
|
||||
{
|
||||
c.method(someFunctor);
|
||||
}
|
||||
//]
|
||||
|
||||
// Some test-only code to verify what is described
|
||||
|
|
@ -42,21 +45,22 @@ struct CheckReceivedValue
|
|||
#define BOOST_AUTO_TEST_CASE(name) BOOST_FIXTURE_TEST_CASE(name, CheckReceivedValue)
|
||||
|
||||
//[ invoke_functor_solution
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_BASE_CLASS(mock_class, base_class)
|
||||
{
|
||||
MOCK_METHOD(method, 1)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method)
|
||||
{
|
||||
mock_class mock;
|
||||
MOCK_EXPECT( mock.method ).calls( [](const auto &functor){ functor(42); } ); // whenever 'method' is called, invoke the functor with 42
|
||||
MOCK_EXPECT(mock.method).calls([](const auto& functor) {
|
||||
functor(42);
|
||||
}); // whenever 'method' is called, invoke the functor with 42
|
||||
function(mock);
|
||||
}
|
||||
//]
|
||||
|
|
|
|||
|
|
@ -7,18 +7,15 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ quick_constraint_problem
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( int data )
|
||||
: data_( data )
|
||||
{}
|
||||
explicit my_class(int data) : data_(data) {}
|
||||
int data_;
|
||||
};
|
||||
|
||||
|
|
@ -31,7 +28,7 @@ namespace
|
|||
{
|
||||
MOCK_METHOD(method, 1, void(const my_class&)) // how to simply write a custom constraint ?
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
//]
|
||||
|
||||
//[ quick_constraint_solution
|
||||
|
|
@ -39,18 +36,21 @@ namespace
|
|||
|
||||
namespace // in the same namespace as 'my_class'
|
||||
{
|
||||
bool operator==( const my_class& actual, const std::string& expected ) // the first part of the trick is to compare to a string
|
||||
bool operator==(const my_class& actual,
|
||||
const std::string& expected) // the first part of the trick is to compare to a string
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << actual;
|
||||
return s.str() == expected;
|
||||
}
|
||||
} // mock
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(method_is_called)
|
||||
{
|
||||
my_mock mock;
|
||||
MOCK_EXPECT( mock.method ).once().with( "my_class( 42 )" ); // the second part of the trick is to express the constraint as a string
|
||||
MOCK_EXPECT(mock.method)
|
||||
.once()
|
||||
.with("my_class( 42 )"); // the second part of the trick is to express the constraint as a string
|
||||
mock.method(my_class(42));
|
||||
}
|
||||
//]
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ retrieve_cref_problem
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
|
|
@ -20,42 +19,47 @@ namespace
|
|||
public:
|
||||
explicit my_class(base_class&);
|
||||
|
||||
void process(); // the processing will call 'method' two times with the same value, but we don't know what value beforehand
|
||||
void process(); // the processing will call 'method' two times with the same value, but we don't know what value
|
||||
// beforehand
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
//]
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
static base_class* global_b = nullptr;
|
||||
my_class::my_class( base_class& b){ global_b = &b; }
|
||||
my_class::my_class(base_class& b)
|
||||
{
|
||||
global_b = &b;
|
||||
}
|
||||
void my_class::process()
|
||||
{
|
||||
int secret_value = 42;
|
||||
global_b->method(secret_value);
|
||||
global_b->method(secret_value);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
//[ retrieve_cref_solution
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_BASE_CLASS(mock_base_class, base_class)
|
||||
{
|
||||
MOCK_METHOD(method, 1)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(method_is_called_two_times_with_the_same_value)
|
||||
{
|
||||
mock_base_class mock;
|
||||
my_class c(mock);
|
||||
int value;
|
||||
MOCK_EXPECT( mock.method ).once().with( mock::retrieve( value ) ); // on first call retrieve the value, this expectation takes precedence because it can never fail
|
||||
MOCK_EXPECT( mock.method ).once().with( std::cref( value ) ); // on second call compare the previously retrieved value with the newly received one
|
||||
MOCK_EXPECT(mock.method).once().with(mock::retrieve(value)); // on first call retrieve the value, this expectation
|
||||
// takes precedence because it can never fail
|
||||
MOCK_EXPECT(mock.method)
|
||||
.once()
|
||||
.with(std::cref(value)); // on second call compare the previously retrieved value with the newly received one
|
||||
c.process();
|
||||
}
|
||||
//]
|
||||
|
|
|
|||
|
|
@ -17,16 +17,14 @@
|
|||
#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
|
||||
{
|
||||
my_class( int i ) : i_( i )
|
||||
{}
|
||||
my_class(int i) : i_(i) {}
|
||||
|
||||
int i_;
|
||||
};
|
||||
|
|
@ -37,12 +35,13 @@ namespace
|
|||
}
|
||||
|
||||
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'
|
||||
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,7 +50,8 @@ 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
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -65,7 +65,9 @@ BOOST_FIXTURE_TEST_CASE( static_object_partial_solution, fixture )
|
|||
//]
|
||||
|
||||
//[ 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);
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
|
@ -17,9 +17,11 @@
|
|||
// Dummy to detect if the assertion unexpectedly succeeded to test what is explained
|
||||
#undef BOOST_CHECK_THROW
|
||||
#define BOOST_CHECK_THROW(expr, exc) \
|
||||
try { \
|
||||
try \
|
||||
{ \
|
||||
expr; \
|
||||
} catch(const exc&) { \
|
||||
} catch(const exc&) \
|
||||
{ \
|
||||
std::cerr << "Exception thrown but should not"; \
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace class_example_1
|
||||
{
|
||||
namespace class_example_1 {
|
||||
//[ class_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{};
|
||||
|
|
@ -20,10 +19,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_class )
|
|||
mock_class c;
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace class_example_1
|
||||
|
||||
namespace class_example_2
|
||||
{
|
||||
namespace class_example_2 {
|
||||
//[ class_example_2
|
||||
template<typename T>
|
||||
MOCK_CLASS(mock_class)
|
||||
|
|
@ -34,10 +32,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_template_mock_class )
|
|||
mock_class<int> c;
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace class_example_2
|
||||
|
||||
namespace class_example_3
|
||||
{
|
||||
namespace class_example_3 {
|
||||
//[ class_example_3
|
||||
struct base_class
|
||||
{};
|
||||
|
|
@ -50,10 +47,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_derived_mock_class )
|
|||
mock_class c;
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace class_example_3
|
||||
|
||||
namespace class_example_4
|
||||
{
|
||||
namespace class_example_4 {
|
||||
//[ class_example_4
|
||||
template<typename T>
|
||||
struct base_class
|
||||
|
|
@ -68,40 +64,37 @@ BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_template_derived_mock_class )
|
|||
mock_class<int> c;
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace class_example_4
|
||||
|
||||
namespace class_example_5
|
||||
{
|
||||
namespace class_example_5 {
|
||||
//[ class_example_5
|
||||
struct name : mock::object // equivalent to using MOCK_CLASS
|
||||
{};
|
||||
//]
|
||||
}
|
||||
} // namespace class_example_5
|
||||
|
||||
namespace class_example_6
|
||||
{
|
||||
namespace class_example_6 {
|
||||
//[ class_example_6
|
||||
template<typename T>
|
||||
struct name : mock::object // equivalent to using MOCK_CLASS
|
||||
{};
|
||||
//]
|
||||
}
|
||||
} // namespace class_example_6
|
||||
|
||||
namespace class_example_7
|
||||
{
|
||||
namespace class_example_7 {
|
||||
//[ class_example_7
|
||||
class base
|
||||
{};
|
||||
|
||||
struct name : base, mock::object // equivalent to using MOCK_BASE_CLASS
|
||||
{
|
||||
typedef base base_type; // this is required for the shortest form of MOCK_METHOD to work when not using MOCK_BASE_CLASS
|
||||
typedef base
|
||||
base_type; // this is required for the shortest form of MOCK_METHOD to work when not using MOCK_BASE_CLASS
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace class_example_7
|
||||
|
||||
namespace class_example_8
|
||||
{
|
||||
namespace class_example_8 {
|
||||
//[ class_example_8
|
||||
template<typename T>
|
||||
struct base
|
||||
|
|
@ -113,10 +106,9 @@ struct name : base< T >, mock::object
|
|||
typedef base<T> base_type;
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace class_example_8
|
||||
|
||||
namespace member_function_example_1
|
||||
{
|
||||
namespace member_function_example_1 {
|
||||
//[ member_function_example_1
|
||||
struct base_class
|
||||
{
|
||||
|
|
@ -129,10 +121,9 @@ MOCK_BASE_CLASS( mock_class, base_class )
|
|||
MOCK_METHOD(method, 1) // only possible when referring unambiguously to a base class method
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_1
|
||||
|
||||
namespace member_function_example_2
|
||||
{
|
||||
namespace member_function_example_2 {
|
||||
//[ member_function_example_2
|
||||
struct base_class
|
||||
{
|
||||
|
|
@ -143,14 +134,20 @@ struct base_class
|
|||
|
||||
MOCK_BASE_CLASS(mock_class, base_class)
|
||||
{
|
||||
MOCK_METHOD( method, 2, void( int, const std::string& ), identifier_1 ) // both the signature and identifier must be specified because of ambiguity due to overloading
|
||||
MOCK_METHOD( method, 1, void( float ), identifier_2 ) // the identifier must differ from the previous one in order to fully disambiguate methods
|
||||
MOCK_METHOD(
|
||||
method,
|
||||
2,
|
||||
void(int, const std::string&),
|
||||
identifier_1) // both the signature and identifier must be specified because of ambiguity due to overloading
|
||||
MOCK_METHOD(method,
|
||||
1,
|
||||
void(float),
|
||||
identifier_2) // the identifier must differ from the previous one in order to fully disambiguate methods
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_2
|
||||
|
||||
namespace member_function_example_3
|
||||
{
|
||||
namespace member_function_example_3 {
|
||||
//[ member_function_example_3
|
||||
struct base_class
|
||||
{
|
||||
|
|
@ -164,10 +161,9 @@ MOCK_BASE_CLASS( mock_class, base_class )
|
|||
MOCK_METHOD(method, 1, void(float)) // this generates both const and non-const versions
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_3
|
||||
|
||||
namespace member_function_example_4
|
||||
{
|
||||
namespace member_function_example_4 {
|
||||
//[ member_function_example_4
|
||||
struct base_class
|
||||
{
|
||||
|
|
@ -179,13 +175,13 @@ struct base_class
|
|||
MOCK_BASE_CLASS(mock_class, base_class)
|
||||
{
|
||||
MOCK_CONST_METHOD(method, 1, void(float), identifier_1) // this generates only the const version
|
||||
MOCK_NON_CONST_METHOD( method, 1, void( float ), identifier_2 ) // this generates only the non-const version, with a different identifier
|
||||
MOCK_NON_CONST_METHOD(
|
||||
method, 1, void(float), identifier_2) // this generates only the non-const version, with a different identifier
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_4
|
||||
|
||||
namespace member_function_example_5
|
||||
{
|
||||
namespace member_function_example_5 {
|
||||
//[ member_function_example_5
|
||||
struct base_class
|
||||
{
|
||||
|
|
@ -200,63 +196,68 @@ struct mock_class : base_class
|
|||
MOCK_METHOD(method, 1)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_5
|
||||
|
||||
namespace member_function_example_6
|
||||
{
|
||||
namespace member_function_example_6 {
|
||||
//[ member_function_example_6
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_NON_CONST_METHOD( operator=, 1, mock_class&( const mock_class& ), assignment ) // operators require a custom identifier
|
||||
MOCK_NON_CONST_METHOD(operator=,
|
||||
1,
|
||||
mock_class &(const mock_class&),
|
||||
assignment) // operators require a custom identifier
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_6
|
||||
|
||||
namespace member_function_example_7
|
||||
{
|
||||
namespace member_function_example_7 {
|
||||
//[ member_function_example_7
|
||||
template<typename T>
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_METHOD_TPL( method, 1, void( const T& ) ) // the _TPL variants must be used if the signature includes a template parameter of the class
|
||||
MOCK_METHOD_TPL(
|
||||
method,
|
||||
1,
|
||||
void(const T&)) // the _TPL variants must be used if the signature includes a template parameter of the class
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_7
|
||||
|
||||
namespace member_function_example_8
|
||||
{
|
||||
namespace member_function_example_8 {
|
||||
//[ member_function_example_8
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_METHOD( method, 0, BOOST_IDENTITY_TYPE((std::map< int, int >())) ) // the signature must be wrapped in BOOST_IDENTITY_TYPE if the return type contains a comma
|
||||
MOCK_METHOD(
|
||||
method, 0, BOOST_IDENTITY_TYPE((std::map<int, int>()))) // the signature must be wrapped in BOOST_IDENTITY_TYPE if
|
||||
// the return type contains a comma
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_8
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace member_function_example_9
|
||||
{
|
||||
namespace member_function_example_9 {
|
||||
//[ member_function_example_9
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_METHOD( __stdcall method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
|
||||
MOCK_METHOD(__stdcall method,
|
||||
0,
|
||||
void(),
|
||||
method) // all parameters must be provided when specifying a different calling convention
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace member_function_example_9
|
||||
#endif
|
||||
|
||||
namespace static_member_function_example_1
|
||||
{
|
||||
namespace static_member_function_example_1 {
|
||||
//[ static_member_function_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_STATIC_METHOD(method, 1, float(int))
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace static_member_function_example_1
|
||||
|
||||
namespace static_member_function_example_2
|
||||
{
|
||||
namespace static_member_function_example_2 {
|
||||
//[ static_member_function_example_2
|
||||
template<typename T>
|
||||
MOCK_CLASS(mock_class)
|
||||
|
|
@ -264,32 +265,32 @@ MOCK_CLASS( mock_class )
|
|||
MOCK_STATIC_METHOD_TPL(method, 1, void(T))
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace static_member_function_example_2
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace static_member_function_example_3
|
||||
{
|
||||
namespace static_member_function_example_3 {
|
||||
//[ static_member_function_example_3
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_STATIC_METHOD( __stdcall method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
|
||||
MOCK_STATIC_METHOD(__stdcall method,
|
||||
0,
|
||||
void(),
|
||||
method) // all parameters must be provided when specifying a different calling convention
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace static_member_function_example_3
|
||||
#endif
|
||||
|
||||
namespace constructor_example_1
|
||||
{
|
||||
namespace constructor_example_1 {
|
||||
//[ constructor_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_CONSTRUCTOR(mock_class, 2, (int, const std::string&), identifier)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace constructor_example_1
|
||||
|
||||
namespace constructor_example_2
|
||||
{
|
||||
namespace constructor_example_2 {
|
||||
//[ constructor_example_2
|
||||
template<typename T>
|
||||
MOCK_CLASS(mock_class)
|
||||
|
|
@ -298,44 +299,40 @@ MOCK_CLASS( mock_class )
|
|||
MOCK_CONSTRUCTOR_TPL(mock_class, 2, (T, const std::string&), identifier_2)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace constructor_example_2
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace constructor_example_3
|
||||
{
|
||||
namespace constructor_example_3 {
|
||||
//[ constructor_example_3
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_CONSTRUCTOR(__stdcall mock_class, 0, (), constructor)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace constructor_example_3
|
||||
#endif
|
||||
|
||||
namespace destructor_example_1
|
||||
{
|
||||
namespace destructor_example_1 {
|
||||
//[ destructor_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_DESTRUCTOR(~mock_class, destructor)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace destructor_example_1
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace destructor_example_2
|
||||
{
|
||||
namespace destructor_example_2 {
|
||||
//[ destructor_example_2
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_DESTRUCTOR(__stdcall ~mock_class, destructor)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace destructor_example_2
|
||||
#endif
|
||||
|
||||
namespace conversion_operator_example_1
|
||||
{
|
||||
namespace conversion_operator_example_1 {
|
||||
//[ conversion_operator_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -343,35 +340,33 @@ MOCK_CLASS( mock_class )
|
|||
MOCK_CONST_CONVERSION_OPERATOR(operator, const std::string&, conversion_to_string)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace conversion_operator_example_1
|
||||
|
||||
namespace conversion_operator_example_2
|
||||
{
|
||||
namespace conversion_operator_example_2 {
|
||||
//[ conversion_operator_example_2
|
||||
template<typename T>
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_CONVERSION_OPERATOR_TPL( operator, T, conversion_to_T ) // the _TPL variants must be used if the signature includes a template parameter of the class
|
||||
MOCK_CONVERSION_OPERATOR_TPL(operator, T, conversion_to_T) // the _TPL variants must be used if the signature
|
||||
// includes a template parameter of the class
|
||||
MOCK_CONST_CONVERSION_OPERATOR(operator, const std::string&, const_conversion_to_string)
|
||||
MOCK_NON_CONST_CONVERSION_OPERATOR(operator, const std::string&, non_const_conversion_to_string)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace conversion_operator_example_2
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace conversion_operator_example_3
|
||||
{
|
||||
namespace conversion_operator_example_3 {
|
||||
//[ conversion_operator_example_3
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_CONVERSION_OPERATOR(__stdcall operator, int, conversion_to_int)
|
||||
};
|
||||
//]
|
||||
}
|
||||
} // namespace conversion_operator_example_3
|
||||
#endif
|
||||
|
||||
namespace function_example_1
|
||||
{
|
||||
namespace function_example_1 {
|
||||
//[ function_example_1
|
||||
MOCK_FUNCTION(f, 1, void(int))
|
||||
|
||||
|
|
@ -381,19 +376,20 @@ BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_function )
|
|||
f(3);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace function_example_1
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace function_example_2
|
||||
{
|
||||
namespace function_example_2 {
|
||||
//[ function_example_2
|
||||
MOCK_FUNCTION( __stdcall f, 0, void(), f ) // all parameters must be provided when specifying a different calling convention
|
||||
MOCK_FUNCTION(__stdcall f,
|
||||
0,
|
||||
void(),
|
||||
f) // all parameters must be provided when specifying a different calling convention
|
||||
//]
|
||||
}
|
||||
} // namespace function_example_2
|
||||
#endif
|
||||
|
||||
namespace functor_example_1
|
||||
{
|
||||
namespace functor_example_1 {
|
||||
//[ functor_example_1
|
||||
BOOST_AUTO_TEST_CASE(demonstrates_instantiating_a_mock_functor)
|
||||
{
|
||||
|
|
@ -402,10 +398,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_functor )
|
|||
f(3);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace functor_example_1
|
||||
|
||||
namespace functor_example_2
|
||||
{
|
||||
namespace functor_example_2 {
|
||||
//[ functor_example_2
|
||||
template<typename T>
|
||||
struct mock_class
|
||||
|
|
@ -420,10 +415,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_functor_inside_a_class )
|
|||
c.f(3);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace functor_example_2
|
||||
|
||||
namespace expectation_example_1
|
||||
{
|
||||
namespace expectation_example_1 {
|
||||
//[ expectation_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -443,10 +437,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_mock_objects )
|
|||
BOOST_CHECK_THROW(c.method("not ok", 2.f), std::runtime_error);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace expectation_example_1
|
||||
|
||||
namespace invocation_example_1
|
||||
{
|
||||
namespace invocation_example_1 {
|
||||
//[ invocation_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -465,10 +458,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_setting_up_invocations_on_a_mock_method )
|
|||
c.method2(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace invocation_example_1
|
||||
|
||||
namespace invocation_example_2
|
||||
{
|
||||
namespace invocation_example_2 {
|
||||
//[ invocation_example_2
|
||||
BOOST_AUTO_TEST_CASE(demonstrates_setting_up_an_invocation_on_a_mock_functor)
|
||||
{
|
||||
|
|
@ -477,10 +469,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_setting_up_an_invocation_on_a_mock_functor )
|
|||
f(42, "Hello world!");
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace invocation_example_2
|
||||
|
||||
namespace invocation_example_3
|
||||
{
|
||||
namespace invocation_example_3 {
|
||||
//[ invocation_example_3
|
||||
MOCK_FUNCTION(f, 1, void(int))
|
||||
|
||||
|
|
@ -490,10 +481,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_setting_up_an_invocation_on_a_mock_function )
|
|||
f(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace invocation_example_3
|
||||
|
||||
namespace invocation_example_4
|
||||
{
|
||||
namespace invocation_example_4 {
|
||||
//[ invocation_example_4
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -510,10 +500,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_setting_up_an_invocation_on_a_mock_static_met
|
|||
c.method2(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace invocation_example_4
|
||||
|
||||
namespace constraints_example_1
|
||||
{
|
||||
namespace constraints_example_1 {
|
||||
//[ constraints_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -530,10 +519,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_adding_builtin_constraints )
|
|||
c.method2(3, "some string");
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_1
|
||||
|
||||
namespace constraints_example_2
|
||||
{
|
||||
namespace constraints_example_2 {
|
||||
//[ constraints_example_2
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -552,10 +540,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_a_free_functi
|
|||
c.method(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_2
|
||||
|
||||
namespace constraints_example_3
|
||||
{
|
||||
namespace constraints_example_3 {
|
||||
//[ constraints_example_3
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -570,14 +557,14 @@ bool custom_constraint( int expected, int actual )
|
|||
BOOST_AUTO_TEST_CASE(demonstrates_adding_a_custom_constraint_with_a_standard_library_functor)
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( std::bind1st( std::ptr_fun( &custom_constraint ), 42 ) ); // std::ptr_fun creates an std::unary_function
|
||||
MOCK_EXPECT(c.method).with(
|
||||
std::bind1st(std::ptr_fun(&custom_constraint), 42)); // std::ptr_fun creates an std::unary_function
|
||||
c.method(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_3
|
||||
|
||||
namespace constraints_example_4
|
||||
{
|
||||
namespace constraints_example_4 {
|
||||
//[ constraints_example_4
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -597,14 +584,13 @@ BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_std_bind )
|
|||
c.method(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_4
|
||||
|
||||
#ifndef BOOST_MSVC // this produces an ICE with all versions of MSVC
|
||||
|
||||
# include <boost/lambda/lambda.hpp>
|
||||
|
||||
namespace constraints_example_5
|
||||
{
|
||||
namespace constraints_example_5 {
|
||||
//[ constraints_example_5
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -618,14 +604,13 @@ BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_boost_lambda
|
|||
c.method(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_5
|
||||
|
||||
#endif // BOOST_MSVC
|
||||
|
||||
#include <boost/phoenix/phoenix.hpp>
|
||||
|
||||
namespace constraints_example_6
|
||||
{
|
||||
namespace constraints_example_6 {
|
||||
//[ constraints_example_6
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -642,10 +627,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_boost_phoenix
|
|||
c.method2(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_6
|
||||
|
||||
namespace constraints_example_7
|
||||
{
|
||||
namespace constraints_example_7 {
|
||||
//[ constraints_example_7
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -659,10 +643,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_adding_a_constraint_with_cxx11_lambda )
|
|||
c.method(42);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_7
|
||||
|
||||
namespace constraints_example_8
|
||||
{
|
||||
namespace constraints_example_8 {
|
||||
//[ constraints_example_8
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -676,10 +659,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_combining_constraints )
|
|||
c.method(3, "Hello World!");
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_8
|
||||
|
||||
namespace constraints_example_9
|
||||
{
|
||||
namespace constraints_example_9 {
|
||||
//[ constraints_example_9
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -698,10 +680,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_one_constraint_for_all_arguments )
|
|||
c.method("1234", 4);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace constraints_example_9
|
||||
|
||||
namespace sequence_example_1
|
||||
{
|
||||
namespace sequence_example_1 {
|
||||
//[ sequence_example_1
|
||||
MOCK_CLASS(mock_class_1)
|
||||
{
|
||||
|
|
@ -725,17 +706,17 @@ BOOST_AUTO_TEST_CASE( demonstrates_enforcing_several_expectation_orders )
|
|||
mock_class_3 c_3;
|
||||
mock::sequence s_1, s_2;
|
||||
MOCK_EXPECT(c_1.method_1).in(s_1);
|
||||
MOCK_EXPECT( c_2.method_2 ).in( s_2 ); // c_1.method_1 and c_2.method_2 are in different sequences and can be called in any order
|
||||
MOCK_EXPECT(c_2.method_2)
|
||||
.in(s_2); // c_1.method_1 and c_2.method_2 are in different sequences and can be called in any order
|
||||
MOCK_EXPECT(c_3.method_3).in(s_1, s_2); // c_3.method_3 must be called after both c_1.method_1 and c_2.method_2
|
||||
c_2.method_2();
|
||||
c_1.method_1();
|
||||
c_3.method_3();
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace sequence_example_1
|
||||
|
||||
namespace action_example_1
|
||||
{
|
||||
namespace action_example_1 {
|
||||
//[ action_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -754,7 +735,8 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_actions )
|
|||
MOCK_EXPECT(c.method).once().moves(42); // returns by moving the value
|
||||
MOCK_EXPECT(c.method).once().throws(std::runtime_error("error !"));
|
||||
MOCK_EXPECT(c.method).once().calls(&function); // forwards 'method' parameter to 'function'
|
||||
MOCK_EXPECT( c.method ).once().calls( std::bind( &function, 42 ) ); // drops 'method' parameter and binds 42 as parameter to 'function'
|
||||
MOCK_EXPECT(c.method).once().calls(
|
||||
std::bind(&function, 42)); // drops 'method' parameter and binds 42 as parameter to 'function'
|
||||
MOCK_EXPECT(c.method).once().calls([](int i) { return i; }); // uses a C++11 lambda
|
||||
BOOST_TEST(c.method(0) == 42);
|
||||
BOOST_TEST(c.method(1) == 42);
|
||||
|
|
@ -764,10 +746,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_actions )
|
|||
BOOST_TEST(c.method(4) == 4);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace action_example_1
|
||||
|
||||
namespace action_example_2
|
||||
{
|
||||
namespace action_example_2 {
|
||||
//[ action_example_2
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -783,10 +764,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_actions_with_references )
|
|||
BOOST_CHECK_EQUAL(42, i); // indeed
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace action_example_2
|
||||
|
||||
namespace verification_example_1
|
||||
{
|
||||
namespace verification_example_1 {
|
||||
//[ verification_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -801,10 +781,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_verifying_a_mock_method )
|
|||
mock::verify(); // verifies all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace verification_example_1
|
||||
|
||||
namespace verification_example_2
|
||||
{
|
||||
namespace verification_example_2 {
|
||||
//[ verification_example_2
|
||||
BOOST_AUTO_TEST_CASE(demonstrates_verifying_a_mock_functor)
|
||||
{
|
||||
|
|
@ -814,10 +793,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_verifying_a_mock_functor )
|
|||
mock::verify(); // verifies all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace verification_example_2
|
||||
|
||||
namespace verification_example_3
|
||||
{
|
||||
namespace verification_example_3 {
|
||||
//[ verification_example_3
|
||||
MOCK_FUNCTION(f, 1, void(int))
|
||||
|
||||
|
|
@ -827,10 +805,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_verifying_a_mock_function )
|
|||
mock::verify(); // verifies all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace verification_example_3
|
||||
|
||||
namespace verification_example_4
|
||||
{
|
||||
namespace verification_example_4 {
|
||||
//[ verification_example_4
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -845,10 +822,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_verifying_a_static_mock_method )
|
|||
mock::verify(); // verifies all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace verification_example_4
|
||||
|
||||
namespace reset_example_1
|
||||
{
|
||||
namespace reset_example_1 {
|
||||
//[ reset_example_1
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -863,10 +839,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_mock_method )
|
|||
mock::reset(); // resets all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace reset_example_1
|
||||
|
||||
namespace reset_example_2
|
||||
{
|
||||
namespace reset_example_2 {
|
||||
//[ reset_example_2
|
||||
BOOST_AUTO_TEST_CASE(demonstrates_resetting_a_mock_functor)
|
||||
{
|
||||
|
|
@ -876,10 +851,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_mock_functor )
|
|||
mock::reset(); // resets all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace reset_example_2
|
||||
|
||||
namespace reset_example_3
|
||||
{
|
||||
namespace reset_example_3 {
|
||||
//[ reset_example_3
|
||||
MOCK_FUNCTION(f, 1, void(int))
|
||||
|
||||
|
|
@ -889,10 +863,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_mock_function )
|
|||
mock::reset(); // resets all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace reset_example_3
|
||||
|
||||
namespace reset_example_4
|
||||
{
|
||||
namespace reset_example_4 {
|
||||
//[ reset_example_4
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
|
|
@ -907,10 +880,9 @@ BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_static_mock_method )
|
|||
mock::reset(); // resets all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace reset_example_4
|
||||
|
||||
namespace helpers_example_1
|
||||
{
|
||||
namespace helpers_example_1 {
|
||||
//[ helpers_example_1
|
||||
MOCK_CONSTRAINT(any, true) // this is how mock::any could be defined
|
||||
MOCK_CONSTRAINT(forty_two, actual == 42) // this defines a 'forty_two' constraint
|
||||
|
|
@ -922,13 +894,15 @@ BOOST_AUTO_TEST_CASE( mock_constraint_0_arity )
|
|||
MOCK_EXPECT(f).with(any);
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace helpers_example_1
|
||||
|
||||
namespace helpers_example_2
|
||||
{
|
||||
namespace helpers_example_2 {
|
||||
//[ helpers_example_2
|
||||
MOCK_CONSTRAINT(equal, expected, actual == expected) // this is how mock::equal could be defined
|
||||
MOCK_CONSTRAINT( near, expected, std::abs( actual - expected ) < 0.01 ) // this defines a 'near' constraint which can be used as 'near( 42 )'
|
||||
MOCK_CONSTRAINT(near,
|
||||
expected,
|
||||
std::abs(actual - expected) <
|
||||
0.01) // this defines a 'near' constraint which can be used as 'near( 42 )'
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mock_constraint_1_arity)
|
||||
{
|
||||
|
|
@ -937,12 +911,14 @@ BOOST_AUTO_TEST_CASE( mock_constraint_1_arity )
|
|||
MOCK_EXPECT(f).with(equal(42));
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace helpers_example_2
|
||||
|
||||
namespace helpers_example_3
|
||||
{
|
||||
namespace helpers_example_3 {
|
||||
//[ helpers_example_3
|
||||
MOCK_CONSTRAINT( near, expected, tolerance, std::abs( actual - expected ) < tolerance ) // this is how mock::near could be defined
|
||||
MOCK_CONSTRAINT(near,
|
||||
expected,
|
||||
tolerance,
|
||||
std::abs(actual - expected) < tolerance) // this is how mock::near could be defined
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mock_constraint_2_arity)
|
||||
{
|
||||
|
|
@ -950,4 +926,4 @@ BOOST_AUTO_TEST_CASE( mock_constraint_2_arity )
|
|||
MOCK_EXPECT(f).with(near(42, 0.001));
|
||||
}
|
||||
//]
|
||||
}
|
||||
} // namespace helpers_example_3
|
||||
|
|
|
|||
|
|
@ -21,8 +21,10 @@ struct catch_mock_error_policy
|
|||
}
|
||||
|
||||
template<typename Context>
|
||||
static void fail( const char* message, const Context& context,
|
||||
const char* file = "file://unknown-location", int line = 0 )
|
||||
static void fail(const char* message,
|
||||
const Context& context,
|
||||
const char* file = "file://unknown-location",
|
||||
int line = 0)
|
||||
{
|
||||
CAPTURE(context);
|
||||
FAIL_CHECK(message << " in: " << file << ":" << line);
|
||||
|
|
@ -35,10 +37,7 @@ struct catch_mock_error_policy
|
|||
INFO(file << ":" << line);
|
||||
}
|
||||
|
||||
static void pass( const char* file, int line )
|
||||
{
|
||||
INFO( file << ":" << line );
|
||||
}
|
||||
static void pass(const char* file, int line) { INFO(file << ":" << line); }
|
||||
};
|
||||
|
||||
#define MOCK_ERROR_POLICY catch_mock_error_policy
|
||||
|
|
|
|||
|
|
@ -10,20 +10,16 @@
|
|||
#define MOCK_CLEANUP_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "verify.hpp"
|
||||
#include "reset.hpp"
|
||||
#include "verify.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
# include <boost/test/unit_test_suite.hpp>
|
||||
#endif
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
struct cleanup
|
||||
{
|
||||
~cleanup()
|
||||
{
|
||||
mock::reset();
|
||||
}
|
||||
~cleanup() { mock::reset(); }
|
||||
};
|
||||
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
|
|
@ -33,7 +29,6 @@ namespace mock
|
|||
# endif
|
||||
#endif
|
||||
|
||||
} // mock
|
||||
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_CLEANUP_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__cpp_lib_uncaught_exceptions) || \
|
||||
defined(_MSC_VER) && (_MSC_VER >= 1900)
|
||||
#if defined(__cpp_lib_uncaught_exceptions) || defined(_MSC_VER) && (_MSC_VER >= 1900)
|
||||
# ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS
|
||||
# define MOCK_UNCAUGHT_EXCEPTIONS
|
||||
# endif
|
||||
|
|
|
|||
|
|
@ -12,38 +12,31 @@
|
|||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "unwrap_reference.hpp"
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/array.hpp>
|
||||
#include <boost/preprocessor/control/if.hpp>
|
||||
#include <boost/preprocessor/variadic/to_array.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/preprocessor/array.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/variadic/to_array.hpp>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
template<typename Constraint>
|
||||
struct constraint
|
||||
{
|
||||
constraint() {}
|
||||
constraint( const Constraint& c )
|
||||
: c_( c )
|
||||
{}
|
||||
constraint(const Constraint& c) : c_(c) {}
|
||||
Constraint c_;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
template<typename Lhs, typename Rhs>
|
||||
class and_
|
||||
{
|
||||
public:
|
||||
and_( const Lhs& lhs, const Rhs& rhs )
|
||||
: lhs_( lhs )
|
||||
, rhs_( rhs )
|
||||
{}
|
||||
and_(const Lhs& lhs, const Rhs& rhs) : lhs_(lhs), rhs_(rhs) {}
|
||||
template<typename Actual>
|
||||
bool operator()(const Actual& actual) const
|
||||
{
|
||||
|
|
@ -51,9 +44,9 @@ namespace detail
|
|||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const and_& a)
|
||||
{
|
||||
return s << "( " << mock::format( a.lhs_ )
|
||||
<< " && " << mock::format( a.rhs_ ) << " )";
|
||||
return s << "( " << mock::format(a.lhs_) << " && " << mock::format(a.rhs_) << " )";
|
||||
}
|
||||
|
||||
private:
|
||||
Lhs lhs_;
|
||||
Rhs rhs_;
|
||||
|
|
@ -63,10 +56,7 @@ namespace detail
|
|||
class or_
|
||||
{
|
||||
public:
|
||||
or_( const Lhs& lhs, const Rhs& rhs )
|
||||
: lhs_( lhs )
|
||||
, rhs_( rhs )
|
||||
{}
|
||||
or_(const Lhs& lhs, const Rhs& rhs) : lhs_(lhs), rhs_(rhs) {}
|
||||
template<typename Actual>
|
||||
bool operator()(const Actual& actual) const
|
||||
{
|
||||
|
|
@ -74,9 +64,9 @@ namespace detail
|
|||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const or_& o)
|
||||
{
|
||||
return s << "( " << mock::format( o.lhs_ )
|
||||
<< " || " << mock::format( o.rhs_ )<< " )";
|
||||
return s << "( " << mock::format(o.lhs_) << " || " << mock::format(o.rhs_) << " )";
|
||||
}
|
||||
|
||||
private:
|
||||
Lhs lhs_;
|
||||
Rhs rhs_;
|
||||
|
|
@ -86,169 +76,220 @@ namespace detail
|
|||
class not_
|
||||
{
|
||||
public:
|
||||
explicit not_( const Constraint& c )
|
||||
: c_( c )
|
||||
{}
|
||||
explicit not_(const Constraint& c) : c_(c) {}
|
||||
template<typename Actual>
|
||||
bool operator()(const Actual& actual) const
|
||||
{
|
||||
return !c_(actual);
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const not_& n )
|
||||
{
|
||||
return s << "! " << mock::format( n.c_ );
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const not_& n) { return s << "! " << mock::format(n.c_); }
|
||||
|
||||
private:
|
||||
Constraint c_;
|
||||
};
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template<typename Lhs, typename Rhs>
|
||||
const constraint< detail::or_< Lhs, Rhs > >
|
||||
operator||( const constraint< Lhs >& lhs,
|
||||
const constraint< Rhs >& rhs )
|
||||
const constraint<detail::or_<Lhs, Rhs>> operator||(const constraint<Lhs>& lhs, const constraint<Rhs>& rhs)
|
||||
{
|
||||
return detail::or_<Lhs, Rhs>(lhs.c_, rhs.c_);
|
||||
}
|
||||
|
||||
template<typename Lhs, typename Rhs>
|
||||
const constraint< detail::and_< Lhs, Rhs > >
|
||||
operator&&( const constraint< Lhs >& lhs,
|
||||
const constraint< Rhs >& rhs )
|
||||
const constraint<detail::and_<Lhs, Rhs>> operator&&(const constraint<Lhs>& lhs, const constraint<Rhs>& rhs)
|
||||
{
|
||||
return detail::and_<Lhs, Rhs>(lhs.c_, rhs.c_);
|
||||
}
|
||||
|
||||
template<typename Constraint>
|
||||
const constraint< detail::not_< Constraint > >
|
||||
operator!( const constraint< Constraint >& c )
|
||||
const constraint<detail::not_<Constraint>> operator!(const constraint<Constraint>& c)
|
||||
{
|
||||
return detail::not_<Constraint>(c.c_);
|
||||
}
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#define MOCK_UNARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
namespace detail { \
|
||||
struct Name \
|
||||
{ \
|
||||
template<typename Actual> \
|
||||
bool operator()(const Actual& actual) const \
|
||||
{ \
|
||||
(void) actual; return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<( std::ostream& s, const Name& ) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(Name); \
|
||||
(void)actual; \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<(std::ostream& s, const Name&) { return s << BOOST_STRINGIZE(Name); } \
|
||||
}; \
|
||||
} \
|
||||
const mock::constraint<detail::Name> Name;
|
||||
|
||||
#define MOCK_CONSTRAINT_ASSIGN(z, n, d) \
|
||||
expected##n( std::forward< T##n >(e##n) )
|
||||
#define MOCK_CONSTRAINT_ASSIGN(z, n, d) expected##n(std::forward<T##n>(e##n))
|
||||
|
||||
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \
|
||||
mock::unwrap_ref( expected##n )
|
||||
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) mock::unwrap_ref(expected##n)
|
||||
|
||||
#define MOCK_CONSTRAINT_FORMAT(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) mock::format( c.expected##n )
|
||||
#define MOCK_CONSTRAINT_FORMAT(z, n, d) BOOST_PP_IF(n, << ", " <<, ) mock::format(c.expected##n)
|
||||
|
||||
#define MOCK_CONSTRAINT_MEMBER(z, n, d) \
|
||||
Expected_##n expected##n;
|
||||
#define MOCK_CONSTRAINT_MEMBER(z, n, d) Expected_##n expected##n;
|
||||
|
||||
#define MOCK_CONSTRAINT_TPL_TYPE(z, n, d) \
|
||||
std::decay_t< const T##n >
|
||||
#define MOCK_CONSTRAINT_TPL_TYPE(z, n, d) std::decay_t<const T##n>
|
||||
|
||||
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
||||
const mock::unwrap_reference_t< Expected_##n >& \
|
||||
BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
const mock::unwrap_reference_t<Expected_##n>& BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
|
||||
#define MOCK_CONSTRAINT_ARG(z, n, Args) \
|
||||
T##n&& BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
#define MOCK_CONSTRAINT_ARG(z, n, Args) T##n&& BOOST_PP_ARRAY_ELEM(n, Args)
|
||||
|
||||
#define MOCK_CONSTRAINT_ARGS(z, n, Args) \
|
||||
T##n&& e##n
|
||||
#define MOCK_CONSTRAINT_ARGS(z, n, Args) T##n&& e##n
|
||||
|
||||
#define MOCK_CONSTRAINT_PARAM(z, n, Args) \
|
||||
std::forward< T##n >( BOOST_PP_ARRAY_ELEM(n, Args) )
|
||||
#define MOCK_CONSTRAINT_PARAM(z, n, Args) std::forward<T##n>(BOOST_PP_ARRAY_ELEM(n, Args))
|
||||
|
||||
#define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||
namespace detail \
|
||||
{ \
|
||||
namespace detail { \
|
||||
template<BOOST_PP_ENUM_PARAMS(n, typename Expected_)> \
|
||||
struct Name \
|
||||
{ \
|
||||
template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
|
||||
explicit Name( \
|
||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARGS, _) ) \
|
||||
: BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
||||
explicit Name(BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARGS, _)) : BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
||||
{} \
|
||||
template<typename Actual> \
|
||||
bool operator()(const Actual& actual) const \
|
||||
{ \
|
||||
return test( actual, \
|
||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_UNWRAP_REF, _) ); \
|
||||
return test(actual, BOOST_PP_ENUM(n, MOCK_CONSTRAINT_UNWRAP_REF, _)); \
|
||||
} \
|
||||
template<typename Actual> \
|
||||
bool test( const Actual& actual, \
|
||||
BOOST_PP_ENUM(n, \
|
||||
MOCK_CONSTRAINT_CREF_PARAM, (n, Args)) ) const \
|
||||
bool test(const Actual& actual, BOOST_PP_ENUM(n, MOCK_CONSTRAINT_CREF_PARAM, (n, Args))) const \
|
||||
{ \
|
||||
return Expr; \
|
||||
} \
|
||||
friend std::ostream& operator<<(std::ostream& s, const Name& c) \
|
||||
{ \
|
||||
return s << BOOST_STRINGIZE(Name) << "( " \
|
||||
<< BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_FORMAT, _) \
|
||||
<< " )"; \
|
||||
return s << BOOST_STRINGIZE(Name) << "( " << BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_FORMAT, _) << " )"; \
|
||||
} \
|
||||
BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_MEMBER, _) \
|
||||
}; \
|
||||
} \
|
||||
template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
|
||||
mock::constraint< \
|
||||
detail::Name< BOOST_PP_ENUM(n, MOCK_CONSTRAINT_TPL_TYPE, _) > \
|
||||
> Name( BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARG, (n, Args)) ) \
|
||||
mock::constraint<detail::Name<BOOST_PP_ENUM(n, MOCK_CONSTRAINT_TPL_TYPE, _)>> Name( \
|
||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARG, (n, Args))) \
|
||||
{ \
|
||||
return detail::Name<BOOST_PP_ENUM(n, MOCK_CONSTRAINT_TPL_TYPE, _)>( \
|
||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_PARAM, (n, Args))); \
|
||||
}
|
||||
|
||||
#define MOCK_CONSTRAINT_EXT(Name, n, Args, Expr) \
|
||||
BOOST_PP_IF(n, \
|
||||
MOCK_NARY_CONSTRAINT, \
|
||||
MOCK_UNARY_CONSTRAINT)(Name, n, Args, Expr)
|
||||
BOOST_PP_IF(n, MOCK_NARY_CONSTRAINT, MOCK_UNARY_CONSTRAINT)(Name, n, Args, Expr)
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# define MOCK_VARIADIC_SIZE(...) \
|
||||
BOOST_PP_CAT(MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
|
||||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, \
|
||||
22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \
|
||||
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,),)
|
||||
32, \
|
||||
31, \
|
||||
30, \
|
||||
29, \
|
||||
28, \
|
||||
27, \
|
||||
26, \
|
||||
25, \
|
||||
24, \
|
||||
23, \
|
||||
22, \
|
||||
21, \
|
||||
20, \
|
||||
19, \
|
||||
18, \
|
||||
17, \
|
||||
16, \
|
||||
15, \
|
||||
14, \
|
||||
13, \
|
||||
12, \
|
||||
11, \
|
||||
10, \
|
||||
9, \
|
||||
8, \
|
||||
7, \
|
||||
6, \
|
||||
5, \
|
||||
4, \
|
||||
3, \
|
||||
2, \
|
||||
1, ), )
|
||||
#else // BOOST_MSVC
|
||||
# define MOCK_VARIADIC_SIZE(...) \
|
||||
MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
|
||||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, \
|
||||
22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \
|
||||
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,)
|
||||
32, \
|
||||
31, \
|
||||
30, \
|
||||
29, \
|
||||
28, \
|
||||
27, \
|
||||
26, \
|
||||
25, \
|
||||
24, \
|
||||
23, \
|
||||
22, \
|
||||
21, \
|
||||
20, \
|
||||
19, \
|
||||
18, \
|
||||
17, \
|
||||
16, \
|
||||
15, \
|
||||
14, \
|
||||
13, \
|
||||
12, \
|
||||
11, \
|
||||
10, \
|
||||
9, \
|
||||
8, \
|
||||
7, \
|
||||
6, \
|
||||
5, \
|
||||
4, \
|
||||
3, \
|
||||
2, \
|
||||
1, )
|
||||
#endif // BOOST_MSVC
|
||||
#define MOCK_VARIADIC_SIZE_I( \
|
||||
e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, \
|
||||
e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, \
|
||||
e25, e26, e27, e28, e29, e30, e31, size, ...) size
|
||||
#define MOCK_VARIADIC_SIZE_I(e0, \
|
||||
e1, \
|
||||
e2, \
|
||||
e3, \
|
||||
e4, \
|
||||
e5, \
|
||||
e6, \
|
||||
e7, \
|
||||
e8, \
|
||||
e9, \
|
||||
e10, \
|
||||
e11, \
|
||||
e12, \
|
||||
e13, \
|
||||
e14, \
|
||||
e15, \
|
||||
e16, \
|
||||
e17, \
|
||||
e18, \
|
||||
e19, \
|
||||
e20, \
|
||||
e21, \
|
||||
e22, \
|
||||
e23, \
|
||||
e24, \
|
||||
e25, \
|
||||
e26, \
|
||||
e27, \
|
||||
e28, \
|
||||
e29, \
|
||||
e30, \
|
||||
e31, \
|
||||
size, \
|
||||
...) \
|
||||
size
|
||||
|
||||
#define MOCK_CONSTRAINT_AUX_AUX(Name, n, Array) \
|
||||
MOCK_CONSTRAINT_EXT( \
|
||||
Name, n, \
|
||||
BOOST_PP_ARRAY_TO_TUPLE(BOOST_PP_ARRAY_POP_BACK(Array)), \
|
||||
BOOST_PP_ARRAY_ELEM(n, Array))
|
||||
MOCK_CONSTRAINT_EXT(Name, n, BOOST_PP_ARRAY_TO_TUPLE(BOOST_PP_ARRAY_POP_BACK(Array)), BOOST_PP_ARRAY_ELEM(n, Array))
|
||||
|
||||
#define MOCK_CONSTRAINT_AUX(Name, Size, Tuple) \
|
||||
MOCK_CONSTRAINT_AUX_AUX(Name, BOOST_PP_DEC(Size), (Size,Tuple))
|
||||
#define MOCK_CONSTRAINT_AUX(Name, Size, Tuple) MOCK_CONSTRAINT_AUX_AUX(Name, BOOST_PP_DEC(Size), (Size, Tuple))
|
||||
|
||||
#define MOCK_CONSTRAINT(Name, ...) \
|
||||
MOCK_CONSTRAINT_AUX( \
|
||||
Name, MOCK_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))
|
||||
#define MOCK_CONSTRAINT(Name, ...) MOCK_CONSTRAINT_AUX(Name, MOCK_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))
|
||||
|
||||
#endif // MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
#include "config.hpp"
|
||||
#include "constraint.hpp"
|
||||
#include "detail/move_helper.hpp"
|
||||
#include "unwrap_reference.hpp"
|
||||
#include "detail/void_t.hpp"
|
||||
#include "unwrap_reference.hpp"
|
||||
#include <boost/version.hpp>
|
||||
#if BOOST_VERSION >= 107000
|
||||
# include <boost/test/tools/floating_point_comparison.hpp>
|
||||
|
|
@ -24,8 +24,7 @@
|
|||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
MOCK_UNARY_CONSTRAINT(any, 0, , ((void)actual, true))
|
||||
MOCK_UNARY_CONSTRAINT(affirm, 0, , !!actual)
|
||||
MOCK_UNARY_CONSTRAINT(negate, 0, , !actual)
|
||||
|
|
@ -38,23 +37,15 @@ namespace mock
|
|||
|
||||
#if BOOST_VERSION < 105900
|
||||
|
||||
# define MOCK_SMALL() \
|
||||
boost::test_tools::check_is_small( actual, tolerance )
|
||||
# define MOCK_SMALL() boost::test_tools::check_is_small(actual, tolerance)
|
||||
# define MOCK_PERCENT_TOLERANCE() \
|
||||
boost::test_tools::check_is_close( \
|
||||
actual, \
|
||||
expected, \
|
||||
boost::test_tools::percent_tolerance( tolerance ) )
|
||||
boost::test_tools::check_is_close(actual, expected, boost::test_tools::percent_tolerance(tolerance))
|
||||
# define MOCK_FRACTION_TOLERANCE() \
|
||||
boost::test_tools::check_is_close( \
|
||||
actual, \
|
||||
expected, \
|
||||
boost::test_tools::fraction_tolerance( tolerance ) )
|
||||
boost::test_tools::check_is_close(actual, expected, boost::test_tools::fraction_tolerance(tolerance))
|
||||
|
||||
#else // BOOST_VERSION < 105900
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
template<typename T, typename Tolerance>
|
||||
bool is_small(const T& t, const Tolerance& tolerance)
|
||||
{
|
||||
|
|
@ -65,18 +56,13 @@ namespace detail
|
|||
bool is_close(const T1& t1, const T2& t2, const Tolerance& tolerance)
|
||||
{
|
||||
typedef std::common_type_t<T1, T2> common_type;
|
||||
return boost::math::fpc::close_at_tolerance< common_type >(
|
||||
tolerance, boost::math::fpc::FPC_STRONG )( t1, t2 );
|
||||
}
|
||||
return boost::math::fpc::close_at_tolerance<common_type>(tolerance, boost::math::fpc::FPC_STRONG)(t1, t2);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
# define MOCK_SMALL() \
|
||||
detail::is_small( actual, tolerance )
|
||||
# define MOCK_PERCENT_TOLERANCE() \
|
||||
detail::is_close( actual, expected, \
|
||||
boost::math::fpc::percent_tolerance( tolerance ) )
|
||||
# define MOCK_FRACTION_TOLERANCE() \
|
||||
detail::is_close( actual, expected, tolerance )
|
||||
# define MOCK_SMALL() detail::is_small(actual, tolerance)
|
||||
# define MOCK_PERCENT_TOLERANCE() detail::is_close(actual, expected, boost::math::fpc::percent_tolerance(tolerance))
|
||||
# define MOCK_FRACTION_TOLERANCE() detail::is_close(actual, expected, tolerance)
|
||||
|
||||
#endif // BOOST_VERSION < 105900
|
||||
|
||||
|
|
@ -85,17 +71,14 @@ namespace detail
|
|||
# undef small
|
||||
# define MOCK_SMALL_DEFINED
|
||||
#endif
|
||||
MOCK_NARY_CONSTRAINT( small, 1, ( tolerance ),
|
||||
( MOCK_SMALL() ) )
|
||||
MOCK_NARY_CONSTRAINT(small, 1, (tolerance), (MOCK_SMALL()))
|
||||
#ifdef MOCK_SMALL_DEFINED
|
||||
# pragma pop_macro("small")
|
||||
#endif
|
||||
|
||||
MOCK_NARY_CONSTRAINT( close, 2, ( expected, tolerance ),
|
||||
( MOCK_PERCENT_TOLERANCE() ) )
|
||||
MOCK_NARY_CONSTRAINT(close, 2, (expected, tolerance), (MOCK_PERCENT_TOLERANCE()))
|
||||
|
||||
MOCK_NARY_CONSTRAINT( close_fraction, 2, ( expected, tolerance ),
|
||||
( MOCK_FRACTION_TOLERANCE() ) )
|
||||
MOCK_NARY_CONSTRAINT(close_fraction, 2, (expected, tolerance), (MOCK_FRACTION_TOLERANCE()))
|
||||
|
||||
#undef MOCK_PERCENT_TOLERANCE
|
||||
#undef MOCK_FRACTION_TOLERANCE
|
||||
|
|
@ -105,14 +88,12 @@ namespace detail
|
|||
# undef near
|
||||
# define MOCK_NEAR_DEFINED
|
||||
#endif
|
||||
MOCK_NARY_CONSTRAINT( near, 2, ( expected, tolerance ),
|
||||
std::abs( actual - expected ) <= tolerance )
|
||||
MOCK_NARY_CONSTRAINT(near, 2, (expected, tolerance), std::abs(actual - expected) <= tolerance)
|
||||
#ifdef MOCK_NEAR_DEFINED
|
||||
# pragma pop_macro("near")
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
template<class T, class U = T, class = void>
|
||||
struct has_equal_to : std::false_type
|
||||
{};
|
||||
|
|
@ -124,28 +105,16 @@ namespace detail
|
|||
template<typename Expected>
|
||||
struct equal
|
||||
{
|
||||
explicit equal( Expected expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
explicit equal(Expected expected) : expected_(expected) {}
|
||||
template<typename Actual>
|
||||
bool operator()(const Actual& actual,
|
||||
std::enable_if_t<
|
||||
has_equal_to<
|
||||
Actual,
|
||||
unwrap_reference_t< Expected >
|
||||
>::value
|
||||
>* = 0 ) const
|
||||
std::enable_if_t<has_equal_to<Actual, unwrap_reference_t<Expected>>::value>* = 0) const
|
||||
{
|
||||
return actual == unwrap_ref(expected_);
|
||||
}
|
||||
template<typename Actual>
|
||||
bool operator()(const Actual& actual,
|
||||
std::enable_if_t<
|
||||
!has_equal_to<
|
||||
Actual,
|
||||
unwrap_reference_t< Expected >
|
||||
>::value
|
||||
>* = 0 ) const
|
||||
std::enable_if_t<!has_equal_to<Actual, unwrap_reference_t<Expected>>::value>* = 0) const
|
||||
{
|
||||
return actual && *actual == unwrap_ref(expected_);
|
||||
}
|
||||
|
|
@ -159,9 +128,7 @@ namespace detail
|
|||
template<typename Expected>
|
||||
struct same
|
||||
{
|
||||
explicit same( const Expected& expected )
|
||||
: expected_( std::addressof( unwrap_ref( expected ) ) )
|
||||
{}
|
||||
explicit same(const Expected& expected) : expected_(std::addressof(unwrap_ref(expected))) {}
|
||||
template<typename Actual>
|
||||
bool operator()(const Actual& actual) const
|
||||
{
|
||||
|
|
@ -177,40 +144,26 @@ namespace detail
|
|||
template<typename Expected>
|
||||
struct retrieve
|
||||
{
|
||||
explicit retrieve( Expected& expected )
|
||||
: expected_( std::addressof( unwrap_ref( expected ) ) )
|
||||
{}
|
||||
explicit retrieve(Expected& expected) : expected_(std::addressof(unwrap_ref(expected))) {}
|
||||
template<typename Actual>
|
||||
bool operator()( const Actual& actual,
|
||||
std::enable_if_t<
|
||||
!std::is_convertible<
|
||||
const Actual*,
|
||||
unwrap_reference_t< Expected >
|
||||
>::value
|
||||
>* = 0 ) const
|
||||
bool operator()(
|
||||
const Actual& actual,
|
||||
std::enable_if_t<!std::is_convertible<const Actual*, unwrap_reference_t<Expected>>::value>* = 0) const
|
||||
{
|
||||
*expected_ = actual;
|
||||
return true;
|
||||
}
|
||||
template<typename Actual>
|
||||
bool operator()( Actual&& actual,
|
||||
std::enable_if_t<
|
||||
!std::is_convertible<
|
||||
const Actual*,
|
||||
unwrap_reference_t< Expected >
|
||||
>::value
|
||||
>* = 0 ) const
|
||||
bool operator()(
|
||||
Actual&& actual,
|
||||
std::enable_if_t<!std::is_convertible<const Actual*, unwrap_reference_t<Expected>>::value>* = 0) const
|
||||
{
|
||||
*expected_ = std::move(actual);
|
||||
return true;
|
||||
}
|
||||
template<typename Actual>
|
||||
bool operator()(Actual& actual,
|
||||
std::enable_if_t<
|
||||
std::is_convertible< Actual*,
|
||||
unwrap_reference_t< Expected >
|
||||
>::value
|
||||
>* = 0 ) const
|
||||
std::enable_if_t<std::is_convertible<Actual*, unwrap_reference_t<Expected>>::value>* = 0) const
|
||||
{
|
||||
*expected_ = std::addressof(actual);
|
||||
return true;
|
||||
|
|
@ -225,9 +178,7 @@ namespace detail
|
|||
template<typename Expected>
|
||||
struct assign
|
||||
{
|
||||
explicit assign( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
explicit assign(const Expected& expected) : expected_(expected) {}
|
||||
template<typename Actual>
|
||||
bool operator()(Actual& actual) const
|
||||
{
|
||||
|
|
@ -236,12 +187,7 @@ namespace detail
|
|||
}
|
||||
template<typename Actual>
|
||||
bool operator()(Actual* actual,
|
||||
std::enable_if_t<
|
||||
std::is_convertible<
|
||||
unwrap_reference_t< Expected >,
|
||||
Actual
|
||||
>::value
|
||||
>* = 0 ) const
|
||||
std::enable_if_t<std::is_convertible<unwrap_reference_t<Expected>, Actual>::value>* = 0) const
|
||||
{
|
||||
if(!actual)
|
||||
return false;
|
||||
|
|
@ -258,13 +204,10 @@ namespace detail
|
|||
template<typename Expected>
|
||||
struct contain
|
||||
{
|
||||
explicit contain( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
explicit contain(const Expected& expected) : expected_(expected) {}
|
||||
bool operator()(const std::string& actual) const
|
||||
{
|
||||
return actual.find( unwrap_ref( expected_ ) )
|
||||
!= std::string::npos;
|
||||
return actual.find(unwrap_ref(expected_)) != std::string::npos;
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const contain& n)
|
||||
{
|
||||
|
|
@ -272,7 +215,7 @@ namespace detail
|
|||
}
|
||||
Expected expected_;
|
||||
};
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template<typename T>
|
||||
constraint<detail::equal<T>> equal(T&& t)
|
||||
|
|
@ -306,6 +249,6 @@ namespace detail
|
|||
{
|
||||
return constraint<T>(t);
|
||||
}
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@
|
|||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
template<typename Result, typename Signature>
|
||||
class action_base
|
||||
{
|
||||
|
|
@ -33,20 +30,11 @@ namespace detail
|
|||
action_base(action_base&&) = delete;
|
||||
action_base& operator=(const action_base&) = delete;
|
||||
action_base& operator=(action_base&&) = delete;
|
||||
public:
|
||||
|
||||
const functor_type& functor() const
|
||||
{
|
||||
return f_;
|
||||
}
|
||||
bool valid() const
|
||||
{
|
||||
return f_ || a_;
|
||||
}
|
||||
Result trigger() const
|
||||
{
|
||||
return a_();
|
||||
}
|
||||
public:
|
||||
const functor_type& functor() const { return f_; }
|
||||
bool valid() const { return f_ || a_; }
|
||||
Result trigger() const { return a_(); }
|
||||
|
||||
void calls(const functor_type& f)
|
||||
{
|
||||
|
|
@ -62,10 +50,7 @@ namespace detail
|
|||
}
|
||||
|
||||
protected:
|
||||
void set( const action_type& a )
|
||||
{
|
||||
a_ = a;
|
||||
}
|
||||
void set(const action_type& a) { a_ = a; }
|
||||
template<typename Y>
|
||||
void set(const std::reference_wrapper<Y>& r)
|
||||
{
|
||||
|
|
@ -144,7 +129,6 @@ namespace detail
|
|||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_ACTION_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,22 +10,17 @@
|
|||
#define MOCK_CHILD_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "parent.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include "type_name.hpp"
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class child
|
||||
{
|
||||
public:
|
||||
child()
|
||||
: parent_( 0 )
|
||||
{}
|
||||
child() : parent_(0) {}
|
||||
void update(parent& p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
|
|
@ -42,11 +37,11 @@ namespace detail
|
|||
s << *c.parent_;
|
||||
return s << c.name_;
|
||||
}
|
||||
|
||||
private:
|
||||
const parent* parent_;
|
||||
boost::unit_test::const_string name_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_CHILD_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -15,10 +15,7 @@
|
|||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class verifiable;
|
||||
|
||||
class context
|
||||
|
|
@ -30,17 +27,16 @@ namespace detail
|
|||
|
||||
virtual ~context() = default;
|
||||
|
||||
virtual void add( const void* p, verifiable& v,
|
||||
virtual void add(const void* p,
|
||||
verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
boost::unit_test::const_string name) = 0;
|
||||
virtual void add(verifiable& v) = 0;
|
||||
virtual void remove(verifiable& v) = 0;
|
||||
|
||||
virtual void serialize( std::ostream& s,
|
||||
const verifiable& v ) const = 0;
|
||||
virtual void serialize(std::ostream& s, const verifiable& v) const = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_CONTEXT_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -8,115 +8,83 @@
|
|||
|
||||
#include "matcher_base_template.hpp"
|
||||
|
||||
#define MOCK_EXPECTATION_INITIALIZE(z, n, d) \
|
||||
BOOST_PP_COMMA_IF(n) c##n##_( c##n )
|
||||
#define MOCK_EXPECTATION_INITIALIZE(z, n, d) BOOST_PP_COMMA_IF(n) c##n##_(c##n)
|
||||
|
||||
#define MOCK_EXPECTATION_MEMBER(z, n, d) \
|
||||
matcher< T##n, Constraint_##n > c##n##_;
|
||||
#define MOCK_EXPECTATION_MEMBER(z, n, d) matcher<T##n, Constraint_##n> c##n##_;
|
||||
|
||||
#define MOCK_EXPECTATION_IS_VALID(z, n, d) \
|
||||
BOOST_PP_IF(n, &&,) c##n##_( std::forward< T##n >( a##n ) )
|
||||
#define MOCK_EXPECTATION_IS_VALID(z, n, d) BOOST_PP_IF(n, &&, ) c##n##_(std::forward<T##n>(a##n))
|
||||
|
||||
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) c##n##_
|
||||
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) BOOST_PP_IF(n, << ", " <<, ) c##n##_
|
||||
|
||||
#define MOCK_EXPECTATION_SERIALIZE_ANY(z, n, d) \
|
||||
BOOST_PP_IF(n, << ", " <<,) "any"
|
||||
#define MOCK_EXPECTATION_SERIALIZE_ANY(z, n, d) BOOST_PP_IF(n, << ", " <<, ) "any"
|
||||
|
||||
#define MOCK_EXPECTATION_PARAM(z, n, Args) \
|
||||
std::forward< T##n >( a##n )
|
||||
#define MOCK_EXPECTATION_PARAM(z, n, Args) std::forward<T##n>(a##n)
|
||||
|
||||
#define MOCK_REF_ARG(z, n, d) \
|
||||
typename ref_arg< T##n >::type a##n
|
||||
#define MOCK_REF_ARG(z, n, d) typename ref_arg<T##n>::type a##n
|
||||
|
||||
#define MOCK_REF_ARG_T(z, n, d) \
|
||||
typename ref_arg< T##n >::type
|
||||
#define MOCK_REF_ARG_T(z, n, d) typename ref_arg<T##n>::type
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class default_matcher;
|
||||
namespace mock { namespace detail {
|
||||
template<typename Signature>
|
||||
class default_matcher;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class default_matcher< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||
class default_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> :
|
||||
public matcher_base<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>
|
||||
{
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG_T, _) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual bool operator()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG_T, _)) { return true; }
|
||||
virtual void serialize(std::ostream& s) const
|
||||
{
|
||||
s << "" BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_SERIALIZE_ANY, _);
|
||||
s << "" BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_SERIALIZE_ANY, _);
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
|
||||
template< typename Constraint, typename Signature > class single_matcher;
|
||||
template<typename Constraint, typename Signature>
|
||||
class single_matcher;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_),
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)
|
||||
>
|
||||
class single_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_) ),
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_), BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||
class single_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_)),
|
||||
void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> :
|
||||
public matcher_base<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>
|
||||
{
|
||||
public:
|
||||
single_matcher(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
: BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_INITIALIZE, _)
|
||||
single_matcher(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c))
|
||||
: BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_INITIALIZE, _)
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) )
|
||||
virtual bool operator()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _))
|
||||
{
|
||||
return BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_IS_VALID, _);
|
||||
return BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_IS_VALID, _);
|
||||
}
|
||||
virtual void serialize(std::ostream& s) const
|
||||
{
|
||||
s << BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
||||
MOCK_EXPECTATION_SERIALIZE, _);
|
||||
s << BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_SERIALIZE, _);
|
||||
}
|
||||
|
||||
private:
|
||||
BOOST_PP_REPEAT(
|
||||
MOCK_NUM_ARGS, MOCK_EXPECTATION_MEMBER, _)
|
||||
BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_MEMBER, _)
|
||||
};
|
||||
|
||||
template< typename F, typename Signature > class multi_matcher;
|
||||
template<typename F, typename Signature>
|
||||
class multi_matcher;
|
||||
|
||||
template< typename F,
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class multi_matcher< F, void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
template<typename F, BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||
class multi_matcher<F, void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> :
|
||||
public matcher_base<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>
|
||||
{
|
||||
public:
|
||||
multi_matcher( const F& f )
|
||||
: f_( f )
|
||||
{}
|
||||
multi_matcher(const F& f) : f_(f) {}
|
||||
|
||||
private:
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) )
|
||||
virtual bool operator()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _))
|
||||
{
|
||||
return f_(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _));
|
||||
}
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
s << mock::format( f_ );
|
||||
}
|
||||
virtual void serialize(std::ostream& s) const { s << mock::format(f_); }
|
||||
|
||||
private:
|
||||
F f_;
|
||||
|
|
@ -124,35 +92,23 @@ namespace detail
|
|||
|
||||
#endif
|
||||
|
||||
template< typename Signature > class expectation;
|
||||
template<typename Signature>
|
||||
class expectation;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class expectation< R (BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T)) >
|
||||
: public action< R, R (BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T)) >
|
||||
template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||
class expectation<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> :
|
||||
public action<R, R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>
|
||||
{
|
||||
public:
|
||||
expectation()
|
||||
: invocation_( std::make_unique< unlimited >() )
|
||||
, matcher_(
|
||||
std::make_unique<
|
||||
default_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> () )
|
||||
, file_( "unknown location" )
|
||||
, line_( 0 )
|
||||
: invocation_(std::make_unique<unlimited>()),
|
||||
matcher_(std::make_unique<default_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>>()),
|
||||
file_("unknown location"), line_(0)
|
||||
{}
|
||||
expectation(const char* file, int line)
|
||||
: invocation_( std::make_unique< unlimited >() )
|
||||
, matcher_(
|
||||
std::make_unique<
|
||||
default_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> () )
|
||||
, file_( file )
|
||||
, line_( line )
|
||||
: invocation_(std::make_unique<unlimited>()),
|
||||
matcher_(std::make_unique<default_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>>()), file_(file),
|
||||
line_(line)
|
||||
{}
|
||||
|
||||
expectation(expectation&&) = default;
|
||||
|
|
@ -166,34 +122,22 @@ namespace detail
|
|||
sequence->remove(this);
|
||||
}
|
||||
|
||||
void invoke( std::unique_ptr< invocation > i )
|
||||
{
|
||||
invocation_ = std::move(i);
|
||||
}
|
||||
void invoke(std::unique_ptr<invocation> i) { invocation_ = std::move(i); }
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)
|
||||
>
|
||||
expectation& with(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)>
|
||||
expectation& with(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c))
|
||||
{
|
||||
matcher_ = std::make_unique<
|
||||
single_matcher<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_) ),
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>>( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) );
|
||||
matcher_ = std::make_unique<single_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_)),
|
||||
void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>>(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c));
|
||||
return *this;
|
||||
}
|
||||
# if MOCK_NUM_ARGS > 1
|
||||
template<typename Constraint>
|
||||
expectation& with(const Constraint& c)
|
||||
{
|
||||
matcher_ = std::make_unique<
|
||||
multi_matcher<
|
||||
Constraint,
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>>( c );
|
||||
matcher_ = std::make_unique<multi_matcher<Constraint, void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>>(c);
|
||||
return *this;
|
||||
}
|
||||
# endif
|
||||
|
|
@ -205,16 +149,11 @@ namespace detail
|
|||
sequences_.push_back(s.impl_);
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
return invocation_->verify();
|
||||
}
|
||||
bool verify() const { return invocation_->verify(); }
|
||||
|
||||
bool is_valid(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) ) const
|
||||
bool is_valid(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _)) const
|
||||
{
|
||||
return !invocation_->exhausted()
|
||||
&& (*matcher_)( BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _) );
|
||||
return !invocation_->exhausted() && (*matcher_)(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _));
|
||||
}
|
||||
|
||||
bool invoke() const
|
||||
|
|
@ -230,19 +169,12 @@ namespace detail
|
|||
return result;
|
||||
}
|
||||
|
||||
const char* file() const
|
||||
{
|
||||
return file_;
|
||||
}
|
||||
int line() const
|
||||
{
|
||||
return line_;
|
||||
}
|
||||
const char* file() const { return file_; }
|
||||
int line() const { return line_; }
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& s, const expectation& e)
|
||||
{
|
||||
return s << ( e.invocation_->exhausted() ? 'v' : '.' )
|
||||
<< ' ' << *e.invocation_
|
||||
return s << (e.invocation_->exhausted() ? 'v' : '.') << ' ' << *e.invocation_
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
<< ".with( " << *e.matcher_ << " )"
|
||||
#endif
|
||||
|
|
@ -251,17 +183,12 @@ namespace detail
|
|||
|
||||
private:
|
||||
std::unique_ptr<invocation> invocation_;
|
||||
std::unique_ptr<
|
||||
matcher_base<
|
||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
>
|
||||
> matcher_;
|
||||
std::unique_ptr<matcher_base<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>> matcher_;
|
||||
std::vector<std::shared_ptr<sequence_impl>> sequences_;
|
||||
const char* file_;
|
||||
int line_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#undef MOCK_EXPECTATION_INITIALIZE
|
||||
#undef MOCK_EXPECTATION_MEMBER
|
||||
|
|
|
|||
|
|
@ -13,20 +13,12 @@
|
|||
#include "../stream.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
template<typename T>
|
||||
struct formatter
|
||||
{
|
||||
explicit formatter( const T& t )
|
||||
: t_( std::addressof( t ) )
|
||||
{}
|
||||
void serialize( stream& s ) const
|
||||
{
|
||||
detail::serialize( s, *t_ );
|
||||
}
|
||||
explicit formatter(const T& t) : t_(std::addressof(t)) {}
|
||||
void serialize(stream& s) const { detail::serialize(s, *t_); }
|
||||
const T* t_;
|
||||
};
|
||||
|
||||
|
|
@ -44,7 +36,6 @@ namespace detail
|
|||
f.serialize(ss);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_FORMATTER_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,41 +10,36 @@
|
|||
#define MOCK_FUNCTION_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "../constraints.hpp"
|
||||
#include "../error.hpp"
|
||||
#include "../log.hpp"
|
||||
#include "../constraints.hpp"
|
||||
#include "../sequence.hpp"
|
||||
#include "../matcher.hpp"
|
||||
#include "../sequence.hpp"
|
||||
#include "action.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include "invocation.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "context.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include "invocation.hpp"
|
||||
#include "move_helper.hpp"
|
||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include "mutex.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/preprocessor/comparison/equal.hpp>
|
||||
#include <boost/preprocessor/comparison/greater.hpp>
|
||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/test/utils/lazy_ostream.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <list>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
template<typename R, typename E>
|
||||
struct wrapper_base
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
wrapper_base(E& e) : e_(&e) {}
|
||||
|
||||
template<typename T>
|
||||
void returns(T t)
|
||||
|
|
@ -57,23 +52,16 @@ namespace detail
|
|||
template<typename E>
|
||||
struct wrapper_base<void, E>
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
wrapper_base(E& e) : e_(&e) {}
|
||||
|
||||
E* e_;
|
||||
};
|
||||
template<typename R, typename E>
|
||||
struct wrapper_base<R*, E>
|
||||
{
|
||||
wrapper_base( E& e )
|
||||
: e_( &e )
|
||||
{}
|
||||
wrapper_base(E& e) : e_(&e) {}
|
||||
|
||||
void returns( R* r )
|
||||
{
|
||||
e_->returns( r );
|
||||
}
|
||||
void returns(R* r) { e_->returns(r); }
|
||||
template<typename Y>
|
||||
void returns(const std::reference_wrapper<Y>& r)
|
||||
{
|
||||
|
|
@ -92,8 +80,7 @@ namespace detail
|
|||
return std::uncaught_exception() ? 1 : 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#define MOCK_NUM_ARGS 0
|
||||
#define MOCK_NUM_ARGS_0
|
||||
|
|
|
|||
|
|
@ -12,43 +12,29 @@
|
|||
# error no error policy has been set
|
||||
#endif
|
||||
|
||||
#define MOCK_FUNCTION_FORMAT(z, n, N) \
|
||||
<< ' ' << mock::format( t##n ) \
|
||||
<< BOOST_PP_IF(BOOST_PP_EQUAL(N,n), ' ', ',')
|
||||
#define MOCK_FUNCTION_FORMAT(z, n, N) << ' ' << mock::format(t##n) << BOOST_PP_IF(BOOST_PP_EQUAL(N, n), ' ', ',')
|
||||
|
||||
#define MOCK_FUNCTION_CONTEXT \
|
||||
boost::unit_test::lazy_ostream::instance() \
|
||||
<< lazy_context( this ) \
|
||||
<< '(' BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_FORMAT, \
|
||||
BOOST_PP_DEC(MOCK_NUM_ARGS)) \
|
||||
<< ')' \
|
||||
<< lazy_expectations( this )
|
||||
<< lazy_context(this) << '(' BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_FORMAT, BOOST_PP_DEC(MOCK_NUM_ARGS)) \
|
||||
<< ')' << lazy_expectations(this)
|
||||
|
||||
#define MOCK_FORWARD(z, n, d) \
|
||||
std::forward< T##n >( t##n )
|
||||
#define MOCK_FORWARD(z, n, d) std::forward<T##n>(t##n)
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class function_impl;
|
||||
namespace mock { namespace detail {
|
||||
template<typename Signature>
|
||||
class function_impl;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
class function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
||||
: public verifiable, public std::enable_shared_from_this<
|
||||
function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )> >
|
||||
template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||
class function_impl<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> :
|
||||
public verifiable,
|
||||
public std::enable_shared_from_this<function_impl<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>>
|
||||
{
|
||||
public:
|
||||
typedef safe_error<R, MOCK_ERROR_POLICY<R>> error_type;
|
||||
|
||||
public:
|
||||
function_impl()
|
||||
: context_( 0 )
|
||||
, valid_( true )
|
||||
, exceptions_( exceptions() )
|
||||
, mutex_( std::make_shared< mutex >() )
|
||||
{}
|
||||
function_impl() : context_(0), valid_(true), exceptions_(exceptions()), mutex_(std::make_shared<mutex>()) {}
|
||||
virtual ~function_impl()
|
||||
{
|
||||
if(valid_ && exceptions_ >= exceptions())
|
||||
|
|
@ -59,9 +45,9 @@ namespace detail
|
|||
{
|
||||
error_type::fail("untriggered expectation",
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< lazy_context( this )
|
||||
<< lazy_expectations( this ),
|
||||
expectation.file(), expectation.line() );
|
||||
<< lazy_context(this) << lazy_expectations(this),
|
||||
expectation.file(),
|
||||
expectation.line());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -79,9 +65,9 @@ namespace detail
|
|||
valid_ = false;
|
||||
error_type::fail("verification failed",
|
||||
boost::unit_test::lazy_ostream::instance()
|
||||
<< lazy_context( this )
|
||||
<< lazy_expectations( this ),
|
||||
expectation.file(), expectation.line() );
|
||||
<< lazy_context(this) << lazy_expectations(this),
|
||||
expectation.file(),
|
||||
expectation.line());
|
||||
}
|
||||
}
|
||||
return valid_;
|
||||
|
|
@ -91,15 +77,12 @@ namespace detail
|
|||
{
|
||||
lock _(mutex_);
|
||||
valid_ = true;
|
||||
std::shared_ptr< function_impl > guard =
|
||||
this->shared_from_this();
|
||||
std::shared_ptr<function_impl> guard = this->shared_from_this();
|
||||
expectations_.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef expectation<
|
||||
R( BOOST_PP_ENUM_PARAMS( MOCK_NUM_ARGS, T ) )
|
||||
> expectation_type;
|
||||
typedef expectation<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> expectation_type;
|
||||
|
||||
class wrapper : public wrapper_base<R, expectation_type>
|
||||
{
|
||||
|
|
@ -107,10 +90,7 @@ namespace detail
|
|||
typedef wrapper_base<R, expectation_type> base_type;
|
||||
|
||||
public:
|
||||
wrapper( const std::shared_ptr< mutex >& m, expectation_type& e )
|
||||
: base_type( e )
|
||||
, lock_( m )
|
||||
{}
|
||||
wrapper(const std::shared_ptr<mutex>& m, expectation_type& e) : base_type(e), lock_(m) {}
|
||||
wrapper(const wrapper&) = delete;
|
||||
wrapper(wrapper&& x) = default;
|
||||
wrapper& operator=(const wrapper&) = delete;
|
||||
|
|
@ -147,14 +127,10 @@ namespace detail
|
|||
}
|
||||
|
||||
#ifndef MOCK_NUM_ARGS_0
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)
|
||||
>
|
||||
wrapper& with(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
||||
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)>
|
||||
wrapper& with(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c))
|
||||
{
|
||||
this->e_->with(
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) );
|
||||
this->e_->with(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -168,8 +144,7 @@ namespace detail
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#define MOCK_FUNCTION_IN_ADD(z, n, d) \
|
||||
this->e_->add( s##n );
|
||||
#define MOCK_FUNCTION_IN_ADD(z, n, d) this->e_->add(s##n);
|
||||
|
||||
#define MOCK_FUNCTION_IN(z, n, d) \
|
||||
wrapper& in(BOOST_PP_ENUM_PARAMS(n, sequence& s)) \
|
||||
|
|
@ -178,8 +153,7 @@ namespace detail
|
|||
return *this; \
|
||||
}
|
||||
|
||||
BOOST_PP_REPEAT(MOCK_MAX_SEQUENCES,
|
||||
MOCK_FUNCTION_IN, _)
|
||||
BOOST_PP_REPEAT(MOCK_MAX_SEQUENCES, MOCK_FUNCTION_IN, _)
|
||||
|
||||
#undef MOCK_FUNCTION_IN
|
||||
#undef MOCK_FUNCTION_IN_ADD
|
||||
|
|
@ -221,33 +195,30 @@ namespace detail
|
|||
return wrapper(mutex_, expectations_.back());
|
||||
}
|
||||
|
||||
R operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const
|
||||
R operator()(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t)) const
|
||||
{
|
||||
lock _(mutex_);
|
||||
valid_ = false;
|
||||
for(const auto& expectation : expectations_)
|
||||
{
|
||||
if( expectation.is_valid(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _) ) )
|
||||
if(expectation.is_valid(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _)))
|
||||
{
|
||||
if(!expectation.invoke())
|
||||
{
|
||||
error_type::fail( "sequence failed",
|
||||
MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line() );
|
||||
error_type::fail(
|
||||
"sequence failed", MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line());
|
||||
return error_type::abort();
|
||||
}
|
||||
if(!expectation.valid())
|
||||
{
|
||||
error_type::fail( "missing action",
|
||||
MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line() );
|
||||
error_type::fail(
|
||||
"missing action", MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line());
|
||||
return error_type::abort();
|
||||
}
|
||||
valid_ = true;
|
||||
error_type::call(MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line());
|
||||
if(expectation.functor())
|
||||
return expectation.functor()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _) );
|
||||
return expectation.functor()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _));
|
||||
return expectation.trigger();
|
||||
}
|
||||
}
|
||||
|
|
@ -255,7 +226,8 @@ namespace detail
|
|||
return error_type::abort();
|
||||
}
|
||||
|
||||
void add( context& c, const void* p,
|
||||
void add(context& c,
|
||||
const void* p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
boost::unit_test::const_string name)
|
||||
|
|
@ -275,9 +247,7 @@ namespace detail
|
|||
|
||||
struct lazy_context
|
||||
{
|
||||
lazy_context( const function_impl* impl )
|
||||
: impl_( impl )
|
||||
{}
|
||||
lazy_context(const function_impl* impl) : impl_(impl) {}
|
||||
friend std::ostream& operator<<(std::ostream& s, const lazy_context& c)
|
||||
{
|
||||
if(c.impl_->context_)
|
||||
|
|
@ -291,9 +261,7 @@ namespace detail
|
|||
|
||||
struct lazy_expectations
|
||||
{
|
||||
lazy_expectations( const function_impl* impl )
|
||||
: impl_( impl )
|
||||
{}
|
||||
lazy_expectations(const function_impl* impl) : impl_(impl) {}
|
||||
friend std::ostream& operator<<(std::ostream& s, const lazy_expectations& e)
|
||||
{
|
||||
for(const auto& expectation : e.impl_->expectations_)
|
||||
|
|
@ -309,8 +277,7 @@ namespace detail
|
|||
const int exceptions_;
|
||||
const std::shared_ptr<mutex> mutex_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#undef MOCK_FUNCTION_FORMAT
|
||||
#undef MOCK_FUNCTION_CONTEXT
|
||||
|
|
|
|||
|
|
@ -8,44 +8,30 @@
|
|||
|
||||
#include "function_impl_template.hpp"
|
||||
|
||||
#define MOCK_FORWARD(z, n, d) \
|
||||
std::forward< T##n >( t##n )
|
||||
#define MOCK_FORWARD(z, n, d) std::forward<T##n>(t##n)
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class function;
|
||||
namespace mock { namespace detail {
|
||||
template<typename Signature>
|
||||
class function;
|
||||
|
||||
template< typename R
|
||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||
class function<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>
|
||||
{
|
||||
private:
|
||||
typedef function_impl<
|
||||
R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
||||
> impl_type;
|
||||
typedef function_impl<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> impl_type;
|
||||
typedef typename impl_type::wrapper_type expectation_type;
|
||||
typedef typename impl_type::error_type error_type;
|
||||
|
||||
public:
|
||||
function()
|
||||
: impl_( std::make_shared< impl_type >() )
|
||||
{}
|
||||
function() : impl_(std::make_shared<impl_type>()) {}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
return impl_->verify();
|
||||
}
|
||||
bool verify() const { return impl_->verify(); }
|
||||
bool verify(const char* file, int line) const
|
||||
{
|
||||
error_type::pass(file, line);
|
||||
return impl_->verify();
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
impl_->reset();
|
||||
}
|
||||
void reset() { impl_->reset(); }
|
||||
void reset(const char* file, int line)
|
||||
{
|
||||
error_type::pass(file, line);
|
||||
|
|
@ -57,30 +43,23 @@ namespace detail
|
|||
error_type::pass(file, line);
|
||||
return impl_->expect(file, line);
|
||||
}
|
||||
expectation_type expect()
|
||||
{
|
||||
return impl_->expect();
|
||||
}
|
||||
expectation_type expect() { return impl_->expect(); }
|
||||
|
||||
R operator()(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const
|
||||
R operator()(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t)) const
|
||||
{
|
||||
return (*impl_)(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _));
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const function& f )
|
||||
{
|
||||
return s << *f.impl_;
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const function& f) { return s << *f.impl_; }
|
||||
|
||||
function& operator()( context& c,
|
||||
boost::unit_test::const_string instance )
|
||||
function& operator()(context& c, boost::unit_test::const_string instance)
|
||||
{
|
||||
impl_->add(c, impl_.get(), instance, boost::none, "");
|
||||
return *this;
|
||||
}
|
||||
|
||||
void configure( context& c, const void* p,
|
||||
void configure(context& c,
|
||||
const void* p,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
boost::unit_test::const_string name) const
|
||||
|
|
@ -91,7 +70,6 @@ namespace detail
|
|||
private:
|
||||
std::shared_ptr<impl_type> impl_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#undef MOCK_FORWARD
|
||||
|
|
|
|||
|
|
@ -14,13 +14,8 @@
|
|||
#include "mutex.hpp"
|
||||
#include "singleton.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class functor_mutex_t :
|
||||
public singleton< functor_mutex_t >,
|
||||
public mutex
|
||||
namespace mock { namespace detail {
|
||||
class functor_mutex_t : public singleton<functor_mutex_t>, public mutex
|
||||
{
|
||||
MOCK_SINGLETON_CONS(functor_mutex_t);
|
||||
};
|
||||
|
|
@ -38,15 +33,13 @@ namespace detail
|
|||
*this = *f;
|
||||
f = 0;
|
||||
functor_mutex.unlock();
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
functor_mutex.lock();
|
||||
f = this;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_FUNCTOR_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -11,26 +11,18 @@
|
|||
|
||||
#include "../config.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class group
|
||||
{
|
||||
public:
|
||||
void add( verifiable& v )
|
||||
{
|
||||
verifiables_.push_back( &v );
|
||||
}
|
||||
void add(verifiable& v) { verifiables_.push_back(&v); }
|
||||
void remove(verifiable& v)
|
||||
{
|
||||
verifiables_.erase(
|
||||
std::remove( verifiables_.begin(), verifiables_.end(), &v ),
|
||||
verifiables_.end() );
|
||||
verifiables_.erase(std::remove(verifiables_.begin(), verifiables_.end(), &v), verifiables_.end());
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
|
|
@ -52,7 +44,6 @@ namespace detail
|
|||
private:
|
||||
std::vector<verifiable*> verifiables_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_GROUP_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,14 +10,11 @@
|
|||
#define MOCK_INVOCATION_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <stdexcept>
|
||||
#include <ostream>
|
||||
#include <limits>
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class invocation
|
||||
{
|
||||
public:
|
||||
|
|
@ -32,10 +29,7 @@ namespace detail
|
|||
|
||||
virtual bool exhausted() const = 0;
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const invocation& i )
|
||||
{
|
||||
return i.serialize( s );
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const invocation& i) { return i.serialize(s); }
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize(std::ostream& s) const = 0;
|
||||
|
|
@ -44,10 +38,7 @@ namespace detail
|
|||
class between : public invocation
|
||||
{
|
||||
public:
|
||||
between( std::size_t min, std::size_t max )
|
||||
: min_( min )
|
||||
, max_( max )
|
||||
, count_( 0 )
|
||||
between(std::size_t min, std::size_t max) : min_(min), max_(max), count_(0)
|
||||
{
|
||||
if(min > max)
|
||||
throw std::invalid_argument("'min' > 'max'");
|
||||
|
|
@ -61,15 +52,9 @@ namespace detail
|
|||
return true;
|
||||
}
|
||||
|
||||
virtual bool exhausted() const
|
||||
{
|
||||
return count_ >= max_;
|
||||
}
|
||||
virtual bool exhausted() const { return count_ >= max_; }
|
||||
|
||||
virtual bool verify() const
|
||||
{
|
||||
return min_ <= count_ && count_ <= max_;
|
||||
}
|
||||
virtual bool verify() const { return min_ <= count_ && count_ <= max_; }
|
||||
|
||||
protected:
|
||||
const std::size_t min_, max_;
|
||||
|
|
@ -78,17 +63,14 @@ namespace detail
|
|||
private:
|
||||
virtual std::ostream& serialize(std::ostream& s) const
|
||||
{
|
||||
return s << "between( " << count_
|
||||
<< "/[" << min_ << ',' << max_ << "] )";
|
||||
return s << "between( " << count_ << "/[" << min_ << ',' << max_ << "] )";
|
||||
}
|
||||
};
|
||||
|
||||
class exactly : public between
|
||||
{
|
||||
public:
|
||||
explicit exactly( std::size_t count )
|
||||
: between( count, count )
|
||||
{}
|
||||
explicit exactly(std::size_t count) : between(count, count) {}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize(std::ostream& s) const
|
||||
|
|
@ -100,37 +82,25 @@ namespace detail
|
|||
class never : public exactly
|
||||
{
|
||||
public:
|
||||
never()
|
||||
: exactly( 0 )
|
||||
{}
|
||||
never() : exactly(0) {}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "never()";
|
||||
}
|
||||
virtual std::ostream& serialize(std::ostream& s) const { return s << "never()"; }
|
||||
};
|
||||
|
||||
class once : public exactly
|
||||
{
|
||||
public:
|
||||
once()
|
||||
: exactly( 1 )
|
||||
{}
|
||||
once() : exactly(1) {}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "once()";
|
||||
}
|
||||
virtual std::ostream& serialize(std::ostream& s) const { return s << "once()"; }
|
||||
};
|
||||
|
||||
class at_least : public between
|
||||
{
|
||||
public:
|
||||
explicit at_least( std::size_t min )
|
||||
: between( min, (std::numeric_limits< std::size_t >::max)() )
|
||||
{}
|
||||
explicit at_least(std::size_t min) : between(min, (std::numeric_limits<std::size_t>::max)()) {}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize(std::ostream& s) const
|
||||
|
|
@ -142,9 +112,7 @@ namespace detail
|
|||
class at_most : public between
|
||||
{
|
||||
public:
|
||||
explicit at_most( std::size_t max )
|
||||
: between( 0, max )
|
||||
{}
|
||||
explicit at_most(std::size_t max) : between(0, max) {}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize(std::ostream& s) const
|
||||
|
|
@ -156,17 +124,11 @@ namespace detail
|
|||
class unlimited : public at_least
|
||||
{
|
||||
public:
|
||||
unlimited()
|
||||
: at_least( 0 )
|
||||
{}
|
||||
unlimited() : at_least(0) {}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "unlimited()";
|
||||
}
|
||||
virtual std::ostream& serialize(std::ostream& s) const { return s << "unlimited()"; }
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_INVOCATION_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -13,10 +13,7 @@
|
|||
#include "void_t.hpp"
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
/// Trait to return true if F is a functor that can be called with a single argument Arg
|
||||
template<typename F, typename Arg, class = void>
|
||||
struct is_functor : std::false_type
|
||||
|
|
@ -24,7 +21,6 @@ namespace detail
|
|||
template<typename F, typename Arg>
|
||||
struct is_functor<F, Arg, void_t<decltype(std::declval<F>()(std::declval<Arg>()))>> : std::true_type
|
||||
{};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -6,17 +6,13 @@
|
|||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define MOCK_REF_ARG(z, n, d) \
|
||||
typename ref_arg< T##n >::type
|
||||
#define MOCK_REF_ARG(z, n, d) typename ref_arg<T##n>::type
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Signature > class matcher_base;
|
||||
namespace mock { namespace detail {
|
||||
template<typename Signature>
|
||||
class matcher_base;
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
||||
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||
class matcher_base<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>
|
||||
{
|
||||
public:
|
||||
|
|
@ -25,8 +21,7 @@ namespace detail
|
|||
matcher_base& operator=(const matcher_base&) = delete;
|
||||
virtual ~matcher_base() = default;
|
||||
|
||||
virtual bool operator()(
|
||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) ) = 0;
|
||||
virtual bool operator()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _)) = 0;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& s, const matcher_base& m)
|
||||
{
|
||||
|
|
@ -37,7 +32,6 @@ namespace detail
|
|||
private:
|
||||
virtual void serialize(std::ostream&) const = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#undef MOCK_REF_ARG
|
||||
|
|
|
|||
|
|
@ -11,17 +11,9 @@
|
|||
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
template<typename T>
|
||||
using ref_arg = std::conditional<
|
||||
std::is_reference< T >::value,
|
||||
T,
|
||||
std::add_rvalue_reference_t< T >
|
||||
>;
|
||||
}
|
||||
}
|
||||
using ref_arg = std::conditional<std::is_reference<T>::value, T, std::add_rvalue_reference_t<T>>;
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_MOVE_HELPER_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -18,14 +18,11 @@
|
|||
# ifdef MOCK_HDR_MUTEX
|
||||
# include <mutex>
|
||||
# else
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
# include <boost/thread/lock_guard.hpp>
|
||||
# include <boost/thread/recursive_mutex.hpp>
|
||||
# endif
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
# ifdef MOCK_HDR_MUTEX
|
||||
typedef std::recursive_mutex mutex;
|
||||
typedef std::lock_guard<mutex> scoped_lock;
|
||||
|
|
@ -37,11 +34,7 @@ namespace detail
|
|||
struct lock
|
||||
{
|
||||
public:
|
||||
lock( const std::shared_ptr< mutex >& m )
|
||||
: m_( m )
|
||||
{
|
||||
m_->lock();
|
||||
}
|
||||
lock(const std::shared_ptr<mutex>& m) : m_(m) { m_->lock(); }
|
||||
~lock()
|
||||
{
|
||||
if(m_)
|
||||
|
|
@ -55,25 +48,19 @@ namespace detail
|
|||
private:
|
||||
std::shared_ptr<mutex> m_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#else // MOCK_THREAD_SAFE
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
struct mutex
|
||||
{
|
||||
mutex() = default;
|
||||
mutex(const mutex&) = delete;
|
||||
mutex& operator=(const mutex&) = delete;
|
||||
|
||||
void lock()
|
||||
{}
|
||||
void unlock()
|
||||
{}
|
||||
void lock() {}
|
||||
void unlock() {}
|
||||
};
|
||||
// Dummy lock classes.
|
||||
// Constructor + Destructor make it RAII classes for compilers and avoid unused variable warnings
|
||||
|
|
@ -95,17 +82,12 @@ namespace detail
|
|||
lock& operator=(const lock&) = delete;
|
||||
lock& operator=(lock&&) = default;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_THREAD_SAFE
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class error_mutex_t : public singleton< error_mutex_t >,
|
||||
public mutex
|
||||
namespace mock { namespace detail {
|
||||
class error_mutex_t : public singleton<error_mutex_t>, public mutex
|
||||
{
|
||||
MOCK_SINGLETON_CONS(error_mutex_t);
|
||||
};
|
||||
|
|
@ -124,8 +106,10 @@ namespace detail
|
|||
return Error::abort();
|
||||
}
|
||||
template<typename Context>
|
||||
static void fail( const char* message, const Context& context,
|
||||
const char* file = "unknown location", int line = 0 )
|
||||
static void fail(const char* message,
|
||||
const Context& context,
|
||||
const char* file = "unknown location",
|
||||
int line = 0)
|
||||
{
|
||||
scoped_lock _(error_mutex);
|
||||
Error::fail(message, context, file, line);
|
||||
|
|
@ -145,7 +129,6 @@ namespace detail
|
|||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_MUTEX_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,28 +10,23 @@
|
|||
#define MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "root.hpp"
|
||||
#include "parent.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include "context.hpp"
|
||||
#include "child.hpp"
|
||||
#include "context.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include "parent.hpp"
|
||||
#include "root.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class object_impl : public context, public verifiable,
|
||||
public std::enable_shared_from_this< object_impl >
|
||||
namespace mock { namespace detail {
|
||||
class object_impl : public context, public verifiable, public std::enable_shared_from_this<object_impl>
|
||||
{
|
||||
public:
|
||||
object_impl()
|
||||
: mutex_( std::make_shared< mutex >() )
|
||||
{}
|
||||
object_impl() : mutex_(std::make_shared<mutex>()) {}
|
||||
|
||||
virtual void add( const void* /*p*/, verifiable& v,
|
||||
virtual void add(const void* /*p*/,
|
||||
verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
boost::unit_test::const_string name)
|
||||
|
|
@ -83,7 +78,6 @@ namespace detail
|
|||
std::map<const verifiable*, child> children_;
|
||||
const std::shared_ptr<mutex> mutex_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -11,10 +11,7 @@
|
|||
|
||||
#include "../config.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
template<class...>
|
||||
struct tuple;
|
||||
|
||||
|
|
@ -74,7 +71,6 @@ namespace detail
|
|||
};
|
||||
template<typename T>
|
||||
using parameter_type_t = typename parameter_type<T>::type;
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_PARAMETER_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -11,22 +11,17 @@
|
|||
|
||||
#include "../config.hpp"
|
||||
#include "type_name.hpp"
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class parent
|
||||
{
|
||||
public:
|
||||
parent() = default;
|
||||
parent( boost::unit_test::const_string instance,
|
||||
boost::optional< type_name > type )
|
||||
: instance_( instance )
|
||||
, type_( type )
|
||||
parent(boost::unit_test::const_string instance, boost::optional<type_name> type)
|
||||
: instance_(instance), type_(type)
|
||||
{}
|
||||
friend std::ostream& operator<<(std::ostream& s, const parent& p)
|
||||
{
|
||||
|
|
@ -35,11 +30,11 @@ namespace detail
|
|||
s << *p.type_ << "::";
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
boost::unit_test::const_string instance_;
|
||||
boost::optional<type_name> type_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_PARENT_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,34 +10,30 @@
|
|||
#define MOCK_ROOT_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include "parent.hpp"
|
||||
#include "group.hpp"
|
||||
#include "context.hpp"
|
||||
#include "child.hpp"
|
||||
#include "context.hpp"
|
||||
#include "group.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include "parent.hpp"
|
||||
#include "singleton.hpp"
|
||||
#include <boost/optional.hpp>
|
||||
#include <ostream>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class root_t : public singleton<root_t>, public context
|
||||
{
|
||||
public:
|
||||
virtual void add( const void* p, verifiable& v,
|
||||
virtual void add(const void* p,
|
||||
verifiable& v,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
boost::unit_test::const_string name)
|
||||
{
|
||||
scoped_lock _(mutex_);
|
||||
auto it = children_.lower_bound(&v);
|
||||
if( it == children_.end() ||
|
||||
children_.key_comp()( &v, it->first ) )
|
||||
it = children_.insert( it,
|
||||
std::make_pair( &v, counter_child( parents_, p ) ) );
|
||||
if(it == children_.end() || children_.key_comp()(&v, it->first))
|
||||
it = children_.insert(it, std::make_pair(&v, counter_child(parents_, p)));
|
||||
it->second.update(instance, type, name);
|
||||
}
|
||||
virtual void add(verifiable& v)
|
||||
|
|
@ -75,23 +71,17 @@ namespace detail
|
|||
}
|
||||
|
||||
private:
|
||||
typedef std::map< const void*,
|
||||
std::pair< parent, std::size_t > > parents_t;
|
||||
typedef std::map<const void*, std::pair<parent, std::size_t>> parents_t;
|
||||
|
||||
class counter_child
|
||||
{
|
||||
public:
|
||||
counter_child(parents_t& parents, const void* p)
|
||||
: parents_( &parents )
|
||||
, it_( parents.insert(
|
||||
std::make_pair( p, parents_t::mapped_type() ) ).first )
|
||||
: parents_(&parents), it_(parents.insert(std::make_pair(p, parents_t::mapped_type())).first)
|
||||
{
|
||||
++it_->second.second;
|
||||
}
|
||||
counter_child( const counter_child& rhs )
|
||||
: parents_( rhs.parents_ )
|
||||
, it_( rhs.it_ )
|
||||
, child_( rhs.child_ )
|
||||
counter_child(const counter_child& rhs) : parents_(rhs.parents_), it_(rhs.it_), child_(rhs.child_)
|
||||
{
|
||||
++it_->second.second;
|
||||
}
|
||||
|
|
@ -106,11 +96,7 @@ namespace detail
|
|||
{
|
||||
child_.update(it_->second.first, instance, type, name);
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s,
|
||||
const counter_child& c )
|
||||
{
|
||||
return s << c.child_;
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const counter_child& c) { return s << c.child_; }
|
||||
|
||||
private:
|
||||
counter_child& operator=(const counter_child&);
|
||||
|
|
@ -128,7 +114,6 @@ namespace detail
|
|||
MOCK_SINGLETON_CONS(root_t);
|
||||
};
|
||||
MOCK_SINGLETON_INST(root)
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_ROOT_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -15,16 +15,11 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class sequence_impl
|
||||
{
|
||||
public:
|
||||
sequence_impl()
|
||||
: mutex_( std::make_shared< mutex >() )
|
||||
{}
|
||||
sequence_impl() : mutex_(std::make_shared<mutex>()) {}
|
||||
|
||||
void add(void* e)
|
||||
{
|
||||
|
|
@ -34,15 +29,13 @@ namespace detail
|
|||
void remove(void* e)
|
||||
{
|
||||
lock _(mutex_);
|
||||
elements_.erase( std::remove( elements_.begin(),
|
||||
elements_.end(), e ), elements_.end() );
|
||||
elements_.erase(std::remove(elements_.begin(), elements_.end(), e), elements_.end());
|
||||
}
|
||||
|
||||
bool is_valid(const void* e) const
|
||||
{
|
||||
lock _(mutex_);
|
||||
return std::find( elements_.begin(), elements_.end(), e )
|
||||
!= elements_.end();
|
||||
return std::find(elements_.begin(), elements_.end(), e) != elements_.end();
|
||||
}
|
||||
|
||||
void invalidate(const void* e)
|
||||
|
|
@ -57,7 +50,6 @@ namespace detail
|
|||
std::vector<void*> elements_;
|
||||
const std::shared_ptr<mutex> mutex_;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -12,18 +12,19 @@
|
|||
#include "../config.hpp"
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
#define MOCK_NOARG
|
||||
#define MOCK_STRIP_FUNCTION_QUALIFIERS(cv, ref) \
|
||||
template<typename R, typename... Args> \
|
||||
struct strip_function_qualifiers<R(Args...) cv ref> \
|
||||
{ using type = R(Args...); }; \
|
||||
{ \
|
||||
using type = R(Args...); \
|
||||
}; \
|
||||
template<typename R, typename... Args> \
|
||||
struct strip_function_qualifiers<R(Args..., ...) cv ref> \
|
||||
{ using type = R(Args..., ...); };
|
||||
{ \
|
||||
using type = R(Args..., ...); \
|
||||
};
|
||||
|
||||
#define MOCK_STRIP_FUNCTION_QUALIFIERS_REF(cv) \
|
||||
MOCK_STRIP_FUNCTION_QUALIFIERS(cv, ) \
|
||||
|
|
@ -64,14 +65,10 @@ namespace detail
|
|||
// disambiguate
|
||||
template<typename T>
|
||||
T& ambiguous_method_requires_to_specify_signature(const T&);
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#define MOCK_SIGNATURE(M) \
|
||||
mock::detail::signature< \
|
||||
std::remove_cv_t< std::remove_reference_t < decltype( \
|
||||
mock::detail::ambiguous_method_requires_to_specify_signature( &base_type::M ) \
|
||||
) > > \
|
||||
>::type
|
||||
mock::detail::signature<std::remove_cv_t<std::remove_reference_t<decltype( \
|
||||
mock::detail::ambiguous_method_requires_to_specify_signature(&base_type::M))>>>::type
|
||||
|
||||
#endif // MOCK_SIGNATURE_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace mock {
|
||||
namespace detail {
|
||||
namespace mock { namespace detail {
|
||||
|
||||
template<typename Derived>
|
||||
class singleton {
|
||||
class singleton
|
||||
{
|
||||
public:
|
||||
static Derived& instance()
|
||||
{
|
||||
|
|
@ -23,16 +23,15 @@ public:
|
|||
return the_inst;
|
||||
}
|
||||
|
||||
BOOST_DELETED_FUNCTION(singleton(singleton const&))
|
||||
BOOST_DELETED_FUNCTION(singleton& operator=(singleton const&))
|
||||
singleton(singleton const&) = delete;
|
||||
singleton& operator=(singleton const&) = delete;
|
||||
|
||||
protected:
|
||||
BOOST_DEFAULTED_FUNCTION(singleton(), {})
|
||||
BOOST_DEFAULTED_FUNCTION(~singleton(), {})
|
||||
singleton() = default;
|
||||
~singleton() = default;
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
// Add a private ctor to the type to prevent misuse
|
||||
#define MOCK_SINGLETON_CONS(type) \
|
||||
|
|
@ -40,7 +39,6 @@ private: \
|
|||
friend class mock::detail::singleton<type>; \
|
||||
type() = default
|
||||
|
||||
#define MOCK_SINGLETON_INST( inst ) \
|
||||
static BOOST_JOIN( inst, _t )& inst = BOOST_JOIN( inst, _t )::instance();
|
||||
#define MOCK_SINGLETON_INST(inst) static BOOST_JOIN(inst, _t)& inst = BOOST_JOIN(inst, _t)::instance();
|
||||
|
||||
#endif // MOCK_SINGLETON_HPP
|
||||
|
|
|
|||
|
|
@ -10,35 +10,31 @@
|
|||
#define MOCK_TYPE_NAME_HPP_INCLUDED
|
||||
|
||||
#include "../config.hpp"
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/erase.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||
#include <boost/version.hpp>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <typeinfo>
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#ifdef __GNUC__
|
||||
#include <cxxabi.h>
|
||||
# include <cstdlib>
|
||||
# include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class type_name
|
||||
{
|
||||
public:
|
||||
explicit type_name( const std::type_info& info )
|
||||
: info_( &info )
|
||||
{}
|
||||
explicit type_name(const std::type_info& info) : info_(&info) {}
|
||||
friend std::ostream& operator<<(std::ostream& s, const type_name& t)
|
||||
{
|
||||
t.serialize(s, *t.info_);
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
static void serialize(std::ostream& s, const std::type_info& info)
|
||||
{
|
||||
|
|
@ -49,8 +45,7 @@ namespace detail
|
|||
{
|
||||
void operator()(const void* p) { std::free(const_cast<void*>(p)); }
|
||||
};
|
||||
std::unique_ptr< const char, Deleter > demangled(
|
||||
abi::__cxa_demangle( name, 0, 0, &status ));
|
||||
std::unique_ptr<const char, Deleter> demangled(abi::__cxa_demangle(name, 0, 0, &status));
|
||||
if(!status && demangled)
|
||||
serialize(s, demangled.get());
|
||||
else
|
||||
|
|
@ -120,7 +115,6 @@ namespace detail
|
|||
{
|
||||
return type_name(typeid(T));
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_TYPE_NAME_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -11,10 +11,7 @@
|
|||
|
||||
#include "../config.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
class verifiable
|
||||
{
|
||||
public:
|
||||
|
|
@ -27,7 +24,6 @@ namespace detail
|
|||
|
||||
virtual void reset() = 0;
|
||||
};
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -9,10 +9,7 @@
|
|||
#ifndef MOCK_VOID_T_HPP_INCLUDED
|
||||
#define MOCK_VOID_T_HPP_INCLUDED
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
template<typename...>
|
||||
struct make_void
|
||||
{
|
||||
|
|
@ -21,7 +18,6 @@ namespace detail
|
|||
/// Standard helper to implement the detection idiom. Returns always void
|
||||
template<typename... Ts>
|
||||
using void_t = typename make_void<Ts...>::type;
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
#endif // MOCK_VOID_T_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -12,33 +12,29 @@
|
|||
#include "config.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
# include "exception.hpp"
|
||||
#include <boost/version.hpp>
|
||||
# include <boost/exception/enable_current_exception.hpp>
|
||||
# include <boost/test/framework.hpp>
|
||||
# include <boost/test/test_tools.hpp>
|
||||
# include <boost/test/unit_test_suite.hpp>
|
||||
#include <boost/exception/enable_current_exception.hpp>
|
||||
# include <boost/version.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
template<typename Result>
|
||||
struct error
|
||||
{
|
||||
static Result abort()
|
||||
{
|
||||
boost::unit_test::framework::test_unit_aborted(
|
||||
boost::unit_test::framework::current_test_case() );
|
||||
boost::unit_test::framework::test_unit_aborted(boost::unit_test::framework::current_test_case());
|
||||
throw boost::enable_current_exception(exception());
|
||||
}
|
||||
|
||||
static void pass(const char* file, int line)
|
||||
{
|
||||
boost::unit_test::unit_test_log.set_checkpoint( file,
|
||||
static_cast< std::size_t >( line ) );
|
||||
boost::unit_test::unit_test_log.set_checkpoint(file, static_cast<std::size_t>(line));
|
||||
}
|
||||
|
||||
template<typename Context>
|
||||
static void fail( const char* message, const Context& context,
|
||||
const char* file = "unknown location", int line = 0 )
|
||||
static void fail(const char* message, const Context& context, const char* file = "unknown location", int line = 0)
|
||||
{
|
||||
boost::unit_test::framework::assertion_result(
|
||||
# if BOOST_VERSION < 105900
|
||||
|
|
@ -47,11 +43,8 @@ namespace mock
|
|||
boost::unit_test::AR_FAILED
|
||||
# endif
|
||||
);
|
||||
boost::unit_test::unit_test_log
|
||||
<< boost::unit_test::log::begin( file,
|
||||
static_cast< std::size_t >( line ) )
|
||||
<< boost::unit_test::log_all_errors
|
||||
<< message << ": " << context
|
||||
boost::unit_test::unit_test_log << boost::unit_test::log::begin(file, static_cast<std::size_t>(line))
|
||||
<< boost::unit_test::log_all_errors << message << ": " << context
|
||||
<< boost::unit_test::log::end();
|
||||
}
|
||||
|
||||
|
|
@ -65,15 +58,12 @@ namespace mock
|
|||
boost::unit_test::AR_PASSED
|
||||
# endif
|
||||
);
|
||||
boost::unit_test::unit_test_log
|
||||
<< boost::unit_test::log::begin( file,
|
||||
static_cast< std::size_t >( line ) )
|
||||
boost::unit_test::unit_test_log << boost::unit_test::log::begin(file, static_cast<std::size_t>(line))
|
||||
<< boost::unit_test::log_successful_tests
|
||||
<< "mock expectation fulfilled: " << context
|
||||
<< boost::unit_test::log::end();
|
||||
<< "mock expectation fulfilled: " << context << boost::unit_test::log::end();
|
||||
}
|
||||
};
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,10 @@
|
|||
#ifdef MOCK_USE_BOOST_TEST
|
||||
# include <boost/test/execution_monitor.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
struct exception : virtual boost::execution_aborted
|
||||
{};
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,13 @@
|
|||
#include "config.hpp"
|
||||
#include "detail/formatter.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
template<typename T>
|
||||
detail::formatter<T> format(const T& t)
|
||||
{
|
||||
return detail::formatter<T>(t);
|
||||
}
|
||||
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_FORMAT_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,38 +10,39 @@
|
|||
#define MOCK_LOG_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "stream.hpp"
|
||||
#include "format.hpp"
|
||||
#include "stream.hpp"
|
||||
#include <boost/detail/container_fwd.hpp>
|
||||
#include <boost/none.hpp>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< typename T > class shared_ptr;
|
||||
template< typename T > class weak_ptr;
|
||||
template< typename T > class reference_wrapper;
|
||||
template< typename T > class optional;
|
||||
namespace boost {
|
||||
template<typename T>
|
||||
class shared_ptr;
|
||||
template<typename T>
|
||||
class weak_ptr;
|
||||
template<typename T>
|
||||
class reference_wrapper;
|
||||
template<typename T>
|
||||
class optional;
|
||||
|
||||
namespace phoenix
|
||||
{
|
||||
template< typename T > struct actor;
|
||||
namespace phoenix {
|
||||
template<typename T>
|
||||
struct actor;
|
||||
}
|
||||
namespace lambda
|
||||
{
|
||||
template< typename T > class lambda_functor;
|
||||
}
|
||||
namespace assign_detail
|
||||
{
|
||||
template< typename T > class generic_list;
|
||||
namespace lambda {
|
||||
template<typename T>
|
||||
class lambda_functor;
|
||||
}
|
||||
namespace assign_detail {
|
||||
template<typename T>
|
||||
class generic_list;
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
void serialize(stream& s, const T& begin, const T& end)
|
||||
{
|
||||
|
|
@ -59,13 +60,12 @@ namespace detail
|
|||
template<typename T>
|
||||
struct is_callable : is_callable_impl<std::remove_cv_t<T>>
|
||||
{};
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template<typename T1, typename T2>
|
||||
stream& operator<<(stream& s, const std::pair<T1, T2>& p)
|
||||
{
|
||||
return s << '(' << mock::format( p.first )
|
||||
<< ',' << mock::format( p.second ) << ')';
|
||||
return s << '(' << mock::format(p.first) << ',' << mock::format(p.second) << ')';
|
||||
}
|
||||
|
||||
template<typename T, typename A>
|
||||
|
|
@ -111,8 +111,7 @@ namespace detail
|
|||
return s;
|
||||
}
|
||||
template<typename T>
|
||||
stream& operator<<( stream& s,
|
||||
const boost::assign_detail::generic_list< T >& t )
|
||||
stream& operator<<(stream& s, const boost::assign_detail::generic_list<T>& t)
|
||||
{
|
||||
detail::serialize(s, t.begin(), t.end());
|
||||
return s;
|
||||
|
|
@ -182,18 +181,16 @@ namespace detail
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t< detail::is_callable< T >::value, stream& >
|
||||
operator<<( stream& s, T* )
|
||||
std::enable_if_t<detail::is_callable<T>::value, stream&> operator<<(stream& s, T*)
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
template<typename T>
|
||||
std::enable_if_t< !detail::is_callable< T >::value, stream& >
|
||||
operator<<( stream& s, T* t )
|
||||
std::enable_if_t<!detail::is_callable<T>::value, stream&> operator<<(stream& s, T* t)
|
||||
{
|
||||
*s.s_ << t;
|
||||
return s;
|
||||
}
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_LOG_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,31 +10,26 @@
|
|||
#define MOCK_MATCHER_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "constraints.hpp"
|
||||
#include "detail/is_functor.hpp"
|
||||
#include "detail/move_helper.hpp"
|
||||
#include "log.hpp"
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
template<typename Actual, typename Expected, typename Enable = void>
|
||||
class matcher
|
||||
{
|
||||
public:
|
||||
explicit matcher( Expected expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
explicit matcher(Expected expected) : expected_(expected) {}
|
||||
bool operator()(std::add_lvalue_reference_t<const Actual> actual)
|
||||
{
|
||||
return mock::equal(mock::unwrap_ref(expected_)).c_(actual);
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.expected_ );
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const matcher& m) { return s << mock::format(m.expected_); }
|
||||
|
||||
private:
|
||||
Expected expected_;
|
||||
};
|
||||
|
|
@ -43,17 +38,10 @@ namespace mock
|
|||
class matcher<const char*, const char*>
|
||||
{
|
||||
public:
|
||||
explicit matcher( const char* expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
bool operator()( const char* actual )
|
||||
{
|
||||
return std::strcmp( actual, expected_ ) == 0;
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.expected_ );
|
||||
}
|
||||
explicit matcher(const char* expected) : expected_(expected) {}
|
||||
bool operator()(const char* actual) { return std::strcmp(actual, expected_) == 0; }
|
||||
friend std::ostream& operator<<(std::ostream& s, const matcher& m) { return s << mock::format(m.expected_); }
|
||||
|
||||
private:
|
||||
const char* expected_;
|
||||
};
|
||||
|
|
@ -62,43 +50,31 @@ namespace mock
|
|||
class matcher<Actual, mock::constraint<Constraint>>
|
||||
{
|
||||
public:
|
||||
explicit matcher( const constraint< Constraint >& c )
|
||||
: c_( c.c_ )
|
||||
{}
|
||||
explicit matcher(const constraint<Constraint>& c) : c_(c.c_) {}
|
||||
bool operator()(typename detail::ref_arg<Actual>::type actual)
|
||||
{
|
||||
return c_(std::forward<typename detail::ref_arg<Actual>::type>(actual));
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.c_ );
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const matcher& m) { return s << mock::format(m.c_); }
|
||||
|
||||
private:
|
||||
Constraint c_;
|
||||
};
|
||||
|
||||
template<typename Actual, typename Functor>
|
||||
class matcher< Actual, Functor,
|
||||
std::enable_if_t<
|
||||
detail::is_functor< Functor, Actual >::value
|
||||
>
|
||||
>
|
||||
class matcher<Actual, Functor, std::enable_if_t<detail::is_functor<Functor, Actual>::value>>
|
||||
{
|
||||
public:
|
||||
explicit matcher( const Functor& f )
|
||||
: c_( f )
|
||||
{}
|
||||
explicit matcher(const Functor& f) : c_(f) {}
|
||||
bool operator()(typename detail::ref_arg<Actual>::type actual)
|
||||
{
|
||||
return c_(std::forward<typename detail::ref_arg<Actual>::type>(actual));
|
||||
}
|
||||
friend std::ostream& operator<<( std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << mock::format( m.c_ );
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& s, const matcher& m) { return s << mock::format(m.c_); }
|
||||
|
||||
private:
|
||||
Functor c_;
|
||||
};
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_MATCHER_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -9,86 +9,70 @@
|
|||
#ifndef MOCK_MOCK_HPP_INCLUDED
|
||||
#define MOCK_MOCK_HPP_INCLUDED
|
||||
|
||||
#include "cleanup.hpp"
|
||||
#include "config.hpp"
|
||||
#include "detail/function.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
#include "detail/parameter.hpp"
|
||||
#include "detail/signature.hpp"
|
||||
#include "detail/type_name.hpp"
|
||||
#include "object.hpp"
|
||||
#include "reset.hpp"
|
||||
#include "verify.hpp"
|
||||
#include "cleanup.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
#include "detail/function.hpp"
|
||||
#include "detail/type_name.hpp"
|
||||
#include "detail/signature.hpp"
|
||||
#include "detail/parameter.hpp"
|
||||
#include <boost/preprocessor/repetition/repeat.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
|
||||
/// MOCK_CLASS( name )
|
||||
/// Define a class
|
||||
#define MOCK_CLASS(T) \
|
||||
struct T : mock::object
|
||||
#define MOCK_CLASS(T) struct T : mock::object
|
||||
|
||||
/// MOCK_PROTECT_FUNCTION_SIG( signature )
|
||||
/// Use this with MOCK_FUNCTION/MOCK_*_METHOD if the return type contains commas
|
||||
#define MOCK_PROTECT_FUNCTION_SIG(...) \
|
||||
mock::detail::parameter_type_t<void (__VA_ARGS__)>
|
||||
#define MOCK_PROTECT_FUNCTION_SIG(...) mock::detail::parameter_type_t<void(__VA_ARGS__)>
|
||||
|
||||
/// Internal compatibility macro if function signature is passed via BOOST_IDENTITY_TYPE
|
||||
/// TODO: Remove support for doing that and move remove_pointer_t to MOCK_PROTECT_FUNCTION_SIG
|
||||
#define MOCK_FUNCTION_TYPE(...) \
|
||||
std::remove_pointer_t< __VA_ARGS__ >
|
||||
#define MOCK_FUNCTION_TYPE(...) std::remove_pointer_t<__VA_ARGS__>
|
||||
|
||||
/// MOCK_BASE_CLASS( name, base )
|
||||
/// Define a class deriving from a base class
|
||||
#define MOCK_BASE_CLASS(T, ...) \
|
||||
struct T : __VA_ARGS__, mock::object, mock::detail::base< __VA_ARGS__ >
|
||||
#define MOCK_BASE_CLASS(T, ...) struct T : __VA_ARGS__, mock::object, mock::detail::base<__VA_ARGS__>
|
||||
|
||||
/// MOCK_FUNCTOR( name, signature )
|
||||
/// Define a callable variable/member
|
||||
#define MOCK_FUNCTOR(f, ...) \
|
||||
mock::detail::functor< MOCK_FUNCTION_TYPE(__VA_ARGS__) > f, f##_mock
|
||||
#define MOCK_FUNCTOR(f, ...) mock::detail::functor<MOCK_FUNCTION_TYPE(__VA_ARGS__)> f, f##_mock
|
||||
/// MOCK_FUNCTOR_TPL( name, signature )
|
||||
#define MOCK_FUNCTOR_TPL(f, ...) static_assert(false, "MOCK_FUNCTOR_TPL has been replaced by MOCK_FUNCTOR")
|
||||
|
||||
#define MOCK_HELPER(t) \
|
||||
t##_mock( mock::detail::root, BOOST_PP_STRINGIZE(t) )
|
||||
#define MOCK_ANONYMOUS_HELPER(t) \
|
||||
t##_mock( mock::detail::root, "?." )
|
||||
#define MOCK_HELPER(t) t##_mock(mock::detail::root, BOOST_PP_STRINGIZE(t))
|
||||
#define MOCK_ANONYMOUS_HELPER(t) t##_mock(mock::detail::root, "?.")
|
||||
|
||||
#define MOCK_METHOD_HELPER(S, t) \
|
||||
mutable mock::detail::function<MOCK_FUNCTION_TYPE(S)> t##_mock_; \
|
||||
mock::detail::function< MOCK_FUNCTION_TYPE(S) >& t##_mock( \
|
||||
const mock::detail::context&, \
|
||||
mock::detail::function<MOCK_FUNCTION_TYPE(S)>& t##_mock(const mock::detail::context&, \
|
||||
const boost::unit_test::const_string& instance) const \
|
||||
{ \
|
||||
mock::detail::configure( *this, t##_mock_, \
|
||||
mock::detail::configure(*this, \
|
||||
t##_mock_, \
|
||||
instance.substr(0, instance.rfind(BOOST_PP_STRINGIZE(t))), \
|
||||
mock::detail::make_type_name(*this), \
|
||||
BOOST_PP_STRINGIZE(t)); \
|
||||
return t##_mock_; \
|
||||
}
|
||||
|
||||
#define MOCK_PARAM(S, tpn) \
|
||||
tpn mock::detail::parameter< MOCK_FUNCTION_TYPE(S)
|
||||
#define MOCK_DECL_PARAM(z, n, d) \
|
||||
BOOST_PP_COMMA_IF(n) d, n >::type p##n
|
||||
#define MOCK_DECL_PARAMS(n, S, tpn) \
|
||||
BOOST_PP_REPEAT(n, MOCK_DECL_PARAM, MOCK_PARAM(S, tpn))
|
||||
#define MOCK_PARAM(S, tpn) tpn mock::detail::parameter < MOCK_FUNCTION_TYPE(S)
|
||||
#define MOCK_DECL_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > ::type p##n
|
||||
#define MOCK_DECL_PARAMS(n, S, tpn) BOOST_PP_REPEAT(n, MOCK_DECL_PARAM, MOCK_PARAM(S, tpn))
|
||||
#define MOCK_DECL(M, n, S, c, tpn) \
|
||||
tpn mock::detail::result_type< \
|
||||
MOCK_FUNCTION_TYPE(S) >::type M( \
|
||||
MOCK_DECL_PARAMS(n, S, tpn) ) c
|
||||
tpn mock::detail::result_type<MOCK_FUNCTION_TYPE(S)>::type M(MOCK_DECL_PARAMS(n, S, tpn)) c
|
||||
|
||||
#define MOCK_FORWARD_PARAM(z, n, d) \
|
||||
BOOST_PP_COMMA_IF(n) d, n >::type >( p##n )
|
||||
#define MOCK_FORWARD_PARAMS(n, S, tpn) \
|
||||
BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, \
|
||||
std::forward< MOCK_PARAM(S, tpn))
|
||||
#define MOCK_FORWARD_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > ::type > (p##n)
|
||||
#define MOCK_FORWARD_PARAMS(n, S, tpn) BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, std::forward < MOCK_PARAM(S, tpn))
|
||||
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
|
||||
MOCK_DECL(M, n, S, c, tpn) \
|
||||
{ \
|
||||
static_assert(n == mock::detail::function_arity<MOCK_FUNCTION_TYPE(S)>::value, "Arity mismatch"); \
|
||||
return MOCK_ANONYMOUS_HELPER(t)( \
|
||||
MOCK_FORWARD_PARAMS(n, S, tpn) ); \
|
||||
return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S, tpn)); \
|
||||
}
|
||||
|
||||
#define MOCK_METHOD_EXT(M, n, S, t) \
|
||||
|
|
@ -135,8 +119,7 @@
|
|||
#define MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(M, T, t) MOCK_NON_CONST_CONVERSION_OPERATOR(M, T, t)
|
||||
|
||||
#define MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
||||
s mock::detail::function< MOCK_FUNCTION_TYPE(S) >& t##_mock( \
|
||||
mock::detail::context& context, \
|
||||
s mock::detail::function<MOCK_FUNCTION_TYPE(S)>& t##_mock(mock::detail::context& context, \
|
||||
boost::unit_test::const_string instance) \
|
||||
{ \
|
||||
static mock::detail::function<MOCK_FUNCTION_TYPE(S)> f; \
|
||||
|
|
@ -144,25 +127,27 @@
|
|||
}
|
||||
|
||||
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t, tpn) \
|
||||
T( MOCK_DECL_PARAMS(n, void A, tpn) ) \
|
||||
{ \
|
||||
MOCK_HELPER(t)( MOCK_FORWARD_PARAMS(n, void A, tpn) ); \
|
||||
} \
|
||||
T(MOCK_DECL_PARAMS(n, void A, tpn)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A, tpn)); } \
|
||||
MOCK_FUNCTION_HELPER(void A, t, static, tpn)
|
||||
|
||||
/// MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier )
|
||||
/// As constructors do not have a return type, the usual signature gets restricted here to just the parameters.
|
||||
#define MOCK_CONSTRUCTOR(T, n, A, t) \
|
||||
MOCK_CONSTRUCTOR_AUX(T, n, A, t,)
|
||||
#define MOCK_CONSTRUCTOR(T, n, A, t) MOCK_CONSTRUCTOR_AUX(T, n, A, t, )
|
||||
/// MOCK_CONSTRUCTOR( [calling convention] name, arity, parameters, identifier )
|
||||
/// must be used if the signature uses a template parameter of the class
|
||||
/// As constructors do not have a return type, the usual signature gets restricted here to just the parameters.
|
||||
#define MOCK_CONSTRUCTOR_TPL(T, n, A, t) \
|
||||
MOCK_CONSTRUCTOR_AUX(T, n, A, t, typename)
|
||||
#define MOCK_CONSTRUCTOR_TPL(T, n, A, t) MOCK_CONSTRUCTOR_AUX(T, n, A, t, typename)
|
||||
|
||||
/// MOCK_DESTRUCTOR( [calling convention] ~name, identifier )
|
||||
#define MOCK_DESTRUCTOR(T, t) \
|
||||
T() { try { MOCK_ANONYMOUS_HELPER(t)(); } catch( ... ) {} } \
|
||||
T() \
|
||||
{ \
|
||||
try \
|
||||
{ \
|
||||
MOCK_ANONYMOUS_HELPER(t)(); \
|
||||
} catch(...) \
|
||||
{} \
|
||||
} \
|
||||
MOCK_METHOD_HELPER(void(), t)
|
||||
|
||||
#define MOCK_FUNCTION_AUX(F, n, S, t, s, tpn) \
|
||||
|
|
@ -199,53 +184,38 @@
|
|||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
|
||||
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
|
||||
|
||||
|
||||
/// MOCK_METHOD_TPL( [calling convention] name, arity, signature[, identifier] )
|
||||
/// must be used if the signature uses a template parameter of the class
|
||||
/// generates both const and non-const methods
|
||||
#define MOCK_METHOD_TPL(M, n, ...) \
|
||||
MOCK_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
||||
MOCK_METHOD_EXT_TPL(M, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
||||
/// MOCK_CONST_METHOD_TPL( [calling convention] name, arity, signature[, identifier] )
|
||||
/// must be used if the signature uses a template parameter of the class
|
||||
/// generates only the const version of the method
|
||||
#define MOCK_CONST_METHOD_TPL(M, n, ...) \
|
||||
MOCK_CONST_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
||||
MOCK_CONST_METHOD_EXT_TPL(M, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
||||
/// MOCK_NON_CONST_METHOD_TPL( [calling convention] name, arity, signature[, identifier] )
|
||||
/// must be used if the signature uses a template parameter of the class
|
||||
/// generates only the non-const version of the method
|
||||
#define MOCK_NON_CONST_METHOD_TPL(M, n, ...) \
|
||||
MOCK_NON_CONST_METHOD_EXT_TPL(M, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
||||
MOCK_NON_CONST_METHOD_EXT_TPL(M, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
||||
|
||||
/// MOCK_FUNCTION( [calling convention] name, arity, signature[, identifier] )
|
||||
/// if 'identifier' is omitted it will default to 'name'
|
||||
#define MOCK_FUNCTION(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), \
|
||||
inline,)
|
||||
MOCK_FUNCTION_AUX(F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), inline, )
|
||||
|
||||
/// MOCK_STATIC_METHOD( [calling convention] name, arity, signature[, identifier] )
|
||||
/// if 'identifier' is omitted it will default to 'name'
|
||||
#define MOCK_STATIC_METHOD(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), \
|
||||
static,)
|
||||
MOCK_FUNCTION_AUX(F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static, )
|
||||
|
||||
/// MOCK_STATIC_METHOD_TPL( [calling convention] name, arity, signature[, identifier] )
|
||||
/// must be used if the signature uses a template parameter of the class
|
||||
/// if 'identifier' is omitted it will default to 'name'
|
||||
#define MOCK_STATIC_METHOD_TPL(F, n, ...) \
|
||||
MOCK_FUNCTION_AUX(F, n, \
|
||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), \
|
||||
static, typename)
|
||||
MOCK_FUNCTION_AUX( \
|
||||
F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static, typename)
|
||||
|
||||
/// MOCK_EXPECT( identifier )
|
||||
#define MOCK_EXPECT(t) MOCK_HELPER(t).expect(__FILE__, __LINE__)
|
||||
|
|
|
|||
|
|
@ -10,28 +10,28 @@
|
|||
#define MOCK_OBJECT_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "detail/object_impl.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/type_name.hpp"
|
||||
#include "detail/object_impl.hpp"
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
class object;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
template<typename E>
|
||||
E& configure( const object& o, E& e,
|
||||
E& configure(const object& o,
|
||||
E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
boost::unit_test::const_string name);
|
||||
|
||||
template<typename T, typename E>
|
||||
E& configure( const T& t, E& e,
|
||||
E& configure(const T& t,
|
||||
E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
boost::unit_test::const_string name,
|
||||
|
|
@ -40,23 +40,23 @@ namespace detail
|
|||
e.configure(detail::root, &t, instance, type, name);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
class object
|
||||
{
|
||||
public:
|
||||
object()
|
||||
: impl_( std::make_shared< detail::object_impl >() )
|
||||
{}
|
||||
object() : impl_(std::make_shared<detail::object_impl>()) {}
|
||||
|
||||
protected:
|
||||
~object() = default;
|
||||
|
||||
public:
|
||||
std::shared_ptr<detail::object_impl> impl_;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
template<typename E>
|
||||
E& configure( const object& o, E& e,
|
||||
E& configure(const object& o,
|
||||
E& e,
|
||||
boost::unit_test::const_string instance,
|
||||
boost::optional<type_name> type,
|
||||
boost::unit_test::const_string name)
|
||||
|
|
@ -64,7 +64,7 @@ namespace detail
|
|||
e.configure(*o.impl_, o.impl_.get(), instance, type, name);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
} // namespace detail
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_OBJECT_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
#define MOCK_RESET_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "object.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "object.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
inline void reset()
|
||||
{
|
||||
detail::root.reset();
|
||||
|
|
@ -29,6 +28,6 @@ namespace mock
|
|||
{
|
||||
f.reset();
|
||||
}
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_RESET_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -13,17 +13,14 @@
|
|||
#include "detail/sequence_impl.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
class sequence
|
||||
{
|
||||
public:
|
||||
sequence()
|
||||
: impl_( std::make_shared< detail::sequence_impl >() )
|
||||
{}
|
||||
sequence() : impl_(std::make_shared<detail::sequence_impl>()) {}
|
||||
|
||||
std::shared_ptr<detail::sequence_impl> impl_;
|
||||
};
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_SEQUENCE_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -13,22 +13,16 @@
|
|||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
struct stream
|
||||
{
|
||||
explicit stream( std::ostream& s )
|
||||
: s_( &s )
|
||||
{}
|
||||
explicit stream(std::ostream& s) : s_(&s) {}
|
||||
std::ostream* s_;
|
||||
};
|
||||
|
||||
#ifdef MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace conversion
|
||||
{
|
||||
namespace detail { namespace conversion {
|
||||
struct sink
|
||||
{
|
||||
template<typename T>
|
||||
|
|
@ -36,10 +30,7 @@ namespace conversion
|
|||
{}
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& s, const sink& )
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
inline std::ostream& operator<<(std::ostream& s, const sink&) { return s << '?'; }
|
||||
|
||||
struct holder
|
||||
{
|
||||
|
|
@ -54,9 +45,7 @@ namespace conversion
|
|||
template<typename T>
|
||||
struct holder_imp : holder
|
||||
{
|
||||
explicit holder_imp( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
explicit holder_imp(const T& t) : t_(t) {}
|
||||
virtual void serialize(std::ostream& s) const
|
||||
{
|
||||
// if an error about an ambiguous conversion is generated by the
|
||||
|
|
@ -74,8 +63,7 @@ namespace conversion
|
|||
{}
|
||||
std::unique_ptr<holder> h_;
|
||||
};
|
||||
}
|
||||
}
|
||||
}} // namespace detail::conversion
|
||||
|
||||
inline stream& operator<<(stream& s, const detail::conversion::any& d)
|
||||
{
|
||||
|
|
@ -85,17 +73,13 @@ namespace conversion
|
|||
|
||||
#else // MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace conversion
|
||||
{
|
||||
namespace detail { namespace conversion {
|
||||
template<typename S, typename T>
|
||||
S& operator<<(S& s, const T&)
|
||||
{
|
||||
return s << '?';
|
||||
}
|
||||
}
|
||||
}
|
||||
}} // namespace detail::conversion
|
||||
|
||||
template<typename T>
|
||||
stream& operator<<(stream& s, const T& t)
|
||||
|
|
@ -107,8 +91,7 @@ namespace conversion
|
|||
|
||||
#endif // MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
void serialize(stream& s, const T& t)
|
||||
{
|
||||
|
|
@ -117,24 +100,15 @@ namespace detail
|
|||
// mock::stream for T
|
||||
s << t;
|
||||
}
|
||||
inline void serialize( stream& s, bool b )
|
||||
{
|
||||
s << (b ? "true" : "false");
|
||||
}
|
||||
inline void serialize(stream& s, bool b) { s << (b ? "true" : "false"); }
|
||||
template<typename C, typename T, typename A>
|
||||
void serialize(stream& s, const std::basic_string<C, T, A>& str)
|
||||
{
|
||||
s << '"' << str << '"';
|
||||
}
|
||||
inline void serialize( stream& s, const char* const str )
|
||||
{
|
||||
s << '"' << str << '"';
|
||||
}
|
||||
inline void serialize( stream& s, unsigned char c )
|
||||
{
|
||||
s << static_cast< int >( c );
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
inline void serialize(stream& s, const char* const str) { s << '"' << str << '"'; }
|
||||
inline void serialize(stream& s, unsigned char c) { s << static_cast<int>(c); }
|
||||
} // namespace detail
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_STREAM_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@
|
|||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
template<class T>
|
||||
struct unwrap_reference
|
||||
{
|
||||
|
|
@ -37,6 +36,6 @@ namespace mock
|
|||
{
|
||||
return t;
|
||||
}
|
||||
}
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_UNWRAP_REFERENCE_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
#define MOCK_VERIFY_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "object.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "detail/functor.hpp"
|
||||
#include "detail/root.hpp"
|
||||
#include "object.hpp"
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace mock {
|
||||
inline bool verify()
|
||||
{
|
||||
return detail::root.verify();
|
||||
|
|
@ -29,6 +28,6 @@ namespace mock
|
|||
{
|
||||
return f.verify();
|
||||
}
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
#endif // MOCK_VERIFY_HPP_INCLUDED
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -11,8 +11,7 @@
|
|||
# pragma warning(disable : 4505)
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
|
|
@ -1070,7 +1069,7 @@ namespace
|
|||
mock_class_28 c_28;
|
||||
mock_class_29 c_29;
|
||||
mock_class_30 c_30;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@
|
|||
# pragma warning(disable : 4505)
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
|
|
@ -1071,7 +1070,7 @@ namespace
|
|||
mock_class_28 c_28;
|
||||
mock_class_29 c_29;
|
||||
mock_class_30 c_30;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@
|
|||
# pragma warning(disable : 4505)
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
|
|
@ -1071,7 +1070,7 @@ namespace
|
|||
mock_class_28 c_28;
|
||||
mock_class_29 c_29;
|
||||
mock_class_30 c_30;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@
|
|||
# pragma warning(disable : 4505)
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
|
|
@ -1071,7 +1070,7 @@ namespace
|
|||
mock_class_28 c_28;
|
||||
mock_class_29 c_29;
|
||||
mock_class_30 c_30;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
#include "../mock_error.hpp"
|
||||
#include "../undefined.hpp"
|
||||
#include <turtle/detail/function.hpp>
|
||||
#include <turtle/constraints.hpp>
|
||||
#include <turtle/detail/function.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
// static
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
std::function<void()> static_f;
|
||||
|
||||
static_assert(std::is_same<void, decltype(mock::detail::function<void()>{}())>::value, "!");
|
||||
static_assert(std::is_same<int, decltype(mock::detail::function<int()>{}())>::value, "!");
|
||||
static_assert(std::is_same<void, decltype(mock::detail::function<void(float)>{}(std::declval<float>()))>::value, "!");
|
||||
static_assert(std::is_same<int, decltype(mock::detail::function<int(float)>{}(std::declval<float>()))>::value, "!");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// functor
|
||||
|
||||
|
|
@ -254,7 +253,9 @@ BOOST_FIXTURE_TEST_CASE( verifying_a_reset_function_succeeds, mock_error_fixture
|
|||
|
||||
// constraints
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_constraint_calls_unexpected_call_error, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
triggering_an_expectation_with_wrong_parameter_value_in_equal_constraint_calls_unexpected_call_error,
|
||||
mock_error_fixture)
|
||||
{
|
||||
{
|
||||
mock::detail::function<void(int)> f;
|
||||
|
|
@ -264,11 +265,14 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
|
|||
{
|
||||
mock::detail::function<int(int, const std::string&)> f;
|
||||
f.expect().with(42, "expected");
|
||||
CHECK_ERROR( f( 42, "actual" ), "unexpected call", 0, "?( 42, \"actual\" )\n. unlimited().with( 42, \"expected\" )" );
|
||||
CHECK_ERROR(
|
||||
f(42, "actual"), "unexpected call", 0, "?( 42, \"actual\" )\n. unlimited().with( 42, \"expected\" )");
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_or_less_constraint_calls_unexpected_call_error, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
triggering_an_expectation_with_wrong_parameter_value_in_equal_or_less_constraint_calls_unexpected_call_error,
|
||||
mock_error_fixture)
|
||||
{
|
||||
mock::detail::function<void(int)> f;
|
||||
f.expect().with(mock::equal(42) || mock::less(42));
|
||||
|
|
@ -277,7 +281,9 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
|
|||
CHECK_ERROR(f(43), "unexpected call", 2, "?( 43 )\n. unlimited().with( ( equal( 42 ) || less( 42 ) ) )");
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in_equal_and_not_less_constraint_calls_unexpected_call_error, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
triggering_an_expectation_with_wrong_parameter_value_in_equal_and_not_less_constraint_calls_unexpected_call_error,
|
||||
mock_error_fixture)
|
||||
{
|
||||
mock::detail::function<void(int)> f;
|
||||
f.expect().with(mock::equal(42) && !mock::less(41));
|
||||
|
|
@ -285,8 +291,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
|
|||
CHECK_ERROR(f(43), "unexpected call", 1, "?( 43 )\n. unlimited().with( ( equal( 42 ) && ! less( 41 ) ) )");
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class my_interface
|
||||
{
|
||||
public:
|
||||
|
|
@ -302,7 +307,7 @@ namespace
|
|||
{
|
||||
virtual void my_method() {}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(passing_call_values_by_reference_is_transparent, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -322,15 +327,15 @@ BOOST_FIXTURE_TEST_CASE( passing_call_values_by_reference_is_transparent, mock_e
|
|||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
bool custom_constraint(int)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_failing_custom_constraint_calls_unexpected_call_error, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_with_failing_custom_constraint_calls_unexpected_call_error,
|
||||
mock_error_fixture)
|
||||
{
|
||||
{
|
||||
mock::detail::function<void(int)> f;
|
||||
|
|
@ -491,8 +496,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, mock_e
|
|||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct base
|
||||
{
|
||||
virtual ~base() = default;
|
||||
|
|
@ -500,10 +504,9 @@ namespace
|
|||
};
|
||||
struct derived : base
|
||||
{
|
||||
virtual void f()
|
||||
{}
|
||||
virtual void f() {}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_moves_the_set_lvalue, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -595,13 +598,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, mock_er
|
|||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
int custom_result()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_calls_the_custom_functor, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -611,13 +613,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor, moc
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
int custom_result_with_parameter(int i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_calls_the_custom_functor_with_parameters, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -627,7 +628,8 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_with
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_without_parameters_thanks_to_std_bind, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_calls_the_custom_functor_without_parameters_thanks_to_std_bind,
|
||||
mock_error_fixture)
|
||||
{
|
||||
mock::detail::function<int(int)> f;
|
||||
f.expect().calls(std::bind(&custom_result));
|
||||
|
|
@ -642,8 +644,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, moc
|
|||
try
|
||||
{
|
||||
f();
|
||||
}
|
||||
catch( std::runtime_error& f )
|
||||
} catch(std::runtime_error& f)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("some exception", f.what());
|
||||
CHECK_CALLS(1);
|
||||
|
|
@ -670,7 +671,8 @@ BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_
|
|||
f.expect().once().with("second");
|
||||
f("first");
|
||||
f("second");
|
||||
CHECK_ERROR( f( "third"), "unexpected call", 2, "?( \"third\" )\nv once().with( \"first\" )\nv once().with( \"second\" )" );
|
||||
CHECK_ERROR(
|
||||
f("third"), "unexpected call", 2, "?( \"third\" )\nv once().with( \"first\" )\nv once().with( \"second\" )");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -690,14 +692,14 @@ BOOST_FIXTURE_TEST_CASE( best_expectation_is_selected_first, mock_error_fixture
|
|||
f.expect().once().with("second");
|
||||
f("second");
|
||||
f("first");
|
||||
CHECK_ERROR( f( "third"), "unexpected call", 2, "?( \"third\" )\nv once().with( \"first\" )\nv once().with( \"second\" )" );
|
||||
CHECK_ERROR(
|
||||
f("third"), "unexpected call", 2, "?( \"third\" )\nv once().with( \"first\" )\nv once().with( \"second\" )");
|
||||
}
|
||||
}
|
||||
|
||||
// error report
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
std::string to_string(const T& t)
|
||||
{
|
||||
|
|
@ -705,7 +707,7 @@ namespace
|
|||
s << t;
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(expectation_can_be_serialized_to_be_human_readable, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -784,21 +786,25 @@ BOOST_FIXTURE_TEST_CASE( expectation_can_be_serialized_to_be_human_readable, moc
|
|||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( expectation_with_remaining_untriggered_matches_upon_destruction_calls_untriggered_expectation, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(expectation_with_remaining_untriggered_matches_upon_destruction_calls_untriggered_expectation,
|
||||
mock_error_fixture)
|
||||
{
|
||||
auto f = std::make_unique<mock::detail::function<void()>>();
|
||||
f->expect().once();
|
||||
CHECK_ERROR(f.reset(), "untriggered expectation", 0, "?\n. once()");
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( verifying_expectation_with_remaining_matches_disables_the_automatic_verification_upon_destruction, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
verifying_expectation_with_remaining_matches_disables_the_automatic_verification_upon_destruction,
|
||||
mock_error_fixture)
|
||||
{
|
||||
mock::detail::function<void()> f;
|
||||
f.expect().once();
|
||||
CHECK_ERROR(f.verify(), "verification failed", 0, "?\n. once()");
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( triggering_unexpected_call_call_disables_the_automatic_verification_upon_destruction, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(triggering_unexpected_call_call_disables_the_automatic_verification_upon_destruction,
|
||||
mock_error_fixture)
|
||||
{
|
||||
mock::detail::function<void()> f;
|
||||
CHECK_ERROR(f(), "unexpected call", 0, "?()");
|
||||
|
|
@ -819,8 +825,7 @@ BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verificati
|
|||
mock::detail::function<void()> f;
|
||||
f.expect().once();
|
||||
throw std::exception();
|
||||
}
|
||||
catch( std::exception& )
|
||||
} catch(std::exception&)
|
||||
{}
|
||||
}
|
||||
|
||||
|
|
@ -837,19 +842,17 @@ BOOST_FIXTURE_TEST_CASE( adding_file_and_line_number_information, mock_error_fix
|
|||
|
||||
# include <boost/thread.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
void iterate(mock::detail::function<int()>& f)
|
||||
{
|
||||
f.expect().once().returns(0);
|
||||
try
|
||||
{
|
||||
f();
|
||||
}
|
||||
catch( ... )
|
||||
} catch(...)
|
||||
{}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(function_is_thread_safe, mock_error_fixture)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,14 +16,13 @@
|
|||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/bind/placeholders.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/version.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct declared_but_not_defined;
|
||||
static_assert(!mock::detail::is_functor<declared_but_not_defined, int>::value, "Should not be a functor");
|
||||
|
||||
|
|
@ -39,9 +38,15 @@ namespace
|
|||
}
|
||||
|
||||
void f0() {}
|
||||
bool f1( int ) { return false; }
|
||||
bool f2( std::string, int ) { return false; }
|
||||
bool f1(int)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool f2(std::string, int)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(data_is_not_functor)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,15 +10,14 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct base
|
||||
{
|
||||
void method_1();
|
||||
float method_2(int) const;
|
||||
};
|
||||
typedef base base_type;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mock_signature_generates_signature)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
std::string to_string(const T& t)
|
||||
{
|
||||
|
|
@ -19,7 +18,7 @@ namespace
|
|||
s << mock::detail::make_type_name(t);
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_base_type_is_extracted)
|
||||
{
|
||||
|
|
@ -35,7 +34,8 @@ BOOST_AUTO_TEST_CASE( name_of_base_type_is_extracted )
|
|||
|
||||
struct my_type_in_default_namespace
|
||||
{
|
||||
struct inner {};
|
||||
struct inner
|
||||
{};
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_type_in_default_namespace_is_extracted)
|
||||
|
|
@ -51,12 +51,14 @@ BOOST_AUTO_TEST_CASE( name_of_inner_type_from_type_in_default_namespace_is_extra
|
|||
template<typename T>
|
||||
struct my_template_type_in_default_namespace
|
||||
{
|
||||
struct inner {};
|
||||
struct inner
|
||||
{};
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_template_type_in_default_namespace_is_extracted)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_template_type_in_default_namespace<int>", to_string( my_template_type_in_default_namespace<int>() ) );
|
||||
BOOST_CHECK_EQUAL("my_template_type_in_default_namespace<int>",
|
||||
to_string(my_template_type_in_default_namespace<int>()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_inner_type_from_template_type_in_default_namespace_is_extracted)
|
||||
|
|
@ -64,46 +66,40 @@ BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_default_namespace
|
|||
BOOST_CHECK_EQUAL("inner", to_string(my_template_type_in_default_namespace<int>::inner()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_type_in_anonymous_namespace {};
|
||||
}
|
||||
namespace {
|
||||
struct my_type_in_anonymous_namespace
|
||||
{};
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_type_in_anonymous_namespace_is_extracted)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("my_type_in_anonymous_namespace", to_string(my_type_in_anonymous_namespace()));
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
struct my_type_from_named_namespace {};
|
||||
}
|
||||
namespace nm {
|
||||
struct my_type_from_named_namespace
|
||||
{};
|
||||
} // namespace nm
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_type_from_named_namespace_is_extracted)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("my_type_from_named_namespace", to_string(nm::my_type_from_named_namespace()));
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
namespace inner
|
||||
{
|
||||
struct my_type_in_named_inner_namespace {};
|
||||
}
|
||||
}
|
||||
namespace nm { namespace inner {
|
||||
struct my_type_in_named_inner_namespace
|
||||
{};
|
||||
}} // namespace nm::inner
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_type_in_named_inner_namespace_is_extracted)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("my_type_in_named_inner_namespace", to_string(nm::inner::my_type_in_named_inner_namespace()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace inner
|
||||
{
|
||||
struct my_type_in_unnamed_inner_namespace {};
|
||||
}
|
||||
}
|
||||
namespace { namespace inner {
|
||||
struct my_type_in_unnamed_inner_namespace
|
||||
{};
|
||||
}} // namespace ::inner
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_type_in_unnamed_inner_namespace_is_extracted)
|
||||
{
|
||||
|
|
@ -112,18 +108,19 @@ BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted )
|
|||
|
||||
BOOST_AUTO_TEST_CASE(name_of_local_type_is_extracted)
|
||||
{
|
||||
struct my_local_type {};
|
||||
struct my_local_type
|
||||
{};
|
||||
BOOST_CHECK_EQUAL("my_local_type", to_string(my_local_type()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
struct my_template_type
|
||||
{
|
||||
struct inner {};
|
||||
struct inner
|
||||
{};
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_template_type_in_anonymous_namespace_is_extracted)
|
||||
{
|
||||
|
|
@ -149,14 +146,14 @@ BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_anonymous_namespa
|
|||
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<std::exception const*&>::inner()));
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
namespace nm {
|
||||
template<typename T>
|
||||
struct my_template_type
|
||||
{
|
||||
struct inner {};
|
||||
struct inner
|
||||
{};
|
||||
};
|
||||
}
|
||||
} // namespace nm
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_template_type_in_named_namespace_is_extracted)
|
||||
{
|
||||
|
|
@ -182,15 +179,15 @@ BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_named_namespace_i
|
|||
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<std::exception const*&>::inner()));
|
||||
}
|
||||
|
||||
namespace nm2
|
||||
{
|
||||
namespace nm2 {
|
||||
template<typename T>
|
||||
struct my_template_type
|
||||
{
|
||||
template<typename U>
|
||||
struct inner {};
|
||||
struct inner
|
||||
{};
|
||||
};
|
||||
}
|
||||
} // namespace nm2
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted)
|
||||
{
|
||||
|
|
@ -212,16 +209,17 @@ BOOST_AUTO_TEST_CASE( name_of_template_inner_type_from_template_type_in_named_na
|
|||
BOOST_CHECK_EQUAL("inner<int const*&>", to_string(nm2::my_template_type<std::exception>::inner<int const*&>()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T1, typename T2, typename T3>
|
||||
struct my_tpl
|
||||
{};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(name_of_nested_template_with_multiple_arguments_is_extracted)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("vector<int, allocator<int>>", to_string(std::vector<int>()));
|
||||
BOOST_CHECK_EQUAL( "vector<vector<int, allocator<int>>, allocator<vector<int, allocator<int>>>>", to_string( std::vector< std::vector< int > >() ) );
|
||||
BOOST_CHECK_EQUAL( "my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>", to_string( my_tpl< my_tpl< int, int, int >, my_tpl< int, int, int >, my_tpl< int, int, int > >() ) );
|
||||
BOOST_CHECK_EQUAL("vector<vector<int, allocator<int>>, allocator<vector<int, allocator<int>>>>",
|
||||
to_string(std::vector<std::vector<int>>()));
|
||||
BOOST_CHECK_EQUAL("my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>",
|
||||
to_string(my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_base
|
||||
{
|
||||
virtual ~my_base() = default;
|
||||
|
|
@ -21,4 +20,4 @@ namespace
|
|||
{
|
||||
MOCK_METHOD(my_method, 0)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ MOCK_CLASS(my_class)
|
|||
{
|
||||
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
|
||||
};
|
||||
bool constraint(int, int) { return true; }
|
||||
bool constraint(int, int)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void test_case()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_base
|
||||
{
|
||||
virtual ~my_base() = default;
|
||||
|
|
@ -19,4 +18,4 @@ namespace
|
|||
{
|
||||
MOCK_METHOD(my_method, 0)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@
|
|||
|
||||
BOOST_STATIC_ASSERT(MOCK_MAX_ARGS == 9);
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_base
|
||||
{
|
||||
virtual ~my_base() = default;
|
||||
|
|
@ -22,4 +21,4 @@ namespace
|
|||
{
|
||||
MOCK_METHOD(my_method, 10)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_base
|
||||
{
|
||||
virtual ~my_base() = default;
|
||||
|
|
@ -20,4 +19,4 @@ namespace
|
|||
{
|
||||
MOCK_METHOD(my_method, 2)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
#define MOCK_ERROR_POLICY mock_error
|
||||
#include <turtle/detail/singleton.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
struct mock_error_data_t : mock::detail::singleton<mock_error_data_t>
|
||||
{
|
||||
|
|
@ -24,10 +24,7 @@ struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
|
|||
last_message.clear();
|
||||
last_context.clear();
|
||||
}
|
||||
bool verify()
|
||||
{
|
||||
return error_count == 0;
|
||||
}
|
||||
bool verify() { return error_count == 0; }
|
||||
|
||||
void call()
|
||||
{
|
||||
|
|
@ -35,9 +32,7 @@ struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
|
|||
last_message.clear();
|
||||
++call_count;
|
||||
}
|
||||
void fail( const std::string& message,
|
||||
const std::string& context,
|
||||
const char* file, int line )
|
||||
void fail(const std::string& message, const std::string& context, const char* file, int line)
|
||||
{
|
||||
last_context = context;
|
||||
last_message = message;
|
||||
|
|
@ -59,13 +54,9 @@ MOCK_SINGLETON_INST( mock_error_data )
|
|||
template<typename Result>
|
||||
struct mock_error
|
||||
{
|
||||
static Result abort()
|
||||
{
|
||||
throw std::runtime_error( "aborted" );
|
||||
}
|
||||
static Result abort() { throw std::runtime_error("aborted"); }
|
||||
|
||||
static void pass( const char* /*file*/, int /*line*/ )
|
||||
{}
|
||||
static void pass(const char* /*file*/, int /*line*/) {}
|
||||
|
||||
template<typename Context>
|
||||
static void call(const Context& /*context*/, const char* /*file*/, int /*line*/)
|
||||
|
|
@ -84,10 +75,7 @@ struct mock_error
|
|||
|
||||
struct mock_error_fixture
|
||||
{
|
||||
mock_error_fixture()
|
||||
{
|
||||
mock_error_data.reset();
|
||||
}
|
||||
mock_error_fixture() { mock_error_data.reset(); }
|
||||
~mock_error_fixture()
|
||||
{
|
||||
BOOST_CHECK(mock_error_data.verify());
|
||||
|
|
@ -100,7 +88,11 @@ struct mock_error_fixture
|
|||
mock_error_data.call_count = 0;
|
||||
#define CHECK_ERROR(expr, error, calls, context) \
|
||||
BOOST_CHECK(mock_error_data.verify()); \
|
||||
try { expr; } catch( ... ) {} \
|
||||
try \
|
||||
{ \
|
||||
expr; \
|
||||
} catch(...) \
|
||||
{} \
|
||||
BOOST_CHECK_EQUAL(1, mock_error_data.error_count); \
|
||||
BOOST_CHECK_EQUAL(error, mock_error_data.last_message); \
|
||||
BOOST_CHECK_EQUAL(context, mock_error_data.last_context); \
|
||||
|
|
|
|||
|
|
@ -9,12 +9,11 @@
|
|||
#include <turtle/constraint.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CONSTRAINT(constraint_0, actual == 0)
|
||||
MOCK_CONSTRAINT(constraint_1, expected, actual == expected)
|
||||
MOCK_CONSTRAINT(constraint_2, expected_0, expected_1, actual == expected_0 || actual == expected_1)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mock_constraint_is_supported_by_compilers_with_variadic_macros)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -130,11 +130,7 @@ BOOST_AUTO_TEST_CASE( assign_constraint )
|
|||
{
|
||||
int i = 0;
|
||||
int j = 1;
|
||||
mock::constraint<
|
||||
mock::detail::assign<
|
||||
std::reference_wrapper< const int >
|
||||
>
|
||||
> c = mock::assign( std::cref( j ) );
|
||||
mock::constraint<mock::detail::assign<std::reference_wrapper<const int>>> c = mock::assign(std::cref(j));
|
||||
BOOST_CHECK(c.c_(i));
|
||||
BOOST_CHECK_EQUAL(1, i);
|
||||
j = 3;
|
||||
|
|
@ -242,19 +238,14 @@ BOOST_AUTO_TEST_CASE( retrieve_constraint )
|
|||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct A
|
||||
{
|
||||
};
|
||||
{};
|
||||
struct B
|
||||
{
|
||||
B& operator=( const A& )
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
B& operator=(const A&) { return *this; }
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(retrieve_constraint_uses_assignment_operator)
|
||||
{
|
||||
|
|
@ -287,8 +278,7 @@ BOOST_AUTO_TEST_CASE( negate_constraint )
|
|||
BOOST_CHECK(!mock::negate.c_(&j));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
bool return_true()
|
||||
{
|
||||
return true;
|
||||
|
|
@ -297,7 +287,7 @@ namespace
|
|||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(call_constraint)
|
||||
{
|
||||
|
|
@ -337,11 +327,8 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
|
|||
BOOST_CHECK(!mock::contain(std::string("not found")).c_(std::string("this is a string")));
|
||||
{
|
||||
std::string s;
|
||||
mock::constraint<
|
||||
mock::detail::contain<
|
||||
std::reference_wrapper< const std::string >
|
||||
>
|
||||
> c = mock::contain( std::cref( s ) );
|
||||
mock::constraint<mock::detail::contain<std::reference_wrapper<const std::string>>> c =
|
||||
mock::contain(std::cref(s));
|
||||
s = "string";
|
||||
BOOST_CHECK(c.c_("this is a string"));
|
||||
BOOST_CHECK(c.c_(std::string("this is a string")));
|
||||
|
|
@ -351,14 +338,13 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
|
|||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct type_with_overloaded_address_operator
|
||||
{
|
||||
void operator&() {}
|
||||
void operator&() const {}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_with_overloaded_address_operator_can_be_used_in_constraints)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,11 +15,9 @@ BOOST_AUTO_TEST_CASE( a_mock_exception_is_not_an_std_exception_to_not_mess_with_
|
|||
try
|
||||
{
|
||||
throw mock::exception();
|
||||
}
|
||||
catch( std::exception& )
|
||||
} catch(std::exception&)
|
||||
{
|
||||
BOOST_FAIL("mock::exception must not be an std::exception");
|
||||
}
|
||||
catch( mock::exception& )
|
||||
} catch(mock::exception&)
|
||||
{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,18 +9,17 @@
|
|||
#include "mock_error.hpp"
|
||||
#include "undefined.hpp"
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_custom_mock
|
||||
{
|
||||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_and_without_inheriting_from_object, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -30,13 +29,12 @@ BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheritin
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_custom_mock_object
|
||||
{
|
||||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -46,13 +44,12 @@ BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros, mock_error_fixture )
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(my_mock)
|
||||
{
|
||||
MOCK_METHOD_EXT(my_method, 1, int(int), my_tag)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(basic_mock_object_usage, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -78,8 +75,7 @@ BOOST_FIXTURE_TEST_CASE( basic_mock_object_usage, mock_error_fixture )
|
|||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class my_ambiguited_interface
|
||||
{
|
||||
public:
|
||||
|
|
@ -96,7 +92,7 @@ namespace
|
|||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag1)
|
||||
MOCK_METHOD_EXT(my_method, 1, void(int), my_tag_2)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_object_method_disambiguation, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -106,8 +102,7 @@ BOOST_FIXTURE_TEST_CASE( mock_object_method_disambiguation, mock_error_fixture )
|
|||
CHECK_ERROR(m.my_method(12), "unexpected call", 1, "?.my_ambiguited_mock::my_tag_2( 12 )");
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class my_const_ambiguited_interface
|
||||
{
|
||||
public:
|
||||
|
|
@ -124,7 +119,7 @@ namespace
|
|||
MOCK_NON_CONST_METHOD_EXT(my_method, 0, void(), tag1)
|
||||
MOCK_CONST_METHOD_EXT(my_method, 0, void(), tag_2)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_object_method_const_disambiguation, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -135,13 +130,12 @@ BOOST_FIXTURE_TEST_CASE( mock_object_method_const_disambiguation, mock_error_fix
|
|||
CHECK_ERROR(const_mock.my_method(), "unexpected call", 1, "?.my_const_ambiguited_mock::tag_2()");
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(my_undefined_mock)
|
||||
{
|
||||
MOCK_METHOD_EXT(m, 1, void(undefined&), t)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_object_method_with_declared_but_not_defined_parameter_is_valid, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -149,8 +143,7 @@ BOOST_FIXTURE_TEST_CASE( mock_object_method_with_declared_but_not_defined_parame
|
|||
MOCK_EXPECT(mock.t);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_FUNCTOR(gf, int(float, const std::string&));
|
||||
}
|
||||
|
||||
|
|
@ -175,13 +168,12 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_in_function_is_supported, mock_error_fixtu
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct functor_fixture : mock_error_fixture
|
||||
{
|
||||
MOCK_FUNCTOR(f, int(float, const std::string&));
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_functor_in_fixture_is_supported, functor_fixture)
|
||||
{
|
||||
|
|
@ -190,8 +182,7 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_in_fixture_is_supported, functor_fixture )
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
struct my_template_mock
|
||||
{
|
||||
|
|
@ -199,7 +190,7 @@ namespace
|
|||
MOCK_METHOD_EXT_TPL(my_method, 2, void(T, std::string), my_tpl_tag)
|
||||
MOCK_METHOD_EXT_TPL(my_other_method, 0, void(), my_other_tag)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mocking_a_template_class_method_is_supported, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -210,8 +201,7 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_template_class_method_is_supported, mock_erro
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
struct my_template_base_class
|
||||
{
|
||||
|
|
@ -225,7 +215,7 @@ namespace
|
|||
MOCK_METHOD_EXT_TPL(my_method, 1, void(T), my_method)
|
||||
MOCK_METHOD_EXT_TPL(my_other_method, 0, void(), my_other_method)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mocking_a_template_base_class_method_is_supported, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -236,8 +226,7 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_template_base_class_method_is_supported, mock
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
class my_observer
|
||||
{
|
||||
public:
|
||||
|
|
@ -261,14 +250,9 @@ namespace
|
|||
class my_subject
|
||||
{
|
||||
public:
|
||||
explicit my_subject( my_manager& f )
|
||||
: o_( f.get_observer() )
|
||||
, value_( 0 )
|
||||
{}
|
||||
void increment()
|
||||
{
|
||||
o_.notify( ++value_ );
|
||||
}
|
||||
explicit my_subject(my_manager& f) : o_(f.get_observer()), value_(0) {}
|
||||
void increment() { o_.notify(++value_); }
|
||||
|
||||
private:
|
||||
my_observer& o_;
|
||||
int value_;
|
||||
|
|
@ -289,7 +273,7 @@ namespace
|
|||
my_mock_manager manager;
|
||||
my_mock_observer observer;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(basic_mock_object_collaboration_usage, fixture)
|
||||
{
|
||||
|
|
@ -304,13 +288,12 @@ BOOST_FIXTURE_TEST_CASE( basic_mock_object_collaboration_usage, fixture )
|
|||
CHECK_CALLS(4);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(my_constructed_class)
|
||||
{
|
||||
MOCK_CONSTRUCTOR(my_constructed_class, 2, (int, const std::string&), constructor)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mocking_a_constructor, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -320,14 +303,13 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_constructor, mock_error_fixture )
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
MOCK_CLASS(my_constructed_template_class)
|
||||
{
|
||||
MOCK_CONSTRUCTOR_TPL(my_constructed_template_class, 2, (T, const std::string&), constructor)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mocking_a_template_class_constructor, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -337,13 +319,12 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_template_class_constructor, mock_error_fixtur
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(my_destroyed_class)
|
||||
{
|
||||
MOCK_DESTRUCTOR(~my_destroyed_class, destructor)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mocking_a_destructor, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -357,15 +338,13 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_destructor, mock_error_fixture )
|
|||
BOOST_FIXTURE_TEST_CASE(failed_expectation_in_mocked_destructor_does_not_throw, mock_error_fixture)
|
||||
{
|
||||
CHECK_ERROR(
|
||||
try
|
||||
{
|
||||
try {
|
||||
my_destroyed_class c;
|
||||
throw std::runtime_error("should not crash");
|
||||
}
|
||||
catch( std::runtime_error& )
|
||||
{
|
||||
},
|
||||
"unexpected call", 0, "?.my_destroyed_class::destructor()" );
|
||||
} catch(std::runtime_error&){},
|
||||
"unexpected call",
|
||||
0,
|
||||
"?.my_destroyed_class::destructor()");
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(failed_sequence_in_mocked_destructor_does_not_throw, mock_error_fixture)
|
||||
|
|
@ -379,16 +358,17 @@ BOOST_FIXTURE_TEST_CASE( failed_sequence_in_mocked_destructor_does_not_throw, mo
|
|||
MOCK_EXPECT(m.my_tag).once().in(s);
|
||||
m.my_method();
|
||||
},
|
||||
"sequence failed", 1, "c.my_destroyed_class::destructor()\n. once()" );
|
||||
"sequence failed",
|
||||
1,
|
||||
"c.my_destroyed_class::destructor()\n. once()");
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(boost_optional)
|
||||
{
|
||||
MOCK_METHOD_EXT(method, 0, boost::optional<my_observer&>(), tag)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(boost_optional_on_base_class_reference_as_return_type_is_supported, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -399,8 +379,7 @@ BOOST_FIXTURE_TEST_CASE( boost_optional_on_base_class_reference_as_return_type_i
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
bool serialized = false;
|
||||
|
||||
struct custom_argument
|
||||
|
|
@ -424,7 +403,7 @@ namespace
|
|||
return s;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(constraints_and_arguments_are_serialized_lazily, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -435,8 +414,7 @@ BOOST_FIXTURE_TEST_CASE( constraints_and_arguments_are_serialized_lazily, mock_e
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct custom_constraint_with_non_const_operator
|
||||
{
|
||||
template<typename Actual>
|
||||
|
|
@ -445,12 +423,13 @@ namespace
|
|||
return actual == 42;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(custom_constraint_function_operator_does_not_need_to_be_const, mock_error_fixture)
|
||||
{
|
||||
MOCK_FUNCTOR(f, void(float));
|
||||
MOCK_EXPECT( f ).with( mock::constraint< custom_constraint_with_non_const_operator >( custom_constraint_with_non_const_operator() ) );
|
||||
MOCK_EXPECT(f).with(
|
||||
mock::constraint<custom_constraint_with_non_const_operator>(custom_constraint_with_non_const_operator()));
|
||||
f(42);
|
||||
CHECK_CALLS(1);
|
||||
}
|
||||
|
|
@ -465,8 +444,7 @@ BOOST_FIXTURE_TEST_CASE( boost_reference_wrapper_is_supported_in_value_constrain
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
void nothing(T)
|
||||
{}
|
||||
|
|
@ -475,15 +453,14 @@ namespace
|
|||
{
|
||||
MOCK_CONST_METHOD_EXT(my_method, 0, void(), my_method)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(member_pointer_on_mock_method_is_valid, mock_error_fixture)
|
||||
{
|
||||
nothing(&member_pointer_mock_class::my_method);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_FUNCTION(free_function, 1, void(int), free_function)
|
||||
}
|
||||
|
||||
|
|
@ -491,28 +468,27 @@ BOOST_FIXTURE_TEST_CASE( a_free_function_can_be_mocked, mock_error_fixture )
|
|||
{
|
||||
MOCK_EXPECT(free_function).once();
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! MOCK_VERIFY( free_function ) ),
|
||||
"verification failed", 0, "free_function\n. once().with( any )" );
|
||||
BOOST_CHECK(!MOCK_VERIFY(free_function)), "verification failed", 0, "free_function\n. once().with( any )");
|
||||
free_function(42);
|
||||
CHECK_CALLS(1);
|
||||
BOOST_CHECK(MOCK_VERIFY(free_function));
|
||||
MOCK_RESET(free_function);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct some_class : mock::object
|
||||
{
|
||||
MOCK_STATIC_METHOD(some_static_method, 1, void(int), some_static_method)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(a_static_method_can_be_mocked, mock_error_fixture)
|
||||
{
|
||||
MOCK_EXPECT(some_class::some_static_method).once();
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! MOCK_VERIFY( some_class::some_static_method ) ),
|
||||
"verification failed", 0, "some_class::some_static_method\n. once().with( any )" );
|
||||
CHECK_ERROR(BOOST_CHECK(!MOCK_VERIFY(some_class::some_static_method)),
|
||||
"verification failed",
|
||||
0,
|
||||
"some_class::some_static_method\n. once().with( any )");
|
||||
some_class::some_static_method(42);
|
||||
CHECK_CALLS(1);
|
||||
BOOST_CHECK(MOCK_VERIFY(some_class::some_static_method));
|
||||
|
|
@ -524,27 +500,28 @@ BOOST_FIXTURE_TEST_CASE( a_static_method_is_not_reset_when_resetting_an_instance
|
|||
MOCK_EXPECT(some_class::some_static_method).once();
|
||||
some_class c;
|
||||
mock::reset(c);
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! MOCK_VERIFY( some_class::some_static_method ) ),
|
||||
"verification failed", 0, "some_class::some_static_method\n. once().with( any )" );
|
||||
CHECK_ERROR(BOOST_CHECK(!MOCK_VERIFY(some_class::some_static_method)),
|
||||
"verification failed",
|
||||
0,
|
||||
"some_class::some_static_method\n. once().with( any )");
|
||||
MOCK_RESET(some_class::some_static_method);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
struct some_template_class
|
||||
{
|
||||
MOCK_STATIC_METHOD_TPL(some_static_method, 1, void(T), some_static_method)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(a_static_method_in_a_template_class_can_be_mocked, mock_error_fixture)
|
||||
{
|
||||
MOCK_EXPECT(some_template_class<int>::some_static_method).once();
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! MOCK_VERIFY( some_template_class< int >::some_static_method ) ),
|
||||
"verification failed", 0, "some_template_class< int >::some_static_method\n. once().with( any )" );
|
||||
CHECK_ERROR(BOOST_CHECK(!MOCK_VERIFY(some_template_class<int>::some_static_method)),
|
||||
"verification failed",
|
||||
0,
|
||||
"some_template_class<int>::some_static_method\n. once().with( any )");
|
||||
some_template_class<int>::some_static_method(42);
|
||||
BOOST_CHECK(mock::verify());
|
||||
BOOST_CHECK(MOCK_VERIFY(some_template_class<int>::some_static_method));
|
||||
|
|
@ -552,13 +529,12 @@ BOOST_FIXTURE_TEST_CASE( a_static_method_in_a_template_class_can_be_mocked, mock
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(mock_class)
|
||||
{
|
||||
MOCK_METHOD_EXT(m, 0, void(), t);
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(resetting_referenced_mock_class_does_not_crash, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -571,13 +547,12 @@ BOOST_FIXTURE_TEST_CASE( resetting_referenced_mock_class_does_not_crash, mock_er
|
|||
mock::reset();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(mock_class2)
|
||||
{
|
||||
MOCK_METHOD_EXT(m, 0, mock_class2(), t);
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(resetting_self_referenced_mock_class_does_not_crash, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -588,8 +563,7 @@ BOOST_FIXTURE_TEST_CASE( resetting_self_referenced_mock_class_does_not_crash, mo
|
|||
mock::reset();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T1, typename T2>
|
||||
struct my_base
|
||||
{};
|
||||
|
|
@ -597,14 +571,13 @@ namespace
|
|||
{};
|
||||
MOCK_BASE_CLASS(my_boost_pp_comma_mock, my_base<int BOOST_PP_COMMA() int>)
|
||||
{};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#ifdef MOCK_THREAD_SAFE
|
||||
|
||||
# include <boost/thread.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
void create_class()
|
||||
{
|
||||
my_mock m;
|
||||
|
|
@ -612,11 +585,10 @@ namespace
|
|||
try
|
||||
{
|
||||
m.my_method(3);
|
||||
}
|
||||
catch( ... )
|
||||
} catch(...)
|
||||
{}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_class_creation_is_thread_safe, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -627,8 +599,7 @@ BOOST_FIXTURE_TEST_CASE( mock_class_creation_is_thread_safe, mock_error_fixture
|
|||
CHECK_CALLS(100);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
void create_functor(int i)
|
||||
{
|
||||
mock::detail::functor<void(int)> f;
|
||||
|
|
@ -638,11 +609,10 @@ namespace
|
|||
try
|
||||
{
|
||||
f(i);
|
||||
}
|
||||
catch( ... )
|
||||
} catch(...)
|
||||
{}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_functor_creation_is_thread_safe, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -653,14 +623,13 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_creation_is_thread_safe, mock_error_fixtur
|
|||
CHECK_CALLS(100);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
void iterate(my_mock& m)
|
||||
{
|
||||
MOCK_EXPECT(m.my_tag).once().with(3).returns(42);
|
||||
BOOST_CHECK_EQUAL(42, m.my_method(3));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_class_is_thread_safe, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -674,14 +643,13 @@ BOOST_FIXTURE_TEST_CASE( mock_class_is_thread_safe, mock_error_fixture )
|
|||
|
||||
#endif // MOCK_THREAD_SAFE
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(my_multi_mock)
|
||||
{
|
||||
MOCK_METHOD_EXT(m1, 1, void(int), m1);
|
||||
MOCK_METHOD_EXT(m2, 2, void(int, int), m2);
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_method_accepts_multi_constraint, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -693,8 +661,7 @@ BOOST_FIXTURE_TEST_CASE( mock_method_accepts_multi_constraint, mock_error_fixtur
|
|||
CHECK_CALLS(2);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_polymorphic_constraint
|
||||
{
|
||||
template<typename T1, typename T2>
|
||||
|
|
@ -703,7 +670,7 @@ namespace
|
|||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_method_accepts_polymorphic_multi_constraint, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -717,10 +684,7 @@ BOOST_FIXTURE_TEST_CASE( std_unique_ptr_argument_is_supported_in_action, mock_er
|
|||
{
|
||||
MOCK_FUNCTOR(f, void(std::unique_ptr<int>));
|
||||
std::unique_ptr<int> p;
|
||||
MOCK_EXPECT( f ).once().calls(
|
||||
[]( std::unique_ptr< int > )
|
||||
{
|
||||
} );
|
||||
MOCK_EXPECT(f).once().calls([](std::unique_ptr<int>) {});
|
||||
f(std::unique_ptr<int>(new int(7)));
|
||||
CHECK_CALLS(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/log.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(push, 0)
|
||||
#endif
|
||||
#include <boost/phoenix/phoenix.hpp>
|
||||
#include <boost/phoenix/bind.hpp>
|
||||
#include <boost/phoenix/phoenix.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
|
@ -24,16 +24,15 @@
|
|||
# include <boost/lambda/lambda.hpp>
|
||||
#endif
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
std::string to_string(const T& t)
|
||||
{
|
||||
|
|
@ -48,7 +47,7 @@ namespace
|
|||
s << mock::format(t);
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(pointer_yields_its_value_when_serialized)
|
||||
{
|
||||
|
|
@ -87,34 +86,31 @@ BOOST_AUTO_TEST_CASE( strings_are_serialized_with_double_quotes )
|
|||
BOOST_CHECK_EQUAL("\"string\"", to_string(std::string("string")));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct non_serializable
|
||||
{};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(non_serializable_type_yields_a_question_mark_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("?", to_string(non_serializable()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct serializable
|
||||
{};
|
||||
std::ostream& operator<<(std::ostream& s, const serializable&)
|
||||
{
|
||||
return s << "serializable";
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(serializable_type_yields_its_value_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("serializable", to_string(serializable()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct streamable
|
||||
{};
|
||||
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const streamable&)
|
||||
|
|
@ -126,15 +122,14 @@ namespace
|
|||
{
|
||||
return s << "streamable";
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(streamable_type_yields_its_value_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("streamable", to_string(streamable()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct mock_streamable
|
||||
{};
|
||||
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const mock_streamable&)
|
||||
|
|
@ -142,25 +137,23 @@ namespace
|
|||
BOOST_FAIL("should not have been called");
|
||||
return s;
|
||||
}
|
||||
}
|
||||
namespace mock
|
||||
{
|
||||
} // namespace
|
||||
namespace mock {
|
||||
stream& operator<<(stream& s, const mock_streamable&)
|
||||
{
|
||||
return s << "mock_streamable";
|
||||
}
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mock_streamable_type_yields_its_value_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("mock_streamable", to_string(mock_streamable()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct derived_from_serializable : serializable
|
||||
{};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_derived_from_serializable_yields_a_question_mark_when_serialized)
|
||||
{
|
||||
|
|
@ -171,11 +164,10 @@ BOOST_AUTO_TEST_CASE( type_derived_from_serializable_yields_a_question_mark_when
|
|||
#endif
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct derived_from_streamable : streamable
|
||||
{};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_derived_from_streamable_yields_a_question_mark_when_serialized)
|
||||
{
|
||||
|
|
@ -186,79 +178,77 @@ BOOST_AUTO_TEST_CASE( type_derived_from_streamable_yields_a_question_mark_when_s
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifndef MOCK_USE_CONVERSIONS // all this does not compile with conversions activated, which is precisely the purpose of having this compilation flag
|
||||
#ifndef MOCK_USE_CONVERSIONS // all this does not compile with conversions activated, which is precisely the purpose of
|
||||
// having this compilation flag
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct convertible_to_base
|
||||
{
|
||||
operator int() const;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_convertible_to_base_yields_a_question_mark_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("?", to_string(convertible_to_base()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct convertible_to_serializable
|
||||
{
|
||||
operator serializable() const;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_convertible_to_serializable_yields_a_question_mark_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("?", to_string(convertible_to_serializable()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct convertible_to_streamable
|
||||
{
|
||||
operator streamable() const;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_convertible_to_streamable_yields_a_question_mark_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("?", to_string(convertible_to_streamable()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct ambiguous_convertible
|
||||
{
|
||||
operator float() const;
|
||||
operator int() const;
|
||||
operator serializable() const;
|
||||
operator streamable() const;
|
||||
template< typename T > operator T() const;
|
||||
template<typename T>
|
||||
operator T() const;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_ambiguous_convertible_yields_a_question_mark_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("?", to_string(ambiguous_convertible()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct ambiguous_convertible_serializable
|
||||
{
|
||||
operator float() const;
|
||||
operator int() const;
|
||||
operator serializable() const;
|
||||
operator streamable() const;
|
||||
template< typename T > operator T() const;
|
||||
template<typename T>
|
||||
operator T() const;
|
||||
};
|
||||
std::ostream& operator<<(std::ostream& s, const ambiguous_convertible_serializable&)
|
||||
{
|
||||
return s << "ambiguous_convertible_serializable";
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_convertible_serializable_yields_its_value_when_serialized)
|
||||
{
|
||||
|
|
@ -267,15 +257,15 @@ BOOST_AUTO_TEST_CASE( type_convertible_serializable_yields_its_value_when_serial
|
|||
|
||||
#endif // MOCK_USE_CONVERSIONS
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct ambiguous_convertible_streamable
|
||||
{
|
||||
operator float() const;
|
||||
operator int() const;
|
||||
operator serializable() const;
|
||||
operator streamable() const;
|
||||
template< typename T > operator T() const;
|
||||
template<typename T>
|
||||
operator T() const;
|
||||
};
|
||||
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const ambiguous_convertible_streamable&)
|
||||
{
|
||||
|
|
@ -286,44 +276,42 @@ namespace
|
|||
{
|
||||
return s << "ambiguous_convertible_streamable";
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_ambiguous_convertible_streamable_yields_its_value_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("ambiguous_convertible_streamable", to_string(ambiguous_convertible_streamable()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct ambiguous_convertible_mock_streamable
|
||||
{
|
||||
operator float() const;
|
||||
operator int() const;
|
||||
operator serializable() const;
|
||||
operator streamable() const;
|
||||
template< typename T > operator T() const;
|
||||
template<typename T>
|
||||
operator T() const;
|
||||
};
|
||||
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const ambiguous_convertible_mock_streamable&)
|
||||
{
|
||||
BOOST_FAIL("should not have been called");
|
||||
return s;
|
||||
}
|
||||
}
|
||||
namespace mock
|
||||
{
|
||||
} // namespace
|
||||
namespace mock {
|
||||
stream& operator<<(stream& s, const ambiguous_convertible_mock_streamable&)
|
||||
{
|
||||
return s << "ambiguous_convertible_mock_streamable";
|
||||
}
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_ambiguous_convertible_mock_streamable_yields_its_value_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("ambiguous_convertible_mock_streamable", to_string(ambiguous_convertible_mock_streamable()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
struct template_serializable
|
||||
{};
|
||||
|
|
@ -332,15 +320,14 @@ namespace
|
|||
{
|
||||
return s << "template_serializable";
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(template_type_serializable_yields_its_value_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("template_serializable", to_string(template_serializable<int>()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
struct template_streamable
|
||||
{};
|
||||
|
|
@ -355,15 +342,14 @@ namespace
|
|||
{
|
||||
return s << "template_streamable";
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(template_template_streamable_yields_its_value_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("template_streamable", to_string(template_streamable<int>()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
struct template_mock_streamable
|
||||
{};
|
||||
|
|
@ -373,15 +359,14 @@ namespace
|
|||
BOOST_FAIL("should not have been called");
|
||||
return s;
|
||||
}
|
||||
}
|
||||
namespace mock
|
||||
{
|
||||
} // namespace
|
||||
namespace mock {
|
||||
template<typename T>
|
||||
stream& operator<<(stream& s, const template_mock_streamable<T>&)
|
||||
{
|
||||
return s << "template_mock_streamable";
|
||||
}
|
||||
} // mock
|
||||
} // namespace mock
|
||||
|
||||
BOOST_AUTO_TEST_CASE(template_mock_streamable_yields_its_value_when_serialized)
|
||||
{
|
||||
|
|
@ -520,11 +505,9 @@ BOOST_AUTO_TEST_CASE( std_reference_wrappers_are_serialized )
|
|||
BOOST_CHECK_EQUAL("\"string\"", to_string(std::cref("string")));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void callable_builtin()
|
||||
{}
|
||||
}
|
||||
namespace {
|
||||
void callable_builtin() {}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(callable_builtin_yields_a_question_mark_when_serialized)
|
||||
{
|
||||
|
|
@ -532,55 +515,49 @@ BOOST_AUTO_TEST_CASE( callable_builtin_yields_a_question_mark_when_serialized )
|
|||
BOOST_CHECK_EQUAL("?", to_string(&callable_builtin));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct serialized_using_format
|
||||
{};
|
||||
std::ostream& operator<<(std::ostream& s, const serialized_using_format&)
|
||||
{
|
||||
return s << mock::format("string");
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_can_use_format_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("\"string\"", to_string(serialized_using_format()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct streamed_using_format
|
||||
{};
|
||||
mock::stream& operator<<(mock::stream& s, const streamed_using_format&)
|
||||
{
|
||||
return s << mock::format("string");
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(type_can_use_format_when_streamed)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("\"string\"", to_string(streamed_using_format()));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct std_string_streamed
|
||||
{};
|
||||
mock::stream& operator<<(mock::stream& s, const std_string_streamed&)
|
||||
{
|
||||
return s << std::string("string");
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(std_string_streamed_is_not_a_container)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("string", to_string(std_string_streamed()));
|
||||
}
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
template<typename T>
|
||||
struct template_serializable
|
||||
{};
|
||||
|
|
@ -589,18 +566,14 @@ namespace detail
|
|||
{
|
||||
return s << "mock::detail::template_serializable";
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mock_detail_template_type_serializable_yields_its_value_when_serialized)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("mock::detail::template_serializable", to_string(mock::detail::template_serializable<int>()));
|
||||
}
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
namespace mock { namespace detail {
|
||||
template<typename T>
|
||||
struct template_streamable
|
||||
{};
|
||||
|
|
@ -615,8 +588,7 @@ namespace detail
|
|||
{
|
||||
return s << "mock::detail::template_streamable";
|
||||
}
|
||||
}
|
||||
} // mock
|
||||
}} // namespace mock::detail
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mock_detail_template_template_streamable_yields_its_value_when_serialized)
|
||||
{
|
||||
|
|
@ -628,13 +600,12 @@ BOOST_AUTO_TEST_CASE( unsigned_char_is_serialized_as_int )
|
|||
BOOST_CHECK_EQUAL(std::to_string(static_cast<int>('a')), to_string<unsigned char>('a'));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
bool some_function()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(boost_phoenix_functor_yields_question_mark_when_serialized)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,14 +9,13 @@
|
|||
#include <turtle/detail/function.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename Expected, typename Actual>
|
||||
bool match(Expected expected, Actual actual)
|
||||
{
|
||||
return mock::matcher<Actual, Expected>(expected)(actual);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(int_and_int_can_be_compared)
|
||||
{
|
||||
|
|
@ -32,13 +31,10 @@ BOOST_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared )
|
|||
BOOST_CHECK(!match(4, std::cref(i)));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct fixture
|
||||
{
|
||||
fixture()
|
||||
: text( "same text" )
|
||||
, actual( text.c_str() )
|
||||
fixture() : text("same text"), actual(text.c_str())
|
||||
{
|
||||
const char* static_string = "same text";
|
||||
BOOST_REQUIRE(actual != static_string);
|
||||
|
|
@ -47,7 +43,7 @@ namespace
|
|||
std::string text;
|
||||
const char* actual;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_pointer_can_be_compared, fixture)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,19 +8,18 @@
|
|||
|
||||
#include "mock_error.hpp"
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#define IDENTITY(z, n, d) d
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_custom_mock
|
||||
{
|
||||
MOCK_METHOD_EXT(method, MOCK_MAX_ARGS, void(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag)
|
||||
MOCK_METHOD_EXT(method2, MOCK_MAX_ARGS, int(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag_2)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(call_mock_method_with_max_number_of_args, mock_error_fixture)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
void my_function(T& t)
|
||||
{
|
||||
|
|
@ -22,7 +21,7 @@ namespace
|
|||
{
|
||||
MOCK_METHOD_EXT(my_method, 1, void(const std::string&), my_tag)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_object_for_static_polymorphism, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -32,13 +31,12 @@ BOOST_FIXTURE_TEST_CASE( mock_object_for_static_polymorphism, mock_error_fixture
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(mock_class_with_operator)
|
||||
{
|
||||
MOCK_CONST_METHOD_EXT(operator+=, 1, mock_class_with_operator &(int), addition)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_addition_operator, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -48,13 +46,12 @@ BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture )
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(mock_class_with_conversion_operator)
|
||||
{
|
||||
MOCK_CONVERSION_OPERATOR(operator, int, conversion)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_conversion_operator, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -64,14 +61,11 @@ BOOST_FIXTURE_TEST_CASE( mock_conversion_operator, mock_error_fixture )
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
MOCK_CLASS(mock_template_class_with_conversion_operator)
|
||||
{
|
||||
MOCK_CONVERSION_OPERATOR_TPL( operator, T, conversion )
|
||||
};
|
||||
}
|
||||
{ MOCK_CONVERSION_OPERATOR_TPL(operator, T, conversion) };
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -81,13 +75,12 @@ BOOST_FIXTURE_TEST_CASE( mock_template_conversion_operator, mock_error_fixture )
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(mock_class_with_const_conversion_operator)
|
||||
{
|
||||
MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_const_conversion_operator, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -98,13 +91,12 @@ BOOST_FIXTURE_TEST_CASE( mock_const_conversion_operator, mock_error_fixture )
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(mock_class_with_non_const_conversion_operator)
|
||||
{
|
||||
MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_non_const_conversion_operator, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -115,14 +107,13 @@ BOOST_FIXTURE_TEST_CASE( mock_non_const_conversion_operator, mock_error_fixture
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
MOCK_CLASS(mock_template_class_with_const_conversion_operator)
|
||||
{
|
||||
MOCK_CONST_CONVERSION_OPERATOR_TPL(operator, T, conversion)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_template_const_conversion_operator, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -132,14 +123,13 @@ BOOST_FIXTURE_TEST_CASE( mock_template_const_conversion_operator, mock_error_fix
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
MOCK_CLASS(mock_template_class_with_non_const_conversion_operator)
|
||||
{
|
||||
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(operator, T, conversion)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_template_non_const_conversion_operator, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -149,14 +139,13 @@ BOOST_FIXTURE_TEST_CASE( mock_template_non_const_conversion_operator, mock_error
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(my_mock)
|
||||
{
|
||||
MOCK_CONST_METHOD_EXT(my_method, 1, void(int), my_method)
|
||||
MOCK_CONST_METHOD_EXT(my_method_2, 1, void(int), my_method_2)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -185,8 +174,7 @@ BOOST_FIXTURE_TEST_CASE( MOCK_EXPECT_macro, mock_error_fixture )
|
|||
CHECK_CALLS(1);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
std::string to_string(const T& t)
|
||||
{
|
||||
|
|
@ -194,7 +182,7 @@ namespace
|
|||
s << t;
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_object_is_named, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -225,16 +213,16 @@ BOOST_FIXTURE_TEST_CASE( mock_object_const_shared_pointer_is_named, mock_error_f
|
|||
BOOST_CHECK_EQUAL("m->my_mock::my_method", to_string(MOCK_HELPER(m->my_method)));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_custom_mock
|
||||
{
|
||||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
||||
MOCK_METHOD_EXT(my_method_2, 0, void(), my_tag_2)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object_is_named, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_and_without_inheriting_from_object_is_named,
|
||||
mock_error_fixture)
|
||||
{
|
||||
my_custom_mock m;
|
||||
BOOST_CHECK_EQUAL("?.my_custom_mock::my_tag", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag)));
|
||||
|
|
@ -245,14 +233,13 @@ BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheritin
|
|||
BOOST_CHECK_EQUAL("m.my_custom_mock::my_tag", to_string(MOCK_HELPER(m.my_tag)));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct my_custom_mock_object : mock::object
|
||||
{
|
||||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
||||
MOCK_METHOD_EXT(my_method_2, 0, void(), my_tag_2)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_is_named, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -271,14 +258,13 @@ BOOST_FIXTURE_TEST_CASE( mock_functor, mock_error_fixture )
|
|||
MOCK_FUNCTOR(f2, int(const std::string&));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
struct tpl_functor_class
|
||||
{
|
||||
MOCK_FUNCTOR(f, void(T));
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_functor_reset, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -300,8 +286,7 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_is_named, mock_error_fixture )
|
|||
BOOST_CHECK_EQUAL("f", to_string(MOCK_HELPER(f)));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_FUNCTION(mock_function, 1, float(int), mock_function)
|
||||
}
|
||||
|
||||
|
|
@ -310,21 +295,19 @@ BOOST_FIXTURE_TEST_CASE( mock_function_is_named, mock_error_fixture )
|
|||
BOOST_CHECK_EQUAL("mock_function", to_string(MOCK_HELPER(mock_function)));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(static_function_class)
|
||||
{
|
||||
MOCK_STATIC_METHOD(f, 1, float(int), f)
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(mock_static_function_is_named, mock_error_fixture)
|
||||
{
|
||||
BOOST_CHECK_EQUAL("static_function_class::f", to_string(MOCK_HELPER(static_function_class::f)));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
MOCK_CLASS(round_parenthesized_signature)
|
||||
{
|
||||
MOCK_METHOD_EXT(m0, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()), m0)
|
||||
|
|
@ -332,10 +315,9 @@ namespace
|
|||
MOCK_FUNCTOR(f0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()));
|
||||
};
|
||||
MOCK_FUNCTION(fun0, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()), fun0)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct base
|
||||
{
|
||||
virtual ~base() = default;
|
||||
|
|
@ -382,7 +364,7 @@ namespace
|
|||
MOCK_FUNCTION(fun3, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()))
|
||||
|
||||
MOCK_FUNCTOR(f_variadic, std::map<int, int>());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# define MOCK_STDCALL __stdcall
|
||||
|
|
@ -390,8 +372,7 @@ namespace
|
|||
# define MOCK_STDCALL
|
||||
#endif
|
||||
|
||||
namespace stdcall
|
||||
{
|
||||
namespace stdcall {
|
||||
struct base
|
||||
{
|
||||
virtual ~base() = default;
|
||||
|
|
@ -411,4 +392,4 @@ namespace stdcall
|
|||
};
|
||||
|
||||
MOCK_FUNCTION(MOCK_STDCALL f, 0, void(), f)
|
||||
}
|
||||
} // namespace stdcall
|
||||
|
|
|
|||
|
|
@ -7,19 +7,18 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "mock_error.hpp"
|
||||
#include <turtle/detail/function.hpp>
|
||||
#include <turtle/reset.hpp>
|
||||
#include <turtle/verify.hpp>
|
||||
#include <turtle/detail/function.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct object : mock::object
|
||||
{};
|
||||
|
||||
object static_o;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(verifying_an_empty_object_succeeds, mock_error_fixture)
|
||||
{
|
||||
|
|
@ -27,25 +26,19 @@ BOOST_FIXTURE_TEST_CASE( verifying_an_empty_object_succeeds, mock_error_fixture
|
|||
BOOST_CHECK(mock::verify(o));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
struct fixture : mock_error_fixture
|
||||
{
|
||||
fixture()
|
||||
{
|
||||
mock::detail::configure( o, e, "instance", mock::detail::make_type_name(o), "name" );
|
||||
}
|
||||
fixture() { mock::detail::configure(o, e, "instance", mock::detail::make_type_name(o), "name"); }
|
||||
object o;
|
||||
mock::detail::function<void()> e;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(verifying_an_object_containing_a_failing_expectation_fails, fixture)
|
||||
{
|
||||
e.expect().once();
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! mock::verify( o ) ),
|
||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||
CHECK_ERROR(BOOST_CHECK(!mock::verify(o)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||
mock::reset(o);
|
||||
BOOST_CHECK(mock::verify(o));
|
||||
}
|
||||
|
|
@ -53,9 +46,7 @@ BOOST_FIXTURE_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fa
|
|||
BOOST_FIXTURE_TEST_CASE(verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails, fixture)
|
||||
{
|
||||
e.expect().once();
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! mock::verify() ),
|
||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||
CHECK_ERROR(BOOST_CHECK(!mock::verify()), "verification failed", 0, "instanceobject::name\n. once()");
|
||||
mock::reset();
|
||||
BOOST_CHECK(mock::verify());
|
||||
}
|
||||
|
|
@ -76,16 +67,10 @@ BOOST_FIXTURE_TEST_CASE( an_object_is_assignable_by_sharing_its_state, mock_erro
|
|||
mock::detail::configure(o2, e, "instance", mock::detail::make_type_name(o2), "name");
|
||||
e.expect().once();
|
||||
o1 = o2;
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! mock::verify( o1 ) ),
|
||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! mock::verify( o2 ) ),
|
||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||
CHECK_ERROR(BOOST_CHECK(!mock::verify(o2)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||
}
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! mock::verify( o1 ) ),
|
||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(an_object_is_copiable_by_sharing_its_state, mock_error_fixture)
|
||||
|
|
@ -95,14 +80,8 @@ BOOST_FIXTURE_TEST_CASE( an_object_is_copiable_by_sharing_its_state, mock_error_
|
|||
mock::detail::function<void()> e;
|
||||
mock::detail::configure(*o2, e, "instance", mock::detail::make_type_name(*o2), "name");
|
||||
e.expect().once();
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! mock::verify( *o2 ) ),
|
||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! mock::verify( o1 ) ),
|
||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||
CHECK_ERROR(BOOST_CHECK(!mock::verify(*o2)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||
o2.reset();
|
||||
CHECK_ERROR(
|
||||
BOOST_CHECK( ! mock::verify( o1 ) ),
|
||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
||||
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "mock_error.hpp"
|
||||
#include <turtle/sequence.hpp>
|
||||
#include <turtle/detail/function.hpp>
|
||||
#include <turtle/sequence.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_and_calling_out_of_order_throws, mock_error_fixture)
|
||||
|
|
@ -21,7 +21,8 @@ BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_thro
|
|||
CHECK_ERROR(e(1), "sequence failed", 1, "?( 1 )\n. once().with( 1 )\nv once().with( 2 )");
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_multiple_invocations_throws, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_and_calling_out_of_order_multiple_invocations_throws,
|
||||
mock_error_fixture)
|
||||
{
|
||||
mock::sequence s;
|
||||
mock::detail::function<void(int)> e;
|
||||
|
|
@ -58,7 +59,8 @@ BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_multiply_calling_in_order
|
|||
CHECK_CALLS(4);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_enforces_call_order_verification_between_two_different_expectations, mock_error_fixture )
|
||||
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_enforces_call_order_verification_between_two_different_expectations,
|
||||
mock_error_fixture)
|
||||
{
|
||||
mock::sequence s;
|
||||
mock::detail::function<void()> e1, e2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue