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

Unified Diff: ios/testing/ocmock_complex_type_helper.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.h ('k') | ios/testing/ocmock_complex_type_helper_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/testing/ocmock_complex_type_helper.mm
diff --git a/ios/testing/ocmock_complex_type_helper.mm b/ios/testing/ocmock_complex_type_helper.mm
new file mode 100644
index 0000000000000000000000000000000000000000..bc89a887d2515b926f72c83fd20f76b07b74b817
--- /dev/null
+++ b/ios/testing/ocmock_complex_type_helper.mm
@@ -0,0 +1,78 @@
+// 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"
+
+@implementation OCMockComplexTypeHelper {
+ // Same as the superclass -representedObject, but retained.
+ base::scoped_nsobject<OCMockObject> _object;
+ // All the blocks registered by selector.
+ base::scoped_nsobject<NSMutableDictionary> _blocks;
+}
+
+#pragma mark - public methods.
+
+- (instancetype)initWithRepresentedObject:(id)object {
+ if ((self = [super initWithRepresentedObject:object]))
+ _object.reset([object retain]);
+ return self;
+}
+
+- (void)onSelector:(SEL)selector callBlockExpectation:(id)block {
+ if (!_blocks)
+ _blocks.reset([[NSMutableDictionary alloc] init]);
+
+ NSString* key = NSStringFromSelector(selector);
+ DCHECK(![_blocks objectForKey:key]) << "Only one expectation per signature";
+ base::scoped_nsobject<id> value([block copy]);
+ [_blocks setObject:value forKey:key];
+}
+
+- (void)removeBlockExpectationOnSelector:(SEL)selector {
+ NSString* key = NSStringFromSelector(selector);
+ DCHECK([_blocks objectForKey:key]) << "No expectation for selector "
+ << [key UTF8String];
+ [_blocks removeObjectForKey:key];
+}
+
+- (id)blockForSelector:(SEL)selector {
+ NSString* key = NSStringFromSelector(selector);
+ id block = [_blocks objectForKey:key];
+ DCHECK(block) << "Missing block expectation for selector "
+ << [key UTF8String];
+ return block;
+}
+
+#pragma mark - OCMockObject forwarding.
+
+// OCMockObject -respondsToSelector responds NO for the OCMock object specific
+// methods. This confuses the GTMLightweightProxy class. In order to forward
+// those properly the simplest approach is to forward them explicitely.
+- (id)stub {
+ return [_object stub];
+}
+- (id)expect {
+ return [_object expect];
+}
+- (id)reject {
+ return [_object reject];
+}
+- (void)verify {
+ [_object verify];
+}
+- (void)setExpectationOrderMatters:(BOOL)flag {
+ [_object setExpectationOrderMatters:flag];
+}
+
+#pragma mark - Internal methods.
+
+- (BOOL)respondsToSelector:(SEL)selector {
+ DCHECK(![_blocks objectForKey:NSStringFromSelector(selector)]);
+ return [super respondsToSelector:selector];
+}
+
+@end
« no previous file with comments | « ios/testing/ocmock_complex_type_helper.h ('k') | ios/testing/ocmock_complex_type_helper_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698