Skip to content

Commit

Permalink
Convert test to XCTest framework
Browse files Browse the repository at this point in the history
Deleted obsolete files
Updated copyright dates
  • Loading branch information
glebd committed Jul 5, 2015
1 parent 04742c2 commit d1db7dc
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 243 deletions.
2 changes: 1 addition & 1 deletion objc/CFobLicGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Gleb Dolgich on 09/02/2009.
// Follow me on Twitter @glebd.
// Copyright (C) 2009-2012 PixelEspresso. All rights reserved.
// Copyright (C) 2009-2015 PixelEspresso. All rights reserved.
// BSD License
//

Expand Down
2 changes: 1 addition & 1 deletion objc/CFobLicGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Gleb Dolgich on 09/02/2009.
// Follow me on Twitter @glebd.
// Copyright (C) 2009-2012 PixelEspresso. All rights reserved.
// Copyright (C) 2009-2015 PixelEspresso. All rights reserved.
// BSD License
//

Expand Down
2 changes: 1 addition & 1 deletion objc/CFobLicVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Gleb Dolgich on 06/02/2009.
// Follow me on Twitter @glebd.
// Copyright 2009-2012 PixelEspresso. All rights reserved.
// Copyright 2009-2015 PixelEspresso. All rights reserved.
// Licensed under BSD license.
//

Expand Down
2 changes: 1 addition & 1 deletion objc/CFobLicVerifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Gleb Dolgich on 06/02/2009.
// Follow me on Twitter @glebd.
// Copyright 2009-2012 PixelEspresso. All rights reserved.
// Copyright 2009-2015 PixelEspresso. All rights reserved.
// Licensed under BSD license.
//

Expand Down
2 changes: 1 addition & 1 deletion objc/CocoaFob-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.pixelespresso.cocoafob</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
Expand Down
2 changes: 1 addition & 1 deletion objc/CocoaFobARC-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.pixelespresso.cocoafob</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
Expand Down
7 changes: 0 additions & 7 deletions objc/CocoaFobTests/CocoaFobTests-Prefix.pch

This file was deleted.

13 changes: 0 additions & 13 deletions objc/CocoaFobTests/CocoaFobTests.h

This file was deleted.

132 changes: 73 additions & 59 deletions objc/CocoaFobTests/CocoaFobTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,111 @@
// CocoaFobTests.m
// CocoaFobTests
//
// Created by Gleb Dolgich on 01/09/2012.
// Twitter: @glebd
// Website: http://pixelespressoapps.com
//
// License: BSD
// Created by Gleb Dolgich on 05/07/2015.
//
//

#import "CocoaFobTests.h"
#import <XCTest/XCTest.h>

#import "CFobLicGenerator.h"
#import "CFobLicVerifier.h"

@interface CocoaFobTests ()
@interface CocoaFobTests : XCTestCase
@property (nonatomic, strong) CFobLicGenerator *generator;
@property (nonatomic, strong) CFobLicVerifier *verifier;
@property (nonatomic, strong) NSString *pubKey;
@end

@implementation CocoaFobTests

static NSString *privKey = @"-----BEGIN DSA PRIVATE KEY-----\n"
"MIH5AgEAAkEA8wm04e0QcQRoAVJWWnUw/4rQEKbLKjujJu6oyEv7Y2oT3itY5pbO\n"
"bgYCHEu9FBizqq7apsWYSF3YXiRjKlg10wIVALfs9eVL10PhoV6zczFpi3C7FzWN\n"
"AkBaPhALEKlgIltHsumHdTSBqaVoR1/bmlgw/BCC13IAsW40nkFNsK1OVwjo2ocn\n"
"3MwW4Rdq6uLm3DlENRZ5bYrTAkEA4reDYZKAl1vx+8EIMP/+2Z7ekydHfX0sTMDg\n"
"kxhtRm6qtcywg01X847Y9ySgNepqleD+Ka2Wbucj1pOry8MoDQIVAIXgAB9GBLh4\n"
"keUwLHBtpClnD5E8\n"
"-----END DSA PRIVATE KEY-----\n";
static NSString *privKey =
@"-----BEGIN DSA PRIVATE KEY-----\n"
"MIH5AgEAAkEA8wm04e0QcQRoAVJWWnUw/4rQEKbLKjujJu6oyEv7Y2oT3itY5pbO\n"
"bgYCHEu9FBizqq7apsWYSF3YXiRjKlg10wIVALfs9eVL10PhoV6zczFpi3C7FzWN\n"
"AkBaPhALEKlgIltHsumHdTSBqaVoR1/bmlgw/BCC13IAsW40nkFNsK1OVwjo2ocn\n"
"3MwW4Rdq6uLm3DlENRZ5bYrTAkEA4reDYZKAl1vx+8EIMP/+2Z7ekydHfX0sTMDg\n"
"kxhtRm6qtcywg01X847Y9ySgNepqleD+Ka2Wbucj1pOry8MoDQIVAIXgAB9GBLh4\n"
"keUwLHBtpClnD5E8\n"
"-----END DSA PRIVATE KEY-----\n";

