Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Unified Diff: ios/testing/ocmock_complex_type_helper_unittest.mm

Issue 1024443002: Upstream ios/testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/testing/ocmock_complex_type_helper.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/testing/ocmock_complex_type_helper_unittest.mm
diff --git a/ios/testing/ocmock_complex_type_helper_unittest.mm b/ios/testing/ocmock_complex_type_helper_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..df2fba27fa0596d5098944d655a132962de4bff0
--- /dev/null
+++ b/ios/testing/ocmock_complex_type_helper_unittest.mm
@@ -0,0 +1,101 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/testing/ocmock_complex_type_helper.h"
+
+#include "base/logging.h"
+#include "base/mac/scoped_nsobject.h"
+#include "testing/platform_test.h"
+#import "third_party/ocmock/OCMock/OCMock.h"
+#include "third_party/ocmock/gtest_support.h"
+
+// A complex type to test with..
+struct SampleComplexType {
+ int number;
+ float blob;
+};
+
+typedef int ScalarType;
+
+@protocol TestedProtocol
+- (void)passObject:(id)foo;
+- (void)passComplexType:(const SampleComplexType&)foo;
+- (void)passScalar:(ScalarType)foo;
+@end
+
+@interface MockClass : OCMockComplexTypeHelper
+@end
+
+@implementation MockClass
+
+typedef void (^complexTypeBlock)(const SampleComplexType&);
+
+- (void)passComplexType:(const SampleComplexType&)foo {
+ return static_cast<complexTypeBlock>([self blockForSelector:_cmd])(foo);
+}
+
+typedef void (^ScalarBlock)(const ScalarType&);
+
+- (void)passScalar:(ScalarType)foo {
+ return static_cast<ScalarBlock>([self blockForSelector:_cmd])(foo);
+}
+
+@end
+
+namespace {
+
+class OCMockComplexTypeHelperTest : public PlatformTest {
+ protected:
+ void SetUp() override {
+ PlatformTest::SetUp();
+ helped_mock_.reset([[MockClass alloc]
+ initWithRepresentedObject:
+ [OCMockObject mockForProtocol:@protocol(TestedProtocol)]]);
+ }
+
+ void TearDown() override {
+ EXPECT_OCMOCK_VERIFY(helped_mock_);
+ PlatformTest::TearDown();
+ }
+
+ base::scoped_nsobject<id> helped_mock_;
+};
+
+TEST_F(OCMockComplexTypeHelperTest, nilObjectStillWorks) {
+ [[helped_mock_ expect] passObject:nil];
+ [helped_mock_ passObject:nil];
+}
+
+TEST_F(OCMockComplexTypeHelperTest, anyObjectStillWorks) {
+ base::scoped_nsobject<id> someObject([[NSObject alloc] init]);
+ [[helped_mock_ expect] passObject:OCMOCK_ANY];
+ [helped_mock_ passObject:someObject];
+}
+
+TEST_F(OCMockComplexTypeHelperTest, complexType) {
+ const SampleComplexType expected_value = {1, 1.0};
+
+ complexTypeBlock block = ^(const SampleComplexType& value) {
+ EXPECT_EQ(expected_value.number, value.number);
+ EXPECT_EQ(expected_value.blob, value.blob);
+ };
+ [helped_mock_ onSelector:@selector(passComplexType:)
+ callBlockExpectation:(id)block];
+
+ [helped_mock_ passComplexType:expected_value];
+}
+
+TEST_F(OCMockComplexTypeHelperTest, scalarType) {
+ const ScalarType expected_value = 42;
+
+ ScalarBlock block = ^(const ScalarType& value) {
+ EXPECT_EQ(expected_value, value);
+ };
+ [helped_mock_ onSelector:@selector(passScalar:)
+ callBlockExpectation:(id)block];
+
+ [helped_mock_ passScalar:expected_value];
+}
+
+} // namespace
« no previous file with comments | « ios/testing/ocmock_complex_type_helper.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698