more tests

This commit is contained in:
Kilian Hofmann 2016-04-17 20:21:18 +02:00
parent 97992a66cc
commit ead815ab65
7 changed files with 99 additions and 61 deletions

View File

@ -35,22 +35,6 @@
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "FMC Planner 2Tests/FMC_Planner_2Tests.m"
timestampString = "482591208.671376"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
landmarkName = "-setUp"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
@ -58,11 +42,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "FMC Planner 2/DropboxV2ObjC.m" filePath = "FMC Planner 2/DropboxV2ObjC.m"
timestampString = "482597611.374247" timestampString = "482609979.426219"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "562" startingLineNumber = "571"
endingLineNumber = "562" endingLineNumber = "571"
landmarkName = "-setupDropboxWithHandler:presenter:" landmarkName = "-setupDropboxWithHandler:presenter:"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -74,11 +58,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "FMC Planner 2/DropboxV2ObjC.m" filePath = "FMC Planner 2/DropboxV2ObjC.m"
timestampString = "482597611.374247" timestampString = "482609979.426219"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "568" startingLineNumber = "577"
endingLineNumber = "568" endingLineNumber = "577"
landmarkName = "-setupDropboxWithHandler:presenter:" landmarkName = "-setupDropboxWithHandler:presenter:"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -90,11 +74,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "FMC Planner 2/DropboxV2ObjC.m" filePath = "FMC Planner 2/DropboxV2ObjC.m"
timestampString = "482597611.374247" timestampString = "482609979.426219"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "570" startingLineNumber = "579"
endingLineNumber = "570" endingLineNumber = "579"
landmarkName = "-setupDropboxWithHandler:presenter:" landmarkName = "-setupDropboxWithHandler:presenter:"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -106,11 +90,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "FMC Planner 2/DropboxV2ObjC.m" filePath = "FMC Planner 2/DropboxV2ObjC.m"
timestampString = "482597611.374247" timestampString = "482609979.426219"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "589" startingLineNumber = "598"
endingLineNumber = "589" endingLineNumber = "598"
landmarkName = "-setupDropboxWithHandler:presenter:" landmarkName = "-setupDropboxWithHandler:presenter:"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -122,11 +106,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "FMC Planner 2/DropboxV2ObjC.m" filePath = "FMC Planner 2/DropboxV2ObjC.m"
timestampString = "482597611.374247" timestampString = "482609979.426219"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "608" startingLineNumber = "617"
endingLineNumber = "608" endingLineNumber = "617"
landmarkName = "-setupDropboxWithHandler:presenter:" landmarkName = "-setupDropboxWithHandler:presenter:"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>
@ -138,11 +122,11 @@
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "FMC Planner 2/DropboxV2ObjC.m" filePath = "FMC Planner 2/DropboxV2ObjC.m"
timestampString = "482597611.374247" timestampString = "482609979.426219"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "627" startingLineNumber = "636"
endingLineNumber = "627" endingLineNumber = "636"
landmarkName = "-setupDropboxWithHandler:presenter:" landmarkName = "-setupDropboxWithHandler:presenter:"
landmarkType = "5"> landmarkType = "5">
</BreakpointContent> </BreakpointContent>

View File

@ -32,12 +32,12 @@
- (void)downloadFromDropbox:(NSArray *)files - (void)downloadFromDropbox:(NSArray *)files
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
completion:(void (^)(void))handler; completion:(void (^)(BOOL success))handler;
- (void)uploadToDropbox:(NSArray *)files - (void)uploadToDropbox:(NSArray *)files
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
completion:(void (^)(void))handler; completion:(void (^)(BOOL success))handler;
- (void)contentsOfPath:(NSString *)path - (void)contentsOfPath:(NSString *)path
completion:(void (^)(NSArray *data))handler completion:(void (^)(NSArray *data, BOOL success))handler
presenter:(UIViewController *)presenter; presenter:(UIViewController *)presenter;
- (void)createFolderAtPath:(NSString *)path - (void)createFolderAtPath:(NSString *)path
presenter:(UIViewController *)presenter; presenter:(UIViewController *)presenter;