static NSString *regName = @"decloner|Joe Bloggs";

- (void)setUp
{
[super setUp];

self.generator = [[CFobLicGenerator alloc] init];

NSError *err = nil;
if (![self.generator setPrivateKey:privKey error:&err]) {
STFail(@"Could not set up private key: %@", err);
}

// Modelled after AquaticPrime's method of splitting public key to obfuscate it.
// It is probably better if you invent your own splitting pattern. Go wild.
NSMutableString *pubKeyBase64 = [NSMutableString string];
[pubKeyBase64 appendString:@"MIHxMIGoBgcqhkj"];
[pubKeyBase64 appendString:@"OOAQBMIGcAkEA8wm04e0QcQRoAVJW"];
[pubKeyBase64 appendString:@"WnUw/4rQEKbLKjujJu6o\n"];
[pubKeyBase64 appendString:@"yE"];
[pubKeyBase64 appendString:@"v7Y2oT3itY5pbObgYCHEu9FBizqq7apsWYSF3YX"];
[pubKeyBase64 appendString:@"iRjKlg10wIVALfs9eVL10Ph\n"];
[pubKeyBase64 appendString:@"oV6zczFpi3C7FzWNAkBaPhALEKlgIltHsumHdTSBqaVoR1/bmlgw"];
[pubKeyBase64 appendString:@"/BCC13IAsW40\n"];
[pubKeyBase64 appendString:@"nkFNsK1OVwjo2ocn"];
[pubKeyBase64 appendString:@"3M"];
[pubKeyBase64 appendString:@"wW"];
[pubKeyBase64 appendString:@"4Rdq6uLm3DlENRZ5bYrTA"];
[pubKeyBase64 appendString:@"0QAAkEA4reDYZKAl1vx+8EI\n"];
[pubKeyBase64 appendString:@"MP/+"];
[pubKeyBase64 appendString:@"2Z7ekydHfX0sTMDgkxhtRm6qtcywg01X847Y9ySgNepqleD+Ka2Wbucj1pOr\n"];
[pubKeyBase64 appendString:@"y8MoDQ==\n"];
[super setUp];

self.generator = [[CFobLicGenerator alloc] init];
self.verifier = [[CFobLicVerifier alloc] init];

// Modelled after AquaticPrime's method of splitting public key to obfuscate it.
// It is probably better if you invent your own splitting pattern. Go wild.
NSMutableString *pubKeyBase64 = [NSMutableString string];
[pubKeyBase64 appendString:@"MIHxMIGoBgcqhkj"];
[pubKeyBase64 appendString:@"OOAQBMIGcAkEA8wm04e0QcQRoAVJW"];
[pubKeyBase64 appendString:@"WnUw/4rQEKbLKjujJu6o\n"];
[pubKeyBase64 appendString:@"yE"];
[pubKeyBase64 appendString:@"v7Y2oT3itY5pbObgYCHEu9FBizqq7apsWYSF3YX"];
[pubKeyBase64 appendString:@"iRjKlg10wIVALfs9eVL10Ph\n"];
[pubKeyBase64 appendString:@"oV6zczFpi3C7FzWNAkBaPhALEKlgIltHsumHdTSBqaVoR1/bmlgw"];
[pubKeyBase64 appendString:@"/BCC13IAsW40\n"];
[pubKeyBase64 appendString:@"nkFNsK1OVwjo2ocn"];
[pubKeyBase64 appendString:@"3M"];
[pubKeyBase64 appendString:@"wW"];
[pubKeyBase64 appendString:@"4Rdq6uLm3DlENRZ5bYrTA"];
[pubKeyBase64 appendString:@"0QAAkEA4reDYZKAl1vx+8EI\n"];
[pubKeyBase64 appendString:@"MP/+"];
[pubKeyBase64 appendString:@"2Z7ekydHfX0sTMDgkxhtRm6qtcywg01X847Y9ySgNepqleD+Ka2Wbucj1pOr\n"];
[pubKeyBase64 appendString:@"y8MoDQ==\n"];

self.pubKey = [CFobLicVerifier completePublicKeyPEM:pubKeyBase64];
}

