mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Preview of clang-format changes and CI
This commit is contained in:
parent
bfd1701fcb
commit
805e3b02bf
98 changed files with 6339 additions and 11357 deletions
139
.clang-format
Normal file
139
.clang-format
Normal file
|
|
@ -0,0 +1,139 @@
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveMacros: false
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
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: NonAssignment
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: AfterColon
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 120
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: true
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 2
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
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: '(Impl|_Win32|_Other)?$'
|
||||||
|
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: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 10000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
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: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
Standard: c++14
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 4
|
||||||
|
UseCRLF: false
|
||||||
|
UseTab: Never
|
||||||
|
...
|
||||||
|
|
||||||
17
.github/workflows/static-analysis.yml
vendored
Normal file
17
.github/workflows/static-analysis.yml
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
name: Static analysis
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Formatting:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: git submodule update --init
|
||||||
|
- name: Formatting
|
||||||
|
uses: DoozyX/clang-format-lint-action@v0.9
|
||||||
|
with:
|
||||||
|
source: 'include test doc'
|
||||||
|
clangFormatVersion: 10
|
||||||
|
|
@ -14,8 +14,7 @@
|
||||||
#include "mock_view.hpp"
|
#include "mock_view.hpp"
|
||||||
|
|
||||||
//[ mock_stream_user_type
|
//[ mock_stream_user_type
|
||||||
namespace user_namespace
|
namespace user_namespace {
|
||||||
{
|
|
||||||
struct user_type
|
struct user_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
|
|
@ -23,11 +22,10 @@ namespace user_namespace
|
||||||
{
|
{
|
||||||
return s << "user_type";
|
return s << "user_type";
|
||||||
}
|
}
|
||||||
}
|
} // namespace user_namespace
|
||||||
//]
|
//]
|
||||||
|
|
||||||
namespace custom_constraint_free_function_test
|
namespace custom_constraint_free_function_test {
|
||||||
{
|
|
||||||
//[ custom_constraint_free_function
|
//[ custom_constraint_free_function
|
||||||
bool custom_constraint(int actual)
|
bool custom_constraint(int actual)
|
||||||
{
|
{
|
||||||
|
|
@ -44,22 +42,15 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two )
|
||||||
c.add(41, 1);
|
c.add(41, 1);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace custom_constraint_free_function_test
|
||||||
|
|
||||||
namespace custom_constraint_functor_test
|
namespace custom_constraint_functor_test {
|
||||||
{
|
|
||||||
//[ custom_constraint_functor
|
//[ custom_constraint_functor
|
||||||
struct custom_constraint
|
struct custom_constraint
|
||||||
{
|
{
|
||||||
friend bool operator==( int actual, const custom_constraint& )
|
friend bool operator==(int actual, const custom_constraint&) { return actual == 42; }
|
||||||
{
|
|
||||||
return actual == 42;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& s, const custom_constraint& )
|
friend std::ostream& operator<<(std::ostream& s, const custom_constraint&) { return s << "_ == 42"; }
|
||||||
{
|
|
||||||
return s << "_ == 42";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
//]
|
//]
|
||||||
|
|
||||||
|
|
@ -72,28 +63,23 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two )
|
||||||
c.add(41, 1);
|
c.add(41, 1);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace custom_constraint_functor_test
|
||||||
|
|
||||||
//[ near_constraint
|
//[ near_constraint
|
||||||
template<typename Expected>
|
template<typename Expected>
|
||||||
struct near_constraint
|
struct near_constraint
|
||||||
{
|
{
|
||||||
near_constraint( Expected expected, Expected threshold )
|
near_constraint(Expected expected, Expected threshold) : expected_(expected), threshold_(threshold) {}
|
||||||
: expected_( expected )
|
|
||||||
, threshold_( threshold )
|
|
||||||
{}
|
|
||||||
|
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()(Actual actual) const
|
bool operator()(Actual actual) const
|
||||||
{
|
{
|
||||||
return std::abs( actual - boost::unwrap_ref( expected_ ) )
|
return std::abs(actual - boost::unwrap_ref(expected_)) < boost::unwrap_ref(threshold_);
|
||||||
< boost::unwrap_ref( threshold_ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& s, const near_constraint& c)
|
friend std::ostream& operator<<(std::ostream& s, const near_constraint& c)
|
||||||
{
|
{
|
||||||
return s << "near( " << mock::format( c.expected_ )
|
return s << "near( " << mock::format(c.expected_) << ", " << mock::format(c.threshold_) << " )";
|
||||||
<< ", " << mock::format( c.threshold_ ) << " )";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected expected_, threshold_;
|
Expected expected_, threshold_;
|
||||||
|
|
@ -106,8 +92,7 @@ mock::constraint< near_constraint< Expected > > near( Expected expected, Expecte
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
|
|
||||||
namespace near_constraint_test
|
namespace near_constraint_test {
|
||||||
{
|
|
||||||
//[ near_constraint_test
|
//[ near_constraint_test
|
||||||
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two_plus_or_minus_one)
|
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two_plus_or_minus_one)
|
||||||
{
|
{
|
||||||
|
|
@ -117,10 +102,9 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one )
|
||||||
c.add(41, 1);
|
c.add(41, 1);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace near_constraint_test
|
||||||
|
|
||||||
namespace near_constraint_cref_test
|
namespace near_constraint_cref_test {
|
||||||
{
|
|
||||||
//[ near_constraint_cref_test
|
//[ near_constraint_cref_test
|
||||||
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two_plus_or_minus_one)
|
BOOST_AUTO_TEST_CASE(forty_one_plus_one_is_forty_two_plus_or_minus_one)
|
||||||
{
|
{
|
||||||
|
|
@ -133,7 +117,7 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one )
|
||||||
c.add(41, 1);
|
c.add(41, 1);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace near_constraint_cref_test
|
||||||
|
|
||||||
#undef MOCK_MAX_ARGS
|
#undef MOCK_MAX_ARGS
|
||||||
//[ max_args
|
//[ max_args
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,13 @@
|
||||||
|
|
||||||
//[ prerequisite
|
//[ prerequisite
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
//]
|
//]
|
||||||
#include "calculator.hpp"
|
#include "calculator.hpp"
|
||||||
#include "mock_view.hpp"
|
#include "mock_view.hpp"
|
||||||
|
|
||||||
namespace phases
|
namespace phases {
|
||||||
{
|
|
||||||
//[ phases
|
//[ phases
|
||||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
||||||
{
|
{
|
||||||
|
|
@ -25,10 +24,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||||
c.add(0, 0); // exercise object under test
|
c.add(0, 0); // exercise object under test
|
||||||
} // verify mock objects
|
} // verify mock objects
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace phases
|
||||||
|
|
||||||
namespace verify_reset
|
namespace verify_reset {
|
||||||
{
|
|
||||||
//[ verify_reset
|
//[ verify_reset
|
||||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
||||||
{
|
{
|
||||||
|
|
@ -44,10 +42,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||||
mock::reset(); // reset all expectations for all existing mock objects
|
mock::reset(); // reset all expectations for all existing mock objects
|
||||||
} // automatically verify all expectations are fulfilled for all mock objects going out of scope
|
} // automatically verify all expectations are fulfilled for all mock objects going out of scope
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace verify_reset
|
||||||
|
|
||||||
namespace expectations
|
namespace expectations {
|
||||||
{
|
|
||||||
//[ expectations
|
//[ expectations
|
||||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
||||||
{
|
{
|
||||||
|
|
@ -58,10 +55,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||||
c.add(0, 0);
|
c.add(0, 0);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace expectations
|
||||||
|
|
||||||
namespace sequence
|
namespace sequence {
|
||||||
{
|
|
||||||
//[ sequence
|
//[ sequence
|
||||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
||||||
{
|
{
|
||||||
|
|
@ -74,10 +70,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||||
c.add(1, 0);
|
c.add(1, 0);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace sequence
|
||||||
|
|
||||||
namespace several_sequences
|
namespace several_sequences {
|
||||||
{
|
|
||||||
//[ several_sequences
|
//[ several_sequences
|
||||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
||||||
{
|
{
|
||||||
|
|
@ -93,10 +88,9 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||||
c.add(2, 0);
|
c.add(2, 0);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace several_sequences
|
||||||
|
|
||||||
namespace action
|
namespace action {
|
||||||
{
|
|
||||||
//[ action_view
|
//[ action_view
|
||||||
class view
|
class view
|
||||||
{
|
{
|
||||||
|
|
@ -105,10 +99,7 @@ public:
|
||||||
};
|
};
|
||||||
//]
|
//]
|
||||||
|
|
||||||
MOCK_BASE_CLASS( mock_view, view )
|
MOCK_BASE_CLASS(mock_view, view){MOCK_METHOD(display, 1)};
|
||||||
{
|
|
||||||
MOCK_METHOD( display, 1 )
|
|
||||||
};
|
|
||||||
|
|
||||||
class calculator
|
class calculator
|
||||||
{
|
{
|
||||||
|
|
@ -126,4 +117,4 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||||
c.add(0, 0);
|
c.add(0, 0);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace action
|
||||||
|
|
|
||||||
|
|
@ -7,42 +7,36 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
//[ limitations_comma_in_macro_problem
|
//[ limitations_comma_in_macro_problem
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct my_base_class
|
struct my_base_class
|
||||||
{};
|
{};
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
namespace limitations_comma_in_macro_solution_1
|
namespace limitations_comma_in_macro_solution_1 {
|
||||||
{
|
|
||||||
//[ limitations_comma_in_macro_solution_1
|
//[ limitations_comma_in_macro_solution_1
|
||||||
typedef my_base_class<int, int> my_base_type;
|
typedef my_base_class<int, int> my_base_type;
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_mock, my_base_type )
|
MOCK_BASE_CLASS(my_mock, my_base_type){};
|
||||||
{};
|
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace limitations_comma_in_macro_solution_1
|
||||||
|
|
||||||
namespace limitations_comma_in_macro_solution_2
|
namespace limitations_comma_in_macro_solution_2 {
|
||||||
{
|
|
||||||
//[ limitations_comma_in_macro_solution_2
|
//[ limitations_comma_in_macro_solution_2
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
MOCK_BASE_CLASS( my_mock, my_base_class< T1 BOOST_PP_COMMA() T2 > )
|
MOCK_BASE_CLASS(my_mock, my_base_class<T1 BOOST_PP_COMMA() T2>){};
|
||||||
{};
|
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace limitations_comma_in_macro_solution_2
|
||||||
|
|
||||||
namespace limitations_comma_in_macro_solution_3
|
namespace limitations_comma_in_macro_solution_3 {
|
||||||
{
|
|
||||||
//[ limitations_comma_in_macro_solution_3
|
//[ limitations_comma_in_macro_solution_3
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct my_mock : my_base_class<T1, T2>, mock::object
|
struct my_mock : my_base_class<T1, T2>, mock::object
|
||||||
{};
|
{};
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace limitations_comma_in_macro_solution_3
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,10 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
//[ limitations_const_parameter_warning_problem
|
//[ limitations_const_parameter_warning_problem
|
||||||
class base
|
class base
|
||||||
{
|
{
|
||||||
|
|
@ -19,10 +18,9 @@ namespace
|
||||||
virtual void method(const int) = 0;
|
virtual void method(const int) = 0;
|
||||||
};
|
};
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
namespace limitations_const_parameter_warning_explanation
|
namespace limitations_const_parameter_warning_explanation {
|
||||||
{
|
|
||||||
//[ limitations_const_parameter_warning_explanation
|
//[ limitations_const_parameter_warning_explanation
|
||||||
class derived : public base
|
class derived : public base
|
||||||
{
|
{
|
||||||
|
|
@ -30,21 +28,16 @@ namespace limitations_const_parameter_warning_explanation
|
||||||
virtual void method(const int);
|
virtual void method(const int);
|
||||||
};
|
};
|
||||||
|
|
||||||
void derived::method( int )
|
void derived::method(int) {}
|
||||||
{}
|
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace limitations_const_parameter_warning_explanation
|
||||||
|
|
||||||
namespace limitations_const_parameter_warning_solution
|
namespace limitations_const_parameter_warning_solution {
|
||||||
{
|
|
||||||
//[ limitations_const_parameter_warning_solution
|
//[ limitations_const_parameter_warning_solution
|
||||||
MOCK_BASE_CLASS( mock_base, base )
|
MOCK_BASE_CLASS(mock_base, base){void method(const int i){method_stub(i);
|
||||||
{
|
} // namespace limitations_const_parameter_warning_solution
|
||||||
void method( const int i )
|
|
||||||
{
|
|
||||||
method_stub( i );
|
|
||||||
}
|
|
||||||
MOCK_METHOD(method_stub, 1, void(int), method)
|
MOCK_METHOD(method_stub, 1, void(int), method)
|
||||||
};
|
}
|
||||||
|
;
|
||||||
//]
|
//]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,10 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
//[ limitations_literal_zero_problem
|
//[ limitations_literal_zero_problem
|
||||||
class base
|
class base
|
||||||
{
|
{
|
||||||
|
|
@ -19,12 +18,9 @@ namespace
|
||||||
virtual void method(int* i) = 0;
|
virtual void method(int* i) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( mock_base, base )
|
MOCK_BASE_CLASS(mock_base, base){MOCK_METHOD(method, 1)};
|
||||||
{
|
|
||||||
MOCK_METHOD( method, 1 )
|
|
||||||
};
|
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(literal_zero)
|
BOOST_AUTO_TEST_CASE(literal_zero)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
//[ limitations_non_virtual_method_problem
|
//[ limitations_non_virtual_method_problem
|
||||||
class base
|
class base
|
||||||
|
|
@ -20,8 +20,5 @@ public:
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ limitations_non_virtual_method_problem_2
|
//[ limitations_non_virtual_method_problem_2
|
||||||
MOCK_BASE_CLASS( mock_base, base )
|
MOCK_BASE_CLASS(mock_base, base){MOCK_METHOD(method, 0)};
|
||||||
{
|
|
||||||
MOCK_METHOD( method, 0 )
|
|
||||||
};
|
|
||||||
//]
|
//]
|
||||||
|
|
|
||||||
|
|
@ -7,26 +7,22 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
//[ limitations_protected_private_method_problem
|
//[ limitations_protected_private_method_problem
|
||||||
class base
|
class base
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
virtual void method_1() = 0;
|
virtual void method_1() = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void method_2() = 0;
|
virtual void method_2() = 0;
|
||||||
};
|
};
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ limitations_protected_private_method_solution
|
//[ limitations_protected_private_method_solution
|
||||||
MOCK_BASE_CLASS( mock_base, base )
|
MOCK_BASE_CLASS(mock_base, base){MOCK_METHOD(method_1, 0, void()) MOCK_METHOD(method_2, 0, void())};
|
||||||
{
|
|
||||||
MOCK_METHOD( method_1, 0, void() )
|
|
||||||
MOCK_METHOD( method_2, 0, void() )
|
|
||||||
};
|
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,16 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
//[ limitations_template_base_class_method_problem
|
//[ limitations_template_base_class_method_problem
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class base
|
class base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~base()
|
virtual ~base() {}
|
||||||
{}
|
|
||||||
|
|
||||||
virtual void method() = 0;
|
virtual void method() = 0;
|
||||||
};
|
};
|
||||||
|
|
@ -26,9 +24,6 @@ namespace
|
||||||
|
|
||||||
//[ limitations_template_base_class_method_solution
|
//[ limitations_template_base_class_method_solution
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_BASE_CLASS( mock_base, base< T > )
|
MOCK_BASE_CLASS(mock_base, base<T>){MOCK_METHOD(method, 1, void())};
|
||||||
{
|
|
||||||
MOCK_METHOD( method, 1, void() )
|
|
||||||
};
|
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,10 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace limitations_template_method_problem
|
namespace limitations_template_method_problem {
|
||||||
{
|
|
||||||
//[ limitations_template_method_problem
|
//[ limitations_template_method_problem
|
||||||
class concept
|
class concept
|
||||||
{
|
{
|
||||||
|
|
@ -30,16 +29,12 @@ void function_under_test( T t ) // T is supposed to model the previous concept
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ limitations_template_method_solution
|
//[ limitations_template_method_solution
|
||||||
MOCK_CLASS( mock_concept )
|
MOCK_CLASS(mock_concept){MOCK_METHOD(method, 1, void(int), method_int)
|
||||||
{
|
MOCK_METHOD(method, 1, void(const char*), method_string)};
|
||||||
MOCK_METHOD( method, 1, void( int ), method_int )
|
|
||||||
MOCK_METHOD( method, 1, void( const char* ), method_string )
|
|
||||||
};
|
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace limitations_template_method_problem
|
||||||
|
|
||||||
namespace limitations_template_method_problem_2
|
namespace limitations_template_method_problem_2 {
|
||||||
{
|
|
||||||
//[ limitations_template_method_problem_2
|
//[ limitations_template_method_problem_2
|
||||||
class concept
|
class concept
|
||||||
{
|
{
|
||||||
|
|
@ -80,4 +75,4 @@ std::string mock_concept::create< std::string >()
|
||||||
return create_string();
|
return create_string();
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace limitations_template_method_problem_2
|
||||||
|
|
|
||||||
|
|
@ -7,29 +7,24 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
//[ limitations_throw_specifier_problem
|
//[ limitations_throw_specifier_problem
|
||||||
struct base_class
|
struct base_class
|
||||||
{
|
{
|
||||||
virtual ~base_class()
|
virtual ~base_class() {}
|
||||||
{}
|
|
||||||
|
|
||||||
virtual void method() throw();
|
virtual void method() throw();
|
||||||
};
|
};
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ limitations_throw_specifier_solution
|
//[ limitations_throw_specifier_solution
|
||||||
MOCK_BASE_CLASS( mock_class, base_class )
|
MOCK_BASE_CLASS(mock_class, base_class){void method() throw(){method_proxy();
|
||||||
{
|
} // namespace
|
||||||
void method() throw ()
|
|
||||||
{
|
|
||||||
method_proxy();
|
|
||||||
}
|
|
||||||
MOCK_METHOD(method_proxy, 0, void(), method)
|
MOCK_METHOD(method_proxy, 0, void(), method)
|
||||||
};
|
}
|
||||||
|
;
|
||||||
//]
|
//]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
#ifndef MOCK_VIEW
|
#ifndef MOCK_VIEW
|
||||||
#define MOCK_VIEW
|
#define MOCK_VIEW
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
|
||||||
#include "view.hpp"
|
#include "view.hpp"
|
||||||
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
//[ mock_view
|
//[ mock_view
|
||||||
MOCK_BASE_CLASS(mock_view, view) // declare a 'mock_view' class implementing 'view'
|
MOCK_BASE_CLASS(mock_view, view) // declare a 'mock_view' class implementing 'view'
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,12 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
|
||||||
#include "calculator.hpp"
|
#include "calculator.hpp"
|
||||||
#include "mock_view.hpp"
|
#include "mock_view.hpp"
|
||||||
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace simple
|
namespace simple {
|
||||||
{
|
|
||||||
//[ simple_calculator
|
//[ simple_calculator
|
||||||
class calculator
|
class calculator
|
||||||
{
|
{
|
||||||
|
|
@ -29,17 +28,14 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||||
BOOST_CHECK_EQUAL(0, c.add(0, 0));
|
BOOST_CHECK_EQUAL(0, c.add(0, 0));
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace simple
|
||||||
|
|
||||||
namespace without_mock_object
|
namespace without_mock_object {
|
||||||
{
|
|
||||||
//[ my_view
|
//[ my_view
|
||||||
class my_view : public view
|
class my_view : public view
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
my_view()
|
my_view() : called(false) {}
|
||||||
: called( false )
|
|
||||||
{}
|
|
||||||
virtual void display(int result)
|
virtual void display(int result)
|
||||||
{
|
{
|
||||||
called = true;
|
called = true;
|
||||||
|
|
@ -60,17 +56,17 @@ BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||||
BOOST_CHECK_EQUAL(0, v.value);
|
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
|
//[ zero_plus_zero_is_zero_with_mock_object
|
||||||
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
BOOST_AUTO_TEST_CASE(zero_plus_zero_is_zero)
|
||||||
{
|
{
|
||||||
mock_view v;
|
mock_view v;
|
||||||
calculator c(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);
|
c.add(0, 0);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
}
|
} // namespace with_mock_object
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
//[ async_call_problem
|
//[ async_call_problem
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class base_class
|
class base_class
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -22,18 +21,17 @@ namespace
|
||||||
|
|
||||||
void flush(); // repetitively calling this method will in turn call base_class::method at some point
|
void flush(); // repetitively calling this method will in turn call base_class::method at some point
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ async_call_solution
|
//[ async_call_solution
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/lambda/lambda.hpp>
|
|
||||||
#include <boost/thread.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/lambda/lambda.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
void check(bool& condition, F flush, int attempts = 100, int sleep = 100)
|
void check(bool& condition, F flush, int attempts = 100, int sleep = 100)
|
||||||
{
|
{
|
||||||
|
|
@ -45,15 +43,12 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
MOCK_BASE_CLASS(mock_base_class, base_class){MOCK_METHOD(method, 0)};
|
||||||
{
|
|
||||||
MOCK_METHOD( method, 0 )
|
|
||||||
};
|
|
||||||
void set_bool(bool& b)
|
void set_bool(bool& b)
|
||||||
{
|
{
|
||||||
b = true;
|
b = true;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(method_is_called)
|
BOOST_AUTO_TEST_CASE(method_is_called)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@
|
||||||
//[ invoke_functor_problem
|
//[ invoke_functor_problem
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class base_class
|
class base_class
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -18,27 +17,24 @@ namespace
|
||||||
};
|
};
|
||||||
|
|
||||||
void function(base_class&); // the function will call 'method' with a functor to be applied
|
void function(base_class&); // the function will call 'method' with a functor to be applied
|
||||||
}
|
} // namespace
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ invoke_functor_solution
|
//[ invoke_functor_solution
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/bind/apply.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/bind/apply.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_BASE_CLASS(mock_class, base_class){MOCK_METHOD(method, 1)};
|
||||||
MOCK_BASE_CLASS( mock_class, base_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD( method, 1 )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method)
|
BOOST_AUTO_TEST_CASE(how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method)
|
||||||
{
|
{
|
||||||
mock_class mock;
|
mock_class mock;
|
||||||
MOCK_EXPECT( mock.method ).calls( boost::bind( boost::apply< void >(), _1, 42 ) ); // whenever 'method' is called, invoke the functor with 42
|
MOCK_EXPECT(mock.method)
|
||||||
|
.calls(boost::bind(boost::apply<void>(), _1, 42)); // whenever 'method' is called, invoke the functor with 42
|
||||||
function(mock);
|
function(mock);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,15 @@
|
||||||
|
|
||||||
//[ quick_constraint_problem
|
//[ quick_constraint_problem
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class my_class
|
class my_class
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit my_class( int data )
|
explicit my_class(int data) : data_(data) {}
|
||||||
: data_( data )
|
|
||||||
{}
|
|
||||||
int data_;
|
int data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -28,11 +25,10 @@ namespace
|
||||||
return os << "my_class( " << c.data_ << " )";
|
return os << "my_class( " << c.data_ << " )";
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_CLASS( my_mock )
|
MOCK_CLASS(my_mock){
|
||||||
{
|
|
||||||
MOCK_METHOD(method, 1, void(const my_class&)) // how to simply write a custom constraint ?
|
MOCK_METHOD(method, 1, void(const my_class&)) // how to simply write a custom constraint ?
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ quick_constraint_solution
|
//[ quick_constraint_solution
|
||||||
|
|
@ -40,16 +36,19 @@ namespace
|
||||||
|
|
||||||
namespace // in the same namespace as 'my_class'
|
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
|
||||||
{
|
{
|
||||||
return boost::lexical_cast<std::string>(actual) == expected;
|
return boost::lexical_cast<std::string>(actual) == expected;
|
||||||
}
|
}
|
||||||
} // mock
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(method_is_called)
|
BOOST_AUTO_TEST_CASE(method_is_called)
|
||||||
{
|
{
|
||||||
my_mock mock;
|
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));
|
mock.method(my_class(42));
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
//[ retrieve_cref_problem
|
//[ retrieve_cref_problem
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class base_class
|
class base_class
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -20,22 +19,19 @@ namespace
|
||||||
public:
|
public:
|
||||||
explicit my_class(base_class&);
|
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
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ retrieve_cref_solution
|
//[ retrieve_cref_solution
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_BASE_CLASS(mock_base_class, base_class){MOCK_METHOD(method, 1)};
|
||||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD( method, 1 )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(method_is_called_two_times_with_the_same_value)
|
BOOST_AUTO_TEST_CASE(method_is_called_two_times_with_the_same_value)
|
||||||
|
|
@ -43,8 +39,11 @@ BOOST_AUTO_TEST_CASE( method_is_called_two_times_with_the_same_value )
|
||||||
mock_base_class mock;
|
mock_base_class mock;
|
||||||
my_class c(mock);
|
my_class c(mock);
|
||||||
int value;
|
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(mock::retrieve(value)); // on first call retrieve the value, this expectation
|
||||||
MOCK_EXPECT( mock.method ).once().with( boost::cref( value ) ); // on second call compare the previously retrieved value with the newly received one
|
// takes precedence because it can never fail
|
||||||
|
MOCK_EXPECT(mock.method)
|
||||||
|
.once()
|
||||||
|
.with(boost::cref(value)); // on second call compare the previously retrieved value with the newly received one
|
||||||
c.process();
|
c.process();
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,14 @@
|
||||||
|
|
||||||
//[ static_objects_problem
|
//[ static_objects_problem
|
||||||
#define BOOST_AUTO_TEST_MAIN
|
#define BOOST_AUTO_TEST_MAIN
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_class
|
struct my_class
|
||||||
{
|
{
|
||||||
my_class( int i )
|
my_class(int i) : i_(i) {}
|
||||||
: i_( i )
|
|
||||||
{}
|
|
||||||
|
|
||||||
int i_;
|
int i_;
|
||||||
};
|
};
|
||||||
|
|
@ -29,12 +26,13 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_FUNCTION(f, 1, void(my_class*)) // being static 'f' outlive the test case
|
MOCK_FUNCTION(f, 1, void(my_class*)) // being static 'f' outlive the test case
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(static_objects_problem)
|
BOOST_AUTO_TEST_CASE(static_objects_problem)
|
||||||
{
|
{
|
||||||
my_class c(42);
|
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
|
} // the 'c' instance goes out of scope and the '&c' pointer becomes dangling
|
||||||
//]
|
//]
|
||||||
|
|
||||||
|
|
@ -43,7 +41,8 @@ struct fixture
|
||||||
{
|
{
|
||||||
~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
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -57,7 +56,9 @@ BOOST_FIXTURE_TEST_CASE( static_object_partial_solution, fixture )
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[ static_objects_solution
|
//[ 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);
|
my_class c(42);
|
||||||
MOCK_EXPECT(f).once().with(&c);
|
MOCK_EXPECT(f).once().with(&c);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
|
||||||
#include "calculator.hpp"
|
#include "calculator.hpp"
|
||||||
#include "mock_view.hpp"
|
#include "mock_view.hpp"
|
||||||
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
//[ overflow_throws
|
//[ overflow_throws
|
||||||
BOOST_AUTO_TEST_CASE(overflow_throws)
|
BOOST_AUTO_TEST_CASE(overflow_throws)
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -21,8 +21,8 @@ struct catch_mock_error_policy
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Context>
|
template<typename Context>
|
||||||
static void fail( const char* message, const Context& context,
|
static void fail(const char* message, const Context& context, const char* file = "file://unknown-location",
|
||||||
const char* file = "file://unknown-location", int line = 0 )
|
int line = 0)
|
||||||
{
|
{
|
||||||
CAPTURE(context);
|
CAPTURE(context);
|
||||||
FAIL_CHECK(message << " in: " << file << ":" << line);
|
FAIL_CHECK(message << " in: " << file << ":" << line);
|
||||||
|
|
@ -35,10 +35,7 @@ struct catch_mock_error_policy
|
||||||
INFO(file << ":" << line);
|
INFO(file << ":" << line);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pass( const char* file, int line )
|
static void pass(const char* file, int line) { INFO(file << ":" << line); }
|
||||||
{
|
|
||||||
INFO( file << ":" << line );
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MOCK_ERROR_POLICY catch_mock_error_policy
|
#define MOCK_ERROR_POLICY catch_mock_error_policy
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,16 @@
|
||||||
#define MOCK_CLEANUP_HPP_INCLUDED
|
#define MOCK_CLEANUP_HPP_INCLUDED
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "verify.hpp"
|
|
||||||
#include "reset.hpp"
|
#include "reset.hpp"
|
||||||
|
#include "verify.hpp"
|
||||||
#ifdef MOCK_USE_BOOST_TEST
|
#ifdef MOCK_USE_BOOST_TEST
|
||||||
# include <boost/test/unit_test_suite.hpp>
|
# include <boost/test/unit_test_suite.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
struct cleanup
|
struct cleanup
|
||||||
{
|
{
|
||||||
~cleanup()
|
~cleanup() { mock::reset(); }
|
||||||
{
|
|
||||||
mock::reset();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MOCK_USE_BOOST_TEST
|
#ifdef MOCK_USE_BOOST_TEST
|
||||||
|
|
@ -33,7 +29,6 @@ namespace mock
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
|
|
||||||
#endif // MOCK_CLEANUP_HPP_INCLUDED
|
#endif // MOCK_CLEANUP_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,7 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__cpp_lib_uncaught_exceptions) || \
|
#if defined(__cpp_lib_uncaught_exceptions) || defined(_MSC_VER) && (_MSC_VER >= 1900)
|
||||||
defined(_MSC_VER) && (_MSC_VER >= 1900)
|
|
||||||
# ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS
|
# ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS
|
||||||
# define MOCK_UNCAUGHT_EXCEPTIONS
|
# define MOCK_UNCAUGHT_EXCEPTIONS
|
||||||
# endif
|
# endif
|
||||||
|
|
|
||||||
|
|
@ -11,40 +11,32 @@
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include <boost/ref.hpp>
|
#include <boost/move/move.hpp>
|
||||||
#include <boost/preprocessor/stringize.hpp>
|
#include <boost/preprocessor/array.hpp>
|
||||||
#include <boost/preprocessor/control/if.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_binary_params.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum.hpp>
|
#include <boost/preprocessor/stringize.hpp>
|
||||||
#include <boost/preprocessor/array.hpp>
|
#include <boost/preprocessor/variadic/to_array.hpp>
|
||||||
#include <boost/move/move.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/type_traits/decay.hpp>
|
#include <boost/type_traits/decay.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
template<typename Constraint>
|
template<typename Constraint>
|
||||||
struct constraint
|
struct constraint
|
||||||
{
|
{
|
||||||
constraint()
|
constraint() {}
|
||||||
{}
|
constraint(const Constraint& c) : c_(c) {}
|
||||||
constraint( const Constraint& c )
|
|
||||||
: c_( c )
|
|
||||||
{}
|
|
||||||
Constraint c_;
|
Constraint c_;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
template<typename Lhs, typename Rhs>
|
template<typename Lhs, typename Rhs>
|
||||||
class and_
|
class and_
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
and_( const Lhs& lhs, const Rhs& rhs )
|
and_(const Lhs& lhs, const Rhs& rhs) : lhs_(lhs), rhs_(rhs) {}
|
||||||
: lhs_( lhs )
|
|
||||||
, rhs_( rhs )
|
|
||||||
{}
|
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()(const Actual& actual) const
|
bool operator()(const Actual& actual) const
|
||||||
{
|
{
|
||||||
|
|
@ -52,9 +44,9 @@ namespace detail
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<(std::ostream& s, const and_& a)
|
friend std::ostream& operator<<(std::ostream& s, const and_& a)
|
||||||
{
|
{
|
||||||
return s << "( " << mock::format( a.lhs_ )
|
return s << "( " << mock::format(a.lhs_) << " && " << mock::format(a.rhs_) << " )";
|
||||||
<< " && " << mock::format( a.rhs_ ) << " )";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Lhs lhs_;
|
Lhs lhs_;
|
||||||
Rhs rhs_;
|
Rhs rhs_;
|
||||||
|
|
@ -64,10 +56,7 @@ namespace detail
|
||||||
class or_
|
class or_
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
or_( const Lhs& lhs, const Rhs& rhs )
|
or_(const Lhs& lhs, const Rhs& rhs) : lhs_(lhs), rhs_(rhs) {}
|
||||||
: lhs_( lhs )
|
|
||||||
, rhs_( rhs )
|
|
||||||
{}
|
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()(const Actual& actual) const
|
bool operator()(const Actual& actual) const
|
||||||
{
|
{
|
||||||
|
|
@ -75,9 +64,9 @@ namespace detail
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<(std::ostream& s, const or_& o)
|
friend std::ostream& operator<<(std::ostream& s, const or_& o)
|
||||||
{
|
{
|
||||||
return s << "( " << mock::format( o.lhs_ )
|
return s << "( " << mock::format(o.lhs_) << " || " << mock::format(o.rhs_) << " )";
|
||||||
<< " || " << mock::format( o.rhs_ )<< " )";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Lhs lhs_;
|
Lhs lhs_;
|
||||||
Rhs rhs_;
|
Rhs rhs_;
|
||||||
|
|
@ -87,50 +76,40 @@ namespace detail
|
||||||
class not_
|
class not_
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit not_( const Constraint& c )
|
explicit not_(const Constraint& c) : c_(c) {}
|
||||||
: c_( c )
|
|
||||||
{}
|
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()(const Actual& actual) const
|
bool operator()(const Actual& actual) const
|
||||||
{
|
{
|
||||||
return !c_(actual);
|
return !c_(actual);
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<( std::ostream& s, const not_& n )
|
friend std::ostream& operator<<(std::ostream& s, const not_& n) { return s << "! " << mock::format(n.c_); }
|
||||||
{
|
|
||||||
return s << "! " << mock::format( n.c_ );
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
Constraint c_;
|
Constraint c_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs>
|
template<typename Lhs, typename Rhs>
|
||||||
const constraint< detail::or_< Lhs, Rhs > >
|
const constraint<detail::or_<Lhs, Rhs>> operator||(const constraint<Lhs>& lhs, const constraint<Rhs>& rhs)
|
||||||
operator||( const constraint< Lhs >& lhs,
|
|
||||||
const constraint< Rhs >& rhs )
|
|
||||||
{
|
{
|
||||||
return detail::or_<Lhs, Rhs>(lhs.c_, rhs.c_);
|
return detail::or_<Lhs, Rhs>(lhs.c_, rhs.c_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs>
|
template<typename Lhs, typename Rhs>
|
||||||
const constraint< detail::and_< Lhs, Rhs > >
|
const constraint<detail::and_<Lhs, Rhs>> operator&&(const constraint<Lhs>& lhs, const constraint<Rhs>& rhs)
|
||||||
operator&&( const constraint< Lhs >& lhs,
|
|
||||||
const constraint< Rhs >& rhs )
|
|
||||||
{
|
{
|
||||||
return detail::and_<Lhs, Rhs>(lhs.c_, rhs.c_);
|
return detail::and_<Lhs, Rhs>(lhs.c_, rhs.c_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Constraint>
|
template<typename Constraint>
|
||||||
const constraint< detail::not_< Constraint > >
|
const constraint<detail::not_<Constraint>> operator!(const constraint<Constraint>& c)
|
||||||
operator!( const constraint< Constraint >& c )
|
|
||||||
{
|
{
|
||||||
return detail::not_<Constraint>(c.c_);
|
return detail::not_<Constraint>(c.c_);
|
||||||
}
|
}
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#define MOCK_UNARY_CONSTRAINT(Name, n, Args, Expr) \
|
#define MOCK_UNARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||||
namespace detail \
|
namespace detail { \
|
||||||
{ \
|
|
||||||
struct Name \
|
struct Name \
|
||||||
{ \
|
{ \
|
||||||
template<typename Actual> \
|
template<typename Actual> \
|
||||||
|
|
@ -138,121 +117,88 @@ namespace detail
|
||||||
{ \
|
{ \
|
||||||
return Expr; \
|
return Expr; \
|
||||||
} \
|
} \
|
||||||
friend std::ostream& operator<<( std::ostream& s, const Name& ) \
|
friend std::ostream& operator<<(std::ostream& s, const Name&) { return s << BOOST_STRINGIZE(Name); } \
|
||||||
{ \
|
|
||||||
return s << BOOST_STRINGIZE(Name); \
|
|
||||||
} \
|
|
||||||
}; \
|
}; \
|
||||||
} \
|
} \
|
||||||
const mock::constraint<detail::Name> Name;
|
const mock::constraint<detail::Name> Name;
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_ASSIGN(z, n, d) \
|
#define MOCK_CONSTRAINT_ASSIGN(z, n, d) expected##n(boost::forward<T##n>(e##n))
|
||||||
expected##n( boost::forward< T##n >(e##n) )
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \
|
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) boost::unwrap_ref(expected##n)
|
||||||
boost::unwrap_ref( expected##n )
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_FORMAT(z, n, d) \
|
#define MOCK_CONSTRAINT_FORMAT(z, n, d) BOOST_PP_IF(n, << ", " <<, ) mock::format(c.expected##n)
|
||||||
BOOST_PP_IF(n, << ", " <<,) mock::format( c.expected##n )
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_MEMBER(z, n, d) \
|
#define MOCK_CONSTRAINT_MEMBER(z, n, d) Expected_##n expected##n;
|
||||||
Expected_##n expected##n;
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_TPL_TYPE(z, n, d) \
|
#define MOCK_CONSTRAINT_TPL_TYPE(z, n, d) typename boost::decay<const T##n>::type
|
||||||
typename boost::decay< const T##n >::type
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
||||||
const typename boost::unwrap_reference< Expected_##n >::type& \
|
const typename boost::unwrap_reference<Expected_##n>::type& BOOST_PP_ARRAY_ELEM(n, Args)
|
||||||
BOOST_PP_ARRAY_ELEM(n, Args)
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_ARG(z, n, Args) \
|
#define MOCK_CONSTRAINT_ARG(z, n, Args) BOOST_FWD_REF(T##n) BOOST_PP_ARRAY_ELEM(n, Args)
|
||||||
BOOST_FWD_REF(T##n) BOOST_PP_ARRAY_ELEM(n, Args)
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_ARGS(z, n, Args) \
|
#define MOCK_CONSTRAINT_ARGS(z, n, Args) BOOST_FWD_REF(T##n) e##n
|
||||||
BOOST_FWD_REF(T##n) e##n
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_PARAM(z, n, Args) \
|
#define MOCK_CONSTRAINT_PARAM(z, n, Args) boost::forward<T##n>(BOOST_PP_ARRAY_ELEM(n, Args))
|
||||||
boost::forward< T##n >( BOOST_PP_ARRAY_ELEM(n, Args) )
|
|
||||||
|
|
||||||
#define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \
|
#define MOCK_NARY_CONSTRAINT(Name, n, Args, Expr) \
|
||||||
namespace detail \
|
namespace detail { \
|
||||||
{ \
|
|
||||||
template<BOOST_PP_ENUM_PARAMS(n, typename Expected_)> \
|
template<BOOST_PP_ENUM_PARAMS(n, typename Expected_)> \
|
||||||
struct Name \
|
struct Name \
|
||||||
{ \
|
{ \
|
||||||
template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
|
template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
|
||||||
explicit Name( \
|
explicit Name(BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARGS, _)) : BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
||||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARGS, _) ) \
|
|
||||||
: BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ASSIGN, _) \
|
|
||||||
{} \
|
{} \
|
||||||
template<typename Actual> \
|
template<typename Actual> \
|
||||||
bool operator()(const Actual& actual) const \
|
bool operator()(const Actual& actual) const \
|
||||||
{ \
|
{ \
|
||||||
return test( actual, \
|
return test(actual, BOOST_PP_ENUM(n, MOCK_CONSTRAINT_UNWRAP_REF, _)); \
|
||||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_UNWRAP_REF, _) ); \
|
|
||||||
} \
|
} \
|
||||||
template<typename Actual> \
|
template<typename Actual> \
|
||||||
bool test( const Actual& actual, \
|
bool test(const Actual& actual, BOOST_PP_ENUM(n, MOCK_CONSTRAINT_CREF_PARAM, (n, Args))) const \
|
||||||
BOOST_PP_ENUM(n, \
|
|
||||||
MOCK_CONSTRAINT_CREF_PARAM, (n, Args)) ) const \
|
|
||||||
{ \
|
{ \
|
||||||
return Expr; \
|
return Expr; \
|
||||||
} \
|
} \
|
||||||
friend std::ostream& operator<<(std::ostream& s, const Name& c) \
|
friend std::ostream& operator<<(std::ostream& s, const Name& c) \
|
||||||
{ \
|
{ \
|
||||||
return s << BOOST_STRINGIZE(Name) << "( " \
|
return s << BOOST_STRINGIZE(Name) << "( " << BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_FORMAT, _) << " )"; \
|
||||||
<< BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_FORMAT, _) \
|
|
||||||
<< " )"; \
|
|
||||||
} \
|
} \
|
||||||
BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_MEMBER, _) \
|
BOOST_PP_REPEAT(n, MOCK_CONSTRAINT_MEMBER, _) \
|
||||||
}; \
|
}; \
|
||||||
} \
|
} \
|
||||||
template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
|
template<BOOST_PP_ENUM_PARAMS(n, typename T)> \
|
||||||
mock::constraint< \
|
mock::constraint<detail::Name<BOOST_PP_ENUM(n, MOCK_CONSTRAINT_TPL_TYPE, _)>> Name( \
|
||||||
detail::Name< BOOST_PP_ENUM(n, MOCK_CONSTRAINT_TPL_TYPE, _) > \
|
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARG, (n, Args))) \
|
||||||
> Name( BOOST_PP_ENUM(n, MOCK_CONSTRAINT_ARG, (n, Args)) ) \
|
|
||||||
{ \
|
{ \
|
||||||
return detail::Name<BOOST_PP_ENUM(n, MOCK_CONSTRAINT_TPL_TYPE, _)>( \
|
return detail::Name<BOOST_PP_ENUM(n, MOCK_CONSTRAINT_TPL_TYPE, _)>( \
|
||||||
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_PARAM, (n, Args))); \
|
BOOST_PP_ENUM(n, MOCK_CONSTRAINT_PARAM, (n, Args))); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_EXT(Name, n, Args, Expr) \
|
#define MOCK_CONSTRAINT_EXT(Name, n, Args, Expr) \
|
||||||
BOOST_PP_IF(n, \
|
BOOST_PP_IF(n, MOCK_NARY_CONSTRAINT, MOCK_UNARY_CONSTRAINT)(Name, n, Args, Expr)
|
||||||
MOCK_NARY_CONSTRAINT, \
|
|
||||||
MOCK_UNARY_CONSTRAINT)(Name, n, Args, Expr)
|
|
||||||
|
|
||||||
#ifdef MOCK_VARIADIC_MACROS
|
#ifdef MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
# ifdef BOOST_MSVC
|
# ifdef BOOST_MSVC
|
||||||
# define MOCK_VARIADIC_SIZE(...) \
|
# define MOCK_VARIADIC_SIZE(...) \
|
||||||
BOOST_PP_CAT(MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
|
BOOST_PP_CAT(MOCK_VARIADIC_SIZE_I(__VA_ARGS__, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, \
|
||||||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, \
|
17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, ), )
|
||||||
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
|
# else // BOOST_MSVC
|
||||||
# define MOCK_VARIADIC_SIZE(...) \
|
# define MOCK_VARIADIC_SIZE(...) \
|
||||||
MOCK_VARIADIC_SIZE_I(__VA_ARGS__, \
|
MOCK_VARIADIC_SIZE_I(__VA_ARGS__, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, \
|
||||||
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, \
|
14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, )
|
||||||
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
|
# endif // BOOST_MSVC
|
||||||
#define MOCK_VARIADIC_SIZE_I( \
|
# define MOCK_VARIADIC_SIZE_I(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, \
|
||||||
e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, \
|
e19, e20, e21, e22, e23, e24, e25, e26, e27, e28, e29, e30, e31, size, ...) \
|
||||||
e13, e14, e15, e16, e17, e18, e19, e20, e21, e22, e23, e24, \
|
size
|
||||||
e25, e26, e27, e28, e29, e30, e31, size, ...) size
|
|
||||||
|
|
||||||
# define MOCK_CONSTRAINT_AUX_AUX(Name, n, Array) \
|
# define MOCK_CONSTRAINT_AUX_AUX(Name, n, Array) \
|
||||||
MOCK_CONSTRAINT_EXT( \
|
MOCK_CONSTRAINT_EXT(Name, n, BOOST_PP_ARRAY_TO_TUPLE(BOOST_PP_ARRAY_POP_BACK(Array)), \
|
||||||
Name, n, \
|
|
||||||
BOOST_PP_ARRAY_TO_TUPLE(BOOST_PP_ARRAY_POP_BACK(Array)), \
|
|
||||||
BOOST_PP_ARRAY_ELEM(n, Array))
|
BOOST_PP_ARRAY_ELEM(n, Array))
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_AUX(Name, Size, Tuple) \
|
# define MOCK_CONSTRAINT_AUX(Name, Size, Tuple) MOCK_CONSTRAINT_AUX_AUX(Name, BOOST_PP_DEC(Size), (Size, Tuple))
|
||||||
MOCK_CONSTRAINT_AUX_AUX(Name, BOOST_PP_DEC(Size), (Size,Tuple))
|
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT(Name, ...) \
|
# define MOCK_CONSTRAINT(Name, ...) MOCK_CONSTRAINT_AUX(Name, MOCK_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))
|
||||||
MOCK_CONSTRAINT_AUX( \
|
|
||||||
Name, MOCK_VARIADIC_SIZE(__VA_ARGS__), (__VA_ARGS__))
|
|
||||||
|
|
||||||
#endif // MOCK_VARIADIC_MACROS
|
#endif // MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,18 @@
|
||||||
#include "detail/addressof.hpp"
|
#include "detail/addressof.hpp"
|
||||||
#include "detail/move_helper.hpp"
|
#include "detail/move_helper.hpp"
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/version.hpp>
|
|
||||||
#include <boost/utility/enable_if.hpp>
|
|
||||||
#include <boost/type_traits/common_type.hpp>
|
#include <boost/type_traits/common_type.hpp>
|
||||||
#include <boost/type_traits/is_convertible.hpp>
|
|
||||||
#include <boost/type_traits/has_equal_to.hpp>
|
#include <boost/type_traits/has_equal_to.hpp>
|
||||||
|
#include <boost/type_traits/is_convertible.hpp>
|
||||||
|
#include <boost/utility/enable_if.hpp>
|
||||||
|
#include <boost/version.hpp>
|
||||||
#if BOOST_VERSION >= 107000
|
#if BOOST_VERSION >= 107000
|
||||||
# include <boost/test/tools/floating_point_comparison.hpp>
|
# include <boost/test/tools/floating_point_comparison.hpp>
|
||||||
#else
|
#else
|
||||||
# include <boost/test/floating_point_comparison.hpp>
|
# include <boost/test/floating_point_comparison.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
MOCK_UNARY_CONSTRAINT(any, 0, , ((void)actual, true))
|
MOCK_UNARY_CONSTRAINT(any, 0, , ((void)actual, true))
|
||||||
MOCK_UNARY_CONSTRAINT(affirm, 0, , !!actual)
|
MOCK_UNARY_CONSTRAINT(affirm, 0, , !!actual)
|
||||||
MOCK_UNARY_CONSTRAINT(negate, 0, , !actual)
|
MOCK_UNARY_CONSTRAINT(negate, 0, , !actual)
|
||||||
|
|
@ -39,23 +38,15 @@ namespace mock
|
||||||
|
|
||||||
#if BOOST_VERSION < 105900
|
#if BOOST_VERSION < 105900
|
||||||
|
|
||||||
# define MOCK_SMALL() \
|
# define MOCK_SMALL() boost::test_tools::check_is_small(actual, tolerance)
|
||||||
boost::test_tools::check_is_small( actual, tolerance )
|
|
||||||
# define MOCK_PERCENT_TOLERANCE() \
|
# define MOCK_PERCENT_TOLERANCE() \
|
||||||
boost::test_tools::check_is_close( \
|
boost::test_tools::check_is_close(actual, expected, boost::test_tools::percent_tolerance(tolerance))
|
||||||
actual, \
|
|
||||||
expected, \
|
|
||||||
boost::test_tools::percent_tolerance( tolerance ) )
|
|
||||||
# define MOCK_FRACTION_TOLERANCE() \
|
# define MOCK_FRACTION_TOLERANCE() \
|
||||||
boost::test_tools::check_is_close( \
|
boost::test_tools::check_is_close(actual, expected, boost::test_tools::fraction_tolerance(tolerance))
|
||||||
actual, \
|
|
||||||
expected, \
|
|
||||||
boost::test_tools::fraction_tolerance( tolerance ) )
|
|
||||||
|
|
||||||
#else // BOOST_VERSION < 105900
|
#else // BOOST_VERSION < 105900
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
template<typename T, typename Tolerance>
|
template<typename T, typename Tolerance>
|
||||||
bool is_small(const T& t, const Tolerance& tolerance)
|
bool is_small(const T& t, const Tolerance& tolerance)
|
||||||
{
|
{
|
||||||
|
|
@ -66,18 +57,13 @@ namespace detail
|
||||||
bool is_close(const T1& t1, const T2& t2, const Tolerance& tolerance)
|
bool is_close(const T1& t1, const T2& t2, const Tolerance& tolerance)
|
||||||
{
|
{
|
||||||
typedef typename boost::common_type<T1, T2>::type common_type;
|
typedef typename boost::common_type<T1, T2>::type common_type;
|
||||||
return boost::math::fpc::close_at_tolerance< common_type >(
|
return boost::math::fpc::close_at_tolerance<common_type>(tolerance, boost::math::fpc::FPC_STRONG)(t1, t2);
|
||||||
tolerance, boost::math::fpc::FPC_STRONG )( t1, t2 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
# define MOCK_SMALL() \
|
# define MOCK_SMALL() detail::is_small(actual, tolerance)
|
||||||
detail::is_small( actual, tolerance )
|
# define MOCK_PERCENT_TOLERANCE() detail::is_close(actual, expected, boost::math::fpc::percent_tolerance(tolerance))
|
||||||
# define MOCK_PERCENT_TOLERANCE() \
|
# define MOCK_FRACTION_TOLERANCE() detail::is_close(actual, expected, 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
|
#endif // BOOST_VERSION < 105900
|
||||||
|
|
||||||
|
|
@ -86,17 +72,14 @@ namespace detail
|
||||||
# undef small
|
# undef small
|
||||||
# define MOCK_SMALL_DEFINED
|
# define MOCK_SMALL_DEFINED
|
||||||
#endif
|
#endif
|
||||||
MOCK_NARY_CONSTRAINT( small, 1, ( tolerance ),
|
MOCK_NARY_CONSTRAINT(small, 1, (tolerance), (MOCK_SMALL()))
|
||||||
( MOCK_SMALL() ) )
|
|
||||||
#ifdef MOCK_SMALL_DEFINED
|
#ifdef MOCK_SMALL_DEFINED
|
||||||
# pragma pop_macro("small")
|
# pragma pop_macro("small")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MOCK_NARY_CONSTRAINT( close, 2, ( expected, tolerance ),
|
MOCK_NARY_CONSTRAINT(close, 2, (expected, tolerance), (MOCK_PERCENT_TOLERANCE()))
|
||||||
( MOCK_PERCENT_TOLERANCE() ) )
|
|
||||||
|
|
||||||
MOCK_NARY_CONSTRAINT( close_fraction, 2, ( expected, tolerance ),
|
MOCK_NARY_CONSTRAINT(close_fraction, 2, (expected, tolerance), (MOCK_FRACTION_TOLERANCE()))
|
||||||
( MOCK_FRACTION_TOLERANCE() ) )
|
|
||||||
|
|
||||||
#undef MOCK_PERCENT_TOLERANCE
|
#undef MOCK_PERCENT_TOLERANCE
|
||||||
#undef MOCK_FRACTION_TOLERANCE
|
#undef MOCK_FRACTION_TOLERANCE
|
||||||
|
|
@ -106,41 +89,29 @@ namespace detail
|
||||||
# undef near
|
# undef near
|
||||||
# define MOCK_NEAR_DEFINED
|
# define MOCK_NEAR_DEFINED
|
||||||
#endif
|
#endif
|
||||||
MOCK_NARY_CONSTRAINT( near, 2, ( expected, tolerance ),
|
MOCK_NARY_CONSTRAINT(near, 2, (expected, tolerance), std::abs(actual - expected) < tolerance)
|
||||||
std::abs( actual - expected ) < tolerance )
|
|
||||||
#ifdef MOCK_NEAR_DEFINED
|
#ifdef MOCK_NEAR_DEFINED
|
||||||
# pragma pop_macro("near")
|
# pragma pop_macro("near")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
template<typename Expected>
|
template<typename Expected>
|
||||||
struct equal
|
struct equal
|
||||||
{
|
{
|
||||||
explicit equal( Expected expected )
|
explicit equal(Expected expected) : expected_(expected) {}
|
||||||
: expected_( expected )
|
|
||||||
{}
|
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()( const Actual& actual,
|
bool
|
||||||
|
operator()(const Actual& actual,
|
||||||
typename boost::enable_if<
|
typename boost::enable_if<
|
||||||
boost::has_equal_to<
|
boost::has_equal_to<Actual, typename boost::unwrap_reference<Expected>::type>>::type* = 0) const
|
||||||
Actual,
|
|
||||||
typename
|
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>
|
|
||||||
>::type* = 0 ) const
|
|
||||||
{
|
{
|
||||||
return actual == boost::unwrap_ref(expected_);
|
return actual == boost::unwrap_ref(expected_);
|
||||||
}
|
}
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()( const Actual& actual,
|
bool
|
||||||
|
operator()(const Actual& actual,
|
||||||
typename boost::disable_if<
|
typename boost::disable_if<
|
||||||
boost::has_equal_to<
|
boost::has_equal_to<Actual, typename boost::unwrap_reference<Expected>::type>>::type* = 0) const
|
||||||
Actual,
|
|
||||||
typename
|
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>
|
|
||||||
>::type* = 0 ) const
|
|
||||||
{
|
{
|
||||||
return actual && *actual == boost::unwrap_ref(expected_);
|
return actual && *actual == boost::unwrap_ref(expected_);
|
||||||
}
|
}
|
||||||
|
|
@ -154,9 +125,7 @@ namespace detail
|
||||||
template<typename Expected>
|
template<typename Expected>
|
||||||
struct same
|
struct same
|
||||||
{
|
{
|
||||||
explicit same( const Expected& expected )
|
explicit same(const Expected& expected) : expected_(detail::addressof(boost::unwrap_ref(expected))) {}
|
||||||
: expected_( detail::addressof( boost::unwrap_ref( expected ) ) )
|
|
||||||
{}
|
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()(const Actual& actual) const
|
bool operator()(const Actual& actual) const
|
||||||
{
|
{
|
||||||
|
|
@ -166,50 +135,36 @@ namespace detail
|
||||||
{
|
{
|
||||||
return os << "same( " << mock::format(*s.expected_) << " )";
|
return os << "same( " << mock::format(*s.expected_) << " )";
|
||||||
}
|
}
|
||||||
const typename
|
const typename boost::unwrap_reference<Expected>::type* expected_;
|
||||||
boost::unwrap_reference< Expected >::type* expected_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Expected>
|
template<typename Expected>
|
||||||
struct retrieve
|
struct retrieve
|
||||||
{
|
{
|
||||||
explicit retrieve( Expected& expected )
|
explicit retrieve(Expected& expected) : expected_(detail::addressof(boost::unwrap_ref(expected))) {}
|
||||||
: expected_( detail::addressof( boost::unwrap_ref( expected ) ) )
|
|
||||||
{}
|
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()( const Actual& actual,
|
bool operator()(
|
||||||
|
const Actual& actual,
|
||||||
typename boost::disable_if<
|
typename boost::disable_if<
|
||||||
boost::is_convertible<
|
boost::is_convertible<const Actual*, typename boost::unwrap_reference<Expected>::type>>::type* = 0) const
|
||||||
const Actual*,
|
|
||||||
typename
|
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>
|
|
||||||
>::type* = 0 ) const
|
|
||||||
{
|
{
|
||||||
*expected_ = actual;
|
*expected_ = actual;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()( BOOST_RV_REF(Actual) actual,
|
bool operator()(
|
||||||
|
BOOST_RV_REF(Actual) actual,
|
||||||
typename boost::disable_if<
|
typename boost::disable_if<
|
||||||
boost::is_convertible<
|
boost::is_convertible<const Actual*, typename boost::unwrap_reference<Expected>::type>>::type* = 0) const
|
||||||
const Actual*,
|
|
||||||
typename
|
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>
|
|
||||||
>::type* = 0 ) const
|
|
||||||
{
|
{
|
||||||
*expected_ = boost::move(actual);
|
*expected_ = boost::move(actual);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()( Actual& actual,
|
bool
|
||||||
|
operator()(Actual& actual,
|
||||||
typename boost::enable_if<
|
typename boost::enable_if<
|
||||||
boost::is_convertible< Actual*,
|
boost::is_convertible<Actual*, typename boost::unwrap_reference<Expected>::type>>::type* = 0) const
|
||||||
typename
|
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>
|
|
||||||
>::type* = 0 ) const
|
|
||||||
{
|
{
|
||||||
*expected_ = detail::addressof(actual);
|
*expected_ = detail::addressof(actual);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -218,16 +173,13 @@ namespace detail
|
||||||
{
|
{
|
||||||
return s << "retrieve( " << mock::format(*r.expected_) << " )";
|
return s << "retrieve( " << mock::format(*r.expected_) << " )";
|
||||||
}
|
}
|
||||||
typename
|
typename boost::unwrap_reference<Expected>::type* expected_;
|
||||||
boost::unwrap_reference< Expected >::type* expected_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Expected>
|
template<typename Expected>
|
||||||
struct assign
|
struct assign
|
||||||
{
|
{
|
||||||
explicit assign( const Expected& expected )
|
explicit assign(const Expected& expected) : expected_(expected) {}
|
||||||
: expected_( expected )
|
|
||||||
{}
|
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()(Actual& actual) const
|
bool operator()(Actual& actual) const
|
||||||
{
|
{
|
||||||
|
|
@ -235,14 +187,10 @@ namespace detail
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
bool operator()( Actual* actual,
|
bool
|
||||||
|
operator()(Actual* actual,
|
||||||
typename boost::enable_if<
|
typename boost::enable_if<
|
||||||
boost::is_convertible<
|
boost::is_convertible<typename boost::unwrap_reference<Expected>::type, Actual>>::type* = 0) const
|
||||||
typename
|
|
||||||
boost::unwrap_reference< Expected >::type,
|
|
||||||
Actual
|
|
||||||
>
|
|
||||||
>::type* = 0 ) const
|
|
||||||
{
|
{
|
||||||
if(!actual)
|
if(!actual)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -259,13 +207,10 @@ namespace detail
|
||||||
template<typename Expected>
|
template<typename Expected>
|
||||||
struct contain
|
struct contain
|
||||||
{
|
{
|
||||||
explicit contain( const Expected& expected )
|
explicit contain(const Expected& expected) : expected_(expected) {}
|
||||||
: expected_( expected )
|
|
||||||
{}
|
|
||||||
bool operator()(const std::string& actual) const
|
bool operator()(const std::string& actual) const
|
||||||
{
|
{
|
||||||
return actual.find( boost::unwrap_ref( expected_ ) )
|
return actual.find(boost::unwrap_ref(expected_)) != std::string::npos;
|
||||||
!= std::string::npos;
|
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<(std::ostream& s, const contain& n)
|
friend std::ostream& operator<<(std::ostream& s, const contain& n)
|
||||||
{
|
{
|
||||||
|
|
@ -273,7 +218,7 @@ namespace detail
|
||||||
}
|
}
|
||||||
Expected expected_;
|
Expected expected_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constraint<detail::equal<typename detail::forward_type<T>::type>> equal(BOOST_FWD_REF(T) t)
|
constraint<detail::equal<typename detail::forward_type<T>::type>> equal(BOOST_FWD_REF(T) t)
|
||||||
|
|
@ -307,6 +252,6 @@ namespace detail
|
||||||
{
|
{
|
||||||
return constraint<T>(t);
|
return constraint<T>(t);
|
||||||
}
|
}
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_CONSTRAINTS_HPP_INCLUDED
|
#endif // MOCK_CONSTRAINTS_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,19 +10,16 @@
|
||||||
#define MOCK_ACTION_HPP_INCLUDED
|
#define MOCK_ACTION_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/type_traits/remove_reference.hpp>
|
|
||||||
#include <boost/type_traits/remove_const.hpp>
|
|
||||||
#include <boost/noncopyable.hpp>
|
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
#include <boost/move/move.hpp>
|
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/function.hpp>
|
||||||
|
#include <boost/move/move.hpp>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/type_traits/remove_const.hpp>
|
||||||
|
#include <boost/type_traits/remove_reference.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename Result, typename Signature>
|
template<typename Result, typename Signature>
|
||||||
class action_base
|
class action_base
|
||||||
{
|
{
|
||||||
|
|
@ -36,18 +33,9 @@ namespace detail
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const functor_type& functor() const
|
const functor_type& functor() const { return f_; }
|
||||||
{
|
bool valid() const { return f_ || a_; }
|
||||||
return f_;
|
Result trigger() const { return a_(); }
|
||||||
}
|
|
||||||
bool valid() const
|
|
||||||
{
|
|
||||||
return f_ || a_;
|
|
||||||
}
|
|
||||||
Result trigger() const
|
|
||||||
{
|
|
||||||
return a_();
|
|
||||||
}
|
|
||||||
|
|
||||||
void calls(const functor_type& f)
|
void calls(const functor_type& f)
|
||||||
{
|
{
|
||||||
|
|
@ -63,10 +51,7 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void set( const action_type& a )
|
void set(const action_type& a) { a_ = a; }
|
||||||
{
|
|
||||||
a_ = a;
|
|
||||||
}
|
|
||||||
template<typename Y>
|
template<typename Y>
|
||||||
void set(const boost::reference_wrapper<Y>& r)
|
void set(const boost::reference_wrapper<Y>& r)
|
||||||
{
|
{
|
||||||
|
|
@ -108,9 +93,7 @@ namespace detail
|
||||||
void moves(BOOST_RV_REF(Value) v)
|
void moves(BOOST_RV_REF(Value) v)
|
||||||
{
|
{
|
||||||
this->set(
|
this->set(
|
||||||
boost::bind(
|
boost::bind(&move<typename boost::remove_reference<Value>::type>, boost::ref(store(boost::move(v)))));
|
||||||
&move< typename boost::remove_reference< Value >::type >,
|
|
||||||
boost::ref( store( boost::move( v ) ) ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -121,28 +104,17 @@ namespace detail
|
||||||
}
|
}
|
||||||
struct value : boost::noncopyable
|
struct value : boost::noncopyable
|
||||||
{
|
{
|
||||||
virtual ~value()
|
virtual ~value() {}
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct value_imp : value
|
struct value_imp : value
|
||||||
{
|
{
|
||||||
typedef
|
typedef typename boost::remove_const<typename boost::remove_reference<T>::type>::type value_type;
|
||||||
typename boost::remove_const<
|
|
||||||
typename boost::remove_reference<
|
|
||||||
T
|
|
||||||
>::type
|
|
||||||
>::type value_type;
|
|
||||||
|
|
||||||
value_imp( BOOST_RV_REF(value_type) t )
|
value_imp(BOOST_RV_REF(value_type) t) : t_(boost::move(t)) {}
|
||||||
: t_( boost::move( t ) )
|
value_imp(const value_type& t) : t_(t) {}
|
||||||
{}
|
|
||||||
value_imp( const value_type& t )
|
|
||||||
: t_( t )
|
|
||||||
{}
|
|
||||||
template<typename Y>
|
template<typename Y>
|
||||||
value_imp( Y* y )
|
value_imp(Y* y) : t_(y)
|
||||||
: t_( y )
|
|
||||||
{}
|
{}
|
||||||
value_type t_;
|
value_type t_;
|
||||||
};
|
};
|
||||||
|
|
@ -173,26 +145,19 @@ namespace detail
|
||||||
class action<void, Signature> : public action_base<void, Signature>
|
class action<void, Signature> : public action_base<void, Signature>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
action()
|
action() { this->set(boost::bind(&do_nothing)); }
|
||||||
{
|
|
||||||
this->set( boost::bind( &do_nothing ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void do_nothing()
|
static void do_nothing() {}
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MOCK_AUTO_PTR
|
#ifdef MOCK_AUTO_PTR
|
||||||
template<typename Result, typename Signature>
|
template<typename Result, typename Signature>
|
||||||
class action< std::auto_ptr< Result >, Signature >
|
class action<std::auto_ptr<Result>, Signature> : public action_base<std::auto_ptr<Result>, Signature>
|
||||||
: public action_base< std::auto_ptr< Result >, Signature >
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
action()
|
action() {}
|
||||||
{}
|
action(const action& rhs) : v_(rhs.v_.release())
|
||||||
action( const action& rhs )
|
|
||||||
: v_( rhs.v_.release() )
|
|
||||||
{
|
{
|
||||||
if(v_.get())
|
if(v_.get())
|
||||||
returns(boost::ref(v_));
|
returns(boost::ref(v_));
|
||||||
|
|
@ -220,7 +185,6 @@ namespace detail
|
||||||
mutable std::auto_ptr<Result> v_;
|
mutable std::auto_ptr<Result> v_;
|
||||||
};
|
};
|
||||||
#endif // MOCK_AUTO_PTR
|
#endif // MOCK_AUTO_PTR
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_ACTION_HPP_INCLUDED
|
#endif // MOCK_ACTION_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -12,25 +12,15 @@
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/utility/addressof.hpp>
|
#include <boost/utility/addressof.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
using boost::addressof;
|
using boost::addressof;
|
||||||
|
|
||||||
#ifdef MOCK_NULLPTR
|
#ifdef MOCK_NULLPTR
|
||||||
|
|
||||||
inline const std::nullptr_t* addressof( const std::nullptr_t& p )
|
inline const std::nullptr_t* addressof(const std::nullptr_t& p) { return &p; }
|
||||||
{
|
inline std::nullptr_t* addressof(std::nullptr_t& p) { return &p; }
|
||||||
return &p;
|
|
||||||
}
|
|
||||||
inline std::nullptr_t* addressof( std::nullptr_t& p )
|
|
||||||
{
|
|
||||||
return &p;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_ADDRESSOF_HPP_INCLUDED
|
#endif // MOCK_ADDRESSOF_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,25 +10,18 @@
|
||||||
#define MOCK_CHILD_HPP_INCLUDED
|
#define MOCK_CHILD_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include "type_name.hpp"
|
|
||||||
#include "parent.hpp"
|
#include "parent.hpp"
|
||||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
#include "type_name.hpp"
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class child
|
class child
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
child()
|
child() : parent_(0) {}
|
||||||
: parent_( 0 )
|
void update(parent& p, boost::unit_test::const_string instance, boost::optional<type_name> type,
|
||||||
{}
|
|
||||||
void update( parent& p,
|
|
||||||
boost::unit_test::const_string instance,
|
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name)
|
boost::unit_test::const_string name)
|
||||||
{
|
{
|
||||||
if(instance != "?." || name_.empty())
|
if(instance != "?." || name_.empty())
|
||||||
|
|
@ -42,11 +35,11 @@ namespace detail
|
||||||
s << *c.parent_;
|
s << *c.parent_;
|
||||||
return s << c.name_;
|
return s << c.name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const parent* parent_;
|
const parent* parent_;
|
||||||
boost::unit_test::const_string name_;
|
boost::unit_test::const_string name_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_CHILD_HPP_INCLUDED
|
#endif // MOCK_CHILD_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,7 @@
|
||||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class verifiable;
|
class verifiable;
|
||||||
|
|
||||||
class context : boost::noncopyable
|
class context : boost::noncopyable
|
||||||
|
|
@ -28,17 +25,13 @@ namespace detail
|
||||||
context() {}
|
context() {}
|
||||||
virtual ~context() {}
|
virtual ~context() {}
|
||||||
|
|
||||||
virtual void add( const void* p, verifiable& v,
|
virtual void add(const void* p, verifiable& v, boost::unit_test::const_string instance,
|
||||||
boost::unit_test::const_string instance,
|
boost::optional<type_name> type, boost::unit_test::const_string name) = 0;
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name ) = 0;
|
|
||||||
virtual void add(verifiable& v) = 0;
|
virtual void add(verifiable& v) = 0;
|
||||||
virtual void remove(verifiable& v) = 0;
|
virtual void remove(verifiable& v) = 0;
|
||||||
|
|
||||||
virtual void serialize( std::ostream& s,
|
virtual void serialize(std::ostream& s, const verifiable& v) const = 0;
|
||||||
const verifiable& v ) const = 0;
|
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_CONTEXT_HPP_INCLUDED
|
#endif // MOCK_CONTEXT_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -8,115 +8,84 @@
|
||||||
|
|
||||||
#include "matcher_base_template.hpp"
|
#include "matcher_base_template.hpp"
|
||||||
|
|
||||||
#define MOCK_EXPECTATION_INITIALIZE(z, n, d) \
|
#define MOCK_EXPECTATION_INITIALIZE(z, n, d) BOOST_PP_COMMA_IF(n) c##n##_(c##n)
|
||||||
BOOST_PP_COMMA_IF(n) c##n##_( c##n )
|
|
||||||
|
|
||||||
#define MOCK_EXPECTATION_MEMBER(z, n, d) \
|
#define MOCK_EXPECTATION_MEMBER(z, n, d) matcher<T##n, Constraint_##n> c##n##_;
|
||||||
matcher< T##n, Constraint_##n > c##n##_;
|
|
||||||
|
|
||||||
#define MOCK_EXPECTATION_IS_VALID(z, n, d) \
|
#define MOCK_EXPECTATION_IS_VALID(z, n, d) \
|
||||||
BOOST_PP_IF(n, &&, ) c##n##_(mock::detail::move_if_not_lvalue_reference<T##n>(a##n))
|
BOOST_PP_IF(n, &&, ) c##n##_(mock::detail::move_if_not_lvalue_reference<T##n>(a##n))
|
||||||
|
|
||||||
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) \
|
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) BOOST_PP_IF(n, << ", " <<, ) c##n##_
|
||||||
BOOST_PP_IF(n, << ", " <<,) c##n##_
|
|
||||||
|
|
||||||
#define MOCK_EXPECTATION_SERIALIZE_ANY(z, n, d) \
|
#define MOCK_EXPECTATION_SERIALIZE_ANY(z, n, d) BOOST_PP_IF(n, << ", " <<, ) "any"
|
||||||
BOOST_PP_IF(n, << ", " <<,) "any"
|
|
||||||
|
|
||||||
#define MOCK_EXPECTATION_PARAM(z, n, Args) \
|
#define MOCK_EXPECTATION_PARAM(z, n, Args) mock::detail::move_if_not_lvalue_reference<T##n>(a##n)
|
||||||
mock::detail::move_if_not_lvalue_reference< T##n >( a##n )
|
|
||||||
|
|
||||||
#define MOCK_REF_ARG(z, n, d) \
|
#define MOCK_REF_ARG(z, n, d) typename ref_arg<T##n>::type a##n
|
||||||
typename ref_arg< T##n >::type a##n
|
|
||||||
|
|
||||||
#define MOCK_REF_ARG_T(z, n, d) \
|
#define MOCK_REF_ARG_T(z, n, d) typename ref_arg<T##n>::type
|
||||||
typename ref_arg< T##n >::type
|
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
template<typename Signature>
|
||||||
namespace detail
|
class default_matcher;
|
||||||
{
|
|
||||||
template< typename Signature > class default_matcher;
|
|
||||||
|
|
||||||
template<
|
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
class default_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, 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))>
|
||||||
: public matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
virtual bool operator()(
|
virtual bool operator()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG_T, _)) { return true; }
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG_T, _) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
virtual void serialize(std::ostream& s) const
|
virtual void serialize(std::ostream& s) const
|
||||||
{
|
{
|
||||||
s << "" BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
s << "" BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_SERIALIZE_ANY, _);
|
||||||
MOCK_EXPECTATION_SERIALIZE_ANY, _);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef MOCK_NUM_ARGS_0
|
#ifndef MOCK_NUM_ARGS_0
|
||||||
|
|
||||||
template< typename Constraint, typename Signature > class single_matcher;
|
template<typename Constraint, typename Signature>
|
||||||
|
class single_matcher;
|
||||||
|
|
||||||
template<
|
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_), BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_),
|
class single_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_)),
|
||||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)
|
void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> :
|
||||||
>
|
public matcher_base<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, 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:
|
public:
|
||||||
single_matcher(
|
single_matcher(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c))
|
||||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
: BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_INITIALIZE, _)
|
||||||
: BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
|
||||||
MOCK_EXPECTATION_INITIALIZE, _)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool operator()(
|
virtual bool operator()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _))
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) )
|
|
||||||
{
|
{
|
||||||
return BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
return BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_IS_VALID, _);
|
||||||
MOCK_EXPECTATION_IS_VALID, _);
|
|
||||||
}
|
}
|
||||||
virtual void serialize(std::ostream& s) const
|
virtual void serialize(std::ostream& s) const
|
||||||
{
|
{
|
||||||
s << BOOST_PP_REPEAT(MOCK_NUM_ARGS,
|
s << BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_SERIALIZE, _);
|
||||||
MOCK_EXPECTATION_SERIALIZE, _);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BOOST_PP_REPEAT(
|
BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_EXPECTATION_MEMBER, _)
|
||||||
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,
|
template<typename F, BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
class multi_matcher<F, void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, 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 matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
multi_matcher( const F& f )
|
multi_matcher(const F& f) : f_(f) {}
|
||||||
: f_( f )
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool operator()(
|
virtual bool operator()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _))
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) )
|
|
||||||
{
|
{
|
||||||
return f_(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _));
|
return f_(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _));
|
||||||
}
|
}
|
||||||
virtual void serialize( std::ostream& s ) const
|
virtual void serialize(std::ostream& s) const { s << mock::format(f_); }
|
||||||
{
|
|
||||||
s << mock::format( f_ );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
F f_;
|
F f_;
|
||||||
|
|
@ -124,72 +93,47 @@ namespace detail
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template< typename Signature > class expectation;
|
template<typename Signature>
|
||||||
|
class expectation;
|
||||||
|
|
||||||
template< typename R
|
template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
class expectation<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, 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 action< R, R (BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS,T)) >
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
expectation()
|
expectation()
|
||||||
: invocation_( boost::make_shared< unlimited >() )
|
: invocation_(boost::make_shared<unlimited>()),
|
||||||
, matcher_(
|
matcher_(boost::make_shared<default_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>>()),
|
||||||
boost::make_shared<
|
file_("unknown location"), line_(0)
|
||||||
default_matcher<
|
|
||||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
|
||||||
>
|
|
||||||
> () )
|
|
||||||
, file_( "unknown location" )
|
|
||||||
, line_( 0 )
|
|
||||||
{}
|
{}
|
||||||
expectation(const char* file, int line)
|
expectation(const char* file, int line)
|
||||||
: invocation_( boost::make_shared< unlimited >() )
|
: invocation_(boost::make_shared<unlimited>()),
|
||||||
, matcher_(
|
matcher_(boost::make_shared<default_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>>()),
|
||||||
boost::make_shared<
|
file_(file), line_(line)
|
||||||
default_matcher<
|
|
||||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
|
||||||
>
|
|
||||||
> () )
|
|
||||||
, file_( file )
|
|
||||||
, line_( line )
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~expectation()
|
~expectation()
|
||||||
{
|
{
|
||||||
for( sequences_cit it = sequences_.begin();
|
for(sequences_cit it = sequences_.begin(); it != sequences_.end(); ++it)
|
||||||
it != sequences_.end(); ++it )
|
|
||||||
(*it)->remove(this);
|
(*it)->remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void invoke( const boost::shared_ptr< invocation >& i )
|
void invoke(const boost::shared_ptr<invocation>& i) { invocation_ = i; }
|
||||||
{
|
|
||||||
invocation_ = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef MOCK_NUM_ARGS_0
|
#ifndef MOCK_NUM_ARGS_0
|
||||||
template<
|
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)>
|
||||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)
|
expectation& with(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c))
|
||||||
>
|
|
||||||
expectation& with(
|
|
||||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
|
||||||
{
|
{
|
||||||
matcher_.reset(
|
matcher_.reset(
|
||||||
new single_matcher<
|
new single_matcher<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, Constraint_)),
|
||||||
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)));
|
||||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
|
||||||
>( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) ) );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
# if MOCK_NUM_ARGS > 1
|
# if MOCK_NUM_ARGS > 1
|
||||||
template<typename Constraint>
|
template<typename Constraint>
|
||||||
expectation& with(const Constraint& c)
|
expectation& with(const Constraint& c)
|
||||||
{
|
{
|
||||||
matcher_.reset(
|
matcher_.reset(new multi_matcher<Constraint, void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>(c));
|
||||||
new multi_matcher<
|
|
||||||
Constraint,
|
|
||||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
|
||||||
>( c ) );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
@ -201,45 +145,30 @@ namespace detail
|
||||||
sequences_.push_back(s.impl_);
|
sequences_.push_back(s.impl_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool verify() const
|
bool verify() const { return invocation_->verify(); }
|
||||||
{
|
|
||||||
return invocation_->verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_valid(
|
bool is_valid(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _)) const
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) ) const
|
|
||||||
{
|
{
|
||||||
return !invocation_->exhausted()
|
return !invocation_->exhausted() && (*matcher_)(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _));
|
||||||
&& (*matcher_)( BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_EXPECTATION_PARAM, _) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool invoke() const
|
bool invoke() const
|
||||||
{
|
{
|
||||||
for( sequences_cit it = sequences_.begin();
|
for(sequences_cit it = sequences_.begin(); it != sequences_.end(); ++it)
|
||||||
it != sequences_.end(); ++it )
|
|
||||||
if(!(*it)->is_valid(this))
|
if(!(*it)->is_valid(this))
|
||||||
return false;
|
return false;
|
||||||
bool result = invocation_->invoke();
|
bool result = invocation_->invoke();
|
||||||
for( sequences_cit it = sequences_.begin();
|
for(sequences_cit it = sequences_.begin(); it != sequences_.end(); ++it)
|
||||||
it != sequences_.end(); ++it )
|
|
||||||
(*it)->invalidate(this);
|
(*it)->invalidate(this);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* file() const
|
const char* file() const { return file_; }
|
||||||
{
|
int line() const { return line_; }
|
||||||
return file_;
|
|
||||||
}
|
|
||||||
int line() const
|
|
||||||
{
|
|
||||||
return line_;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend std::ostream& operator<<(
|
friend std::ostream& operator<<(std::ostream& s, const expectation& e)
|
||||||
std::ostream& s, const expectation& e )
|
|
||||||
{
|
{
|
||||||
return s << ( e.invocation_->exhausted() ? 'v' : '.' )
|
return s << (e.invocation_->exhausted() ? 'v' : '.') << ' ' << *e.invocation_
|
||||||
<< ' ' << *e.invocation_
|
|
||||||
#ifndef MOCK_NUM_ARGS_0
|
#ifndef MOCK_NUM_ARGS_0
|
||||||
<< ".with( " << *e.matcher_ << " )"
|
<< ".with( " << *e.matcher_ << " )"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -247,23 +176,16 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector<
|
typedef std::vector<boost::shared_ptr<sequence_impl>> sequences_type;
|
||||||
boost::shared_ptr< sequence_impl >
|
|
||||||
> sequences_type;
|
|
||||||
typedef sequences_type::const_iterator sequences_cit;
|
typedef sequences_type::const_iterator sequences_cit;
|
||||||
|
|
||||||
boost::shared_ptr<invocation> invocation_;
|
boost::shared_ptr<invocation> invocation_;
|
||||||
boost::shared_ptr<
|
boost::shared_ptr<matcher_base<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>> matcher_;
|
||||||
matcher_base<
|
|
||||||
void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
|
||||||
>
|
|
||||||
> matcher_;
|
|
||||||
sequences_type sequences_;
|
sequences_type sequences_;
|
||||||
const char* file_;
|
const char* file_;
|
||||||
int line_;
|
int line_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#undef MOCK_EXPECTATION_INITIALIZE
|
#undef MOCK_EXPECTATION_INITIALIZE
|
||||||
#undef MOCK_EXPECTATION_MEMBER
|
#undef MOCK_EXPECTATION_MEMBER
|
||||||
|
|
|
||||||
|
|
@ -13,20 +13,12 @@
|
||||||
#include "../stream.hpp"
|
#include "../stream.hpp"
|
||||||
#include "addressof.hpp"
|
#include "addressof.hpp"
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct formatter
|
struct formatter
|
||||||
{
|
{
|
||||||
explicit formatter( const T& t )
|
explicit formatter(const T& t) : t_(detail::addressof(t)) {}
|
||||||
: t_( detail::addressof( t ) )
|
void serialize(stream& s) const { detail::serialize(s, *t_); }
|
||||||
{}
|
|
||||||
void serialize( stream& s ) const
|
|
||||||
{
|
|
||||||
detail::serialize( s, *t_ );
|
|
||||||
}
|
|
||||||
const T* t_;
|
const T* t_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -44,7 +36,6 @@ namespace detail
|
||||||
f.serialize(ss);
|
f.serialize(ss);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_FORMATTER_HPP_INCLUDED
|
#endif // MOCK_FORMATTER_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,46 +10,41 @@
|
||||||
#define MOCK_FUNCTION_HPP_INCLUDED
|
#define MOCK_FUNCTION_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
|
#include "../constraints.hpp"
|
||||||
#include "../error.hpp"
|
#include "../error.hpp"
|
||||||
#include "../log.hpp"
|
#include "../log.hpp"
|
||||||
#include "../constraints.hpp"
|
|
||||||
#include "../sequence.hpp"
|
|
||||||
#include "../matcher.hpp"
|
#include "../matcher.hpp"
|
||||||
|
#include "../sequence.hpp"
|
||||||
#include "action.hpp"
|
#include "action.hpp"
|
||||||
#include "verifiable.hpp"
|
|
||||||
#include "invocation.hpp"
|
|
||||||
#include "type_name.hpp"
|
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
#include "mutex.hpp"
|
#include "invocation.hpp"
|
||||||
#include "move_helper.hpp"
|
#include "move_helper.hpp"
|
||||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
#include "mutex.hpp"
|
||||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
#include "type_name.hpp"
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include "verifiable.hpp"
|
||||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
#include <boost/call_traits.hpp>
|
||||||
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/move/move.hpp>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <boost/preprocessor/comparison/equal.hpp>
|
#include <boost/preprocessor/comparison/equal.hpp>
|
||||||
#include <boost/preprocessor/comparison/greater.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/basic_cstring/basic_cstring.hpp>
|
||||||
#include <boost/test/utils/lazy_ostream.hpp>
|
#include <boost/test/utils/lazy_ostream.hpp>
|
||||||
#include <boost/enable_shared_from_this.hpp>
|
#include <list>
|
||||||
#include <boost/call_traits.hpp>
|
|
||||||
#include <boost/make_shared.hpp>
|
|
||||||
#include <boost/noncopyable.hpp>
|
|
||||||
#include <boost/move/move.hpp>
|
|
||||||
#include <boost/optional.hpp>
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename R, typename E>
|
template<typename R, typename E>
|
||||||
struct wrapper_base
|
struct wrapper_base
|
||||||
{
|
{
|
||||||
wrapper_base( E& e )
|
wrapper_base(E& e) : e_(&e) {}
|
||||||
: e_( &e )
|
|
||||||
{}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void returns(T t)
|
void returns(T t)
|
||||||
|
|
@ -62,23 +57,16 @@ namespace detail
|
||||||
template<typename E>
|
template<typename E>
|
||||||
struct wrapper_base<void, E>
|
struct wrapper_base<void, E>
|
||||||
{
|
{
|
||||||
wrapper_base( E& e )
|
wrapper_base(E& e) : e_(&e) {}
|
||||||
: e_( &e )
|
|
||||||
{}
|
|
||||||
|
|
||||||
E* e_;
|
E* e_;
|
||||||
};
|
};
|
||||||
template<typename R, typename E>
|
template<typename R, typename E>
|
||||||
struct wrapper_base<R*, E>
|
struct wrapper_base<R*, E>
|
||||||
{
|
{
|
||||||
wrapper_base( E& e )
|
wrapper_base(E& e) : e_(&e) {}
|
||||||
: e_( &e )
|
|
||||||
{}
|
|
||||||
|
|
||||||
void returns( R* r )
|
void returns(R* r) { e_->returns(r); }
|
||||||
{
|
|
||||||
e_->returns( r );
|
|
||||||
}
|
|
||||||
template<typename Y>
|
template<typename Y>
|
||||||
void returns(const boost::reference_wrapper<Y>& r)
|
void returns(const boost::reference_wrapper<Y>& r)
|
||||||
{
|
{
|
||||||
|
|
@ -97,8 +85,7 @@ namespace detail
|
||||||
return std::uncaught_exception() ? 1 : 0;
|
return std::uncaught_exception() ? 1 : 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#define MOCK_NUM_ARGS 0
|
#define MOCK_NUM_ARGS 0
|
||||||
#define MOCK_NUM_ARGS_0
|
#define MOCK_NUM_ARGS_0
|
||||||
|
|
|
||||||
|
|
@ -12,53 +12,37 @@
|
||||||
# error no error policy has been set
|
# error no error policy has been set
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MOCK_FUNCTION_FORMAT(z, n, N) \
|
#define MOCK_FUNCTION_FORMAT(z, n, N) << ' ' << mock::format(t##n) << BOOST_PP_IF(BOOST_PP_EQUAL(N, n), ' ', ',')
|
||||||
<< ' ' << mock::format( t##n ) \
|
|
||||||
<< BOOST_PP_IF(BOOST_PP_EQUAL(N,n), ' ', ',')
|
|
||||||
|
|
||||||
#define MOCK_FUNCTION_CONTEXT \
|
#define MOCK_FUNCTION_CONTEXT \
|
||||||
boost::unit_test::lazy_ostream::instance() \
|
boost::unit_test::lazy_ostream::instance() \
|
||||||
<< lazy_context( this ) \
|
<< lazy_context(this) << '(' BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_FORMAT, BOOST_PP_DEC(MOCK_NUM_ARGS)) \
|
||||||
<< '(' BOOST_PP_REPEAT(MOCK_NUM_ARGS, MOCK_FUNCTION_FORMAT, \
|
<< ')' << lazy_expectations(this)
|
||||||
BOOST_PP_DEC(MOCK_NUM_ARGS)) \
|
|
||||||
<< ')' \
|
|
||||||
<< lazy_expectations( this )
|
|
||||||
|
|
||||||
#define MOCK_MOVE(z, n, d) \
|
#define MOCK_MOVE(z, n, d) mock::detail::move_if_not_lvalue_reference<T##n>(t##n)
|
||||||
mock::detail::move_if_not_lvalue_reference< T##n >( t##n )
|
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
template<typename Signature>
|
||||||
namespace detail
|
class function_impl;
|
||||||
{
|
|
||||||
template< typename Signature > class function_impl;
|
|
||||||
|
|
||||||
template< typename R
|
template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
class function_impl<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> :
|
||||||
class function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
public verifiable,
|
||||||
: public verifiable, public boost::enable_shared_from_this<
|
public boost::enable_shared_from_this<function_impl<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>>
|
||||||
function_impl< R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )> >
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef safe_error<R, MOCK_ERROR_POLICY<R>> error_type;
|
typedef safe_error<R, MOCK_ERROR_POLICY<R>> error_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
function_impl()
|
function_impl() : context_(0), valid_(true), exceptions_(exceptions()), mutex_(boost::make_shared<mutex>()) {}
|
||||||
: context_( 0 )
|
|
||||||
, valid_( true )
|
|
||||||
, exceptions_( exceptions() )
|
|
||||||
, mutex_( boost::make_shared< mutex >() )
|
|
||||||
{}
|
|
||||||
virtual ~function_impl()
|
virtual ~function_impl()
|
||||||
{
|
{
|
||||||
if(valid_ && exceptions_ >= exceptions())
|
if(valid_ && exceptions_ >= exceptions())
|
||||||
for( expectations_cit it = expectations_.begin();
|
for(expectations_cit it = expectations_.begin(); it != expectations_.end(); ++it)
|
||||||
it != expectations_.end(); ++it )
|
|
||||||
if(!it->verify())
|
if(!it->verify())
|
||||||
error_type::fail("untriggered expectation",
|
error_type::fail("untriggered expectation",
|
||||||
boost::unit_test::lazy_ostream::instance()
|
boost::unit_test::lazy_ostream::instance()
|
||||||
<< lazy_context( this )
|
<< lazy_context(this) << lazy_expectations(this),
|
||||||
<< lazy_expectations( this ),
|
|
||||||
it->file(), it->line());
|
it->file(), it->line());
|
||||||
if(context_)
|
if(context_)
|
||||||
context_->remove(*this);
|
context_->remove(*this);
|
||||||
|
|
@ -67,15 +51,13 @@ namespace detail
|
||||||
virtual bool verify() const
|
virtual bool verify() const
|
||||||
{
|
{
|
||||||
lock _(mutex_);
|
lock _(mutex_);
|
||||||
for( expectations_cit it = expectations_.begin();
|
for(expectations_cit it = expectations_.begin(); it != expectations_.end(); ++it)
|
||||||
it != expectations_.end(); ++it )
|
|
||||||
if(!it->verify())
|
if(!it->verify())
|
||||||
{
|
{
|
||||||
valid_ = false;
|
valid_ = false;
|
||||||
error_type::fail("verification failed",
|
error_type::fail("verification failed",
|
||||||
boost::unit_test::lazy_ostream::instance()
|
boost::unit_test::lazy_ostream::instance()
|
||||||
<< lazy_context( this )
|
<< lazy_context(this) << lazy_expectations(this),
|
||||||
<< lazy_expectations( this ),
|
|
||||||
it->file(), it->line());
|
it->file(), it->line());
|
||||||
}
|
}
|
||||||
return valid_;
|
return valid_;
|
||||||
|
|
@ -85,15 +67,12 @@ namespace detail
|
||||||
{
|
{
|
||||||
lock _(mutex_);
|
lock _(mutex_);
|
||||||
valid_ = true;
|
valid_ = true;
|
||||||
boost::shared_ptr< function_impl > guard =
|
boost::shared_ptr<function_impl> guard = this->shared_from_this();
|
||||||
this->shared_from_this();
|
|
||||||
expectations_.clear();
|
expectations_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef expectation<
|
typedef expectation<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> expectation_type;
|
||||||
R( BOOST_PP_ENUM_PARAMS( MOCK_NUM_ARGS, T ) )
|
|
||||||
> expectation_type;
|
|
||||||
|
|
||||||
class wrapper : public wrapper_base<R, expectation_type>
|
class wrapper : public wrapper_base<R, expectation_type>
|
||||||
{
|
{
|
||||||
|
|
@ -102,14 +81,8 @@ namespace detail
|
||||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(wrapper)
|
BOOST_MOVABLE_BUT_NOT_COPYABLE(wrapper)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wrapper( const boost::shared_ptr< mutex >& m, expectation_type& e )
|
wrapper(const boost::shared_ptr<mutex>& m, expectation_type& e) : base_type(e), lock_(m) {}
|
||||||
: base_type( e )
|
wrapper(BOOST_RV_REF(wrapper) x) : base_type(x), lock_(boost::move(x.lock_)) {}
|
||||||
, lock_( m )
|
|
||||||
{}
|
|
||||||
wrapper( BOOST_RV_REF( wrapper ) x )
|
|
||||||
: base_type( x )
|
|
||||||
, lock_( boost::move( x.lock_) )
|
|
||||||
{}
|
|
||||||
wrapper& operator=(BOOST_RV_REF(wrapper) x)
|
wrapper& operator=(BOOST_RV_REF(wrapper) x)
|
||||||
{
|
{
|
||||||
static_cast<base_type&>(*this) = x;
|
static_cast<base_type&>(*this) = x;
|
||||||
|
|
@ -128,38 +101,30 @@ namespace detail
|
||||||
}
|
}
|
||||||
wrapper& exactly(std::size_t count)
|
wrapper& exactly(std::size_t count)
|
||||||
{
|
{
|
||||||
this->e_->invoke(
|
this->e_->invoke(boost::make_shared<detail::exactly>(count));
|
||||||
boost::make_shared< detail::exactly >( count ) );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
wrapper& at_least(std::size_t min)
|
wrapper& at_least(std::size_t min)
|
||||||
{
|
{
|
||||||
this->e_->invoke(
|
this->e_->invoke(boost::make_shared<detail::at_least>(min));
|
||||||
boost::make_shared< detail::at_least >( min ) );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
wrapper& at_most(std::size_t max)
|
wrapper& at_most(std::size_t max)
|
||||||
{
|
{
|
||||||
this->e_->invoke(
|
this->e_->invoke(boost::make_shared<detail::at_most>(max));
|
||||||
boost::make_shared< detail::at_most >( max ) );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
wrapper& between(std::size_t min, std::size_t max)
|
wrapper& between(std::size_t min, std::size_t max)
|
||||||
{
|
{
|
||||||
this->e_->invoke(
|
this->e_->invoke(boost::make_shared<detail::between>(min, max));
|
||||||
boost::make_shared< detail::between >( min, max ) );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MOCK_NUM_ARGS_0
|
#ifndef MOCK_NUM_ARGS_0
|
||||||
template<
|
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)>
|
||||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename Constraint_)
|
wrapper& with(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c))
|
||||||
>
|
|
||||||
wrapper& with(
|
|
||||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, Constraint_, c) )
|
|
||||||
{
|
{
|
||||||
this->e_->with(
|
this->e_->with(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c));
|
||||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, c) );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,8 +138,7 @@ namespace detail
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MOCK_FUNCTION_IN_ADD(z, n, d) \
|
#define MOCK_FUNCTION_IN_ADD(z, n, d) this->e_->add(s##n);
|
||||||
this->e_->add( s##n );
|
|
||||||
|
|
||||||
#define MOCK_FUNCTION_IN(z, n, d) \
|
#define MOCK_FUNCTION_IN(z, n, d) \
|
||||||
wrapper& in(BOOST_PP_ENUM_PARAMS(n, sequence& s)) \
|
wrapper& in(BOOST_PP_ENUM_PARAMS(n, sequence& s)) \
|
||||||
|
|
@ -183,8 +147,7 @@ namespace detail
|
||||||
return *this; \
|
return *this; \
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_PP_REPEAT(MOCK_MAX_SEQUENCES,
|
BOOST_PP_REPEAT(MOCK_MAX_SEQUENCES, MOCK_FUNCTION_IN, _)
|
||||||
MOCK_FUNCTION_IN, _)
|
|
||||||
|
|
||||||
#undef MOCK_FUNCTION_IN
|
#undef MOCK_FUNCTION_IN
|
||||||
#undef MOCK_FUNCTION_IN_ADD
|
#undef MOCK_FUNCTION_IN_ADD
|
||||||
|
|
@ -226,43 +189,34 @@ namespace detail
|
||||||
return wrapper(mutex_, expectations_.back());
|
return wrapper(mutex_, expectations_.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
R operator()(
|
R operator()(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t)) const
|
||||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const
|
|
||||||
{
|
{
|
||||||
lock _(mutex_);
|
lock _(mutex_);
|
||||||
valid_ = false;
|
valid_ = false;
|
||||||
for( expectations_cit it = expectations_.begin();
|
for(expectations_cit it = expectations_.begin(); it != expectations_.end(); ++it)
|
||||||
it != expectations_.end(); ++it )
|
if(it->is_valid(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _)))
|
||||||
if( it->is_valid(
|
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) ) )
|
|
||||||
{
|
{
|
||||||
if(!it->invoke())
|
if(!it->invoke())
|
||||||
{
|
{
|
||||||
error_type::fail( "sequence failed",
|
error_type::fail("sequence failed", MOCK_FUNCTION_CONTEXT, it->file(), it->line());
|
||||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
|
||||||
return error_type::abort();
|
return error_type::abort();
|
||||||
}
|
}
|
||||||
if(!it->valid())
|
if(!it->valid())
|
||||||
{
|
{
|
||||||
error_type::fail( "missing action",
|
error_type::fail("missing action", MOCK_FUNCTION_CONTEXT, it->file(), it->line());
|
||||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
|
||||||
return error_type::abort();
|
return error_type::abort();
|
||||||
}
|
}
|
||||||
valid_ = true;
|
valid_ = true;
|
||||||
error_type::call(
|
error_type::call(MOCK_FUNCTION_CONTEXT, it->file(), it->line());
|
||||||
MOCK_FUNCTION_CONTEXT, it->file(), it->line() );
|
|
||||||
if(it->functor())
|
if(it->functor())
|
||||||
return it->functor()(
|
return it->functor()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _));
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) );
|
|
||||||
return it->trigger();
|
return it->trigger();
|
||||||
}
|
}
|
||||||
error_type::fail("unexpected call", MOCK_FUNCTION_CONTEXT);
|
error_type::fail("unexpected call", MOCK_FUNCTION_CONTEXT);
|
||||||
return error_type::abort();
|
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 instance,
|
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name)
|
boost::unit_test::const_string name)
|
||||||
{
|
{
|
||||||
lock _(mutex_);
|
lock _(mutex_);
|
||||||
|
|
@ -272,8 +226,7 @@ namespace detail
|
||||||
context_ = &c;
|
context_ = &c;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<(
|
friend std::ostream& operator<<(std::ostream& s, const function_impl& impl)
|
||||||
std::ostream& s, const function_impl& impl )
|
|
||||||
{
|
{
|
||||||
lock _(impl.mutex_);
|
lock _(impl.mutex_);
|
||||||
return s << lazy_context(&impl) << lazy_expectations(&impl);
|
return s << lazy_context(&impl) << lazy_expectations(&impl);
|
||||||
|
|
@ -281,11 +234,8 @@ namespace detail
|
||||||
|
|
||||||
struct lazy_context
|
struct lazy_context
|
||||||
{
|
{
|
||||||
lazy_context( const function_impl* impl )
|
lazy_context(const function_impl* impl) : impl_(impl) {}
|
||||||
: impl_( impl )
|
friend std::ostream& operator<<(std::ostream& s, const lazy_context& c)
|
||||||
{}
|
|
||||||
friend std::ostream& operator<<(
|
|
||||||
std::ostream& s, const lazy_context& c )
|
|
||||||
{
|
{
|
||||||
if(c.impl_->context_)
|
if(c.impl_->context_)
|
||||||
c.impl_->context_->serialize(s, *c.impl_);
|
c.impl_->context_->serialize(s, *c.impl_);
|
||||||
|
|
@ -298,14 +248,10 @@ namespace detail
|
||||||
|
|
||||||
struct lazy_expectations
|
struct lazy_expectations
|
||||||
{
|
{
|
||||||
lazy_expectations( const function_impl* impl )
|
lazy_expectations(const function_impl* impl) : impl_(impl) {}
|
||||||
: impl_( impl )
|
friend std::ostream& operator<<(std::ostream& s, const lazy_expectations& e)
|
||||||
{}
|
|
||||||
friend std::ostream& operator<<(
|
|
||||||
std::ostream& s, const lazy_expectations& e )
|
|
||||||
{
|
{
|
||||||
for( expectations_cit it = e.impl_->expectations_.begin();
|
for(expectations_cit it = e.impl_->expectations_.begin(); it != e.impl_->expectations_.end(); ++it)
|
||||||
it != e.impl_->expectations_.end(); ++it )
|
|
||||||
s << std::endl << *it;
|
s << std::endl << *it;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
@ -321,8 +267,7 @@ namespace detail
|
||||||
const int exceptions_;
|
const int exceptions_;
|
||||||
const boost::shared_ptr<mutex> mutex_;
|
const boost::shared_ptr<mutex> mutex_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#undef MOCK_FUNCTION_FORMAT
|
#undef MOCK_FUNCTION_FORMAT
|
||||||
#undef MOCK_FUNCTION_CONTEXT
|
#undef MOCK_FUNCTION_CONTEXT
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,13 @@
|
||||||
|
|
||||||
#include "function_impl_template.hpp"
|
#include "function_impl_template.hpp"
|
||||||
|
|
||||||
#define MOCK_MOVE(z, n, d) \
|
#define MOCK_MOVE(z, n, d) mock::detail::move_if_not_lvalue_reference<T##n>(t##n)
|
||||||
mock::detail::move_if_not_lvalue_reference< T##n >( t##n )
|
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
template<typename Signature>
|
||||||
namespace detail
|
class function;
|
||||||
{
|
|
||||||
template< typename Signature > class function;
|
|
||||||
|
|
||||||
template< typename R
|
template<typename R BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||||
BOOST_PP_ENUM_TRAILING_PARAMS(MOCK_NUM_ARGS, typename T) >
|
|
||||||
class function<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>
|
class function<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -31,30 +27,20 @@ namespace detail
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef function_impl<
|
typedef function_impl<R(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> impl_type;
|
||||||
R ( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) )
|
|
||||||
> impl_type;
|
|
||||||
typedef typename impl_type::wrapper_type expectation_type;
|
typedef typename impl_type::wrapper_type expectation_type;
|
||||||
typedef typename impl_type::error_type error_type;
|
typedef typename impl_type::error_type error_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
function()
|
function() : impl_(boost::make_shared<impl_type>()) {}
|
||||||
: impl_( boost::make_shared< impl_type >() )
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool verify() const
|
bool verify() const { return impl_->verify(); }
|
||||||
{
|
|
||||||
return impl_->verify();
|
|
||||||
}
|
|
||||||
bool verify(const char* file, int line) const
|
bool verify(const char* file, int line) const
|
||||||
{
|
{
|
||||||
error_type::pass(file, line);
|
error_type::pass(file, line);
|
||||||
return impl_->verify();
|
return impl_->verify();
|
||||||
}
|
}
|
||||||
void reset()
|
void reset() { impl_->reset(); }
|
||||||
{
|
|
||||||
impl_->reset();
|
|
||||||
}
|
|
||||||
void reset(const char* file, int line)
|
void reset(const char* file, int line)
|
||||||
{
|
{
|
||||||
error_type::pass(file, line);
|
error_type::pass(file, line);
|
||||||
|
|
@ -66,33 +52,23 @@ namespace detail
|
||||||
error_type::pass(file, line);
|
error_type::pass(file, line);
|
||||||
return impl_->expect(file, line);
|
return impl_->expect(file, line);
|
||||||
}
|
}
|
||||||
expectation_type expect()
|
expectation_type expect() { return impl_->expect(); }
|
||||||
{
|
|
||||||
return impl_->expect();
|
|
||||||
}
|
|
||||||
|
|
||||||
R operator()(
|
R operator()(BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t)) const
|
||||||
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const
|
|
||||||
{
|
{
|
||||||
return (*impl_)(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _));
|
return (*impl_)(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _));
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& s, const function& f )
|
friend std::ostream& operator<<(std::ostream& s, const function& f) { return s << *f.impl_; }
|
||||||
{
|
|
||||||
return s << *f.impl_;
|
|
||||||
}
|
|
||||||
|
|
||||||
function& operator()( context& c,
|
function& operator()(context& c, boost::unit_test::const_string instance)
|
||||||
boost::unit_test::const_string instance )
|
|
||||||
{
|
{
|
||||||
impl_->add(c, impl_.get(), instance, boost::none, "");
|
impl_->add(c, impl_.get(), instance, boost::none, "");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure( context& c, const void* p,
|
void configure(context& c, const void* p, boost::unit_test::const_string instance,
|
||||||
boost::unit_test::const_string instance,
|
boost::optional<type_name> type, boost::unit_test::const_string name) const
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name ) const
|
|
||||||
{
|
{
|
||||||
impl_->add(c, p, instance, type, name);
|
impl_->add(c, p, instance, type, name);
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +76,6 @@ namespace detail
|
||||||
private:
|
private:
|
||||||
boost::shared_ptr<impl_type> impl_;
|
boost::shared_ptr<impl_type> impl_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#undef MOCK_MOVE
|
#undef MOCK_MOVE
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,8 @@
|
||||||
#include "mutex.hpp"
|
#include "mutex.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
class functor_mutex_t : public singleton<functor_mutex_t>, public mutex
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class functor_mutex_t :
|
|
||||||
public singleton< functor_mutex_t >,
|
|
||||||
public mutex
|
|
||||||
{
|
{
|
||||||
MOCK_SINGLETON_CONS(functor_mutex_t);
|
MOCK_SINGLETON_CONS(functor_mutex_t);
|
||||||
};
|
};
|
||||||
|
|
@ -38,15 +33,13 @@ namespace detail
|
||||||
*this = *f;
|
*this = *f;
|
||||||
f = 0;
|
f = 0;
|
||||||
functor_mutex.unlock();
|
functor_mutex.unlock();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
functor_mutex.lock();
|
functor_mutex.lock();
|
||||||
f = this;
|
f = this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_FUNCTOR_HPP_INCLUDED
|
#endif // MOCK_FUNCTOR_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -11,33 +11,24 @@
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include "verifiable.hpp"
|
#include "verifiable.hpp"
|
||||||
#include <functional>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class group
|
class group
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void add( verifiable& v )
|
void add(verifiable& v) { verifiables_.push_back(&v); }
|
||||||
{
|
|
||||||
verifiables_.push_back( &v );
|
|
||||||
}
|
|
||||||
void remove(verifiable& v)
|
void remove(verifiable& v)
|
||||||
{
|
{
|
||||||
verifiables_.erase(
|
verifiables_.erase(std::remove(verifiables_.begin(), verifiables_.end(), &v), verifiables_.end());
|
||||||
std::remove( verifiables_.begin(), verifiables_.end(), &v ),
|
|
||||||
verifiables_.end() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool verify() const
|
bool verify() const
|
||||||
{
|
{
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for( verifiables_cit it = verifiables_.begin();
|
for(verifiables_cit it = verifiables_.begin(); it != verifiables_.end(); ++it)
|
||||||
it != verifiables_.end(); ++it )
|
|
||||||
if(!(*it)->verify())
|
if(!(*it)->verify())
|
||||||
valid = false;
|
valid = false;
|
||||||
return valid;
|
return valid;
|
||||||
|
|
@ -45,10 +36,8 @@ namespace detail
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
const verifiables_t verifiables = verifiables_;
|
const verifiables_t verifiables = verifiables_;
|
||||||
for( verifiables_cit it = verifiables.begin();
|
for(verifiables_cit it = verifiables.begin(); it != verifiables.end(); ++it)
|
||||||
it != verifiables.end(); ++it )
|
if(std::find(verifiables_.begin(), verifiables_.end(), *it) != verifiables_.end())
|
||||||
if( std::find( verifiables_.begin(), verifiables_.end(), *it )
|
|
||||||
!= verifiables_.end() )
|
|
||||||
(*it)->reset();
|
(*it)->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +47,6 @@ namespace detail
|
||||||
|
|
||||||
verifiables_t verifiables_;
|
verifiables_t verifiables_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_GROUP_HPP_INCLUDED
|
#endif // MOCK_GROUP_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,11 @@
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <stdexcept>
|
|
||||||
#include <ostream>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <ostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class invocation : private boost::noncopyable
|
class invocation : private boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -30,10 +27,7 @@ namespace detail
|
||||||
|
|
||||||
virtual bool exhausted() const = 0;
|
virtual bool exhausted() const = 0;
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& s, const invocation& i )
|
friend std::ostream& operator<<(std::ostream& s, const invocation& i) { return i.serialize(s); }
|
||||||
{
|
|
||||||
return i.serialize( s );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::ostream& serialize(std::ostream& s) const = 0;
|
virtual std::ostream& serialize(std::ostream& s) const = 0;
|
||||||
|
|
@ -42,10 +36,7 @@ namespace detail
|
||||||
class between : public invocation
|
class between : public invocation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
between( std::size_t min, std::size_t max )
|
between(std::size_t min, std::size_t max) : min_(min), max_(max), count_(0)
|
||||||
: min_( min )
|
|
||||||
, max_( max )
|
|
||||||
, count_( 0 )
|
|
||||||
{
|
{
|
||||||
if(min > max)
|
if(min > max)
|
||||||
throw std::invalid_argument("'min' > 'max'");
|
throw std::invalid_argument("'min' > 'max'");
|
||||||
|
|
@ -59,15 +50,9 @@ namespace detail
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool exhausted() const
|
virtual bool exhausted() const { return count_ >= max_; }
|
||||||
{
|
|
||||||
return count_ >= max_;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool verify() const
|
virtual bool verify() const { return min_ <= count_ && count_ <= max_; }
|
||||||
{
|
|
||||||
return min_ <= count_ && count_ <= max_;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const std::size_t min_, max_;
|
const std::size_t min_, max_;
|
||||||
|
|
@ -76,17 +61,14 @@ namespace detail
|
||||||
private:
|
private:
|
||||||
virtual std::ostream& serialize(std::ostream& s) const
|
virtual std::ostream& serialize(std::ostream& s) const
|
||||||
{
|
{
|
||||||
return s << "between( " << count_
|
return s << "between( " << count_ << "/[" << min_ << ',' << max_ << "] )";
|
||||||
<< "/[" << min_ << ',' << max_ << "] )";
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class exactly : public between
|
class exactly : public between
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit exactly( std::size_t count )
|
explicit exactly(std::size_t count) : between(count, count) {}
|
||||||
: between( count, count )
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::ostream& serialize(std::ostream& s) const
|
virtual std::ostream& serialize(std::ostream& s) const
|
||||||
|
|
@ -98,37 +80,25 @@ namespace detail
|
||||||
class never : public exactly
|
class never : public exactly
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
never()
|
never() : exactly(0) {}
|
||||||
: exactly( 0 )
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::ostream& serialize( std::ostream& s ) const
|
virtual std::ostream& serialize(std::ostream& s) const { return s << "never()"; }
|
||||||
{
|
|
||||||
return s << "never()";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class once : public exactly
|
class once : public exactly
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
once()
|
once() : exactly(1) {}
|
||||||
: exactly( 1 )
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::ostream& serialize( std::ostream& s ) const
|
virtual std::ostream& serialize(std::ostream& s) const { return s << "once()"; }
|
||||||
{
|
|
||||||
return s << "once()";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class at_least : public between
|
class at_least : public between
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit at_least( std::size_t min )
|
explicit at_least(std::size_t min) : between(min, (std::numeric_limits<std::size_t>::max)()) {}
|
||||||
: between( min, (std::numeric_limits< std::size_t >::max)() )
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::ostream& serialize(std::ostream& s) const
|
virtual std::ostream& serialize(std::ostream& s) const
|
||||||
|
|
@ -140,9 +110,7 @@ namespace detail
|
||||||
class at_most : public between
|
class at_most : public between
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit at_most( std::size_t max )
|
explicit at_most(std::size_t max) : between(0, max) {}
|
||||||
: between( 0, max )
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::ostream& serialize(std::ostream& s) const
|
virtual std::ostream& serialize(std::ostream& s) const
|
||||||
|
|
@ -154,17 +122,11 @@ namespace detail
|
||||||
class unlimited : public at_least
|
class unlimited : public at_least
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unlimited()
|
unlimited() : at_least(0) {}
|
||||||
: at_least( 0 )
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual std::ostream& serialize( std::ostream& s ) const
|
virtual std::ostream& serialize(std::ostream& s) const { return s << "unlimited()"; }
|
||||||
{
|
|
||||||
return s << "unlimited()";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_INVOCATION_HPP_INCLUDED
|
#endif // MOCK_INVOCATION_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,12 @@
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/function_types/is_callable_builtin.hpp>
|
#include <boost/function_types/is_callable_builtin.hpp>
|
||||||
#include <boost/type_traits/detail/yes_no_type.hpp>
|
|
||||||
#include <boost/utility/declval.hpp>
|
|
||||||
#include <boost/mpl/has_xxx.hpp>
|
#include <boost/mpl/has_xxx.hpp>
|
||||||
#include <boost/mpl/or.hpp>
|
#include <boost/mpl/or.hpp>
|
||||||
|
#include <boost/type_traits/detail/yes_no_type.hpp>
|
||||||
|
#include <boost/utility/declval.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
|
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
|
||||||
BOOST_MPL_HAS_XXX_TEMPLATE_DEF(sig)
|
BOOST_MPL_HAS_XXX_TEMPLATE_DEF(sig)
|
||||||
BOOST_MPL_HAS_XXX_TEMPLATE_DEF(result)
|
BOOST_MPL_HAS_XXX_TEMPLATE_DEF(result)
|
||||||
|
|
@ -33,30 +30,23 @@ namespace detail
|
||||||
typedef boost::type_traits::no_type no_type;
|
typedef boost::type_traits::no_type no_type;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static yes_type check(
|
static yes_type check(decltype(boost::declval<T>()(boost::declval<P>()))*);
|
||||||
decltype( boost::declval< T >()( boost::declval< P >() ) )* );
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static no_type check(...);
|
static no_type check(...);
|
||||||
|
|
||||||
typedef boost::mpl::bool_<
|
typedef boost::mpl::bool_<sizeof(check<F>(0)) == sizeof(yes_type)> type;
|
||||||
sizeof( check< F >( 0 ) ) == sizeof( yes_type ) > type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MOCK_DECLTYPE
|
#endif // MOCK_DECLTYPE
|
||||||
|
|
||||||
template<typename T, typename P>
|
template<typename T, typename P>
|
||||||
struct is_functor
|
struct is_functor :
|
||||||
: boost::mpl::or_<
|
boost::mpl::or_<boost::function_types::is_callable_builtin<T>,
|
||||||
boost::function_types::is_callable_builtin< T >,
|
|
||||||
#ifdef MOCK_DECLTYPE
|
#ifdef MOCK_DECLTYPE
|
||||||
is_callable<T, P>,
|
is_callable<T, P>,
|
||||||
#endif
|
#endif
|
||||||
has_result_type< T >,
|
has_result_type<T>, has_result<T>, has_sig<T>>
|
||||||
has_result< T >,
|
|
||||||
has_sig< T >
|
|
||||||
>
|
|
||||||
{};
|
{};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_IS_FUNCTOR_HPP_INCLUDED
|
#endif // MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -6,28 +6,21 @@
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#define MOCK_REF_ARG(z, n, d) \
|
#define MOCK_REF_ARG(z, n, d) typename ref_arg<T##n>::type
|
||||||
typename ref_arg< T##n >::type
|
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
template<typename Signature>
|
||||||
namespace detail
|
class matcher_base;
|
||||||
{
|
|
||||||
template< typename Signature > class matcher_base;
|
|
||||||
|
|
||||||
template<
|
template<BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T)>
|
||||||
BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) >
|
class matcher_base<void(BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T))> : boost::noncopyable
|
||||||
class matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) >
|
|
||||||
: boost::noncopyable
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~matcher_base() {}
|
virtual ~matcher_base() {}
|
||||||
|
|
||||||
virtual bool operator()(
|
virtual bool operator()(BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _)) = 0;
|
||||||
BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) ) = 0;
|
|
||||||
|
|
||||||
friend std::ostream& operator<<(
|
friend std::ostream& operator<<(std::ostream& s, const matcher_base& m)
|
||||||
std::ostream& s, const matcher_base& m )
|
|
||||||
{
|
{
|
||||||
m.serialize(s);
|
m.serialize(s);
|
||||||
return s;
|
return s;
|
||||||
|
|
@ -36,7 +29,6 @@ namespace detail
|
||||||
private:
|
private:
|
||||||
virtual void serialize(std::ostream&) const = 0;
|
virtual void serialize(std::ostream&) const = 0;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#undef MOCK_REF_ARG
|
#undef MOCK_REF_ARG
|
||||||
|
|
|
||||||
|
|
@ -10,17 +10,14 @@
|
||||||
#define MOCK_MOVE_HELPER_HPP_INCLUDED
|
#define MOCK_MOVE_HELPER_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/type_traits/conditional.hpp>
|
|
||||||
#include <boost/type_traits/is_reference.hpp>
|
|
||||||
#include <boost/type_traits/remove_reference.hpp>
|
|
||||||
#include <boost/type_traits/add_reference.hpp>
|
#include <boost/type_traits/add_reference.hpp>
|
||||||
#include <boost/type_traits/add_rvalue_reference.hpp>
|
#include <boost/type_traits/add_rvalue_reference.hpp>
|
||||||
|
#include <boost/type_traits/conditional.hpp>
|
||||||
#include <boost/type_traits/decay.hpp>
|
#include <boost/type_traits/decay.hpp>
|
||||||
|
#include <boost/type_traits/is_reference.hpp>
|
||||||
|
#include <boost/type_traits/remove_reference.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
#ifdef MOCK_RVALUE_REFERENCES
|
#ifdef MOCK_RVALUE_REFERENCES
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct forward_type
|
struct forward_type
|
||||||
|
|
@ -30,9 +27,7 @@ namespace detail
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ref_arg
|
struct ref_arg
|
||||||
{
|
{
|
||||||
typedef typename boost::conditional<
|
typedef typename boost::conditional<boost::is_reference<T>::value, T,
|
||||||
boost::is_reference< T >::value,
|
|
||||||
T,
|
|
||||||
typename boost::add_rvalue_reference<T>::type>::type type;
|
typename boost::add_rvalue_reference<T>::type>::type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -61,18 +56,16 @@ namespace detail
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ref_arg
|
struct ref_arg
|
||||||
{
|
{
|
||||||
typedef typename boost::conditional<
|
typedef typename boost::conditional<boost::is_reference<T>::value, T,
|
||||||
boost::is_reference< T >::value,
|
|
||||||
T,
|
|
||||||
const typename boost::add_reference<T>::type>::type type;
|
const typename boost::add_reference<T>::type>::type type;
|
||||||
};
|
};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline typename boost::remove_reference< T >::type& move_if_not_lvalue_reference(typename boost::remove_reference< T >::type& t)
|
inline typename boost::remove_reference<T>::type&
|
||||||
|
move_if_not_lvalue_reference(typename boost::remove_reference<T>::type& t)
|
||||||
{
|
{
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}} // namespace mock::detail
|
||||||
}
|
|
||||||
|
|
||||||
#endif // MOCK_MOVE_HELPER_HPP_INCLUDED
|
#endif // MOCK_MOVE_HELPER_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,11 @@
|
||||||
# ifdef MOCK_HDR_MUTEX
|
# ifdef MOCK_HDR_MUTEX
|
||||||
# include <mutex>
|
# include <mutex>
|
||||||
# else
|
# else
|
||||||
#include <boost/thread/recursive_mutex.hpp>
|
|
||||||
# include <boost/thread/lock_guard.hpp>
|
# include <boost/thread/lock_guard.hpp>
|
||||||
|
# include <boost/thread/recursive_mutex.hpp>
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
# ifdef MOCK_HDR_MUTEX
|
# ifdef MOCK_HDR_MUTEX
|
||||||
typedef std::recursive_mutex mutex;
|
typedef std::recursive_mutex mutex;
|
||||||
typedef std::lock_guard<mutex> scoped_lock;
|
typedef std::lock_guard<mutex> scoped_lock;
|
||||||
|
|
@ -42,18 +39,13 @@ namespace detail
|
||||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(lock)
|
BOOST_MOVABLE_BUT_NOT_COPYABLE(lock)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
lock( const boost::shared_ptr< mutex >& m )
|
lock(const boost::shared_ptr<mutex>& m) : m_(m) { m_->lock(); }
|
||||||
: m_( m )
|
|
||||||
{
|
|
||||||
m_->lock();
|
|
||||||
}
|
|
||||||
~lock()
|
~lock()
|
||||||
{
|
{
|
||||||
if(m_)
|
if(m_)
|
||||||
m_->unlock();
|
m_->unlock();
|
||||||
}
|
}
|
||||||
lock( BOOST_RV_REF( lock ) x )
|
lock(BOOST_RV_REF(lock) x) : m_(x.m_)
|
||||||
: m_( x.m_ )
|
|
||||||
{
|
{
|
||||||
// Explicit reset to avoid unlock in destructor
|
// Explicit reset to avoid unlock in destructor
|
||||||
x.m_.reset();
|
x.m_.reset();
|
||||||
|
|
@ -68,30 +60,22 @@ namespace detail
|
||||||
private:
|
private:
|
||||||
boost::shared_ptr<mutex> m_;
|
boost::shared_ptr<mutex> m_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#else // MOCK_THREAD_SAFE
|
#else // MOCK_THREAD_SAFE
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct mutex : boost::noncopyable
|
struct mutex : boost::noncopyable
|
||||||
{
|
{
|
||||||
void lock()
|
void lock() {}
|
||||||
{}
|
void unlock() {}
|
||||||
void unlock()
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
// Dummy lock classes.
|
// Dummy lock classes.
|
||||||
// Constructor + Destructor make it RAII classes for compilers and avoid unused variable warnings
|
// Constructor + Destructor make it RAII classes for compilers and avoid unused variable warnings
|
||||||
struct scoped_lock : boost::noncopyable
|
struct scoped_lock : boost::noncopyable
|
||||||
{
|
{
|
||||||
scoped_lock( mutex& )
|
scoped_lock(mutex&) {}
|
||||||
{}
|
~scoped_lock() {}
|
||||||
~scoped_lock()
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
class lock : boost::noncopyable
|
class lock : boost::noncopyable
|
||||||
{
|
{
|
||||||
|
|
@ -99,28 +83,17 @@ namespace detail
|
||||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(lock)
|
BOOST_MOVABLE_BUT_NOT_COPYABLE(lock)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
lock( const boost::shared_ptr< mutex >& )
|
lock(const boost::shared_ptr<mutex>&) {}
|
||||||
{}
|
~lock() {}
|
||||||
~lock()
|
lock(BOOST_RV_REF(lock)) {}
|
||||||
{}
|
lock& operator=(BOOST_RV_REF(lock)) { return *this; }
|
||||||
lock( BOOST_RV_REF( lock ) )
|
|
||||||
{}
|
|
||||||
lock& operator=( BOOST_RV_REF( lock ) )
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_THREAD_SAFE
|
#endif // MOCK_THREAD_SAFE
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
class error_mutex_t : public singleton<error_mutex_t>, public mutex
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class error_mutex_t : public singleton< error_mutex_t >,
|
|
||||||
public mutex
|
|
||||||
{
|
{
|
||||||
MOCK_SINGLETON_CONS(error_mutex_t);
|
MOCK_SINGLETON_CONS(error_mutex_t);
|
||||||
};
|
};
|
||||||
|
|
@ -139,8 +112,8 @@ namespace detail
|
||||||
return Error::abort();
|
return Error::abort();
|
||||||
}
|
}
|
||||||
template<typename Context>
|
template<typename Context>
|
||||||
static void fail( const char* message, const Context& context,
|
static void fail(const char* message, const Context& context, const char* file = "unknown location",
|
||||||
const char* file = "unknown location", int line = 0 )
|
int line = 0)
|
||||||
{
|
{
|
||||||
scoped_lock _(error_mutex);
|
scoped_lock _(error_mutex);
|
||||||
Error::fail(message, context, file, line);
|
Error::fail(message, context, file, line);
|
||||||
|
|
@ -160,7 +133,6 @@ namespace detail
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
# pragma warning(pop)
|
# pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_MUTEX_HPP_INCLUDED
|
#endif // MOCK_MUTEX_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,33 +10,25 @@
|
||||||
#define MOCK_OBJECT_IMPL_HPP_INCLUDED
|
#define MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include "root.hpp"
|
|
||||||
#include "parent.hpp"
|
|
||||||
#include "type_name.hpp"
|
|
||||||
#include "context.hpp"
|
|
||||||
#include "child.hpp"
|
#include "child.hpp"
|
||||||
|
#include "context.hpp"
|
||||||
#include "mutex.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/enable_shared_from_this.hpp>
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
class object_impl : public context, public verifiable, public boost::enable_shared_from_this<object_impl>
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class object_impl : public context, public verifiable,
|
|
||||||
public boost::enable_shared_from_this< object_impl >
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
object_impl()
|
object_impl() : mutex_(boost::make_shared<mutex>()) {}
|
||||||
: mutex_( boost::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::unit_test::const_string instance,
|
boost::optional<type_name> type, boost::unit_test::const_string name)
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name )
|
|
||||||
{
|
{
|
||||||
lock _(mutex_);
|
lock _(mutex_);
|
||||||
if(children_.empty())
|
if(children_.empty())
|
||||||
|
|
@ -88,7 +80,6 @@ namespace detail
|
||||||
children_t children_;
|
children_t children_;
|
||||||
const boost::shared_ptr<mutex> mutex_;
|
const boost::shared_ptr<mutex> mutex_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_OBJECT_IMPL_HPP_INCLUDED
|
#endif // MOCK_OBJECT_IMPL_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,25 +10,16 @@
|
||||||
#define MOCK_PARAMETER_HPP_INCLUDED
|
#define MOCK_PARAMETER_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/function_types/parameter_types.hpp>
|
|
||||||
#include <boost/function_types/function_arity.hpp>
|
#include <boost/function_types/function_arity.hpp>
|
||||||
|
#include <boost/function_types/parameter_types.hpp>
|
||||||
#include <boost/mpl/at.hpp>
|
#include <boost/mpl/at.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename Signature, int n>
|
template<typename Signature, int n>
|
||||||
struct parameter
|
struct parameter
|
||||||
{
|
{
|
||||||
typedef typename
|
typedef typename boost::mpl::at_c<typename boost::function_types::parameter_types<Signature>, n>::type type;
|
||||||
boost::mpl::at_c<
|
|
||||||
typename
|
|
||||||
boost::function_types::parameter_types< Signature >,
|
|
||||||
n
|
|
||||||
>::type type;
|
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_PARAMETER_HPP_INCLUDED
|
#endif // MOCK_PARAMETER_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -11,23 +11,17 @@
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include "type_name.hpp"
|
#include "type_name.hpp"
|
||||||
#include <boost/test/utils/basic_cstring/io.hpp>
|
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class parent
|
class parent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
parent()
|
parent() {}
|
||||||
{}
|
parent(boost::unit_test::const_string instance, boost::optional<type_name> type)
|
||||||
parent( boost::unit_test::const_string instance,
|
: instance_(instance), type_(type)
|
||||||
boost::optional< type_name > type )
|
|
||||||
: instance_( instance )
|
|
||||||
, type_( type )
|
|
||||||
{}
|
{}
|
||||||
friend std::ostream& operator<<(std::ostream& s, const parent& p)
|
friend std::ostream& operator<<(std::ostream& s, const parent& p)
|
||||||
{
|
{
|
||||||
|
|
@ -36,11 +30,11 @@ namespace detail
|
||||||
s << *p.type_ << "::";
|
s << *p.type_ << "::";
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::unit_test::const_string instance_;
|
boost::unit_test::const_string instance_;
|
||||||
boost::optional<type_name> type_;
|
boost::optional<type_name> type_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_PARENT_HPP_INCLUDED
|
#endif // MOCK_PARENT_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,34 +10,27 @@
|
||||||
#define MOCK_ROOT_HPP_INCLUDED
|
#define MOCK_ROOT_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include "parent.hpp"
|
|
||||||
#include "group.hpp"
|
|
||||||
#include "context.hpp"
|
|
||||||
#include "child.hpp"
|
#include "child.hpp"
|
||||||
|
#include "context.hpp"
|
||||||
|
#include "group.hpp"
|
||||||
#include "mutex.hpp"
|
#include "mutex.hpp"
|
||||||
|
#include "parent.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <ostream>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class root_t : public singleton<root_t>, public context
|
class root_t : public singleton<root_t>, public context
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void add( const void* p, verifiable& v,
|
virtual void add(const void* p, verifiable& v, boost::unit_test::const_string instance,
|
||||||
boost::unit_test::const_string instance,
|
boost::optional<type_name> type, boost::unit_test::const_string name)
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name )
|
|
||||||
{
|
{
|
||||||
scoped_lock _(mutex_);
|
scoped_lock _(mutex_);
|
||||||
children_t::iterator it = children_.lower_bound(&v);
|
children_t::iterator it = children_.lower_bound(&v);
|
||||||
if( it == children_.end() ||
|
if(it == children_.end() || children_.key_comp()(&v, it->first))
|
||||||
children_.key_comp()( &v, it->first ) )
|
it = children_.insert(it, std::make_pair(&v, counter_child(parents_, p)));
|
||||||
it = children_.insert( it,
|
|
||||||
std::make_pair( &v, counter_child( parents_, p ) ) );
|
|
||||||
it->second.update(instance, type, name);
|
it->second.update(instance, type, name);
|
||||||
}
|
}
|
||||||
virtual void add(verifiable& v)
|
virtual void add(verifiable& v)
|
||||||
|
|
@ -75,23 +68,17 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map< const void*,
|
typedef std::map<const void*, std::pair<parent, std::size_t>> parents_t;
|
||||||
std::pair< parent, std::size_t > > parents_t;
|
|
||||||
|
|
||||||
class counter_child
|
class counter_child
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
counter_child(parents_t& parents, const void* p)
|
counter_child(parents_t& parents, const void* p)
|
||||||
: parents_( &parents )
|
: parents_(&parents), it_(parents.insert(std::make_pair(p, parents_t::mapped_type())).first)
|
||||||
, it_( parents.insert(
|
|
||||||
std::make_pair( p, parents_t::mapped_type() ) ).first )
|
|
||||||
{
|
{
|
||||||
++it_->second.second;
|
++it_->second.second;
|
||||||
}
|
}
|
||||||
counter_child( const counter_child& rhs )
|
counter_child(const counter_child& rhs) : parents_(rhs.parents_), it_(rhs.it_), child_(rhs.child_)
|
||||||
: parents_( rhs.parents_ )
|
|
||||||
, it_( rhs.it_ )
|
|
||||||
, child_( rhs.child_ )
|
|
||||||
{
|
{
|
||||||
++it_->second.second;
|
++it_->second.second;
|
||||||
}
|
}
|
||||||
|
|
@ -100,17 +87,12 @@ namespace detail
|
||||||
if(--it_->second.second == 0)
|
if(--it_->second.second == 0)
|
||||||
parents_->erase(it_);
|
parents_->erase(it_);
|
||||||
}
|
}
|
||||||
void update( boost::unit_test::const_string instance,
|
void update(boost::unit_test::const_string instance, boost::optional<type_name> type,
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name)
|
boost::unit_test::const_string name)
|
||||||
{
|
{
|
||||||
child_.update(it_->second.first, instance, type, name);
|
child_.update(it_->second.first, instance, type, name);
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<( std::ostream& s,
|
friend std::ostream& operator<<(std::ostream& s, const counter_child& c) { return s << c.child_; }
|
||||||
const counter_child& c )
|
|
||||||
{
|
|
||||||
return s << c.child_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
counter_child& operator=(const counter_child&);
|
counter_child& operator=(const counter_child&);
|
||||||
|
|
@ -131,7 +113,6 @@ namespace detail
|
||||||
MOCK_SINGLETON_CONS(root_t);
|
MOCK_SINGLETON_CONS(root_t);
|
||||||
};
|
};
|
||||||
MOCK_SINGLETON_INST(root)
|
MOCK_SINGLETON_INST(root)
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_ROOT_HPP_INCLUDED
|
#endif // MOCK_ROOT_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -11,21 +11,16 @@
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include "mutex.hpp"
|
#include "mutex.hpp"
|
||||||
#include <boost/noncopyable.hpp>
|
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/noncopyable.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class sequence_impl : private boost::noncopyable
|
class sequence_impl : private boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
sequence_impl()
|
sequence_impl() : mutex_(boost::make_shared<mutex>()) {}
|
||||||
: mutex_( boost::make_shared< mutex >() )
|
|
||||||
{}
|
|
||||||
|
|
||||||
void add(void* e)
|
void add(void* e)
|
||||||
{
|
{
|
||||||
|
|
@ -35,22 +30,19 @@ namespace detail
|
||||||
void remove(void* e)
|
void remove(void* e)
|
||||||
{
|
{
|
||||||
lock _(mutex_);
|
lock _(mutex_);
|
||||||
elements_.erase( std::remove( elements_.begin(),
|
elements_.erase(std::remove(elements_.begin(), elements_.end(), e), elements_.end());
|
||||||
elements_.end(), e ), elements_.end() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_valid(const void* e) const
|
bool is_valid(const void* e) const
|
||||||
{
|
{
|
||||||
lock _(mutex_);
|
lock _(mutex_);
|
||||||
return std::find( elements_.begin(), elements_.end(), e )
|
return std::find(elements_.begin(), elements_.end(), e) != elements_.end();
|
||||||
!= elements_.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void invalidate(const void* e)
|
void invalidate(const void* e)
|
||||||
{
|
{
|
||||||
lock _(mutex_);
|
lock _(mutex_);
|
||||||
elements_type::iterator it =
|
elements_type::iterator it = std::find(elements_.begin(), elements_.end(), e);
|
||||||
std::find( elements_.begin(), elements_.end(), e );
|
|
||||||
if(it != elements_.end())
|
if(it != elements_.end())
|
||||||
elements_.erase(elements_.begin(), it);
|
elements_.erase(elements_.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +53,6 @@ namespace detail
|
||||||
elements_type elements_;
|
elements_type elements_;
|
||||||
const boost::shared_ptr<mutex> mutex_;
|
const boost::shared_ptr<mutex> mutex_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
#endif // MOCK_SEQUENCE_IMPL_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,33 +10,21 @@
|
||||||
#define MOCK_SIGNATURE_HPP_INCLUDED
|
#define MOCK_SIGNATURE_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/function_types/parameter_types.hpp>
|
|
||||||
#include <boost/function_types/function_type.hpp>
|
#include <boost/function_types/function_type.hpp>
|
||||||
|
#include <boost/function_types/parameter_types.hpp>
|
||||||
#include <boost/function_types/result_type.hpp>
|
#include <boost/function_types/result_type.hpp>
|
||||||
#include <boost/mpl/single_view.hpp>
|
|
||||||
#include <boost/mpl/joint_view.hpp>
|
#include <boost/mpl/joint_view.hpp>
|
||||||
#include <boost/mpl/pop_front.hpp>
|
#include <boost/mpl/pop_front.hpp>
|
||||||
|
#include <boost/mpl/single_view.hpp>
|
||||||
#define BOOST_TYPEOF_SILENT
|
#define BOOST_TYPEOF_SILENT
|
||||||
#include <boost/typeof/typeof.hpp>
|
#include <boost/typeof/typeof.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename M>
|
template<typename M>
|
||||||
struct signature :
|
struct signature :
|
||||||
boost::function_types::function_type<
|
boost::function_types::function_type<boost::mpl::joint_view<
|
||||||
boost::mpl::joint_view<
|
boost::mpl::single_view<typename boost::function_types::result_type<M>::type>,
|
||||||
boost::mpl::single_view<
|
typename boost::mpl::pop_front<typename boost::function_types::parameter_types<M>>::type>>
|
||||||
typename
|
|
||||||
boost::function_types::result_type< M >::type
|
|
||||||
>,
|
|
||||||
typename boost::mpl::pop_front<
|
|
||||||
typename
|
|
||||||
boost::function_types::parameter_types< M >
|
|
||||||
>::type
|
|
||||||
>
|
|
||||||
>
|
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -50,14 +38,10 @@ namespace detail
|
||||||
// disambiguate
|
// disambiguate
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& ambiguous_method_requires_to_specify_signature(const T&);
|
T& ambiguous_method_requires_to_specify_signature(const T&);
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#define MOCK_SIGNATURE(M) \
|
#define MOCK_SIGNATURE(M) \
|
||||||
mock::detail::signature< \
|
mock::detail::signature<BOOST_TYPEOF( \
|
||||||
BOOST_TYPEOF( \
|
mock::detail::ambiguous_method_requires_to_specify_signature(&base_type::M))>::type
|
||||||
mock::detail::ambiguous_method_requires_to_specify_signature( \
|
|
||||||
&base_type::M ) ) \
|
|
||||||
>::type
|
|
||||||
|
|
||||||
#endif // MOCK_SIGNATURE_HPP_INCLUDED
|
#endif // MOCK_SIGNATURE_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
namespace mock {
|
namespace mock { namespace detail {
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
class singleton {
|
class singleton
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
static Derived& instance()
|
static Derived& instance()
|
||||||
{
|
{
|
||||||
|
|
@ -31,8 +31,7 @@ protected:
|
||||||
BOOST_DEFAULTED_FUNCTION(~singleton(), {})
|
BOOST_DEFAULTED_FUNCTION(~singleton(), {})
|
||||||
};
|
};
|
||||||
|
|
||||||
} // detail
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
// Add a private ctor to the type to prevent misuse
|
// Add a private ctor to the type to prevent misuse
|
||||||
#define MOCK_SINGLETON_CONS(type) \
|
#define MOCK_SINGLETON_CONS(type) \
|
||||||
|
|
@ -40,7 +39,6 @@ private: \
|
||||||
friend class mock::detail::singleton<type>; \
|
friend class mock::detail::singleton<type>; \
|
||||||
type() {}
|
type() {}
|
||||||
|
|
||||||
#define MOCK_SINGLETON_INST( inst ) \
|
#define MOCK_SINGLETON_INST(inst) static BOOST_JOIN(inst, _t)& inst = BOOST_JOIN(inst, _t)::instance();
|
||||||
static BOOST_JOIN( inst, _t )& inst = BOOST_JOIN( inst, _t )::instance();
|
|
||||||
|
|
||||||
#endif // MOCK_SINGLETON_HPP
|
#endif // MOCK_SINGLETON_HPP
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@
|
||||||
#define MOCK_TYPE_NAME_HPP_INCLUDED
|
#define MOCK_TYPE_NAME_HPP_INCLUDED
|
||||||
|
|
||||||
#include "../config.hpp"
|
#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/erase.hpp>
|
||||||
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
#include <boost/test/utils/basic_cstring/io.hpp>
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
#if BOOST_VERSION >= 107000
|
#if BOOST_VERSION >= 107000
|
||||||
# include <boost/core/typeinfo.hpp>
|
# include <boost/core/typeinfo.hpp>
|
||||||
|
|
@ -25,41 +25,34 @@
|
||||||
# define MOCK_TYPEINFO boost::detail::sp_typeinfo
|
# define MOCK_TYPEINFO boost::detail::sp_typeinfo
|
||||||
#endif
|
#endif
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <ostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <ostream>
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#include <cxxabi.h>
|
|
||||||
# include <cstdlib>
|
# include <cstdlib>
|
||||||
|
# include <cxxabi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MOCK_TYPE_NAME(t) mock::detail::type_name(MOCK_TYPEID(t))
|
#define MOCK_TYPE_NAME(t) mock::detail::type_name(MOCK_TYPEID(t))
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class type_name
|
class type_name
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit type_name( const MOCK_TYPEINFO& info )
|
explicit type_name(const MOCK_TYPEINFO& info) : info_(&info) {}
|
||||||
: info_( &info )
|
|
||||||
{}
|
|
||||||
friend std::ostream& operator<<(std::ostream& s, const type_name& t)
|
friend std::ostream& operator<<(std::ostream& s, const type_name& t)
|
||||||
{
|
{
|
||||||
t.serialize(s, *t.info_);
|
t.serialize(s, *t.info_);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void serialize( std::ostream& s,
|
void serialize(std::ostream& s, const MOCK_TYPEINFO& info) const
|
||||||
const MOCK_TYPEINFO& info ) const
|
|
||||||
{
|
{
|
||||||
const char* name = info.name();
|
const char* name = info.name();
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
int status = 0;
|
int status = 0;
|
||||||
boost::shared_ptr< char > demangled(
|
boost::shared_ptr<char> demangled(abi::__cxa_demangle(name, 0, 0, &status), &std::free);
|
||||||
abi::__cxa_demangle( name, 0, 0, &status ),
|
|
||||||
&std::free );
|
|
||||||
if(!status && demangled)
|
if(!status && demangled)
|
||||||
serialize(s, demangled.get());
|
serialize(s, demangled.get());
|
||||||
else
|
else
|
||||||
|
|
@ -119,7 +112,6 @@ namespace detail
|
||||||
|
|
||||||
const MOCK_TYPEINFO* info_;
|
const MOCK_TYPEINFO* info_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_TYPE_NAME_HPP_INCLUDED
|
#endif // MOCK_TYPE_NAME_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,7 @@
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
class verifiable : private boost::noncopyable
|
class verifiable : private boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -26,7 +23,6 @@ namespace detail
|
||||||
|
|
||||||
virtual void reset() = 0;
|
virtual void reset() = 0;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_VERIFIABLE_HPP_INCLUDED
|
#endif // MOCK_VERIFIABLE_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -12,33 +12,29 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#ifdef MOCK_USE_BOOST_TEST
|
#ifdef MOCK_USE_BOOST_TEST
|
||||||
# include "exception.hpp"
|
# include "exception.hpp"
|
||||||
#include <boost/version.hpp>
|
# include <boost/exception/enable_current_exception.hpp>
|
||||||
# include <boost/test/framework.hpp>
|
# include <boost/test/framework.hpp>
|
||||||
# include <boost/test/test_tools.hpp>
|
# include <boost/test/test_tools.hpp>
|
||||||
# include <boost/test/unit_test_suite.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>
|
template<typename Result>
|
||||||
struct error
|
struct error
|
||||||
{
|
{
|
||||||
static Result abort()
|
static Result abort()
|
||||||
{
|
{
|
||||||
boost::unit_test::framework::test_unit_aborted(
|
boost::unit_test::framework::test_unit_aborted(boost::unit_test::framework::current_test_case());
|
||||||
boost::unit_test::framework::current_test_case() );
|
|
||||||
throw boost::enable_current_exception(exception());
|
throw boost::enable_current_exception(exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pass(const char* file, int line)
|
static void pass(const char* file, int line)
|
||||||
{
|
{
|
||||||
boost::unit_test::unit_test_log.set_checkpoint( file,
|
boost::unit_test::unit_test_log.set_checkpoint(file, static_cast<std::size_t>(line));
|
||||||
static_cast< std::size_t >( line ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Context>
|
template<typename Context>
|
||||||
static void fail( const char* message, const Context& context,
|
static void fail(const char* message, const Context& context, const char* file = "unknown location", int line = 0)
|
||||||
const char* file = "unknown location", int line = 0 )
|
|
||||||
{
|
{
|
||||||
boost::unit_test::framework::assertion_result(
|
boost::unit_test::framework::assertion_result(
|
||||||
# if BOOST_VERSION < 105900
|
# if BOOST_VERSION < 105900
|
||||||
|
|
@ -47,11 +43,8 @@ namespace mock
|
||||||
boost::unit_test::AR_FAILED
|
boost::unit_test::AR_FAILED
|
||||||
# endif
|
# endif
|
||||||
);
|
);
|
||||||
boost::unit_test::unit_test_log
|
boost::unit_test::unit_test_log << boost::unit_test::log::begin(file, static_cast<std::size_t>(line))
|
||||||
<< boost::unit_test::log::begin( file,
|
<< boost::unit_test::log_all_errors << message << ": " << context
|
||||||
static_cast< std::size_t >( line ) )
|
|
||||||
<< boost::unit_test::log_all_errors
|
|
||||||
<< message << ": " << context
|
|
||||||
<< boost::unit_test::log::end();
|
<< boost::unit_test::log::end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,15 +58,12 @@ namespace mock
|
||||||
boost::unit_test::AR_PASSED
|
boost::unit_test::AR_PASSED
|
||||||
# endif
|
# endif
|
||||||
);
|
);
|
||||||
boost::unit_test::unit_test_log
|
boost::unit_test::unit_test_log << boost::unit_test::log::begin(file, static_cast<std::size_t>(line))
|
||||||
<< boost::unit_test::log::begin( file,
|
|
||||||
static_cast< std::size_t >( line ) )
|
|
||||||
<< boost::unit_test::log_successful_tests
|
<< boost::unit_test::log_successful_tests
|
||||||
<< "mock expectation fulfilled: " << context
|
<< "mock expectation fulfilled: " << context << boost::unit_test::log::end();
|
||||||
<< boost::unit_test::log::end();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_USE_BOOST_TEST
|
#endif // MOCK_USE_BOOST_TEST
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,10 @@
|
||||||
#ifdef MOCK_USE_BOOST_TEST
|
#ifdef MOCK_USE_BOOST_TEST
|
||||||
# include <boost/test/execution_monitor.hpp>
|
# include <boost/test/execution_monitor.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
struct exception : virtual boost::execution_aborted
|
struct exception : virtual boost::execution_aborted
|
||||||
{};
|
{};
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_USE_BOOST_TEST
|
#endif // MOCK_USE_BOOST_TEST
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,13 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "detail/formatter.hpp"
|
#include "detail/formatter.hpp"
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
detail::formatter<T> format(const T& t)
|
detail::formatter<T> format(const T& t)
|
||||||
{
|
{
|
||||||
return detail::formatter<T>(t);
|
return detail::formatter<T>(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_FORMAT_HPP_INCLUDED
|
#endif // MOCK_FORMAT_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,39 +10,40 @@
|
||||||
#define MOCK_LOG_HPP_INCLUDED
|
#define MOCK_LOG_HPP_INCLUDED
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "stream.hpp"
|
|
||||||
#include "format.hpp"
|
#include "format.hpp"
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include "stream.hpp"
|
||||||
#include <boost/detail/container_fwd.hpp>
|
#include <boost/detail/container_fwd.hpp>
|
||||||
#include <boost/function_types/is_callable_builtin.hpp>
|
#include <boost/function_types/is_callable_builtin.hpp>
|
||||||
#include <boost/none.hpp>
|
#include <boost/none.hpp>
|
||||||
|
#include <boost/utility/enable_if.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace boost
|
namespace boost {
|
||||||
{
|
template<typename T>
|
||||||
template< typename T > class shared_ptr;
|
class shared_ptr;
|
||||||
template< typename T > class weak_ptr;
|
template<typename T>
|
||||||
template< typename T > class reference_wrapper;
|
class weak_ptr;
|
||||||
template< typename T > class optional;
|
template<typename T>
|
||||||
|
class reference_wrapper;
|
||||||
|
template<typename T>
|
||||||
|
class optional;
|
||||||
|
|
||||||
namespace phoenix
|
namespace phoenix {
|
||||||
{
|
template<typename T>
|
||||||
template< typename T > struct actor;
|
struct actor;
|
||||||
}
|
}
|
||||||
namespace lambda
|
namespace lambda {
|
||||||
{
|
template<typename T>
|
||||||
template< typename T > class lambda_functor;
|
class lambda_functor;
|
||||||
}
|
|
||||||
namespace assign_detail
|
|
||||||
{
|
|
||||||
template< typename T > class generic_list;
|
|
||||||
}
|
}
|
||||||
|
namespace assign_detail {
|
||||||
|
template<typename T>
|
||||||
|
class generic_list;
|
||||||
}
|
}
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
namespace detail {
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void serialize(stream& s, const T& begin, const T& end)
|
void serialize(stream& s, const T& begin, const T& end)
|
||||||
{
|
{
|
||||||
|
|
@ -51,7 +52,7 @@ namespace detail
|
||||||
s << (it == begin ? "" : ",") << mock::format(*it);
|
s << (it == begin ? "" : ",") << mock::format(*it);
|
||||||
s << ')';
|
s << ')';
|
||||||
}
|
}
|
||||||
}
|
} // namespace detail
|
||||||
|
|
||||||
#ifdef MOCK_AUTO_PTR
|
#ifdef MOCK_AUTO_PTR
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -64,8 +65,7 @@ namespace detail
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
stream& operator<<(stream& s, const std::pair<T1, T2>& p)
|
stream& operator<<(stream& s, const std::pair<T1, T2>& p)
|
||||||
{
|
{
|
||||||
return s << '(' << mock::format( p.first )
|
return s << '(' << mock::format(p.first) << ',' << mock::format(p.second) << ')';
|
||||||
<< ',' << mock::format( p.second ) << ')';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename A>
|
template<typename T, typename A>
|
||||||
|
|
@ -111,8 +111,7 @@ namespace detail
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
stream& operator<<( stream& s,
|
stream& operator<<(stream& s, const boost::assign_detail::generic_list<T>& t)
|
||||||
const boost::assign_detail::generic_list< T >& t )
|
|
||||||
{
|
{
|
||||||
detail::serialize(s, t.begin(), t.end());
|
detail::serialize(s, t.begin(), t.end());
|
||||||
return s;
|
return s;
|
||||||
|
|
@ -181,24 +180,16 @@ namespace detail
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename boost::enable_if<
|
typename boost::enable_if<boost::function_types::is_callable_builtin<T>, stream&>::type operator<<(stream& s, T*)
|
||||||
boost::function_types::is_callable_builtin< T >,
|
|
||||||
stream&
|
|
||||||
>::type
|
|
||||||
operator<<( stream& s, T* )
|
|
||||||
{
|
{
|
||||||
return s << '?';
|
return s << '?';
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename boost::disable_if<
|
typename boost::disable_if<boost::function_types::is_callable_builtin<T>, stream&>::type operator<<(stream& s, T* t)
|
||||||
boost::function_types::is_callable_builtin< T >,
|
|
||||||
stream&
|
|
||||||
>::type
|
|
||||||
operator<<( stream& s, T* t )
|
|
||||||
{
|
{
|
||||||
*s.s_ << t;
|
*s.s_ << t;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_LOG_HPP_INCLUDED
|
#endif // MOCK_LOG_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,34 +10,27 @@
|
||||||
#define MOCK_MATCHER_HPP_INCLUDED
|
#define MOCK_MATCHER_HPP_INCLUDED
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "log.hpp"
|
|
||||||
#include "constraints.hpp"
|
#include "constraints.hpp"
|
||||||
#include "detail/is_functor.hpp"
|
#include "detail/is_functor.hpp"
|
||||||
#include "detail/move_helper.hpp"
|
#include "detail/move_helper.hpp"
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include "log.hpp"
|
||||||
#include <boost/type_traits/add_reference.hpp>
|
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
|
#include <boost/type_traits/add_reference.hpp>
|
||||||
|
#include <boost/utility/enable_if.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
template<typename Actual, typename Expected, typename Enable = void>
|
template<typename Actual, typename Expected, typename Enable = void>
|
||||||
class matcher
|
class matcher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit matcher( Expected expected )
|
explicit matcher(Expected expected) : expected_(expected) {}
|
||||||
: expected_( expected )
|
|
||||||
{}
|
|
||||||
bool operator()(typename boost::add_reference<const Actual>::type actual)
|
bool operator()(typename boost::add_reference<const Actual>::type actual)
|
||||||
{
|
{
|
||||||
return mock::equal(
|
return mock::equal(boost::unwrap_ref(expected_)).c_(actual);
|
||||||
boost::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:
|
private:
|
||||||
Expected expected_;
|
Expected expected_;
|
||||||
};
|
};
|
||||||
|
|
@ -46,18 +39,10 @@ namespace mock
|
||||||
class matcher<const char*, const char*>
|
class matcher<const char*, const char*>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit matcher( const char* expected )
|
explicit matcher(const char* expected) : expected_(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_); }
|
||||||
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:
|
private:
|
||||||
const char* expected_;
|
const char* expected_;
|
||||||
};
|
};
|
||||||
|
|
@ -66,45 +51,31 @@ namespace mock
|
||||||
class matcher<Actual, mock::constraint<Constraint>>
|
class matcher<Actual, mock::constraint<Constraint>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit matcher( const constraint< Constraint >& c )
|
explicit matcher(const constraint<Constraint>& c) : c_(c.c_) {}
|
||||||
: c_( c.c_ )
|
|
||||||
{}
|
|
||||||
bool operator()(typename detail::ref_arg<Actual>::type actual)
|
bool operator()(typename detail::ref_arg<Actual>::type actual)
|
||||||
{
|
{
|
||||||
return c_(mock::detail::move_if_not_lvalue_reference<typename detail::ref_arg<Actual>::type>(actual));
|
return c_(mock::detail::move_if_not_lvalue_reference<typename detail::ref_arg<Actual>::type>(actual));
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<(
|
friend std::ostream& operator<<(std::ostream& s, const matcher& m) { return s << mock::format(m.c_); }
|
||||||
std::ostream& s, const matcher& m )
|
|
||||||
{
|
|
||||||
return s << mock::format( m.c_ );
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
Constraint c_;
|
Constraint c_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Actual, typename Functor>
|
template<typename Actual, typename Functor>
|
||||||
class matcher< Actual, Functor,
|
class matcher<Actual, Functor, typename boost::enable_if<detail::is_functor<Functor, Actual>>::type>
|
||||||
typename boost::enable_if<
|
|
||||||
detail::is_functor< Functor, Actual >
|
|
||||||
>::type
|
|
||||||
>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit matcher( const Functor& f )
|
explicit matcher(const Functor& f) : c_(f) {}
|
||||||
: c_( f )
|
|
||||||
{}
|
|
||||||
bool operator()(typename detail::ref_arg<Actual>::type actual)
|
bool operator()(typename detail::ref_arg<Actual>::type actual)
|
||||||
{
|
{
|
||||||
return c_(mock::detail::move_if_not_lvalue_reference<typename detail::ref_arg<Actual>::type>(actual));
|
return c_(mock::detail::move_if_not_lvalue_reference<typename detail::ref_arg<Actual>::type>(actual));
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<(
|
friend std::ostream& operator<<(std::ostream& s, const matcher& m) { return s << mock::format(m.c_); }
|
||||||
std::ostream& s, const matcher& m )
|
|
||||||
{
|
|
||||||
return s << mock::format( m.c_ );
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
Functor c_;
|
Functor c_;
|
||||||
};
|
};
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_MATCHER_HPP_INCLUDED
|
#endif // MOCK_MATCHER_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -9,93 +9,68 @@
|
||||||
#ifndef MOCK_MOCK_HPP_INCLUDED
|
#ifndef MOCK_MOCK_HPP_INCLUDED
|
||||||
#define MOCK_MOCK_HPP_INCLUDED
|
#define MOCK_MOCK_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "cleanup.hpp"
|
||||||
#include "config.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 "object.hpp"
|
||||||
#include "reset.hpp"
|
#include "reset.hpp"
|
||||||
#include "verify.hpp"
|
#include "verify.hpp"
|
||||||
#include "cleanup.hpp"
|
#include <boost/mpl/assert.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/repetition/repeat.hpp>
|
||||||
#include <boost/preprocessor/stringize.hpp>
|
#include <boost/preprocessor/stringize.hpp>
|
||||||
#include <boost/utility/identity_type.hpp>
|
#include <boost/utility/identity_type.hpp>
|
||||||
#include <boost/mpl/assert.hpp>
|
|
||||||
|
|
||||||
#define MOCK_CLASS(T) \
|
#define MOCK_CLASS(T) struct T : mock::object
|
||||||
struct T : mock::object
|
|
||||||
|
|
||||||
#define MOCK_FUNCTION_TYPE(S, tpn) \
|
#define MOCK_FUNCTION_TYPE(S, tpn) tpn boost::remove_pointer<tpn BOOST_IDENTITY_TYPE(S)>::type
|
||||||
tpn boost::remove_pointer< tpn BOOST_IDENTITY_TYPE(S) >::type
|
|
||||||
|
|
||||||
#ifdef MOCK_VARIADIC_MACROS
|
#ifdef MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
#define MOCK_BASE_CLASS(T, ...) \
|
# define MOCK_BASE_CLASS(T, ...) struct T : __VA_ARGS__, mock::object, mock::detail::base<__VA_ARGS__>
|
||||||
struct T : __VA_ARGS__, mock::object, mock::detail::base< __VA_ARGS__ >
|
|
||||||
|
|
||||||
#define MOCK_FUNCTOR(f, ...) \
|
# define MOCK_FUNCTOR(f, ...) mock::detail::functor<MOCK_FUNCTION_TYPE((__VA_ARGS__), )> f, f##_mock
|
||||||
mock::detail::functor< MOCK_FUNCTION_TYPE((__VA_ARGS__),) > f, f##_mock
|
# define MOCK_FUNCTOR_TPL(f, ...) mock::detail::functor<MOCK_FUNCTION_TYPE((__VA_ARGS__), typename)> f, f##_mock
|
||||||
#define MOCK_FUNCTOR_TPL(f, ...) \
|
|
||||||
mock::detail::functor< \
|
|
||||||
MOCK_FUNCTION_TYPE((__VA_ARGS__), typename) > f, f##_mock
|
|
||||||
|
|
||||||
#else // MOCK_VARIADIC_MACROS
|
#else // MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
#define MOCK_BASE_CLASS(T, I) \
|
# define MOCK_BASE_CLASS(T, I) struct T : I, mock::object, mock::detail::base<I>
|
||||||
struct T : I, mock::object, mock::detail::base< I >
|
|
||||||
|
|
||||||
#define MOCK_FUNCTOR(f, S) \
|
# define MOCK_FUNCTOR(f, S) mock::detail::functor<MOCK_FUNCTION_TYPE((S), )> f, f##_mock
|
||||||
mock::detail::functor< MOCK_FUNCTION_TYPE((S),) > f, f##_mock
|
# define MOCK_FUNCTOR_TPL(f, S) mock::detail::functor<MOCK_FUNCTION_TYPE((S), typename)> f, f##_mock
|
||||||
#define MOCK_FUNCTOR_TPL(f, S) \
|
|
||||||
mock::detail::functor< \
|
|
||||||
MOCK_FUNCTION_TYPE((S), typename) > f, f##_mock
|
|
||||||
|
|
||||||
#endif // MOCK_VARIADIC_MACROS
|
#endif // MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
#define MOCK_HELPER(t) \
|
#define MOCK_HELPER(t) t##_mock(mock::detail::root, BOOST_PP_STRINGIZE(t))
|
||||||
t##_mock( mock::detail::root, BOOST_PP_STRINGIZE(t) )
|
#define MOCK_ANONYMOUS_HELPER(t) t##_mock(mock::detail::root, "?.")
|
||||||
#define MOCK_ANONYMOUS_HELPER(t) \
|
|
||||||
t##_mock( mock::detail::root, "?." )
|
|
||||||
|
|
||||||
#define MOCK_METHOD_HELPER(S, t, tpn) \
|
#define MOCK_METHOD_HELPER(S, t, tpn) \
|
||||||
mutable mock::detail::function<MOCK_FUNCTION_TYPE((S), tpn)> t##_mock_; \
|
mutable mock::detail::function<MOCK_FUNCTION_TYPE((S), tpn)> t##_mock_; \
|
||||||
mock::detail::function<MOCK_FUNCTION_TYPE((S), tpn)>& t##_mock( \
|
mock::detail::function<MOCK_FUNCTION_TYPE((S), tpn)>& t##_mock( \
|
||||||
const mock::detail::context&, \
|
const mock::detail::context&, const boost::unit_test::const_string& instance) const \
|
||||||
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))), \
|
||||||
instance.substr( 0, instance.rfind( BOOST_PP_STRINGIZE(t) ) ), \
|
MOCK_TYPE_NAME(*this), BOOST_PP_STRINGIZE(t)); \
|
||||||
MOCK_TYPE_NAME(*this), \
|
|
||||||
BOOST_PP_STRINGIZE(t) ); \
|
|
||||||
return t##_mock_; \
|
return t##_mock_; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MOCK_PARAM(S, tpn) \
|
#define MOCK_PARAM(S, tpn) tpn mock::detail::parameter < MOCK_FUNCTION_TYPE((S), tpn)
|
||||||
tpn mock::detail::parameter< MOCK_FUNCTION_TYPE((S), tpn)
|
#define MOCK_DECL_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > ::type p##n
|
||||||
#define MOCK_DECL_PARAM(z, n, d) \
|
#define MOCK_DECL_PARAMS(n, S, tpn) BOOST_PP_REPEAT(n, MOCK_DECL_PARAM, MOCK_PARAM(S, tpn))
|
||||||
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) \
|
#define MOCK_DECL(M, n, S, c, tpn) \
|
||||||
tpn boost::function_types::result_type< \
|
tpn boost::function_types::result_type<MOCK_FUNCTION_TYPE((S), tpn)>::type M(MOCK_DECL_PARAMS(n, S, tpn)) c
|
||||||
MOCK_FUNCTION_TYPE((S), tpn) >::type M( \
|
|
||||||
MOCK_DECL_PARAMS(n, S, tpn) ) c
|
|
||||||
|
|
||||||
#define MOCK_FORWARD_PARAM(z, n, d) \
|
#define MOCK_FORWARD_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > ::type > (p##n)
|
||||||
BOOST_PP_COMMA_IF(n) d, n >::type >( p##n )
|
|
||||||
#define MOCK_FORWARD_PARAMS(n, S, tpn) \
|
#define MOCK_FORWARD_PARAMS(n, S, tpn) \
|
||||||
BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, \
|
BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, mock::detail::move_if_not_lvalue_reference < MOCK_PARAM(S, tpn))
|
||||||
mock::detail::move_if_not_lvalue_reference< MOCK_PARAM(S, tpn))
|
|
||||||
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
|
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
|
||||||
MOCK_DECL(M, n, S, c, tpn) \
|
MOCK_DECL(M, n, S, c, tpn) \
|
||||||
{ \
|
{ \
|
||||||
BOOST_MPL_ASSERT_RELATION( n, ==, \
|
BOOST_MPL_ASSERT_RELATION(n, ==, boost::function_types::function_arity<MOCK_FUNCTION_TYPE((S), tpn)>::value); \
|
||||||
boost::function_types::function_arity< \
|
return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S, tpn)); \
|
||||||
MOCK_FUNCTION_TYPE((S), tpn) >::value ); \
|
|
||||||
return MOCK_ANONYMOUS_HELPER(t)( \
|
|
||||||
MOCK_FORWARD_PARAMS(n, S, tpn) ); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MOCK_METHOD_EXT(M, n, S, t) \
|
#define MOCK_METHOD_EXT(M, n, S, t) \
|
||||||
|
|
@ -143,8 +118,7 @@
|
||||||
MOCK_METHOD_HELPER(T(), t, typename)
|
MOCK_METHOD_HELPER(T(), t, typename)
|
||||||
|
|
||||||
#define MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
#define MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
||||||
s mock::detail::function< MOCK_FUNCTION_TYPE((S), tpn) >& t##_mock( \
|
s mock::detail::function<MOCK_FUNCTION_TYPE((S), tpn)>& t##_mock(mock::detail::context& context, \
|
||||||
mock::detail::context& context, \
|
|
||||||
boost::unit_test::const_string instance) \
|
boost::unit_test::const_string instance) \
|
||||||
{ \
|
{ \
|
||||||
static mock::detail::function<MOCK_FUNCTION_TYPE((S), tpn)> f; \
|
static mock::detail::function<MOCK_FUNCTION_TYPE((S), tpn)> f; \
|
||||||
|
|
@ -152,28 +126,28 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t, tpn) \
|
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t, tpn) \
|
||||||
T( MOCK_DECL_PARAMS(n, void A, tpn) ) \
|
T(MOCK_DECL_PARAMS(n, void A, tpn)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A, tpn)); } \
|
||||||
{ \
|
|
||||||
MOCK_HELPER(t)( MOCK_FORWARD_PARAMS(n, void A, tpn) ); \
|
|
||||||
} \
|
|
||||||
MOCK_FUNCTION_HELPER(void A, t, static, tpn)
|
MOCK_FUNCTION_HELPER(void A, t, static, tpn)
|
||||||
|
|
||||||
#define MOCK_CONSTRUCTOR(T, n, A, t) \
|
#define MOCK_CONSTRUCTOR(T, n, A, t) MOCK_CONSTRUCTOR_AUX(T, n, A, t, )
|
||||||
MOCK_CONSTRUCTOR_AUX(T, n, A, t,)
|
#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)
|
|
||||||
|
|
||||||
#define MOCK_DESTRUCTOR(T, t) \
|
#define MOCK_DESTRUCTOR(T, t) \
|
||||||
T() { try { MOCK_ANONYMOUS_HELPER(t)(); } catch( ... ) {} } \
|
T() \
|
||||||
|
{ \
|
||||||
|
try \
|
||||||
|
{ \
|
||||||
|
MOCK_ANONYMOUS_HELPER(t)(); \
|
||||||
|
} catch(...) \
|
||||||
|
{} \
|
||||||
|
} \
|
||||||
MOCK_METHOD_HELPER(void(), t, )
|
MOCK_METHOD_HELPER(void(), t, )
|
||||||
|
|
||||||
#define MOCK_FUNCTION_AUX(F, n, S, t, s, tpn) \
|
#define MOCK_FUNCTION_AUX(F, n, S, t, s, tpn) \
|
||||||
MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
MOCK_FUNCTION_HELPER(S, t, s, tpn) \
|
||||||
s MOCK_DECL(F, n, S, , tpn) \
|
s MOCK_DECL(F, n, S, , tpn) \
|
||||||
{ \
|
{ \
|
||||||
BOOST_MPL_ASSERT_RELATION( n, ==, \
|
BOOST_MPL_ASSERT_RELATION(n, ==, boost::function_types::function_arity<MOCK_FUNCTION_TYPE((S), tpn)>::value); \
|
||||||
boost::function_types::function_arity< \
|
|
||||||
MOCK_FUNCTION_TYPE((S), tpn) >::value ); \
|
|
||||||
return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S, tpn)); \
|
return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S, tpn)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,65 +158,44 @@
|
||||||
# define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2
|
# define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2
|
||||||
|
|
||||||
# define MOCK_METHOD(M, ...) \
|
# define MOCK_METHOD(M, ...) \
|
||||||
MOCK_METHOD_EXT(M, \
|
MOCK_METHOD_EXT(M, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
|
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
|
||||||
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
|
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
|
||||||
# define MOCK_CONST_METHOD(M, ...) \
|
# define MOCK_CONST_METHOD(M, ...) \
|
||||||
MOCK_CONST_METHOD_EXT(M, \
|
MOCK_CONST_METHOD_EXT(M, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
|
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
|
||||||
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
|
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
|
||||||
# define MOCK_NON_CONST_METHOD(M, ...) \
|
# define MOCK_NON_CONST_METHOD(M, ...) \
|
||||||
MOCK_NON_CONST_METHOD_EXT(M, \
|
MOCK_NON_CONST_METHOD_EXT(M, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
||||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
|
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M), ), \
|
||||||
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
|
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M, ))
|
||||||
|
|
||||||
# define MOCK_METHOD_TPL(M, n, ...) \
|
# define MOCK_METHOD_TPL(M, n, ...) \
|
||||||
MOCK_METHOD_EXT_TPL(M, n, \
|
MOCK_METHOD_EXT_TPL(M, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
||||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
|
||||||
# define MOCK_CONST_METHOD_TPL(M, n, ...) \
|
# define MOCK_CONST_METHOD_TPL(M, n, ...) \
|
||||||
MOCK_CONST_METHOD_EXT_TPL(M, n, \
|
MOCK_CONST_METHOD_EXT_TPL(M, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
||||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
|
||||||
# define MOCK_NON_CONST_METHOD_TPL(M, n, ...) \
|
# define MOCK_NON_CONST_METHOD_TPL(M, n, ...) \
|
||||||
MOCK_NON_CONST_METHOD_EXT_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_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, M, ))
|
|
||||||
|
|
||||||
# define MOCK_FUNCTION(F, n, ...) \
|
# define MOCK_FUNCTION(F, n, ...) \
|
||||||
MOCK_FUNCTION_AUX(F, n, \
|
MOCK_FUNCTION_AUX(F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), inline, )
|
||||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), \
|
|
||||||
inline,)
|
|
||||||
|
|
||||||
# define MOCK_STATIC_METHOD(F, n, ...) \
|
# define MOCK_STATIC_METHOD(F, n, ...) \
|
||||||
MOCK_FUNCTION_AUX(F, n, \
|
MOCK_FUNCTION_AUX(F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static, )
|
||||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), \
|
|
||||||
static,)
|
|
||||||
|
|
||||||
# define MOCK_STATIC_METHOD_TPL(F, n, ...) \
|
# define MOCK_STATIC_METHOD_TPL(F, n, ...) \
|
||||||
MOCK_FUNCTION_AUX(F, n, \
|
MOCK_FUNCTION_AUX(F, n, MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), static, \
|
||||||
MOCK_VARIADIC_ELEM_0(__VA_ARGS__, ), \
|
typename)
|
||||||
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, F, ), \
|
|
||||||
static, typename)
|
|
||||||
|
|
||||||
#else // MOCK_VARIADIC_MACROS
|
#else // MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
#define MOCK_METHOD(M, n) \
|
# define MOCK_METHOD(M, n) MOCK_METHOD_EXT(M, n, MOCK_SIGNATURE(M), M)
|
||||||
MOCK_METHOD_EXT(M, n, MOCK_SIGNATURE(M), M)
|
|
||||||
|
|
||||||
#define MOCK_FUNCTION(F, n, S, t) \
|
# define MOCK_FUNCTION(F, n, S, t) MOCK_FUNCTION_AUX(F, n, S, t, inline, )
|
||||||
MOCK_FUNCTION_AUX(F, n, S, t, inline,)
|
|
||||||
|
|
||||||
#define MOCK_STATIC_METHOD(F, n, S, t) \
|
# define MOCK_STATIC_METHOD(F, n, S, t) MOCK_FUNCTION_AUX(F, n, S, t, static, )
|
||||||
MOCK_FUNCTION_AUX(F, n, S, t, static,)
|
|
||||||
|
|
||||||
#define MOCK_STATIC_METHOD_TPL(F, n, S, t) \
|
# define MOCK_STATIC_METHOD_TPL(F, n, S, t) MOCK_FUNCTION_AUX(F, n, S, t, static, typename)
|
||||||
MOCK_FUNCTION_AUX(F, n, S, t, static, typename)
|
|
||||||
|
|
||||||
#endif // MOCK_VARIADIC_MACROS
|
#endif // MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,65 +10,53 @@
|
||||||
#define MOCK_OBJECT_HPP_INCLUDED
|
#define MOCK_OBJECT_HPP_INCLUDED
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
#include "detail/object_impl.hpp"
|
||||||
#include "detail/root.hpp"
|
#include "detail/root.hpp"
|
||||||
#include "detail/type_name.hpp"
|
#include "detail/type_name.hpp"
|
||||||
#include "detail/object_impl.hpp"
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||||
#include <boost/type_traits/is_base_of.hpp>
|
#include <boost/type_traits/is_base_of.hpp>
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include <boost/utility/enable_if.hpp>
|
||||||
#include <boost/make_shared.hpp>
|
|
||||||
#include <boost/optional.hpp>
|
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
class object;
|
class object;
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
template<typename E>
|
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 instance,
|
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name);
|
boost::unit_test::const_string name);
|
||||||
|
|
||||||
template<typename T, typename E>
|
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 instance,
|
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name,
|
boost::unit_test::const_string name,
|
||||||
typename boost::disable_if<
|
typename boost::disable_if<typename boost::is_base_of<object, T>>::type* = 0)
|
||||||
typename boost::is_base_of< object, T >
|
|
||||||
>::type* = 0 )
|
|
||||||
{
|
{
|
||||||
e.configure(detail::root, &t, instance, type, name);
|
e.configure(detail::root, &t, instance, type, name);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
} // namespace detail
|
||||||
class object
|
class object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
object()
|
object() : impl_(boost::make_shared<detail::object_impl>()) {}
|
||||||
: impl_( boost::make_shared< detail::object_impl >() )
|
|
||||||
{}
|
|
||||||
protected:
|
protected:
|
||||||
~object()
|
~object() {}
|
||||||
{}
|
|
||||||
public:
|
public:
|
||||||
boost::shared_ptr<detail::object_impl> impl_;
|
boost::shared_ptr<detail::object_impl> impl_;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
template<typename E>
|
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 instance,
|
|
||||||
boost::optional< type_name > type,
|
|
||||||
boost::unit_test::const_string name)
|
boost::unit_test::const_string name)
|
||||||
{
|
{
|
||||||
e.configure(*o.impl_, o.impl_.get(), instance, type, name);
|
e.configure(*o.impl_, o.impl_.get(), instance, type, name);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
} // namespace detail
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_OBJECT_HPP_INCLUDED
|
#endif // MOCK_OBJECT_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,11 @@
|
||||||
#define MOCK_RESET_HPP_INCLUDED
|
#define MOCK_RESET_HPP_INCLUDED
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "object.hpp"
|
|
||||||
#include "detail/root.hpp"
|
|
||||||
#include "detail/functor.hpp"
|
#include "detail/functor.hpp"
|
||||||
|
#include "detail/root.hpp"
|
||||||
|
#include "object.hpp"
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
inline void reset()
|
inline void reset()
|
||||||
{
|
{
|
||||||
detail::root.reset();
|
detail::root.reset();
|
||||||
|
|
@ -29,6 +28,6 @@ namespace mock
|
||||||
{
|
{
|
||||||
f.reset();
|
f.reset();
|
||||||
}
|
}
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_RESET_HPP_INCLUDED
|
#endif // MOCK_RESET_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,14 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "detail/sequence_impl.hpp"
|
#include "detail/sequence_impl.hpp"
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
class sequence
|
class sequence
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
sequence()
|
sequence() : impl_(boost::make_shared<detail::sequence_impl>()) {}
|
||||||
: impl_( boost::make_shared< detail::sequence_impl >() )
|
|
||||||
{}
|
|
||||||
|
|
||||||
boost::shared_ptr<detail::sequence_impl> impl_;
|
boost::shared_ptr<detail::sequence_impl> impl_;
|
||||||
};
|
};
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_SEQUENCE_HPP_INCLUDED
|
#endif // MOCK_SEQUENCE_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -13,22 +13,16 @@
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
struct stream
|
struct stream
|
||||||
{
|
{
|
||||||
explicit stream( std::ostream& s )
|
explicit stream(std::ostream& s) : s_(&s) {}
|
||||||
: s_( &s )
|
|
||||||
{}
|
|
||||||
std::ostream* s_;
|
std::ostream* s_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MOCK_USE_CONVERSIONS
|
#ifdef MOCK_USE_CONVERSIONS
|
||||||
|
|
||||||
namespace detail
|
namespace detail { namespace conversion {
|
||||||
{
|
|
||||||
namespace conversion
|
|
||||||
{
|
|
||||||
struct sink
|
struct sink
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -36,24 +30,18 @@ namespace conversion
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<( std::ostream& s, const sink& )
|
inline std::ostream& operator<<(std::ostream& s, const sink&) { return s << '?'; }
|
||||||
{
|
|
||||||
return s << '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
struct holder : boost::noncopyable
|
struct holder : boost::noncopyable
|
||||||
{
|
{
|
||||||
virtual ~holder()
|
virtual ~holder() {}
|
||||||
{}
|
|
||||||
virtual void serialize(std::ostream& s) const = 0;
|
virtual void serialize(std::ostream& s) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct holder_imp : holder
|
struct holder_imp : holder
|
||||||
{
|
{
|
||||||
explicit holder_imp( const T& t )
|
explicit holder_imp(const T& t) : t_(t) {}
|
||||||
: t_( t )
|
|
||||||
{}
|
|
||||||
virtual void serialize(std::ostream& s) const
|
virtual void serialize(std::ostream& s) const
|
||||||
{
|
{
|
||||||
// if an error about an ambiguous conversion is generated by the
|
// if an error about an ambiguous conversion is generated by the
|
||||||
|
|
@ -67,17 +55,12 @@ namespace conversion
|
||||||
struct any : boost::noncopyable
|
struct any : boost::noncopyable
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
any( const T& t )
|
any(const T& t) : h_(new holder_imp<T>(t))
|
||||||
: h_( new holder_imp< T >( t ) )
|
|
||||||
{}
|
{}
|
||||||
~any()
|
~any() { delete h_; }
|
||||||
{
|
|
||||||
delete h_;
|
|
||||||
}
|
|
||||||
holder* h_;
|
holder* h_;
|
||||||
};
|
};
|
||||||
}
|
}} // namespace detail::conversion
|
||||||
}
|
|
||||||
|
|
||||||
inline stream& operator<<(stream& s, const detail::conversion::any& d)
|
inline stream& operator<<(stream& s, const detail::conversion::any& d)
|
||||||
{
|
{
|
||||||
|
|
@ -87,17 +70,13 @@ namespace conversion
|
||||||
|
|
||||||
#else // MOCK_USE_CONVERSIONS
|
#else // MOCK_USE_CONVERSIONS
|
||||||
|
|
||||||
namespace detail
|
namespace detail { namespace conversion {
|
||||||
{
|
|
||||||
namespace conversion
|
|
||||||
{
|
|
||||||
template<typename S, typename T>
|
template<typename S, typename T>
|
||||||
S& operator<<(S& s, const T&)
|
S& operator<<(S& s, const T&)
|
||||||
{
|
{
|
||||||
return s << '?';
|
return s << '?';
|
||||||
}
|
}
|
||||||
}
|
}} // namespace detail::conversion
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
stream& operator<<(stream& s, const T& t)
|
stream& operator<<(stream& s, const T& t)
|
||||||
|
|
@ -109,8 +88,7 @@ namespace conversion
|
||||||
|
|
||||||
#endif // MOCK_USE_CONVERSIONS
|
#endif // MOCK_USE_CONVERSIONS
|
||||||
|
|
||||||
namespace detail
|
namespace detail {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void serialize(stream& s, const T& t)
|
void serialize(stream& s, const T& t)
|
||||||
{
|
{
|
||||||
|
|
@ -119,24 +97,15 @@ namespace detail
|
||||||
// mock::stream for T
|
// mock::stream for T
|
||||||
s << t;
|
s << t;
|
||||||
}
|
}
|
||||||
inline void serialize( stream& s, bool b )
|
inline void serialize(stream& s, bool b) { s << (b ? "true" : "false"); }
|
||||||
{
|
|
||||||
s << (b ? "true" : "false");
|
|
||||||
}
|
|
||||||
template<typename C, typename T, typename A>
|
template<typename C, typename T, typename A>
|
||||||
void serialize(stream& s, const std::basic_string<C, T, A>& str)
|
void serialize(stream& s, const std::basic_string<C, T, A>& str)
|
||||||
{
|
{
|
||||||
s << '"' << str << '"';
|
s << '"' << str << '"';
|
||||||
}
|
}
|
||||||
inline void serialize( stream& s, const char* const 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); }
|
||||||
s << '"' << str << '"';
|
} // namespace detail
|
||||||
}
|
} // namespace mock
|
||||||
inline void serialize( stream& s, unsigned char c )
|
|
||||||
{
|
|
||||||
s << static_cast< int >( c );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_STREAM_HPP_INCLUDED
|
#endif // MOCK_STREAM_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,11 @@
|
||||||
#define MOCK_VERIFY_HPP_INCLUDED
|
#define MOCK_VERIFY_HPP_INCLUDED
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "object.hpp"
|
|
||||||
#include "detail/root.hpp"
|
|
||||||
#include "detail/functor.hpp"
|
#include "detail/functor.hpp"
|
||||||
|
#include "detail/root.hpp"
|
||||||
|
#include "object.hpp"
|
||||||
|
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
inline bool verify()
|
inline bool verify()
|
||||||
{
|
{
|
||||||
return detail::root.verify();
|
return detail::root.verify();
|
||||||
|
|
@ -29,6 +28,6 @@ namespace mock
|
||||||
{
|
{
|
||||||
return f.verify();
|
return f.verify();
|
||||||
}
|
}
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
#endif // MOCK_VERIFY_HPP_INCLUDED
|
#endif // MOCK_VERIFY_HPP_INCLUDED
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -8,30 +8,25 @@
|
||||||
|
|
||||||
#include "../mock_error.hpp"
|
#include "../mock_error.hpp"
|
||||||
#include "../undefined.hpp"
|
#include "../undefined.hpp"
|
||||||
#include <turtle/detail/function.hpp>
|
|
||||||
#include <turtle/constraints.hpp>
|
#include <turtle/constraints.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <turtle/detail/function.hpp>
|
||||||
#include <boost/utility/result_of.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/function.hpp>
|
||||||
#include <boost/mpl/assert.hpp>
|
#include <boost/mpl/assert.hpp>
|
||||||
#include <boost/scoped_ptr.hpp>
|
#include <boost/scoped_ptr.hpp>
|
||||||
#include <boost/function.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
boost::function<void()> static_f;
|
boost::function<void()> static_f;
|
||||||
|
|
||||||
BOOST_MPL_ASSERT((
|
BOOST_MPL_ASSERT((boost::is_same<void, boost::result_of<mock::detail::function<void()>()>::type>));
|
||||||
boost::is_same< void, boost::result_of< mock::detail::function< void() >() >::type > ));
|
BOOST_MPL_ASSERT((boost::is_same<int, boost::result_of<mock::detail::function<int()>()>::type>));
|
||||||
BOOST_MPL_ASSERT((
|
BOOST_MPL_ASSERT((boost::is_same<void, boost::result_of<mock::detail::function<void(float)>(float)>::type>));
|
||||||
boost::is_same< int, boost::result_of< mock::detail::function< int() >() >::type > ));
|
BOOST_MPL_ASSERT((boost::is_same<int, boost::result_of<mock::detail::function<int(float)>(float)>::type>));
|
||||||
BOOST_MPL_ASSERT((
|
} // namespace
|
||||||
boost::is_same< void, boost::result_of< mock::detail::function< void( float ) >( float ) >::type > ));
|
|
||||||
BOOST_MPL_ASSERT((
|
|
||||||
boost::is_same< int, boost::result_of< mock::detail::function< int( float ) >( float ) >::type > ));
|
|
||||||
}
|
|
||||||
|
|
||||||
// functor
|
// functor
|
||||||
|
|
||||||
|
|
@ -260,7 +255,9 @@ BOOST_FIXTURE_TEST_CASE( verifying_a_reset_function_succeeds, mock_error_fixture
|
||||||
|
|
||||||
// constraints
|
// 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;
|
mock::detail::function<void(int)> f;
|
||||||
|
|
@ -270,11 +267,14 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in
|
||||||
{
|
{
|
||||||
mock::detail::function<int(int, const std::string&)> f;
|
mock::detail::function<int(int, const std::string&)> f;
|
||||||
f.expect().with(42, "expected");
|
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;
|
mock::detail::function<void(int)> f;
|
||||||
f.expect().with(mock::equal(42) || mock::less(42));
|
f.expect().with(mock::equal(42) || mock::less(42));
|
||||||
|
|
@ -283,7 +283,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 ) ) )");
|
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;
|
mock::detail::function<void(int)> f;
|
||||||
f.expect().with(mock::equal(42) && !mock::less(41));
|
f.expect().with(mock::equal(42) && !mock::less(41));
|
||||||
|
|
@ -291,12 +293,12 @@ 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 ) ) )");
|
CHECK_ERROR(f(43), "unexpected call", 1, "?( 43 )\n. unlimited().with( ( equal( 42 ) && ! less( 41 ) ) )");
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class my_interface : boost::noncopyable
|
class my_interface : boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~my_interface() {}
|
virtual ~my_interface() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void my_method() = 0;
|
virtual void my_method() = 0;
|
||||||
};
|
};
|
||||||
|
|
@ -304,7 +306,7 @@ namespace
|
||||||
{
|
{
|
||||||
virtual void my_method() {}
|
virtual void my_method() {}
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(passing_call_values_by_reference_is_transparent, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(passing_call_values_by_reference_is_transparent, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -324,15 +326,15 @@ BOOST_FIXTURE_TEST_CASE( passing_call_values_by_reference_is_transparent, mock_e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
bool custom_constraint(int)
|
bool custom_constraint(int)
|
||||||
{
|
{
|
||||||
return false;
|
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;
|
mock::detail::function<void(int)> f;
|
||||||
|
|
@ -501,20 +503,17 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, mock_e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct base
|
struct base
|
||||||
{
|
{
|
||||||
virtual ~base()
|
virtual ~base() {}
|
||||||
{}
|
|
||||||
virtual void f() = 0;
|
virtual void f() = 0;
|
||||||
};
|
};
|
||||||
struct derived : base
|
struct derived : base
|
||||||
{
|
{
|
||||||
virtual void f()
|
virtual void f() {}
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
#ifdef MOCK_AUTO_PTR
|
#ifdef MOCK_AUTO_PTR
|
||||||
|
|
||||||
|
|
@ -673,13 +672,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, mock_er
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
int custom_result()
|
int custom_result()
|
||||||
{
|
{
|
||||||
return 42;
|
return 42;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_calls_the_custom_functor, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_calls_the_custom_functor, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -689,13 +687,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor, moc
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
int custom_result_with_parameter(int i)
|
int custom_result_with_parameter(int i)
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_calls_the_custom_functor_with_parameters, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_calls_the_custom_functor_with_parameters, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -705,7 +702,8 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_with
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_without_parameters_thanks_to_boost_bind, mock_error_fixture )
|
BOOST_FIXTURE_TEST_CASE(triggering_an_expectation_calls_the_custom_functor_without_parameters_thanks_to_boost_bind,
|
||||||
|
mock_error_fixture)
|
||||||
{
|
{
|
||||||
mock::detail::function<int(int)> f;
|
mock::detail::function<int(int)> f;
|
||||||
f.expect().calls(boost::bind(&custom_result));
|
f.expect().calls(boost::bind(&custom_result));
|
||||||
|
|
@ -720,8 +718,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, moc
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
f();
|
f();
|
||||||
}
|
} catch(std::runtime_error& f)
|
||||||
catch( std::runtime_error& f )
|
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("some exception", f.what());
|
BOOST_CHECK_EQUAL("some exception", f.what());
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
|
|
@ -748,7 +745,8 @@ BOOST_FIXTURE_TEST_CASE( expecting_twice_a_single_expectation_makes_it_callable_
|
||||||
f.expect().once().with("second");
|
f.expect().once().with("second");
|
||||||
f("first");
|
f("first");
|
||||||
f("second");
|
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\" )");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -768,14 +766,14 @@ BOOST_FIXTURE_TEST_CASE( best_expectation_is_selected_first, mock_error_fixture
|
||||||
f.expect().once().with("second");
|
f.expect().once().with("second");
|
||||||
f("second");
|
f("second");
|
||||||
f("first");
|
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
|
// error report
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string to_string(const T& t)
|
std::string to_string(const T& t)
|
||||||
{
|
{
|
||||||
|
|
@ -783,7 +781,7 @@ namespace
|
||||||
s << t;
|
s << t;
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(expectation_can_be_serialized_to_be_human_readable, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(expectation_can_be_serialized_to_be_human_readable, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -862,21 +860,24 @@ 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)
|
||||||
{
|
{
|
||||||
boost::scoped_ptr<mock::detail::function<void()>> f(new mock::detail::function<void()>);
|
boost::scoped_ptr<mock::detail::function<void()>> f(new mock::detail::function<void()>);
|
||||||
f->expect().once();
|
f->expect().once();
|
||||||
CHECK_ERROR(f.reset(), "untriggered expectation", 0, "?\n. 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;
|
mock::detail::function<void()> f;
|
||||||
f.expect().once();
|
f.expect().once();
|
||||||
CHECK_ERROR(f.verify(), "verification failed", 0, "?\n. 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;
|
mock::detail::function<void()> f;
|
||||||
CHECK_ERROR(f(), "unexpected call", 0, "?()");
|
CHECK_ERROR(f(), "unexpected call", 0, "?()");
|
||||||
|
|
@ -897,8 +898,7 @@ BOOST_FIXTURE_TEST_CASE( throwing_an_exception_disables_the_automatic_verificati
|
||||||
mock::detail::function<void()> f;
|
mock::detail::function<void()> f;
|
||||||
f.expect().once();
|
f.expect().once();
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
} catch(std::exception&)
|
||||||
catch( std::exception& )
|
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -915,19 +915,17 @@ BOOST_FIXTURE_TEST_CASE( adding_file_and_line_number_information, mock_error_fix
|
||||||
|
|
||||||
# include <boost/thread.hpp>
|
# include <boost/thread.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
void iterate(mock::detail::function<int()>& f)
|
void iterate(mock::detail::function<int()>& f)
|
||||||
{
|
{
|
||||||
f.expect().once().returns(0);
|
f.expect().once().returns(0);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
f();
|
f();
|
||||||
}
|
} catch(...)
|
||||||
catch( ... )
|
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(function_is_thread_safe, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(function_is_thread_safe, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,12 @@
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
# pragma warning(pop)
|
# pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct declared_but_not_defined;
|
struct declared_but_not_defined;
|
||||||
BOOST_MPL_ASSERT_NOT((
|
BOOST_MPL_ASSERT_NOT((mock::detail::is_functor<declared_but_not_defined, int>));
|
||||||
mock::detail::is_functor< declared_but_not_defined, int > ));
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void is_functor(T)
|
void is_functor(T)
|
||||||
|
|
@ -37,9 +35,15 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
void f0() {}
|
void f0() {}
|
||||||
bool f1( int ) { return false; }
|
bool f1(int)
|
||||||
bool f2( std::string, int ) { return false; }
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
bool f2(std::string, int)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(data_is_not_functor)
|
BOOST_AUTO_TEST_CASE(data_is_not_functor)
|
||||||
{
|
{
|
||||||
|
|
@ -71,13 +75,12 @@ BOOST_AUTO_TEST_CASE( std_bind_first_is_functor )
|
||||||
is_functor(std::bind1st(std::ptr_fun(&f2), ""));
|
is_functor(std::bind1st(std::ptr_fun(&f2), ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct unary_functor0 : public std::unary_function<void, void>
|
struct unary_functor0 : public std::unary_function<void, void>
|
||||||
{};
|
{};
|
||||||
struct unary_functor1 : public std::unary_function<int, void>
|
struct unary_functor1 : public std::unary_function<int, void>
|
||||||
{};
|
{};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(std_unary_functor_is_functor)
|
BOOST_AUTO_TEST_CASE(std_unary_functor_is_functor)
|
||||||
{
|
{
|
||||||
|
|
@ -108,21 +111,19 @@ BOOST_AUTO_TEST_CASE( boost_function_is_functor )
|
||||||
is_functor(boost::function<void()>());
|
is_functor(boost::function<void()>());
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct result_type_functor
|
struct result_type_functor
|
||||||
{
|
{
|
||||||
typedef void result_type;
|
typedef void result_type;
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(class_with_result_type_is_functor)
|
BOOST_AUTO_TEST_CASE(class_with_result_type_is_functor)
|
||||||
{
|
{
|
||||||
is_functor(result_type_functor());
|
is_functor(result_type_functor());
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct sig_functor
|
struct sig_functor
|
||||||
{
|
{
|
||||||
template<typename Args>
|
template<typename Args>
|
||||||
|
|
@ -131,7 +132,7 @@ namespace
|
||||||
typedef void type;
|
typedef void type;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(class_with_sig_is_functor)
|
BOOST_AUTO_TEST_CASE(class_with_sig_is_functor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,20 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include <turtle/detail/signature.hpp>
|
#include <turtle/detail/signature.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/mpl/assert.hpp>
|
#include <boost/mpl/assert.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct base
|
struct base
|
||||||
{
|
{
|
||||||
void method_1();
|
void method_1();
|
||||||
float method_2(int) const;
|
float method_2(int) const;
|
||||||
};
|
};
|
||||||
typedef base base_type;
|
typedef base base_type;
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(mock_signature_generates_signature)
|
BOOST_AUTO_TEST_CASE(mock_signature_generates_signature)
|
||||||
{
|
{
|
||||||
BOOST_MPL_ASSERT((
|
BOOST_MPL_ASSERT((boost::is_same<void(), MOCK_SIGNATURE(method_1)>));
|
||||||
boost::is_same< void(), MOCK_SIGNATURE(method_1) > ));
|
BOOST_MPL_ASSERT((boost::is_same<float(int), MOCK_SIGNATURE(method_2)>));
|
||||||
BOOST_MPL_ASSERT((
|
|
||||||
boost::is_same< float( int ), MOCK_SIGNATURE(method_2) > ));
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,16 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include <turtle/detail/type_name.hpp>
|
#include <turtle/detail/type_name.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string to_string(const T&)
|
std::string to_string(const T&)
|
||||||
{
|
{
|
||||||
return boost::lexical_cast<std::string>(MOCK_TYPE_NAME(T));
|
return boost::lexical_cast<std::string>(MOCK_TYPE_NAME(T));
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_base_type_is_extracted)
|
BOOST_AUTO_TEST_CASE(name_of_base_type_is_extracted)
|
||||||
{
|
{
|
||||||
|
|
@ -33,7 +32,8 @@ BOOST_AUTO_TEST_CASE( name_of_base_type_is_extracted )
|
||||||
|
|
||||||
struct my_type_in_default_namespace
|
struct my_type_in_default_namespace
|
||||||
{
|
{
|
||||||
struct inner {};
|
struct inner
|
||||||
|
{};
|
||||||
};
|
};
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_type_in_default_namespace_is_extracted)
|
BOOST_AUTO_TEST_CASE(name_of_type_in_default_namespace_is_extracted)
|
||||||
|
|
@ -49,12 +49,14 @@ BOOST_AUTO_TEST_CASE( name_of_inner_type_from_type_in_default_namespace_is_extra
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct my_template_type_in_default_namespace
|
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_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)
|
BOOST_AUTO_TEST_CASE(name_of_inner_type_from_template_type_in_default_namespace_is_extracted)
|
||||||
|
|
@ -62,46 +64,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()));
|
BOOST_CHECK_EQUAL("inner", to_string(my_template_type_in_default_namespace<int>::inner()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
struct my_type_in_anonymous_namespace
|
||||||
struct my_type_in_anonymous_namespace {};
|
{};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_type_in_anonymous_namespace_is_extracted)
|
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()));
|
BOOST_CHECK_EQUAL("my_type_in_anonymous_namespace", to_string(my_type_in_anonymous_namespace()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nm
|
namespace nm {
|
||||||
{
|
struct my_type_from_named_namespace
|
||||||
struct my_type_from_named_namespace {};
|
{};
|
||||||
}
|
} // namespace nm
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_type_from_named_namespace_is_extracted)
|
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()));
|
BOOST_CHECK_EQUAL("my_type_from_named_namespace", to_string(nm::my_type_from_named_namespace()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nm
|
namespace nm { namespace inner {
|
||||||
{
|
struct my_type_in_named_inner_namespace
|
||||||
namespace inner
|
{};
|
||||||
{
|
}} // namespace nm::inner
|
||||||
struct my_type_in_named_inner_namespace {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_type_in_named_inner_namespace_is_extracted)
|
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()));
|
BOOST_CHECK_EQUAL("my_type_in_named_inner_namespace", to_string(nm::inner::my_type_in_named_inner_namespace()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace { namespace inner {
|
||||||
{
|
struct my_type_in_unnamed_inner_namespace
|
||||||
namespace inner
|
{};
|
||||||
{
|
}} // namespace ::inner
|
||||||
struct my_type_in_unnamed_inner_namespace {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_type_in_unnamed_inner_namespace_is_extracted)
|
BOOST_AUTO_TEST_CASE(name_of_type_in_unnamed_inner_namespace_is_extracted)
|
||||||
{
|
{
|
||||||
|
|
@ -110,18 +106,19 @@ BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted )
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_local_type_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", boost::lexical_cast<std::string>(MOCK_TYPE_NAME(my_local_type)));
|
BOOST_CHECK_EQUAL("my_local_type", boost::lexical_cast<std::string>(MOCK_TYPE_NAME(my_local_type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct my_template_type
|
struct my_template_type
|
||||||
{
|
{
|
||||||
struct inner {};
|
struct inner
|
||||||
|
{};
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_template_type_in_anonymous_namespace_is_extracted)
|
BOOST_AUTO_TEST_CASE(name_of_template_type_in_anonymous_namespace_is_extracted)
|
||||||
{
|
{
|
||||||
|
|
@ -147,14 +144,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()));
|
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<std::exception const*&>::inner()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nm
|
namespace nm {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct my_template_type
|
struct my_template_type
|
||||||
{
|
{
|
||||||
struct inner {};
|
struct inner
|
||||||
|
{};
|
||||||
};
|
};
|
||||||
}
|
} // namespace nm
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_template_type_in_named_namespace_is_extracted)
|
BOOST_AUTO_TEST_CASE(name_of_template_type_in_named_namespace_is_extracted)
|
||||||
{
|
{
|
||||||
|
|
@ -180,15 +177,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()));
|
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<std::exception const*&>::inner()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nm2
|
namespace nm2 {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct my_template_type
|
struct my_template_type
|
||||||
{
|
{
|
||||||
template<typename U>
|
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)
|
BOOST_AUTO_TEST_CASE(name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted)
|
||||||
{
|
{
|
||||||
|
|
@ -210,16 +207,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*&>()));
|
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>
|
template<typename T1, typename T2, typename T3>
|
||||||
struct my_tpl
|
struct my_tpl
|
||||||
{};
|
{};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_of_nested_template_with_multiple_arguments_is_extracted)
|
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<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("vector<vector<int, allocator<int>>, allocator<vector<int, allocator<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 > >() ) );
|
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>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_base
|
struct my_base
|
||||||
{
|
{
|
||||||
virtual ~my_base() {}
|
virtual ~my_base() {}
|
||||||
|
|
@ -17,8 +16,5 @@ namespace
|
||||||
virtual void my_method(int) = 0;
|
virtual void my_method(int) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_class, my_base )
|
MOCK_BASE_CLASS(my_class, my_base){MOCK_METHOD(my_method, 0)};
|
||||||
{
|
} // namespace
|
||||||
MOCK_METHOD( my_method, 0 )
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,8 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_class){MOCK_METHOD_EXT(my_method, 1, void(int), my_method)};
|
||||||
MOCK_CLASS( my_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
|
|
||||||
};
|
|
||||||
bool constraint(int, int);
|
bool constraint(int, int);
|
||||||
|
|
||||||
void test_case()
|
void test_case()
|
||||||
|
|
@ -21,4 +17,4 @@ namespace
|
||||||
my_class c;
|
my_class c;
|
||||||
MOCK_EXPECT(c.my_method).with(&constraint);
|
MOCK_EXPECT(c.my_method).with(&constraint);
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,11 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_class){MOCK_METHOD_EXT(my_method, 1, void(int), my_method)};
|
||||||
MOCK_CLASS( my_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
|
|
||||||
};
|
|
||||||
void test_case()
|
void test_case()
|
||||||
{
|
{
|
||||||
my_class c;
|
my_class c;
|
||||||
MOCK_EXPECT(c.my_method).with("42");
|
MOCK_EXPECT(c.my_method).with("42");
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,11 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_class){MOCK_METHOD_EXT(my_method, 1, void(int), my_method)};
|
||||||
MOCK_CLASS( my_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
|
|
||||||
};
|
|
||||||
void test_case()
|
void test_case()
|
||||||
{
|
{
|
||||||
my_class c;
|
my_class c;
|
||||||
MOCK_EXPECT(c.my_method).with(mock::equal("42"));
|
MOCK_EXPECT(c.my_method).with(mock::equal("42"));
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,11 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_class){MOCK_METHOD_EXT(my_method, 0, int(), my_method)};
|
||||||
MOCK_CLASS( my_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 0, int(), my_method )
|
|
||||||
};
|
|
||||||
void test_case()
|
void test_case()
|
||||||
{
|
{
|
||||||
my_class c;
|
my_class c;
|
||||||
MOCK_EXPECT(c.my_method).returns(std::string());
|
MOCK_EXPECT(c.my_method).returns(std::string());
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,11 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_class){MOCK_METHOD_EXT(my_method, 0, std::string(), my_method)};
|
||||||
MOCK_CLASS( my_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 0, std::string(), my_method )
|
|
||||||
};
|
|
||||||
void test_case()
|
void test_case()
|
||||||
{
|
{
|
||||||
my_class c;
|
my_class c;
|
||||||
MOCK_EXPECT(c.my_method).returns(42);
|
MOCK_EXPECT(c.my_method).returns(42);
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,11 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_class){MOCK_METHOD_EXT(my_method, 0, void(), my_method)};
|
||||||
MOCK_CLASS( my_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
|
|
||||||
};
|
|
||||||
void test_case()
|
void test_case()
|
||||||
{
|
{
|
||||||
my_class c;
|
my_class c;
|
||||||
MOCK_EXPECT(c.my_method).returns("42");
|
MOCK_EXPECT(c.my_method).returns("42");
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,11 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_base
|
struct my_base
|
||||||
{
|
{
|
||||||
virtual ~my_base() {}
|
virtual ~my_base() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_class, my_base )
|
MOCK_BASE_CLASS(my_class, my_base){MOCK_METHOD(my_method, 0)};
|
||||||
{
|
} // namespace
|
||||||
MOCK_METHOD( my_method, 0 )
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,12 @@
|
||||||
|
|
||||||
BOOST_STATIC_ASSERT(MOCK_MAX_ARGS == 9);
|
BOOST_STATIC_ASSERT(MOCK_MAX_ARGS == 9);
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_base
|
struct my_base
|
||||||
{
|
{
|
||||||
virtual ~my_base() {}
|
virtual ~my_base() {}
|
||||||
virtual void my_method(int, int, int, int, int, int, int, int, int, int) = 0;
|
virtual void my_method(int, int, int, int, int, int, int, int, int, int) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_class, my_base )
|
MOCK_BASE_CLASS(my_class, my_base){MOCK_METHOD(my_method, 10)};
|
||||||
{
|
} // namespace
|
||||||
MOCK_METHOD( my_method, 10 )
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,7 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_CLASS( my_class )
|
MOCK_CLASS(my_class){MOCK_METHOD_EXT(my_method, 1, void(T), my_method)};
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 1, void( T ), my_method )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,12 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_base
|
struct my_base
|
||||||
{
|
{
|
||||||
virtual ~my_base() {}
|
virtual ~my_base() {}
|
||||||
virtual void my_method(int) = 0;
|
virtual void my_method(int) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_class, my_base )
|
MOCK_BASE_CLASS(my_class, my_base){MOCK_METHOD(my_method, 2)};
|
||||||
{
|
} // namespace
|
||||||
MOCK_METHOD( my_method, 2 )
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,11 @@
|
||||||
|
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_class){MOCK_METHOD_EXT(my_method, 1, void(int), my_method)};
|
||||||
MOCK_CLASS( my_class )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
|
|
||||||
};
|
|
||||||
void test_case()
|
void test_case()
|
||||||
{
|
{
|
||||||
my_class c;
|
my_class c;
|
||||||
MOCK_EXPECT(c.my_method).with(42, 42);
|
MOCK_EXPECT(c.my_method).with(42, 42);
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,7 @@ struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
|
||||||
last_message.clear();
|
last_message.clear();
|
||||||
last_context.clear();
|
last_context.clear();
|
||||||
}
|
}
|
||||||
bool verify()
|
bool verify() { return error_count == 0; }
|
||||||
{
|
|
||||||
return error_count == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void call()
|
void call()
|
||||||
{
|
{
|
||||||
|
|
@ -35,9 +32,7 @@ struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
|
||||||
last_message.clear();
|
last_message.clear();
|
||||||
++call_count;
|
++call_count;
|
||||||
}
|
}
|
||||||
void fail( const std::string& message,
|
void fail(const std::string& message, const std::string& context, const char* file, int line)
|
||||||
const std::string& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
{
|
||||||
last_context = context;
|
last_context = context;
|
||||||
last_message = message;
|
last_message = message;
|
||||||
|
|
@ -59,36 +54,26 @@ MOCK_SINGLETON_INST( mock_error_data )
|
||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct mock_error
|
struct mock_error
|
||||||
{
|
{
|
||||||
static Result abort()
|
static Result abort() { throw std::runtime_error("aborted"); }
|
||||||
{
|
|
||||||
throw std::runtime_error( "aborted" );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pass( const char* /*file*/, int /*line*/ )
|
static void pass(const char* /*file*/, int /*line*/) {}
|
||||||
{}
|
|
||||||
|
|
||||||
template<typename Context>
|
template<typename Context>
|
||||||
static void call( const Context& /*context*/,
|
static void call(const Context& /*context*/, const char* /*file*/, int /*line*/)
|
||||||
const char* /*file*/, int /*line*/ )
|
|
||||||
{
|
{
|
||||||
mock_error_data.call();
|
mock_error_data.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Context>
|
template<typename Context>
|
||||||
static void fail( const std::string& message, const Context& context,
|
static void fail(const std::string& message, const Context& context, const char* file = "", int line = 0)
|
||||||
const char* file = "", int line = 0 )
|
|
||||||
{
|
{
|
||||||
mock_error_data.fail( message,
|
mock_error_data.fail(message, boost::lexical_cast<std::string>(context), file, line);
|
||||||
boost::lexical_cast< std::string >( context ), file, line );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mock_error_fixture
|
struct mock_error_fixture
|
||||||
{
|
{
|
||||||
mock_error_fixture()
|
mock_error_fixture() { mock_error_data.reset(); }
|
||||||
{
|
|
||||||
mock_error_data.reset();
|
|
||||||
}
|
|
||||||
~mock_error_fixture()
|
~mock_error_fixture()
|
||||||
{
|
{
|
||||||
BOOST_CHECK(mock_error_data.verify());
|
BOOST_CHECK(mock_error_data.verify());
|
||||||
|
|
@ -101,7 +86,11 @@ struct mock_error_fixture
|
||||||
mock_error_data.call_count = 0;
|
mock_error_data.call_count = 0;
|
||||||
#define CHECK_ERROR(expr, error, calls, context) \
|
#define CHECK_ERROR(expr, error, calls, context) \
|
||||||
BOOST_CHECK(mock_error_data.verify()); \
|
BOOST_CHECK(mock_error_data.verify()); \
|
||||||
try { expr; } catch( ... ) {} \
|
try \
|
||||||
|
{ \
|
||||||
|
expr; \
|
||||||
|
} catch(...) \
|
||||||
|
{} \
|
||||||
BOOST_CHECK_EQUAL(1, mock_error_data.error_count); \
|
BOOST_CHECK_EQUAL(1, mock_error_data.error_count); \
|
||||||
BOOST_CHECK_EQUAL(error, mock_error_data.last_message); \
|
BOOST_CHECK_EQUAL(error, mock_error_data.last_message); \
|
||||||
BOOST_CHECK_EQUAL(context, mock_error_data.last_context); \
|
BOOST_CHECK_EQUAL(context, mock_error_data.last_context); \
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,11 @@
|
||||||
|
|
||||||
#ifdef MOCK_VARIADIC_MACROS
|
#ifdef MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_CONSTRAINT(constraint_0, actual == 0)
|
MOCK_CONSTRAINT(constraint_0, actual == 0)
|
||||||
MOCK_CONSTRAINT(constraint_1, expected, actual == expected)
|
MOCK_CONSTRAINT(constraint_1, expected, actual == expected)
|
||||||
MOCK_CONSTRAINT(constraint_2, expected_0, expected_1, actual == expected_0 || actual == expected_1)
|
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)
|
BOOST_AUTO_TEST_CASE(mock_constraint_is_supported_by_compilers_with_variadic_macros)
|
||||||
{
|
{
|
||||||
|
|
@ -27,12 +26,11 @@ BOOST_AUTO_TEST_CASE( mock_constraint_is_supported_by_compilers_with_variadic_ma
|
||||||
|
|
||||||
#endif // MOCK_VARIADIC_MACROS
|
#endif // MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_CONSTRAINT_EXT(constraint_0_ext, 0, , actual == 0)
|
MOCK_CONSTRAINT_EXT(constraint_0_ext, 0, , actual == 0)
|
||||||
MOCK_CONSTRAINT_EXT(constraint_1_ext, 1, (expected), actual == expected)
|
MOCK_CONSTRAINT_EXT(constraint_1_ext, 1, (expected), actual == expected)
|
||||||
MOCK_CONSTRAINT_EXT(constraint_2_ext, 2, (expected_0, expected_1), actual == expected_0 || actual == expected_1)
|
MOCK_CONSTRAINT_EXT(constraint_2_ext, 2, (expected_0, expected_1), actual == expected_0 || actual == expected_1)
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(mock_constraint_ext_is_supported_by_all_compilers)
|
BOOST_AUTO_TEST_CASE(mock_constraint_ext_is_supported_by_all_compilers)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,7 @@ BOOST_AUTO_TEST_CASE( equal_constraint )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( equal_constraint_deref )
|
BOOST_AUTO_TEST_CASE(equal_constraint_deref){{int i = 3;
|
||||||
{
|
|
||||||
{
|
|
||||||
int i = 3;
|
|
||||||
BOOST_CHECK(mock::equal(3).c_(&i));
|
BOOST_CHECK(mock::equal(3).c_(&i));
|
||||||
BOOST_CHECK(!mock::equal(7).c_(&i));
|
BOOST_CHECK(!mock::equal(7).c_(&i));
|
||||||
}
|
}
|
||||||
|
|
@ -85,10 +82,7 @@ BOOST_AUTO_TEST_CASE( equal_constraint_deref )
|
||||||
#endif // MOCK_SMART_PTR
|
#endif // MOCK_SMART_PTR
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( same_constraint )
|
BOOST_AUTO_TEST_CASE(same_constraint){{int i = 0;
|
||||||
{
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
BOOST_CHECK_EQUAL(i, j);
|
BOOST_CHECK_EQUAL(i, j);
|
||||||
BOOST_CHECK(!mock::same(i).c_(j));
|
BOOST_CHECK(!mock::same(i).c_(j));
|
||||||
|
|
@ -98,11 +92,7 @@ BOOST_AUTO_TEST_CASE( same_constraint )
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
BOOST_CHECK_EQUAL(i, j);
|
BOOST_CHECK_EQUAL(i, j);
|
||||||
mock::constraint<
|
mock::constraint<mock::detail::same<const boost::reference_wrapper<const int>>> c = mock::same(boost::cref(i));
|
||||||
mock::detail::same<
|
|
||||||
const boost::reference_wrapper< const int >
|
|
||||||
>
|
|
||||||
> c = mock::same( boost::cref( i ) );
|
|
||||||
BOOST_CHECK(!c.c_(j));
|
BOOST_CHECK(!c.c_(j));
|
||||||
BOOST_CHECK(c.c_(i));
|
BOOST_CHECK(c.c_(i));
|
||||||
}
|
}
|
||||||
|
|
@ -141,11 +131,7 @@ BOOST_AUTO_TEST_CASE( assign_constraint )
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 1;
|
int j = 1;
|
||||||
mock::constraint<
|
mock::constraint<mock::detail::assign<boost::reference_wrapper<const int>>> c = mock::assign(boost::cref(j));
|
||||||
mock::detail::assign<
|
|
||||||
boost::reference_wrapper< const int >
|
|
||||||
>
|
|
||||||
> c = mock::assign( boost::cref( j ) );
|
|
||||||
BOOST_CHECK(c.c_(i));
|
BOOST_CHECK(c.c_(i));
|
||||||
BOOST_CHECK_EQUAL(1, i);
|
BOOST_CHECK_EQUAL(1, i);
|
||||||
j = 3;
|
j = 3;
|
||||||
|
|
@ -155,11 +141,7 @@ BOOST_AUTO_TEST_CASE( assign_constraint )
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 1;
|
int j = 1;
|
||||||
mock::constraint<
|
mock::constraint<mock::detail::assign<boost::reference_wrapper<const int>>> c = mock::assign(boost::cref(j));
|
||||||
mock::detail::assign<
|
|
||||||
boost::reference_wrapper< const int >
|
|
||||||
>
|
|
||||||
> c = mock::assign( boost::cref( j ) );
|
|
||||||
BOOST_CHECK(c.c_(&i));
|
BOOST_CHECK(c.c_(&i));
|
||||||
BOOST_CHECK_EQUAL(1, i);
|
BOOST_CHECK_EQUAL(1, i);
|
||||||
j = 3;
|
j = 3;
|
||||||
|
|
@ -170,11 +152,7 @@ BOOST_AUTO_TEST_CASE( assign_constraint )
|
||||||
const int* i = 0;
|
const int* i = 0;
|
||||||
int k = 1;
|
int k = 1;
|
||||||
int* j = &k;
|
int* j = &k;
|
||||||
mock::constraint<
|
mock::constraint<mock::detail::assign<boost::reference_wrapper<int* const>>> c = mock::assign(boost::cref(j));
|
||||||
mock::detail::assign<
|
|
||||||
boost::reference_wrapper< int* const >
|
|
||||||
>
|
|
||||||
> c = mock::assign( boost::cref( j ) );
|
|
||||||
BOOST_CHECK(c.c_(i));
|
BOOST_CHECK(c.c_(i));
|
||||||
BOOST_CHECK_EQUAL(j, i);
|
BOOST_CHECK_EQUAL(j, i);
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
@ -265,19 +243,14 @@ BOOST_AUTO_TEST_CASE( retrieve_constraint )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct A
|
struct A
|
||||||
{
|
{};
|
||||||
};
|
|
||||||
struct B
|
struct B
|
||||||
{
|
{
|
||||||
B& operator=( const A& )
|
B& operator=(const A&) { return *this; }
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(retrieve_constraint_uses_assignment_operator)
|
BOOST_AUTO_TEST_CASE(retrieve_constraint_uses_assignment_operator)
|
||||||
{
|
{
|
||||||
|
|
@ -312,8 +285,7 @@ BOOST_AUTO_TEST_CASE( negate_constraint )
|
||||||
BOOST_CHECK(!mock::negate.c_(&j));
|
BOOST_CHECK(!mock::negate.c_(&j));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
bool return_true()
|
bool return_true()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -322,7 +294,7 @@ namespace
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(call_constraint)
|
BOOST_AUTO_TEST_CASE(call_constraint)
|
||||||
{
|
{
|
||||||
|
|
@ -344,11 +316,8 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_const_char_ptr )
|
||||||
BOOST_CHECK(!mock::contain("not found").c_(std::string("this is a string")));
|
BOOST_CHECK(!mock::contain("not found").c_(std::string("this is a string")));
|
||||||
{
|
{
|
||||||
const char* s = 0;
|
const char* s = 0;
|
||||||
mock::constraint<
|
mock::constraint<mock::detail::contain<boost::reference_wrapper<const char* const>>> c =
|
||||||
mock::detail::contain<
|
mock::contain(boost::cref(s));
|
||||||
boost::reference_wrapper< const char* const >
|
|
||||||
>
|
|
||||||
> c = mock::contain( boost::cref( s ) );
|
|
||||||
s = "string";
|
s = "string";
|
||||||
BOOST_CHECK(c.c_("this is a string"));
|
BOOST_CHECK(c.c_("this is a string"));
|
||||||
BOOST_CHECK(c.c_(std::string("this is a string")));
|
BOOST_CHECK(c.c_(std::string("this is a string")));
|
||||||
|
|
@ -366,11 +335,8 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
|
||||||
BOOST_CHECK(!mock::contain(std::string("not found")).c_(std::string("this is a string")));
|
BOOST_CHECK(!mock::contain(std::string("not found")).c_(std::string("this is a string")));
|
||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
mock::constraint<
|
mock::constraint<mock::detail::contain<boost::reference_wrapper<const std::string>>> c =
|
||||||
mock::detail::contain<
|
mock::contain(boost::cref(s));
|
||||||
boost::reference_wrapper< const std::string >
|
|
||||||
>
|
|
||||||
> c = mock::contain( boost::cref( s ) );
|
|
||||||
s = "string";
|
s = "string";
|
||||||
BOOST_CHECK(c.c_("this is a string"));
|
BOOST_CHECK(c.c_("this is a string"));
|
||||||
BOOST_CHECK(c.c_(std::string("this is a string")));
|
BOOST_CHECK(c.c_(std::string("this is a string")));
|
||||||
|
|
@ -380,14 +346,13 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct type_with_overloaded_address_operator
|
struct type_with_overloaded_address_operator
|
||||||
{
|
{
|
||||||
void operator&() {}
|
void operator&() {}
|
||||||
void operator&() const {}
|
void operator&() const {}
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_with_overloaded_address_operator_can_be_used_in_constraints)
|
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
|
try
|
||||||
{
|
{
|
||||||
throw mock::exception();
|
throw mock::exception();
|
||||||
}
|
} catch(std::exception&)
|
||||||
catch( std::exception& )
|
|
||||||
{
|
{
|
||||||
BOOST_FAIL("mock::exception must not be an std::exception");
|
BOOST_FAIL("mock::exception must not be an std::exception");
|
||||||
}
|
} catch(mock::exception&)
|
||||||
catch( mock::exception& )
|
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,18 @@
|
||||||
#include "mock_error.hpp"
|
#include "mock_error.hpp"
|
||||||
#include "undefined.hpp"
|
#include "undefined.hpp"
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_custom_mock
|
struct my_custom_mock
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
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)
|
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_and_without_inheriting_from_object, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -31,13 +30,12 @@ BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheritin
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_custom_mock_object
|
struct my_custom_mock_object
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -47,12 +45,8 @@ BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros, mock_error_fixture )
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_mock){MOCK_METHOD_EXT(my_method, 1, int(int), my_tag)};
|
||||||
MOCK_CLASS( my_mock )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( my_method, 1, int( int ), my_tag )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(basic_mock_object_usage, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(basic_mock_object_usage, mock_error_fixture)
|
||||||
|
|
@ -79,23 +73,18 @@ BOOST_FIXTURE_TEST_CASE( basic_mock_object_usage, mock_error_fixture )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class my_ambiguited_interface : boost::noncopyable
|
class my_ambiguited_interface : boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~my_ambiguited_interface()
|
virtual ~my_ambiguited_interface() {}
|
||||||
{}
|
|
||||||
virtual void my_method() = 0;
|
virtual void my_method() = 0;
|
||||||
virtual void my_method(int) = 0;
|
virtual void my_method(int) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_ambiguited_mock, my_ambiguited_interface )
|
MOCK_BASE_CLASS(my_ambiguited_mock, my_ambiguited_interface){MOCK_METHOD_EXT(my_method, 0, void(), my_tag1)
|
||||||
{
|
MOCK_METHOD_EXT(my_method, 1, void(int), my_tag_2)};
|
||||||
MOCK_METHOD_EXT( my_method, 0, void(), my_tag1 )
|
} // namespace
|
||||||
MOCK_METHOD_EXT( my_method, 1, void( int ), my_tag_2 )
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_object_method_disambiguation, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_object_method_disambiguation, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -105,23 +94,18 @@ 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 )");
|
CHECK_ERROR(m.my_method(12), "unexpected call", 1, "?.my_ambiguited_mock::my_tag_2( 12 )");
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class my_const_ambiguited_interface : boost::noncopyable
|
class my_const_ambiguited_interface : boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~my_const_ambiguited_interface()
|
virtual ~my_const_ambiguited_interface() {}
|
||||||
{}
|
|
||||||
virtual void my_method() = 0;
|
virtual void my_method() = 0;
|
||||||
virtual void my_method() const = 0;
|
virtual void my_method() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_const_ambiguited_mock, my_const_ambiguited_interface )
|
MOCK_BASE_CLASS(my_const_ambiguited_mock, my_const_ambiguited_interface){
|
||||||
{
|
MOCK_NON_CONST_METHOD_EXT(my_method, 0, void(), tag1) MOCK_CONST_METHOD_EXT(my_method, 0, void(), tag_2)};
|
||||||
MOCK_NON_CONST_METHOD_EXT( my_method, 0, void(), tag1 )
|
} // namespace
|
||||||
MOCK_CONST_METHOD_EXT( my_method, 0, void(), tag_2 )
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_object_method_const_disambiguation, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_object_method_const_disambiguation, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -132,12 +116,8 @@ 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()");
|
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)};
|
||||||
MOCK_CLASS( my_undefined_mock )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( m, 1, void( undefined& ), t )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_object_method_with_declared_but_not_defined_parameter_is_valid, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_object_method_with_declared_but_not_defined_parameter_is_valid, mock_error_fixture)
|
||||||
|
|
@ -146,8 +126,7 @@ BOOST_FIXTURE_TEST_CASE( mock_object_method_with_declared_but_not_defined_parame
|
||||||
MOCK_EXPECT(mock.t);
|
MOCK_EXPECT(mock.t);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_FUNCTOR(gf, int(float, const std::string&));
|
MOCK_FUNCTOR(gf, int(float, const std::string&));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,13 +151,12 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_in_function_is_supported, mock_error_fixtu
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct functor_fixture : mock_error_fixture
|
struct functor_fixture : mock_error_fixture
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR(f, int(float, const std::string&));
|
MOCK_FUNCTOR(f, int(float, const std::string&));
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_functor_in_fixture_is_supported, functor_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_functor_in_fixture_is_supported, functor_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -187,8 +165,7 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_in_fixture_is_supported, functor_fixture )
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct my_template_mock
|
struct my_template_mock
|
||||||
{
|
{
|
||||||
|
|
@ -196,7 +173,7 @@ namespace
|
||||||
MOCK_METHOD_EXT_TPL(my_method, 2, void(T, std::string), my_tpl_tag)
|
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)
|
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)
|
BOOST_FIXTURE_TEST_CASE(mocking_a_template_class_method_is_supported, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -207,23 +184,19 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_template_class_method_is_supported, mock_erro
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct my_template_base_class
|
struct my_template_base_class
|
||||||
{
|
{
|
||||||
virtual ~my_template_base_class()
|
virtual ~my_template_base_class() {}
|
||||||
{}
|
|
||||||
virtual void my_method(T) = 0;
|
virtual void my_method(T) = 0;
|
||||||
virtual void my_other_method() = 0;
|
virtual void my_other_method() = 0;
|
||||||
};
|
};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_BASE_CLASS( my_template_base_class_mock, my_template_base_class< T > )
|
MOCK_BASE_CLASS(my_template_base_class_mock,
|
||||||
{
|
my_template_base_class<T>){MOCK_METHOD_EXT_TPL(my_method, 1, void(T), my_method)
|
||||||
MOCK_METHOD_EXT_TPL( my_method, 1, void( T ), my_method )
|
MOCK_METHOD_EXT_TPL(my_other_method, 0, void(), my_other_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)
|
BOOST_FIXTURE_TEST_CASE(mocking_a_template_base_class_method_is_supported, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -234,56 +207,42 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_template_base_class_method_is_supported, mock
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
class my_observer : boost::noncopyable
|
class my_observer : boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~my_observer()
|
virtual ~my_observer() {}
|
||||||
{}
|
|
||||||
virtual void notify(int value) = 0;
|
virtual void notify(int value) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class my_manager : boost::noncopyable
|
class my_manager : boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~my_manager()
|
virtual ~my_manager() {}
|
||||||
{}
|
|
||||||
virtual my_observer& get_observer() const = 0;
|
virtual my_observer& get_observer() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class my_subject : boost::noncopyable
|
class my_subject : boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit my_subject( my_manager& f )
|
explicit my_subject(my_manager& f) : o_(f.get_observer()), value_(0) {}
|
||||||
: o_( f.get_observer() )
|
void increment() { o_.notify(++value_); }
|
||||||
, value_( 0 )
|
|
||||||
{}
|
|
||||||
void increment()
|
|
||||||
{
|
|
||||||
o_.notify( ++value_ );
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
my_observer& o_;
|
my_observer& o_;
|
||||||
int value_;
|
int value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_mock_observer, my_observer )
|
MOCK_BASE_CLASS(my_mock_observer, my_observer){MOCK_METHOD(notify, 1)};
|
||||||
{
|
|
||||||
MOCK_METHOD( notify, 1 )
|
|
||||||
};
|
|
||||||
|
|
||||||
MOCK_BASE_CLASS( my_mock_manager, my_manager )
|
MOCK_BASE_CLASS(my_mock_manager, my_manager){MOCK_METHOD(get_observer, 0)};
|
||||||
{
|
|
||||||
MOCK_METHOD( get_observer, 0 )
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fixture : mock_error_fixture
|
struct fixture : mock_error_fixture
|
||||||
{
|
{
|
||||||
my_mock_manager manager;
|
my_mock_manager manager;
|
||||||
my_mock_observer observer;
|
my_mock_observer observer;
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(basic_mock_object_collaboration_usage, fixture)
|
BOOST_FIXTURE_TEST_CASE(basic_mock_object_collaboration_usage, fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -298,12 +257,8 @@ BOOST_FIXTURE_TEST_CASE( basic_mock_object_collaboration_usage, fixture )
|
||||||
CHECK_CALLS(4);
|
CHECK_CALLS(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_constructed_class){MOCK_CONSTRUCTOR(my_constructed_class, 2, (int, const std::string&), constructor)};
|
||||||
MOCK_CLASS( my_constructed_class )
|
|
||||||
{
|
|
||||||
MOCK_CONSTRUCTOR( my_constructed_class, 2, ( int, const std::string& ), constructor )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mocking_a_constructor, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mocking_a_constructor, mock_error_fixture)
|
||||||
|
|
@ -314,13 +269,10 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_constructor, mock_error_fixture )
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_CLASS( my_constructed_template_class )
|
MOCK_CLASS(my_constructed_template_class){
|
||||||
{
|
MOCK_CONSTRUCTOR_TPL(my_constructed_template_class, 2, (T, const std::string&), constructor)};
|
||||||
MOCK_CONSTRUCTOR_TPL( my_constructed_template_class, 2, ( T, const std::string& ), constructor )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mocking_a_template_class_constructor, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mocking_a_template_class_constructor, mock_error_fixture)
|
||||||
|
|
@ -331,12 +283,8 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_template_class_constructor, mock_error_fixtur
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_destroyed_class){MOCK_DESTRUCTOR(~my_destroyed_class, destructor)};
|
||||||
MOCK_CLASS( my_destroyed_class )
|
|
||||||
{
|
|
||||||
MOCK_DESTRUCTOR( ~my_destroyed_class, destructor )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mocking_a_destructor, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mocking_a_destructor, mock_error_fixture)
|
||||||
|
|
@ -351,14 +299,10 @@ 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)
|
BOOST_FIXTURE_TEST_CASE(failed_expectation_in_mocked_destructor_does_not_throw, mock_error_fixture)
|
||||||
{
|
{
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
my_destroyed_class c;
|
my_destroyed_class c;
|
||||||
throw std::runtime_error("should not crash");
|
throw std::runtime_error("should not crash");
|
||||||
}
|
} catch(std::runtime_error&){},
|
||||||
catch( std::runtime_error& )
|
|
||||||
{
|
|
||||||
},
|
|
||||||
"unexpected call", 0, "?.my_destroyed_class::destructor()");
|
"unexpected call", 0, "?.my_destroyed_class::destructor()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -376,12 +320,8 @@ BOOST_FIXTURE_TEST_CASE( failed_sequence_in_mocked_destructor_does_not_throw, mo
|
||||||
"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)};
|
||||||
MOCK_CLASS( boost_optional )
|
|
||||||
{
|
|
||||||
MOCK_METHOD_EXT( method, 0, boost::optional< my_observer& >(), tag )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(boost_optional_on_base_class_reference_as_return_type_is_supported, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(boost_optional_on_base_class_reference_as_return_type_is_supported, mock_error_fixture)
|
||||||
|
|
@ -393,8 +333,7 @@ BOOST_FIXTURE_TEST_CASE( boost_optional_on_base_class_reference_as_return_type_i
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
bool serialized = false;
|
bool serialized = false;
|
||||||
|
|
||||||
struct custom_argument
|
struct custom_argument
|
||||||
|
|
@ -418,7 +357,7 @@ namespace
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(constraints_and_arguments_are_serialized_lazily, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(constraints_and_arguments_are_serialized_lazily, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -429,8 +368,7 @@ BOOST_FIXTURE_TEST_CASE( constraints_and_arguments_are_serialized_lazily, mock_e
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct custom_constraint_with_non_const_operator
|
struct custom_constraint_with_non_const_operator
|
||||||
{
|
{
|
||||||
template<typename Actual>
|
template<typename Actual>
|
||||||
|
|
@ -439,12 +377,13 @@ namespace
|
||||||
return actual == 42;
|
return actual == 42;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(custom_constraint_function_operator_does_not_need_to_be_const, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(custom_constraint_function_operator_does_not_need_to_be_const, mock_error_fixture)
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR(f, void(float));
|
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);
|
f(42);
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
@ -459,8 +398,7 @@ BOOST_FIXTURE_TEST_CASE( boost_reference_wrapper_is_supported_in_value_constrain
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void nothing(T)
|
void nothing(T)
|
||||||
{}
|
{}
|
||||||
|
|
@ -469,44 +407,40 @@ namespace
|
||||||
{
|
{
|
||||||
MOCK_CONST_METHOD_EXT(my_method, 0, void(), my_method)
|
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)
|
BOOST_FIXTURE_TEST_CASE(member_pointer_on_mock_method_is_valid, mock_error_fixture)
|
||||||
{
|
{
|
||||||
nothing(&member_pointer_mock_class::my_method);
|
nothing(&member_pointer_mock_class::my_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_FUNCTION(free_function, 1, void(int), free_function)
|
MOCK_FUNCTION(free_function, 1, void(int), free_function)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(a_free_function_can_be_mocked, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(a_free_function_can_be_mocked, mock_error_fixture)
|
||||||
{
|
{
|
||||||
MOCK_EXPECT(free_function).once();
|
MOCK_EXPECT(free_function).once();
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!MOCK_VERIFY(free_function)), "verification failed", 0,
|
||||||
BOOST_CHECK( ! MOCK_VERIFY( free_function ) ),
|
"free_function\n. once().with( any )");
|
||||||
"verification failed", 0, "free_function\n. once().with( any )" );
|
|
||||||
free_function(42);
|
free_function(42);
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
BOOST_CHECK(MOCK_VERIFY(free_function));
|
BOOST_CHECK(MOCK_VERIFY(free_function));
|
||||||
MOCK_RESET(free_function);
|
MOCK_RESET(free_function);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct some_class : mock::object
|
struct some_class : mock::object
|
||||||
{
|
{
|
||||||
MOCK_STATIC_METHOD(some_static_method, 1, void(int), some_static_method)
|
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)
|
BOOST_FIXTURE_TEST_CASE(a_static_method_can_be_mocked, mock_error_fixture)
|
||||||
{
|
{
|
||||||
MOCK_EXPECT(some_class::some_static_method).once();
|
MOCK_EXPECT(some_class::some_static_method).once();
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!MOCK_VERIFY(some_class::some_static_method)), "verification failed", 0,
|
||||||
BOOST_CHECK( ! MOCK_VERIFY( some_class::some_static_method ) ),
|
"some_class::some_static_method\n. once().with( any )");
|
||||||
"verification failed", 0, "some_class::some_static_method\n. once().with( any )" );
|
|
||||||
some_class::some_static_method(42);
|
some_class::some_static_method(42);
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
BOOST_CHECK(MOCK_VERIFY(some_class::some_static_method));
|
BOOST_CHECK(MOCK_VERIFY(some_class::some_static_method));
|
||||||
|
|
@ -518,27 +452,24 @@ BOOST_FIXTURE_TEST_CASE( a_static_method_is_not_reset_when_resetting_an_instance
|
||||||
MOCK_EXPECT(some_class::some_static_method).once();
|
MOCK_EXPECT(some_class::some_static_method).once();
|
||||||
some_class c;
|
some_class c;
|
||||||
mock::reset(c);
|
mock::reset(c);
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!MOCK_VERIFY(some_class::some_static_method)), "verification failed", 0,
|
||||||
BOOST_CHECK( ! MOCK_VERIFY( some_class::some_static_method ) ),
|
"some_class::some_static_method\n. once().with( any )");
|
||||||
"verification failed", 0, "some_class::some_static_method\n. once().with( any )" );
|
|
||||||
MOCK_RESET(some_class::some_static_method);
|
MOCK_RESET(some_class::some_static_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct some_template_class
|
struct some_template_class
|
||||||
{
|
{
|
||||||
MOCK_STATIC_METHOD_TPL(some_static_method, 1, void(T), some_static_method)
|
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)
|
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();
|
MOCK_EXPECT(some_template_class<int>::some_static_method).once();
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!MOCK_VERIFY(some_template_class<int>::some_static_method)), "verification failed", 0,
|
||||||
BOOST_CHECK( ! MOCK_VERIFY( some_template_class< int >::some_static_method ) ),
|
"some_template_class< int >::some_static_method\n. once().with( any )");
|
||||||
"verification failed", 0, "some_template_class< int >::some_static_method\n. once().with( any )" );
|
|
||||||
some_template_class<int>::some_static_method(42);
|
some_template_class<int>::some_static_method(42);
|
||||||
BOOST_CHECK(mock::verify());
|
BOOST_CHECK(mock::verify());
|
||||||
BOOST_CHECK(MOCK_VERIFY(some_template_class<int>::some_static_method));
|
BOOST_CHECK(MOCK_VERIFY(some_template_class<int>::some_static_method));
|
||||||
|
|
@ -546,13 +477,12 @@ BOOST_FIXTURE_TEST_CASE( a_static_method_in_a_template_class_can_be_mocked, mock
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_CLASS(mock_class)
|
MOCK_CLASS(mock_class)
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(m, 0, void(), t);
|
MOCK_METHOD_EXT(m, 0, void(), t);
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(resetting_referenced_mock_class_does_not_crash, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(resetting_referenced_mock_class_does_not_crash, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -565,13 +495,12 @@ BOOST_FIXTURE_TEST_CASE( resetting_referenced_mock_class_does_not_crash, mock_er
|
||||||
mock::reset();
|
mock::reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_CLASS(mock_class2)
|
MOCK_CLASS(mock_class2)
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(m, 0, mock_class2(), t);
|
MOCK_METHOD_EXT(m, 0, mock_class2(), t);
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(resetting_self_referenced_mock_class_does_not_crash, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(resetting_self_referenced_mock_class_does_not_crash, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -582,21 +511,18 @@ BOOST_FIXTURE_TEST_CASE( resetting_self_referenced_mock_class_does_not_crash, mo
|
||||||
mock::reset();
|
mock::reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct my_base
|
struct my_base
|
||||||
{};
|
{};
|
||||||
MOCK_BASE_CLASS( my_comma_mock, my_base< int BOOST_PP_COMMA() int > )
|
MOCK_BASE_CLASS(my_comma_mock, my_base<int BOOST_PP_COMMA() int>){};
|
||||||
{};
|
} // namespace
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef MOCK_THREAD_SAFE
|
#ifdef MOCK_THREAD_SAFE
|
||||||
|
|
||||||
# include <boost/thread.hpp>
|
# include <boost/thread.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
void create_class()
|
void create_class()
|
||||||
{
|
{
|
||||||
my_mock m;
|
my_mock m;
|
||||||
|
|
@ -604,11 +530,10 @@ namespace
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m.my_method(3);
|
m.my_method(3);
|
||||||
}
|
} catch(...)
|
||||||
catch( ... )
|
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_class_creation_is_thread_safe, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_class_creation_is_thread_safe, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -619,8 +544,7 @@ BOOST_FIXTURE_TEST_CASE( mock_class_creation_is_thread_safe, mock_error_fixture
|
||||||
CHECK_CALLS(100);
|
CHECK_CALLS(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
void create_functor(int i)
|
void create_functor(int i)
|
||||||
{
|
{
|
||||||
mock::detail::functor<void(int)> f;
|
mock::detail::functor<void(int)> f;
|
||||||
|
|
@ -630,11 +554,10 @@ namespace
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
f(i);
|
f(i);
|
||||||
}
|
} catch(...)
|
||||||
catch( ... )
|
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_functor_creation_is_thread_safe, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_functor_creation_is_thread_safe, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -645,14 +568,13 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_creation_is_thread_safe, mock_error_fixtur
|
||||||
CHECK_CALLS(100);
|
CHECK_CALLS(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
void iterate(my_mock& m)
|
void iterate(my_mock& m)
|
||||||
{
|
{
|
||||||
MOCK_EXPECT(m.my_tag).once().with(3).returns(42);
|
MOCK_EXPECT(m.my_tag).once().with(3).returns(42);
|
||||||
BOOST_CHECK_EQUAL(42, m.my_method(3));
|
BOOST_CHECK_EQUAL(42, m.my_method(3));
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_class_is_thread_safe, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_class_is_thread_safe, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -666,14 +588,13 @@ BOOST_FIXTURE_TEST_CASE( mock_class_is_thread_safe, mock_error_fixture )
|
||||||
|
|
||||||
#endif // MOCK_THREAD_SAFE
|
#endif // MOCK_THREAD_SAFE
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_CLASS(my_multi_mock)
|
MOCK_CLASS(my_multi_mock)
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(m1, 1, void(int), m1);
|
MOCK_METHOD_EXT(m1, 1, void(int), m1);
|
||||||
MOCK_METHOD_EXT(m2, 2, void(int, int), m2);
|
MOCK_METHOD_EXT(m2, 2, void(int, int), m2);
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_method_accepts_multi_constraint, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_method_accepts_multi_constraint, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -685,8 +606,7 @@ BOOST_FIXTURE_TEST_CASE( mock_method_accepts_multi_constraint, mock_error_fixtur
|
||||||
CHECK_CALLS(2);
|
CHECK_CALLS(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_polymorphic_constraint
|
struct my_polymorphic_constraint
|
||||||
{
|
{
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
|
|
@ -695,7 +615,7 @@ namespace
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_method_accepts_polymorphic_multi_constraint, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_method_accepts_polymorphic_multi_constraint, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -711,10 +631,7 @@ BOOST_FIXTURE_TEST_CASE( std_unique_ptr_argument_is_supported_in_action, mock_er
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR(f, void(std::unique_ptr<int>));
|
MOCK_FUNCTOR(f, void(std::unique_ptr<int>));
|
||||||
std::unique_ptr<int> p;
|
std::unique_ptr<int> p;
|
||||||
MOCK_EXPECT( f ).once().calls(
|
MOCK_EXPECT(f).once().calls([](std::unique_ptr<int>) {});
|
||||||
[]( std::unique_ptr< int > )
|
|
||||||
{
|
|
||||||
} );
|
|
||||||
f(std::unique_ptr<int>(new int(7)));
|
f(std::unique_ptr<int>(new int(7)));
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,17 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include <turtle/log.hpp>
|
#include <turtle/log.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/assign.hpp>
|
#include <boost/assign.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
#include <boost/weak_ptr.hpp>
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
# pragma warning(push, 0)
|
# pragma warning(push, 0)
|
||||||
#endif
|
#endif
|
||||||
#include <boost/phoenix/phoenix.hpp>
|
|
||||||
#include <boost/phoenix/bind.hpp>
|
#include <boost/phoenix/bind.hpp>
|
||||||
|
#include <boost/phoenix/phoenix.hpp>
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
# pragma warning(pop)
|
# pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -26,14 +26,13 @@
|
||||||
# include <boost/lambda/lambda.hpp>
|
# include <boost/lambda/lambda.hpp>
|
||||||
#endif
|
#endif
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <vector>
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string to_string(const T& t)
|
std::string to_string(const T& t)
|
||||||
{
|
{
|
||||||
|
|
@ -48,7 +47,7 @@ namespace
|
||||||
s << mock::format(t);
|
s << mock::format(t);
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(pointer_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(pointer_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
|
|
@ -81,34 +80,31 @@ BOOST_AUTO_TEST_CASE( strings_are_serialized_with_double_quotes )
|
||||||
BOOST_CHECK_EQUAL("\"string\"", to_string(std::string("string")));
|
BOOST_CHECK_EQUAL("\"string\"", to_string(std::string("string")));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct non_serializable
|
struct non_serializable
|
||||||
{};
|
{};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(non_serializable_type_yields_a_question_mark_when_serialized)
|
BOOST_AUTO_TEST_CASE(non_serializable_type_yields_a_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("?", to_string(non_serializable()));
|
BOOST_CHECK_EQUAL("?", to_string(non_serializable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct serializable
|
struct serializable
|
||||||
{};
|
{};
|
||||||
std::ostream& operator<<(std::ostream& s, const serializable&)
|
std::ostream& operator<<(std::ostream& s, const serializable&)
|
||||||
{
|
{
|
||||||
return s << "serializable";
|
return s << "serializable";
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(serializable_type_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(serializable_type_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("serializable", to_string(serializable()));
|
BOOST_CHECK_EQUAL("serializable", to_string(serializable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct streamable
|
struct streamable
|
||||||
{};
|
{};
|
||||||
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const streamable&)
|
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const streamable&)
|
||||||
|
|
@ -120,15 +116,14 @@ namespace
|
||||||
{
|
{
|
||||||
return s << "streamable";
|
return s << "streamable";
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(streamable_type_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(streamable_type_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("streamable", to_string(streamable()));
|
BOOST_CHECK_EQUAL("streamable", to_string(streamable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct mock_streamable
|
struct mock_streamable
|
||||||
{};
|
{};
|
||||||
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const mock_streamable&)
|
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const mock_streamable&)
|
||||||
|
|
@ -136,25 +131,23 @@ namespace
|
||||||
BOOST_FAIL("should not have been called");
|
BOOST_FAIL("should not have been called");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
stream& operator<<(stream& s, const mock_streamable&)
|
stream& operator<<(stream& s, const mock_streamable&)
|
||||||
{
|
{
|
||||||
return s << "mock_streamable";
|
return s << "mock_streamable";
|
||||||
}
|
}
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(mock_streamable_type_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(mock_streamable_type_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("mock_streamable", to_string(mock_streamable()));
|
BOOST_CHECK_EQUAL("mock_streamable", to_string(mock_streamable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct derived_from_serializable : serializable
|
struct derived_from_serializable : serializable
|
||||||
{};
|
{};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_derived_from_serializable_yields_a_question_mark_when_serialized)
|
BOOST_AUTO_TEST_CASE(type_derived_from_serializable_yields_a_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
|
|
@ -165,11 +158,10 @@ BOOST_AUTO_TEST_CASE( type_derived_from_serializable_yields_a_question_mark_when
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct derived_from_streamable : streamable
|
struct derived_from_streamable : streamable
|
||||||
{};
|
{};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_derived_from_streamable_yields_a_question_mark_when_serialized)
|
BOOST_AUTO_TEST_CASE(type_derived_from_streamable_yields_a_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
|
|
@ -180,79 +172,77 @@ BOOST_AUTO_TEST_CASE( type_derived_from_streamable_yields_a_question_mark_when_s
|
||||||
#endif
|
#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
|
struct convertible_to_base
|
||||||
{
|
{
|
||||||
operator int() const;
|
operator int() const;
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_convertible_to_base_yields_a_question_mark_when_serialized)
|
BOOST_AUTO_TEST_CASE(type_convertible_to_base_yields_a_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("?", to_string(convertible_to_base()));
|
BOOST_CHECK_EQUAL("?", to_string(convertible_to_base()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct convertible_to_serializable
|
struct convertible_to_serializable
|
||||||
{
|
{
|
||||||
operator serializable() const;
|
operator serializable() const;
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_convertible_to_serializable_yields_a_question_mark_when_serialized)
|
BOOST_AUTO_TEST_CASE(type_convertible_to_serializable_yields_a_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("?", to_string(convertible_to_serializable()));
|
BOOST_CHECK_EQUAL("?", to_string(convertible_to_serializable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct convertible_to_streamable
|
struct convertible_to_streamable
|
||||||
{
|
{
|
||||||
operator streamable() const;
|
operator streamable() const;
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_convertible_to_streamable_yields_a_question_mark_when_serialized)
|
BOOST_AUTO_TEST_CASE(type_convertible_to_streamable_yields_a_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("?", to_string(convertible_to_streamable()));
|
BOOST_CHECK_EQUAL("?", to_string(convertible_to_streamable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct ambiguous_convertible
|
struct ambiguous_convertible
|
||||||
{
|
{
|
||||||
operator float() const;
|
operator float() const;
|
||||||
operator int() const;
|
operator int() const;
|
||||||
operator serializable() const;
|
operator serializable() const;
|
||||||
operator streamable() 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_AUTO_TEST_CASE(type_ambiguous_convertible_yields_a_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("?", to_string(ambiguous_convertible()));
|
BOOST_CHECK_EQUAL("?", to_string(ambiguous_convertible()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct ambiguous_convertible_serializable
|
struct ambiguous_convertible_serializable
|
||||||
{
|
{
|
||||||
operator float() const;
|
operator float() const;
|
||||||
operator int() const;
|
operator int() const;
|
||||||
operator serializable() const;
|
operator serializable() const;
|
||||||
operator streamable() 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&)
|
std::ostream& operator<<(std::ostream& s, const ambiguous_convertible_serializable&)
|
||||||
{
|
{
|
||||||
return s << "ambiguous_convertible_serializable";
|
return s << "ambiguous_convertible_serializable";
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_convertible_serializable_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(type_convertible_serializable_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
|
|
@ -261,15 +251,15 @@ BOOST_AUTO_TEST_CASE( type_convertible_serializable_yields_its_value_when_serial
|
||||||
|
|
||||||
#endif // MOCK_USE_CONVERSIONS
|
#endif // MOCK_USE_CONVERSIONS
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct ambiguous_convertible_streamable
|
struct ambiguous_convertible_streamable
|
||||||
{
|
{
|
||||||
operator float() const;
|
operator float() const;
|
||||||
operator int() const;
|
operator int() const;
|
||||||
operator serializable() const;
|
operator serializable() const;
|
||||||
operator streamable() 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&)
|
BOOST_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const ambiguous_convertible_streamable&)
|
||||||
{
|
{
|
||||||
|
|
@ -280,44 +270,42 @@ namespace
|
||||||
{
|
{
|
||||||
return s << "ambiguous_convertible_streamable";
|
return s << "ambiguous_convertible_streamable";
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_ambiguous_convertible_streamable_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(type_ambiguous_convertible_streamable_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("ambiguous_convertible_streamable", to_string(ambiguous_convertible_streamable()));
|
BOOST_CHECK_EQUAL("ambiguous_convertible_streamable", to_string(ambiguous_convertible_streamable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct ambiguous_convertible_mock_streamable
|
struct ambiguous_convertible_mock_streamable
|
||||||
{
|
{
|
||||||
operator float() const;
|
operator float() const;
|
||||||
operator int() const;
|
operator int() const;
|
||||||
operator serializable() const;
|
operator serializable() const;
|
||||||
operator streamable() 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_ATTRIBUTE_UNUSED std::ostream& operator<<(std::ostream& s, const ambiguous_convertible_mock_streamable&)
|
||||||
{
|
{
|
||||||
BOOST_FAIL("should not have been called");
|
BOOST_FAIL("should not have been called");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
stream& operator<<(stream& s, const ambiguous_convertible_mock_streamable&)
|
stream& operator<<(stream& s, const ambiguous_convertible_mock_streamable&)
|
||||||
{
|
{
|
||||||
return s << "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_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()));
|
BOOST_CHECK_EQUAL("ambiguous_convertible_mock_streamable", to_string(ambiguous_convertible_mock_streamable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct template_serializable
|
struct template_serializable
|
||||||
{};
|
{};
|
||||||
|
|
@ -326,15 +314,14 @@ namespace
|
||||||
{
|
{
|
||||||
return s << "template_serializable";
|
return s << "template_serializable";
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(template_type_serializable_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(template_type_serializable_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("template_serializable", to_string(template_serializable<int>()));
|
BOOST_CHECK_EQUAL("template_serializable", to_string(template_serializable<int>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct template_streamable
|
struct template_streamable
|
||||||
{};
|
{};
|
||||||
|
|
@ -349,15 +336,14 @@ namespace
|
||||||
{
|
{
|
||||||
return s << "template_streamable";
|
return s << "template_streamable";
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(template_template_streamable_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(template_template_streamable_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("template_streamable", to_string(template_streamable<int>()));
|
BOOST_CHECK_EQUAL("template_streamable", to_string(template_streamable<int>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct template_mock_streamable
|
struct template_mock_streamable
|
||||||
{};
|
{};
|
||||||
|
|
@ -367,15 +353,14 @@ namespace
|
||||||
BOOST_FAIL("should not have been called");
|
BOOST_FAIL("should not have been called");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
namespace mock
|
namespace mock {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
stream& operator<<(stream& s, const template_mock_streamable<T>&)
|
stream& operator<<(stream& s, const template_mock_streamable<T>&)
|
||||||
{
|
{
|
||||||
return s << "template_mock_streamable";
|
return s << "template_mock_streamable";
|
||||||
}
|
}
|
||||||
} // mock
|
} // namespace mock
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(template_mock_streamable_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(template_mock_streamable_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
|
|
@ -528,11 +513,9 @@ BOOST_AUTO_TEST_CASE( boost_reference_wrappers_are_serialized )
|
||||||
BOOST_CHECK_EQUAL("\"string\"", to_string(boost::cref("string")));
|
BOOST_CHECK_EQUAL("\"string\"", to_string(boost::cref("string")));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
void callable_builtin() {}
|
||||||
void callable_builtin()
|
} // namespace
|
||||||
{}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(callable_builtin_yields_a_question_mark_when_serialized)
|
BOOST_AUTO_TEST_CASE(callable_builtin_yields_a_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
|
|
@ -540,55 +523,49 @@ BOOST_AUTO_TEST_CASE( callable_builtin_yields_a_question_mark_when_serialized )
|
||||||
BOOST_CHECK_EQUAL("?", to_string(&callable_builtin));
|
BOOST_CHECK_EQUAL("?", to_string(&callable_builtin));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct serialized_using_format
|
struct serialized_using_format
|
||||||
{};
|
{};
|
||||||
std::ostream& operator<<(std::ostream& s, const serialized_using_format&)
|
std::ostream& operator<<(std::ostream& s, const serialized_using_format&)
|
||||||
{
|
{
|
||||||
return s << mock::format("string");
|
return s << mock::format("string");
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_can_use_format_when_serialized)
|
BOOST_AUTO_TEST_CASE(type_can_use_format_when_serialized)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("\"string\"", to_string(serialized_using_format()));
|
BOOST_CHECK_EQUAL("\"string\"", to_string(serialized_using_format()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct streamed_using_format
|
struct streamed_using_format
|
||||||
{};
|
{};
|
||||||
mock::stream& operator<<(mock::stream& s, const streamed_using_format&)
|
mock::stream& operator<<(mock::stream& s, const streamed_using_format&)
|
||||||
{
|
{
|
||||||
return s << mock::format("string");
|
return s << mock::format("string");
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(type_can_use_format_when_streamed)
|
BOOST_AUTO_TEST_CASE(type_can_use_format_when_streamed)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("\"string\"", to_string(streamed_using_format()));
|
BOOST_CHECK_EQUAL("\"string\"", to_string(streamed_using_format()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct std_string_streamed
|
struct std_string_streamed
|
||||||
{};
|
{};
|
||||||
mock::stream& operator<<(mock::stream& s, const std_string_streamed&)
|
mock::stream& operator<<(mock::stream& s, const std_string_streamed&)
|
||||||
{
|
{
|
||||||
return s << std::string("string");
|
return s << std::string("string");
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(std_string_streamed_is_not_a_container)
|
BOOST_AUTO_TEST_CASE(std_string_streamed_is_not_a_container)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL("string", to_string(std_string_streamed()));
|
BOOST_CHECK_EQUAL("string", to_string(std_string_streamed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct template_serializable
|
struct template_serializable
|
||||||
{};
|
{};
|
||||||
|
|
@ -597,18 +574,14 @@ namespace detail
|
||||||
{
|
{
|
||||||
return s << "mock::detail::template_serializable";
|
return s << "mock::detail::template_serializable";
|
||||||
}
|
}
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(mock_detail_template_type_serializable_yields_its_value_when_serialized)
|
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>()));
|
BOOST_CHECK_EQUAL("mock::detail::template_serializable", to_string(mock::detail::template_serializable<int>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace mock
|
namespace mock { namespace detail {
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct template_streamable
|
struct template_streamable
|
||||||
{};
|
{};
|
||||||
|
|
@ -623,8 +596,7 @@ namespace detail
|
||||||
{
|
{
|
||||||
return s << "mock::detail::template_streamable";
|
return s << "mock::detail::template_streamable";
|
||||||
}
|
}
|
||||||
}
|
}} // namespace mock::detail
|
||||||
} // mock
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(mock_detail_template_template_streamable_yields_its_value_when_serialized)
|
BOOST_AUTO_TEST_CASE(mock_detail_template_template_streamable_yields_its_value_when_serialized)
|
||||||
{
|
{
|
||||||
|
|
@ -636,13 +608,12 @@ BOOST_AUTO_TEST_CASE( unsigned_char_is_serialized_as_int )
|
||||||
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<int>('a')), to_string<unsigned char>('a'));
|
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<int>('a')), to_string<unsigned char>('a'));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
bool some_function()
|
bool some_function()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(boost_phoenix_functor_yields_question_mark_when_serialized)
|
BOOST_AUTO_TEST_CASE(boost_phoenix_functor_yields_question_mark_when_serialized)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,13 @@
|
||||||
#include <turtle/detail/function.hpp>
|
#include <turtle/detail/function.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename Expected, typename Actual>
|
template<typename Expected, typename Actual>
|
||||||
bool match(Expected expected, Actual actual)
|
bool match(Expected expected, Actual actual)
|
||||||
{
|
{
|
||||||
return mock::matcher<Actual, Expected>(expected)(actual);
|
return mock::matcher<Actual, Expected>(expected)(actual);
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(int_and_int_can_be_compared)
|
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, boost::cref(i)));
|
BOOST_CHECK(!match(4, boost::cref(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct fixture
|
struct fixture
|
||||||
{
|
{
|
||||||
fixture()
|
fixture() : text("same text"), actual(text.c_str())
|
||||||
: text( "same text" )
|
|
||||||
, actual( text.c_str() )
|
|
||||||
{
|
{
|
||||||
const char* static_string = "same text";
|
const char* static_string = "same text";
|
||||||
BOOST_REQUIRE(actual != static_string);
|
BOOST_REQUIRE(actual != static_string);
|
||||||
|
|
@ -47,7 +43,7 @@ namespace
|
||||||
std::string text;
|
std::string text;
|
||||||
const char* actual;
|
const char* actual;
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_pointer_can_be_compared, fixture)
|
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_pointer_can_be_compared, fixture)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,18 @@
|
||||||
|
|
||||||
#include "mock_error.hpp"
|
#include "mock_error.hpp"
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/preprocessor/repetition/enum.hpp>
|
#include <boost/preprocessor/repetition/enum.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
#define IDENTITY(z, n, d) d
|
#define IDENTITY(z, n, d) d
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_custom_mock
|
struct my_custom_mock
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(method, MOCK_MAX_ARGS, void(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag)
|
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)
|
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)
|
BOOST_FIXTURE_TEST_CASE(call_mock_method_with_max_number_of_args, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,22 +8,18 @@
|
||||||
|
|
||||||
#include "mock_error.hpp"
|
#include "mock_error.hpp"
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void my_function(T& t)
|
void my_function(T& t)
|
||||||
{
|
{
|
||||||
t.my_method("some parameter");
|
t.my_method("some parameter");
|
||||||
}
|
}
|
||||||
MOCK_CLASS( mock_class )
|
MOCK_CLASS(mock_class){MOCK_METHOD_EXT(my_method, 1, void(const std::string&), my_tag)};
|
||||||
{
|
} // namespace
|
||||||
MOCK_METHOD_EXT( my_method, 1, void( const std::string& ), my_tag )
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_object_for_static_polymorphism, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_object_for_static_polymorphism, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -33,12 +29,8 @@ BOOST_FIXTURE_TEST_CASE( mock_object_for_static_polymorphism, mock_error_fixture
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(mock_class_with_operator){MOCK_CONST_METHOD_EXT(operator+=, 1, mock_class_with_operator &(int), addition)};
|
||||||
MOCK_CLASS( mock_class_with_operator )
|
|
||||||
{
|
|
||||||
MOCK_CONST_METHOD_EXT( operator+=, 1, mock_class_with_operator&( int ), addition )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_addition_operator, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_addition_operator, mock_error_fixture)
|
||||||
|
|
@ -49,12 +41,8 @@ BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture )
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(mock_class_with_conversion_operator){MOCK_CONVERSION_OPERATOR(operator, int, conversion)};
|
||||||
MOCK_CLASS( mock_class_with_conversion_operator )
|
|
||||||
{
|
|
||||||
MOCK_CONVERSION_OPERATOR( operator, int, conversion )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_conversion_operator, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_conversion_operator, mock_error_fixture)
|
||||||
|
|
@ -65,13 +53,9 @@ BOOST_FIXTURE_TEST_CASE( mock_conversion_operator, mock_error_fixture )
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_CLASS( mock_template_class_with_conversion_operator )
|
MOCK_CLASS(mock_template_class_with_conversion_operator){MOCK_CONVERSION_OPERATOR_TPL(operator, T, conversion)};
|
||||||
{
|
|
||||||
MOCK_CONVERSION_OPERATOR_TPL( operator, T, conversion )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture)
|
||||||
|
|
@ -82,12 +66,8 @@ BOOST_FIXTURE_TEST_CASE( mock_template_conversion_operator, mock_error_fixture )
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(mock_class_with_const_conversion_operator){MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion)};
|
||||||
MOCK_CLASS( mock_class_with_const_conversion_operator )
|
|
||||||
{
|
|
||||||
MOCK_CONST_CONVERSION_OPERATOR( operator, int, conversion )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_const_conversion_operator, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_const_conversion_operator, mock_error_fixture)
|
||||||
|
|
@ -99,12 +79,8 @@ BOOST_FIXTURE_TEST_CASE( mock_const_conversion_operator, mock_error_fixture )
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(mock_class_with_non_const_conversion_operator){MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion)};
|
||||||
MOCK_CLASS( mock_class_with_non_const_conversion_operator )
|
|
||||||
{
|
|
||||||
MOCK_CONST_CONVERSION_OPERATOR( operator, int, conversion )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_non_const_conversion_operator, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_non_const_conversion_operator, mock_error_fixture)
|
||||||
|
|
@ -116,13 +92,10 @@ BOOST_FIXTURE_TEST_CASE( mock_non_const_conversion_operator, mock_error_fixture
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_CLASS( mock_template_class_with_const_conversion_operator )
|
MOCK_CLASS(mock_template_class_with_const_conversion_operator){
|
||||||
{
|
MOCK_CONST_CONVERSION_OPERATOR_TPL(operator, T, conversion)};
|
||||||
MOCK_CONST_CONVERSION_OPERATOR_TPL( operator, T, conversion )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_template_const_conversion_operator, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_template_const_conversion_operator, mock_error_fixture)
|
||||||
|
|
@ -133,13 +106,10 @@ BOOST_FIXTURE_TEST_CASE( mock_template_const_conversion_operator, mock_error_fix
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_CLASS( mock_template_class_with_non_const_conversion_operator )
|
MOCK_CLASS(mock_template_class_with_non_const_conversion_operator){
|
||||||
{
|
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(operator, T, conversion)};
|
||||||
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL( operator, T, conversion )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_template_non_const_conversion_operator, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_template_non_const_conversion_operator, mock_error_fixture)
|
||||||
|
|
@ -150,13 +120,9 @@ BOOST_FIXTURE_TEST_CASE( mock_template_non_const_conversion_operator, mock_error
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
MOCK_CLASS(my_mock){MOCK_CONST_METHOD_EXT(my_method, 1, void(int), my_method)
|
||||||
MOCK_CLASS( my_mock )
|
MOCK_CONST_METHOD_EXT(my_method_2, 1, void(int), my_method_2)};
|
||||||
{
|
|
||||||
MOCK_CONST_METHOD_EXT( my_method, 1, void( int ), my_method )
|
|
||||||
MOCK_CONST_METHOD_EXT( my_method_2, 1, void( int ), my_method_2 )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture)
|
||||||
|
|
@ -185,8 +151,7 @@ BOOST_FIXTURE_TEST_CASE( MOCK_EXPECT_macro, mock_error_fixture )
|
||||||
CHECK_CALLS(1);
|
CHECK_CALLS(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string to_string(const T& t)
|
std::string to_string(const T& t)
|
||||||
{
|
{
|
||||||
|
|
@ -194,7 +159,7 @@ namespace
|
||||||
s << t;
|
s << t;
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_object_is_named, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_object_is_named, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -247,16 +212,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)));
|
BOOST_CHECK_EQUAL("m->my_mock::my_method", to_string(MOCK_HELPER(m->my_method)));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct my_custom_mock
|
struct my_custom_mock
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
||||||
MOCK_METHOD_EXT(my_method_2, 0, void(), my_tag_2)
|
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;
|
my_custom_mock m;
|
||||||
BOOST_CHECK_EQUAL("?.my_custom_mock::my_tag", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag)));
|
BOOST_CHECK_EQUAL("?.my_custom_mock::my_tag", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag)));
|
||||||
|
|
@ -267,14 +232,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)));
|
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
|
struct my_custom_mock_object : mock::object
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
|
||||||
MOCK_METHOD_EXT(my_method_2, 0, void(), my_tag_2)
|
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)
|
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_is_named, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -293,14 +257,13 @@ BOOST_FIXTURE_TEST_CASE( mock_functor, mock_error_fixture )
|
||||||
MOCK_FUNCTOR(f2, int(const std::string&));
|
MOCK_FUNCTOR(f2, int(const std::string&));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct tpl_functor_class
|
struct tpl_functor_class
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR_TPL(f, void(T));
|
MOCK_FUNCTOR_TPL(f, void(T));
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_functor_reset, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_functor_reset, mock_error_fixture)
|
||||||
{
|
{
|
||||||
|
|
@ -322,8 +285,7 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_is_named, mock_error_fixture )
|
||||||
BOOST_CHECK_EQUAL("f", to_string(MOCK_HELPER(f)));
|
BOOST_CHECK_EQUAL("f", to_string(MOCK_HELPER(f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_FUNCTION(mock_function, 1, float(int), mock_function)
|
MOCK_FUNCTION(mock_function, 1, float(int), mock_function)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,12 +294,8 @@ BOOST_FIXTURE_TEST_CASE( mock_function_is_named, mock_error_fixture )
|
||||||
BOOST_CHECK_EQUAL("mock_function", to_string(MOCK_HELPER(mock_function)));
|
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)};
|
||||||
MOCK_CLASS( static_function_class )
|
|
||||||
{
|
|
||||||
MOCK_STATIC_METHOD( f, 1, float( int ), f )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(mock_static_function_is_named, mock_error_fixture)
|
BOOST_FIXTURE_TEST_CASE(mock_static_function_is_named, mock_error_fixture)
|
||||||
|
|
@ -345,8 +303,7 @@ 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)));
|
BOOST_CHECK_EQUAL("static_function_class::f", to_string(MOCK_HELPER(static_function_class::f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
MOCK_CLASS(round_parenthesized_signature)
|
MOCK_CLASS(round_parenthesized_signature)
|
||||||
{
|
{
|
||||||
MOCK_METHOD_EXT(m0, 0, BOOST_IDENTITY_TYPE((std::map<int, int>())), m0)
|
MOCK_METHOD_EXT(m0, 0, BOOST_IDENTITY_TYPE((std::map<int, int>())), m0)
|
||||||
|
|
@ -354,84 +311,57 @@ namespace
|
||||||
MOCK_FUNCTOR(f0, BOOST_IDENTITY_TYPE((std::map<int, int>())));
|
MOCK_FUNCTOR(f0, BOOST_IDENTITY_TYPE((std::map<int, int>())));
|
||||||
};
|
};
|
||||||
MOCK_FUNCTION(fun0, 0, BOOST_IDENTITY_TYPE((std::map<int, int>())), fun0)
|
MOCK_FUNCTION(fun0, 0, BOOST_IDENTITY_TYPE((std::map<int, int>())), fun0)
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
#ifdef MOCK_VARIADIC_MACROS
|
#ifdef MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct base
|
struct base
|
||||||
{
|
{
|
||||||
virtual ~base()
|
virtual ~base() {}
|
||||||
{}
|
|
||||||
|
|
||||||
virtual void m1() = 0;
|
virtual void m1() = 0;
|
||||||
virtual void m10() const = 0;
|
virtual void m10() const = 0;
|
||||||
virtual void m11() = 0;
|
virtual void m11() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( variadic, base )
|
MOCK_BASE_CLASS(variadic, base){MOCK_METHOD(m1, 0) MOCK_METHOD(m2, 0, void()) MOCK_METHOD(m3, 0, void(), m3)
|
||||||
{
|
MOCK_CONST_METHOD(m10, 0) MOCK_CONST_METHOD(m4, 0, void())
|
||||||
MOCK_METHOD( m1, 0 )
|
MOCK_CONST_METHOD(m5, 0, void(), m5) MOCK_NON_CONST_METHOD(m11, 0)
|
||||||
MOCK_METHOD( m2, 0, void() )
|
MOCK_NON_CONST_METHOD(m6, 0, void()) MOCK_NON_CONST_METHOD(m7, 0, void(), m7)
|
||||||
MOCK_METHOD( m3, 0, void(), m3 )
|
MOCK_STATIC_METHOD(m8, 0, void()) MOCK_STATIC_METHOD(m9, 0, void(), m9)};
|
||||||
MOCK_CONST_METHOD( m10, 0 )
|
|
||||||
MOCK_CONST_METHOD( m4, 0, void() )
|
|
||||||
MOCK_CONST_METHOD( m5, 0, void(), m5 )
|
|
||||||
MOCK_NON_CONST_METHOD( m11, 0 )
|
|
||||||
MOCK_NON_CONST_METHOD( m6, 0, void() )
|
|
||||||
MOCK_NON_CONST_METHOD( m7, 0, void(), m7 )
|
|
||||||
MOCK_STATIC_METHOD( m8, 0, void() )
|
|
||||||
MOCK_STATIC_METHOD( m9, 0, void(), m9 )
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_BASE_CLASS( variadic_tpl, base )
|
MOCK_BASE_CLASS(variadic_tpl, base){MOCK_METHOD(m1, 0, void()) MOCK_METHOD_TPL(m2, 0, T())
|
||||||
{
|
MOCK_METHOD_TPL(m3, 0, T(), m3) MOCK_CONST_METHOD_TPL(m4, 0, T())
|
||||||
MOCK_METHOD( m1, 0, void() )
|
MOCK_CONST_METHOD_TPL(m5, 0, T(), m5) MOCK_NON_CONST_METHOD_TPL(m6, 0, T())
|
||||||
MOCK_METHOD_TPL( m2, 0, T() )
|
MOCK_NON_CONST_METHOD_TPL(m7, 0, T(), m7) MOCK_STATIC_METHOD_TPL(m8, 0, T())
|
||||||
MOCK_METHOD_TPL( m3, 0, T(), m3 )
|
MOCK_STATIC_METHOD_TPL(m9, 0, T(), m9)};
|
||||||
MOCK_CONST_METHOD_TPL( m4, 0, T() )
|
|
||||||
MOCK_CONST_METHOD_TPL( m5, 0, T(), m5 )
|
|
||||||
MOCK_NON_CONST_METHOD_TPL( m6, 0, T() )
|
|
||||||
MOCK_NON_CONST_METHOD_TPL( m7, 0, T(), m7 )
|
|
||||||
MOCK_STATIC_METHOD_TPL( m8, 0, T() )
|
|
||||||
MOCK_STATIC_METHOD_TPL( m9, 0, T(), m9 )
|
|
||||||
};
|
|
||||||
|
|
||||||
MOCK_BASE_CLASS( comma_base, std::map< int, int > )
|
MOCK_BASE_CLASS(comma_base, std::map<int, int>){};
|
||||||
{};
|
|
||||||
|
|
||||||
MOCK_FUNCTION(fun1, 0, void())
|
MOCK_FUNCTION(fun1, 0, void())
|
||||||
MOCK_FUNCTION(fun2, 0, void(), fun2)
|
MOCK_FUNCTION(fun2, 0, void(), fun2)
|
||||||
MOCK_FUNCTION(fun3, 0, BOOST_IDENTITY_TYPE((std::map<int, int>())))
|
MOCK_FUNCTION(fun3, 0, BOOST_IDENTITY_TYPE((std::map<int, int>())))
|
||||||
|
|
||||||
MOCK_FUNCTOR(f_variadic, std::map<int, int>());
|
MOCK_FUNCTOR(f_variadic, std::map<int, int>());
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
#else // MOCK_VARIADIC_MACROS
|
#else // MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct base
|
struct base
|
||||||
{
|
{
|
||||||
virtual ~base()
|
virtual ~base() {}
|
||||||
{}
|
|
||||||
|
|
||||||
virtual void m1() = 0;
|
virtual void m1() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( derived, base )
|
MOCK_BASE_CLASS(derived, base){MOCK_METHOD(m1, 0)};
|
||||||
{
|
|
||||||
MOCK_METHOD( m1, 0 )
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MOCK_BASE_CLASS( derived_tpl, base )
|
MOCK_BASE_CLASS(derived_tpl, base){MOCK_METHOD_EXT(m1, 0, void(), m1)};
|
||||||
{
|
} // namespace
|
||||||
MOCK_METHOD_EXT( m1, 0, void(), m1 )
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // MOCK_VARIADIC_MACROS
|
#endif // MOCK_VARIADIC_MACROS
|
||||||
|
|
||||||
|
|
@ -441,28 +371,22 @@ namespace
|
||||||
# define MOCK_STDCALL
|
# define MOCK_STDCALL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace stdcall
|
namespace stdcall {
|
||||||
{
|
|
||||||
struct base
|
struct base
|
||||||
{
|
{
|
||||||
virtual ~base()
|
virtual ~base() {}
|
||||||
{}
|
|
||||||
|
|
||||||
virtual void MOCK_STDCALL m1() = 0;
|
virtual void MOCK_STDCALL m1() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
MOCK_BASE_CLASS( derived, base )
|
MOCK_BASE_CLASS(derived, base){
|
||||||
{
|
MOCK_CONSTRUCTOR(MOCK_STDCALL derived, 0, (), derived) MOCK_DESTRUCTOR(MOCK_STDCALL ~derived, derived)
|
||||||
MOCK_CONSTRUCTOR( MOCK_STDCALL derived, 0, (), derived )
|
MOCK_CONVERSION_OPERATOR(MOCK_STDCALL operator, int, to_int) MOCK_METHOD_EXT(MOCK_STDCALL m1, 0, void(), m1)
|
||||||
MOCK_DESTRUCTOR( MOCK_STDCALL ~derived, derived )
|
|
||||||
MOCK_CONVERSION_OPERATOR( MOCK_STDCALL operator, int, to_int )
|
|
||||||
MOCK_METHOD_EXT( MOCK_STDCALL m1, 0, void(), m1 )
|
|
||||||
MOCK_METHOD_EXT(MOCK_STDCALL m2, 0, void(), m2)
|
MOCK_METHOD_EXT(MOCK_STDCALL m2, 0, void(), m2)
|
||||||
#ifdef MOCK_VARIADIC_MACROS
|
#ifdef MOCK_VARIADIC_MACROS
|
||||||
MOCK_METHOD(MOCK_STDCALL m3, 0, void(), m3)
|
MOCK_METHOD(MOCK_STDCALL m3, 0, void(), m3)
|
||||||
#endif
|
#endif
|
||||||
MOCK_STATIC_METHOD( MOCK_STDCALL m4, 0, void(), m4 )
|
MOCK_STATIC_METHOD(MOCK_STDCALL m4, 0, void(), m4)};
|
||||||
};
|
|
||||||
|
|
||||||
MOCK_FUNCTION(MOCK_STDCALL f, 0, void(), f)
|
MOCK_FUNCTION(MOCK_STDCALL f, 0, void(), f)
|
||||||
}
|
} // namespace stdcall
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,18 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include "mock_error.hpp"
|
#include "mock_error.hpp"
|
||||||
|
#include <turtle/detail/function.hpp>
|
||||||
#include <turtle/reset.hpp>
|
#include <turtle/reset.hpp>
|
||||||
#include <turtle/verify.hpp>
|
#include <turtle/verify.hpp>
|
||||||
#include <turtle/detail/function.hpp>
|
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
|
||||||
#include <boost/scoped_ptr.hpp>
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct object : mock::object
|
struct object : mock::object
|
||||||
{};
|
{};
|
||||||
|
|
||||||
object static_o;
|
object static_o;
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(verifying_an_empty_object_succeeds, mock_error_fixture)
|
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));
|
BOOST_CHECK(mock::verify(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
|
||||||
struct fixture : mock_error_fixture
|
struct fixture : mock_error_fixture
|
||||||
{
|
{
|
||||||
fixture()
|
fixture() { mock::detail::configure(o, e, "instance", MOCK_TYPE_NAME(o), "name"); }
|
||||||
{
|
|
||||||
mock::detail::configure( o, e, "instance", MOCK_TYPE_NAME(o), "name" );
|
|
||||||
}
|
|
||||||
object o;
|
object o;
|
||||||
mock::detail::function<void()> e;
|
mock::detail::function<void()> e;
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(verifying_an_object_containing_a_failing_expectation_fails, fixture)
|
BOOST_FIXTURE_TEST_CASE(verifying_an_object_containing_a_failing_expectation_fails, fixture)
|
||||||
{
|
{
|
||||||
e.expect().once();
|
e.expect().once();
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!mock::verify(o)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||||
BOOST_CHECK( ! mock::verify( o ) ),
|
|
||||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
|
||||||
mock::reset(o);
|
mock::reset(o);
|
||||||
BOOST_CHECK(mock::verify(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)
|
BOOST_FIXTURE_TEST_CASE(verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails, fixture)
|
||||||
{
|
{
|
||||||
e.expect().once();
|
e.expect().once();
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!mock::verify()), "verification failed", 0, "instanceobject::name\n. once()");
|
||||||
BOOST_CHECK( ! mock::verify() ),
|
|
||||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
|
||||||
mock::reset();
|
mock::reset();
|
||||||
BOOST_CHECK(mock::verify());
|
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_TYPE_NAME(o2), "name");
|
mock::detail::configure(o2, e, "instance", MOCK_TYPE_NAME(o2), "name");
|
||||||
e.expect().once();
|
e.expect().once();
|
||||||
o1 = o2;
|
o1 = o2;
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||||
BOOST_CHECK( ! mock::verify( o1 ) ),
|
CHECK_ERROR(BOOST_CHECK(!mock::verify(o2)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
|
||||||
CHECK_ERROR(
|
|
||||||
BOOST_CHECK( ! mock::verify( o2 ) ),
|
|
||||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
|
||||||
}
|
}
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||||
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)
|
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::function<void()> e;
|
||||||
mock::detail::configure(*o2, e, "instance", MOCK_TYPE_NAME(*o2), "name");
|
mock::detail::configure(*o2, e, "instance", MOCK_TYPE_NAME(*o2), "name");
|
||||||
e.expect().once();
|
e.expect().once();
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!mock::verify(*o2)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||||
BOOST_CHECK( ! mock::verify( *o2 ) ),
|
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
|
||||||
CHECK_ERROR(
|
|
||||||
BOOST_CHECK( ! mock::verify( o1 ) ),
|
|
||||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
|
||||||
o2.reset();
|
o2.reset();
|
||||||
CHECK_ERROR(
|
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
|
||||||
BOOST_CHECK( ! mock::verify( o1 ) ),
|
|
||||||
"verification failed", 0, "instanceobject::name\n. once()" );
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include "mock_error.hpp"
|
#include "mock_error.hpp"
|
||||||
#include <turtle/sequence.hpp>
|
|
||||||
#include <turtle/detail/function.hpp>
|
#include <turtle/detail/function.hpp>
|
||||||
|
#include <turtle/sequence.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_and_calling_out_of_order_throws, mock_error_fixture)
|
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 )");
|
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::sequence s;
|
||||||
mock::detail::function<void(int)> e;
|
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);
|
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::sequence s;
|
||||||
mock::detail::function<void()> e1, e2;
|
mock::detail::function<void()> e1, e2;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue