diff options
| author | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2009-04-09 07:29:58 +0000 | 
|---|---|---|
| committer | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2009-04-09 07:29:58 +0000 | 
| commit | 1c8eb1c059d6727d9fcf45864dc6efa3d844e184 (patch) | |
| tree | 8948f12f2103c2a66204050e6f837e0e43a1099b /test | |
| parent | 56fe7460a898f8d0dea4869ab4ff9c598ba90085 (diff) | |
| download | googletest-1c8eb1c059d6727d9fcf45864dc6efa3d844e184.tar.gz googletest-1c8eb1c059d6727d9fcf45864dc6efa3d844e184.tar.bz2 googletest-1c8eb1c059d6727d9fcf45864dc6efa3d844e184.zip  | |
Adds actions ReturnNew<T>(...) and DeleteArg<k>(), by Jason Hsueh.
Diffstat (limited to 'test')
| -rw-r--r-- | test/gmock-generated-actions_test.cc | 103 | 
1 files changed, 103 insertions, 0 deletions
diff --git a/test/gmock-generated-actions_test.cc b/test/gmock-generated-actions_test.cc index dd25a123..922efca9 100644 --- a/test/gmock-generated-actions_test.cc +++ b/test/gmock-generated-actions_test.cc @@ -53,10 +53,12 @@ using testing::_;  using testing::Action;  using testing::ActionInterface;  using testing::ByRef; +using testing::DeleteArg;  using testing::DoAll;  using testing::Invoke;  using testing::InvokeArgument;  using testing::Return; +using testing::ReturnNew;  using testing::SaveArg;  using testing::SetArgReferee;  using testing::SetArgumentPointee; @@ -1371,6 +1373,107 @@ TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {    EXPECT_EQ('a', value);  } +class NullaryConstructorClass { + public: +  NullaryConstructorClass() : value_(123) {} +  int value_; +}; + +// Tests using ReturnNew() with a nullary constructor. +TEST(ReturnNewTest, NoArgs) { +  Action<NullaryConstructorClass*()> a = ReturnNew<NullaryConstructorClass>(); +  NullaryConstructorClass* c = a.Perform(make_tuple()); +  EXPECT_EQ(123, c->value_); +  delete c; +} + +class UnaryConstructorClass { + public: +  explicit UnaryConstructorClass(int value) : value_(value) {} +  int value_; +}; + +// Tests using ReturnNew() with a unary constructor. +TEST(ReturnNewTest, Unary) { +  Action<UnaryConstructorClass*()> a = ReturnNew<UnaryConstructorClass>(4000); +  UnaryConstructorClass* c = a.Perform(make_tuple()); +  EXPECT_EQ(4000, c->value_); +  delete c; +} + +TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) { +  Action<UnaryConstructorClass*(bool, int)> a = +      ReturnNew<UnaryConstructorClass>(4000); +  UnaryConstructorClass* c = a.Perform(make_tuple(false, 5)); +  EXPECT_EQ(4000, c->value_); +  delete c; +} + +TEST(ReturnNewTest, UnaryWorksWhenMockMethodReturnsPointerToConst) { +  Action<const UnaryConstructorClass*()> a = +      ReturnNew<UnaryConstructorClass>(4000); +  const UnaryConstructorClass* c = a.Perform(make_tuple()); +  EXPECT_EQ(4000, c->value_); +  delete c; +} + +class TenArgConstructorClass { + public: +  TenArgConstructorClass(int a1, int a2, int a3, int a4, int a5, +                         int a6, int a7, int a8, int a9, int a10) +    : value_(a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10) { +  } +  int value_; +}; + +// Tests using ReturnNew() with a 10-argument constructor. +TEST(ReturnNewTest, ConstructorThatTakes10Arguments) { +  Action<TenArgConstructorClass*()> a = +      ReturnNew<TenArgConstructorClass>(1000000000, 200000000, 30000000, +                                        4000000, 500000, 60000, +                                        7000, 800, 90, 0); +  TenArgConstructorClass* c = a.Perform(make_tuple()); +  EXPECT_EQ(1234567890, c->value_); +  delete c; +} + +// A class that can be used to verify that its destructor is called: it will set +// the bool provided to the constructor to true when destroyed. +class DeletionTester { + public: +  explicit DeletionTester(bool* is_deleted) +    : is_deleted_(is_deleted) { +    // Make sure the bit is set to false. +    *is_deleted_ = false; +  } + +  ~DeletionTester() { +    *is_deleted_ = true; +  } + + private: +  bool* is_deleted_; +}; + +TEST(DeleteArgActionTest, OneArg) { +  bool is_deleted = false; +  DeletionTester* t = new DeletionTester(&is_deleted); +  const Action<void(DeletionTester*)> a1 = DeleteArg<0>();      // NOLINT +  EXPECT_FALSE(is_deleted); +  a1.Perform(make_tuple(t)); +  EXPECT_TRUE(is_deleted); +} + +TEST(DeleteArgActionTest, TenArgs) { +  bool is_deleted = false; +  DeletionTester* t = new DeletionTester(&is_deleted); +  const Action<void(bool, int, int, const char*, bool, +                    int, int, int, int, DeletionTester*)> a1 = DeleteArg<9>(); +  EXPECT_FALSE(is_deleted); +  a1.Perform(make_tuple(true, 5, 6, "hi", false, 7, 8, 9, 10, t)); +  EXPECT_TRUE(is_deleted); +} +  #if GTEST_HAS_EXCEPTIONS  TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) {  | 
