Keep unit tests with their class files

Moved from Signal-iOS and updated to use standard XCTest macros vs. our
test-util's

// FREEBIE
This commit is contained in:
Michael Kirk 2017-03-19 16:09:14 -04:00
parent 478b5b247a
commit d3ecbba0e8
4 changed files with 216 additions and 46 deletions

View file

@ -118,7 +118,7 @@
C0DC1A83C39CBC09FB2405A3 /* libPods-TSKitiOSTestAppTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-TSKitiOSTestAppTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
D2AECE721DE8C3360068CE15 /* ContactSortingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ContactSortingTest.m; path = ../../../tests/Contacts/ContactSortingTest.m; sourceTree = "<group>"; };
D3737F7A041D7147015C02C2 /* Pods-TSKitiOSTestAppTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TSKitiOSTestAppTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TSKitiOSTestAppTests/Pods-TSKitiOSTestAppTests.release.xcconfig"; sourceTree = "<group>"; };
E95668311E0964F9002418B1 /* PhoneNumberUtilTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PhoneNumberUtilTest.m; sourceTree = "<group>"; };
E95668311E0964F9002418B1 /* PhoneNumberUtilTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PhoneNumberUtilTest.m; path = ../../../tests/Contacts/PhoneNumberUtilTest.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -194,7 +194,6 @@
45458B721CC342B600A02153 /* Util */ = {
isa = PBXGroup;
children = (
E95668311E0964F9002418B1 /* PhoneNumberUtilTest.m */,
45458B731CC342B600A02153 /* CryptographyTests.m */,
45458B741CC342B600A02153 /* MessagePaddingTests.m */,
);
@ -213,12 +212,13 @@
459850BF1D22C6C4006FFEDB /* Contacts */ = {
isa = PBXGroup;
children = (
459850C01D22C6F2006FFEDB /* PhoneNumberTest.m */,
452EE6CE1D4A754C00E934BA /* TSThreadTest.m */,
D2AECE721DE8C3360068CE15 /* ContactSortingTest.m */,
45B700961D9841E400269FFD /* OWSDisappearingMessagesConfigurationTest.m */,
459850C01D22C6F2006FFEDB /* PhoneNumberTest.m */,
E95668311E0964F9002418B1 /* PhoneNumberUtilTest.m */,
452EE6CE1D4A754C00E934BA /* TSThreadTest.m */,
4516E3E71DD153CC00DC4206 /* TSGroupThreadTest.m */,
4516E3E91DD1542300DC4206 /* TSContactThreadTest.m */,
D2AECE721DE8C3360068CE15 /* ContactSortingTest.m */,
);
name = Contacts;
sourceTree = "<group>";

View file

@ -1,9 +1,5 @@
//
// PhoneNumberTest.m
// Signal
//
// Created by Michael Kirk on 6/28/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <XCTest/XCTest.h>
@ -15,6 +11,13 @@
@implementation PhoneNumberTest
-(void)testE164 {
XCTAssertEqualObjects(@"+19025555555", [[PhoneNumber tryParsePhoneNumberFromText:@"+1 (902) 555-5555" fromRegion:@"US"] toE164]);
XCTAssertEqualObjects(@"+19025555555", [[PhoneNumber tryParsePhoneNumberFromText:@"1 (902) 555-5555" fromRegion:@"US"] toE164]);
XCTAssertEqualObjects(@"+19025555555", [[PhoneNumber tryParsePhoneNumberFromText:@"1-902-555-5555" fromRegion:@"US"] toE164]);
XCTAssertEqualObjects(@"+19025555555", [[PhoneNumber tryParsePhoneNumberFromText:@"1-902--5555" fromRegion:@"US"] toE164]);
}
- (void)testTryParsePhoneNumberFromUserSpecifiedTextAssumesLocalRegion {
PhoneNumber *actual = [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:@"3235551234"];
XCTAssertEqualObjects(@"+13235551234", [actual toE164]);

View file

@ -0,0 +1,203 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "PhoneNumberUtil.h"
#import <XCTest/XCTest.h>
@interface PhoneNumberUtilTest : XCTestCase
@end
@implementation PhoneNumberUtilTest
- (void)testQueryMatching
{
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"big dave"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"dave big"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"dave"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"big"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"big "]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@" big "]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"dav"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"bi dav"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave"
matchesQuery:@"big big big big big big big big big big dave dave dave dave dave"]);
XCTAssertFalse([PhoneNumberUtil name:@"big dave" matchesQuery:@"ave"]);
XCTAssertFalse([PhoneNumberUtil name:@"big dave" matchesQuery:@"dare"]);
XCTAssertFalse([PhoneNumberUtil name:@"big dave" matchesQuery:@"mike"]);
XCTAssertFalse([PhoneNumberUtil name:@"big dave" matchesQuery:@"mike"]);
XCTAssertFalse([PhoneNumberUtil name:@"dave" matchesQuery:@"big"]);
}
- (void)testTranslateCursorPosition
{
XCTAssertThrows([PhoneNumberUtil translateCursorPosition:0 from:nil to:@"" stickingRightward:true]);
XCTAssertThrows([PhoneNumberUtil translateCursorPosition:0 from:@"" to:nil stickingRightward:true]);
XCTAssertThrows([PhoneNumberUtil translateCursorPosition:1 from:@"" to:@"" stickingRightward:true]);
XCTAssertEqual(0, [PhoneNumberUtil translateCursorPosition:0 from:@"" to:@"" stickingRightward:true]);
XCTAssertEqual(0, [PhoneNumberUtil translateCursorPosition:0 from:@"12" to:@"1" stickingRightward:true]);
XCTAssertEqual(1, [PhoneNumberUtil translateCursorPosition:1 from:@"12" to:@"1" stickingRightward:true]);
XCTAssertEqual(1, [PhoneNumberUtil translateCursorPosition:2 from:@"12" to:@"1" stickingRightward:true]);
XCTAssertEqual(0, [PhoneNumberUtil translateCursorPosition:0 from:@"1" to:@"12" stickingRightward:false]);
XCTAssertEqual(0, [PhoneNumberUtil translateCursorPosition:0 from:@"1" to:@"12" stickingRightward:true]);
XCTAssertEqual(1, [PhoneNumberUtil translateCursorPosition:1 from:@"1" to:@"12" stickingRightward:false]);
XCTAssertEqual(2, [PhoneNumberUtil translateCursorPosition:1 from:@"1" to:@"12" stickingRightward:true]);
XCTAssertEqual(0, [PhoneNumberUtil translateCursorPosition:0 from:@"12" to:@"132" stickingRightward:false]);
XCTAssertEqual(0, [PhoneNumberUtil translateCursorPosition:0 from:@"12" to:@"132" stickingRightward:true]);
XCTAssertEqual(1, [PhoneNumberUtil translateCursorPosition:1 from:@"12" to:@"132" stickingRightward:false]);
XCTAssertEqual(2, [PhoneNumberUtil translateCursorPosition:1 from:@"12" to:@"132" stickingRightward:true]);
XCTAssertEqual(3, [PhoneNumberUtil translateCursorPosition:2 from:@"12" to:@"132" stickingRightward:false]);
XCTAssertEqual(3, [PhoneNumberUtil translateCursorPosition:2 from:@"12" to:@"132" stickingRightward:true]);
XCTAssertEqual(0,
[PhoneNumberUtil translateCursorPosition:0 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(1,
[PhoneNumberUtil translateCursorPosition:1 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(2,
[PhoneNumberUtil translateCursorPosition:2 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(3,
[PhoneNumberUtil translateCursorPosition:3 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(3,
[PhoneNumberUtil translateCursorPosition:4 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(3,
[PhoneNumberUtil translateCursorPosition:5 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(6,
[PhoneNumberUtil translateCursorPosition:6 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(7,
[PhoneNumberUtil translateCursorPosition:7 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(8,
[PhoneNumberUtil translateCursorPosition:8 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(8,
[PhoneNumberUtil translateCursorPosition:9 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:true]);
XCTAssertEqual(0,
[PhoneNumberUtil translateCursorPosition:0 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(1,
[PhoneNumberUtil translateCursorPosition:1 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(2,
[PhoneNumberUtil translateCursorPosition:2 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(3,
[PhoneNumberUtil translateCursorPosition:3 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(3,
[PhoneNumberUtil translateCursorPosition:4 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(3,
[PhoneNumberUtil translateCursorPosition:5 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(4,
[PhoneNumberUtil translateCursorPosition:6 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(7,
[PhoneNumberUtil translateCursorPosition:7 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(8,
[PhoneNumberUtil translateCursorPosition:8 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(8,
[PhoneNumberUtil translateCursorPosition:9 from:@"(55) 123-4567" to:@"(551) 234-567" stickingRightward:false]);
XCTAssertEqual(0,
[PhoneNumberUtil translateCursorPosition:0 from:@"(5551) 234-567" to:@"(555) 123-4567" stickingRightward:true]);
XCTAssertEqual(1,
[PhoneNumberUtil translateCursorPosition:1 from:@"(5551) 234-567" to:@"(555) 123-4567" stickingRightward:true]);
XCTAssertEqual(2,
[PhoneNumberUtil translateCursorPosition:2 from:@"(5551) 234-567" to:@"(555) 123-4567" stickingRightward:true]);
XCTAssertEqual(3,
[PhoneNumberUtil translateCursorPosition:3 from:@"(5551) 234-567" to:@"(555) 123-4567" stickingRightward:true]);
XCTAssertEqual(6,
[PhoneNumberUtil translateCursorPosition:4 from:@"(5551) 234-567" to:@"(555) 123-4567" stickingRightward:true]);
XCTAssertEqual(7,
[PhoneNumberUtil translateCursorPosition:5 from:@"(5551) 234-567" to:@"(555) 123-4567" stickingRightward:true]);
XCTAssertEqual(0,
[PhoneNumberUtil translateCursorPosition:0
from:@"(5551) 234-567"
to:@"(555) 123-4567"
stickingRightward:false]);
XCTAssertEqual(1,
[PhoneNumberUtil translateCursorPosition:1
from:@"(5551) 234-567"
to:@"(555) 123-4567"
stickingRightward:false]);
XCTAssertEqual(2,
[PhoneNumberUtil translateCursorPosition:2
from:@"(5551) 234-567"
to:@"(555) 123-4567"
stickingRightward:false]);
XCTAssertEqual(3,
[PhoneNumberUtil translateCursorPosition:3
from:@"(5551) 234-567"
to:@"(555) 123-4567"
stickingRightward:false]);
XCTAssertEqual(4,
[PhoneNumberUtil translateCursorPosition:4
from:@"(5551) 234-567"
to:@"(555) 123-4567"
stickingRightward:false]);
XCTAssertEqual(7,
[PhoneNumberUtil translateCursorPosition:5
from:@"(5551) 234-567"
to:@"(555) 123-4567"
stickingRightward:false]);
}
- (void)testCallingCodeFromCountryCode
{
XCTAssertEqualObjects([PhoneNumberUtil callingCodeFromCountryCode:@"US"], @"+1");
XCTAssertEqualObjects([PhoneNumberUtil callingCodeFromCountryCode:@"GB"], @"+44");
// Invalid country code.
XCTAssertEqualObjects([PhoneNumberUtil callingCodeFromCountryCode:@"EK"], @"+0");
XCTAssertEqualObjects([PhoneNumberUtil callingCodeFromCountryCode:@"ZZZ"], @"+0");
XCTAssertEqualObjects([PhoneNumberUtil callingCodeFromCountryCode:nil], @"+0");
}
- (void)testCountryNameFromCountryCode
{
XCTAssertEqualObjects([PhoneNumberUtil countryNameFromCountryCode:@"US"], @"United States");
XCTAssertEqualObjects([PhoneNumberUtil countryNameFromCountryCode:@"GB"], @"United Kingdom");
// Invalid country code.
XCTAssertEqualObjects([PhoneNumberUtil countryNameFromCountryCode:@"EK"], @"EK");
XCTAssertEqualObjects([PhoneNumberUtil countryNameFromCountryCode:@"ZZZ"], @"ZZZ");
XCTAssertThrows([PhoneNumberUtil countryNameFromCountryCode:nil]);
}
- (void)testCountryCodesForSearchTerm
{
// Empty search.
XCTAssertGreaterThan([PhoneNumberUtil countryCodesForSearchTerm:nil].count, (NSUInteger)30);
XCTAssertGreaterThan([PhoneNumberUtil countryCodesForSearchTerm:@""].count, (NSUInteger)30);
XCTAssertGreaterThan([PhoneNumberUtil countryCodesForSearchTerm:@" "].count, (NSUInteger)30);
// Searches with no results.
XCTAssertEqual([PhoneNumberUtil countryCodesForSearchTerm:@" . "].count, (NSUInteger)0);
XCTAssertEqual([PhoneNumberUtil countryCodesForSearchTerm:@" XXXXX "].count, (NSUInteger)0);
XCTAssertEqual([PhoneNumberUtil countryCodesForSearchTerm:@" ! "].count, (NSUInteger)0);
// Search by country code.
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@"GB"], (@[ @"GB" ]));
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@"gb"], (@[ @"GB" ]));
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@"GB "], (@[ @"GB" ]));
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@" GB"], (@[ @"GB" ]));
XCTAssertTrue([[PhoneNumberUtil countryCodesForSearchTerm:@" G"] containsObject:@"GB"]);
XCTAssertFalse([[PhoneNumberUtil countryCodesForSearchTerm:@" B"] containsObject:@"GB"]);
// Search by country name.
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@"united kingdom"], (@[ @"GB" ]));
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@" UNITED KINGDOM "], (@[ @"GB" ]));
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@" UNITED KING "], (@[ @"GB" ]));
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@" UNI KING "], (@[ @"GB" ]));
XCTAssertEqualObjects([PhoneNumberUtil countryCodesForSearchTerm:@" u k "], (@[ @"GB" ]));
XCTAssertTrue([[PhoneNumberUtil countryCodesForSearchTerm:@" u"] containsObject:@"GB"]);
XCTAssertTrue([[PhoneNumberUtil countryCodesForSearchTerm:@" k"] containsObject:@"GB"]);
XCTAssertFalse([[PhoneNumberUtil countryCodesForSearchTerm:@" m"] containsObject:@"GB"]);
// Search by calling code.
XCTAssertTrue([[PhoneNumberUtil countryCodesForSearchTerm:@" +44 "] containsObject:@"GB"]);
XCTAssertTrue([[PhoneNumberUtil countryCodesForSearchTerm:@" 44 "] containsObject:@"GB"]);
XCTAssertTrue([[PhoneNumberUtil countryCodesForSearchTerm:@" +4 "] containsObject:@"GB"]);
XCTAssertTrue([[PhoneNumberUtil countryCodesForSearchTerm:@" 4 "] containsObject:@"GB"]);
XCTAssertFalse([[PhoneNumberUtil countryCodesForSearchTerm:@" +123 "] containsObject:@"GB"]);
XCTAssertFalse([[PhoneNumberUtil countryCodesForSearchTerm:@" +444 "] containsObject:@"GB"]);
}
@end

View file

@ -1,36 +0,0 @@
//
// PhoneNumberTest.m
// Signal
//
// Created by Michael Kirk on 6/28/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "PhoneNumberUtil.h"
@interface PhoneNumberUtilTest : XCTestCase
@end
@implementation PhoneNumberUtilTest
- (void)testQueryMatching {
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"big dave"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"dave big"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"dave"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"big"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"big "]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@" big "]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"dav"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"bi dav"]);
XCTAssertTrue([PhoneNumberUtil name:@"big dave" matchesQuery:@"big big big big big big big big big big dave dave dave dave dave"]);
XCTAssertFalse([PhoneNumberUtil name:@"big dave" matchesQuery:@"ave"]);
XCTAssertFalse([PhoneNumberUtil name:@"big dave" matchesQuery:@"dare"]);
XCTAssertFalse([PhoneNumberUtil name:@"big dave" matchesQuery:@"mike"]);
XCTAssertFalse([PhoneNumberUtil name:@"big dave" matchesQuery:@"mike"]);
XCTAssertFalse([PhoneNumberUtil name:@"dave" matchesQuery:@"big"]);
}
@end