Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
testing::internal::ExpectationBase Class Referenceabstract

#include <gmock-spec-builders.h>

Inheritance diagram for testing::internal::ExpectationBase:
Collaboration diagram for testing::internal::ExpectationBase:

Public Member Functions

 ExpectationBase (const char *file, int line, const std::string &source_text)
 
virtual ~ExpectationBase ()
 
const char * file () const
 
int line () const
 
const char * source_text () const
 
const Cardinalitycardinality () const
 
void DescribeLocationTo (::std::ostream *os) const
 
void DescribeCallCountTo (::std::ostream *os) const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
virtual void MaybeDescribeExtraMatcherTo (::std::ostream *os)=0
 

Protected Types

enum  Clause {
  kNone , kWith , kTimes , kInSequence ,
  kAfter , kWillOnce , kWillRepeatedly , kRetiresOnSaturation
}
 
typedef std::vector< const void * > UntypedActions
 

Protected Member Functions

virtual Expectation GetHandle ()=0
 
void AssertSpecProperty (bool property, const std::string &failure_message) const
 
void ExpectSpecProperty (bool property, const std::string &failure_message) const
 
void SpecifyCardinality (const Cardinality &cardinality)
 
bool cardinality_specified () const
 
void set_cardinality (const Cardinality &a_cardinality)
 
void RetireAllPreRequisites () GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
bool is_retired () const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
void Retire () GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
bool IsSatisfied () const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
bool IsSaturated () const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
bool IsOverSaturated () const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
bool AllPrerequisitesAreSatisfied () const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
void FindUnsatisfiedPrerequisites (ExpectationSet *result) const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
int call_count () const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
void IncrementCallCount () GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
void CheckActionCountIfNotDone () const GTEST_LOCK_EXCLUDED_(mutex_)
 
void UntypedTimes (const Cardinality &a_cardinality)
 
 GTEST_DISALLOW_ASSIGN_ (ExpectationBase)
 

Protected Attributes

const char * file_
 
int line_
 
const std::string source_text_
 
bool cardinality_specified_
 
Cardinality cardinality_
 
ExpectationSet immediate_prerequisites_
 
int call_count_
 
bool retired_
 
UntypedActions untyped_actions_
 
bool extra_matcher_specified_
 
bool repeated_action_specified_
 
bool retires_on_saturation_
 
Clause last_clause_
 
bool action_count_checked_
 
Mutex mutex_
 

Friends

class ::testing::Expectation
 
class UntypedFunctionMockerBase
 
class ::testing::Sequence
 
class ::testing::internal::ExpectationTester
 
template<typename Function >
class TypedExpectation
 

Detailed Description

Definition at line 695 of file gmock-spec-builders.h.

Member Typedef Documentation

◆ UntypedActions

std::vector<const void*> testing::internal::ExpectationBase::UntypedActions
protected

Definition at line 739 of file gmock-spec-builders.h.

Member Enumeration Documentation

◆ Clause

Constructor & Destructor Documentation

◆ ExpectationBase()

testing::internal::ExpectationBase::ExpectationBase ( const char * file,
int line,
const std::string & source_text )

Definition at line 78 of file gmock-spec-builders.cc.

80 : file_(a_file),
81 line_(a_line),
82 source_text_(a_source_text),
85 call_count_(0),
86 retired_(false),
91 action_count_checked_(false) {}
GTEST_API_ Cardinality Exactly(int n)

◆ ~ExpectationBase()

testing::internal::ExpectationBase::~ExpectationBase ( )
virtual

Definition at line 94 of file gmock-spec-builders.cc.

94{}

Member Function Documentation

◆ AllPrerequisitesAreSatisfied()

bool testing::internal::ExpectationBase::AllPrerequisitesAreSatisfied ( ) const
protected

Definition at line 131 of file gmock-spec-builders.cc.

132 {
133 g_gmock_mutex.AssertHeld();
134 ::std::vector<const ExpectationBase*> expectations(1, this);
135 while (!expectations.empty()) {
136 const ExpectationBase* exp = expectations.back();
137 expectations.pop_back();
138
140 exp->immediate_prerequisites_.begin();
141 it != exp->immediate_prerequisites_.end(); ++it) {
142 const ExpectationBase* next = it->expectation_base().get();
143 if (!next->IsSatisfied()) return false;
144 expectations.push_back(next);
145 }
146 }
147 return true;
148}
Expectation::Set::const_iterator const_iterator
ExpectationBase(const char *file, int line, const std::string &source_text)
uint32_t next(octet_iterator &it, octet_iterator end)
Definition checked.h:137
Here is the call graph for this function:

