Revision: 148
Author: trevor.pounds
Date: Tue Oct 30 03:53:45 2012
Log: mockitopp:
* Fix compile error when verifying function invocations (Fixes 9)
* Function invocations are correctly computed based on when(...) arguments
* Misc. cleanup
http://code.google.com/p/mockitopp/source/detail?r=148
Modified:
/trunk/include/mockitopp/detail/stubbing/dynamic_object.hpp
/trunk/include/mockitopp/detail/stubbing/dynamic_object.hpp.m4
/trunk/include/mockitopp/detail/stubbing/dynamic_vfunction.hpp
/trunk/include/mockitopp/detail/stubbing/dynamic_vfunction.hpp.m4
/trunk/include/mockitopp/mock_object.hpp
/trunk/test/src/TestArguments.cpp
/trunk/test/src/TestBasicStubbing.cpp
/trunk/test/src/TestSimpleComposite.cpp
/trunk/test/src/test_overloaded_functions.cpp
/trunk/test/src/test_verify.cpp
=======================================
--- /trunk/include/mockitopp/detail/stubbing/dynamic_object.hpp Sat Sep 29
00:40:54 2012
+++ /trunk/include/mockitopp/detail/stubbing/dynamic_object.hpp Tue Oct 30
03:53:45 2012
@@ -89,33 +89,33 @@
void* functions[50];
};
- vtable* vtable_ptr;
+ void* vtable_object_ptr;
void* vtable_mocks[50];
+ vtable* vtable_actual_ptr;
dynamic_object()
- : vtable_ptr(new vtable)
+ : vtable_actual_ptr(new vtable)
{
- vtable_ptr->vbase_offset = 0;
- vtable_ptr->vcall_offset = 0;
- vtable_ptr->offset_to_top = 0;
- vtable_ptr->type_info = 0;
+ vtable_actual_ptr->vbase_offset = 0;
+ vtable_actual_ptr->vcall_offset = 0;
+ vtable_actual_ptr->offset_to_top = 0;
+ vtable_actual_ptr->type_info = 0;
for(int i = 0; i < 50; i++)
{
- vtable_ptr->functions[i] =
horrible_cast<void*>(&dynamic_object::missing_vfunction);
+ vtable_actual_ptr->functions[i] =
horrible_cast<void*>(&dynamic_object::missing_vfunction);
vtable_mocks[i] = 0;
}
+ vtable_object_ptr = vtable_actual_ptr->functions;
}
~dynamic_object()
{
- // delete vtable_ptr->functions[i] not necessary, entries
point to statically defined functions
- vtable_ptr = (vtable*) (((char*) vtable_ptr) - sizeof(void*) *
4);
- delete vtable_ptr;
for(int i = 0; i < 50; i++)
{
if(vtable_mocks[i] != 0)
{ delete
reinterpret_cast<dynamic_vfunction_base*>(vtable_mocks[i]); }
}
+ delete vtable_actual_ptr;
}
template <typename M>
@@ -124,7 +124,7 @@
int offset = vtable_offset_helper::get(ptr2member);
if(vtable_mocks[offset] == 0)
{
- vtable_ptr->functions[offset] =
proxy_vfunction_factory<M>::get(ptr2member);
+ vtable_actual_ptr->functions[offset] =
proxy_vfunction_factory<M>::get(ptr2member);
vtable_mocks[offset] = new dynamic_vfunction<typename
remove_member_function_pointer_cv<M>::type>();
}
return *reinterpret_cast<dynamic_vfunction<typename
remove_member_function_pointer_cv<M>::type>*>(vtable_mocks[offset]);
=======================================
--- /trunk/include/mockitopp/detail/stubbing/dynamic_object.hpp.m4 Sat Sep
29 00:40:54 2012
+++ /trunk/include/mockitopp/detail/stubbing/dynamic_object.hpp.m4 Tue Oct
30 03:53:45 2012
@@ -43,33 +43,33 @@
void* functions[MOCKITOPP_MAX_VIRTUAL_FUNCTIONS];
};
- vtable* vtable_ptr;
+ void* vtable_object_ptr;
void* vtable_mocks[MOCKITOPP_MAX_VIRTUAL_FUNCTIONS];
+ vtable* vtable_actual_ptr;
dynamic_object()
- : vtable_ptr(new vtable)
+ : vtable_actual_ptr(new vtable)
{
- vtable_ptr->vbase_offset = 0;
- vtable_ptr->vcall_offset = 0;
- vtable_ptr->offset_to_top = 0;
- vtable_ptr->type_info = 0;
+ vtable_actual_ptr->vbase_offset = 0;
+ vtable_actual_ptr->vcall_offset = 0;
+ vtable_actual_ptr->offset_to_top = 0;
+ vtable_actual_ptr->type_info = 0;
for(int i = 0; i < MOCKITOPP_MAX_VIRTUAL_FUNCTIONS; i++)
{
- vtable_ptr->functions[i] =
horrible_cast<void*>(&dynamic_object::missing_vfunction);
+ vtable_actual_ptr->functions[i] =
horrible_cast<void*>(&dynamic_object::missing_vfunction);
vtable_mocks[i] = 0;
}
+ vtable_object_ptr = vtable_actual_ptr->functions;
}
~dynamic_object()
{
- // delete vtable_ptr->functions[i] not necessary, entries
point to statically defined functions
- vtable_ptr = (vtable*) (((char*) vtable_ptr) - sizeof(void*) *
4);
- delete vtable_ptr;
for(int i = 0; i < MOCKITOPP_MAX_VIRTUAL_FUNCTIONS; i++)
{
if(vtable_mocks[i] != 0)
{ delete
reinterpret_cast<dynamic_vfunction_base*>(vtable_mocks[i]); }
}
+ delete vtable_actual_ptr;
}
template <typename M>
@@ -78,7 +78,7 @@
int offset = vtable_offset_helper::get(ptr2member);
if(vtable_mocks[offset] == 0)
{
- vtable_ptr->functions[offset] =
proxy_vfunction_factory<M>::get(ptr2member);
+ vtable_actual_ptr->functions[offset] =
proxy_vfunction_factory<M>::get(ptr2member);
vtable_mocks[offset] = new dynamic_vfunction<typename
remove_member_function_pointer_cv<M>::type>();
}
return *reinterpret_cast<dynamic_vfunction<typename
remove_member_function_pointer_cv<M>::type>*>(vtable_mocks[offset]);
=======================================
--- /trunk/include/mockitopp/detail/stubbing/dynamic_vfunction.hpp Sat Sep
29 00:40:54 2012
+++ /trunk/include/mockitopp/detail/stubbing/dynamic_vfunction.hpp Tue Oct
30 03:53:45 2012
@@ -3,7 +3,6 @@
#include <algorithm>
#include <list>
-#include <utility>
#include <mockitopp/exceptions.hpp>
#include <mockitopp/detail/stubbing/action.hpp>
@@ -19,10 +18,6 @@
struct dynamic_vfunction_base
{
int calls;
-
- dynamic_vfunction_base()
- : calls(0)
- {}
// allow polymorphic desctruction with unknown subtype
virtual ~dynamic_vfunction_base() {}
@@ -72,63 +67,64 @@
};
template <typename R>
- struct dynamic_vfunction_action
+ struct dynamic_vfunction_progress : dynamic_vfunction_base
{
typedef shared_ptr<action<R> > action_type;
typedef std::list<action_type> action_queue_type;
- action_queue_type* transient_stubbing;
+ action_queue_type* stubbing_progress;
- dynamic_vfunction_action& thenReturn(R value)
+ dynamic_vfunction_progress& thenReturn(R value)
{
- transient_stubbing->push_back(action_type(new
returnable_action<R>(value)));
+ stubbing_progress->push_back(action_type(new
returnable_action<R>(value)));
return *this;
}
template <typename T>
- dynamic_vfunction_action& thenThrow(T throwable)
+ dynamic_vfunction_progress& thenThrow(T throwable)
{
- transient_stubbing->push_back(action_type(new
throwable_action<R, T>(throwable)));
+ stubbing_progress->push_back(action_type(new
throwable_action<R, T>(throwable)));
return *this;
}
};
template <>
- struct dynamic_vfunction_action<void>
+ struct dynamic_vfunction_progress<void> : dynamic_vfunction_base
{
typedef shared_ptr<action<void> > action_type;
typedef std::list<action_type> action_queue_type;
- action_queue_type* transient_stubbing;
+ action_queue_type* stubbing_progress;
- dynamic_vfunction_action& thenReturn()
+ dynamic_vfunction_progress& thenReturn()
{
- transient_stubbing->push_back(action_type(new
returnable_action<void>()));
+ stubbing_progress->push_back(action_type(new
returnable_action<void>()));
return *this;
}
template <typename T>
- dynamic_vfunction_action& thenThrow(T throwable)
+ dynamic_vfunction_progress& thenThrow(T throwable)
{
- transient_stubbing->push_back(action_type(new
throwable_action<void, T>(throwable)));
+ stubbing_progress->push_back(action_type(new
throwable_action<void, T>(throwable)));
return *this;
}
};
template <typename K, typename V>
- struct key_comparable_pair : public std::pair<K, V>
+ struct map_entry
{
- key_comparable_pair(const K& key, const V& pair)
- : std::pair<K, V>(key, pair)
- {}
+ K key;
+ V val;
- template <typename KRHS, typename VRHS>
- bool operator== (const key_comparable_pair<KRHS, VRHS>& rhs) const
- { return this->first == rhs.first; }
+ map_entry(const K& k, const V& v) : key(k), val(v) {}
- template <typename RHS>
- bool operator== (const RHS& rhs) const
- { return this->first == rhs; }
+ template <typename K2, typename V2>
+ bool operator== (const map_entry<K2, V2>& rhs) const
+ { return key == rhs.key; }
+
+ template <typename T>
+ bool operator== (const T& rhs) const
+ { return key == rhs; }
};
template <typename T>
@@ -163,58 +159,78 @@
// 0 arity template
template <typename R, typename C>
- struct dynamic_vfunction<R (C::*)()>
- : private dynamic_vfunction_action<R>
- , public dynamic_vfunction_base
+ struct dynamic_vfunction<R (C::*)()> : private
dynamic_vfunction_progress<R>
{
- typedef tr1::tuple<> raw_tuple_type;
- typedef tr1::tuple< > matcher_tuple_type;
+ typedef tr1::tuple<> exact_tuple_type;
+ typedef tr1::tuple< > fuzzy_tuple_type;
- typedef typename dynamic_vfunction_action<R>::action_type
action_type;
- typedef typename dynamic_vfunction_action<R>::action_queue_type
action_queue_type;
+ typedef typename dynamic_vfunction_progress<R>::action_type
action_type;
+ typedef typename dynamic_vfunction_progress<R>::action_queue_type
action_queue_type;
- std::list<key_comparable_pair<raw_tuple_type, action_queue_type>
> raw_actions_map;
- std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> > matcher_actions_map;
+ std::list<map_entry<exact_tuple_type, action_queue_type> >
exact_matches;
+ std::list<map_entry<fuzzy_tuple_type, action_queue_type> >
fuzzy_matches;
+ std::list<map_entry<exact_tuple_type, int> >
args_to_calls;
dynamic_vfunction()
- : dynamic_vfunction_action<R>()
- , dynamic_vfunction_base()
- , raw_actions_map()
- , matcher_actions_map()
+ : dynamic_vfunction_progress<R>()
+ , exact_matches()
+ , fuzzy_matches()
{}
+
+ template <typename T>
+ int calculate_calls_for_arguments(const T args) {
+ int calls = 0;
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = args_to_calls.begin();
+ for(; calls_it != args_to_calls.end(); calls_it++) {
+ if(args == calls_it->key) {
+ calls += calls_it->val;
+ }
+ }
+ return calls;
+ }
- dynamic_vfunction_action<R>& when()
+ dynamic_vfunction_progress<R>& when()
{
- raw_tuple_type args = raw_tuple_type();
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(raw_actions_map.begin(),
raw_actions_map.end(), args);
- if(pair_it == raw_actions_map.end())
+ const exact_tuple_type args = exact_tuple_type();
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(match == exact_matches.end())
{
-
raw_actions_map.push_back(key_comparable_pair<raw_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --raw_actions_map.end();
+ exact_matches.push_back(map_entry<exact_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --exact_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
R invoke()
{
- this->calls++;
- raw_tuple_type args = raw_tuple_type();
+ const exact_tuple_type args = exact_tuple_type();
+
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = std::find(args_to_calls.begin(), args_to_calls.end(),
args);
+ if(calls_it == args_to_calls.end()) {
+ args_to_calls.push_back(map_entry<exact_tuple_type,
int>(args, 1));
+ } else {
+ (calls_it->val)++;
+ }
+
action_queue_type* actions = 0;
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator raw_actions_it =
- std::find(raw_actions_map.begin(), raw_actions_map.end(),
args);
- if(raw_actions_it != raw_actions_map.end())
- { actions = &(raw_actions_it->second); }
- if(actions == 0)
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator exact_match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(exact_match != exact_matches.end())
+ { actions = &(exact_match->val); }
+ if(!actions)
{
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
- { throw partial_implementation_exception(); }
- actions = &(pair_it->second);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator fuzzy_match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(fuzzy_match == fuzzy_matches.end())
+ { throw partial_implementation_exception(); }
+ actions = &(fuzzy_match->val);
}
action_type action = actions->front();
if(actions->size() > 1)
@@ -225,70 +241,91 @@
// 1 arity template
template <typename R, typename C, typename A0>
- struct dynamic_vfunction<R (C::*)(A0)>
- : private dynamic_vfunction_action<R>
- , public dynamic_vfunction_base
+ struct dynamic_vfunction<R (C::*)(A0)> : private
dynamic_vfunction_progress<R>
{
- typedef tr1::tuple<A0> raw_tuple_type;
- typedef tr1::tuple<matcher_element<A0 > > matcher_tuple_type;
+ typedef tr1::tuple<A0> exact_tuple_type;
+ typedef tr1::tuple<matcher_element<A0 > > fuzzy_tuple_type;
- typedef typename dynamic_vfunction_action<R>::action_type
action_type;
- typedef typename dynamic_vfunction_action<R>::action_queue_type
action_queue_type;
+ typedef typename dynamic_vfunction_progress<R>::action_type
action_type;
+ typedef typename dynamic_vfunction_progress<R>::action_queue_type
action_queue_type;
- std::list<key_comparable_pair<raw_tuple_type, action_queue_type>
> raw_actions_map;
- std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> > matcher_actions_map;
+ std::list<map_entry<exact_tuple_type, action_queue_type> >
exact_matches;
+ std::list<map_entry<fuzzy_tuple_type, action_queue_type> >
fuzzy_matches;
+ std::list<map_entry<exact_tuple_type, int> >
args_to_calls;
dynamic_vfunction()
- : dynamic_vfunction_action<R>()
- , dynamic_vfunction_base()
- , raw_actions_map()
- , matcher_actions_map()
+ : dynamic_vfunction_progress<R>()
+ , exact_matches()
+ , fuzzy_matches()
{}
- dynamic_vfunction_action<R>& when(const matcher::Matcher<A0 >& a0)
+ template <typename T>
+ int calculate_calls_for_arguments(const T args) {
+ int calls = 0;
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = args_to_calls.begin();
+ for(; calls_it != args_to_calls.end(); calls_it++) {
+ if(args == calls_it->key) {
+ calls += calls_it->val;
+ }
+ }
+ return calls;
+ }
+
+ dynamic_vfunction_progress<R>& when(const matcher::Matcher<A0 >&
a0)
{
- matcher_tuple_type args = matcher_tuple_type(a0);
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
+ const fuzzy_tuple_type args = fuzzy_tuple_type(a0);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(match == fuzzy_matches.end())
{
-
matcher_actions_map.push_back(key_comparable_pair<matcher_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --matcher_actions_map.end();
+ fuzzy_matches.push_back(map_entry<fuzzy_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --fuzzy_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
- dynamic_vfunction_action<R>& when(A0 a0)
+ dynamic_vfunction_progress<R>& when(A0 a0)
{
- raw_tuple_type args = raw_tuple_type(a0);
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(raw_actions_map.begin(),
raw_actions_map.end(), args);
- if(pair_it == raw_actions_map.end())
+ const exact_tuple_type args = exact_tuple_type(a0);
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(match == exact_matches.end())
{
-
raw_actions_map.push_back(key_comparable_pair<raw_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --raw_actions_map.end();
+ exact_matches.push_back(map_entry<exact_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --exact_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
R invoke(A0 a0)
{
- this->calls++;
- raw_tuple_type args = raw_tuple_type(a0);
+ const exact_tuple_type args = exact_tuple_type(a0);
+
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = std::find(args_to_calls.begin(), args_to_calls.end(),
args);
+ if(calls_it == args_to_calls.end()) {
+ args_to_calls.push_back(map_entry<exact_tuple_type,
int>(args, 1));
+ } else {
+ (calls_it->val)++;
+ }
+
action_queue_type* actions = 0;
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator raw_actions_it =
- std::find(raw_actions_map.begin(), raw_actions_map.end(),
args);
- if(raw_actions_it != raw_actions_map.end())
- { actions = &(raw_actions_it->second); }
- if(actions == 0)
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator exact_match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(exact_match != exact_matches.end())
+ { actions = &(exact_match->val); }
+ if(!actions)
{
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
- { throw partial_implementation_exception(); }
- actions = &(pair_it->second);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator fuzzy_match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(fuzzy_match == fuzzy_matches.end())
+ { throw partial_implementation_exception(); }
+ actions = &(fuzzy_match->val);
}
action_type action = actions->front();
if(actions->size() > 1)
@@ -299,70 +336,91 @@
// 2 arity template
template <typename R, typename C, typename A0, typename A1>
- struct dynamic_vfunction<R (C::*)(A0, A1)>
- : private dynamic_vfunction_action<R>
- , public dynamic_vfunction_base
+ struct dynamic_vfunction<R (C::*)(A0, A1)> : private
dynamic_vfunction_progress<R>
{
- typedef tr1::tuple<A0, A1> raw_tuple_type;
- typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 > >
matcher_tuple_type;
+ typedef tr1::tuple<A0, A1> exact_tuple_type;
+ typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 > >
fuzzy_tuple_type;
- typedef typename dynamic_vfunction_action<R>::action_type
action_type;
- typedef typename dynamic_vfunction_action<R>::action_queue_type
action_queue_type;
+ typedef typename dynamic_vfunction_progress<R>::action_type
action_type;
+ typedef typename dynamic_vfunction_progress<R>::action_queue_type
action_queue_type;
- std::list<key_comparable_pair<raw_tuple_type, action_queue_type>
> raw_actions_map;
- std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> > matcher_actions_map;
+ std::list<map_entry<exact_tuple_type, action_queue_type> >
exact_matches;
+ std::list<map_entry<fuzzy_tuple_type, action_queue_type> >
fuzzy_matches;
+ std::list<map_entry<exact_tuple_type, int> >
args_to_calls;
dynamic_vfunction()
- : dynamic_vfunction_action<R>()
- , dynamic_vfunction_base()
- , raw_actions_map()
- , matcher_actions_map()
+ : dynamic_vfunction_progress<R>()
+ , exact_matches()
+ , fuzzy_matches()
{}
- dynamic_vfunction_action<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1)
+ template <typename T>
+ int calculate_calls_for_arguments(const T args) {
+ int calls = 0;
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = args_to_calls.begin();
+ for(; calls_it != args_to_calls.end(); calls_it++) {
+ if(args == calls_it->key) {
+ calls += calls_it->val;
+ }
+ }
+ return calls;
+ }
+
+ dynamic_vfunction_progress<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1)
{
- matcher_tuple_type args = matcher_tuple_type(a0, a1);
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
+ const fuzzy_tuple_type args = fuzzy_tuple_type(a0, a1);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(match == fuzzy_matches.end())
{
-
matcher_actions_map.push_back(key_comparable_pair<matcher_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --matcher_actions_map.end();
+ fuzzy_matches.push_back(map_entry<fuzzy_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --fuzzy_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
- dynamic_vfunction_action<R>& when(A0 a0, A1 a1)
+ dynamic_vfunction_progress<R>& when(A0 a0, A1 a1)
{
- raw_tuple_type args = raw_tuple_type(a0, a1);
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(raw_actions_map.begin(),
raw_actions_map.end(), args);
- if(pair_it == raw_actions_map.end())
+ const exact_tuple_type args = exact_tuple_type(a0, a1);
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(match == exact_matches.end())
{
-
raw_actions_map.push_back(key_comparable_pair<raw_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --raw_actions_map.end();
+ exact_matches.push_back(map_entry<exact_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --exact_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
R invoke(A0 a0, A1 a1)
{
- this->calls++;
- raw_tuple_type args = raw_tuple_type(a0, a1);
+ const exact_tuple_type args = exact_tuple_type(a0, a1);
+
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = std::find(args_to_calls.begin(), args_to_calls.end(),
args);
+ if(calls_it == args_to_calls.end()) {
+ args_to_calls.push_back(map_entry<exact_tuple_type,
int>(args, 1));
+ } else {
+ (calls_it->val)++;
+ }
+
action_queue_type* actions = 0;
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator raw_actions_it =
- std::find(raw_actions_map.begin(), raw_actions_map.end(),
args);
- if(raw_actions_it != raw_actions_map.end())
- { actions = &(raw_actions_it->second); }
- if(actions == 0)
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator exact_match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(exact_match != exact_matches.end())
+ { actions = &(exact_match->val); }
+ if(!actions)
{
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
- { throw partial_implementation_exception(); }
- actions = &(pair_it->second);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator fuzzy_match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(fuzzy_match == fuzzy_matches.end())
+ { throw partial_implementation_exception(); }
+ actions = &(fuzzy_match->val);
}
action_type action = actions->front();
if(actions->size() > 1)
@@ -373,70 +431,91 @@
// 3 arity template
template <typename R, typename C, typename A0, typename A1, typename
A2>
- struct dynamic_vfunction<R (C::*)(A0, A1, A2)>
- : private dynamic_vfunction_action<R>
- , public dynamic_vfunction_base
+ struct dynamic_vfunction<R (C::*)(A0, A1, A2)> : private
dynamic_vfunction_progress<R>
{
- typedef tr1::tuple<A0, A1, A2> raw_tuple_type;
- typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 >,
matcher_element<A2 > > matcher_tuple_type;
+ typedef tr1::tuple<A0, A1, A2> exact_tuple_type;
+ typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 >,
matcher_element<A2 > > fuzzy_tuple_type;
- typedef typename dynamic_vfunction_action<R>::action_type
action_type;
- typedef typename dynamic_vfunction_action<R>::action_queue_type
action_queue_type;
+ typedef typename dynamic_vfunction_progress<R>::action_type
action_type;
+ typedef typename dynamic_vfunction_progress<R>::action_queue_type
action_queue_type;
- std::list<key_comparable_pair<raw_tuple_type, action_queue_type>
> raw_actions_map;
- std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> > matcher_actions_map;
+ std::list<map_entry<exact_tuple_type, action_queue_type> >
exact_matches;
+ std::list<map_entry<fuzzy_tuple_type, action_queue_type> >
fuzzy_matches;
+ std::list<map_entry<exact_tuple_type, int> >
args_to_calls;
dynamic_vfunction()
- : dynamic_vfunction_action<R>()
- , dynamic_vfunction_base()
- , raw_actions_map()
- , matcher_actions_map()
+ : dynamic_vfunction_progress<R>()
+ , exact_matches()
+ , fuzzy_matches()
{}
- dynamic_vfunction_action<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1, const matcher::Matcher<A2 >& a2)
+ template <typename T>
+ int calculate_calls_for_arguments(const T args) {
+ int calls = 0;
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = args_to_calls.begin();
+ for(; calls_it != args_to_calls.end(); calls_it++) {
+ if(args == calls_it->key) {
+ calls += calls_it->val;
+ }
+ }
+ return calls;
+ }
+
+ dynamic_vfunction_progress<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1, const matcher::Matcher<A2 >& a2)
{
- matcher_tuple_type args = matcher_tuple_type(a0, a1, a2);
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
+ const fuzzy_tuple_type args = fuzzy_tuple_type(a0, a1, a2);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(match == fuzzy_matches.end())
{
-
matcher_actions_map.push_back(key_comparable_pair<matcher_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --matcher_actions_map.end();
+ fuzzy_matches.push_back(map_entry<fuzzy_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --fuzzy_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
- dynamic_vfunction_action<R>& when(A0 a0, A1 a1, A2 a2)
+ dynamic_vfunction_progress<R>& when(A0 a0, A1 a1, A2 a2)
{
- raw_tuple_type args = raw_tuple_type(a0, a1, a2);
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(raw_actions_map.begin(),
raw_actions_map.end(), args);
- if(pair_it == raw_actions_map.end())
+ const exact_tuple_type args = exact_tuple_type(a0, a1, a2);
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(match == exact_matches.end())
{
-
raw_actions_map.push_back(key_comparable_pair<raw_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --raw_actions_map.end();
+ exact_matches.push_back(map_entry<exact_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --exact_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
R invoke(A0 a0, A1 a1, A2 a2)
{
- this->calls++;
- raw_tuple_type args = raw_tuple_type(a0, a1, a2);
+ const exact_tuple_type args = exact_tuple_type(a0, a1, a2);
+
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = std::find(args_to_calls.begin(), args_to_calls.end(),
args);
+ if(calls_it == args_to_calls.end()) {
+ args_to_calls.push_back(map_entry<exact_tuple_type,
int>(args, 1));
+ } else {
+ (calls_it->val)++;
+ }
+
action_queue_type* actions = 0;
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator raw_actions_it =
- std::find(raw_actions_map.begin(), raw_actions_map.end(),
args);
- if(raw_actions_it != raw_actions_map.end())
- { actions = &(raw_actions_it->second); }
- if(actions == 0)
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator exact_match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(exact_match != exact_matches.end())
+ { actions = &(exact_match->val); }
+ if(!actions)
{
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
- { throw partial_implementation_exception(); }
- actions = &(pair_it->second);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator fuzzy_match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(fuzzy_match == fuzzy_matches.end())
+ { throw partial_implementation_exception(); }
+ actions = &(fuzzy_match->val);
}
action_type action = actions->front();
if(actions->size() > 1)
@@ -447,70 +526,91 @@
// 4 arity template
template <typename R, typename C, typename A0, typename A1, typename
A2, typename A3>
- struct dynamic_vfunction<R (C::*)(A0, A1, A2, A3)>
- : private dynamic_vfunction_action<R>
- , public dynamic_vfunction_base
+ struct dynamic_vfunction<R (C::*)(A0, A1, A2, A3)> : private
dynamic_vfunction_progress<R>
{
- typedef tr1::tuple<A0, A1, A2, A3> raw_tuple_type;
- typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 >,
matcher_element<A2 >, matcher_element<A3 > > matcher_tuple_type;
+ typedef tr1::tuple<A0, A1, A2, A3> exact_tuple_type;
+ typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 >,
matcher_element<A2 >, matcher_element<A3 > > fuzzy_tuple_type;
- typedef typename dynamic_vfunction_action<R>::action_type
action_type;
- typedef typename dynamic_vfunction_action<R>::action_queue_type
action_queue_type;
+ typedef typename dynamic_vfunction_progress<R>::action_type
action_type;
+ typedef typename dynamic_vfunction_progress<R>::action_queue_type
action_queue_type;
- std::list<key_comparable_pair<raw_tuple_type, action_queue_type>
> raw_actions_map;
- std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> > matcher_actions_map;
+ std::list<map_entry<exact_tuple_type, action_queue_type> >
exact_matches;
+ std::list<map_entry<fuzzy_tuple_type, action_queue_type> >
fuzzy_matches;
+ std::list<map_entry<exact_tuple_type, int> >
args_to_calls;
dynamic_vfunction()
- : dynamic_vfunction_action<R>()
- , dynamic_vfunction_base()
- , raw_actions_map()
- , matcher_actions_map()
+ : dynamic_vfunction_progress<R>()
+ , exact_matches()
+ , fuzzy_matches()
{}
- dynamic_vfunction_action<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1, const matcher::Matcher<A2 >& a2, const
matcher::Matcher<A3 >& a3)
+ template <typename T>
+ int calculate_calls_for_arguments(const T args) {
+ int calls = 0;
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = args_to_calls.begin();
+ for(; calls_it != args_to_calls.end(); calls_it++) {
+ if(args == calls_it->key) {
+ calls += calls_it->val;
+ }
+ }
+ return calls;
+ }
+
+ dynamic_vfunction_progress<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1, const matcher::Matcher<A2 >& a2, const
matcher::Matcher<A3 >& a3)
{
- matcher_tuple_type args = matcher_tuple_type(a0, a1, a2, a3);
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
+ const fuzzy_tuple_type args = fuzzy_tuple_type(a0, a1, a2, a3);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(match == fuzzy_matches.end())
{
-
matcher_actions_map.push_back(key_comparable_pair<matcher_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --matcher_actions_map.end();
+ fuzzy_matches.push_back(map_entry<fuzzy_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --fuzzy_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
- dynamic_vfunction_action<R>& when(A0 a0, A1 a1, A2 a2, A3 a3)
+ dynamic_vfunction_progress<R>& when(A0 a0, A1 a1, A2 a2, A3 a3)
{
- raw_tuple_type args = raw_tuple_type(a0, a1, a2, a3);
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(raw_actions_map.begin(),
raw_actions_map.end(), args);
- if(pair_it == raw_actions_map.end())
+ const exact_tuple_type args = exact_tuple_type(a0, a1, a2, a3);
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(match == exact_matches.end())
{
-
raw_actions_map.push_back(key_comparable_pair<raw_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --raw_actions_map.end();
+ exact_matches.push_back(map_entry<exact_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --exact_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
R invoke(A0 a0, A1 a1, A2 a2, A3 a3)
{
- this->calls++;
- raw_tuple_type args = raw_tuple_type(a0, a1, a2, a3);
+ const exact_tuple_type args = exact_tuple_type(a0, a1, a2, a3);
+
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = std::find(args_to_calls.begin(), args_to_calls.end(),
args);
+ if(calls_it == args_to_calls.end()) {
+ args_to_calls.push_back(map_entry<exact_tuple_type,
int>(args, 1));
+ } else {
+ (calls_it->val)++;
+ }
+
action_queue_type* actions = 0;
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator raw_actions_it =
- std::find(raw_actions_map.begin(), raw_actions_map.end(),
args);
- if(raw_actions_it != raw_actions_map.end())
- { actions = &(raw_actions_it->second); }
- if(actions == 0)
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator exact_match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(exact_match != exact_matches.end())
+ { actions = &(exact_match->val); }
+ if(!actions)
{
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
- { throw partial_implementation_exception(); }
- actions = &(pair_it->second);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator fuzzy_match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(fuzzy_match == fuzzy_matches.end())
+ { throw partial_implementation_exception(); }
+ actions = &(fuzzy_match->val);
}
action_type action = actions->front();
if(actions->size() > 1)
@@ -521,70 +621,91 @@
// 5 arity template
template <typename R, typename C, typename A0, typename A1, typename
A2, typename A3, typename A4>
- struct dynamic_vfunction<R (C::*)(A0, A1, A2, A3, A4)>
- : private dynamic_vfunction_action<R>
- , public dynamic_vfunction_base
+ struct dynamic_vfunction<R (C::*)(A0, A1, A2, A3, A4)> : private
dynamic_vfunction_progress<R>
{
- typedef tr1::tuple<A0, A1, A2, A3, A4> raw_tuple_type;
- typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 >,
matcher_element<A2 >, matcher_element<A3 >, matcher_element<A4 > >
matcher_tuple_type;
+ typedef tr1::tuple<A0, A1, A2, A3, A4> exact_tuple_type;
+ typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 >,
matcher_element<A2 >, matcher_element<A3 >, matcher_element<A4 > >
fuzzy_tuple_type;
- typedef typename dynamic_vfunction_action<R>::action_type
action_type;
- typedef typename dynamic_vfunction_action<R>::action_queue_type
action_queue_type;
+ typedef typename dynamic_vfunction_progress<R>::action_type
action_type;
+ typedef typename dynamic_vfunction_progress<R>::action_queue_type
action_queue_type;
- std::list<key_comparable_pair<raw_tuple_type, action_queue_type>
> raw_actions_map;
- std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> > matcher_actions_map;
+ std::list<map_entry<exact_tuple_type, action_queue_type> >
exact_matches;
+ std::list<map_entry<fuzzy_tuple_type, action_queue_type> >
fuzzy_matches;
+ std::list<map_entry<exact_tuple_type, int> >
args_to_calls;
dynamic_vfunction()
- : dynamic_vfunction_action<R>()
- , dynamic_vfunction_base()
- , raw_actions_map()
- , matcher_actions_map()
+ : dynamic_vfunction_progress<R>()
+ , exact_matches()
+ , fuzzy_matches()
{}
- dynamic_vfunction_action<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1, const matcher::Matcher<A2 >& a2, const
matcher::Matcher<A3 >& a3, const matcher::Matcher<A4 >& a4)
+ template <typename T>
+ int calculate_calls_for_arguments(const T args) {
+ int calls = 0;
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = args_to_calls.begin();
+ for(; calls_it != args_to_calls.end(); calls_it++) {
+ if(args == calls_it->key) {
+ calls += calls_it->val;
+ }
+ }
+ return calls;
+ }
+
+ dynamic_vfunction_progress<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1, const matcher::Matcher<A2 >& a2, const
matcher::Matcher<A3 >& a3, const matcher::Matcher<A4 >& a4)
{
- matcher_tuple_type args = matcher_tuple_type(a0, a1, a2, a3,
a4);
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
+ const fuzzy_tuple_type args = fuzzy_tuple_type(a0, a1, a2, a3,
a4);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(match == fuzzy_matches.end())
{
-
matcher_actions_map.push_back(key_comparable_pair<matcher_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --matcher_actions_map.end();
+ fuzzy_matches.push_back(map_entry<fuzzy_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --fuzzy_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
- dynamic_vfunction_action<R>& when(A0 a0, A1 a1, A2 a2, A3 a3, A4
a4)
+ dynamic_vfunction_progress<R>& when(A0 a0, A1 a1, A2 a2, A3 a3,
A4 a4)
{
- raw_tuple_type args = raw_tuple_type(a0, a1, a2, a3, a4);
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(raw_actions_map.begin(),
raw_actions_map.end(), args);
- if(pair_it == raw_actions_map.end())
+ const exact_tuple_type args = exact_tuple_type(a0, a1, a2, a3,
a4);
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(match == exact_matches.end())
{
-
raw_actions_map.push_back(key_comparable_pair<raw_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --raw_actions_map.end();
+ exact_matches.push_back(map_entry<exact_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --exact_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
R invoke(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4)
{
- this->calls++;
- raw_tuple_type args = raw_tuple_type(a0, a1, a2, a3,
a4);
+ const exact_tuple_type args = exact_tuple_type(a0, a1, a2, a3,
a4);
+
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = std::find(args_to_calls.begin(), args_to_calls.end(),
args);
+ if(calls_it == args_to_calls.end()) {
+ args_to_calls.push_back(map_entry<exact_tuple_type,
int>(args, 1));
+ } else {
+ (calls_it->val)++;
+ }
+
action_queue_type* actions = 0;
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator raw_actions_it =
- std::find(raw_actions_map.begin(), raw_actions_map.end(),
args);
- if(raw_actions_it != raw_actions_map.end())
- { actions = &(raw_actions_it->second); }
- if(actions == 0)
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator exact_match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(exact_match != exact_matches.end())
+ { actions = &(exact_match->val); }
+ if(!actions)
{
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
- { throw partial_implementation_exception(); }
- actions = &(pair_it->second);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator fuzzy_match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(fuzzy_match == fuzzy_matches.end())
+ { throw partial_implementation_exception(); }
+ actions = &(fuzzy_match->val);
}
action_type action = actions->front();
if(actions->size() > 1)
@@ -595,70 +716,91 @@
// 6 arity template
template <typename R, typename C, typename A0, typename A1, typename
A2, typename A3, typename A4, typename A5>
- struct dynamic_vfunction<R (C::*)(A0, A1, A2, A3, A4, A5)>
- : private dynamic_vfunction_action<R>
- , public dynamic_vfunction_base
+ struct dynamic_vfunction<R (C::*)(A0, A1, A2, A3, A4, A5)> : private
dynamic_vfunction_progress<R>
{
- typedef tr1::tuple<A0, A1, A2, A3, A4, A5> raw_tuple_type;
- typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 >,
matcher_element<A2 >, matcher_element<A3 >, matcher_element<A4 >,
matcher_element<A5 > > matcher_tuple_type;
+ typedef tr1::tuple<A0, A1, A2, A3, A4, A5> exact_tuple_type;
+ typedef tr1::tuple<matcher_element<A0 >, matcher_element<A1 >,
matcher_element<A2 >, matcher_element<A3 >, matcher_element<A4 >,
matcher_element<A5 > > fuzzy_tuple_type;
- typedef typename dynamic_vfunction_action<R>::action_type
action_type;
- typedef typename dynamic_vfunction_action<R>::action_queue_type
action_queue_type;
+ typedef typename dynamic_vfunction_progress<R>::action_type
action_type;
+ typedef typename dynamic_vfunction_progress<R>::action_queue_type
action_queue_type;
- std::list<key_comparable_pair<raw_tuple_type, action_queue_type>
> raw_actions_map;
- std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> > matcher_actions_map;
+ std::list<map_entry<exact_tuple_type, action_queue_type> >
exact_matches;
+ std::list<map_entry<fuzzy_tuple_type, action_queue_type> >
fuzzy_matches;
+ std::list<map_entry<exact_tuple_type, int> >
args_to_calls;
dynamic_vfunction()
- : dynamic_vfunction_action<R>()
- , dynamic_vfunction_base()
- , raw_actions_map()
- , matcher_actions_map()
+ : dynamic_vfunction_progress<R>()
+ , exact_matches()
+ , fuzzy_matches()
{}
- dynamic_vfunction_action<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1, const matcher::Matcher<A2 >& a2, const
matcher::Matcher<A3 >& a3, const matcher::Matcher<A4 >& a4, const
matcher::Matcher<A5 >& a5)
+ template <typename T>
+ int calculate_calls_for_arguments(const T args) {
+ int calls = 0;
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = args_to_calls.begin();
+ for(; calls_it != args_to_calls.end(); calls_it++) {
+ if(args == calls_it->key) {
+ calls += calls_it->val;
+ }
+ }
+ return calls;
+ }
+
+ dynamic_vfunction_progress<R>& when(const matcher::Matcher<A0 >&
a0, const matcher::Matcher<A1 >& a1, const matcher::Matcher<A2 >& a2, const
matcher::Matcher<A3 >& a3, const matcher::Matcher<A4 >& a4, const
matcher::Matcher<A5 >& a5)
{
- matcher_tuple_type args = matcher_tuple_type(a0, a1, a2, a3,
a4, a5);
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
+ const fuzzy_tuple_type args = fuzzy_tuple_type(a0, a1, a2, a3,
a4, a5);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(match == fuzzy_matches.end())
{
-
matcher_actions_map.push_back(key_comparable_pair<matcher_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --matcher_actions_map.end();
+ fuzzy_matches.push_back(map_entry<fuzzy_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --fuzzy_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
- dynamic_vfunction_action<R>& when(A0 a0, A1 a1, A2 a2, A3 a3, A4
a4, A5 a5)
+ dynamic_vfunction_progress<R>& when(A0 a0, A1 a1, A2 a2, A3 a3,
A4 a4, A5 a5)
{
- raw_tuple_type args = raw_tuple_type(a0, a1, a2, a3, a4, a5);
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(raw_actions_map.begin(),
raw_actions_map.end(), args);
- if(pair_it == raw_actions_map.end())
+ const exact_tuple_type args = exact_tuple_type(a0, a1, a2, a3,
a4, a5);
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(match == exact_matches.end())
{
-
raw_actions_map.push_back(key_comparable_pair<raw_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --raw_actions_map.end();
+ exact_matches.push_back(map_entry<exact_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --exact_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
R invoke(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
{
- this->calls++;
- raw_tuple_type args = raw_tuple_type(a0, a1, a2, a3,
a4, a5);
+ const exact_tuple_type args = exact_tuple_type(a0, a1, a2, a3,
a4, a5);
+
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = std::find(args_to_calls.begin(), args_to_calls.end(),
args);
+ if(calls_it == args_to_calls.end()) {
+ args_to_calls.push_back(map_entry<exact_tuple_type,
int>(args, 1));
+ } else {
+ (calls_it->val)++;
+ }
+
action_queue_type* actions = 0;
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator raw_actions_it =
- std::find(raw_actions_map.begin(), raw_actions_map.end(),
args);
- if(raw_actions_it != raw_actions_map.end())
- { actions = &(raw_actions_it->second); }
- if(actions == 0)
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator exact_match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/include/mockitopp/detail/stubbing/dynamic_vfunction.hpp.m4 Sat
Sep 29 00:40:54 2012
+++ /trunk/include/mockitopp/detail/stubbing/dynamic_vfunction.hpp.m4 Tue
Oct 30 03:53:45 2012
@@ -3,7 +3,6 @@
#include <algorithm>
#include <list>
-#include <utility>
#include <mockitopp/exceptions.hpp>
#include <mockitopp/detail/stubbing/action.hpp>
@@ -24,10 +23,6 @@
struct dynamic_vfunction_base
{
int calls;
-
- dynamic_vfunction_base()
- : calls(0)
- {}
// allow polymorphic desctruction with unknown subtype
virtual ~dynamic_vfunction_base() {}
@@ -77,63 +72,64 @@
};
template <typename R>
- struct dynamic_vfunction_action
+ struct dynamic_vfunction_progress : dynamic_vfunction_base
{
typedef shared_ptr<action<R> > action_type;
typedef std::list<action_type> action_queue_type;
- action_queue_type* transient_stubbing;
+ action_queue_type* stubbing_progress;
- dynamic_vfunction_action& thenReturn(R value)
+ dynamic_vfunction_progress& thenReturn(R value)
{
- transient_stubbing->push_back(action_type(new
returnable_action<R>(value)));
+ stubbing_progress->push_back(action_type(new
returnable_action<R>(value)));
return *this;
}
template <typename T>
- dynamic_vfunction_action& thenThrow(T throwable)
+ dynamic_vfunction_progress& thenThrow(T throwable)
{
- transient_stubbing->push_back(action_type(new
throwable_action<R, T>(throwable)));
+ stubbing_progress->push_back(action_type(new
throwable_action<R, T>(throwable)));
return *this;
}
};
template <>
- struct dynamic_vfunction_action<void>
+ struct dynamic_vfunction_progress<void> : dynamic_vfunction_base
{
typedef shared_ptr<action<void> > action_type;
typedef std::list<action_type> action_queue_type;
- action_queue_type* transient_stubbing;
+ action_queue_type* stubbing_progress;
- dynamic_vfunction_action& thenReturn()
+ dynamic_vfunction_progress& thenReturn()
{
- transient_stubbing->push_back(action_type(new
returnable_action<void>()));
+ stubbing_progress->push_back(action_type(new
returnable_action<void>()));
return *this;
}
template <typename T>
- dynamic_vfunction_action& thenThrow(T throwable)
+ dynamic_vfunction_progress& thenThrow(T throwable)
{
- transient_stubbing->push_back(action_type(new
throwable_action<void, T>(throwable)));
+ stubbing_progress->push_back(action_type(new
throwable_action<void, T>(throwable)));
return *this;
}
};
template <typename K, typename V>
- struct key_comparable_pair : public std::pair<K, V>
+ struct map_entry
{
- key_comparable_pair(const K& key, const V& pair)
- : std::pair<K, V>(key, pair)
- {}
+ K key;
+ V val;
- template <typename KRHS, typename VRHS>
- bool operator== (const key_comparable_pair<KRHS, VRHS>& rhs) const
- { return this->first == rhs.first; }
+ map_entry(const K& k, const V& v) : key(k), val(v) {}
- template <typename RHS>
- bool operator== (const RHS& rhs) const
- { return this->first == rhs; }
+ template <typename K2, typename V2>
+ bool operator== (const map_entry<K2, V2>& rhs) const
+ { return key == rhs.key; }
+
+ template <typename T>
+ bool operator== (const T& rhs) const
+ { return key == rhs; }
};
template <typename T>
@@ -168,70 +164,91 @@
define(`DEFINE_DYNAMIC_VFUNCTION', `
// $1 arity template
template <typename R, typename C`'M4_ENUM_TRAILING_PARAMS($1,
typename A)>
- struct dynamic_vfunction<R (C::*)(M4_ENUM_PARAMS($1, A))>
- : private dynamic_vfunction_action<R>
- , public dynamic_vfunction_base
+ struct dynamic_vfunction<R (C::*)(M4_ENUM_PARAMS($1, A))> : private
dynamic_vfunction_progress<R>
{
- typedef tr1::tuple<M4_ENUM_PARAMS($1, A)> raw_tuple_type;
- typedef tr1::tuple<M4_ENUM_BINARY_PARAMS($1, matcher_element<A,
>, M4_INTERCEPT) > matcher_tuple_type;
+ typedef tr1::tuple<M4_ENUM_PARAMS($1, A)> exact_tuple_type;
+ typedef tr1::tuple<M4_ENUM_BINARY_PARAMS($1, matcher_element<A,
>, M4_INTERCEPT) > fuzzy_tuple_type;
- typedef typename dynamic_vfunction_action<R>::action_type
action_type;
- typedef typename dynamic_vfunction_action<R>::action_queue_type
action_queue_type;
+ typedef typename dynamic_vfunction_progress<R>::action_type
action_type;
+ typedef typename dynamic_vfunction_progress<R>::action_queue_type
action_queue_type;
- std::list<key_comparable_pair<raw_tuple_type, action_queue_type>
> raw_actions_map;
- std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> > matcher_actions_map;
+ std::list<map_entry<exact_tuple_type, action_queue_type> >
exact_matches;
+ std::list<map_entry<fuzzy_tuple_type, action_queue_type> >
fuzzy_matches;
+ std::list<map_entry<exact_tuple_type, int> >
args_to_calls;
dynamic_vfunction()
- : dynamic_vfunction_action<R>()
- , dynamic_vfunction_base()
- , raw_actions_map()
- , matcher_actions_map()
+ : dynamic_vfunction_progress<R>()
+ , exact_matches()
+ , fuzzy_matches()
{}
- M4_IF($1, `dynamic_vfunction_action<R>&
when(M4_ENUM_BINARY_PARAMS($1, const matcher::Matcher<A, >& a))
+ template <typename T>
+ int calculate_calls_for_arguments(const T args) {
+ int calls = 0;
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = args_to_calls.begin();
+ for(; calls_it != args_to_calls.end(); calls_it++) {
+ if(args == calls_it->key) {
+ calls += calls_it->val;
+ }
+ }
+ return calls;
+ }
+
+ M4_IF($1, `dynamic_vfunction_progress<R>&
when(M4_ENUM_BINARY_PARAMS($1, const matcher::Matcher<A, >& a))
{
- matcher_tuple_type args =
matcher_tuple_type(M4_ENUM_PARAMS($1, a));
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
+ const fuzzy_tuple_type args =
fuzzy_tuple_type(M4_ENUM_PARAMS($1, a));
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(match == fuzzy_matches.end())
{
-
matcher_actions_map.push_back(key_comparable_pair<matcher_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --matcher_actions_map.end();
+ fuzzy_matches.push_back(map_entry<fuzzy_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --fuzzy_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}',)
- dynamic_vfunction_action<R>& when(M4_ENUM_BINARY_PARAMS($1, A, a))
+ dynamic_vfunction_progress<R>& when(M4_ENUM_BINARY_PARAMS($1, A,
a))
{
- raw_tuple_type args = raw_tuple_type(M4_ENUM_PARAMS($1, a));
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(raw_actions_map.begin(),
raw_actions_map.end(), args);
- if(pair_it == raw_actions_map.end())
+ const exact_tuple_type args =
exact_tuple_type(M4_ENUM_PARAMS($1, a));
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(match == exact_matches.end())
{
-
raw_actions_map.push_back(key_comparable_pair<raw_tuple_type,
action_queue_type>(args, action_queue_type()));
- pair_it = --raw_actions_map.end();
+ exact_matches.push_back(map_entry<exact_tuple_type,
action_queue_type>(args, action_queue_type()));
+ match = --exact_matches.end();
}
- this->transient_stubbing = &(pair_it->second);
+ this->calls = calculate_calls_for_arguments(args);
+ this->stubbing_progress = &(match->val);
return *this;
}
R invoke(M4_ENUM_BINARY_PARAMS($1, A, a))
{
- this->calls++;
- raw_tuple_type args = raw_tuple_type(M4_ENUM_PARAMS($1,
a));
+ const exact_tuple_type args =
exact_tuple_type(M4_ENUM_PARAMS($1, a));
+
+ typename std::list<map_entry<exact_tuple_type, int>
>::iterator calls_it
+ = std::find(args_to_calls.begin(), args_to_calls.end(),
args);
+ if(calls_it == args_to_calls.end()) {
+ args_to_calls.push_back(map_entry<exact_tuple_type,
int>(args, 1));
+ } else {
+ (calls_it->val)++;
+ }
+
action_queue_type* actions = 0;
- typename std::list<key_comparable_pair<raw_tuple_type,
action_queue_type> >::iterator raw_actions_it =
- std::find(raw_actions_map.begin(), raw_actions_map.end(),
args);
- if(raw_actions_it != raw_actions_map.end())
- { actions = &(raw_actions_it->second); }
- if(actions == 0)
+ typename std::list<map_entry<exact_tuple_type,
action_queue_type> >::iterator exact_match
+ = std::find(exact_matches.begin(), exact_matches.end(),
args);
+ if(exact_match != exact_matches.end())
+ { actions = &(exact_match->val); }
+ if(!actions)
{
- typename std::list<key_comparable_pair<matcher_tuple_type,
action_queue_type> >::iterator pair_it;
- pair_it = std::find(matcher_actions_map.begin(),
matcher_actions_map.end(), args);
- if(pair_it == matcher_actions_map.end())
- { throw partial_implementation_exception(); }
- actions = &(pair_it->second);
+ typename std::list<map_entry<fuzzy_tuple_type,
action_queue_type> >::iterator fuzzy_match
+ = std::find(fuzzy_matches.begin(), fuzzy_matches.end(),
args);
+ if(fuzzy_match == fuzzy_matches.end())
+ { throw partial_implementation_exception(); }
+ actions = &(fuzzy_match->val);
}
action_type action = actions->front();
if(actions->size() > 1)
=======================================
--- /trunk/include/mockitopp/mock_object.hpp Sat Sep 29 00:40:54 2012
+++ /trunk/include/mockitopp/mock_object.hpp Tue Oct 30 03:53:45 2012
@@ -25,10 +25,7 @@
* @return mock object
*/
T& getInstance()
- {
- vtable_ptr = (vtable*) (((char*) vtable_ptr) + sizeof(void*) * 4);
- return reinterpret_cast<T&>(*this);
- }
+ { return reinterpret_cast<T&>(*this); }
/**
* stub functionality for a given method
=======================================
--- /trunk/test/src/TestArguments.cpp Fri Oct 7 23:33:10 2011
+++ /trunk/test/src/TestArguments.cpp Tue Oct 30 03:53:45 2012
@@ -35,15 +35,20 @@
ASSERT_EQUAL(2, i.__int(0));
ASSERT_EQUAL(2, i.__int(0));
ASSERT_THROW(i.__int(999),
mockitopp::partial_implementation_exception);
- ASSERT_TRUE(m(&PlainOleDataTypes::__int).exactly(10));
+ ASSERT_TRUE(m(&PlainOleDataTypes::__int).when(0).exactly(5));
+ ASSERT_TRUE(m(&PlainOleDataTypes::__int).when(100).exactly(4));
+ ASSERT_TRUE(m(&PlainOleDataTypes::__int).when(999).exactly(1));
ASSERT_EQUAL(false, i.__bool(true));
ASSERT_EQUAL(true, i.__bool(false));
- ASSERT_TRUE(m(&PlainOleDataTypes::__bool).exactly(2));
+ ASSERT_TRUE(m(&PlainOleDataTypes::__bool).when(true).exactly(1));
+ ASSERT_TRUE(m(&PlainOleDataTypes::__bool).when(false).exactly(1));
ASSERT_EQUAL('Z', i.__char('A'));
ASSERT_EQUAL('0', i.__char('Z'));
ASSERT_THROW(i.__char('B'),
mockitopp::partial_implementation_exception);
- ASSERT_TRUE(m(&PlainOleDataTypes::__char).exactly(3));
+ ASSERT_TRUE(m(&PlainOleDataTypes::__char).when('A').exactly(1));
+ ASSERT_TRUE(m(&PlainOleDataTypes::__char).when('B').exactly(1));
+ ASSERT_TRUE(m(&PlainOleDataTypes::__char).when('Z').exactly(1));
}
} __PlainOleDataTypesTest;
=======================================
--- /trunk/test/src/TestBasicStubbing.cpp Fri Oct 7 23:33:10 2011
+++ /trunk/test/src/TestBasicStubbing.cpp Tue Oct 30 03:53:45 2012
@@ -20,7 +20,7 @@
VoidVoidInterface& i = mock.getInstance();
i.foo();
- ASSERT_TRUE(mock(&VoidVoidInterface::foo).exactly(1));
+ ASSERT_TRUE(mock(&VoidVoidInterface::foo).when().exactly(1));
ASSERT_THROW(i.foo(), std::string);
}
@@ -34,7 +34,7 @@
CharVoidInterface& i = mock.getInstance();
ASSERT_EQUAL('A', i.foo());
- ASSERT_TRUE(mock(&CharVoidInterface::foo).exactly(1));
+ ASSERT_TRUE(mock(&CharVoidInterface::foo).when().exactly(1));
ASSERT_THROW(i.foo(), std::string);
}
@@ -48,6 +48,6 @@
VoidStringRefInterface& i = mock.getInstance();
i.foo("bar");
- ASSERT_TRUE(mock(&VoidStringRefInterface::foo).exactly(1));
+
ASSERT_TRUE(mock(&VoidStringRefInterface::foo).when("bar").exactly(1));
}
} __TestBasicStubbing;
=======================================
--- /trunk/test/src/TestSimpleComposite.cpp Fri Oct 7 23:33:10 2011
+++ /trunk/test/src/TestSimpleComposite.cpp Tue Oct 30 03:53:45 2012
@@ -55,8 +55,8 @@
SimpleComposite c = SimpleComposite(i1, i2);
ASSERT_EQUAL(12, c.simpleAdd());
- ASSERT_TRUE(mock1(&Interface1::foo).exactly(1));
- ASSERT_TRUE(mock2(&Interface2::bar).exactly(1));
+ ASSERT_TRUE(mock1(&Interface1::foo).when().exactly(1));
+ ASSERT_TRUE(mock2(&Interface2::bar).when().exactly(1));
}
void Multiply()
@@ -72,8 +72,8 @@
SimpleComposite c = SimpleComposite(i1, i2);
ASSERT_EQUAL(100, c.simpleMultiply());
- ASSERT_TRUE(mock1(&Interface1::foo).exactly(1));
- ASSERT_TRUE(mock2(&Interface2::bar).exactly(1));
+ ASSERT_TRUE(mock1(&Interface1::foo).when().exactly(1));
+ ASSERT_TRUE(mock2(&Interface2::bar).when().exactly(1));
}
void Add_and_Multiply()
@@ -90,7 +90,7 @@
ASSERT_EQUAL(20, c.simpleAdd());
ASSERT_EQUAL(100, c.simpleMultiply());
- ASSERT_TRUE(mock1(&Interface1::foo).exactly(2));
- ASSERT_TRUE(mock2(&Interface2::bar).exactly(2));
+ ASSERT_TRUE(mock1(&Interface1::foo).when().exactly(2));
+ ASSERT_TRUE(mock2(&Interface2::bar).when().exactly(2));
}
} __TestSimpleComposite;
=======================================
--- /trunk/test/src/test_overloaded_functions.cpp Fri Oct 7 23:33:10 2011
+++ /trunk/test/src/test_overloaded_functions.cpp Tue Oct 30 03:53:45 2012
@@ -39,8 +39,8 @@
ASSERT_EQUAL(10, obj.foo(std::string("hello")));
ASSERT_THROW(obj.foo(std::string("!@#$%")),
mockitopp::partial_implementation_exception);
- ASSERT_TRUE(mock(static_cast<int
(overloaded_interface::*)(bool)>(&overloaded_interface::foo)).exactly(2));
- ASSERT_TRUE(mock(static_cast<int
(overloaded_interface::*)(char)>(&overloaded_interface::foo)).exactly(3));
- ASSERT_TRUE(mock(static_cast<int (overloaded_interface::*)(const
std::string&)>(&overloaded_interface::foo)).exactly(3));
+ ASSERT_TRUE(mock(static_cast<int
(overloaded_interface::*)(bool)>(&overloaded_interface::foo)).when(true).exactly(1));
+ ASSERT_TRUE(mock(static_cast<int
(overloaded_interface::*)(char)>(&overloaded_interface::foo)).when('A').exactly(1));
+ // ASSERT_TRUE(mock(static_cast<int (overloaded_interface::*)(const
std::string&)>(&overloaded_interface::foo)).when(hello).exactly(1));
}
} __test_overloaded_functions;
=======================================
--- /trunk/test/src/test_verify.cpp Fri Oct 7 23:33:10 2011
+++ /trunk/test/src/test_verify.cpp Tue Oct 30 03:53:45 2012
@@ -31,46 +31,46 @@
{
VERIFY_MOCK_DEFINITION
- ASSERT_TRUE(mock(&verify_interface::func).atLeast(1));
- ASSERT_TRUE(mock(&verify_interface::func).atLeast(2));
- ASSERT_TRUE(mock(&verify_interface::func).atLeast(3));
- ASSERT_FALSE(mock(&verify_interface::func).atLeast(4));
+ ASSERT_TRUE(mock(&verify_interface::func).when().atLeast(1));
+ ASSERT_TRUE(mock(&verify_interface::func).when().atLeast(2));
+ ASSERT_TRUE(mock(&verify_interface::func).when().atLeast(3));
+ ASSERT_FALSE(mock(&verify_interface::func).when().atLeast(4));
}
void atMost()
{
VERIFY_MOCK_DEFINITION
- ASSERT_FALSE(mock(&verify_interface::func).atMost(1));
- ASSERT_FALSE(mock(&verify_interface::func).atMost(2));
- ASSERT_TRUE(mock(&verify_interface::func).atMost(3));
- ASSERT_TRUE(mock(&verify_interface::func).atMost(4));
+ ASSERT_FALSE(mock(&verify_interface::func).when().atMost(1));
+ ASSERT_FALSE(mock(&verify_interface::func).when().atMost(2));
+ ASSERT_TRUE(mock(&verify_interface::func).when().atMost(3));
+ ASSERT_TRUE(mock(&verify_interface::func).when().atMost(4));
}
void between()
{
VERIFY_MOCK_DEFINITION
- ASSERT_FALSE(mock(&verify_interface::func).between(0, 2));
- ASSERT_FALSE(mock(&verify_interface::func).between(4, 9));
- ASSERT_TRUE(mock(&verify_interface::func).between(1, 5));
- ASSERT_TRUE(mock(&verify_interface::func).between(3, 3));
+ ASSERT_FALSE(mock(&verify_interface::func).when().between(0, 2));
+ ASSERT_FALSE(mock(&verify_interface::func).when().between(4, 9));
+ ASSERT_TRUE(mock(&verify_interface::func).when().between(1, 5));
+ ASSERT_TRUE(mock(&verify_interface::func).when().between(3, 3));
}
void exactly()
{
VERIFY_MOCK_DEFINITION
- ASSERT_FALSE(mock(&verify_interface::func).exactly(1));
- ASSERT_FALSE(mock(&verify_interface::func).exactly(2));
- ASSERT_TRUE(mock(&verify_interface::func).exactly(3));
- ASSERT_FALSE(mock(&verify_interface::func).exactly(4));
+ ASSERT_FALSE(mock(&verify_interface::func).when().exactly(1));
+ ASSERT_FALSE(mock(&verify_interface::func).when().exactly(2));
+ ASSERT_TRUE(mock(&verify_interface::func).when().exactly(3));
+ ASSERT_FALSE(mock(&verify_interface::func).when().exactly(4));
}
void never()
{
VERIFY_MOCK_DEFINITION
- ASSERT_FALSE(mock(&verify_interface::func).never());
+ ASSERT_FALSE(mock(&verify_interface::func).when().never());
}
} __test_verify;