session-ios/SignalServiceKit/src/TestUtils/MockSSKEnvironment.m

136 lines
5.6 KiB
Mathematica
Raw Normal View History

2018-09-17 15:27:58 +02:00
//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
2018-09-17 15:27:58 +02:00
//
#import "MockSSKEnvironment.h"
2018-10-10 23:36:41 +02:00
#import "ContactDiscoveryService.h"
#import "OWS2FAManager.h"
2018-11-07 23:49:25 +01:00
#import "OWSAttachmentDownloads.h"
#import "OWSBatchMessageProcessor.h"
#import "OWSBlockingManager.h"
2018-10-10 23:36:41 +02:00
#import "OWSDisappearingMessagesJob.h"
2018-09-17 15:27:58 +02:00
#import "OWSFakeCallMessageHandler.h"
#import "OWSFakeContactsUpdater.h"
#import "OWSFakeMessageSender.h"
#import "OWSFakeNetworkManager.h"
#import "OWSFakeProfileManager.h"
#import "OWSIdentityManager.h"
#import "OWSMessageDecrypter.h"
#import "OWSMessageManager.h"
#import "OWSMessageReceiver.h"
2018-10-11 21:29:01 +02:00
#import "OWSOutgoingReceiptManager.h"
2018-09-17 15:27:58 +02:00
#import "OWSPrimaryStorage.h"
2018-10-11 18:51:58 +02:00
#import "OWSReadReceiptManager.h"
#import "TSAccountManager.h"
#import "TSSocketManager.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
2018-09-17 15:27:58 +02:00
NS_ASSUME_NONNULL_BEGIN
2018-09-26 00:44:13 +02:00
#ifdef DEBUG
2018-09-17 15:27:58 +02:00
@interface OWSPrimaryStorage (Tests)
@property (atomic) BOOL areAsyncRegistrationsComplete;
@property (atomic) BOOL areSyncRegistrationsComplete;
@end
#pragma mark -
@implementation MockSSKEnvironment
+ (void)activate
{
MockSSKEnvironment *instance = [self new];
[self setShared:instance];
[instance configure];
2018-09-17 15:27:58 +02:00
}
- (instancetype)init
{
OWSPrimaryStorage *primaryStorage = [MockSSKEnvironment createPrimaryStorageForTests];
id<ContactsManagerProtocol> contactsManager = [OWSFakeContactsManager new];
TSNetworkManager *networkManager = [OWSFakeNetworkManager new];
OWSMessageSender *messageSender = [OWSFakeMessageSender new];
SSKMessageSenderJobQueue *messageSenderJobQueue = [SSKMessageSenderJobQueue new];
2018-09-17 15:27:58 +02:00
OWSMessageManager *messageManager = [[OWSMessageManager alloc] initWithPrimaryStorage:primaryStorage];
OWSBlockingManager *blockingManager = [[OWSBlockingManager alloc] initWithPrimaryStorage:primaryStorage];
OWSIdentityManager *identityManager = [[OWSIdentityManager alloc] initWithPrimaryStorage:primaryStorage];
id<OWSUDManager> udManager = [[OWSUDManagerImpl alloc] initWithPrimaryStorage:primaryStorage];
OWSMessageDecrypter *messageDecrypter = [[OWSMessageDecrypter alloc] initWithPrimaryStorage:primaryStorage];
OWSBatchMessageProcessor *batchMessageProcessor =
[[OWSBatchMessageProcessor alloc] initWithPrimaryStorage:primaryStorage];
OWSMessageReceiver *messageReceiver = [[OWSMessageReceiver alloc] initWithPrimaryStorage:primaryStorage];
TSSocketManager *socketManager = [[TSSocketManager alloc] init];
TSAccountManager *tsAccountManager = [[TSAccountManager alloc] initWithPrimaryStorage:primaryStorage];
2018-10-10 23:36:41 +02:00
OWS2FAManager *ows2FAManager = [[OWS2FAManager alloc] initWithPrimaryStorage:primaryStorage];
OWSDisappearingMessagesJob *disappearingMessagesJob =
[[OWSDisappearingMessagesJob alloc] initWithPrimaryStorage:primaryStorage];
ContactDiscoveryService *contactDiscoveryService = [[ContactDiscoveryService alloc] initDefault];
2018-10-11 18:51:58 +02:00
OWSReadReceiptManager *readReceiptManager = [[OWSReadReceiptManager alloc] initWithPrimaryStorage:primaryStorage];
2018-10-11 21:29:01 +02:00
OWSOutgoingReceiptManager *outgoingReceiptManager =
[[OWSOutgoingReceiptManager alloc] initWithPrimaryStorage:primaryStorage];
2018-10-22 17:42:53 +02:00
id<SSKReachabilityManager> reachabilityManager = [SSKReachabilityManagerImpl new];
2018-10-16 22:02:37 +02:00
id<OWSSyncManagerProtocol> syncManager = [[OWSMockSyncManager alloc] init];
id<OWSTypingIndicators> typingIndicators = [[OWSTypingIndicatorsImpl alloc] init];
2018-11-07 23:49:25 +01:00
OWSAttachmentDownloads *attachmentDownloads = [[OWSAttachmentDownloads alloc] init];
2018-09-17 15:27:58 +02:00
self = [super initWithContactsManager:contactsManager
messageSender:messageSender
messageSenderJobQueue:messageSenderJobQueue
2018-09-17 15:27:58 +02:00
profileManager:[OWSFakeProfileManager new]
primaryStorage:primaryStorage
contactsUpdater:[OWSFakeContactsUpdater new]
networkManager:networkManager
messageManager:messageManager
blockingManager:blockingManager
identityManager:identityManager
udManager:udManager
messageDecrypter:messageDecrypter
batchMessageProcessor:batchMessageProcessor
messageReceiver:messageReceiver
socketManager:socketManager
2018-10-10 23:36:41 +02:00
tsAccountManager:tsAccountManager
ows2FAManager:ows2FAManager
disappearingMessagesJob:disappearingMessagesJob
2018-10-11 18:51:58 +02:00
contactDiscoveryService:contactDiscoveryService
2018-10-16 22:02:37 +02:00
readReceiptManager:readReceiptManager
outgoingReceiptManager:outgoingReceiptManager
2018-10-22 17:42:53 +02:00
reachabilityManager:reachabilityManager
syncManager:syncManager
2018-11-07 23:49:25 +01:00
typingIndicators:typingIndicators
attachmentDownloads:attachmentDownloads];
2018-09-17 15:27:58 +02:00
if (!self) {
return nil;
}
2018-10-16 22:02:37 +02:00
2018-09-17 15:27:58 +02:00
self.callMessageHandler = [OWSFakeCallMessageHandler new];
self.notificationsManager = [NoopNotificationsManager new];
2018-09-17 15:27:58 +02:00
return self;
}
+ (OWSPrimaryStorage *)createPrimaryStorageForTests
{
OWSPrimaryStorage *primaryStorage = [[OWSPrimaryStorage alloc] initStorage];
[OWSPrimaryStorage protectFiles];
return primaryStorage;
}
- (void)configure
{
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[OWSStorage registerExtensionsWithMigrationBlock:^() {
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
2018-09-17 15:27:58 +02:00
@end
2018-09-26 00:44:13 +02:00
#endif
2018-09-17 15:27:58 +02:00
NS_ASSUME_NONNULL_END