◆ AssertSpecProperty()

void testing::internal::ExpectationBase::AssertSpecProperty ( bool property,
const std::string & failure_message ) const
inlineprotected

Definition at line 746 of file gmock-spec-builders.h.

747 {
748 Assert(property, file_, line_, failure_message);
749 }
void Assert(bool condition, const char *file, int line)
Here is the call graph for this function:

◆ call_count()

int testing::internal::ExpectationBase::call_count ( ) const
inlineprotected

Definition at line 822 of file gmock-spec-builders.h.

823 {
824 g_gmock_mutex.AssertHeld();
825 return call_count_;
826 }

◆ cardinality()

const Cardinality & testing::internal::ExpectationBase::cardinality ( ) const
inline

Definition at line 707 of file gmock-spec-builders.h.

707{ return cardinality_; }
Here is the caller graph for this function:

◆ cardinality_specified()

bool testing::internal::ExpectationBase::cardinality_specified ( ) const
inlineprotected

Definition at line 763 of file gmock-spec-builders.h.

763{ return cardinality_specified_; }

◆ CheckActionCountIfNotDone()

void testing::internal::ExpectationBase::CheckActionCountIfNotDone ( ) const
protected

Definition at line 205 of file gmock-spec-builders.cc.

206 {
207 bool should_check = false;
208 {
212 should_check = true;
213 }
214 }
215
216 if (should_check) {
218 // The cardinality was inferred - no need to check the action
219 // count against it.
220 return;
221 }
222
223 // The cardinality was explicitly specified.
224 const int action_count = static_cast<int>(untyped_actions_.size());
225 const int upper_bound = cardinality().ConservativeUpperBound();
226 const int lower_bound = cardinality().ConservativeLowerBound();
227 bool too_many; // True if there are too many actions, or false
228 // if there are too few.
229 if (action_count > upper_bound ||
230 (action_count == upper_bound && repeated_action_specified_)) {
231 too_many = true;
232 } else if (0 < action_count && action_count < lower_bound &&
234 too_many = false;
235 } else {
236 return;
237 }
238
239 ::std::stringstream ss;
241 ss << "Too " << (too_many ? "many" : "few")
242 << " actions specified in " << source_text() << "...\n"
243 << "Expected to be ";
244 cardinality().DescribeTo(&ss);
245 ss << ", but has " << (too_many ? "" : "only ")
246 << action_count << " WillOnce()"
247 << (action_count == 1 ? "" : "s");
249 ss << " and a WillRepeatedly()";
250 }
251 ss << ".";
252 Log(kWarning, ss.str(), -1); // -1 means "don't print stack trace".
253 }
254}
void DescribeTo(::std::ostream *os) const
void DescribeLocationTo(::std::ostream *os) const
const Cardinality & cardinality() const
Definition Logging.h:12
static const Segment ss(Segment::ss)
GTestMutexLock MutexLock
int l
Here is the call graph for this function:

◆ DescribeCallCountTo()

void testing::internal::ExpectationBase::DescribeCallCountTo ( ::std::ostream * os) const

Definition at line 182 of file gmock-spec-builders.cc.

183 {
184 g_gmock_mutex.AssertHeld();
185
186 // Describes how many times the function is expected to be called.
187 *os << " Expected: to be ";
189 *os << "\n Actual: ";
191
192 // Describes the state of the expectation (e.g. is it satisfied?
193 // is it active?).
194 *os << " - " << (IsOverSaturated() ? "over-saturated" :
195 IsSaturated() ? "saturated" :
196 IsSatisfied() ? "satisfied" : "unsatisfied")
197 << " and "
198 << (is_retired() ? "retired" : "active");
199}
static void DescribeActualCallCountTo(int actual_call_count, ::std::ostream *os)
bool IsOverSaturated() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
int call_count() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
bool IsSaturated() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
bool IsSatisfied() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
bool is_retired() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
os_t os
Here is the call graph for this function:

◆ DescribeLocationTo()

void testing::internal::ExpectationBase::DescribeLocationTo ( ::std::ostream * os) const
inline

Definition at line 710 of file gmock-spec-builders.h.

710 {
711 *os << FormatFileLocation(file(), line()) << " ";
712 }
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
Here is the caller graph for this function:

◆ ExpectSpecProperty()

void testing::internal::ExpectationBase::ExpectSpecProperty ( bool property,
const std::string & failure_message ) const
inlineprotected

Definition at line 752 of file gmock-spec-builders.h.

753 {
754 Expect(property, file_, line_, failure_message);
755 }
void Expect(bool condition, const char *file, int line, const std::string &msg)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ file()

