45#include "gtest/gtest.h"
47#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC
60 const char* file,
int line,
61 const string& message) {
62 ::std::ostringstream
s;
63 s << file <<
":" << line <<
": " << message << ::std::endl;
64 Log(severity,
s.str(), 0);
70 const string& a_source_text)
105 ExpectationBase* const prerequisite = it->expectation_base().get();
106 if (!prerequisite->is_retired()) {
107 prerequisite->RetireAllPreRequisites();
108 prerequisite->Retire();
117 g_gmock_mutex.AssertHeld();
120 if (!(it->expectation_base()->IsSatisfied()) ||
121 !(it->expectation_base()->AllPrerequisitesAreSatisfied()))
130 g_gmock_mutex.AssertHeld();
133 if (it->expectation_base()->IsSatisfied()) {
136 if (it->expectation_base()->call_count_ == 0) {
137 it->expectation_base()->FindUnsatisfiedPrerequisites(
result);
152 g_gmock_mutex.AssertHeld();
155 *os <<
" Expected: to be ";
157 *os <<
"\n Actual: ";
175 bool should_check =
false;
193 const int upper_bound =
cardinality().ConservativeUpperBound();
194 const int lower_bound =
cardinality().ConservativeLowerBound();
197 if (action_count > upper_bound ||
200 }
else if (0 < action_count && action_count < lower_bound &&
207 ::std::stringstream ss;
209 ss <<
"Too " << (too_many ?
"many" :
"few")
210 <<
" actions specified in " <<
source_text() <<
"...\n"
211 <<
"Expected to be ";
213 ss <<
", but has " << (too_many ?
"" :
"only ")
214 << action_count <<
" WillOnce()"
215 << (action_count == 1 ?
"" :
"s");
217 ss <<
" and a WillRepeatedly()";
228 ".Times() cannot appear "
229 "more than once in an EXPECT_CALL().");
232 ".Times() cannot appear after "
233 ".InSequence(), .WillOnce(), .WillRepeatedly(), "
234 "or .RetiresOnSaturation().");
249 const int stack_frames_to_skip =
253 Log(
kInfo, msg, stack_frames_to_skip);
258 "\nNOTE: You can safely ignore the above warning unless this "
259 "call should not happen. Do not suppress it by blindly adding "
260 "an EXPECT_CALL() if you don't mean to enforce the call. "
261 "See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#"
262 "knowing-when-to-expect for details.\n",
263 stack_frames_to_skip);
266 Expect(
false, NULL, -1, msg);
285 Mock::Register(mock_obj,
this);
305 const void* mock_obj;
311 "MockObject() must not be called before RegisterOwner() or "
312 "SetOwnerAndName() has been called.");
328 "Name() must not be called before SetOwnerAndName() has "
350 Mock::GetReactionOnUninterestingCalls(
MockObject());
355 const bool need_to_report_uninteresting_call =
366 if (!need_to_report_uninteresting_call) {
372 ::std::stringstream ss;
381 result->PrintAsActionResult(&ss);
387 bool is_excessive =
false;
388 ::std::stringstream ss;
389 ::std::stringstream why;
390 ::std::stringstream loc;
391 const void* untyped_action = NULL;
397 untyped_args, &untyped_action, &is_excessive,
399 const bool found = untyped_expectation != NULL;
404 const bool need_to_report_call =
406 if (!need_to_report_call) {
409 untyped_action == NULL ?
414 ss <<
" Function call: " <<
Name();
419 if (found && !is_excessive) {
424 untyped_action == NULL ?
428 result->PrintAsActionResult(&ss);
429 ss <<
"\n" << why.str();
433 Expect(
false, NULL, -1, ss.str());
434 }
else if (is_excessive) {
437 untyped_expectation->
line(), ss.str());
441 Log(
kInfo, loc.str() + ss.str(), 2);
450 for (UntypedExpectations::const_iterator it =
453 if (it->get() == exp) {
458 Assert(
false, __FILE__, __LINE__,
"Cannot find expectation.");
469 g_gmock_mutex.AssertHeld();
470 bool expectations_met =
true;
471 for (UntypedExpectations::const_iterator it =
474 ExpectationBase* const untyped_expectation = it->get();
475 if (untyped_expectation->IsOverSaturated()) {
479 expectations_met = false;
480 }
else if (!untyped_expectation->IsSatisfied()) {
481 expectations_met = false;
482 ::std::stringstream ss;
483 ss <<
"Actual function call count doesn't match "
484 << untyped_expectation->source_text() <<
"...\n";
488 untyped_expectation->MaybeDescribeExtraMatcherTo(&ss);
489 untyped_expectation->DescribeCallCountTo(&ss);
490 Expect(false, untyped_expectation->file(),
491 untyped_expectation->line(), ss.str());
502 UntypedExpectations expectations_to_delete;
503 untyped_expectations_.swap(expectations_to_delete);
505 g_gmock_mutex.Unlock();
506 expectations_to_delete.clear();
507 g_gmock_mutex.Lock();
509 return expectations_met;
518typedef std::set<internal::UntypedFunctionMockerBase*> FunctionMockers;
523struct MockObjectState {
525 : first_used_file(NULL), first_used_line(-1), leakable(
false) {}
529 const char* first_used_file;
531 ::std::string first_used_test_case;
532 ::std::string first_used_test;
534 FunctionMockers function_mockers;
541class MockObjectRegistry {
544 typedef std::map<const void*, MockObjectState> StateMap;
550 ~MockObjectRegistry() {
557 int leaked_count = 0;
558 for (StateMap::const_iterator it = states_.begin(); it != states_.end();
560 if (it->second.leakable)
566 const MockObjectState&
state = it->second;
568 state.first_used_line);
569 std::cout <<
" ERROR: this mock object";
570 if (
state.first_used_test !=
"") {
571 std::cout <<
" (used in test " <<
state.first_used_test_case <<
"."
572 <<
state.first_used_test <<
")";
574 std::cout <<
" should be deleted but never is. Its address is @"
578 if (leaked_count > 0) {
579 std::cout <<
"\nERROR: " << leaked_count
580 <<
" leaked mock " << (leaked_count == 1 ?
"object" :
"objects")
581 <<
" found at program exit.\n";
592 StateMap& states() {
return states_; }
599MockObjectRegistry g_mock_object_registry;
603std::map<const void*, internal::CallReaction> g_uninteresting_call_reaction;
607void SetReactionOnUninterestingCalls(
const void* mock_obj,
611 g_uninteresting_call_reaction[mock_obj] = reaction;
618void Mock::AllowUninterestingCalls(
const void* mock_obj)
625void Mock::WarnUninterestingCalls(
const void* mock_obj)
632void Mock::FailUninterestingCalls(
const void* mock_obj)
639void Mock::UnregisterCallReaction(
const void* mock_obj)
642 g_uninteresting_call_reaction.erase(mock_obj);
648 const void* mock_obj)
651 return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
657void Mock::AllowLeak(
const void* mock_obj)
660 g_mock_object_registry.states()[mock_obj].leakable =
true;
666bool Mock::VerifyAndClearExpectations(
void* mock_obj)
669 return VerifyAndClearExpectationsLocked(mock_obj);
675bool Mock::VerifyAndClear(
void* mock_obj)
678 ClearDefaultActionsLocked(mock_obj);
679 return VerifyAndClearExpectationsLocked(mock_obj);
685bool Mock::VerifyAndClearExpectationsLocked(
void* mock_obj)
687 internal::g_gmock_mutex.AssertHeld();
688 if (g_mock_object_registry.states().count(mock_obj) == 0) {
695 bool expectations_met =
true;
696 FunctionMockers& mockers =
697 g_mock_object_registry.states()[mock_obj].function_mockers;
698 for (FunctionMockers::const_iterator it = mockers.begin();
699 it != mockers.end(); ++it) {
700 if (!(*it)->VerifyAndClearExpectationsLocked()) {
701 expectations_met =
false;
707 return expectations_met;
711void Mock::Register(
const void* mock_obj,
715 g_mock_object_registry.states()[mock_obj].function_mockers.insert(mocker);
721void Mock::RegisterUseByOnCallOrExpectCall(
const void* mock_obj,
722 const char* file,
int line)
725 MockObjectState&
state = g_mock_object_registry.states()[mock_obj];
726 if (
state.first_used_file == NULL) {
727 state.first_used_file = file;
731 if (test_info != NULL) {
736 state.first_used_test = test_info->
name();
747 internal::g_gmock_mutex.AssertHeld();
748 for (MockObjectRegistry::StateMap::iterator it =
749 g_mock_object_registry.states().begin();
750 it != g_mock_object_registry.states().end(); ++it) {
751 FunctionMockers& mockers = it->second.function_mockers;
752 if (mockers.erase(mocker) > 0) {
754 if (mockers.empty()) {
755 g_mock_object_registry.states().erase(it);
763void Mock::ClearDefaultActionsLocked(
void* mock_obj)
765 internal::g_gmock_mutex.AssertHeld();
767 if (g_mock_object_registry.states().count(mock_obj) == 0) {
774 FunctionMockers& mockers =
775 g_mock_object_registry.states()[mock_obj].function_mockers;
776 for (FunctionMockers::const_iterator it = mockers.begin();
777 it != mockers.end(); ++it) {
778 (*it)->ClearDefaultActionsLocked();
#define s(x, c)
Definition aesb.c:47
const char * name() const
Definition gtest.h:654
const char * test_case_name() const
Definition gtest.h:651
Definition gmock-cardinalities.h:83
static void DescribeActualCallCountTo(int actual_call_count, ::std::ostream *os)
Definition gmock-cardinalities.cc:130
Definition gmock-spec-builders.h:563
Expectation::Set::const_iterator const_iterator
Definition gmock-spec-builders.h:566
Definition gmock-spec-builders.h:487
Expectation()
Definition gmock-spec-builders.cc:785
~Expectation()
Definition gmock-spec-builders.cc:791
internal::linked_ptr< internal::ExpectationBase > expectation_base_
Definition gmock-spec-builders.h:547
const internal::linked_ptr< internal::ExpectationBase > & expectation_base() const
Definition gmock-spec-builders.h:542
InSequence()
Definition gmock-spec-builders.cc:805
bool sequence_created_
Definition gmock-spec-builders.h:665
~InSequence()
Definition gmock-spec-builders.cc:816
Definition gmock-spec-builders.h:619
internal::linked_ptr< Expectation > last_expectation_
Definition gmock-spec-builders.h:633
void AddExpectation(const Expectation &expectation) const
Definition gmock-spec-builders.cc:794
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
Definition gtest.cc:4279
static UnitTest * GetInstance()
Definition gtest.cc:3972
Definition gmock-spec-builders.h:690
void UntypedTimes(const Cardinality &a_cardinality)
Definition gmock-spec-builders.cc:225
bool IsOverSaturated() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.h:800
bool retired_
Definition gmock-spec-builders.h:863
ExpectationSet immediate_prerequisites_
Definition gmock-spec-builders.h:858
bool action_count_checked_
Definition gmock-spec-builders.h:869
void DescribeCallCountTo(::std::ostream *os) const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:150
const char * source_text() const
Definition gmock-spec-builders.h:700
bool extra_matcher_specified_
Definition gmock-spec-builders.h:865
Mutex mutex_
Definition gmock-spec-builders.h:870
void SpecifyCardinality(const Cardinality &cardinality)
Definition gmock-spec-builders.cc:89
@ kTimes
Definition gmock-spec-builders.h:726
@ kNone
Definition gmock-spec-builders.h:724
const char * file() const
Definition gmock-spec-builders.h:698
Clause last_clause_
Definition gmock-spec-builders.h:868
void ExpectSpecProperty(bool property, const string &failure_message) const
Definition gmock-spec-builders.h:746
void DescribeLocationTo(::std::ostream *os) const
Definition gmock-spec-builders.h:705
int line() const
Definition gmock-spec-builders.h:699
bool retires_on_saturation_
Definition gmock-spec-builders.h:867
bool AllPrerequisitesAreSatisfied() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:115
const string source_text_
Definition gmock-spec-builders.h:848
ExpectationBase(const char *file, int line, const string &source_text)
Definition gmock-spec-builders.cc:68
UntypedActions untyped_actions_
Definition gmock-spec-builders.h:864
void FindUnsatisfiedPrerequisites(ExpectationSet *result) const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:128
int call_count() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.h:815
void CheckActionCountIfNotDone() const GTEST_LOCK_EXCLUDED_(mutex_)
Definition gmock-spec-builders.cc:173
int line_
Definition gmock-spec-builders.h:847
bool repeated_action_specified_
Definition gmock-spec-builders.h:866
Cardinality cardinality_
Definition gmock-spec-builders.h:851
bool cardinality_specified_
Definition gmock-spec-builders.h:850
bool IsSaturated() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.h:793
const Cardinality & cardinality() const
Definition gmock-spec-builders.h:702
bool IsSatisfied() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.h:786
int call_count_
Definition gmock-spec-builders.h:862
const char * file_
Definition gmock-spec-builders.h:846
void RetireAllPreRequisites() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:95
bool is_retired() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.h:772
virtual ~ExpectationBase()
Definition gmock-spec-builders.cc:85
Definition gtest-port.h:2162
Definition gmock-spec-builders.h:1362
Definition gmock-spec-builders.h:126
void RegisterOwner(const void *mock_obj) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:279
void SetOwnerAndName(const void *mock_obj, const char *name) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:291
const char * name_
Definition gmock-spec-builders.h:235
bool VerifyAndClearExpectationsLocked() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:467
virtual void UntypedDescribeUninterestingCall(const void *untyped_args, ::std::ostream *os) const GTEST_LOCK_EXCLUDED_(g_gmock_mutex)=0
virtual const ExpectationBase * UntypedFindMatchingExpectation(const void *untyped_args, const void **untyped_action, bool *is_excessive, ::std::ostream *what, ::std::ostream *why) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)=0
virtual ~UntypedFunctionMockerBase()
Definition gmock-spec-builders.cc:273
const void * MockObject() const GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:303
Expectation GetHandleOf(ExpectationBase *exp)
Definition gmock-spec-builders.cc:449
UntypedExpectations untyped_expectations_
Definition gmock-spec-builders.h:241
virtual UntypedActionResultHolderBase * UntypedPerformDefaultAction(const void *untyped_args, const string &call_description) const =0
virtual UntypedActionResultHolderBase * UntypedPerformAction(const void *untyped_action, const void *untyped_args) const =0
UntypedActionResultHolderBase * UntypedInvokeWith(const void *untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:339
const void * mock_obj_
Definition gmock-spec-builders.h:231
virtual void UntypedPrintArgs(const void *untyped_args, ::std::ostream *os) const =0
const char * Name() const GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
Definition gmock-spec-builders.cc:320
UntypedFunctionMockerBase()
Definition gmock-spec-builders.cc:270
Definition gtest-linked_ptr.h:146
#define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
Definition gtest-port.h:2533
#define GTEST_LOCK_EXCLUDED_(locks)
Definition gtest-port.h:2534
#define GTEST_DEFINE_STATIC_MUTEX_(mutex)
Definition gtest-port.h:2147
#define GTEST_API_
Definition gtest-port.h:934
#define GMOCK_FLAG(name)
Definition gmock-port.h:70
void get(std::istream &input, bool &res)
Definition io.h:61
#define const
Definition ipfrdr.c:80
int l
Definition base.py:3
line
Definition check.py:23
Definition gmock-actions.h:64
GTestMutexLock MutexLock
Definition gtest-port.h:2159
LogSeverity
Definition gmock-internal-utils.h:306
@ kInfo
Definition gmock-internal-utils.h:307
@ kWarning
Definition gmock-internal-utils.h:308
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
Definition gtest-port.cc:880
GTEST_API_ bool LogIsVisible(LogSeverity severity)
Definition gmock-internal-utils.cc:110
void Assert(bool condition, const char *file, int line)
Definition gmock-internal-utils.h:288
void ReportUninterestingCall(CallReaction reaction, const string &msg)
Definition gmock-spec-builders.cc:247
const char kInfoVerbosity[]
Definition gmock-internal-utils.h:314
void Expect(bool condition, const char *file, int line, const string &msg)
Definition gmock-internal-utils.h:294
GTEST_API_ void Log(LogSeverity severity, const string &message, int stack_frames_to_skip)
Definition gmock-internal-utils.cc:131
CallReaction
Definition gmock-spec-builders.h:361
@ kFail
Definition gmock-spec-builders.h:364
@ kAllow
Definition gmock-spec-builders.h:362
@ kDefault
Definition gmock-spec-builders.h:365
@ kWarn
Definition gmock-spec-builders.h:363
GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity, const char *file, int line, const string &message)
Definition gmock-spec-builders.cc:59
GTEST_API_ ThreadLocal< Sequence * > g_gmock_implicit_sequence
Definition gmock-spec-builders.cc:243
Definition gmock-actions.h:53
GTEST_API_ Cardinality Exactly(int n)
Definition gmock-cardinalities.cc:154
const char * name
Definition options.c:30
tools::wallet2::message_signature_result_t result
Definition signature.cpp:62
if(!cryptonote::get_account_address_from_str_or_url(info, cryptonote::TESTNET, "9uVsvEryzpN8WH2t1WWhFFCG5tS8cBNdmJYNRuckLENFimfauV5pZKeS1P2CbxGkSDTUPHXWwiYE5ZGSXDAGbaZgDxobqDN"))
Definition signature.cpp:53
static enum @134263177206050322030131042047320152224064051307 state