self.pubKey = [CFobLicVerifier completePublicKeyPEM:pubKeyBase64];
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

self.verifier = [[CFobLicVerifier alloc] init];
if (![self.verifier setPublicKey:self.pubKey error:&err]) {
STFail(@"Could not set public key on verifier %@", err);
}
- (void)testSetPrivateKey {
NSError *error = nil;
BOOL result = [self.generator setPrivateKey:privKey error:&error];
XCTAssertTrue(result, "Must be able to set private key in license generator");
}

- (void)tearDown
{
[super tearDown];
- (void)testSetPublicKey {
NSError *error = nil;
BOOL result = [self.verifier setPublicKey:self.pubKey error:&error];
XCTAssertTrue(result, "Must be able to set public key in license verifier");
}

- (void)testGenerateAndVerify
{
NSError *err = nil;
NSString *regCode = [self.generator generateRegCodeForName:regName error:&err];
STAssertNotNil(regCode, @"Could not generate serial number: %@", err);
- (void)testGenerate {
NSError *error = nil;
BOOL result = [self.generator setPrivateKey:privKey error:&error];
XCTAssertTrue(result, "Must be able to set private key in license generator");
NSString *regCode = [self.generator generateRegCodeForName:regName error:&error];
XCTAssertNotNil(regCode, "Generated registration code must not be nil");
}

BOOL result = [self.verifier verifyRegCode:regCode forName:regName error:&err];
STAssertTrue(result, @"Registration code could not be verified: %@", err);
- (void)testVerify {
NSError *error = nil;
BOOL result = [self.verifier setPublicKey:self.pubKey error:&error];
XCTAssertTrue(result, "Must be able to set public key in license verifier");
result = [self.verifier verifyRegCode:@"GAWQE-F9AQP-XJCCL-PAFAX-NU5XX-EUG6W-KLT3H-VTEB9-A9KHJ-8DZ5R-DL74G-TU4BN-7ATPY-3N4XB-V4V27-Q" forName:@"Joe Bloggs" error:&error];
XCTAssertTrue(result, "Must be able to verify pre-generated registration code");
}

- (void)testVerify
{
NSError *err = nil;
BOOL result = [self.verifier verifyRegCode:@"GAWQE-F9AQP-XJCCL-PAFAX-NU5XX-EUG6W-KLT3H-VTEB9-A9KHJ-8DZ5R-DL74G-TU4BN-7ATPY-3N4XB-V4V27-Q" forName:@"Joe Bloggs" error:&err];
STAssertTrue(result, @"Registration code could not be verified: %@", err);
- (void)testGenerateAndVerify {
NSError *error = nil;
BOOL result = [self.generator setPrivateKey:privKey error:&error];
XCTAssertTrue(result, "Must be able to set private key in license generator");
NSString *regCode = [self.generator generateRegCodeForName:regName error:&error];
result = [self.verifier setPublicKey:self.pubKey error:&error];
XCTAssertTrue(result, "Must be able to set public key in license verifier");
result = [self.verifier verifyRegCode:regCode forName:regName error:&error];
XCTAssertTrue(result, "Must be able to generate and verify registration code");
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.pixelespresso.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
Expand Down
2 changes: 0 additions & 2 deletions objc/CocoaFobTests/en.lproj/InfoPlist.strings

This file was deleted.

Loading

0 comments on commit d1db7dc

Please sign in to comment.