const char * testing::internal::ExpectationBase::file ( ) const
inline

Definition at line 703 of file gmock-spec-builders.h.

703{ return file_; }
Here is the caller graph for this function:

◆ FindUnsatisfiedPrerequisites()

void testing::internal::ExpectationBase::FindUnsatisfiedPrerequisites ( ExpectationSet * result) const
protected

Definition at line 151 of file gmock-spec-builders.cc.

152 {
153 g_gmock_mutex.AssertHeld();
154 ::std::vector<const ExpectationBase*> expectations(1, this);
155 while (!expectations.empty()) {
156 const ExpectationBase* exp = expectations.back();
157 expectations.pop_back();
158
160 exp->immediate_prerequisites_.begin();
161 it != exp->immediate_prerequisites_.end(); ++it) {
162 const ExpectationBase* next = it->expectation_base().get();
163
164 if (next->IsSatisfied()) {
165 // If *it is satisfied and has a call count of 0, some of its
166 // pre-requisites may not be satisfied yet.
167 if (next->call_count_ == 0) {
168 expectations.push_back(next);
169 }
170 } else {
171 // Now that we know next is unsatisfied, we are not so interested
172 // in whether its pre-requisites are satisfied. Therefore we
173 // don't iterate into it here.
174 *result += *it;
175 }
176 }
177 }
178}
Here is the call graph for this function:

◆ GetHandle()

virtual Expectation testing::internal::ExpectationBase::GetHandle ( )
protectedpure virtual

◆ GTEST_DISALLOW_ASSIGN_()

testing::internal::ExpectationBase::GTEST_DISALLOW_ASSIGN_ ( ExpectationBase )
protected

◆ IncrementCallCount()

void testing::internal::ExpectationBase::IncrementCallCount ( )
inlineprotected

Definition at line 829 of file gmock-spec-builders.h.

830 {
831 g_gmock_mutex.AssertHeld();
832 call_count_++;
833 }

◆ is_retired()

bool testing::internal::ExpectationBase::is_retired ( ) const
inlineprotected

Definition at line 779 of file gmock-spec-builders.h.

780 {
781 g_gmock_mutex.AssertHeld();
782 return retired_;
783 }
Here is the caller graph for this function:

◆ IsOverSaturated()

bool testing::internal::ExpectationBase::IsOverSaturated ( ) const
inlineprotected

Definition at line 807 of file gmock-spec-builders.h.

808 {
809 g_gmock_mutex.AssertHeld();
811 }
bool IsOverSaturatedByCallCount(int call_count) const

◆ IsSatisfied()

bool testing::internal::ExpectationBase::IsSatisfied ( ) const
inlineprotected

Definition at line 793 of file gmock-spec-builders.h.

794 {
795 g_gmock_mutex.AssertHeld();
797 }
bool IsSatisfiedByCallCount(int call_count) const

◆ IsSaturated()

bool testing::internal::ExpectationBase::IsSaturated ( ) const
inlineprotected

Definition at line 800 of file gmock-spec-builders.h.

801 {
802 g_gmock_mutex.AssertHeld();
804 }
bool IsSaturatedByCallCount(int call_count) const

◆ line()

int testing::internal::ExpectationBase::line ( ) const
inline

Definition at line 704 of file gmock-spec-builders.h.

704{ return line_; }
Here is the caller graph for this function:

◆ MaybeDescribeExtraMatcherTo()

virtual void testing::internal::ExpectationBase::MaybeDescribeExtraMatcherTo ( ::std::ostream * os)
pure virtual

◆ Retire()

void testing::internal::ExpectationBase::Retire ( )
inlineprotected

Definition at line 786 of file gmock-spec-builders.h.

787 {
788 g_gmock_mutex.AssertHeld();
789 retired_ = true;
790 }

◆ RetireAllPreRequisites()

void testing::internal::ExpectationBase::RetireAllPreRequisites ( )
protected

Definition at line 104 of file gmock-spec-builders.cc.

105 {
106 if (is_retired()) {
107 // We can take this short-cut as we never retire an expectation
108 // until we have retired all its pre-requisites.
109 return;
110 }
111
112 ::std::vector<ExpectationBase*> expectations(1, this);
113 while (!expectations.empty()) {
114 ExpectationBase* exp = expectations.back();
115 expectations.pop_back();
116
118 exp->immediate_prerequisites_.begin();
119 it != exp->immediate_prerequisites_.end(); ++it) {
120 ExpectationBase* next = it->expectation_base().get();
121 if (!next->is_retired()) {
122 next->Retire();
123 expectations.push_back(next);
124 }
125 }
126 }
127}
Here is the call graph for this function:

