From e7bd33df4521bdd0c374b28d6ede774e81901419 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 5 Dec 2017 12:02:21 -0500 Subject: [PATCH] Fix tests broken by SAE. --- Signal/test/util/UtilTest.m | 111 +++---------------------- SignalMessaging/environment/Release.m | 8 +- SignalMessaging/utils/ImageCache.swift | 2 +- 3 files changed, 20 insertions(+), 101 deletions(-) diff --git a/Signal/test/util/UtilTest.m b/Signal/test/util/UtilTest.m index 9394b6dca..fc0692a75 100644 --- a/Signal/test/util/UtilTest.m +++ b/Signal/test/util/UtilTest.m @@ -3,9 +3,20 @@ // #import "UtilTest.h" +#import "NSString+OWS.h" +#import "NumberUtil.h" #import "TestUtil.h" +@interface NSString (OWS_Test) + +- (NSString *)removeAllCharactersIn:(NSCharacterSet *)characterSet; + +@end + +#pragma mark - + @implementation UtilTest + -(void) testFloorMultiple { test([NumberUtil largestIntegerThatIsAtMost:0 andIsAMultipleOf:20] == 0); test([NumberUtil largestIntegerThatIsAtMost:1 andIsAMultipleOf:20] == 0); @@ -15,6 +26,7 @@ test([NumberUtil largestIntegerThatIsAtMost:20 andIsAMultipleOf:20] == 20); test([NumberUtil largestIntegerThatIsAtMost:21 andIsAMultipleOf:20] == 20); } + -(void) testCeilingMultiple { test([NumberUtil smallestIntegerThatIsAtLeast:0 andIsAMultipleOf:20] == 0); test([NumberUtil smallestIntegerThatIsAtLeast:1 andIsAMultipleOf:20] == 20); @@ -33,89 +45,7 @@ test([NumberUtil congruentDifferenceMod2ToThe16From:0x8000 to:0] == -0x8000); test([NumberUtil congruentDifferenceMod2ToThe16From:0 to:0] == 0); } --(void) testToRegex { - testThrows(@"(".toRegularExpression); - NSRegularExpression* r = @"a+b".toRegularExpression; - test([r numberOfMatchesInString:@"a" options:NSMatchingAnchored range:NSMakeRange(0, 1)] == 0); - test([r numberOfMatchesInString:@"b" options:NSMatchingAnchored range:NSMakeRange(0, 1)] == 0); - test([r numberOfMatchesInString:@"ba" options:NSMatchingAnchored range:NSMakeRange(0, 1)] == 0); - test([r numberOfMatchesInString:@"ab" options:NSMatchingAnchored range:NSMakeRange(0, 2)] == 1); - test([r numberOfMatchesInString:@"aab" options:NSMatchingAnchored range:NSMakeRange(0, 3)] == 1); - test([r numberOfMatchesInString:@"aabXBNSAUI" options:NSMatchingAnchored range:NSMakeRange(0, 3)] == 1); - test([r numberOfMatchesInString:@"aacb" options:NSMatchingAnchored range:NSMakeRange(0, 3)] == 0); -} --(void) testWithMatchesAgainstReplacedBy { - test([[@"(555)-555-5555" withMatchesAgainst:[@"[^0-9+]" toRegularExpression] replacedBy:@""] isEqualToString:@"5555555555"]); - test([[@"aaaaaa" withMatchesAgainst:@"a".toRegularExpression replacedBy:@""] isEqualToString:@""]); - test([[@"aabaabaa" withMatchesAgainst:@"b".toRegularExpression replacedBy:@"wonder"] isEqualToString:@"aawonderaawonderaa"]); -} --(void) testContainsAnyMatches { - NSRegularExpression* r = [@"^\\+[0-9]{10,}" toRegularExpression]; - test([@"+5555555555" containsAnyMatches:r]); - test([@"+6555595555" containsAnyMatches:r]); - test([@"+65555555557+/few,pf" containsAnyMatches:r]); - test(![@" +5555555555" containsAnyMatches:r]); - test(![@"+555KL55555" containsAnyMatches:r]); - test(![@"+1-555-555-5555" containsAnyMatches:r]); - test(![@"1-(555)-555-5555" containsAnyMatches:r]); -} --(void) testWithPrefixRemovedElseNull { - test([[@"test" withPrefixRemovedElseNull:@""] isEqualToString:@"test"]); - test([[@"test" withPrefixRemovedElseNull:@"t"] isEqualToString:@"est"]); - test([[@"test" withPrefixRemovedElseNull:@"te"] isEqualToString:@"st"]); - test([[@"test" withPrefixRemovedElseNull:@"tes"] isEqualToString:@"t"]); - test([[@"test" withPrefixRemovedElseNull:@"test"] isEqualToString:@""]); - test([@"test" withPrefixRemovedElseNull:@"test2"] == nil); - test([@"test" withPrefixRemovedElseNull:@"a"] == nil); - testThrows([@"test" withPrefixRemovedElseNull:nil]); -} --(void) testFromJson { - test([[@"{}" decodedAsJsonIntoDictionary] isEqualToDictionary:@{}]); - test([[@"{\"a\":\"b\"}" decodedAsJsonIntoDictionary] isEqualToDictionary:@{@"a":@"b"}]); - test([[@"{\"c\":5}" decodedAsJsonIntoDictionary] isEqualToDictionary:@{@"c":@5}]); - test([[@"{\"a\":5,\"b\":true}" decodedAsJsonIntoDictionary] isEqualToDictionary:(@{@"a":@5,@"b":@YES})]); - - testThrows([@"" decodedAsJsonIntoDictionary]); - testThrows([@"}" decodedAsJsonIntoDictionary]); - testThrows([@"{{}" decodedAsJsonIntoDictionary]); -} --(void) testHasLongLongValue { - test((@0).hasLongLongValue); - test((@1).hasLongLongValue); - test((@-11).hasLongLongValue); - test(@LONG_LONG_MAX.hasLongLongValue); - test(@LONG_LONG_MIN.hasLongLongValue); - test(!@ULONG_LONG_MAX.hasLongLongValue); - test(@(pow(2, 62)).hasLongLongValue); - test(!@(pow(2, 63)).hasLongLongValue); - test(!@(-pow(2, 64)).hasLongLongValue); - test(!(@0.5).hasLongLongValue); -} --(void) testTryParseAsUnsignedInteger { - test([@"" tryParseAsUnsignedInteger] == nil); - test([@"88ffhih" tryParseAsUnsignedInteger] == nil); - test([@"0xA" tryParseAsUnsignedInteger] == nil); - test([@"A" tryParseAsUnsignedInteger] == nil); - test([@"-1" tryParseAsUnsignedInteger] == nil); - test([@"-" tryParseAsUnsignedInteger] == nil); - test([[@"0" tryParseAsUnsignedInteger] isEqual:@0]); - test([[@"00" tryParseAsUnsignedInteger] isEqual:@0]); - test([[@"1" tryParseAsUnsignedInteger] isEqual:@1]); - test([[@"01" tryParseAsUnsignedInteger] isEqual:@1]); - test([[@"25" tryParseAsUnsignedInteger] isEqual:@25]); - test([[(@NSUIntegerMax).description tryParseAsUnsignedInteger] isEqual:@NSUIntegerMax]); - if (NSUIntegerMax == 4294967295UL) { - test([@"4294967296" tryParseAsUnsignedInteger] == nil); - } - if (NSUIntegerMax == 18446744073709551615ULL) { - test([@"18446744073709551616" tryParseAsUnsignedInteger] == nil); - } - - NSString* max = (@NSUIntegerMax).description; - NSString* farTooLarge = [max stringByAppendingString:max]; - test([farTooLarge tryParseAsUnsignedInteger] == nil); -} -(void) testRemoveAllCharactersIn { testThrows([@"" removeAllCharactersIn:nil]); @@ -131,27 +61,12 @@ test([[@"A" removeAllCharactersIn:NSCharacterSet.decimalDigitCharacterSet] isEqual:@"A"]); test([[@"abc123%^&" removeAllCharactersIn:NSCharacterSet.decimalDigitCharacterSet] isEqual:@"abc%^&"]); } + -(void) testDigitsOnly { test([@"".digitsOnly isEqual:@""]); test([@"1".digitsOnly isEqual:@"1"]); test([@"a".digitsOnly isEqual:@""]); test([@"(555) 235-7111".digitsOnly isEqual:@"5552357111"]); } --(void) testWithCharactersInRangeReplacedBy { - testThrows([@"" withCharactersInRange:NSMakeRange(0, 0) replacedBy:nil]); - testThrows([@"" withCharactersInRange:NSMakeRange(0, 1) replacedBy:@""]); - testThrows([@"" withCharactersInRange:NSMakeRange(1, 0) replacedBy:@""]); - testThrows([@"" withCharactersInRange:NSMakeRange(1, 1) replacedBy:@""]); - testThrows([@"abc" withCharactersInRange:NSMakeRange(4, 0) replacedBy:@""]); - testThrows([@"abc" withCharactersInRange:NSMakeRange(3, 1) replacedBy:@""]); - testThrows([@"abc" withCharactersInRange:NSMakeRange(4, NSUIntegerMax) replacedBy:@""]); - - test([[@"" withCharactersInRange:NSMakeRange(0, 0) replacedBy:@""] isEqual:@""]); - test([[@"" withCharactersInRange:NSMakeRange(0, 0) replacedBy:@"abc"] isEqual:@"abc"]); - test([[@"abc" withCharactersInRange:NSMakeRange(0, 0) replacedBy:@"123"] isEqual:@"123abc"]); - test([[@"abc" withCharactersInRange:NSMakeRange(3, 0) replacedBy:@"123"] isEqual:@"abc123"]); - test([[@"abc" withCharactersInRange:NSMakeRange(2, 0) replacedBy:@"123"] isEqual:@"ab123c"]); - test([[@"abcdef" withCharactersInRange:NSMakeRange(1, 2) replacedBy:@"1234"] isEqual:@"a1234def"]); -} @end diff --git a/SignalMessaging/environment/Release.m b/SignalMessaging/environment/Release.m index 9daae7734..f36326bc5 100644 --- a/SignalMessaging/environment/Release.m +++ b/SignalMessaging/environment/Release.m @@ -14,11 +14,13 @@ + (Environment *)releaseEnvironment { + // Order matters here. + TSStorageManager *storageManager = [TSStorageManager sharedManager]; TSNetworkManager *networkManager = [TSNetworkManager sharedManager]; OWSContactsManager *contactsManager = [OWSContactsManager new]; ContactsUpdater *contactsUpdater = [ContactsUpdater sharedUpdater]; OWSMessageSender *messageSender = [[OWSMessageSender alloc] initWithNetworkManager:networkManager - storageManager:[TSStorageManager sharedManager] + storageManager:storageManager contactsManager:contactsManager contactsUpdater:contactsUpdater]; @@ -31,11 +33,13 @@ // TODELETE + (Environment *)stagingEnvironment { + // Order matters here. + TSStorageManager *storageManager = [TSStorageManager sharedManager]; TSNetworkManager *networkManager = [TSNetworkManager sharedManager]; OWSContactsManager *contactsManager = [OWSContactsManager new]; ContactsUpdater *contactsUpdater = [ContactsUpdater sharedUpdater]; OWSMessageSender *messageSender = [[OWSMessageSender alloc] initWithNetworkManager:networkManager - storageManager:[TSStorageManager sharedManager] + storageManager:storageManager contactsManager:contactsManager contactsUpdater:contactsUpdater]; diff --git a/SignalMessaging/utils/ImageCache.swift b/SignalMessaging/utils/ImageCache.swift index ff179aca9..2a8520717 100644 --- a/SignalMessaging/utils/ImageCache.swift +++ b/SignalMessaging/utils/ImageCache.swift @@ -22,7 +22,7 @@ public class ImageCache: NSObject { let backingCache: NSCache - override init() { + public override init() { self.backingCache = NSCache() }