1 #ifndef guard_testing_counters_hpp
2 #define guard_testing_counters_hpp
6 * @brief Some unit tests need to count how many times a function is
7 * called. Here we implement some simple helper classes for that
10 * @author Carlos O'Ryan
13 #include "testing_exception.hpp"
14 #include "ace/Copy_Disabled.h"
19 * @brief Used to count how many times a function gets called. The
20 * unit test should create one instance per function.
27 , failure_countdown_(0)
30 inline long current_count() const
35 inline void failure_countdown(long countdown
)
37 failure_countdown_
= countdown
;
40 inline void operator()()
43 if (--failure_countdown_
== 0)
45 throw testing_exception();
51 long failure_countdown_
;
55 * @brief Used to detect if a testing_counter is "called" the right
59 : private ACE_Copy_Disabled
62 inline expected_calls(call_counter
const & counter
)
63 : current_count_(counter
.current_count())
64 , previous_count_(counter
.current_count())
68 inline bool expect(long n
)
71 return (previous_count_
+ n
== current_count_
);
76 previous_count_
= current_count_
;
77 current_count_
= counter_
.current_count();
80 inline long current_count() const
82 return current_count_
;
85 inline long previous_count() const
87 return previous_count_
;
93 call_counter
const & counter_
;
96 inline std::ostream
& operator<<(std::ostream
& os
, expected_calls
const & x
)
98 return os
<< "current=" << x
.current_count()
99 << ",previous=" << x
.previous_count();
102 #endif // guard_testing_counters_hpp