OLD | NEW |
1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 22 matching lines...) Expand all Loading... |
33 // | 33 // |
34 // This file implements the spec builder syntax (ON_CALL and | 34 // This file implements the spec builder syntax (ON_CALL and |
35 // EXPECT_CALL). | 35 // EXPECT_CALL). |
36 | 36 |
37 #include <gmock/gmock-spec-builders.h> | 37 #include <gmock/gmock-spec-builders.h> |
38 | 38 |
39 #include <stdlib.h> | 39 #include <stdlib.h> |
40 #include <iostream> // NOLINT | 40 #include <iostream> // NOLINT |
41 #include <map> | 41 #include <map> |
42 #include <set> | 42 #include <set> |
| 43 #include <string> |
43 #include <gmock/gmock.h> | 44 #include <gmock/gmock.h> |
44 #include <gtest/gtest.h> | 45 #include <gtest/gtest.h> |
45 | 46 |
46 #if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC | 47 #if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC |
47 #include <unistd.h> // NOLINT | 48 #include <unistd.h> // NOLINT |
48 #endif | 49 #endif |
49 | 50 |
50 namespace testing { | 51 namespace testing { |
51 namespace internal { | 52 namespace internal { |
52 | 53 |
53 // Protects the mock object registry (in class Mock), all function | 54 // Protects the mock object registry (in class Mock), all function |
54 // mockers, and all expectations. | 55 // mockers, and all expectations. |
55 Mutex g_gmock_mutex(Mutex::NO_CONSTRUCTOR_NEEDED_FOR_STATIC_MUTEX); | 56 Mutex g_gmock_mutex(Mutex::NO_CONSTRUCTOR_NEEDED_FOR_STATIC_MUTEX); |
56 | 57 |
57 // Constructs an ExpectationBase object. | 58 // Constructs an ExpectationBase object. |
58 ExpectationBase::ExpectationBase(const char* file, int line) | 59 ExpectationBase::ExpectationBase(const char* a_file, |
59 : file_(file), | 60 int a_line, |
60 line_(line), | 61 const string& a_source_text) |
| 62 : file_(a_file), |
| 63 line_(a_line), |
| 64 source_text_(a_source_text), |
61 cardinality_specified_(false), | 65 cardinality_specified_(false), |
62 cardinality_(Exactly(1)), | 66 cardinality_(Exactly(1)), |
63 call_count_(0), | 67 call_count_(0), |
64 retired_(false) { | 68 retired_(false) { |
65 } | 69 } |
66 | 70 |
67 // Destructs an ExpectationBase object. | 71 // Destructs an ExpectationBase object. |
68 ExpectationBase::~ExpectationBase() {} | 72 ExpectationBase::~ExpectationBase() {} |
69 | 73 |
70 // Explicitly specifies the cardinality of this expectation. Used by | 74 // Explicitly specifies the cardinality of this expectation. Used by |
71 // the subclasses to implement the .Times() clause. | 75 // the subclasses to implement the .Times() clause. |
72 void ExpectationBase::SpecifyCardinality(const Cardinality& cardinality) { | 76 void ExpectationBase::SpecifyCardinality(const Cardinality& a_cardinality) { |
73 cardinality_specified_ = true; | 77 cardinality_specified_ = true; |
74 cardinality_ = cardinality; | 78 cardinality_ = a_cardinality; |
75 } | 79 } |
76 | 80 |
77 // Retires all pre-requisites of this expectation. | 81 // Retires all pre-requisites of this expectation. |
78 void ExpectationBase::RetireAllPreRequisites() { | 82 void ExpectationBase::RetireAllPreRequisites() { |
79 if (is_retired()) { | 83 if (is_retired()) { |
80 // We can take this short-cut as we never retire an expectation | 84 // We can take this short-cut as we never retire an expectation |
81 // until we have retired all its pre-requisites. | 85 // until we have retired all its pre-requisites. |
82 return; | 86 return; |
83 } | 87 } |
84 | 88 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 (*it)->ClearDefaultActionsLocked(); | 420 (*it)->ClearDefaultActionsLocked(); |
417 } | 421 } |
418 | 422 |
419 // We don't clear the content of mockers, as they may still be | 423 // We don't clear the content of mockers, as they may still be |
420 // needed by VerifyAndClearExpectationsLocked(). | 424 // needed by VerifyAndClearExpectationsLocked(). |
421 } | 425 } |
422 | 426 |
423 Expectation::Expectation() {} | 427 Expectation::Expectation() {} |
424 | 428 |
425 Expectation::Expectation( | 429 Expectation::Expectation( |
426 const internal::linked_ptr<internal::ExpectationBase>& expectation_base) | 430 const internal::linked_ptr<internal::ExpectationBase>& an_expectation_base) |
427 : expectation_base_(expectation_base) {} | 431 : expectation_base_(an_expectation_base) {} |
428 | 432 |
429 Expectation::~Expectation() {} | 433 Expectation::~Expectation() {} |
430 | 434 |
431 // Adds an expectation to a sequence. | 435 // Adds an expectation to a sequence. |
432 void Sequence::AddExpectation(const Expectation& expectation) const { | 436 void Sequence::AddExpectation(const Expectation& expectation) const { |
433 if (*last_expectation_ != expectation) { | 437 if (*last_expectation_ != expectation) { |
434 if (last_expectation_->expectation_base() != NULL) { | 438 if (last_expectation_->expectation_base() != NULL) { |
435 expectation.expectation_base()->immediate_prerequisites_ | 439 expectation.expectation_base()->immediate_prerequisites_ |
436 += *last_expectation_; | 440 += *last_expectation_; |
437 } | 441 } |
(...skipping 14 matching lines...) Expand all Loading... |
452 // Deletes the implicit sequence if it was created by the constructor | 456 // Deletes the implicit sequence if it was created by the constructor |
453 // of this object. | 457 // of this object. |
454 InSequence::~InSequence() { | 458 InSequence::~InSequence() { |
455 if (sequence_created_) { | 459 if (sequence_created_) { |
456 delete internal::g_gmock_implicit_sequence.get(); | 460 delete internal::g_gmock_implicit_sequence.get(); |
457 internal::g_gmock_implicit_sequence.set(NULL); | 461 internal::g_gmock_implicit_sequence.set(NULL); |
458 } | 462 } |
459 } | 463 } |
460 | 464 |
461 } // namespace testing | 465 } // namespace testing |
OLD | NEW |