View File

@ -21,6 +21,11 @@
protocol:@"HTTP" protocol:@"HTTP"
realm:nil realm:nil
authenticationMethod:@"OAuth2"]; authenticationMethod:@"OAuth2"];
NSDictionary *credentials =
[[NSURLCredentialStorage sharedCredentialStorage]
credentialsForProtectionSpace:self.kDropboxProtectionSpace];
NSURLCredential *credential = [credentials.objectEnumerator nextObject];
self.token = credential.password;
return self; return self;
} }
@ -156,7 +161,7 @@
* @param completion executed after completion * @param completion executed after completion
*/ */
- (void)contentsOfPath:(NSString *)path - (void)contentsOfPath:(NSString *)path
completion:(void (^)(NSArray *data))handler completion:(void (^)(NSArray *data, BOOL success))handler
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
{ {
@ -250,9 +255,10 @@
.topViewController]; .topViewController];
} }
}]; }];
handler(nil, NO);
} }
else { else {
handler(data2); handler(data2, YES);
} }
} }
} }
@ -265,6 +271,7 @@
.topViewController]; .topViewController];
}]; }];
handler(nil, NO);
} }
}]; }];
} }
@ -275,7 +282,7 @@
*/ */
- (void)downloadFromDropbox:(NSArray *)files - (void)downloadFromDropbox:(NSArray *)files
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
completion:(void (^)(void))handler completion:(void (^)(BOOL success))handler
{ {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
request.URL = [NSURL request.URL = [NSURL
@ -320,6 +327,7 @@
valueForKey:@"error_summary"] == nil) { valueForKey:@"error_summary"] == nil) {
[data writeToFile:[SharedDeclerations savePathForFile:string] [data writeToFile:[SharedDeclerations savePathForFile:string]
atomically:YES]; atomically:YES];
handler(YES);
} }
else { else {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
@ -361,6 +369,7 @@
.topViewController]; .topViewController];
} }
}]; }];
handler(NO);
} }
} }
else if (error != nil) { else if (error != nil) {
@ -370,11 +379,10 @@
presentErrorAlert:error presentErrorAlert:error
presenter:presenter.navigationController presenter:presenter.navigationController
.topViewController]; .topViewController];
}]; }];
handler(NO);
} }
} }
handler();
} }
/** /**
@ -383,7 +391,7 @@
*/ */
- (void)uploadToDropbox:(NSArray *)files - (void)uploadToDropbox:(NSArray *)files
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
completion:(void (^)(void))handler completion:(void (^)(BOOL success))handler
{ {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
request.URL = request.URL =
@ -434,6 +442,7 @@
.topViewController]; .topViewController];
}]; }];
handler(NO);
} }
if ([[NSJSONSerialization JSONObjectWithData:data options:0 error:nil] if ([[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]
valueForKey:@"error_summary"] != nil) { valueForKey:@"error_summary"] != nil) {
@ -475,9 +484,9 @@
.topViewController]; .topViewController];
} }
}]; }];
handler(NO);
} }
} }
handler();
} }
@ -566,7 +575,7 @@
[queue addOperationWithBlock:^{ [queue addOperationWithBlock:^{
// Exports (PMDG format) // Exports (PMDG format)
[self contentsOfPath:nil [self contentsOfPath:nil
completion:^(NSArray *data) { completion:^(NSArray *data, BOOL success) {
BOOL exports = false; BOOL exports = false;
for (NSDictionary *dict in data) { for (NSDictionary *dict in data) {
if ([[dict valueForKey:@"name"] if ([[dict valueForKey:@"name"]
@ -585,7 +594,7 @@
presenter:presenter]; presenter:presenter];
// NavData (3 files from QW Navigraph data // NavData (3 files from QW Navigraph data
[self contentsOfPath:nil [self contentsOfPath:nil
completion:^(NSArray *data) { completion:^(NSArray *data, BOOL success) {
BOOL exports = false; BOOL exports = false;
for (NSDictionary *dict in data) { for (NSDictionary *dict in data) {
if ([[dict valueForKey:@"name"] if ([[dict valueForKey:@"name"]
@ -604,7 +613,7 @@
presenter:presenter.navigationController.topViewController]; presenter:presenter.navigationController.topViewController];
// Backups of Saves // Backups of Saves
[self contentsOfPath:nil [self contentsOfPath:nil
completion:^(NSArray *data) { completion:^(NSArray *data, BOOL success) {
BOOL exports = false; BOOL exports = false;
for (NSDictionary *dict in data) { for (NSDictionary *dict in data) {
if ([[dict valueForKey:@"name"] if ([[dict valueForKey:@"name"]
@ -623,7 +632,7 @@
presenter:presenter.navigationController.topViewController]; presenter:presenter.navigationController.topViewController];
// Old saves (FMC Planner + (or X?)) // Old saves (FMC Planner + (or X?))
[self contentsOfPath:nil [self contentsOfPath:nil
completion:^(NSArray *data) { completion:^(NSArray *data, BOOL success) {
BOOL exports = false; BOOL exports = false;
for (NSDictionary *dict in data) { for (NSDictionary *dict in data) {
if ([[dict valueForKey:@"name"] if ([[dict valueForKey:@"name"]

View File

@ -41,7 +41,7 @@
if ([self.title isEqualToString:@"Download"]) { if ([self.title isEqualToString:@"Download"]) {
[dbClient [dbClient
contentsOfPath:@"SAVES" contentsOfPath:@"SAVES"
completion:^(NSArray *data) { completion:^(NSArray *data, BOOL success) {
NSMutableArray *temp = [[NSMutableArray alloc] init]; NSMutableArray *temp = [[NSMutableArray alloc] init];
if (data != nil) { if (data != nil) {
for (NSDictionary *dict in data) { for (NSDictionary *dict in data) {
@ -184,7 +184,7 @@
[queue addOperationWithBlock:^{ [queue addOperationWithBlock:^{
[dbClient downloadFromDropbox:_markList [dbClient downloadFromDropbox:_markList
presenter:self presenter:self
completion:^{ completion:^(BOOL success) {
[[NSOperationQueue mainQueue] [[NSOperationQueue mainQueue]
addOperationWithBlock:^{ addOperationWithBlock:^{
_sm.dbDownload.enabled = YES; _sm.dbDownload.enabled = YES;
@ -204,7 +204,7 @@
[dbClient [dbClient
uploadToDropbox:_markList uploadToDropbox:_markList
presenter:self presenter:self
completion:^{ completion:^(BOOL success) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
_sm.dbUpload.enabled = YES; _sm.dbUpload.enabled = YES;
_sm.dbUpload.alpha = 1.0; _sm.dbUpload.alpha = 1.0;

View File

@ -29,11 +29,6 @@
// Override point for customization after application launch. // Override point for customization after application launch.
_dbClient = [[DropboxV2ObjC alloc] init]; _dbClient = [[DropboxV2ObjC alloc] init];
((AppDelegate *)[UIApplication sharedApplication].delegate).main = self; ((AppDelegate *)[UIApplication sharedApplication].delegate).main = self;
NSDictionary *credentials =
[[NSURLCredentialStorage sharedCredentialStorage]
credentialsForProtectionSpace:_dbClient.kDropboxProtectionSpace];
NSURLCredential *credential = [credentials.objectEnumerator nextObject];
_dbClient.token = credential.password;
// Reset if user changed it // Reset if user changed it
[_dbClient setupDropboxWithHandler:^{ [_dbClient setupDropboxWithHandler:^{
} }

View File

@ -121,7 +121,7 @@
[queue addOperationWithBlock:^{ [queue addOperationWithBlock:^{
[dbClient [dbClient
contentsOfPath:@"NAVDATA" contentsOfPath:@"NAVDATA"
completion:^(NSArray *files) { completion:^(NSArray *files, BOOL success) {
if (files != nil) { if (files != nil) {
NSMutableArray *dlList = [[NSMutableArray alloc] init]; NSMutableArray *dlList = [[NSMutableArray alloc] init];
for (NSDictionary *file in files) { for (NSDictionary *file in files) {
@ -132,7 +132,7 @@
[dbClient [dbClient
downloadFromDropbox:dlList downloadFromDropbox:dlList
presenter:self presenter:self
completion:^{ completion:^(BOOL success) {
[[NSOperationQueue mainQueue] [[NSOperationQueue mainQueue]
addOperationWithBlock:^{ addOperationWithBlock:^{
_main.navDataActive = false; _main.navDataActive = false;

View File

@ -6,11 +6,14 @@
// Copyright © 2016 Kilian Hofmann. All rights reserved. // Copyright © 2016 Kilian Hofmann. All rights reserved.
// //
#import "DropboxV2ObjC.h"
#import "NavDataParser.h" #import "NavDataParser.h"
#import "SharedDeclerations.h"
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
@interface FMC_Planner_2Tests : XCTestCase { @interface FMC_Planner_2Tests : XCTestCase {
NavDataParser *parser; NavDataParser *parser;
DropboxV2ObjC *dbClient;
} }
@end @end
@ -22,9 +25,8 @@
[super setUp]; [super setUp];
// Put setup code here. This method is called before the invocation of each // Put setup code here. This method is called before the invocation of each
// test method in the class. // test method in the class.
if (parser == nil) { parser = [[NavDataParser alloc] init];
parser = [[NavDataParser alloc] init]; dbClient = [[DropboxV2ObjC alloc] init];
}
} }
- (void)tearDown - (void)tearDown
@ -47,6 +49,8 @@
{ {
XCTAssertTrue([parser findAirway:@"T104"].count > 0); XCTAssertTrue([parser findAirway:@"T104"].count > 0);
XCTAssertTrue([parser findAirway:@"T104T"].count == 0); XCTAssertTrue([parser findAirway:@"T104T"].count == 0);
XCTAssertTrue(
[[parser findAirway:@"DIRECT"].firstObject isEqualToString:@"OK"]);
} }
- (void)testWaypointOnAirway - (void)testWaypointOnAirway
@ -68,4 +72,50 @@
withStart:@"DKB"] == nil); withStart:@"DKB"] == nil);
} }
- (void)testPathContent
{
[dbClient contentsOfPath:nil
completion:^(NSArray *data, BOOL success) {
if (success) {
NSMutableArray *temp = [[NSMutableArray alloc] init];
for (NSDictionary *dict in data) {
[temp addObject:[dict valueForKey:@"name"]];
}
XCTAssertTrue([temp containsObject:@"TEST.txt"]);
}
}
presenter:nil];
}
- (void)testDownload
{
if ([[NSFileManager defaultManager]
fileExistsAtPath:[SharedDeclerations
savePathForFile:@"TEST.txt"]]) {
[[NSFileManager defaultManager]
removeItemAtPath:[SharedDeclerations savePathForFile:@"TEST.txt"]
error:nil];
}
[dbClient downloadFromDropbox:@[ @"TEST.txt" ]
presenter:nil
completion:^(BOOL success) {
if (success) {
XCTAssertTrue([[NSFileManager defaultManager]
fileExistsAtPath:
[SharedDeclerations
savePathForFile:@"TEST.txt"]]);
}
}];
}
- (void)testUpload
{
[dbClient
uploadToDropbox:@[ [SharedDeclerations savePathForFile:@"TEST.txt"] ]
presenter:nil
completion:^(BOOL success) {
XCTAssertTrue(success);
}];
}
@end @end