Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/testing/ocmock_complex_type_helper.h" | 5 #import "ios/testing/ocmock_complex_type_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/scoped_nsobject.h" | |
| 9 #include "testing/platform_test.h" | 8 #include "testing/platform_test.h" |
| 10 #import "third_party/ocmock/OCMock/OCMock.h" | 9 #import "third_party/ocmock/OCMock/OCMock.h" |
| 11 #include "third_party/ocmock/gtest_support.h" | 10 #include "third_party/ocmock/gtest_support.h" |
| 12 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 13 #error "This file requires ARC support." | |
| 14 #endif | |
| 15 | |
| 13 // A complex type to test with.. | 16 // A complex type to test with.. |
| 14 struct SampleComplexType { | 17 struct SampleComplexType { |
| 15 int number; | 18 int number; |
| 16 float blob; | 19 float blob; |
| 17 }; | 20 }; |
| 18 | 21 |
| 19 typedef int ScalarType; | 22 typedef int ScalarType; |
| 20 | 23 |
| 21 @protocol TestedProtocol | 24 @protocol TestedProtocol |
| 22 - (void)passObject:(id)foo; | 25 - (void)passObject:(id)foo; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 42 } | 45 } |
| 43 | 46 |
| 44 @end | 47 @end |
| 45 | 48 |
| 46 namespace { | 49 namespace { |
| 47 | 50 |
| 48 class OCMockComplexTypeHelperTest : public PlatformTest { | 51 class OCMockComplexTypeHelperTest : public PlatformTest { |
| 49 protected: | 52 protected: |
| 50 void SetUp() override { | 53 void SetUp() override { |
| 51 PlatformTest::SetUp(); | 54 PlatformTest::SetUp(); |
| 52 helped_mock_.reset([[MockClass alloc] | 55 OCMockObject* protocol_mock = |
|
liaoyuke
2017/06/14 00:12:45
this temporary variable helps with formatting.
| |
| 53 initWithRepresentedObject: | 56 [OCMockObject mockForProtocol:@protocol(TestedProtocol)]; |
| 54 [OCMockObject mockForProtocol:@protocol(TestedProtocol)]]); | 57 helped_mock_ = [[MockClass alloc] initWithRepresentedObject:protocol_mock]; |
| 55 } | 58 } |
| 56 | 59 |
| 57 void TearDown() override { | 60 void TearDown() override { |
| 58 EXPECT_OCMOCK_VERIFY(helped_mock_); | 61 EXPECT_OCMOCK_VERIFY(helped_mock_); |
| 59 PlatformTest::TearDown(); | 62 PlatformTest::TearDown(); |
| 60 } | 63 } |
| 61 | 64 |
| 62 base::scoped_nsobject<id> helped_mock_; | 65 id helped_mock_; |
| 63 }; | 66 }; |
| 64 | 67 |
| 65 TEST_F(OCMockComplexTypeHelperTest, nilObjectStillWorks) { | 68 TEST_F(OCMockComplexTypeHelperTest, nilObjectStillWorks) { |
| 66 [[helped_mock_ expect] passObject:nil]; | 69 [[helped_mock_ expect] passObject:nil]; |
| 67 [helped_mock_ passObject:nil]; | 70 [helped_mock_ passObject:nil]; |
| 68 } | 71 } |
| 69 | 72 |
| 70 TEST_F(OCMockComplexTypeHelperTest, anyObjectStillWorks) { | 73 TEST_F(OCMockComplexTypeHelperTest, anyObjectStillWorks) { |
| 71 base::scoped_nsobject<id> someObject([[NSObject alloc] init]); | 74 id someObject = [[NSObject alloc] init]; |
| 72 [[helped_mock_ expect] passObject:OCMOCK_ANY]; | 75 [[helped_mock_ expect] passObject:OCMOCK_ANY]; |
| 73 [helped_mock_ passObject:someObject]; | 76 [helped_mock_ passObject:someObject]; |
| 74 } | 77 } |
| 75 | 78 |
| 76 TEST_F(OCMockComplexTypeHelperTest, complexType) { | 79 TEST_F(OCMockComplexTypeHelperTest, complexType) { |
| 77 const SampleComplexType expected_value = {1, 1.0}; | 80 const SampleComplexType expected_value = {1, 1.0}; |
| 78 | 81 |
| 79 complexTypeBlock block = ^(const SampleComplexType& value) { | 82 complexTypeBlock block = ^(const SampleComplexType& value) { |
| 80 EXPECT_EQ(expected_value.number, value.number); | 83 EXPECT_EQ(expected_value.number, value.number); |
| 81 EXPECT_EQ(expected_value.blob, value.blob); | 84 EXPECT_EQ(expected_value.blob, value.blob); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 92 ScalarBlock block = ^(const ScalarType& value) { | 95 ScalarBlock block = ^(const ScalarType& value) { |
| 93 EXPECT_EQ(expected_value, value); | 96 EXPECT_EQ(expected_value, value); |
| 94 }; | 97 }; |
| 95 [helped_mock_ onSelector:@selector(passScalar:) | 98 [helped_mock_ onSelector:@selector(passScalar:) |
| 96 callBlockExpectation:(id)block]; | 99 callBlockExpectation:(id)block]; |
| 97 | 100 |
| 98 [helped_mock_ passScalar:expected_value]; | 101 [helped_mock_ passScalar:expected_value]; |
| 99 } | 102 } |
| 100 | 103 |
| 101 } // namespace | 104 } // namespace |
| OLD | NEW |