2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #import <Foundation/Foundation.h>
26 #import <CloudKit/CloudKit.h>
28 #import "keychain/ckks/CloudKitDependencies.h"
29 #import "keychain/ckks/CKKSNotifier.h"
31 NS_ASSUME_NONNULL_BEGIN
33 @
class CKKSCKRecordHolder
;
36 typedef NSMutableDictionary
<CKRecordZoneID
*, FakeCKZone
*> FakeCKDatabase
;
39 @interface FakeCKModifyRecordZonesOperation
: NSBlockOperation
<CKKSModifyRecordZonesOperation
>
40 @
property (nullable
) NSError
* creationError
;
41 @
property (nonatomic
, nullable
) NSMutableArray
<CKRecordZone
*>* recordZonesSaved
;
42 @
property (nonatomic
, nullable
) NSMutableArray
<CKRecordZoneID
*>* recordZoneIDsDeleted
;
43 +(FakeCKDatabase
*) ckdb
;
47 @interface FakeCKModifySubscriptionsOperation
: NSBlockOperation
<CKKSModifySubscriptionsOperation
>
48 @
property (nullable
) NSError
* subscriptionError
;
49 @
property (nonatomic
, nullable
) NSMutableArray
<CKSubscription
*> *subscriptionsSaved
;
50 @
property (nonatomic
, nullable
) NSMutableArray
<NSString
*> *subscriptionIDsDeleted
;
51 +(FakeCKDatabase
*) ckdb
;
55 @interface FakeCKFetchRecordZoneChangesOperation
: NSOperation
<CKKSFetchRecordZoneChangesOperation
>
56 +(FakeCKDatabase
*) ckdb
;
60 @interface FakeAPSConnection
: NSObject
<CKKSAPSConnection
>
64 @interface FakeNSNotificationCenter
: NSObject
<CKKSNSNotificationCenter
>
65 + (instancetype
)defaultCenter
;
66 - (void)addObserver
:(id
)observer selector
:(SEL
)aSelector name
:(nullable NSNotificationName
)aName object
:(nullable id
)anObject
;
70 @interface FakeCKZone
: NSObject
71 // Used while mocking: database is the contents of the current current CloudKit database, pastDatabase is the state of the world in the past at different change tokens
72 @property CKRecordZoneID
* zoneID
;
73 @property CKServerChangeToken
* currentChangeToken
;
74 @property NSMutableDictionary
<CKRecordID
*, CKRecord
*>* currentDatabase
;
75 @property NSMutableDictionary
<CKServerChangeToken
*, NSMutableDictionary
<CKRecordID
*, CKRecord
*>*>* pastDatabases
;
76 @property
bool flag
; // used however you'd like in a test
78 // Usually nil. If set, trying to 'create' this zone should fail.
79 @
property (nullable
) NSError
* creationError
;
81 // Usually false. If set, trying to 'create' this should should 1) pretend to succeed but 2) delete this zone from existence
82 @property
bool failCreationSilently
;
84 // Usually nil. If set, trying to subscribe to this zone should fail.
85 @
property (nullable
) NSError
* subscriptionError
;
87 - (instancetype
)initZone
: (CKRecordZoneID
*) zoneID
;
89 - (void)rollChangeToken
;
92 - (void)addToZone
: (CKKSCKRecordHolder
*) item zoneID
: (CKRecordZoneID
*) zoneID
;
93 - (void)addToZone
: (CKRecord
*) record
;
95 - (void)addCKRecordToZone
: (CKRecord
*) record
;
96 - (NSError
* _Nullable
)deleteCKRecordIDFromZone
:(CKRecordID
*) recordID
;
98 // Sets up the next fetchChanges to fail with this error
99 - (void)failNextFetchWith
: (NSError
*) fetchChangesError
;
101 // Get the next fetchChanges error. Returns NULL if the fetchChanges should succeed.
102 - (NSError
* _Nullable
)popFetchChangesError
;
104 // Checks if this record add/modification should fail
105 - (NSError
* _Nullable
)errorFromSavingRecord
:(CKRecord
*) record
;
108 @interface FakeCKKSNotifier
: NSObject
<CKKSNotifier
>
111 NS_ASSUME_NONNULL_END