parent
7096563e15
commit
919a7aa4f9
@ -0,0 +1,107 @@
|
||||
//
|
||||
// PEPSyncTest.m
|
||||
// pEpObjCAdapterTests
|
||||
//
|
||||
// Created by Andreas Buff on 17.01.18.
|
||||
// Copyright © 2018 p≡p. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "PEPIdentity.h"
|
||||
#import "PEPObjCAdapter.h"
|
||||
|
||||
// Commented. See testSyncSession
|
||||
// MARK: - PEPSyncDelegate
|
||||
|
||||
@interface SomeSyncDelegate : NSObject<PEPSyncDelegate>
|
||||
|
||||
- (BOOL)waitUntilSent:(time_t)maxSec;
|
||||
|
||||
@property (nonatomic) bool sendWasCalled;
|
||||
@property (nonatomic, strong) NSCondition *cond;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SomeSyncDelegate
|
||||
|
||||
//- (id)init
|
||||
//{
|
||||
// if (self = [super init]) {
|
||||
// self.sendWasCalled = false;
|
||||
// self.cond = [[NSCondition alloc] init];
|
||||
// }
|
||||
// return self;
|
||||
//}
|
||||
//
|
||||
//- (PEP_STATUS)notifyHandshakeWithSignal:(sync_handshake_signal)signal me:(id)me
|
||||
// partner:(id)partner
|
||||
//{
|
||||
// return PEP_STATUS_OK;
|
||||
//}
|
||||
//
|
||||
//- (PEP_STATUS)sendMessage:(id)msg //never used afaics. Delete?
|
||||
//{
|
||||
// [_cond lock];
|
||||
//
|
||||
// self.sendWasCalled = true;
|
||||
// [_cond signal];
|
||||
// [_cond unlock];
|
||||
//
|
||||
// return PEP_STATUS_OK;
|
||||
//}
|
||||
//
|
||||
//- (PEP_STATUS)fastPolling:(bool)isfast
|
||||
//{
|
||||
// return PEP_STATUS_OK;
|
||||
//}
|
||||
//
|
||||
//- (BOOL)waitUntilSent:(time_t)maxSec
|
||||
//{
|
||||
// bool res;
|
||||
// [_cond lock];
|
||||
// [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:maxSec]];
|
||||
// res = _sendWasCalled;
|
||||
// [_cond unlock];
|
||||
// return res;
|
||||
//}
|
||||
//
|
||||
//@end
|
||||
//
|
||||
//@interface PEPSyncTest : XCTestCase
|
||||
//
|
||||
//@end
|
||||
//
|
||||
//@implementation PEPSyncTest
|
||||
//
|
||||
////BUFF: ?? commented due to: Can't currently work, engine doesn't contain sync.
|
||||
//- (void)testSyncSession
|
||||
//{
|
||||
// PEPSession *session = [PEPSession new];
|
||||
// SomeSyncDelegate *syncDelegate = [[SomeSyncDelegate alloc] init];
|
||||
// [self pEpSetUp];
|
||||
//
|
||||
// // This should attach session just created
|
||||
// [PEPObjCAdapter startSync:syncDelegate];
|
||||
//
|
||||
// PEPIdentity *identMe = [[PEPIdentity alloc]
|
||||
// initWithAddress:@"pep.test.iosgenkey@pep-project.org"
|
||||
// userID:@"Me"
|
||||
// userName:@"pEp Test iOS GenKey"
|
||||
// isOwn:YES];
|
||||
//
|
||||
// [session mySelf:identMe];
|
||||
//
|
||||
// bool res = [syncDelegate waitUntilSent:1];
|
||||
//
|
||||
// // Can't currently work, engine doesn't contain sync.
|
||||
// XCTAssertFalse(res);
|
||||
//
|
||||
// // This should detach session just created
|
||||
// [PEPObjCAdapter stopSync];
|
||||
//
|
||||
// [self pEpCleanUp];
|
||||
//}
|
||||
//}
|
||||
|
||||
@end
|
@ -0,0 +1,21 @@
|
||||
//
|
||||
// PEPTestSyncDelegate.h
|
||||
// pEpObjCAdapter
|
||||
//
|
||||
// Created by Andreas Buff on 18.01.18.
|
||||
// Copyright © 2018 p≡p. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "PEPObjCAdapter.h"
|
||||
|
||||
@interface PEPTestSyncDelegate : NSObject<PEPSyncDelegate>
|
||||
|
||||
- (BOOL)waitUntilSent:(time_t)maxSec;
|
||||
|
||||
@property (nonatomic) bool sendWasCalled;
|
||||
@property (nonatomic, strong) NSCondition *cond;
|
||||
|
||||
@end
|
||||
|
@ -0,0 +1,54 @@
|
||||
//
|
||||
// PEPTestSyncDelegate.m
|
||||
// pEpObjCAdapter
|
||||
//
|
||||
// Created by Andreas Buff on 18.01.18.
|
||||
// Copyright © 2018 p≡p. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PEPTestSyncDelegate.h"
|
||||
|
||||
@implementation PEPTestSyncDelegate
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.sendWasCalled = false;
|
||||
self.cond = [[NSCondition alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (PEP_STATUS)notifyHandshakeWithSignal:(sync_handshake_signal)signal me:(id)me
|
||||
partner:(id)partner
|
||||
{
|
||||
return PEP_STATUS_OK;
|
||||
}
|
||||
|
||||
- (PEP_STATUS)sendMessage:(id)msg
|
||||
{
|
||||
[_cond lock];
|
||||
|
||||
self.sendWasCalled = true;
|
||||
[_cond signal];
|
||||
[_cond unlock];
|
||||
|
||||
return PEP_STATUS_OK;
|
||||
}
|
||||
|
||||
- (PEP_STATUS)fastPolling:(bool)isfast
|
||||
{
|
||||
return PEP_STATUS_OK;
|
||||
}
|
||||
|
||||
- (BOOL)waitUntilSent:(time_t)maxSec
|
||||
{
|
||||
bool res;
|
||||
[_cond lock];
|
||||
[_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:maxSec]];
|
||||
res = _sendWasCalled;
|
||||
[_cond unlock];
|
||||
return res;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,41 @@
|
||||
//
|
||||
// PEPTestUtils.h
|
||||
// pEpObjCAdapter
|
||||
//
|
||||
// Created by Andreas Buff on 17.01.18.
|
||||
// Copyright © 2018 p≡p. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class PEPIdentity;
|
||||
@class PEPInternalSession;
|
||||
@class PEPMessage;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
extern NSString * const ownUserId;
|
||||
|
||||
@interface PEPTestUtils : NSObject
|
||||
|
||||
+ (void)importBundledKey:(NSString *)item;
|
||||
|
||||
+ (NSString *)loadStringFromFileName:(NSString *)fileName;
|
||||
|
||||
+ (NSDictionary *)unarchiveDictionary:(NSString *)fileName;
|
||||
|
||||
+ (PEPMessage * _Nonnull) mailFrom:(PEPIdentity * _Nullable) fromIdent
|
||||
toIdent: (PEPIdentity * _Nullable) toIdent
|
||||
shortMessage:(NSString *)shortMessage
|
||||
longMessage: (NSString *)longMessage
|
||||
outgoing:(BOOL) outgoing;
|
||||
|
||||
+ (void)deleteWorkFilesAfterBackingUpWithBackupName:(NSString * _Nullable)backup;
|
||||
|
||||
+ (void)restoreWorkFilesFromBackupNamed:(NSString *)backup;
|
||||
|
||||
+ (NSArray *)pEpWorkFiles;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,141 @@
|
||||
//
|
||||
// PEPTestUtils.m
|
||||
// pEpObjCAdapter
|
||||
//
|
||||
// Created by Andreas Buff on 17.01.18.
|
||||
// Copyright © 2018 p≡p. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PEPTestUtils.h"
|
||||
|
||||
#import "NSDictionary+Extension.h"
|
||||
#import "PEPIdentity.h"
|
||||
#import "PEPInternalSession.h"
|
||||
#import "PEPMessage.h"
|
||||
#import "PEPSession.h"
|
||||
|
||||
/**
|
||||
For now, safer to use that, until the engine copes with our own.
|
||||
Should mimick the value of PEP_OWN_USERID.
|
||||
*/
|
||||
NSString * const ownUserId = @"pEp_own_userId";
|
||||
|
||||
@implementation PEPTestUtils
|
||||
|
||||
+ (void)importBundledKey:(NSString *)item;
|
||||
{
|
||||
PEPSession *session = [PEPSession new];
|
||||
NSString *txtFileContents = [self loadStringFromFileName:item];
|
||||
[session importKey:txtFileContents];
|
||||
}
|
||||
|
||||
+ (NSString *)loadStringFromFileName:(NSString *)fileName;
|
||||
{
|
||||
NSString *txtFilePath = [[[NSBundle bundleForClass:[self class]] resourcePath]
|
||||
stringByAppendingPathComponent:fileName];
|
||||
NSString *txtFileContents = [NSString stringWithContentsOfFile:txtFilePath
|
||||
encoding:NSUTF8StringEncoding error:NULL];
|
||||
return txtFileContents;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)unarchiveDictionary:(NSString *)fileName
|
||||
{
|
||||
NSString *filePath = [[[NSBundle bundleForClass:[self class]]
|
||||
resourcePath] stringByAppendingPathComponent:fileName];
|
||||
NSMutableData *data = [NSMutableData dataWithContentsOfFile:filePath];
|
||||
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
|
||||
NSDictionary *dict = [unarchiver decodeObject];
|
||||
[unarchiver finishDecoding];
|
||||
return dict;
|
||||
}
|
||||
|
||||
+ (PEPMessage * _Nonnull) mailFrom:(PEPIdentity * _Nullable) fromIdent
|
||||
toIdent: (PEPIdentity * _Nullable) toIdent
|
||||
shortMessage:(NSString *)shortMessage
|
||||
longMessage: (NSString *)longMessage
|
||||
outgoing:(BOOL) outgoing;
|
||||
{
|
||||
PEPMessage *message = [PEPMessage new];
|
||||
message.from = fromIdent;
|
||||
message.to = @[toIdent];
|
||||
message.direction = outgoing ? PEP_dir_outgoing:PEP_dir_incoming;
|
||||
message.shortMessage = shortMessage;
|
||||
message.longMessage = longMessage;
|
||||
return message;
|
||||
}
|
||||
|
||||
+ (NSArray *)pEpWorkFiles;
|
||||
{
|
||||
// Only files whose content is affected by tests.
|
||||
NSString* home = [[[NSProcessInfo processInfo]environment]objectForKey:@"HOME"];
|
||||
NSString* gpgHome = [home stringByAppendingPathComponent:@".gnupg"];
|
||||
return @[[home stringByAppendingPathComponent:@".pEp_management.db"],
|
||||
[home stringByAppendingPathComponent:@".pEp_management.db-shm"],
|
||||
[home stringByAppendingPathComponent:@".pEp_management.db-wal"],
|
||||
[gpgHome stringByAppendingPathComponent:@"pubring.gpg"],
|
||||
[gpgHome stringByAppendingPathComponent:@"secring.gpg"]];
|
||||
|
||||
}
|
||||
|
||||
+ (void)deleteWorkFilesAfterBackingUpWithBackupName:(NSString *_Nullable)backup;
|
||||
{
|
||||
[PEPSession cleanup];
|
||||
|
||||
for (id path in [self pEpWorkFiles]) {
|
||||
[self delFilePath:path backup:backup];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)restoreWorkFilesFromBackupNamed:(NSString *)backup;
|
||||
{
|
||||
if (!backup) {
|
||||
return;
|
||||
}
|
||||
[PEPSession cleanup];
|
||||
|
||||
for (id path in [self pEpWorkFiles]) {
|
||||
[self undelFileWithPath:path backup:backup];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - PRIVATE
|
||||
|
||||
+ (void)delFilePath:(NSString *)path backup:(NSString * _Nullable)bkpsfx;
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSError *error = nil;
|
||||
if ([fileManager fileExistsAtPath:path]) {
|
||||
BOOL success;
|
||||
if (!bkpsfx) {
|
||||
success = [fileManager removeItemAtPath:path error:&error];
|
||||
} else {
|
||||
NSString *toPath = [path stringByAppendingString:bkpsfx];
|
||||
|
||||
if ([fileManager fileExistsAtPath:toPath]) {
|
||||
[fileManager removeItemAtPath:toPath error:&error];
|
||||
}
|
||||
|
||||
success = [fileManager moveItemAtPath:path toPath:toPath error:&error];
|
||||
}
|
||||
if (!success) {
|
||||
NSLog(@"Error: %@", [error localizedDescription]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)undelFileWithPath:(NSString *)path backup:(NSString *)backup;
|
||||
{
|
||||
NSParameterAssert(backup);
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString* bpath = [path stringByAppendingString:backup];
|
||||
BOOL fileExists = [fileManager fileExistsAtPath:bpath];
|
||||
if (fileExists) {
|
||||
NSError *error = nil;
|
||||
BOOL success = [fileManager moveItemAtPath:bpath toPath:path error:&error];
|
||||
if (!success) {
|
||||
NSLog(@"Error: %@", [error localizedDescription]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue