| 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 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." |
| 12 #endif |
| 13 |
| 10 @implementation OCMockComplexTypeHelper { | 14 @implementation OCMockComplexTypeHelper { |
| 11 // Same as the superclass -representedObject, but retained. | 15 // Same as the superclass -representedObject, but retained. |
| 12 base::scoped_nsobject<OCMockObject> _object; | 16 base::scoped_nsobject<OCMockObject> _object; |
| 13 // All the blocks registered by selector. | 17 // All the blocks registered by selector. |
| 14 base::scoped_nsobject<NSMutableDictionary> _blocks; | 18 base::scoped_nsobject<NSMutableDictionary> _blocks; |
| 15 } | 19 } |
| 16 | 20 |
| 17 #pragma mark - public methods. | 21 #pragma mark - public methods. |
| 18 | 22 |
| 19 - (instancetype)initWithRepresentedObject:(id)object { | 23 - (instancetype)initWithRepresentedObject:(id)object { |
| 20 if ((self = [super initWithRepresentedObject:object])) | 24 if ((self = [super initWithRepresentedObject:object])) |
| 21 _object.reset([object retain]); | 25 _object.reset(object); |
| 22 return self; | 26 return self; |
| 23 } | 27 } |
| 24 | 28 |
| 25 - (void)onSelector:(SEL)selector callBlockExpectation:(id)block { | 29 - (void)onSelector:(SEL)selector callBlockExpectation:(id)block { |
| 26 if (!_blocks) | 30 if (!_blocks) |
| 27 _blocks.reset([[NSMutableDictionary alloc] init]); | 31 _blocks.reset([[NSMutableDictionary alloc] init]); |
| 28 | 32 |
| 29 NSString* key = NSStringFromSelector(selector); | 33 NSString* key = NSStringFromSelector(selector); |
| 30 DCHECK(![_blocks objectForKey:key]) << "Only one expectation per signature"; | 34 DCHECK(![_blocks objectForKey:key]) << "Only one expectation per signature"; |
| 31 base::scoped_nsobject<id> value([block copy]); | 35 base::scoped_nsobject<id> value([block copy]); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 73 } |
| 70 | 74 |
| 71 #pragma mark - Internal methods. | 75 #pragma mark - Internal methods. |
| 72 | 76 |
| 73 - (BOOL)respondsToSelector:(SEL)selector { | 77 - (BOOL)respondsToSelector:(SEL)selector { |
| 74 DCHECK(![_blocks objectForKey:NSStringFromSelector(selector)]); | 78 DCHECK(![_blocks objectForKey:NSStringFromSelector(selector)]); |
| 75 return [super respondsToSelector:selector]; | 79 return [super respondsToSelector:selector]; |
| 76 } | 80 } |
| 77 | 81 |
| 78 @end | 82 @end |
| OLD | NEW |