I've written a custom conflict handling routine that automatically kicks in to resolve conflicting versions of NSFileVersion. Now I want to write unit tests for in order to make sure it works. Here is the question:
How do I cause/create conflicting versions within a unit test?
This essentiall boils down to: how do I cause a conflict without manually doing it through iCloud? Since this is for testing purposes only, I don't care abput using private API or hacking directly into the system -- as long as the result is a conflict reported from NSFileVersion's +unresolvedConflictVersionsOfItemAtURL
. Any advice would be highly appreciated!
Max
You could patch +unresolvedConflictVersionsOfItemAtURL
with your own version that returns an array of conflicting versions:
#import <objc/runtime.h>
static IMP __originalUnresolvedConflictVersionIMP = NULL ;
static NSArray * MyNSFileVersionUnresolvedConflictVersions( id self, SEL _cmd, NSURL * url )
{
// this code just calls the original implementation...
// You can return an array of conflicting NSFileVersion objects instead...
NSLog(@"%s called\n", __PRETTY_FUNCTION__ ) ;
return (*__originalUnresolvedConflictVersionIMP)( self, _cmd, url ) ;
}
@implementation NSFileVersion (Test)
+(void)load
{
__originalUnresolvedConflictVersionIMP = class_replaceMethod( objc_getMetaClass( "NSFileVersion") , @selector( unresolvedConflictVersionsOfItemAtURL: ), (IMP)MyNSFileVersionUnresolvedConflictVersions, "@@:@" ) ;
}
@end
Is that enough to go on? I might first try this in my replacement "method":
return [ [ self otherVersionsOfItemAtURL:url ] lastObject ] ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With