◆ set_cardinality()

void testing::internal::ExpectationBase::set_cardinality ( const Cardinality & a_cardinality)
inlineprotected

Definition at line 766 of file gmock-spec-builders.h.

766 {
767 cardinality_ = a_cardinality;
768 }

◆ source_text()

const char * testing::internal::ExpectationBase::source_text ( ) const
inline

Definition at line 705 of file gmock-spec-builders.h.

705{ return source_text_.c_str(); }
Here is the caller graph for this function:

◆ SpecifyCardinality()

void testing::internal::ExpectationBase::SpecifyCardinality ( const Cardinality & cardinality)
protected

Definition at line 98 of file gmock-spec-builders.cc.

98 {
100 cardinality_ = a_cardinality;
101}
Here is the caller graph for this function:

◆ UntypedTimes()

void testing::internal::ExpectationBase::UntypedTimes ( const Cardinality & a_cardinality)
protected

Definition at line 257 of file gmock-spec-builders.cc.

257 {
258 if (last_clause_ == kTimes) {
259 ExpectSpecProperty(false,
260 ".Times() cannot appear "
261 "more than once in an EXPECT_CALL().");
262 } else {
264 ".Times() cannot appear after "
265 ".InSequence(), .WillOnce(), .WillRepeatedly(), "
266 "or .RetiresOnSaturation().");
267 }
269
270 SpecifyCardinality(a_cardinality);
271}
void SpecifyCardinality(const Cardinality &cardinality)
void ExpectSpecProperty(bool property, const std::string &failure_message) const
Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ ::testing::Expectation

Definition at line 724 of file gmock-spec-builders.h.

◆ ::testing::internal::ExpectationTester

Definition at line 843 of file gmock-spec-builders.h.

◆ ::testing::Sequence

friend class ::testing::Sequence
friend

Definition at line 842 of file gmock-spec-builders.h.

◆ TypedExpectation

template<typename Function >
friend class TypedExpectation
friend

Definition at line 846 of file gmock-spec-builders.h.

◆ UntypedFunctionMockerBase

Definition at line 725 of file gmock-spec-builders.h.

Member Data Documentation

◆ action_count_checked_

bool testing::internal::ExpectationBase::action_count_checked_
mutableprotected

Definition at line 876 of file gmock-spec-builders.h.

◆ call_count_

int testing::internal::ExpectationBase::call_count_
protected

Definition at line 869 of file gmock-spec-builders.h.

◆ cardinality_

Cardinality testing::internal::ExpectationBase::cardinality_
protected

Definition at line 858 of file gmock-spec-builders.h.

◆ cardinality_specified_

bool testing::internal::ExpectationBase::cardinality_specified_
protected

Definition at line 857 of file gmock-spec-builders.h.

◆ extra_matcher_specified_

bool testing::internal::ExpectationBase::extra_matcher_specified_
protected

Definition at line 872 of file gmock-spec-builders.h.

◆ file_

const char* testing::internal::ExpectationBase::file_
protected

Definition at line 853 of file gmock-spec-builders.h.

◆ immediate_prerequisites_

ExpectationSet testing::internal::ExpectationBase::immediate_prerequisites_
protected

Definition at line 865 of file gmock-spec-builders.h.

◆ last_clause_

Clause testing::internal::ExpectationBase::last_clause_
protected

Definition at line 875 of file gmock-spec-builders.h.

◆ line_

int testing::internal::ExpectationBase::line_
protected

Definition at line 854 of file gmock-spec-builders.h.

◆ mutex_

Mutex testing::internal::ExpectationBase::mutex_
mutableprotected

Definition at line 877 of file gmock-spec-builders.h.

◆ repeated_action_specified_

bool testing::internal::ExpectationBase::repeated_action_specified_
protected

Definition at line 873 of file gmock-spec-builders.h.

◆ retired_

bool testing::internal::ExpectationBase::retired_
protected

Definition at line 870 of file gmock-spec-builders.h.

◆ retires_on_saturation_

bool testing::internal::ExpectationBase::retires_on_saturation_
protected

Definition at line 874 of file gmock-spec-builders.h.

◆ source_text_

const std::string testing::internal::ExpectationBase::source_text_
protected

Definition at line 855 of file gmock-spec-builders.h.

◆ untyped_actions_

UntypedActions testing::internal::ExpectationBase::untyped_actions_
protected

Definition at line 871 of file gmock-spec-builders.h.


The documentation for this class was generated from the following files: