├── .github └── workflows │ └── build-and-test.yaml ├── .gitignore ├── CONTRIBUTING.md ├── Examples ├── ArcExample │ ├── ArcExample.xcodeproj │ │ └── project.pbxproj │ └── ArcExample │ │ ├── ArcExample-Prefix.pch │ │ ├── ArcExample.1 │ │ └── main.m ├── SwiftExamples │ ├── SwiftExamples.xcodeproj │ │ └── project.pbxproj │ ├── SwiftExamples │ │ ├── AppDelegate.swift │ │ ├── Base.lproj │ │ │ └── Main.storyboard │ │ ├── Connection.swift │ │ ├── Controller.swift │ │ ├── DetailViewController.swift │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── LaunchImage.launchimage │ │ │ │ └── Contents.json │ │ ├── Info.plist │ │ └── MasterViewController.swift │ ├── SwiftExamplesTests │ │ ├── Info.plist │ │ ├── MockTests.m │ │ ├── SwiftExamplesTests-Bridging-Header.h │ │ └── SwiftExamplesTests.swift │ └── usr │ │ ├── include │ │ └── OCMock │ │ │ ├── NSNotificationCenter+OCMAdditions.h │ │ │ ├── OCMArg.h │ │ │ ├── OCMConstraint.h │ │ │ ├── OCMLocation.h │ │ │ ├── OCMMacroState.h │ │ │ ├── OCMock.h │ │ │ ├── OCMockObject.h │ │ │ └── OCMockRecorder.h │ │ └── lib │ │ └── libOCMock.a ├── iOS5Example │ ├── iOS5Example.xcodeproj │ │ └── project.pbxproj │ ├── iOS5Example │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── DetailViewController.h │ │ ├── DetailViewController.m │ │ ├── MasterViewController.h │ │ ├── MasterViewController.m │ │ ├── en.lproj │ │ │ ├── InfoPlist.strings │ │ │ ├── MainStoryboard_iPad.storyboard │ │ │ └── MainStoryboard_iPhone.storyboard │ │ ├── iOS5Example-Info.plist │ │ ├── iOS5Example-Prefix.pch │ │ └── main.m │ ├── iOS5ExampleTests │ │ ├── ProtocolTests.h │ │ ├── ProtocolTests.m │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ ├── iOS5ExampleTests-Info.plist │ │ ├── iOS5ExampleTests.h │ │ └── iOS5ExampleTests.m │ └── usr │ │ ├── include │ │ └── OCMock │ │ │ ├── NSNotificationCenter+OCMAdditions.h │ │ │ ├── OCMArg.h │ │ │ ├── OCMConstraint.h │ │ │ ├── OCMock.h │ │ │ ├── OCMockObject.h │ │ │ └── OCMockRecorder.h │ │ └── lib │ │ └── libOCMock.a ├── iOS7Example │ ├── iOS7Example.xcodeproj │ │ └── project.pbxproj │ ├── iOS7Example │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ │ ├── Main_iPad.storyboard │ │ │ └── Main_iPhone.storyboard │ │ ├── DetailViewController.h │ │ ├── DetailViewController.m │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── LaunchImage.launchimage │ │ │ │ └── Contents.json │ │ ├── MasterViewController.h │ │ ├── MasterViewController.m │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ ├── iOS7Example-Info.plist │ │ ├── iOS7Example-Prefix.pch │ │ └── main.m │ ├── iOS7ExampleTests │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ ├── iOS7ExampleTests-Info.plist │ │ └── iOS7ExampleTests.m │ └── usr │ │ ├── include │ │ └── OCMock │ │ │ ├── NSNotificationCenter+OCMAdditions.h │ │ │ ├── OCMArg.h │ │ │ ├── OCMConstraint.h │ │ │ ├── OCMLocation.h │ │ │ ├── OCMMacroState.h │ │ │ ├── OCMRecorder.h │ │ │ ├── OCMStubRecorder.h │ │ │ ├── OCMock.h │ │ │ └── OCMockObject.h │ │ └── lib │ │ └── libOCMock.a ├── iOS9Example │ ├── iOS9Example.xcodeproj │ │ └── project.pbxproj │ ├── iOS9Example │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ ├── DetailViewController.h │ │ ├── DetailViewController.m │ │ ├── Info.plist │ │ ├── MasterViewController.h │ │ ├── MasterViewController.m │ │ └── main.m │ ├── iOS9ExampleTests │ │ ├── Info.plist │ │ └── iOS9ExampleTests.m │ └── usr │ │ ├── include │ │ └── OCMock │ │ │ ├── NSNotificationCenter+OCMAdditions.h │ │ │ ├── OCMArg.h │ │ │ ├── OCMConstraint.h │ │ │ ├── OCMFunctions.h │ │ │ ├── OCMLocation.h │ │ │ ├── OCMMacroState.h │ │ │ ├── OCMRecorder.h │ │ │ ├── OCMStubRecorder.h │ │ │ ├── OCMock.h │ │ │ └── OCMockObject.h │ │ └── lib │ │ └── libOCMock.a └── iPhoneExample │ ├── Classes │ ├── RootViewController.h │ ├── RootViewController.m │ ├── iPhoneExampleAppDelegate.h │ └── iPhoneExampleAppDelegate.m │ ├── Libraries │ ├── Headers │ │ └── OCMock │ │ │ ├── NSNotificationCenter+OCMAdditions.h │ │ │ ├── OCMArg.h │ │ │ ├── OCMConstraint.h │ │ │ ├── OCMock.h │ │ │ ├── OCMockObject.h │ │ │ └── OCMockRecorder.h │ └── libOCMock.a │ ├── MainWindow.xib │ ├── OCMockLogo.png │ ├── RootViewController.xib │ ├── Tests │ ├── RootViewControllerTests.h │ └── RootViewControllerTests.m │ ├── iPhoneExample-Info.plist │ ├── iPhoneExample.xcodeproj │ └── project.pbxproj │ ├── iPhoneExampleTests-Info.plist │ ├── iPhoneExample_Prefix.pch │ └── main.m ├── License.txt ├── Makefile ├── OCMock.podspec ├── Package.swift ├── README.md ├── Source ├── .clang-format ├── Cartfile ├── Changes.txt ├── OCMock.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ ├── OCMock iOS.xcscheme │ │ ├── OCMock tvOS.xcscheme │ │ ├── OCMock watchOS.xcscheme │ │ ├── OCMock.xcscheme │ │ └── OCMockLib.xcscheme ├── OCMock │ ├── NSInvocation+OCMAdditions.h │ ├── NSInvocation+OCMAdditions.m │ ├── NSMethodSignature+OCMAdditions.h │ ├── NSMethodSignature+OCMAdditions.m │ ├── NSNotificationCenter+OCMAdditions.h │ ├── NSNotificationCenter+OCMAdditions.m │ ├── NSObject+OCMAdditions.h │ ├── NSObject+OCMAdditions.m │ ├── NSValue+OCMAdditions.h │ ├── NSValue+OCMAdditions.m │ ├── OCClassMockObject.h │ ├── OCClassMockObject.m │ ├── OCMArg.h │ ├── OCMArg.m │ ├── OCMArgAction.h │ ├── OCMArgAction.m │ ├── OCMBlockArgCaller.h │ ├── OCMBlockArgCaller.m │ ├── OCMBlockCaller.h │ ├── OCMBlockCaller.m │ ├── OCMBoxedReturnValueProvider.h │ ├── OCMBoxedReturnValueProvider.m │ ├── OCMConstraint.h │ ├── OCMConstraint.m │ ├── OCMExceptionReturnValueProvider.h │ ├── OCMExceptionReturnValueProvider.m │ ├── OCMExpectationRecorder.h │ ├── OCMExpectationRecorder.m │ ├── OCMFunctions.h │ ├── OCMFunctions.m │ ├── OCMFunctionsPrivate.h │ ├── OCMIndirectReturnValueProvider.h │ ├── OCMIndirectReturnValueProvider.m │ ├── OCMInvocationExpectation.h │ ├── OCMInvocationExpectation.m │ ├── OCMInvocationMatcher.h │ ├── OCMInvocationMatcher.m │ ├── OCMInvocationStub.h │ ├── OCMInvocationStub.m │ ├── OCMLocation.h │ ├── OCMLocation.m │ ├── OCMMacroState.h │ ├── OCMMacroState.m │ ├── OCMNonRetainingObjectReturnValueProvider.h │ ├── OCMNonRetainingObjectReturnValueProvider.m │ ├── OCMNotificationPoster.h │ ├── OCMNotificationPoster.m │ ├── OCMObjectReturnValueProvider.h │ ├── OCMObjectReturnValueProvider.m │ ├── OCMObserverRecorder.h │ ├── OCMObserverRecorder.m │ ├── OCMPassByRefSetter.h │ ├── OCMPassByRefSetter.m │ ├── OCMQuantifier.h │ ├── OCMQuantifier.m │ ├── OCMRealObjectForwarder.h │ ├── OCMRealObjectForwarder.m │ ├── OCMRecorder.h │ ├── OCMRecorder.m │ ├── OCMStubRecorder.h │ ├── OCMStubRecorder.m │ ├── OCMVerifier.h │ ├── OCMVerifier.m │ ├── OCMock-Info.plist │ ├── OCMock-Prefix.pch │ ├── OCMock.h │ ├── OCMockMacros.h │ ├── OCMockObject.h │ ├── OCMockObject.m │ ├── OCObserverMockObject.h │ ├── OCObserverMockObject.m │ ├── OCPartialMockObject.h │ ├── OCPartialMockObject.m │ ├── OCProtocolMockObject.h │ └── OCProtocolMockObject.m ├── OCMockCI.xcconfig ├── OCMockDist.xcconfig ├── OCMockLib │ └── OCMockLib-Prefix.pch ├── OCMockLibTests │ ├── OCMockLibTests-Info.plist │ └── OCMockLibTests-Prefix.pch ├── OCMockTests │ ├── NSInvocationOCMAdditionsTests.m │ ├── NSMethodSignatureOCMAdditionsTests.m │ ├── OCMArgTests.m │ ├── OCMBoxedReturnValueProviderTests.m │ ├── OCMCPlusPlus11Tests.mm │ ├── OCMCPlusPlus98Tests.mm │ ├── OCMConstraintTests.m │ ├── OCMFunctionsTests.m │ ├── OCMInvocationMatcherTests.m │ ├── OCMNoEscapeBlockTests.m │ ├── OCMQuantifierTests.m │ ├── OCMStubRecorderTests.m │ ├── OCMockObjectClassMethodMockingTests.m │ ├── OCMockObjectDynamicPropertyMockingTests.m │ ├── OCMockObjectForwardingTargetTests.m │ ├── OCMockObjectHamcrestTests.m │ ├── OCMockObjectInternalTests.m │ ├── OCMockObjectMacroTests.m │ ├── OCMockObjectPartialMocksTests.m │ ├── OCMockObjectProtocolMocksTests.m │ ├── OCMockObjectRuntimeTests.m │ ├── OCMockObjectTests.m │ ├── OCMockObjectVerifyAfterRunTests.m │ ├── OCMockTests-Info.plist │ ├── OCMockTests-Prefix.pch │ ├── OCObserverMockObjectTests.m │ ├── Resources │ │ └── TestObjects.xcdatamodeld │ │ │ └── TestObjects.xcdatamodel │ │ │ └── contents │ ├── TestClassWithCustomReferenceCounting.h │ └── TestClassWithCustomReferenceCounting.m └── module.modulemap ├── SwiftPMTests ├── objc │ ├── objc-header.m │ └── objc-module.m └── swift │ └── main.swift └── Tools ├── buildcheck.rb ├── makedmg.rb └── updatebanner.rb /.github/workflows/build-and-test.yaml: -------------------------------------------------------------------------------- 1 | name: Build and test 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | build-and-run-unit-tests: 13 | runs-on: macos-14 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: macOS 17 | run: make ci-macos 18 | check-dist: 19 | needs: build-and-run-unit-tests 20 | runs-on: macos-14 21 | steps: 22 | - uses: actions/checkout@v4 23 | - name: SwiftPM 24 | run: make ci-swiftpm 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | xcuserdata 3 | *.xcworkspace 4 | .idea 5 | .build 6 | build 7 | Carthage 8 | -------------------------------------------------------------------------------- /Examples/ArcExample/ArcExample/ArcExample-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ArcExample' target in the 'ArcExample' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Examples/ArcExample/ArcExample/main.m: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | #import 4 | 5 | @protocol SomeDelegateProtocol 6 | - (void)doStuff; 7 | @end 8 | 9 | @interface SomeClass : NSObject 10 | @property (nonatomic, weak) id delegate; 11 | @end 12 | 13 | @implementation SomeClass 14 | 15 | @synthesize delegate; 16 | 17 | @end 18 | 19 | 20 | int main (int argc, const char * argv[]) 21 | { 22 | 23 | @autoreleasepool { 24 | 25 | SomeClass *someObject = [[SomeClass alloc] init]; 26 | id delegate = [OCMockObject mockForProtocol:@protocol(SomeDelegateProtocol)]; 27 | someObject.delegate = delegate; 28 | NSLog(@"delegate = %@", delegate); 29 | NSLog(@"someObject = %@", someObject.delegate); 30 | 31 | } 32 | return 0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamples/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftExamples 4 | // 5 | // Created by Erik Doernenburg on 11/06/2014. 6 | // Copyright (c) 2014 Mulle Kybernetik. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamples/Connection.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Connection.swift 3 | // SwiftExperiments 4 | // 5 | // Created by Erik D on 05/06/14. 6 | // Copyright (c) 2014 Mulle Kybernetik. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | @objc 12 | protocol Connection { 13 | func fetchData() -> String 14 | } 15 | 16 | class ServerConnection : NSObject, Connection { 17 | func fetchData() -> String { 18 | return "real data returned from other system" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamples/Controller.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Controller.swift 3 | // SwiftExperiments 4 | // 5 | // Created by Erik D on 05/06/14. 6 | // Copyright (c) 2014 Mulle Kybernetik. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class Controller: NSObject { 12 | var connection: Connection; 13 | var data: String; 14 | 15 | class func newController() -> Controller { 16 | return Controller() 17 | } 18 | 19 | override init() { 20 | self.connection = ServerConnection(); 21 | self.data = ""; 22 | } 23 | 24 | func redisplay() { 25 | data = connection.fetchData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamples/DetailViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.swift 3 | // SwiftExamples 4 | // 5 | // Created by Erik Doernenburg on 11/06/2014. 6 | // Copyright (c) 2014 Mulle Kybernetik. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DetailViewController: UIViewController { 12 | 13 | @IBOutlet weak var detailDescriptionLabel: UILabel! 14 | 15 | 16 | var detailItem: AnyObject? { 17 | didSet { 18 | // Update the view. 19 | self.configureView() 20 | } 21 | } 22 | 23 | func configureView() { 24 | // Update the user interface for the detail item. 25 | if let detail: AnyObject = self.detailItem { 26 | if let label = self.detailDescriptionLabel { 27 | label.text = detail.description 28 | } 29 | } 30 | } 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | // Do any additional setup after loading the view, typically from a nib. 35 | self.configureView() 36 | } 37 | 38 | override func didReceiveMemoryWarning() { 39 | super.didReceiveMemoryWarning() 40 | // Dispose of any resources that can be recreated. 41 | } 42 | 43 | 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamples/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "ipad", 20 | "size" : "29x29", 21 | "scale" : "1x" 22 | }, 23 | { 24 | "idiom" : "ipad", 25 | "size" : "29x29", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "ipad", 30 | "size" : "40x40", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "40x40", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "76x76", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "76x76", 46 | "scale" : "2x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamples/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "orientation" : "portrait", 20 | "idiom" : "ipad", 21 | "extent" : "full-screen", 22 | "minimum-system-version" : "7.0", 23 | "scale" : "1x" 24 | }, 25 | { 26 | "orientation" : "landscape", 27 | "idiom" : "ipad", 28 | "extent" : "full-screen", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "1x" 31 | }, 32 | { 33 | "orientation" : "portrait", 34 | "idiom" : "ipad", 35 | "extent" : "full-screen", 36 | "minimum-system-version" : "7.0", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "orientation" : "landscape", 41 | "idiom" : "ipad", 42 | "extent" : "full-screen", 43 | "minimum-system-version" : "7.0", 44 | "scale" : "2x" 45 | } 46 | ], 47 | "info" : { 48 | "version" : 1, 49 | "author" : "xcode" 50 | } 51 | } -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamples/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.mulle-kybernetik.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UIStatusBarTintParameters 32 | 33 | UINavigationBar 34 | 35 | Style 36 | UIBarStyleDefault 37 | Translucent 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamplesTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.mulle-kybernetik.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamplesTests/MockTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MockTests.m 3 | // SwiftExamples 4 | // 5 | // Created by Erik Doernenburg on 11/06/2014. 6 | // Copyright (c) 2014 Mulle Kybernetik. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "SwiftExamplesTests-Swift.h" 12 | 13 | 14 | @interface MockTests : XCTestCase 15 | 16 | @end 17 | 18 | @implementation MockTests 19 | 20 | - (void)testThatOCMockWorksInSwiftProject 21 | { 22 | id mock = OCMClassMock([NSString class]); 23 | 24 | [mock lowercaseString]; 25 | 26 | OCMVerify([mock lowercaseString]); 27 | } 28 | 29 | - (void)testMockingAnObject 30 | { 31 | id mock = OCMClassMock([ServerConnection class]); 32 | OCMStub([mock fetchData]).andReturn(@"stubbed!"); 33 | 34 | Controller *controller = [Controller newController]; 35 | controller.connection = mock; 36 | 37 | [controller redisplay]; 38 | 39 | OCMVerify([mock fetchData]); 40 | XCTAssertEqualObjects(@"stubbed!", controller.data, @"Excpected stubbed data in controller."); 41 | } 42 | 43 | - (void)testPartiallyMockingAnObject 44 | { 45 | ServerConnection *testConnection = [ServerConnection new]; 46 | id mock = OCMPartialMock(testConnection); 47 | OCMStub([mock fetchData]).andReturn(@"stubbed!"); 48 | 49 | Controller *controller = [Controller newController]; 50 | controller.connection = testConnection; 51 | 52 | [controller redisplay]; 53 | 54 | OCMVerify([mock fetchData]); 55 | XCTAssertEqualObjects(@"stubbed!", controller.data, @"Excpected stubbed data in controller."); 56 | } 57 | 58 | - (void)testPartiallyMockingAnObject2 59 | { 60 | Controller *controller = [Controller newController]; 61 | 62 | id mock = OCMPartialMock((NSObject *)controller.connection); // we know connection is derived from NSObject... 63 | OCMStub([mock fetchData]).andReturn(@"stubbed!"); 64 | 65 | [controller redisplay]; 66 | 67 | OCMVerify([mock fetchData]); 68 | XCTAssertEqualObjects(@"stubbed!", controller.data, @"Excpected stubbed data in controller."); 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamplesTests/SwiftExamplesTests-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/SwiftExamplesTests/SwiftExamplesTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftExamplesTests.swift 3 | // SwiftExamplesTests 4 | // 5 | // Created by Erik Doernenburg on 11/06/2014. 6 | // Copyright (c) 2014 Mulle Kybernetik. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class SwiftExamplesTests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | super.tearDown() 21 | } 22 | 23 | func testExample() { 24 | // This is an example of a functional test case. 25 | XCTAssert(true, "Pass") 26 | } 27 | 28 | func testPerformanceExample() { 29 | // This is an example of a performance test case. 30 | self.measureBlock() { 31 | // Put the code you want to measure the time of here. 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/include/OCMock/NSNotificationCenter+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCObserverMockObject; 20 | 21 | 22 | @interface NSNotificationCenter(OCMAdditions) 23 | 24 | - (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/include/OCMock/OCMArg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMArg : NSObject 20 | 21 | // constraining arguments 22 | 23 | + (id)any; 24 | + (SEL)anySelector; 25 | + (void *)anyPointer; 26 | + (id __autoreleasing *)anyObjectRef; 27 | + (id)isNil; 28 | + (id)isNotNil; 29 | + (id)isNotEqual:(id)value; 30 | + (id)checkWithSelector:(SEL)selector onObject:(id)anObject; 31 | + (id)checkWithBlock:(BOOL (^)(id obj))block; 32 | 33 | // manipulating arguments 34 | 35 | + (id *)setTo:(id)value; 36 | + (void *)setToValue:(NSValue *)value; 37 | 38 | // internal use only 39 | 40 | + (id)resolveSpecialValues:(NSValue *)value; 41 | 42 | @end 43 | 44 | #define OCMOCK_ANY [OCMArg any] 45 | 46 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 47 | #define OCMOCK_VALUE(variable) \ 48 | ({ __typeof__(variable) __v = (variable); [NSValue value:&__v withObjCType:@encode(__typeof__(__v))]; }) 49 | #else 50 | #define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))] 51 | #endif 52 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/include/OCMock/OCMConstraint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | 20 | @interface OCMConstraint : NSObject 21 | 22 | + (id)constraint; 23 | - (BOOL)evaluate:(id)value; 24 | 25 | // if you are looking for any, isNil, etc, they have moved to OCMArg 26 | 27 | // try to use [OCMArg checkWith...] instead of the constraintWith... methods below 28 | 29 | + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; 30 | + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; 31 | 32 | 33 | @end 34 | 35 | @interface OCMAnyConstraint : OCMConstraint 36 | @end 37 | 38 | @interface OCMIsNilConstraint : OCMConstraint 39 | @end 40 | 41 | @interface OCMIsNotNilConstraint : OCMConstraint 42 | @end 43 | 44 | @interface OCMIsNotEqualConstraint : OCMConstraint 45 | { 46 | @public 47 | id testValue; 48 | } 49 | 50 | @end 51 | 52 | @interface OCMInvocationConstraint : OCMConstraint 53 | { 54 | @public 55 | NSInvocation *invocation; 56 | } 57 | 58 | @end 59 | 60 | @interface OCMBlockConstraint : OCMConstraint 61 | { 62 | BOOL (^block)(id); 63 | } 64 | 65 | - (id)initWithConstraintBlock:(BOOL (^)(id))block; 66 | 67 | @end 68 | 69 | 70 | #define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self] 71 | #define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)] 72 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/include/OCMock/OCMLocation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMLocation : NSObject 20 | { 21 | id testCase; 22 | NSString *file; 23 | NSUInteger line; 24 | } 25 | 26 | + (id)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; 27 | 28 | - (id)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; 29 | 30 | - (id)testCase; 31 | - (NSString *)file; 32 | - (NSUInteger)line; 33 | 34 | @end 35 | 36 | extern OCMLocation *OCMMakeLocation(id testCase, const char *file, int line); 37 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/include/OCMock/OCMMacroState.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMockRecorder; 21 | 22 | 23 | @interface OCMMacroState : NSObject 24 | { 25 | } 26 | 27 | + (void)beginStubMacro; 28 | + (OCMockRecorder *)endStubMacro; 29 | 30 | + (void)beginExpectMacro; 31 | + (OCMockRecorder *)endExpectMacro; 32 | 33 | + (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation; 34 | + (void)endVerifyMacro; 35 | 36 | + (OCMMacroState *)globalState; 37 | 38 | - (void)switchToClassMethod; 39 | - (BOOL)hasSwitchedToClassMethod; 40 | 41 | - (void)handleInvocation:(NSInvocation *)anInvocation; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/include/OCMock/OCMock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import 19 | #import 20 | #import 21 | #import 22 | #import 23 | #import 24 | 25 | 26 | #define OCMClassMock(cls) [OCMockObject niceMockForClass:cls] 27 | 28 | #define OCMStrictClassMock(cls) [OCMockObject mockForClass:cls] 29 | 30 | #define OCMProtocolMock(protocol) [OCMockObject niceMockForProtocol:protocol] 31 | 32 | #define OCMStrictProtocolMock(protocol) [OCMockObject mockForProtocol:protocol] 33 | 34 | #define OCMPartialMock(obj) [OCMockObject partialMockForObject:obj] 35 | 36 | #define OCMObserverMock() [OCMockObject observerMock] 37 | 38 | 39 | #define OCMStub(invocation) \ 40 | ({ \ 41 | [OCMMacroState beginStubMacro]; \ 42 | invocation; \ 43 | [OCMMacroState endStubMacro]; \ 44 | }) 45 | 46 | #define OCMExpect(invocation) \ 47 | ({ \ 48 | [OCMMacroState beginExpectMacro]; \ 49 | invocation; \ 50 | [OCMMacroState endExpectMacro]; \ 51 | }) 52 | 53 | #define ClassMethod(invocation) \ 54 | [[OCMMacroState globalState] switchToClassMethod]; \ 55 | invocation; 56 | 57 | 58 | #define OCMVerifyAll(mock) [mock verifyAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)] 59 | 60 | #define OCMVerifyAllWithDelay(mock, delay) [mock verifyWithDelay:delay atLocation:OCMMakeLocation(self, __FILE__, __LINE__)] 61 | 62 | #define OCMVerify(invocation) \ 63 | ({ \ 64 | [OCMMacroState beginVerifyMacroAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)]; \ 65 | invocation; \ 66 | [OCMMacroState endVerifyMacro]; \ 67 | }) 68 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/include/OCMock/OCMockObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMockRecorder; 21 | @class OCMInvocationMatcher; 22 | 23 | 24 | @interface OCMockObject : NSProxy 25 | { 26 | BOOL isNice; 27 | BOOL expectationOrderMatters; 28 | NSMutableArray *recorders; 29 | NSMutableArray *expectations; 30 | NSMutableArray *rejections; 31 | NSMutableArray *exceptions; 32 | NSMutableArray *invocations; 33 | } 34 | 35 | + (id)mockForClass:(Class)aClass; 36 | + (id)mockForProtocol:(Protocol *)aProtocol; 37 | + (id)partialMockForObject:(NSObject *)anObject; 38 | 39 | + (id)niceMockForClass:(Class)aClass; 40 | + (id)niceMockForProtocol:(Protocol *)aProtocol; 41 | 42 | + (id)observerMock; 43 | 44 | - (id)init; 45 | 46 | - (void)setExpectationOrderMatters:(BOOL)flag; 47 | 48 | - (id)stub; 49 | - (id)expect; 50 | - (id)reject; 51 | 52 | - (id)verify; 53 | - (id)verifyAtLocation:(OCMLocation *)location; 54 | 55 | - (void)verifyWithDelay:(NSTimeInterval)delay; 56 | - (void)verifyWithDelay:(NSTimeInterval)delay atLocation:(OCMLocation *)location; 57 | 58 | - (void)stopMocking; 59 | 60 | // internal use only 61 | 62 | - (void)prepareForMockingMethod:(__unused SEL)aSelector; 63 | - (void)prepareForMockingClassMethod:(__unused SEL)aSelector; 64 | 65 | - (BOOL)handleInvocation:(NSInvocation *)anInvocation; 66 | - (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation; 67 | - (BOOL)handleSelector:(SEL)sel; 68 | 69 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher; 70 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher atLocation:(OCMLocation *)location; 71 | 72 | @end 73 | 74 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/include/OCMock/OCMockRecorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMockObject; 20 | @class OCMInvocationMatcher; 21 | 22 | 23 | @interface OCMockRecorder : NSProxy 24 | { 25 | OCMockObject *mockObject; 26 | OCMInvocationMatcher *invocationMatcher; 27 | NSMutableArray *invocationHandlers; 28 | } 29 | 30 | - (id)initWithMockObject:(OCMockObject *)aMockObject; 31 | 32 | //- (void)releaseInvocation; 33 | 34 | - (id)andReturn:(id)anObject; 35 | - (id)andReturnValue:(NSValue *)aValue; 36 | - (id)andThrow:(NSException *)anException; 37 | - (id)andPost:(NSNotification *)aNotification; 38 | - (id)andCall:(SEL)selector onObject:(id)anObject; 39 | - (id)andDo:(void (^)(NSInvocation *invocation))block; 40 | - (id)andForwardToRealObject; 41 | 42 | - (id)classMethod; 43 | - (id)ignoringNonObjectArgs; 44 | 45 | - (OCMInvocationMatcher *)invocationMatcher; 46 | 47 | - (void)addInvocationHandler:(id)aHandler; 48 | - (NSArray *)invocationHandlers; 49 | 50 | @end 51 | 52 | 53 | @interface OCMockRecorder(Properties) 54 | 55 | #define andReturn(aValue) _andReturn(({ typeof(aValue) _v = (aValue); [NSValue value:&_v withObjCType:@encode(typeof(_v))]; })) 56 | @property (nonatomic, readonly) OCMockRecorder *(^ _andReturn)(NSValue *); 57 | 58 | #define andThrow(anException) _andThrow(anException) 59 | @property (nonatomic, readonly) OCMockRecorder *(^ _andThrow)(NSException *); 60 | 61 | #define andPost(aNotification) _andPost(aNotification) 62 | @property (nonatomic, readonly) OCMockRecorder *(^ _andPost)(NSNotification *); 63 | 64 | #define andCall(anObject, aSelector) _andCall(anObject, aSelector) 65 | @property (nonatomic, readonly) OCMockRecorder *(^ _andCall)(id, SEL); 66 | 67 | #define andDo(aBlock) _andDo(aBlock) 68 | @property (nonatomic, readonly) OCMockRecorder *(^ _andDo)(void (^)(NSInvocation *)); 69 | 70 | #define andForwardToRealObject() _andForwardToRealObject() 71 | @property (nonatomic, readonly) OCMockRecorder *(^ _andForwardToRealObject)(void); 72 | 73 | @end 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Examples/SwiftExamples/usr/lib/libOCMock.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikdoe/ocmock/7f6e9e9b6c9ffa19a9040860da9f7a1f202b9f4d/Examples/SwiftExamples/usr/lib/libOCMock.a -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // iOS5Example 4 | // 5 | 6 | #import 7 | 8 | @interface AppDelegate : UIResponder 9 | 10 | @property (strong, nonatomic) UIWindow *window; 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5Example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // iOS5Example 4 | // 5 | 6 | #import "AppDelegate.h" 7 | 8 | @implementation AppDelegate 9 | 10 | @synthesize window = _window; 11 | 12 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 13 | { 14 | // Override point for customization after application launch. 15 | if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 16 | UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; 17 | UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; 18 | splitViewController.delegate = (id)navigationController.topViewController; 19 | } 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application 24 | { 25 | /* 26 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 27 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 28 | */ 29 | } 30 | 31 | - (void)applicationDidEnterBackground:(UIApplication *)application 32 | { 33 | /* 34 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 35 | If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 36 | */ 37 | } 38 | 39 | - (void)applicationWillEnterForeground:(UIApplication *)application 40 | { 41 | /* 42 | Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 43 | */ 44 | } 45 | 46 | - (void)applicationDidBecomeActive:(UIApplication *)application 47 | { 48 | /* 49 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 50 | */ 51 | } 52 | 53 | - (void)applicationWillTerminate:(UIApplication *)application 54 | { 55 | /* 56 | Called when the application is about to terminate. 57 | Save data if appropriate. 58 | See also applicationDidEnterBackground:. 59 | */ 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5Example/DetailViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.h 3 | // iOS5Example 4 | // 5 | 6 | #import 7 | 8 | @interface DetailViewController : UIViewController 9 | 10 | @property (strong, nonatomic) id detailItem; 11 | 12 | @property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5Example/MasterViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MasterViewController.h 3 | // iOS5Example 4 | // 5 | 6 | #import 7 | 8 | @class DetailViewController; 9 | 10 | @interface MasterViewController : UITableViewController 11 | 12 | @property (strong, nonatomic) DetailViewController *detailViewController; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5Example/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5Example/iOS5Example-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFiles 12 | 13 | CFBundleIdentifier 14 | com.mulle-kybernetik.ocmock.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1.0 27 | LSRequiresIPhoneOS 28 | 29 | UIMainStoryboardFile 30 | MainStoryboard_iPhone 31 | UIMainStoryboardFile~ipad 32 | MainStoryboard_iPad 33 | UIRequiredDeviceCapabilities 34 | 35 | armv7 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | UISupportedInterfaceOrientations~ipad 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationPortraitUpsideDown 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5Example/iOS5Example-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'iOS5Example' target in the 'iOS5Example' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5Example/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // iOS5Example 4 | // 5 | 6 | #import 7 | 8 | #import "AppDelegate.h" 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | @autoreleasepool { 13 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5ExampleTests/ProtocolTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // ProtocolTests.h 3 | // iOS5Example 4 | // 5 | 6 | #import 7 | 8 | @interface ProtocolTests : SenTestCase 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5ExampleTests/ProtocolTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ProtocolTests.m 3 | // iOS5Example 4 | // 5 | 6 | #import 7 | #import "ProtocolTests.h" 8 | 9 | 10 | @protocol AuthenticationServiceProtocol 11 | 12 | - (void)loginWithEmail:(NSString *)email andPassword:(NSString *)password; 13 | 14 | @end 15 | 16 | @interface Foo : NSObject 17 | { 18 | id authService; 19 | } 20 | 21 | - (id)initWithAuthenticationService:(id)anAuthService; 22 | - (void)doStuff; 23 | 24 | @end 25 | 26 | @implementation Foo 27 | 28 | - (id)initWithAuthenticationService:(id)anAuthService 29 | { 30 | self = [super init]; 31 | authService = anAuthService; 32 | return self; 33 | } 34 | 35 | - (void)doStuff 36 | { 37 | [authService loginWithEmail:@"x" andPassword:@"y"]; 38 | } 39 | 40 | @end 41 | 42 | @implementation ProtocolTests 43 | 44 | - (void)testTheProtocol 45 | { 46 | id authService = [OCMockObject mockForProtocol:@protocol(AuthenticationServiceProtocol)]; 47 | id foo = [[Foo alloc] initWithAuthenticationService:authService]; 48 | 49 | [[authService expect] loginWithEmail:[OCMArg any] andPassword:[OCMArg any]]; 50 | 51 | [foo doStuff]; 52 | 53 | [authService verify]; 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5ExampleTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5ExampleTests/iOS5ExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.mulle-kybernetik.ocmock.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5ExampleTests/iOS5ExampleTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // iOS5ExampleTests.h 3 | // iOS5ExampleTests 4 | // 5 | 6 | #import 7 | 8 | @interface iOS5ExampleTests : SenTestCase 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /Examples/iOS5Example/iOS5ExampleTests/iOS5ExampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // iOS5ExampleTests.m 3 | // iOS5ExampleTests 4 | // 5 | 6 | #import 7 | #import "MasterViewController.h" 8 | #import "iOS5ExampleTests.h" 9 | 10 | @implementation iOS5ExampleTests 11 | 12 | - (void)setUp 13 | { 14 | [super setUp]; 15 | 16 | // Set-up code here. 17 | } 18 | 19 | - (void)tearDown 20 | { 21 | // Tear-down code here. 22 | 23 | [super tearDown]; 24 | } 25 | 26 | - (void)testMasterViewControllerDeletesItemsFromTableView 27 | { 28 | // Test set-up 29 | 30 | MasterViewController *controller = [[MasterViewController alloc] init]; 31 | NSIndexPath *dummyIndexPath = [NSIndexPath indexPathWithIndex:3]; 32 | id tableViewMock = [OCMockObject mockForClass:[UITableView class]]; 33 | [[tableViewMock expect] deleteRowsAtIndexPaths:[NSArray arrayWithObject:dummyIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 34 | 35 | // Invoke functionality to be tested 36 | // If you want to see the test fail you can, for example, change the editing style to UITableViewCellEditingStyleNone. In 37 | // that case the method in the controller does not make a call to the table view and the mock will raise an exception when 38 | // verify is called further down. 39 | 40 | [controller tableView:tableViewMock commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:dummyIndexPath]; 41 | 42 | // Verify that expectations were met 43 | 44 | [tableViewMock verify]; 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Examples/iOS5Example/usr/include/OCMock/NSNotificationCenter+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id$ 3 | // Copyright (c) 2009 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | @class OCMockObserver; 9 | 10 | 11 | @interface NSNotificationCenter(OCMAdditions) 12 | 13 | - (void)addMockObserver:(OCMockObserver *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/iOS5Example/usr/include/OCMock/OCMArg.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id$ 3 | // Copyright (c) 2009-2010 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | @interface OCMArg : NSObject 9 | 10 | // constraining arguments 11 | 12 | + (id)any; 13 | + (void *)anyPointer; 14 | + (id)isNil; 15 | + (id)isNotNil; 16 | + (id)isNotEqual:(id)value; 17 | + (id)checkWithSelector:(SEL)selector onObject:(id)anObject; 18 | #if NS_BLOCKS_AVAILABLE 19 | + (id)checkWithBlock:(BOOL (^)(id))block; 20 | #endif 21 | 22 | // manipulating arguments 23 | 24 | + (id *)setTo:(id)value; 25 | 26 | // internal use only 27 | 28 | + (id)resolveSpecialValues:(NSValue *)value; 29 | 30 | @end 31 | 32 | #define OCMOCK_ANY [OCMArg any] 33 | #define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))] 34 | -------------------------------------------------------------------------------- /Examples/iOS5Example/usr/include/OCMock/OCMConstraint.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id$ 3 | // Copyright (c) 2007-2010 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | 9 | @interface OCMConstraint : NSObject 10 | 11 | + (id)constraint; 12 | - (BOOL)evaluate:(id)value; 13 | 14 | // if you are looking for any, isNil, etc, they have moved to OCMArg 15 | 16 | // try to use [OCMArg checkWith...] instead of the constraintWith... methods below 17 | 18 | + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; 19 | + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; 20 | 21 | 22 | @end 23 | 24 | @interface OCMAnyConstraint : OCMConstraint 25 | @end 26 | 27 | @interface OCMIsNilConstraint : OCMConstraint 28 | @end 29 | 30 | @interface OCMIsNotNilConstraint : OCMConstraint 31 | @end 32 | 33 | @interface OCMIsNotEqualConstraint : OCMConstraint 34 | { 35 | @public 36 | id testValue; 37 | } 38 | 39 | @end 40 | 41 | @interface OCMInvocationConstraint : OCMConstraint 42 | { 43 | @public 44 | NSInvocation *invocation; 45 | } 46 | 47 | @end 48 | 49 | #if NS_BLOCKS_AVAILABLE 50 | 51 | @interface OCMBlockConstraint : OCMConstraint 52 | { 53 | BOOL (^block)(id); 54 | } 55 | 56 | - (id)initWithConstraintBlock:(BOOL (^)(id))block; 57 | 58 | @end 59 | 60 | #endif 61 | 62 | 63 | #define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self] 64 | #define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)] 65 | -------------------------------------------------------------------------------- /Examples/iOS5Example/usr/include/OCMock/OCMock.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id$ 3 | // Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | #import 8 | #import 9 | #import 10 | #import 11 | -------------------------------------------------------------------------------- /Examples/iOS5Example/usr/include/OCMock/OCMockObject.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id$ 3 | // Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | @interface OCMockObject : NSProxy 9 | { 10 | BOOL isNice; 11 | BOOL expectationOrderMatters; 12 | NSMutableArray *recorders; 13 | NSMutableArray *expectations; 14 | NSMutableArray *rejections; 15 | NSMutableArray *exceptions; 16 | } 17 | 18 | + (id)mockForClass:(Class)aClass; 19 | + (id)mockForProtocol:(Protocol *)aProtocol; 20 | + (id)partialMockForObject:(NSObject *)anObject; 21 | 22 | + (id)niceMockForClass:(Class)aClass; 23 | + (id)niceMockForProtocol:(Protocol *)aProtocol; 24 | 25 | + (id)observerMock; 26 | 27 | - (id)init; 28 | 29 | - (void)setExpectationOrderMatters:(BOOL)flag; 30 | 31 | - (id)stub; 32 | - (id)expect; 33 | - (id)reject; 34 | 35 | - (void)verify; 36 | 37 | // internal use only 38 | 39 | - (id)getNewRecorder; 40 | - (BOOL)handleInvocation:(NSInvocation *)anInvocation; 41 | - (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Examples/iOS5Example/usr/include/OCMock/OCMockRecorder.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id$ 3 | // Copyright (c) 2004-2010 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | @interface OCMockRecorder : NSProxy 9 | { 10 | id signatureResolver; 11 | NSInvocation *recordedInvocation; 12 | NSMutableArray *invocationHandlers; 13 | } 14 | 15 | - (id)initWithSignatureResolver:(id)anObject; 16 | 17 | - (BOOL)matchesInvocation:(NSInvocation *)anInvocation; 18 | - (void)releaseInvocation; 19 | 20 | - (id)andReturn:(id)anObject; 21 | - (id)andReturnValue:(NSValue *)aValue; 22 | - (id)andThrow:(NSException *)anException; 23 | - (id)andPost:(NSNotification *)aNotification; 24 | - (id)andCall:(SEL)selector onObject:(id)anObject; 25 | #if NS_BLOCKS_AVAILABLE 26 | - (id)andDo:(void (^)(NSInvocation *))block; 27 | #endif 28 | - (id)andForwardToRealObject; 29 | 30 | - (NSArray *)invocationHandlers; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Examples/iOS5Example/usr/lib/libOCMock.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikdoe/ocmock/7f6e9e9b6c9ffa19a9040860da9f7a1f202b9f4d/Examples/iOS5Example/usr/lib/libOCMock.a -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // iOS7Example 4 | // 5 | // Created by Erik Doernenburg on 10/06/2014. 6 | // Copyright (c) 2014 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // iOS7Example 4 | // 5 | // Created by Erik Doernenburg on 10/06/2014. 6 | // Copyright (c) 2014 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 17 | UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; 18 | UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; 19 | splitViewController.delegate = (id)navigationController.topViewController; 20 | } 21 | return YES; 22 | } 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application 25 | { 26 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 27 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 28 | } 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application 31 | { 32 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 33 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 34 | } 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application 37 | { 38 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application 42 | { 43 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 44 | } 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application 47 | { 48 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/DetailViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.h 3 | // iOS7Example 4 | // 5 | // Created by Erik Doernenburg on 10/06/2014. 6 | // Copyright (c) 2014 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DetailViewController : UIViewController 12 | 13 | @property (strong, nonatomic) id detailItem; 14 | 15 | @property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel; 16 | @end 17 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/DetailViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.m 3 | // iOS7Example 4 | // 5 | // Created by Erik Doernenburg on 10/06/2014. 6 | // Copyright (c) 2014 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import "DetailViewController.h" 10 | 11 | @interface DetailViewController () 12 | @property (strong, nonatomic) UIPopoverController *masterPopoverController; 13 | - (void)configureView; 14 | @end 15 | 16 | @implementation DetailViewController 17 | 18 | #pragma mark - Managing the detail item 19 | 20 | - (void)setDetailItem:(id)newDetailItem 21 | { 22 | if (_detailItem != newDetailItem) { 23 | _detailItem = newDetailItem; 24 | 25 | // Update the view. 26 | [self configureView]; 27 | } 28 | 29 | if (self.masterPopoverController != nil) { 30 | [self.masterPopoverController dismissPopoverAnimated:YES]; 31 | } 32 | } 33 | 34 | - (void)configureView 35 | { 36 | // Update the user interface for the detail item. 37 | 38 | if (self.detailItem) { 39 | self.detailDescriptionLabel.text = [self.detailItem description]; 40 | } 41 | } 42 | 43 | - (void)viewDidLoad 44 | { 45 | [super viewDidLoad]; 46 | // Do any additional setup after loading the view, typically from a nib. 47 | [self configureView]; 48 | } 49 | 50 | - (void)didReceiveMemoryWarning 51 | { 52 | [super didReceiveMemoryWarning]; 53 | // Dispose of any resources that can be recreated. 54 | } 55 | 56 | #pragma mark - Split view 57 | 58 | - (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController 59 | { 60 | barButtonItem.title = NSLocalizedString(@"Master", @"Master"); 61 | [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES]; 62 | self.masterPopoverController = popoverController; 63 | } 64 | 65 | - (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem 66 | { 67 | // Called when the view is shown again in the split view, invalidating the button and popover controller. 68 | [self.navigationItem setLeftBarButtonItem:nil animated:YES]; 69 | self.masterPopoverController = nil; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "ipad", 20 | "size" : "29x29", 21 | "scale" : "1x" 22 | }, 23 | { 24 | "idiom" : "ipad", 25 | "size" : "29x29", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "ipad", 30 | "size" : "40x40", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "40x40", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "76x76", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "76x76", 46 | "scale" : "2x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "orientation" : "portrait", 20 | "idiom" : "ipad", 21 | "extent" : "full-screen", 22 | "minimum-system-version" : "7.0", 23 | "scale" : "1x" 24 | }, 25 | { 26 | "orientation" : "landscape", 27 | "idiom" : "ipad", 28 | "extent" : "full-screen", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "1x" 31 | }, 32 | { 33 | "orientation" : "portrait", 34 | "idiom" : "ipad", 35 | "extent" : "full-screen", 36 | "minimum-system-version" : "7.0", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "orientation" : "landscape", 41 | "idiom" : "ipad", 42 | "extent" : "full-screen", 43 | "minimum-system-version" : "7.0", 44 | "scale" : "2x" 45 | } 46 | ], 47 | "info" : { 48 | "version" : 1, 49 | "author" : "xcode" 50 | } 51 | } -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/MasterViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MasterViewController.h 3 | // iOS7Example 4 | // 5 | // Created by Erik Doernenburg on 10/06/2014. 6 | // Copyright (c) 2014 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class DetailViewController; 12 | 13 | @interface MasterViewController : UITableViewController 14 | 15 | @property (strong, nonatomic) DetailViewController *detailViewController; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/iOS7Example-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.mulle-kybernetik.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main_iPhone 29 | UIMainStoryboardFile~ipad 30 | Main_iPad 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UIStatusBarTintParameters 36 | 37 | UINavigationBar 38 | 39 | Style 40 | UIBarStyleDefault 41 | Translucent 42 | 43 | 44 | 45 | UISupportedInterfaceOrientations 46 | 47 | UIInterfaceOrientationPortrait 48 | UIInterfaceOrientationLandscapeLeft 49 | UIInterfaceOrientationLandscapeRight 50 | 51 | UISupportedInterfaceOrientations~ipad 52 | 53 | UIInterfaceOrientationPortrait 54 | UIInterfaceOrientationPortraitUpsideDown 55 | UIInterfaceOrientationLandscapeLeft 56 | UIInterfaceOrientationLandscapeRight 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/iOS7Example-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7Example/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // iOS7Example 4 | // 5 | // Created by Erik Doernenburg on 10/06/2014. 6 | // Copyright (c) 2014 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7ExampleTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7ExampleTests/iOS7ExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.mulle-kybernetik.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/iOS7Example/iOS7ExampleTests/iOS7ExampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // iOS7ExampleTests.m 3 | // iOS7ExampleTests 4 | // 5 | // Created by Erik Doernenburg on 10/06/2014. 6 | // Copyright (c) 2014 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | #import "MasterViewController.h" 13 | 14 | @interface iOS7ExampleTests : XCTestCase 15 | 16 | @end 17 | 18 | @implementation iOS7ExampleTests 19 | 20 | - (void)setUp 21 | { 22 | [super setUp]; 23 | // Put setup code here. This method is called before the invocation of each test method in the class. 24 | } 25 | 26 | - (void)tearDown 27 | { 28 | // Put teardown code here. This method is called after the invocation of each test method in the class. 29 | [super tearDown]; 30 | } 31 | 32 | - (void)testMasterViewControllerDeletesItemsFromTableView 33 | { 34 | // Test set-up 35 | 36 | MasterViewController *controller = [[MasterViewController alloc] init]; 37 | NSIndexPath *dummyIndexPath = [NSIndexPath indexPathForRow:1 inSection:0]; 38 | 39 | id tableViewMock = OCMClassMock([UITableView class]); 40 | 41 | // Invoke functionality to be tested 42 | // If you want to see the test fail you can, for example, change the editing style to 43 | // UITableViewCellEditingStyleNone. In that case the method in the controller does not 44 | // make a call to the table view and the mock will raise an exception when verify is 45 | // called further down. 46 | 47 | [controller tableView:tableViewMock commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:dummyIndexPath]; 48 | 49 | // Verify that expected methods were called 50 | 51 | OCMVerify([tableViewMock deleteRowsAtIndexPaths:[NSArray arrayWithObject:dummyIndexPath] withRowAnimation:UITableViewRowAnimationFade]); 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/include/OCMock/NSNotificationCenter+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCObserverMockObject; 20 | 21 | 22 | @interface NSNotificationCenter(OCMAdditions) 23 | 24 | - (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/include/OCMock/OCMArg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMArg : NSObject 20 | 21 | // constraining arguments 22 | 23 | + (id)any; 24 | + (SEL)anySelector; 25 | + (void *)anyPointer; 26 | + (id __autoreleasing *)anyObjectRef; 27 | + (id)isNil; 28 | + (id)isNotNil; 29 | + (id)isNotEqual:(id)value; 30 | + (id)checkWithSelector:(SEL)selector onObject:(id)anObject; 31 | + (id)checkWithBlock:(BOOL (^)(id obj))block; 32 | 33 | // manipulating arguments 34 | 35 | + (id *)setTo:(id)value; 36 | + (void *)setToValue:(NSValue *)value; 37 | 38 | // internal use only 39 | 40 | + (id)resolveSpecialValues:(NSValue *)value; 41 | 42 | @end 43 | 44 | #define OCMOCK_ANY [OCMArg any] 45 | 46 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 47 | #define OCMOCK_VALUE(variable) \ 48 | ({ __typeof__(variable) __v = (variable); [NSValue value:&__v withObjCType:@encode(__typeof__(__v))]; }) 49 | #else 50 | #define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))] 51 | #endif 52 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/include/OCMock/OCMConstraint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | 20 | @interface OCMConstraint : NSObject 21 | 22 | + (id)constraint; 23 | - (BOOL)evaluate:(id)value; 24 | 25 | // if you are looking for any, isNil, etc, they have moved to OCMArg 26 | 27 | // try to use [OCMArg checkWith...] instead of the constraintWith... methods below 28 | 29 | + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; 30 | + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; 31 | 32 | 33 | @end 34 | 35 | @interface OCMAnyConstraint : OCMConstraint 36 | @end 37 | 38 | @interface OCMIsNilConstraint : OCMConstraint 39 | @end 40 | 41 | @interface OCMIsNotNilConstraint : OCMConstraint 42 | @end 43 | 44 | @interface OCMIsNotEqualConstraint : OCMConstraint 45 | { 46 | @public 47 | id testValue; 48 | } 49 | 50 | @end 51 | 52 | @interface OCMInvocationConstraint : OCMConstraint 53 | { 54 | @public 55 | NSInvocation *invocation; 56 | } 57 | 58 | @end 59 | 60 | @interface OCMBlockConstraint : OCMConstraint 61 | { 62 | BOOL (^block)(id); 63 | } 64 | 65 | - (id)initWithConstraintBlock:(BOOL (^)(id))block; 66 | 67 | @end 68 | 69 | 70 | #define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self] 71 | #define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)] 72 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/include/OCMock/OCMLocation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMLocation : NSObject 20 | { 21 | id testCase; 22 | NSString *file; 23 | NSUInteger line; 24 | } 25 | 26 | + (id)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; 27 | 28 | - (id)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; 29 | 30 | - (id)testCase; 31 | - (NSString *)file; 32 | - (NSUInteger)line; 33 | 34 | @end 35 | 36 | extern OCMLocation *OCMMakeLocation(id testCase, const char *file, int line); 37 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/include/OCMock/OCMMacroState.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMRecorder; 21 | @class OCMStubRecorder; 22 | @class OCMockObject; 23 | 24 | 25 | @interface OCMMacroState : NSObject 26 | { 27 | OCMRecorder *recorder; 28 | } 29 | 30 | + (void)beginStubMacro; 31 | + (OCMStubRecorder *)endStubMacro; 32 | 33 | + (void)beginExpectMacro; 34 | + (OCMStubRecorder *)endExpectMacro; 35 | 36 | + (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation; 37 | + (void)endVerifyMacro; 38 | 39 | + (OCMMacroState *)globalState; 40 | 41 | - (OCMRecorder *)recorder; 42 | 43 | - (void)switchToClassMethod; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/include/OCMock/OCMRecorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMockObject; 20 | @class OCMInvocationMatcher; 21 | 22 | 23 | @interface OCMRecorder : NSProxy 24 | { 25 | OCMockObject *mockObject; 26 | OCMInvocationMatcher *invocationMatcher; 27 | } 28 | 29 | - (id)init; 30 | - (id)initWithMockObject:(OCMockObject *)aMockObject; 31 | 32 | - (void)setMockObject:(OCMockObject *)aMockObject; 33 | 34 | - (OCMInvocationMatcher *)invocationMatcher; 35 | 36 | - (id)classMethod; 37 | - (id)ignoringNonObjectArgs; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/include/OCMock/OCMStubRecorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMRecorder.h" 18 | 19 | 20 | @interface OCMStubRecorder : OCMRecorder 21 | 22 | - (id)andReturn:(id)anObject; 23 | - (id)andReturnValue:(NSValue *)aValue; 24 | - (id)andThrow:(NSException *)anException; 25 | - (id)andPost:(NSNotification *)aNotification; 26 | - (id)andCall:(SEL)selector onObject:(id)anObject; 27 | - (id)andDo:(void (^)(NSInvocation *invocation))block; 28 | - (id)andForwardToRealObject; 29 | 30 | @end 31 | 32 | 33 | @interface OCMStubRecorder (Properties) 34 | 35 | #define andReturn(aValue) _andReturn(({ typeof(aValue) _v = (aValue); [NSValue value:&_v withObjCType:@encode(typeof(_v))]; })) 36 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *); 37 | 38 | #define andThrow(anException) _andThrow(anException) 39 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andThrow)(NSException *); 40 | 41 | #define andPost(aNotification) _andPost(aNotification) 42 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andPost)(NSNotification *); 43 | 44 | #define andCall(anObject, aSelector) _andCall(anObject, aSelector) 45 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andCall)(id, SEL); 46 | 47 | #define andDo(aBlock) _andDo(aBlock) 48 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andDo)(void (^)(NSInvocation *)); 49 | 50 | #define andForwardToRealObject() _andForwardToRealObject() 51 | @property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(void); 52 | 53 | @end 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/include/OCMock/OCMockObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2014 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMInvocationStub; 21 | @class OCMStubRecorder; 22 | @class OCMInvocationMatcher; 23 | @class OCMInvocationExpectation; 24 | 25 | 26 | @interface OCMockObject : NSProxy 27 | { 28 | BOOL isNice; 29 | BOOL expectationOrderMatters; 30 | NSMutableArray *stubs; 31 | NSMutableArray *expectations; 32 | NSMutableArray *exceptions; 33 | NSMutableArray *invocations; 34 | } 35 | 36 | + (id)mockForClass:(Class)aClass; 37 | + (id)mockForProtocol:(Protocol *)aProtocol; 38 | + (id)partialMockForObject:(NSObject *)anObject; 39 | 40 | + (id)niceMockForClass:(Class)aClass; 41 | + (id)niceMockForProtocol:(Protocol *)aProtocol; 42 | 43 | + (id)observerMock; 44 | 45 | - (id)init; 46 | 47 | - (void)setExpectationOrderMatters:(BOOL)flag; 48 | 49 | - (id)stub; 50 | - (id)expect; 51 | - (id)reject; 52 | 53 | - (id)verify; 54 | - (id)verifyAtLocation:(OCMLocation *)location; 55 | 56 | - (void)verifyWithDelay:(NSTimeInterval)delay; 57 | - (void)verifyWithDelay:(NSTimeInterval)delay atLocation:(OCMLocation *)location; 58 | 59 | - (void)stopMocking; 60 | 61 | // internal use only 62 | 63 | - (void)addStub:(OCMInvocationStub *)aStub; 64 | - (void)addExpectation:(OCMInvocationExpectation *)anExpectation; 65 | 66 | - (BOOL)handleInvocation:(NSInvocation *)anInvocation; 67 | - (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation; 68 | - (BOOL)handleSelector:(SEL)sel; 69 | 70 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher; 71 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher atLocation:(OCMLocation *)location; 72 | 73 | @end 74 | 75 | -------------------------------------------------------------------------------- /Examples/iOS7Example/usr/lib/libOCMock.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikdoe/ocmock/7f6e9e9b6c9ffa19a9040860da9f7a1f202b9f4d/Examples/iOS7Example/usr/lib/libOCMock.a -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // iOS9Example 4 | // 5 | // Created by Erik Doernenburg on 29/09/2015. 6 | // Copyright © 2015 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9Example/DetailViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.h 3 | // iOS9Example 4 | // 5 | // Created by Erik Doernenburg on 29/09/2015. 6 | // Copyright © 2015 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DetailViewController : UIViewController 12 | 13 | @property (strong, nonatomic) id detailItem; 14 | @property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel; 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9Example/DetailViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.m 3 | // iOS9Example 4 | // 5 | // Created by Erik Doernenburg on 29/09/2015. 6 | // Copyright © 2015 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import "DetailViewController.h" 10 | 11 | @interface DetailViewController () 12 | 13 | @end 14 | 15 | @implementation DetailViewController 16 | 17 | #pragma mark - Managing the detail item 18 | 19 | - (void)setDetailItem:(id)newDetailItem { 20 | if (_detailItem != newDetailItem) { 21 | _detailItem = newDetailItem; 22 | 23 | // Update the view. 24 | [self configureView]; 25 | } 26 | } 27 | 28 | - (void)configureView { 29 | // Update the user interface for the detail item. 30 | if (self.detailItem) { 31 | self.detailDescriptionLabel.text = [self.detailItem description]; 32 | } 33 | } 34 | 35 | - (void)viewDidLoad { 36 | [super viewDidLoad]; 37 | // Do any additional setup after loading the view, typically from a nib. 38 | [self configureView]; 39 | } 40 | 41 | - (void)didReceiveMemoryWarning { 42 | [super didReceiveMemoryWarning]; 43 | // Dispose of any resources that can be recreated. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarTintParameters 34 | 35 | UINavigationBar 36 | 37 | Style 38 | UIBarStyleDefault 39 | Translucent 40 | 41 | 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9Example/MasterViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MasterViewController.h 3 | // iOS9Example 4 | // 5 | // Created by Erik Doernenburg on 29/09/2015. 6 | // Copyright © 2015 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class DetailViewController; 12 | 13 | @interface MasterViewController : UITableViewController 14 | 15 | @property (strong, nonatomic) DetailViewController *detailViewController; 16 | 17 | 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9Example/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // iOS9Example 4 | // 5 | // Created by Erik Doernenburg on 29/09/2015. 6 | // Copyright © 2015 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9ExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Examples/iOS9Example/iOS9ExampleTests/iOS9ExampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // iOS9ExampleTests.m 3 | // iOS9ExampleTests 4 | // 5 | // Created by Erik Doernenburg on 29/09/2015. 6 | // Copyright © 2015 Erik Doernenburg. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "MasterViewController.h" 12 | 13 | @interface iOS9ExampleTests : XCTestCase 14 | 15 | @end 16 | 17 | @implementation iOS9ExampleTests 18 | 19 | - (void)testMasterViewControllerDeletesItemsFromTableView 20 | { 21 | // Test set-up 22 | 23 | MasterViewController *controller = [[MasterViewController alloc] init]; 24 | NSIndexPath *dummyIndexPath = [NSIndexPath indexPathForRow:1 inSection:0]; 25 | 26 | id tableViewMock = OCMClassMock([UITableView class]); 27 | 28 | // Invoke functionality to be tested 29 | // If you want to see the test fail you can, for example, change the editing style to 30 | // UITableViewCellEditingStyleNone. In that case the method in the controller does not 31 | // make a call to the table view and the mock will raise an exception when verify is 32 | // called further down. 33 | 34 | [controller tableView:tableViewMock commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:dummyIndexPath]; 35 | 36 | // Verify that expected methods were called 37 | 38 | OCMVerify([tableViewMock deleteRowsAtIndexPaths:@[dummyIndexPath] withRowAnimation:UITableViewRowAnimationFade]); 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/include/OCMock/NSNotificationCenter+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2016 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCObserverMockObject; 20 | 21 | 22 | @interface NSNotificationCenter(OCMAdditions) 23 | 24 | - (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/include/OCMock/OCMArg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2016 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMArg : NSObject 20 | 21 | // constraining arguments 22 | 23 | + (id)any; 24 | + (SEL)anySelector; 25 | + (void *)anyPointer; 26 | + (id __autoreleasing *)anyObjectRef; 27 | + (id)isNil; 28 | + (id)isNotNil; 29 | + (id)isEqual:(id)value; 30 | + (id)isNotEqual:(id)value; 31 | + (id)isKindOfClass:(Class)cls; 32 | + (id)checkWithSelector:(SEL)selector onObject:(id)anObject; 33 | + (id)checkWithBlock:(BOOL (^)(id obj))block; 34 | 35 | // manipulating arguments 36 | 37 | + (id *)setTo:(id)value; 38 | + (void *)setToValue:(NSValue *)value; 39 | + (id)invokeBlock; 40 | + (id)invokeBlockWithArgs:(id)first,... NS_REQUIRES_NIL_TERMINATION; 41 | 42 | + (id)defaultValue; 43 | 44 | // internal use only 45 | 46 | + (id)resolveSpecialValues:(NSValue *)value; 47 | 48 | @end 49 | 50 | #define OCMOCK_ANY [OCMArg any] 51 | 52 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 53 | #define OCMOCK_VALUE(variable) \ 54 | ({ __typeof__(variable) __v = (variable); [NSValue value:&__v withObjCType:@encode(__typeof__(__v))]; }) 55 | #else 56 | #define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))] 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/include/OCMock/OCMConstraint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2016 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | 20 | @interface OCMConstraint : NSObject 21 | 22 | + (instancetype)constraint; 23 | - (BOOL)evaluate:(id)value; 24 | 25 | // if you are looking for any, isNil, etc, they have moved to OCMArg 26 | 27 | // try to use [OCMArg checkWith...] instead of the constraintWith... methods below 28 | 29 | + (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; 30 | + (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; 31 | 32 | 33 | @end 34 | 35 | @interface OCMAnyConstraint : OCMConstraint 36 | @end 37 | 38 | @interface OCMIsNilConstraint : OCMConstraint 39 | @end 40 | 41 | @interface OCMIsNotNilConstraint : OCMConstraint 42 | @end 43 | 44 | @interface OCMIsNotEqualConstraint : OCMConstraint 45 | { 46 | @public 47 | id testValue; 48 | } 49 | 50 | @end 51 | 52 | @interface OCMInvocationConstraint : OCMConstraint 53 | { 54 | @public 55 | NSInvocation *invocation; 56 | } 57 | 58 | @end 59 | 60 | @interface OCMBlockConstraint : OCMConstraint 61 | { 62 | BOOL (^block)(id); 63 | } 64 | 65 | - (instancetype)initWithConstraintBlock:(BOOL (^)(id))block; 66 | 67 | @end 68 | 69 | 70 | #define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self] 71 | #define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)] 72 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/include/OCMock/OCMFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | 20 | #if defined(__cplusplus) 21 | #define OCMOCK_EXTERN extern "C" 22 | #else 23 | #define OCMOCK_EXTERN extern 24 | #endif 25 | 26 | 27 | OCMOCK_EXTERN BOOL OCMIsObjectType(const char *objCType); 28 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/include/OCMock/OCMLocation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import "OCMFunctions.h" 19 | 20 | 21 | @interface OCMLocation : NSObject 22 | { 23 | id testCase; 24 | NSString *file; 25 | NSUInteger line; 26 | } 27 | 28 | + (instancetype)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; 29 | 30 | - (instancetype)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; 31 | 32 | - (id)testCase; 33 | - (NSString *)file; 34 | - (NSUInteger)line; 35 | 36 | @end 37 | 38 | OCMOCK_EXTERN OCMLocation *OCMMakeLocation(id testCase, const char *file, int line); 39 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/include/OCMock/OCMMacroState.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMRecorder; 21 | @class OCMStubRecorder; 22 | @class OCMockObject; 23 | 24 | 25 | @interface OCMMacroState : NSObject 26 | { 27 | OCMRecorder *recorder; 28 | } 29 | 30 | + (void)beginStubMacro; 31 | + (OCMStubRecorder *)endStubMacro; 32 | 33 | + (void)beginExpectMacro; 34 | + (OCMStubRecorder *)endExpectMacro; 35 | 36 | + (void)beginRejectMacro; 37 | + (OCMStubRecorder *)endRejectMacro; 38 | 39 | + (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation; 40 | + (void)endVerifyMacro; 41 | 42 | + (OCMMacroState *)globalState; 43 | 44 | - (OCMRecorder *)recorder; 45 | 46 | - (void)switchToClassMethod; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/include/OCMock/OCMRecorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMockObject; 20 | @class OCMInvocationMatcher; 21 | 22 | 23 | @interface OCMRecorder : NSProxy 24 | { 25 | OCMockObject *mockObject; 26 | OCMInvocationMatcher *invocationMatcher; 27 | } 28 | 29 | - (instancetype)init; 30 | - (instancetype)initWithMockObject:(OCMockObject *)aMockObject; 31 | 32 | - (void)setMockObject:(OCMockObject *)aMockObject; 33 | 34 | - (OCMInvocationMatcher *)invocationMatcher; 35 | 36 | - (id)classMethod; 37 | - (id)ignoringNonObjectArgs; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/include/OCMock/OCMockObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2016 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMInvocationStub; 21 | @class OCMStubRecorder; 22 | @class OCMInvocationMatcher; 23 | @class OCMInvocationExpectation; 24 | 25 | 26 | @interface OCMockObject : NSProxy 27 | { 28 | BOOL isNice; 29 | BOOL expectationOrderMatters; 30 | NSMutableArray *stubs; 31 | NSMutableArray *expectations; 32 | NSMutableArray *exceptions; 33 | NSMutableArray *invocations; 34 | } 35 | 36 | + (id)mockForClass:(Class)aClass; 37 | + (id)mockForProtocol:(Protocol *)aProtocol; 38 | + (id)partialMockForObject:(NSObject *)anObject; 39 | 40 | + (id)niceMockForClass:(Class)aClass; 41 | + (id)niceMockForProtocol:(Protocol *)aProtocol; 42 | 43 | + (id)observerMock; 44 | 45 | - (instancetype)init; 46 | 47 | - (void)setExpectationOrderMatters:(BOOL)flag; 48 | 49 | - (id)stub; 50 | - (id)expect; 51 | - (id)reject; 52 | 53 | - (id)verify; 54 | - (id)verifyAtLocation:(OCMLocation *)location; 55 | 56 | - (void)verifyWithDelay:(NSTimeInterval)delay; 57 | - (void)verifyWithDelay:(NSTimeInterval)delay atLocation:(OCMLocation *)location; 58 | 59 | - (void)stopMocking; 60 | 61 | // internal use only 62 | 63 | - (void)addStub:(OCMInvocationStub *)aStub; 64 | - (void)addExpectation:(OCMInvocationExpectation *)anExpectation; 65 | 66 | - (BOOL)handleInvocation:(NSInvocation *)anInvocation; 67 | - (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation; 68 | - (BOOL)handleSelector:(SEL)sel; 69 | 70 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher; 71 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher atLocation:(OCMLocation *)location; 72 | 73 | @end 74 | 75 | -------------------------------------------------------------------------------- /Examples/iOS9Example/usr/lib/libOCMock.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikdoe/ocmock/7f6e9e9b6c9ffa19a9040860da9f7a1f202b9f4d/Examples/iOS9Example/usr/lib/libOCMock.a -------------------------------------------------------------------------------- /Examples/iPhoneExample/Classes/RootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.h 3 | // iPhoneExample 4 | // 5 | // Created by Erik Doernenburg on 20/07/10. 6 | // Copyright Mulle Kybernetik 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RootViewController : UITableViewController { 12 | } 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Classes/RootViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.m 3 | // iPhoneExample 4 | // 5 | // Created by Erik Doernenburg on 20/07/10. 6 | // Copyright Mulle Kybernetik 2010. All rights reserved. 7 | // 8 | 9 | #import "RootViewController.h" 10 | 11 | 12 | @implementation RootViewController 13 | 14 | 15 | #pragma mark - 16 | #pragma mark Table view data source 17 | 18 | // Customize the number of sections in the table view. 19 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 20 | return 1; 21 | } 22 | 23 | 24 | // Customize the number of rows in the table view. 25 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 26 | return 1; 27 | } 28 | 29 | 30 | // Customize the appearance of table view cells. 31 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 32 | 33 | static NSString *CellIdentifier = @"HelloWorldCell"; 34 | 35 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 36 | if (cell == nil) { 37 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 38 | } 39 | 40 | cell.textLabel.text = @"Hello World!"; 41 | 42 | return cell; 43 | } 44 | 45 | 46 | #pragma mark - 47 | #pragma mark Table view delegate 48 | 49 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 50 | 51 | /* 52 | <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 53 | // ... 54 | // Pass the selected object to the new view controller. 55 | [self.navigationController pushViewController:detailViewController animated:YES]; 56 | [detailViewController release]; 57 | */ 58 | } 59 | 60 | 61 | @end 62 | 63 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Classes/iPhoneExampleAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // iPhoneExampleAppDelegate.h 3 | // iPhoneExample 4 | // 5 | // Created by Erik Doernenburg on 20/07/10. 6 | // Copyright Mulle Kybernetik 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface iPhoneExampleAppDelegate : NSObject { 12 | 13 | UIWindow *window; 14 | UINavigationController *navigationController; 15 | } 16 | 17 | @property (nonatomic, strong) IBOutlet UIWindow *window; 18 | @property (nonatomic, strong) IBOutlet UINavigationController *navigationController; 19 | 20 | @end 21 | 22 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Libraries/Headers/OCMock/NSNotificationCenter+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id: NSNotificationCenter+OCMAdditions.h 57 2010-07-19 06:14:27Z erik $ 3 | // Copyright (c) 2009 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | @class OCMockObserver; 9 | 10 | 11 | @interface NSNotificationCenter(OCMAdditions) 12 | 13 | - (void)addMockObserver:(OCMockObserver *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Libraries/Headers/OCMock/OCMArg.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id: OCMArg.h 57 2010-07-19 06:14:27Z erik $ 3 | // Copyright (c) 2009-2010 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | @interface OCMArg : NSObject 9 | 10 | // constraining arguments 11 | 12 | + (id)any; 13 | + (void *)anyPointer; 14 | + (id)isNil; 15 | + (id)isNotNil; 16 | + (id)isNotEqual:(id)value; 17 | + (id)checkWithSelector:(SEL)selector onObject:(id)anObject; 18 | #if NS_BLOCKS_AVAILABLE 19 | + (id)checkWithBlock:(BOOL (^)(id))block; 20 | #endif 21 | 22 | // manipulating arguments 23 | 24 | + (id *)setTo:(id)value; 25 | 26 | // internal use only 27 | 28 | + (id)resolveSpecialValues:(NSValue *)value; 29 | 30 | @end 31 | 32 | #define OCMOCK_ANY [OCMArg any] 33 | #define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(typeof(variable))] 34 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Libraries/Headers/OCMock/OCMConstraint.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id: OCMConstraint.h 57 2010-07-19 06:14:27Z erik $ 3 | // Copyright (c) 2007-2010 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | 9 | @interface OCMConstraint : NSObject 10 | 11 | + (id)constraint; 12 | - (BOOL)evaluate:(id)value; 13 | 14 | // if you are looking for any, isNil, etc, they have moved to OCMArg 15 | 16 | // try to use [OCMArg checkWith...] instead of the constraintWith... methods below 17 | 18 | + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; 19 | + (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; 20 | 21 | 22 | @end 23 | 24 | @interface OCMAnyConstraint : OCMConstraint 25 | @end 26 | 27 | @interface OCMIsNilConstraint : OCMConstraint 28 | @end 29 | 30 | @interface OCMIsNotNilConstraint : OCMConstraint 31 | @end 32 | 33 | @interface OCMIsNotEqualConstraint : OCMConstraint 34 | { 35 | @public 36 | id testValue; 37 | } 38 | 39 | @end 40 | 41 | @interface OCMInvocationConstraint : OCMConstraint 42 | { 43 | @public 44 | NSInvocation *invocation; 45 | } 46 | 47 | @end 48 | 49 | #if NS_BLOCKS_AVAILABLE 50 | 51 | @interface OCMBlockConstraint : OCMConstraint 52 | { 53 | BOOL (^block)(id); 54 | } 55 | 56 | - (id)initWithConstraintBlock:(BOOL (^)(id))block; 57 | 58 | @end 59 | 60 | #endif 61 | 62 | 63 | #define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self] 64 | #define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)] 65 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Libraries/Headers/OCMock/OCMock.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id: OCMock.h 39 2009-04-09 05:31:28Z erik $ 3 | // Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | #import 8 | #import 9 | #import 10 | #import 11 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Libraries/Headers/OCMock/OCMockObject.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id: OCMockObject.h 52 2009-08-14 07:21:10Z erik $ 3 | // Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | @interface OCMockObject : NSProxy 9 | { 10 | BOOL isNice; 11 | BOOL expectationOrderMatters; 12 | NSMutableArray *recorders; 13 | NSMutableArray *expectations; 14 | NSMutableArray *exceptions; 15 | } 16 | 17 | + (id)mockForClass:(Class)aClass; 18 | + (id)mockForProtocol:(Protocol *)aProtocol; 19 | + (id)partialMockForObject:(NSObject *)anObject; 20 | 21 | + (id)niceMockForClass:(Class)aClass; 22 | + (id)niceMockForProtocol:(Protocol *)aProtocol; 23 | 24 | + (id)observerMock; 25 | 26 | - (id)init; 27 | 28 | - (void)setExpectationOrderMatters:(BOOL)flag; 29 | 30 | - (id)stub; 31 | - (id)expect; 32 | 33 | - (void)verify; 34 | 35 | // internal use only 36 | 37 | - (id)getNewRecorder; 38 | - (BOOL)handleInvocation:(NSInvocation *)anInvocation; 39 | - (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Libraries/Headers/OCMock/OCMockRecorder.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------- 2 | // $Id: OCMockRecorder.h 57 2010-07-19 06:14:27Z erik $ 3 | // Copyright (c) 2004-2010 by Mulle Kybernetik. See License file for details. 4 | //--------------------------------------------------------------------------------------- 5 | 6 | #import 7 | 8 | @interface OCMockRecorder : NSProxy 9 | { 10 | id signatureResolver; 11 | NSInvocation *recordedInvocation; 12 | NSMutableArray *invocationHandlers; 13 | } 14 | 15 | - (id)initWithSignatureResolver:(id)anObject; 16 | 17 | - (BOOL)matchesInvocation:(NSInvocation *)anInvocation; 18 | - (void)releaseInvocation; 19 | 20 | - (id)andReturn:(id)anObject; 21 | - (id)andReturnValue:(NSValue *)aValue; 22 | - (id)andThrow:(NSException *)anException; 23 | - (id)andPost:(NSNotification *)aNotification; 24 | - (id)andCall:(SEL)selector onObject:(id)anObject; 25 | #if NS_BLOCKS_AVAILABLE 26 | - (id)andDo:(void (^)(NSInvocation *))block; 27 | #endif 28 | 29 | - (NSArray *)invocationHandlers; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/Libraries/libOCMock.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikdoe/ocmock/7f6e9e9b6c9ffa19a9040860da9f7a1f202b9f4d/Examples/iPhoneExample/Libraries/libOCMock.a -------------------------------------------------------------------------------- /Examples/iPhoneExample/OCMockLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikdoe/ocmock/7f6e9e9b6c9ffa19a9040860da9f7a1f202b9f4d/Examples/iPhoneExample/OCMockLogo.png -------------------------------------------------------------------------------- /Examples/iPhoneExample/Tests/RootViewControllerTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewControllerTests.h 3 | // iPhoneExample 4 | // 5 | // Created by Erik Doernenburg on 20/07/10. 6 | // Copyright 2010 Mulle Kybernetik. All rights reserved. 7 | // 8 | // See Also: http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html 9 | 10 | 11 | #import 12 | #import 13 | 14 | 15 | @interface RootViewControllerTests : SenTestCase 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/iPhoneExample-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | OCMockLogo.png 13 | CFBundleIdentifier 14 | com.mulle-kybernetik.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/iPhoneExampleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | 20 | 21 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/iPhoneExample_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'iPhoneExample' target in the 'iPhoneExample' project 3 | // 4 | #import 5 | 6 | #ifndef __IPHONE_3_0 7 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 8 | #endif 9 | 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/iPhoneExample/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // iPhoneExample 4 | // 5 | // Created by Erik Doernenburg on 20/07/10. 6 | // Copyright Mulle Kybernetik 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /OCMock.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "OCMock" 3 | s.version = "3.9.4" 4 | 5 | s.summary = "Mock objects for Objective-C" 6 | s.description = <<-DESC 7 | OCMock is an Objective-C implementation of mock objects. It provides 8 | stubs that return pre-determined values for specific method invocations, 9 | dynamic mocks that can be used to verify interaction patterns, and 10 | partial mocks to overwrite selected methods of existing objects. 11 | DESC 12 | 13 | s.homepage = "http://ocmock.org" 14 | s.documentation_url = "http://ocmock.org/reference/" 15 | s.license = { :type => "Apache 2.0", :file => "License.txt" } 16 | 17 | s.author = { "Erik Doernenburg" => "erik@doernenburg.com" } 18 | s.social_media_url = "https://toot.thoughtworks.com/@edoernen" 19 | 20 | s.source = { :git => "https://github.com/erikdoe/ocmock.git", :tag => "v3.9.4" } 21 | s.source_files = "Source/OCMock/*.{h,m}" 22 | 23 | s.requires_arc = false 24 | s.osx.deployment_target = '10.15' 25 | s.ios.deployment_target = '12.0' 26 | s.tvos.deployment_target = '12.0' 27 | s.watchos.deployment_target = '7.0' 28 | s.osx.framework = 'XCTest' 29 | s.ios.framework = 'XCTest' 30 | s.tvos.framework = 'XCTest' 31 | s.watchos.framework = 'XCTest' 32 | 33 | s.pod_target_xcconfig = { 'ENABLE_BITCODE' => 'NO' } 34 | 35 | s.public_header_files = ["OCMock.h", "OCMockObject.h", "OCMArg.h", "OCMConstraint.h", 36 | "OCMLocation.h", "OCMMacroState.h", "OCMRecorder.h", 37 | "OCMStubRecorder.h", "NSNotificationCenter+OCMAdditions.h", 38 | "OCMFunctions.h", "OCMVerifier.h", "OCMQuantifier.h", 39 | "OCMockMacros.h" 40 | ] 41 | .map { |file| "Source/OCMock/" + file } 42 | end 43 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "OCMock", 7 | defaultLocalization: "en", 8 | products: [ 9 | .library( 10 | name: "OCMock", 11 | targets: ["OCMock"] 12 | ) 13 | ], 14 | targets: [ 15 | .target(name: "OCMock", 16 | dependencies: [], 17 | path: "Source", 18 | exclude: [ 19 | "Changes.txt", 20 | "OCMock/OCMock-Info.plist", 21 | "OCMock/OCMock-Prefix.pch", 22 | "OCMockTests/", 23 | "Cartfile", 24 | "OCMockLibTests/OCMockLibTests-Info.plist", 25 | "OCMockLib/OCMockLib-Prefix.pch", 26 | "OCMockLibTests/OCMockLibTests-Prefix.pch", 27 | "OCMockDist.xcconfig", 28 | "OCMockCI.xcconfig", 29 | ], 30 | publicHeadersPath: ".", 31 | cSettings: [ 32 | .headerSearchPath("./"), 33 | .unsafeFlags(["-fno-objc-arc"]) 34 | ], 35 | cxxSettings: nil, 36 | swiftSettings: nil, 37 | linkerSettings: nil 38 | ), 39 | .testTarget( 40 | name: "swift-test", 41 | dependencies: [ 42 | "OCMock", 43 | ], 44 | path: "SwiftPMTests/swift", 45 | cSettings: [ 46 | .headerSearchPath("../"), 47 | ] 48 | ), 49 | .testTarget( 50 | name: "objc-test", 51 | dependencies: [ 52 | "OCMock", 53 | ], 54 | path: "SwiftPMTests/objc", 55 | cSettings: [ 56 | .headerSearchPath("../"), 57 | ] 58 | ) 59 | ] 60 | ) 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OCMock 2 | ====== 3 | 4 | ![Build Status](https://github.com/erikdoe/ocmock/actions/workflows/build-and-test.yaml/badge.svg?branch=master) 5 | 6 | OCMock is an Objective-C implementation of mock objects. 7 | 8 | For downloads, documentation, and support please visit [ocmock.org](http://ocmock.org/). 9 | -------------------------------------------------------------------------------- /Source/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: WebKit 2 | #AlignConsecutiveDeclarations: true (only in instance var declarations) 3 | AllowShortBlocksOnASingleLine: Never 4 | AllowShortCaseLabelsOnASingleLine: true 5 | AllowShortFunctionsOnASingleLine: Empty 6 | BraceWrapping: 7 | AfterCaseLabel: false 8 | AfterControlStatement: Always 9 | AfterEnum: false 10 | AfterFunction: true 11 | AfterObjCDeclaration: true 12 | AfterStruct: false 13 | AfterUnion: false 14 | BeforeWhile: true 15 | IndentBraces: false 16 | SplitEmptyFunction: true 17 | SplitEmptyRecord: true 18 | BreakBeforeBinaryOperators: None 19 | BreakBeforeBraces: Allman 20 | IncludeCategories: 21 | - Regex: '^<[a-z]*' 22 | Priority: -4 23 | - Regex: '^ 18 | 19 | @interface NSInvocation(OCMAdditions) 20 | 21 | + (NSInvocation *)invocationForBlock:(id)block withArguments:(NSArray *)arguments; 22 | 23 | - (void)retainObjectArgumentsExcludingObject:(id)objectToExclude; 24 | 25 | - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex; 26 | 27 | - (NSString *)invocationDescription; 28 | 29 | - (NSString *)argumentDescriptionAtIndex:(NSInteger)argIndex; 30 | 31 | - (NSString *)objectDescriptionAtIndex:(NSInteger)anInt; 32 | - (NSString *)charDescriptionAtIndex:(NSInteger)anInt; 33 | - (NSString *)unsignedCharDescriptionAtIndex:(NSInteger)anInt; 34 | - (NSString *)intDescriptionAtIndex:(NSInteger)anInt; 35 | - (NSString *)unsignedIntDescriptionAtIndex:(NSInteger)anInt; 36 | - (NSString *)shortDescriptionAtIndex:(NSInteger)anInt; 37 | - (NSString *)unsignedShortDescriptionAtIndex:(NSInteger)anInt; 38 | - (NSString *)longDescriptionAtIndex:(NSInteger)anInt; 39 | - (NSString *)unsignedLongDescriptionAtIndex:(NSInteger)anInt; 40 | - (NSString *)longLongDescriptionAtIndex:(NSInteger)anInt; 41 | - (NSString *)unsignedLongLongDescriptionAtIndex:(NSInteger)anInt; 42 | - (NSString *)doubleDescriptionAtIndex:(NSInteger)anInt; 43 | - (NSString *)floatDescriptionAtIndex:(NSInteger)anInt; 44 | - (NSString *)structDescriptionAtIndex:(NSInteger)anInt; 45 | - (NSString *)pointerDescriptionAtIndex:(NSInteger)anInt; 46 | - (NSString *)cStringDescriptionAtIndex:(NSInteger)anInt; 47 | - (NSString *)selectorDescriptionAtIndex:(NSInteger)anInt; 48 | 49 | - (BOOL)methodIsInInitFamily; 50 | - (BOOL)methodIsInCreateFamily; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Source/OCMock/NSMethodSignature+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface NSMethodSignature(OCMAdditions) 20 | 21 | + (NSMethodSignature *)signatureForDynamicPropertyAccessedWithSelector:(SEL)selector inClass:(Class)aClass; 22 | + (NSMethodSignature *)signatureForBlock:(id)block; 23 | 24 | - (BOOL)usesSpecialStructureReturn; 25 | 26 | - (NSString *)fullTypeString; 27 | - (const char *)fullObjCTypes; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Source/OCMock/NSNotificationCenter+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCObserverMockObject; 20 | 21 | 22 | @interface NSNotificationCenter(OCMAdditions) 23 | 24 | - (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Source/OCMock/NSNotificationCenter+OCMAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "NSNotificationCenter+OCMAdditions.h" 18 | #import "OCObserverMockObject.h" 19 | 20 | 21 | @implementation NSNotificationCenter(OCMAdditions) 22 | 23 | #pragma clang diagnostic push 24 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 25 | 26 | - (void)addMockObserver:(OCObserverMockObject *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender 27 | { 28 | [notificationObserver autoRemoveFromCenter:self]; 29 | [self addObserver:notificationObserver selector:@selector(handleNotification:) name:notificationName object:notificationSender]; 30 | } 31 | 32 | #pragma clang diagnostic pop 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Source/OCMock/NSObject+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface NSObject(OCMAdditions) 20 | 21 | + (IMP)instanceMethodForwarderForSelector:(SEL)aSelector; 22 | + (void)enumerateMethodsInClass:(Class)aClass usingBlock:(void (^)(Class cls, SEL sel))aBlock; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Source/OCMock/NSObject+OCMAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import 19 | #import "NSMethodSignature+OCMAdditions.h" 20 | #import "NSObject+OCMAdditions.h" 21 | 22 | @implementation NSObject(OCMAdditions) 23 | 24 | + (IMP)instanceMethodForwarderForSelector:(SEL)aSelector 25 | { 26 | #ifndef __arm64__ 27 | static NSMutableDictionary *_OCMReturnTypeCache; 28 | 29 | if(_OCMReturnTypeCache == nil) 30 | _OCMReturnTypeCache = [[NSMutableDictionary alloc] init]; 31 | 32 | BOOL needsStructureReturn; 33 | void *rawCacheKey[2] = { (void *)self, aSelector }; 34 | NSData *cacheKey = [NSData dataWithBytes:rawCacheKey length:sizeof(rawCacheKey)]; 35 | NSNumber *cachedValue = [_OCMReturnTypeCache objectForKey:cacheKey]; 36 | 37 | if(cachedValue == nil) 38 | { 39 | NSMethodSignature *sig = [self instanceMethodSignatureForSelector:aSelector]; 40 | needsStructureReturn = [sig usesSpecialStructureReturn]; 41 | [_OCMReturnTypeCache setObject:@(needsStructureReturn) forKey:cacheKey]; 42 | } 43 | else 44 | { 45 | needsStructureReturn = [cachedValue boolValue]; 46 | } 47 | 48 | if(needsStructureReturn) 49 | return (IMP)_objc_msgForward_stret; 50 | #endif 51 | 52 | return _objc_msgForward; 53 | } 54 | 55 | + (void)enumerateMethodsInClass:(Class)aClass usingBlock:(void (^)(Class cls, SEL sel))aBlock 56 | { 57 | for(Class cls = aClass; cls != nil; cls = class_getSuperclass(cls)) 58 | { 59 | Method *methodList = class_copyMethodList(cls, NULL); 60 | if(methodList == NULL) 61 | continue; 62 | 63 | for(Method *mPtr = methodList; *mPtr != NULL; mPtr++) 64 | { 65 | SEL sel = method_getName(*mPtr); 66 | aBlock(cls, sel); 67 | } 68 | free(methodList); 69 | } 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /Source/OCMock/NSValue+OCMAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface NSValue(OCMAdditions) 20 | 21 | - (BOOL)getBytes:(void *)outputBuf objCType:(const char *)targetType; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Source/OCMock/OCClassMockObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMockObject.h" 18 | 19 | @interface OCClassMockObject : OCMockObject 20 | { 21 | Class mockedClass; 22 | Class originalMetaClass; 23 | Class classCreatedForNewMetaClass; 24 | } 25 | 26 | - (id)initWithClass:(Class)aClass; 27 | 28 | - (Class)mockedClass; 29 | - (Class)mockObjectClass; // since -class returns the mockedClass 30 | 31 | - (void)assertClassIsSupported:(Class)aClass; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Source/OCMock/OCMArg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMArg : NSObject 20 | 21 | // constraining arguments 22 | 23 | + (id)any; 24 | + (SEL)anySelector; 25 | + (void *)anyPointer; 26 | + (id __autoreleasing *)anyObjectRef; 27 | + (id)isNil; 28 | + (id)isNotNil; 29 | + (id)isEqual:(id)value; 30 | + (id)isNotEqual:(id)value; 31 | + (id)isKindOfClass:(Class)cls; 32 | + (id)checkWithSelector:(SEL)selector onObject:(id)anObject; 33 | + (id)checkWithBlock:(BOOL (^)(id obj))block; 34 | 35 | // manipulating arguments 36 | 37 | + (id *)setTo:(id)value; 38 | + (void *)setToValue:(NSValue *)value; 39 | + (id)invokeBlock; 40 | + (id)invokeBlockWithArgs:(id)first, ... NS_REQUIRES_NIL_TERMINATION; 41 | 42 | + (id)defaultValue; 43 | 44 | // internal use only 45 | 46 | + (id)resolveSpecialValues:(NSValue *)value; 47 | 48 | @end 49 | 50 | #define OCMOCK_ANY [OCMArg any] 51 | 52 | #define OCMOCK_VALUE(variable) \ 53 | ({ __typeof__(variable) __v = (variable); [NSValue value:&__v withObjCType:@encode(__typeof__(__v))]; }) 54 | -------------------------------------------------------------------------------- /Source/OCMock/OCMArgAction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMArgAction : NSObject 20 | 21 | - (void)handleArgument:(id)argument; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Source/OCMock/OCMArgAction.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMArgAction.h" 18 | 19 | 20 | @implementation OCMArgAction 21 | 22 | - (void)handleArgument:(id)argument 23 | { 24 | 25 | } 26 | 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Source/OCMock/OCMBlockArgCaller.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMArgAction.h" 18 | 19 | @interface OCMBlockArgCaller : OCMArgAction 20 | { 21 | NSArray *arguments; 22 | } 23 | 24 | - (instancetype)initWithBlockArguments:(NSArray *)someArgs; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Source/OCMock/OCMBlockArgCaller.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMBlockArgCaller.h" 18 | #import "NSInvocation+OCMAdditions.h" 19 | 20 | 21 | @implementation OCMBlockArgCaller 22 | 23 | - (instancetype)initWithBlockArguments:(NSArray *)someArgs 24 | { 25 | self = [super init]; 26 | if(self) 27 | { 28 | arguments = [someArgs copy]; 29 | } 30 | return self; 31 | } 32 | 33 | - (void)dealloc 34 | { 35 | [arguments release]; 36 | [super dealloc]; 37 | } 38 | 39 | - (id)copyWithZone:(NSZone *)zone 40 | { 41 | return [self retain]; 42 | } 43 | 44 | - (void)handleArgument:(id)aBlock 45 | { 46 | if(aBlock) 47 | { 48 | NSInvocation *inv = [NSInvocation invocationForBlock:aBlock withArguments:arguments]; 49 | [inv invokeWithTarget:aBlock]; 50 | } 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Source/OCMock/OCMBlockCaller.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMBlockCaller : NSObject 20 | { 21 | void (^block)(NSInvocation *); 22 | } 23 | 24 | - (id)initWithCallBlock:(void (^)(NSInvocation *))theBlock; 25 | 26 | - (void)handleInvocation:(NSInvocation *)anInvocation; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Source/OCMock/OCMBlockCaller.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMBlockCaller.h" 18 | 19 | 20 | @implementation OCMBlockCaller 21 | 22 | - (id)initWithCallBlock:(void (^)(NSInvocation *))theBlock 23 | { 24 | if((self = [super init])) 25 | { 26 | block = [theBlock copy]; 27 | } 28 | 29 | return self; 30 | } 31 | 32 | - (void)dealloc 33 | { 34 | [block release]; 35 | [super dealloc]; 36 | } 37 | 38 | - (void)handleInvocation:(NSInvocation *)anInvocation 39 | { 40 | if(block != nil) 41 | { 42 | block(anInvocation); 43 | } 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Source/OCMock/OCMBoxedReturnValueProvider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMObjectReturnValueProvider.h" 18 | 19 | @interface OCMBoxedReturnValueProvider : OCMObjectReturnValueProvider 20 | { 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Source/OCMock/OCMBoxedReturnValueProvider.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMBoxedReturnValueProvider.h" 18 | #import "NSValue+OCMAdditions.h" 19 | #import "OCMFunctionsPrivate.h" 20 | 21 | 22 | @implementation OCMBoxedReturnValueProvider 23 | 24 | - (void)handleInvocation:(NSInvocation *)anInvocation 25 | { 26 | NSUInteger valueSize = 0; 27 | NSValue *returnValueAsNSValue = (NSValue *)returnValue; 28 | NSGetSizeAndAlignment([returnValueAsNSValue objCType], &valueSize, NULL); 29 | char valueBuffer[valueSize]; 30 | [returnValueAsNSValue getValue:valueBuffer]; 31 | 32 | const char *returnType = [[anInvocation methodSignature] methodReturnType]; 33 | 34 | if([self isMethodReturnType:returnType compatibleWithValueType:[returnValueAsNSValue objCType] 35 | value:valueBuffer valueSize:valueSize]) 36 | { 37 | [anInvocation setReturnValue:valueBuffer]; 38 | } 39 | else if([returnValueAsNSValue getBytes:valueBuffer objCType:returnType]) 40 | { 41 | [anInvocation setReturnValue:valueBuffer]; 42 | } 43 | else 44 | { 45 | [NSException raise:NSInvalidArgumentException 46 | format:@"Return value cannot be used for method; method signature declares '%s' but value is '%s'.", returnType, [returnValueAsNSValue objCType]]; 47 | } 48 | } 49 | 50 | - (BOOL)isMethodReturnType:(const char *)returnType compatibleWithValueType:(const char *)valueType value:(const void *)value valueSize:(size_t)valueSize 51 | { 52 | /* Same types are obviously compatible */ 53 | if(strcmp(returnType, valueType) == 0) 54 | return YES; 55 | 56 | /* Special treatment for nil and Nil */ 57 | if(strcmp(returnType, @encode(id)) == 0 || strcmp(returnType, @encode(Class)) == 0) 58 | return OCMIsNilValue(valueType, value, valueSize); 59 | 60 | return OCMEqualTypesAllowingOpaqueStructs(returnType, valueType); 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Source/OCMock/OCMConstraint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMConstraint : NSObject 20 | 21 | + (instancetype)constraint; 22 | - (BOOL)evaluate:(id)value; 23 | 24 | // if you are looking for any, isNil, etc, they have moved to OCMArg 25 | 26 | // try to use [OCMArg checkWith...] instead of the constraintWith... methods below 27 | 28 | + (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject; 29 | + (instancetype)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue; 30 | 31 | 32 | @end 33 | 34 | @interface OCMAnyConstraint : OCMConstraint 35 | @end 36 | 37 | @interface OCMIsNilConstraint : OCMConstraint 38 | @end 39 | 40 | @interface OCMIsNotNilConstraint : OCMConstraint 41 | @end 42 | 43 | @interface OCMIsNotEqualConstraint : OCMConstraint 44 | { 45 | @public 46 | id testValue; 47 | } 48 | 49 | @end 50 | 51 | @interface OCMInvocationConstraint : OCMConstraint 52 | { 53 | @public 54 | NSInvocation *invocation; 55 | } 56 | 57 | @end 58 | 59 | @interface OCMBlockConstraint : OCMConstraint 60 | { 61 | BOOL (^block)(id); 62 | } 63 | 64 | - (instancetype)initWithConstraintBlock:(BOOL (^)(id))block; 65 | 66 | @end 67 | 68 | #ifndef OCM_DISABLE_SHORT_SYNTAX 69 | #define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self] 70 | #define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)] 71 | #endif 72 | -------------------------------------------------------------------------------- /Source/OCMock/OCMExceptionReturnValueProvider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMObjectReturnValueProvider.h" 18 | 19 | extern NSString *OCMStubbedException; 20 | 21 | @interface OCMExceptionReturnValueProvider : OCMObjectReturnValueProvider 22 | { 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Source/OCMock/OCMExceptionReturnValueProvider.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMExceptionReturnValueProvider.h" 18 | 19 | 20 | @implementation OCMExceptionReturnValueProvider 21 | 22 | NSString *OCMStubbedException = @"OCMStubbedException"; 23 | 24 | 25 | - (void)handleInvocation:(NSInvocation *)anInvocation 26 | { 27 | [[NSException exceptionWithName:OCMStubbedException reason:@"Exception stubbed in test." userInfo:@{ @"exception" : returnValue }] raise]; 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Source/OCMock/OCMExpectationRecorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMStubRecorder.h" 18 | 19 | @interface OCMExpectationRecorder : OCMStubRecorder 20 | 21 | - (id)never; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Source/OCMock/OCMExpectationRecorder.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMExpectationRecorder.h" 18 | #import "OCMInvocationExpectation.h" 19 | #import "OCMockObject.h" 20 | 21 | 22 | @implementation OCMExpectationRecorder 23 | 24 | #pragma mark Initialisers, description, accessors, etc. 25 | 26 | - (id)init 27 | { 28 | self = [super init]; 29 | [invocationMatcher release]; 30 | invocationMatcher = [[OCMInvocationExpectation alloc] init]; 31 | return self; 32 | } 33 | 34 | - (OCMInvocationExpectation *)expectation 35 | { 36 | return (OCMInvocationExpectation *)invocationMatcher; 37 | } 38 | 39 | 40 | #pragma mark Modifying the expectation 41 | 42 | - (id)never 43 | { 44 | [[self expectation] setMatchAndReject:YES]; 45 | return self; 46 | } 47 | 48 | 49 | #pragma mark Finishing recording 50 | 51 | - (void)forwardInvocation:(NSInvocation *)anInvocation 52 | { 53 | [super forwardInvocation:anInvocation]; 54 | [mockObject addExpectation:[self expectation]]; 55 | } 56 | 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Source/OCMock/OCMFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | 20 | #if defined(__cplusplus) 21 | #define OCMOCK_EXTERN extern "C" 22 | #else 23 | #define OCMOCK_EXTERN extern 24 | #endif 25 | 26 | 27 | OCMOCK_EXTERN BOOL OCMIsObjectType(const char *objCType); 28 | OCMOCK_EXTERN BOOL OCMIsSubclassOfMockClass(Class cls); 29 | -------------------------------------------------------------------------------- /Source/OCMock/OCMIndirectReturnValueProvider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMIndirectReturnValueProvider : NSObject 20 | { 21 | id provider; 22 | SEL selector; 23 | } 24 | 25 | - (id)initWithProvider:(id)aProvider andSelector:(SEL)aSelector; 26 | 27 | - (void)handleInvocation:(NSInvocation *)anInvocation; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Source/OCMock/OCMIndirectReturnValueProvider.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMIndirectReturnValueProvider.h" 18 | 19 | 20 | @implementation OCMIndirectReturnValueProvider 21 | 22 | - (id)initWithProvider:(id)aProvider andSelector:(SEL)aSelector 23 | { 24 | if((self = [super init])) 25 | { 26 | provider = [aProvider retain]; 27 | selector = aSelector; 28 | } 29 | 30 | return self; 31 | } 32 | 33 | - (void)dealloc 34 | { 35 | [provider release]; 36 | [super dealloc]; 37 | } 38 | 39 | - (void)handleInvocation:(NSInvocation *)anInvocation 40 | { 41 | id originalTarget = [anInvocation target]; 42 | SEL originalSelector = [anInvocation selector]; 43 | 44 | [anInvocation setTarget:provider]; 45 | [anInvocation setSelector:selector]; 46 | [anInvocation invoke]; 47 | 48 | [anInvocation setTarget:originalTarget]; 49 | [anInvocation setSelector:originalSelector]; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Source/OCMock/OCMInvocationExpectation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMInvocationStub.h" 18 | 19 | @interface OCMInvocationExpectation : OCMInvocationStub 20 | { 21 | BOOL matchAndReject; 22 | BOOL isSatisfied; 23 | } 24 | 25 | - (void)setMatchAndReject:(BOOL)flag; 26 | - (BOOL)isMatchAndReject; 27 | 28 | - (BOOL)isSatisfied; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Source/OCMock/OCMInvocationExpectation.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "NSInvocation+OCMAdditions.h" 18 | #import "OCMInvocationExpectation.h" 19 | 20 | 21 | @implementation OCMInvocationExpectation 22 | 23 | - (void)setMatchAndReject:(BOOL)flag 24 | { 25 | matchAndReject = flag; 26 | if(matchAndReject) 27 | isSatisfied = YES; 28 | } 29 | 30 | - (BOOL)isMatchAndReject 31 | { 32 | return matchAndReject; 33 | } 34 | 35 | - (BOOL)isSatisfied 36 | { 37 | return isSatisfied; 38 | } 39 | 40 | - (void)addInvocationAction:(id)anAction 41 | { 42 | if(matchAndReject) 43 | { 44 | [NSException raise:NSInternalInconsistencyException format:@"%@: cannot add action to a reject stub; got %@", 45 | [self description], anAction]; 46 | } 47 | [super addInvocationAction:anAction]; 48 | } 49 | 50 | - (void)handleInvocation:(NSInvocation *)anInvocation 51 | { 52 | if(matchAndReject) 53 | { 54 | isSatisfied = NO; 55 | [NSException raise:NSInternalInconsistencyException format:@"%@: explicitly disallowed method invoked: %@", 56 | [self description], [anInvocation invocationDescription]]; 57 | } 58 | else 59 | { 60 | [super handleInvocation:anInvocation]; 61 | isSatisfied = YES; 62 | } 63 | } 64 | 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Source/OCMock/OCMInvocationMatcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMInvocationMatcher : NSObject 20 | { 21 | NSInvocation *recordedInvocation; 22 | BOOL recordedAsClassMethod; 23 | BOOL ignoreNonObjectArgs; 24 | } 25 | 26 | - (void)setInvocation:(NSInvocation *)anInvocation; 27 | - (NSInvocation *)recordedInvocation; 28 | 29 | - (void)setRecordedAsClassMethod:(BOOL)flag; 30 | - (BOOL)recordedAsClassMethod; 31 | 32 | - (void)setIgnoreNonObjectArgs:(BOOL)flag; 33 | 34 | - (BOOL)matchesSelector:(SEL)aSelector; 35 | - (BOOL)matchesInvocation:(NSInvocation *)anInvocation; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Source/OCMock/OCMInvocationStub.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMInvocationMatcher.h" 18 | 19 | @interface OCMInvocationStub : OCMInvocationMatcher 20 | { 21 | NSMutableArray *invocationActions; 22 | } 23 | 24 | - (void)addInvocationAction:(id)anAction; 25 | - (NSArray *)invocationActions; 26 | 27 | - (void)handleInvocation:(NSInvocation *)anInvocation; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Source/OCMock/OCMLocation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import 19 | 20 | @interface OCMLocation : NSObject 21 | { 22 | id testCase; 23 | NSString *file; 24 | NSUInteger line; 25 | } 26 | 27 | + (instancetype)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; 28 | 29 | - (instancetype)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine; 30 | 31 | - (id)testCase; 32 | - (NSString *)file; 33 | - (NSUInteger)line; 34 | 35 | @end 36 | 37 | OCMOCK_EXTERN OCMLocation *OCMMakeLocation(id testCase, const char *file, int line); 38 | -------------------------------------------------------------------------------- /Source/OCMock/OCMLocation.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMLocation.h" 18 | 19 | 20 | @implementation OCMLocation 21 | 22 | + (instancetype)locationWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine 23 | { 24 | return [[[OCMLocation alloc] initWithTestCase:aTestCase file:aFile line:aLine] autorelease]; 25 | } 26 | 27 | - (instancetype)initWithTestCase:(id)aTestCase file:(NSString *)aFile line:(NSUInteger)aLine 28 | { 29 | if((self = [super init])) 30 | { 31 | testCase = aTestCase; 32 | file = [aFile retain]; 33 | line = aLine; 34 | } 35 | 36 | return self; 37 | } 38 | 39 | - (void)dealloc 40 | { 41 | [file release]; 42 | [super dealloc]; 43 | } 44 | 45 | - (id)testCase 46 | { 47 | return testCase; 48 | } 49 | 50 | - (NSString *)file 51 | { 52 | return file; 53 | } 54 | 55 | - (NSUInteger)line 56 | { 57 | return line; 58 | } 59 | 60 | @end 61 | 62 | 63 | OCMLocation *OCMMakeLocation(id testCase, const char *fileCString, int line) 64 | { 65 | return [OCMLocation locationWithTestCase:testCase file:[NSString stringWithUTF8String:fileCString] line:line]; 66 | } 67 | -------------------------------------------------------------------------------- /Source/OCMock/OCMMacroState.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMQuantifier; 21 | @class OCMRecorder; 22 | @class OCMStubRecorder; 23 | @class OCMockObject; 24 | 25 | 26 | @interface OCMMacroState : NSObject 27 | { 28 | OCMRecorder *recorder; 29 | BOOL invocationDidThrow; 30 | } 31 | 32 | + (void)beginStubMacro; 33 | + (OCMStubRecorder *)endStubMacro; 34 | 35 | + (void)beginExpectMacro; 36 | + (OCMStubRecorder *)endExpectMacro; 37 | 38 | + (void)beginRejectMacro; 39 | + (OCMStubRecorder *)endRejectMacro; 40 | 41 | + (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation; 42 | + (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation withQuantifier:(OCMQuantifier *)quantifier; 43 | + (void)endVerifyMacro; 44 | 45 | + (OCMMacroState *)globalState; 46 | 47 | - (void)setRecorder:(OCMRecorder *)aRecorder; 48 | - (OCMRecorder *)recorder; 49 | 50 | - (void)switchToClassMethod; 51 | 52 | - (void)setInvocationDidThrow:(BOOL)flag; 53 | - (BOOL)invocationDidThrow; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Source/OCMock/OCMNonRetainingObjectReturnValueProvider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMNonRetainingObjectReturnValueProvider : NSObject 20 | { 21 | id returnValue; 22 | } 23 | 24 | - (instancetype)initWithValue:(id)aValue; 25 | 26 | - (void)handleInvocation:(NSInvocation *)anInvocation; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Source/OCMock/OCMNonRetainingObjectReturnValueProvider.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "NSInvocation+OCMAdditions.h" 18 | #import "OCMNonRetainingObjectReturnValueProvider.h" 19 | #import "OCMFunctions.h" 20 | 21 | 22 | @implementation OCMNonRetainingObjectReturnValueProvider 23 | 24 | - (instancetype)initWithValue:(id)aValue 25 | { 26 | if((self = [super init])) 27 | returnValue = aValue; 28 | return self; 29 | } 30 | 31 | - (void)handleInvocation:(NSInvocation *)anInvocation 32 | { 33 | if(!OCMIsObjectType([[anInvocation methodSignature] methodReturnType])) 34 | { 35 | @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Expected invocation with object return type. Did you mean to use andReturnValue: instead?" userInfo:nil]; 36 | } 37 | [anInvocation setReturnValue:&returnValue]; 38 | } 39 | @end 40 | -------------------------------------------------------------------------------- /Source/OCMock/OCMNotificationPoster.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMNotificationPoster : NSObject 20 | { 21 | NSNotification *notification; 22 | } 23 | 24 | - (id)initWithNotification:(id)aNotification; 25 | 26 | - (void)handleInvocation:(NSInvocation *)anInvocation; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Source/OCMock/OCMNotificationPoster.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMNotificationPoster.h" 18 | 19 | 20 | @implementation OCMNotificationPoster 21 | 22 | - (id)initWithNotification:(id)aNotification 23 | { 24 | if((self = [super init])) 25 | { 26 | notification = [aNotification retain]; 27 | } 28 | 29 | return self; 30 | } 31 | 32 | - (void)dealloc 33 | { 34 | [notification release]; 35 | [super dealloc]; 36 | } 37 | 38 | - (void)handleInvocation:(NSInvocation *)anInvocation 39 | { 40 | [[NSNotificationCenter defaultCenter] postNotification:notification]; 41 | } 42 | 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Source/OCMock/OCMObjectReturnValueProvider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMNonRetainingObjectReturnValueProvider.h" 18 | 19 | @interface OCMObjectReturnValueProvider : OCMNonRetainingObjectReturnValueProvider 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Source/OCMock/OCMObjectReturnValueProvider.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMObjectReturnValueProvider.h" 18 | 19 | 20 | @implementation OCMObjectReturnValueProvider 21 | 22 | - (instancetype)initWithValue:(id)aValue 23 | { 24 | if((self = [super initWithValue:aValue])) 25 | [returnValue retain]; 26 | return self; 27 | } 28 | 29 | - (void)dealloc 30 | { 31 | [returnValue release]; 32 | [super dealloc]; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Source/OCMock/OCMObserverRecorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMObserverRecorder : NSObject 20 | { 21 | NSNotification *recordedNotification; 22 | } 23 | 24 | - (NSNotification *)notificationWithName:(NSString *)name object:(id)sender; 25 | 26 | - (NSNotification *)notificationWithName:(NSString *)name object:(id)sender userInfo:(NSDictionary *)userInfo; 27 | 28 | - (BOOL)matchesNotification:(NSNotification *)aNotification; 29 | 30 | - (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg; 31 | 32 | - (BOOL)didRecordInvocation __used; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Source/OCMock/OCMPassByRefSetter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMArgAction.h" 18 | 19 | @interface OCMPassByRefSetter : OCMArgAction 20 | { 21 | id value; 22 | } 23 | 24 | - (id)initWithValue:(id)value; 25 | 26 | + (BOOL)isPassByRefSetterInstance:(void *)ptr; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Source/OCMock/OCMPassByRefSetter.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMPassByRefSetter.h" 18 | 19 | 20 | @implementation OCMPassByRefSetter 21 | 22 | // Stores a reference to all OCMPassByRefSetter instances so that OCMArg can 23 | // check for any given pointer whether its an OCMPassByRefSetter without having 24 | // to get the class for the pointer (see #503). The pointers are stored without 25 | // reference count. 26 | static NSHashTable *_OCMPassByRefSetterInstances = NULL; 27 | 28 | + (void)initialize 29 | { 30 | if(self == [OCMPassByRefSetter class]) 31 | { 32 | _OCMPassByRefSetterInstances = [[NSHashTable hashTableWithOptions:NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality] retain]; 33 | } 34 | } 35 | 36 | + (BOOL)isPassByRefSetterInstance:(void *)ptr 37 | { 38 | @synchronized(_OCMPassByRefSetterInstances) 39 | { 40 | return NSHashGet(_OCMPassByRefSetterInstances, ptr) != NULL; 41 | } 42 | } 43 | 44 | - (id)initWithValue:(id)aValue 45 | { 46 | if((self = [super init])) 47 | { 48 | value = [aValue retain]; 49 | @synchronized(_OCMPassByRefSetterInstances) 50 | { 51 | NSHashInsertKnownAbsent(_OCMPassByRefSetterInstances, self); 52 | } 53 | } 54 | 55 | return self; 56 | } 57 | 58 | - (void)dealloc 59 | { 60 | [value release]; 61 | @synchronized(_OCMPassByRefSetterInstances) 62 | { 63 | NSHashRemove(_OCMPassByRefSetterInstances, self); 64 | } 65 | [super dealloc]; 66 | } 67 | 68 | - (void)handleArgument:(id)arg 69 | { 70 | void *pointerValue = [arg pointerValue]; 71 | if(pointerValue != NULL) 72 | { 73 | if([value isKindOfClass:[NSValue class]]) 74 | [(NSValue *)value getValue:pointerValue]; 75 | else 76 | *(id *)pointerValue = value; 77 | } 78 | } 79 | 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /Source/OCMock/OCMQuantifier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMQuantifier : NSObject 20 | { 21 | NSUInteger expectedCount; 22 | } 23 | 24 | + (instancetype)never; 25 | + (instancetype)exactly:(NSUInteger)count; 26 | + (instancetype)atLeast:(NSUInteger)count; 27 | + (instancetype)atMost:(NSUInteger)count; 28 | 29 | - (BOOL)isValidCount:(NSUInteger)count; 30 | 31 | - (NSString *)description; 32 | 33 | @end 34 | 35 | 36 | #define OCMNever() ([OCMQuantifier never]) 37 | #define OCMTimes(n) ([OCMQuantifier exactly:(n)]) 38 | #define OCMAtLeast(n) ([OCMQuantifier atLeast:(n)]) 39 | #define OCMAtMost(n) ([OCMQuantifier atMost:(n)]) 40 | 41 | #ifndef OCM_DISABLE_SHORT_QSYNTAX 42 | #define never() OCMNever() 43 | #define times(n) OCMTimes(n) 44 | #define atLeast(n) OCMAtLeast(n) 45 | #define atMost(n) OCMAtMost(n) 46 | #endif 47 | -------------------------------------------------------------------------------- /Source/OCMock/OCMRealObjectForwarder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface OCMRealObjectForwarder : NSObject 20 | { 21 | } 22 | 23 | - (void)handleInvocation:(NSInvocation *)anInvocation; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Source/OCMock/OCMRealObjectForwarder.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import "NSInvocation+OCMAdditions.h" 19 | #import "OCMRealObjectForwarder.h" 20 | #import "OCMFunctionsPrivate.h" 21 | #import "OCPartialMockObject.h" 22 | 23 | 24 | @implementation OCMRealObjectForwarder 25 | 26 | - (void)handleInvocation:(NSInvocation *)anInvocation 27 | { 28 | id invocationTarget = [anInvocation target]; 29 | 30 | BOOL isInInitFamily = [anInvocation methodIsInInitFamily]; 31 | BOOL isInCreateFamily = isInInitFamily ? NO : [anInvocation methodIsInCreateFamily]; 32 | 33 | [anInvocation setSelector:OCMAliasForOriginalSelector([anInvocation selector])]; 34 | if([invocationTarget isProxy]) 35 | { 36 | if(!class_getInstanceMethod([invocationTarget mockObjectClass], @selector(realObject))) 37 | [NSException raise:NSInternalInconsistencyException format:@"Method andForwardToRealObject can only be used with partial mocks and class methods."]; 38 | 39 | NSObject *realObject = [(OCPartialMockObject *)invocationTarget realObject]; 40 | [anInvocation setTarget:realObject]; 41 | if(isInInitFamily) 42 | { 43 | // The init method of the real object will "consume" self, but because the method was 44 | // invoked on the mock and not the real object a corresponding retain is missing; so 45 | // we do this here. The analyzer doesn't understand this; see #456 for details. 46 | #ifndef __clang_analyzer__ 47 | [realObject retain]; 48 | #endif 49 | } 50 | } 51 | 52 | [anInvocation invoke]; 53 | 54 | if(isInInitFamily || isInCreateFamily) 55 | { 56 | // After invoking the method on the real object the return value's retain count is correct, 57 | // but because we have a chain of handlers for an invocation and we handle the retain count 58 | // adjustments at the end in the stub, we undo the additional retains here. 59 | id returnVal; 60 | [anInvocation getReturnValue:&returnVal]; 61 | [returnVal autorelease]; 62 | } 63 | } 64 | 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Source/OCMock/OCMRecorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMockObject; 20 | @class OCMInvocationMatcher; 21 | 22 | 23 | @interface OCMRecorder : NSProxy 24 | { 25 | OCMockObject *mockObject; 26 | OCMInvocationMatcher *invocationMatcher; 27 | BOOL didRecordInvocation; 28 | BOOL shouldReturnMockFromInit; 29 | } 30 | 31 | - (instancetype)init; 32 | - (instancetype)initWithMockObject:(OCMockObject *)aMockObject; 33 | 34 | - (void)setMockObject:(OCMockObject *)aMockObject; 35 | - (void)setShouldReturnMockFromInit:(BOOL)flag; 36 | 37 | - (OCMInvocationMatcher *)invocationMatcher; 38 | - (BOOL)didRecordInvocation; 39 | 40 | - (id)classMethod; 41 | - (id)ignoringNonObjectArgs; 42 | 43 | @end 44 | 45 | @interface OCMRecorder (Properties) 46 | 47 | #define ignoringNonObjectArgs() _ignoringNonObjectArgs() 48 | @property(nonatomic, readonly) OCMRecorder * (^_ignoringNonObjectArgs)(void); 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /Source/OCMock/OCMVerifier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMQuantifier; 21 | 22 | @interface OCMVerifier : OCMRecorder 23 | 24 | @property(strong) OCMLocation *location; 25 | @property(strong) OCMQuantifier *quantifier; 26 | 27 | - (id)withQuantifier:(OCMQuantifier *)quantifier; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Source/OCMock/OCMVerifier.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMVerifier.h" 18 | #import "OCMInvocationMatcher.h" 19 | #import "OCMLocation.h" 20 | #import "OCMQuantifier.h" 21 | #import "OCMockObject.h" 22 | 23 | 24 | @implementation OCMVerifier 25 | 26 | - (id)init 27 | { 28 | if(invocationMatcher != nil) 29 | [NSException raise:NSInternalInconsistencyException format:@"** Method init invoked twice on verifier. Are you trying to verify the init method? This is currently not supported."]; 30 | if((self = [super init])) 31 | { 32 | invocationMatcher = [[OCMInvocationMatcher alloc] init]; 33 | } 34 | 35 | return self; 36 | } 37 | 38 | - (id)withQuantifier:(OCMQuantifier *)quantifier 39 | { 40 | [self setQuantifier:quantifier]; 41 | return self; 42 | } 43 | 44 | - (void)forwardInvocation:(NSInvocation *)anInvocation 45 | { 46 | [super forwardInvocation:anInvocation]; 47 | [mockObject verifyInvocation:invocationMatcher withQuantifier:self.quantifier atLocation:self.location]; 48 | } 49 | 50 | - (void)dealloc 51 | { 52 | [_location release]; 53 | [_quantifier release]; 54 | [super dealloc]; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Source/OCMock/OCMock-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 3.9.4 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 3.9.4 25 | NSHumanReadableCopyright 26 | Copyright © 2004-2024 Erik Doernenburg and contributors 27 | NSPrincipalClass 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Source/OCMock/OCMock-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'OCMock' target in the 'OCMock' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Source/OCMock/OCMock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import 19 | #import 20 | #import 21 | #import 22 | #import 23 | #import 24 | #import 25 | #import 26 | #import 27 | #import 28 | #import 29 | -------------------------------------------------------------------------------- /Source/OCMock/OCMockObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | @class OCMQuantifier; 21 | @class OCMInvocationStub; 22 | @class OCMStubRecorder; 23 | @class OCMInvocationMatcher; 24 | @class OCMInvocationExpectation; 25 | 26 | 27 | @interface OCMockObject : NSProxy 28 | { 29 | BOOL isNice; 30 | BOOL expectationOrderMatters; 31 | NSMutableArray *stubs; 32 | NSMutableArray *expectations; 33 | NSMutableArray *exceptions; 34 | NSMutableArray *invocations; 35 | } 36 | 37 | + (id)mockForClass:(Class)aClass; 38 | + (id)mockForProtocol:(Protocol *)aProtocol; 39 | + (id)partialMockForObject:(NSObject *)anObject; 40 | 41 | + (id)niceMockForClass:(Class)aClass; 42 | + (id)niceMockForProtocol:(Protocol *)aProtocol; 43 | 44 | + (id)observerMock __deprecated_msg("Please use XCTNSNotificationExpectation instead."); 45 | 46 | - (instancetype)init; 47 | 48 | - (void)setExpectationOrderMatters:(BOOL)flag; 49 | 50 | - (id)stub; 51 | - (id)expect; 52 | - (id)reject; 53 | 54 | - (id)verify; 55 | - (id)verifyAtLocation:(OCMLocation *)location; 56 | 57 | - (void)verifyWithDelay:(NSTimeInterval)delay; 58 | - (void)verifyWithDelay:(NSTimeInterval)delay atLocation:(OCMLocation *)location; 59 | 60 | - (void)stopMocking; 61 | 62 | // internal use only 63 | 64 | - (void)addStub:(OCMInvocationStub *)aStub; 65 | - (void)addExpectation:(OCMInvocationExpectation *)anExpectation; 66 | - (void)addInvocation:(NSInvocation *)anInvocation; 67 | 68 | - (BOOL)handleInvocation:(NSInvocation *)anInvocation; 69 | - (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation; 70 | - (BOOL)handleSelector:(SEL)sel; 71 | 72 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher; 73 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher atLocation:(OCMLocation *)location; 74 | - (void)verifyInvocation:(OCMInvocationMatcher *)matcher withQuantifier:(OCMQuantifier *)quantifier atLocation:(OCMLocation *)location; 75 | - (NSString *)descriptionForVerificationFailureWithMatcher:(OCMInvocationMatcher *)matcher quantifier:(OCMQuantifier *)quantifier invocationCount:(NSUInteger)count; 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /Source/OCMock/OCObserverMockObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @class OCMLocation; 20 | 21 | 22 | __deprecated_msg("Please use XCTNSNotificationExpectation instead.") 23 | @interface OCObserverMockObject : NSObject 24 | { 25 | BOOL expectationOrderMatters; 26 | NSMutableArray *recorders; 27 | NSMutableArray *centers; 28 | } 29 | 30 | - (void)setExpectationOrderMatters:(BOOL)flag; 31 | 32 | - (id)expect; 33 | 34 | - (void)verify; 35 | - (void)verifyAtLocation:(OCMLocation *)location; 36 | 37 | - (void)handleNotification:(NSNotification *)aNotification; 38 | 39 | // internal use 40 | 41 | - (void)autoRemoveFromCenter:(NSNotificationCenter *)aCenter; 42 | - (NSNotification *)notificationWithName:(NSString *)name object:(id)sender; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Source/OCMock/OCPartialMockObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCClassMockObject.h" 18 | 19 | @interface OCPartialMockObject : OCClassMockObject 20 | { 21 | NSObject *realObject; 22 | NSInvocation *invocationFromMock; 23 | } 24 | 25 | - (id)initWithObject:(NSObject *)anObject; 26 | 27 | - (NSObject *)realObject; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Source/OCMock/OCProtocolMockObject.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import "OCMockObject.h" 18 | 19 | @interface OCProtocolMockObject : OCMockObject 20 | { 21 | Protocol *mockedProtocol; 22 | } 23 | 24 | - (id)initWithProtocol:(Protocol *)aProtocol; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Source/OCMock/OCProtocolMockObject.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import "OCProtocolMockObject.h" 19 | 20 | 21 | @implementation OCProtocolMockObject 22 | 23 | #pragma mark Initialisers, description, accessors, etc. 24 | 25 | - (id)initWithProtocol:(Protocol *)aProtocol 26 | { 27 | if(aProtocol == nil) 28 | [NSException raise:NSInvalidArgumentException format:@"Protocol cannot be nil."]; 29 | 30 | [super init]; 31 | mockedProtocol = aProtocol; 32 | return self; 33 | } 34 | 35 | - (NSString *)description 36 | { 37 | const char *name = protocol_getName(mockedProtocol); 38 | return [NSString stringWithFormat:@"OCProtocolMockObject(%s)", name]; 39 | } 40 | 41 | #pragma mark Proxy API 42 | 43 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 44 | { 45 | struct { BOOL isRequired; BOOL isInstance; } opts[4] = { {YES, YES}, {NO, YES}, {YES, NO}, {NO, NO} }; 46 | for(int i = 0; i < 4; i++) 47 | { 48 | struct objc_method_description methodDescription = protocol_getMethodDescription(mockedProtocol, aSelector, opts[i].isRequired, opts[i].isInstance); 49 | if(methodDescription.name != NULL) 50 | return [NSMethodSignature signatureWithObjCTypes:methodDescription.types]; 51 | } 52 | return nil; 53 | } 54 | 55 | - (BOOL)conformsToProtocol:(Protocol *)aProtocol 56 | { 57 | return protocol_conformsToProtocol(mockedProtocol, aProtocol); 58 | } 59 | 60 | - (BOOL)respondsToSelector:(SEL)selector 61 | { 62 | return ([self methodSignatureForSelector:selector] != nil); 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Source/OCMockCI.xcconfig: -------------------------------------------------------------------------------- 1 | // Configuration settings file format documentation can be found at: 2 | // https://help.apple.com/xcode/#/dev745c5c974 3 | 4 | // If you change these here you must also update the makefile 5 | // Note that OBJROOT is not defined in terms of SYMROOT. For some 6 | // reason that doesn't work; PIFcache files get misplaced. 7 | //SYMROOT = $(PROJECT_DIR)/../Build 8 | //OBJROOT = $(PROJECT_DIR)/../Build/Intermediaries 9 | -------------------------------------------------------------------------------- /Source/OCMockDist.xcconfig: -------------------------------------------------------------------------------- 1 | // Configuration settings file format documentation can be found at: 2 | // https://help.apple.com/xcode/#/dev745c5c974 3 | 4 | // Settings to build archives 5 | SKIP_INSTALL = NO 6 | BUILD_LIBRARY_FOR_DISTRIBUTION=YES 7 | 8 | // Set the codesign identity for distribution 9 | CODE_SIGN_STYLE = Manual 10 | TEAM_IDENTIFIER = 28U2VZ7DF8 11 | CODE_SIGN_IDENTITY = Apple Development: erik@doernenburg.com (FJTF47J852) 12 | -------------------------------------------------------------------------------- /Source/OCMockLib/OCMockLib-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'OCMockLib' target in the 'OCMockLib' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Source/OCMockLibTests/OCMockLibTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Source/OCMockLibTests/OCMockLibTests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #import 10 | #endif 11 | -------------------------------------------------------------------------------- /Source/OCMockTests/OCMockObjectHamcrestTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2004-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import 19 | #import "OCMock.h" 20 | 21 | 22 | @interface OCMockObjectHamcrestTests : XCTestCase 23 | 24 | @end 25 | 26 | 27 | @implementation OCMockObjectHamcrestTests 28 | 29 | - (void)testAcceptsStubbedMethodWithHamcrestConstraint 30 | { 31 | id mock = [OCMockObject mockForClass:[NSString class]]; 32 | [[mock stub] hasSuffix:(id)startsWith(@"foo")]; 33 | [mock hasSuffix:@"foobar"]; 34 | } 35 | 36 | 37 | - (void)testRejectsUnstubbedMethodWithHamcrestConstraint 38 | { 39 | id mock = [OCMockObject mockForClass:[NSString class]]; 40 | [[mock stub] hasSuffix:(id)anyOf(equalTo(@"foo"), equalTo(@"bar"), NULL)]; 41 | XCTAssertThrows([mock hasSuffix:@"foobar"], @"Should have raised an exception."); 42 | } 43 | 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Source/OCMockTests/OCMockTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Source/OCMockTests/OCMockTests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /Source/OCMockTests/Resources/TestObjects.xcdatamodeld/TestObjects.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Source/OCMockTests/TestClassWithCustomReferenceCounting.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | 19 | @interface TestClassWithCustomReferenceCounting : NSObject 20 | @end 21 | -------------------------------------------------------------------------------- /Source/OCMockTests/TestClassWithCustomReferenceCounting.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2021 Erik Doernenburg and contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use these files except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | #import 18 | #import 19 | #import "TestClassWithCustomReferenceCounting.h" 20 | 21 | 22 | @implementation TestClassWithCustomReferenceCounting 23 | { 24 | #if __LP64__ 25 | int64_t _Atomic retainCount; 26 | #else 27 | int32_t retainCount; 28 | #endif 29 | } 30 | 31 | - (NSUInteger)retainCount 32 | { 33 | return retainCount + 1; 34 | } 35 | 36 | - (instancetype)retain 37 | { 38 | #if __LP64__ 39 | atomic_fetch_add(&retainCount, 1); 40 | #else 41 | OSAtomicIncrement32(&retainCount); 42 | #endif 43 | return self; 44 | } 45 | 46 | - (oneway void)release 47 | { 48 | #if __LP64__ 49 | int64_t newRetainCount = atomic_fetch_sub(&retainCount, 1); 50 | #else 51 | int32_t newRetainCount = OSAtomicDecrement32(&retainCount); 52 | #endif 53 | if(newRetainCount == -1) 54 | [self dealloc]; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Source/module.modulemap: -------------------------------------------------------------------------------- 1 | module OCMock { 2 | header "OCMock/OCMock.h" 3 | header "OCMock/OCMockObject.h" 4 | header "OCMock/OCMArg.h" 5 | header "OCMock/OCMConstraint.h" 6 | header "OCMock/OCMLocation.h" 7 | header "OCMock/OCMMacroState.h" 8 | header "OCMock/OCMRecorder.h" 9 | header "OCMock/OCMStubRecorder.h" 10 | header "OCMock/NSNotificationCenter+OCMAdditions.h" 11 | header "OCMock/OCMFunctions.h" 12 | header "OCMock/OCMVerifier.h" 13 | header "OCMock/OCMQuantifier.h" 14 | header "OCMock/OCMockMacros.h" 15 | export * 16 | } 17 | -------------------------------------------------------------------------------- /SwiftPMTests/objc/objc-header.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | #import 5 | #import 6 | #import 7 | #import 8 | #import 9 | #import 10 | #import 11 | #import 12 | #import 13 | -------------------------------------------------------------------------------- /SwiftPMTests/objc/objc-module.m: -------------------------------------------------------------------------------- 1 | @import OCMock; 2 | -------------------------------------------------------------------------------- /SwiftPMTests/swift/main.swift: -------------------------------------------------------------------------------- 1 | import OCMock 2 | -------------------------------------------------------------------------------- /Tools/buildcheck.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | def run(cmd, &block) 4 | puts "> #{cmd}" 5 | if block == nil 6 | abort "** command failed with error" if !system(cmd) 7 | else 8 | IO.popen(cmd, &block) 9 | end 10 | end 11 | 12 | def checkArchs(path, expected) 13 | archs = nil 14 | run("lipo -info \"#{path}\"") { |lipo| archs = /re: (.*)/.match(lipo.readline)[1].strip() } 15 | if (expected.split(" ") - archs.split(" ")).count > 0 16 | puts "Warning: missing architecture; expected \"#{expected}\", found \"#{archs}\"" 17 | end 18 | if (archs.split(" ") - expected.split(" ")).count > 0 19 | puts "Warning: unexpected architecture; expected \"#{expected}\", found \"#{archs}\"" 20 | end 21 | end 22 | 23 | def checkAuthority(path, expected) 24 | authorities = [] 25 | run("codesign -dvv #{path} 2>&1") { |codesign| codesign.readlines 26 | .map { |line| /Authority=(.*)/.match(line) } 27 | .select { |match| match != nil } 28 | .each { |match| authorities.push(match[1])} 29 | } 30 | if ! authorities.include? expected 31 | puts "Warning: missing signing authority; expected \"#{expected}\", found #{authorities}" 32 | end 33 | end 34 | 35 | productdir = ARGV[0] 36 | abort "Error: no product directory specified" if productdir == nil 37 | 38 | checkArchs "#{productdir}/OCMock-macOS.xcarchive/Products/Library/Frameworks/OCMock.framework/OCMock", "x86_64 arm64" 39 | checkArchs "#{productdir}/OCMock-iOS-lib.xcarchive/Products/usr/local/lib/libOCMock.a", "armv7 arm64" 40 | checkArchs "#{productdir}/OCMock-iOS-lib-sim.xcarchive/Products/usr/local/lib/libOCMock.a", "i386 x86_64 arm64" 41 | checkArchs "#{productdir}/OCMock-iOS.xcarchive/Products/Library/Frameworks/OCMock.framework/OCMock", "armv7 arm64" 42 | checkArchs "#{productdir}/OCMock-iOS-sim.xcarchive/Products/Library/Frameworks/OCMock.framework/OCMock", "i386 x86_64 arm64" 43 | checkArchs "#{productdir}/OCMock-tvOS.xcarchive/Products/Library/Frameworks/OCMock.framework/OCMock", "arm64" 44 | checkArchs "#{productdir}/OCMock-tvOS-sim.xcarchive/Products/Library/Frameworks/OCMock.framework/OCMock", "x86_64 arm64" 45 | checkArchs "#{productdir}/OCMock-watchOS.xcarchive/Products/Library/Frameworks/OCMock.framework/OCMock", "armv7k arm64_32" 46 | checkArchs "#{productdir}/OCMock-watchOS-sim.xcarchive/Products/Library/Frameworks/OCMock.framework/OCMock", "i386 x86_64 arm64" 47 | checkArchs "#{productdir}/OCMock-catalyst.xcarchive/Products/Library/Frameworks/OCMock.framework/OCMock", "x86_64 arm64" 48 | 49 | authority = "Apple Development: erik@doernenburg.com (FJTF47J852)" 50 | 51 | checkAuthority "#{productdir}/OCMock-macOS.xcarchive/Products/Library/Frameworks/OCMock.framework", authority 52 | -------------------------------------------------------------------------------- /Tools/makedmg.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | def run(cmd, &block) 4 | puts "> #{cmd}" 5 | if block == nil 6 | abort "** command failed with error" if !system(cmd) 7 | else 8 | IO.popen(cmd, &block) 9 | end 10 | end 11 | 12 | def getVersion(productdir) 13 | File.foreach("#{productdir}/Source/Changes.txt").each do |line| 14 | match = /^OCMock ([0-9.]*)/.match(line) 15 | return match[1] if match != nil 16 | end 17 | end 18 | 19 | def makeDMG(productdir, dmgdir, dmgname, volumename) 20 | tempdmg = "#{dmgdir}/ocmock-temp-#{Process.pid}.dmg" 21 | finaldmg = "#{dmgdir}/#{dmgname}.dmg" 22 | run("hdiutil create -size 8m #{tempdmg} -layout NONE") 23 | disk_id = nil 24 | run("hdid -nomount #{tempdmg}") { |hdid| disk_id = hdid.readline.split[0] } 25 | run("newfs_hfs -v '#{volumename}' #{disk_id}") 26 | run("hdiutil eject #{disk_id}") 27 | run("hdid #{tempdmg}") { |hdid| disk_id = hdid.readline.split[0] } 28 | run("cp -R #{productdir}/* '/Volumes/#{volumename}'") 29 | run("hdiutil eject #{disk_id}") 30 | run("rm -f #{finaldmg}") 31 | run("hdiutil convert -format UDZO #{tempdmg} -o #{finaldmg} -imagekey zlib-level=9") 32 | run("rm #{tempdmg}") 33 | end 34 | 35 | productdir = ARGV[0] 36 | abort "Error: no product directory specified" if productdir == nil 37 | 38 | dmgdir = ARGV[1] 39 | abort "Error: no DMG directory specified" if dmgdir == nil 40 | 41 | version = getVersion "#{productdir}" 42 | abort "Error: cannot determine version" if version == nil 43 | 44 | makeDMG productdir, dmgdir, "ocmock-#{version}", "OCMock #{version}" 45 | -------------------------------------------------------------------------------- /Tools/updatebanner.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | def update_directory(directory) 4 | Dir.entries(directory).each do | file | 5 | path = "#{directory}/#{file}" 6 | if File.directory?(path) 7 | update_directory(path) unless (file =~ /^[.]+$/) 8 | else 9 | update_file(path) if file =~ /\.(h|m|mm)$/ 10 | end 11 | end 12 | end 13 | 14 | def update_file(filename) 15 | tmpname = "#{filename}.orig" 16 | `mv #{filename} #{tmpname}` 17 | infile = File.open("#{tmpname}", "r") 18 | outfile = File.open("#{filename}", "w") 19 | replace_banner(infile, outfile) 20 | `rm #{tmpname}` 21 | end 22 | 23 | def replace_banner(infile, outfile) 24 | in_banner = true 25 | year = nil 26 | infile.each_line do | line | 27 | if in_banner 28 | copyright_match = /Copyright \(c\) ([0-9]{4})/.match(line) 29 | if copyright_match 30 | year = copyright_match[1] 31 | end 32 | if !(line =~ /^\/\//) && !(line =~ /^[\/ ]\*/) 33 | write_banner(outfile, year) 34 | in_banner = false 35 | end 36 | end 37 | if !in_banner 38 | outfile.puts line 39 | end 40 | end 41 | end 42 | 43 | def write_banner(outfile, year) 44 | banner = <<-EOS 45 | /* 46 | * Copyright (c) %YEARS% Erik Doernenburg and contributors 47 | * 48 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 49 | * not use these files except in compliance with the License. You may obtain 50 | * a copy of the License at 51 | * 52 | * http://www.apache.org/licenses/LICENSE-2.0 53 | * 54 | * Unless required by applicable law or agreed to in writing, software 55 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 56 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 57 | * License for the specific language governing permissions and limitations 58 | * under the License. 59 | */ 60 | EOS 61 | years = (year != "2021") ? "#{year}-2021" : year 62 | banner.gsub!(/%YEARS%/, years) 63 | outfile.write(banner) 64 | end 65 | 66 | update_directory(ARGV[0]) 67 | --------------------------------------------------------------------------------