Swiftgram/Support/HockeySDKTests/BITKeychainUtilsTests.m
Andreas Linde 22047b856c Fixes for getting test coverage working again
Xcode 5 does not create .gcda files due to a bug. The workaround used in here has been suggested in the devforums: https://devforums.apple.com/thread/199643?start=0&tstart=0
2013-09-23 17:17:41 +02:00

89 lines
3.0 KiB
Objective-C

//
// BITKeychainHelperTests.m
// HockeySDK
//
// Created by Stephan Diederich on 23.09.13.
// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
#define HC_SHORTHAND
#import <OCHamcrestIOS/OCHamcrestIOS.h>
#define MOCKITO_SHORTHAND
#import <OCMockitoIOS/OCMockitoIOS.h>
#import "HockeySDK.h"
#import "BITKeychainUtils.h"
@interface BITKeychainUtilsTests : SenTestCase {
}
@end
@implementation BITKeychainUtilsTests
- (void)setUp {
[super setUp];
// Set-up code here.
}
- (void)tearDown {
// Tear-down code here.
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wimplicit"
__gcov_flush();
# pragma clang diagnostic pop
[super tearDown];
}
- (void)testThatBITKeychainHelperStoresAndRetrievesPassword {
[BITKeychainUtils deleteItemForUsername:@"Peter" andServiceName:@"Test" error:nil];
BOOL success = [BITKeychainUtils storeUsername:@"Peter"
andPassword:@"Pan"
forServiceName:@"Test"
updateExisting:YES
error:nil];
assertThatBool(success, equalToBool(YES));
NSString *pass = [BITKeychainUtils getPasswordForUsername:@"Peter"
andServiceName:@"Test"
error:NULL];
assertThat(pass, equalTo(@"Pan"));
}
- (void)testThatBITKeychainHelperStoresAndRetrievesPasswordThisDeviceOnly {
[BITKeychainUtils deleteItemForUsername:@"Peter" andServiceName:@"Test" error:nil];
BOOL success = [BITKeychainUtils storeUsername:@"Peter"
andPassword:@"PanThisDeviceOnly"
forServiceName:@"Test"
updateExisting:YES
accessibility:kSecAttrAccessibleWhenUnlockedThisDeviceOnly
error:nil];
assertThatBool(success, equalToBool(YES));
NSString *pass = [BITKeychainUtils getPasswordForUsername:@"Peter"
andServiceName:@"Test"
error:NULL];
assertThat(pass, equalTo(@"PanThisDeviceOnly"));
}
- (void)testThatBITKeychainHelperRemovesAStoredPassword {
[BITKeychainUtils deleteItemForUsername:@"Peter" andServiceName:@"Test" error:nil];
[BITKeychainUtils storeUsername:@"Peter"
andPassword:@"Pan"
forServiceName:@"Test"
updateExisting:YES
error:nil];
BOOL success = [BITKeychainUtils deleteItemForUsername:@"Peter" andServiceName:@"Test" error:nil];
assertThatBool(success, equalToBool(YES));
NSString *pass = [BITKeychainUtils getPasswordForUsername:@"Peter"
andServiceName:@"Test"
error:NULL];
assertThat(pass, equalTo(nil));
}
@end