diff --git a/Core/DTFoundation-Prefix.pch b/Core/DTFoundation-Prefix.pch index de3bf9ad..37fa9571 100644 --- a/Core/DTFoundation-Prefix.pch +++ b/Core/DTFoundation-Prefix.pch @@ -3,6 +3,7 @@ // #import +#import #ifdef __OBJC__ diff --git a/Core/Source/DTDownload.h b/Core/Source/DTDownload.h index 0aec0f1b..52d72874 100644 --- a/Core/Source/DTDownload.h +++ b/Core/Source/DTDownload.h @@ -161,6 +161,13 @@ typedef void (^DTDownloadCompletionHandler)(DTDownload *); - (BOOL)isLoading; +/** +* Removes the downloaded file or the incomplete file if the download is currently running. +* Note: Also the download is cancelled if necessary +*/ +- (void)cleanup; + + /**------------------------------------------------------------------------------------- @name Block Handlers --------------------------------------------------------------------------------------- @@ -171,6 +178,7 @@ typedef void (^DTDownloadCompletionHandler)(DTDownload *); */ @property (nonatomic, copy) DTDownloadResponseHandler responseHandler; + /** Sets the block to execute as soon as the download has completed. */ diff --git a/Core/Source/DTDownload.m b/Core/Source/DTDownload.m index f2d51622..d6de601e 100644 --- a/Core/Source/DTDownload.m +++ b/Core/Source/DTDownload.m @@ -249,6 +249,9 @@ - (void)startWithResume:(BOOL)shouldResume - (void)cancel { + if (_cancelled) { + return; + } _cancelled = YES; self.delegate = nil; @@ -530,6 +533,16 @@ - (BOOL)isLoading return _isLoading; } +- (void)cleanup +{ + [self cancel]; + + // remove cached file + NSFileManager *fileManager = [[NSFileManager alloc] init]; + [fileManager removeItemAtPath:self.internalDownloadFolder error:nil]; +} + + @synthesize URL = _URL, internalDownloadFolder, downloadEntityTag, folderForDownloading, lastPaketTimestamp, delegate, lastModifiedDate; @synthesize MIMEType = _MIMEType; @synthesize totalBytes = _totalBytes; diff --git a/Core/Source/DTVersion.h b/Core/Source/DTVersion.h index 5685b412..a23e7f91 100644 --- a/Core/Source/DTVersion.h +++ b/Core/Source/DTVersion.h @@ -3,36 +3,45 @@ // DTFoundation // // Created by Oliver Drobnik on 11/25/11. -// Copyright (c) 2011 Cocoanetics. All rights reserved. -// - +// Copyright (c) 2012 Cocoanetics. All rights reserved. /** - Class that represents a version number comprised of major, minor and maintenance number separarated by dots. For example "1.2.2". - - This encapsulation simplifies comparing versions against each other. Sub-numbers that are omitted on creating a `DTVersion` are assumed to be 0. + Class that represents a version number comprised of major, minor and maintenance number separarated by dots. For example "1.2.2". + This encapsulation simplifies comparing versions against each other. Sub-numbers that are omitted on creating a `DTVersion` are assumed to be 0. */ @interface DTVersion : NSObject { - NSUInteger _majorVersion; - NSUInteger _minorVersion; - NSUInteger _maintenanceVersion; + NSUInteger _major; + NSUInteger _minor; + NSUInteger _maintenance; + NSUInteger _build; } +/**------------------------------------------------------------------------------------- + @name Properties + --------------------------------------------------------------------------------------- + */ + /** - The receiver's major version number. + The major version number */ -@property (nonatomic, readonly) NSUInteger majorVersion; +@property (nonatomic, readonly) NSUInteger major; /** - The receiver's minor version number. + The minor version number */ -@property (nonatomic, readonly) NSUInteger minorVersion; +@property (nonatomic, readonly) NSUInteger minor; + /** - The receiver's maintenance version number. + The maintenance/hotfix version number */ -@property (nonatomic, readonly) NSUInteger maintenanceVersion; +@property (nonatomic, readonly) NSUInteger maintenance; + +/** + The build number + */ +@property (nonatomic, readonly) NSUInteger build; /**------------------------------------------------------------------------------------- @name Creating Versions @@ -40,73 +49,109 @@ */ /** - creates and returns a `DTVersion` object initialized using the provided string - - @param versionString A string with a version number. - @returns A `DTVersion` object or `nil` if the string is not a valid version number - @see initWithMajor:minor:maintenance: + Initializes the receiver with major, minor and maintenance version. + @param major The major version number + @param minor The minor version number + @param maintenance The maintainance/hotfix version number + @returns The initialized `DTVersion` */ -+ (DTVersion *)versionWithString:(NSString *)versionString; +- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance; /** - creates and retuns a `DTVersion` object initialized with the version information of the current application - - @returns A `DTVersion` object or `nil` if the string of the current application is not a valid version number + Initializes the receiver with major, minor and maintenance version. + @param major The major version number + @param minor The minor version number + @param maintenance The maintainance/hotfix version number + @param build The build number + @returns The initialized `DTVersion` */ -+ (DTVersion *)appBundleVersion; +- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance build:(NSUInteger)build; /** - creates and retuns a `DTVersion` object initialized with the version information of the operating system - - @returns A `DTVersion` object or `nil` if the string of the current application is not a valid version number + creates and returns a DTVersion object initialized using the provided string + @param versionString The `NSString` to create a `DTVersion` from + @returns A DTVersion object or nil if the string is not a valid version number */ -+ (DTVersion *)osVersion; ++ (DTVersion *)versionWithString:(NSString *)versionString; /** - creates and returns a `DTVersion` object initialized using the provided string - - @param major The major version number of the version. - @param minor The minor version number of the version. - @param maintenance The maintenance version number of the version. - @returns A `DTVersion` object or `nil` if the string is not a valid version number + creates and retuns a DTVersion object initialized with the version information of the current application + @returns A DTVersion object or nil if the string of the current application is not a valid version number */ -- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance; ++ (DTVersion *)appBundleVersion; + +/** + creates and retuns a DTVersion object initialized with the version information of the operating system + @returns A DTVersion object or nil if the string of the current application is not a valid version number + */ ++ (DTVersion *)osVersion; /**------------------------------------------------------------------------------------- - @name Comparing Versions + @name Comparing Versions --------------------------------------------------------------------------------------- */ /** - Returns a Boolean value that indicates whether a given `DTVersion` is equal to the receiver. - - @param version The `DTVersion` instance to compare against. - @returns `YES` if the other object is equal to the receiver - */ -- (BOOL) isEqualToVersion:(DTVersion *)version; + @param versionString The OS version as `NSString` to compare the receiver to + @returns true if the given version string is valid and less then the osVersion +*/ ++ (BOOL)osVersionIsLessThen:(NSString *)versionString; + +/** + @param versionString The OS version as `NSString` to compare the receiver to + @returns true if the given version string is valid and greater then the osVersion +*/ ++ (BOOL)osVersionIsGreaterThen:(NSString *)versionString; + +/** + @param version The `DTVersion` to compare the receiver to + @returns true if the give version is less then this version +*/ +- (BOOL)isLessThenVersion:(DTVersion *)version; /** - Returns a Boolean value that indicates whether a given string is equal to the receiver. - - @param versionString The string to compare the receiver against. - @returns `YES` if the other object is equal to the receiver + @param version The `DTVersion` to compare the receiver to + @returns true if the give version is greater then this version +*/ +- (BOOL)isGreaterThenVersion:(DTVersion *)version; + +/** + @param versionString The version as `NSString` to compare the receiver to + @returns true if the give version is less then this version string +*/ +- (BOOL)isLessThenVersionString:(NSString *)versionString; + +/** + @param versionString The version as `NSString` to compare the receiver to +* @returns true if the give version is greater then version string +*/ +- (BOOL)isGreaterThenVersionString:(NSString *)versionString; + +/** + Compares the receiver against a passed `DTVersion` instance + @param version The `DTVersion` to compare the receiver to + @returns `YES` is the versions are equal */ -- (BOOL) isEqualToString:(NSString *)versionString; +- (BOOL)isEqualToVersion:(DTVersion *)version; /** - Returns a Boolean value that indicates whether a given object is equal to the receiver. - - If the other object is an `NSString` then isEqualToString: is called. If it is a `DTVersion` instance isEqualToVersion: is called. - @param object An NSString or `DTVersion` to compare against. - @returns `YES` if the other object is equal to the receiver + Compares the receiver against a passed version as `NSString` + @param versionString The version as `NSString` to compare the receiver to + @returns `YES` is the versions are equal */ -- (BOOL) isEqual:(id)object; +- (BOOL)isEqualToString:(NSString *)versionString; /** -Compares the receiver to object. + Compares the receiver against a passed object + @param object An object of either `NSString` or `DTVersion` + @returns `YES` is the versions are equal + */ +- (BOOL)isEqual:(id)object; - @param version The `DTVersion` instance to compare the receiver with. - @returns `NSOrderedAscending` if the receiver precedes object in version ordering, `NSOrderedSame` if they are equal, and `NSOrderedDescending` if the receiver is higher than object. +/** + Compares the receiver against a passed `DTVersion` instance + @param version The `DTVersion` to compare the receiver to + @returns The comparison result */ - (NSComparisonResult)compare:(DTVersion *)version; diff --git a/Core/Source/DTVersion.m b/Core/Source/DTVersion.m index 4d4d2bd0..938154bf 100644 --- a/Core/Source/DTVersion.m +++ b/Core/Source/DTVersion.m @@ -2,22 +2,33 @@ // DTVersion.m // DTFoundation // -// Created by Oliver Drobnik on 11/25/11. -// Copyright (c) 2011 Cocoanetics. All rights reserved. +// Created by Oliver Drobnik +// Copyright 2012 Cocoanetics. All rights reserved. // #import "DTVersion.h" @implementation DTVersion -- (DTVersion *)initWithMajor:(NSUInteger)majorVersion minor:(NSUInteger)minorVersion maintenance:(NSUInteger)maintenanceVersion +#pragma mark Creating Versions + +- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance build:(NSUInteger)build { self = [super init]; - if (self) + if (self) { + _major = major; + _minor = minor; + _maintenance = maintenance; + _build = build; + } + return self; +} + +- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance +{ + self = [self initWithMajor:major minor:minor maintenance:maintenance build:0]; + if (self) { - _majorVersion = majorVersion; - _minorVersion = minorVersion; - _maintenanceVersion = maintenanceVersion; } return self; } @@ -32,56 +43,58 @@ + (DTVersion *)versionWithString:(NSString*)versionString NSInteger major = 0; NSInteger minor = 0; NSInteger maintenance = 0; - - int i=0; - NSScanner *scanner = [NSScanner scannerWithString:versionString]; - [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"."]]; + NSInteger build = 0; - while (i<3 && ![scanner isAtEnd]) + NSError *error; + NSString *pattern = @"^(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:\\.(\\d+))?(?:$|\\s)"; + + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern + options:NSRegularExpressionCaseInsensitive + error:&error]; + + NSTextCheckingResult *match = [regex firstMatchInString:versionString + options:NSRegularExpressionCaseInsensitive + range:NSMakeRange(0, [versionString length])]; + + if (!match) { - switch (i) + return nil; + } + for (int i = 1; i < match.numberOfRanges; i++) + { + NSRange range = [match rangeAtIndex:i]; + if (range.location == NSNotFound) + { + break; + } + NSUInteger value = [[versionString substringWithRange:range] integerValue]; + + switch (i) { - case 0: - { - if (![scanner scanInteger:&major]) - { - return nil; - } - break; - } - case 1: - { - if (![scanner scanInteger:&minor]) - { - return nil; - }; + major = value; break; - } - case 2: - { - if (![scanner scanInteger:&maintenance]) - { - return nil; - }; + minor = value; + break; + case 3: + maintenance = value; + break; + case 4: + build = value; break; - } - default: - { - // ignore suffix break; - } } - i++; + //NSLog(@"value for %d: %d", i, value); } if (major >= 0 && minor >= 0 && - maintenance >= 0) + maintenance >= 0 && + build >= 0) { - return [[DTVersion alloc] initWithMajor:major minor:minor maintenance:maintenance]; + return [[DTVersion alloc] initWithMajor:major minor:minor maintenance:maintenance build:build]; } return nil; @@ -115,9 +128,46 @@ + (DTVersion *)osVersion return version; } +#pragma mark Comparing Versions + ++ (BOOL)osVersionIsLessThen:(NSString *)versionString +{ + return [[DTVersion osVersion] isLessThenVersionString:versionString]; +} + ++ (BOOL)osVersionIsGreaterThen:(NSString *)versionString +{ + return [[DTVersion osVersion] isGreaterThenVersionString:versionString]; +} + + +- (BOOL)isLessThenVersion:(DTVersion *)version +{ + int result = [self compare:version] == NSOrderedAscending; + //DDLogVerbose(@"%@ < %@? %d = %@", self, version, result, result ? @"YES" : @"NO"); + return result; +} + +- (BOOL)isGreaterThenVersion:(DTVersion *)version +{ + return [self compare:version] == NSOrderedDescending; +} + +- (BOOL)isLessThenVersionString:(NSString *)versionString +{ + return [self isLessThenVersion:[DTVersion versionWithString:versionString]]; +} + +- (BOOL)isGreaterThenVersionString:(NSString *)versionString +{ + return [self isGreaterThenVersion:[DTVersion versionWithString:versionString]]; +} + + + - (BOOL) isEqualToVersion:(DTVersion *)version { - return (self.majorVersion == version.majorVersion) && (self.minorVersion == version.minorVersion) && (self.maintenanceVersion == version.maintenanceVersion); + return (self.major == version.major) && (self.minor == version.minor) && (self.maintenance == version.maintenance); } - (BOOL) isEqualToString:(NSString *)versionString @@ -147,30 +197,39 @@ - (NSComparisonResult)compare:(DTVersion *)version return NSOrderedDescending; } - if (self.majorVersion < version.majorVersion) + if (self.major < version.major) { return NSOrderedAscending; } - if (self.majorVersion > version.majorVersion) + if (self.major > version.major) { return NSOrderedDescending; } - if (self.minorVersion < version.minorVersion) + if (self.minor < version.minor) { return NSOrderedAscending; } - if (self.minorVersion > version.minorVersion) + if (self.minor > version.minor) { return NSOrderedDescending; } - if (self.maintenanceVersion < version.maintenanceVersion) + if (self.maintenance < version.maintenance) { return NSOrderedAscending; } - if (self.maintenanceVersion > version.maintenanceVersion) + if (self.maintenance > version.maintenance) { return NSOrderedDescending; - } + } + if (self.build < version.build) + { + return NSOrderedAscending; + } + if (self.build > version.build) + { + return NSOrderedDescending; + } + return NSOrderedSame; } @@ -178,13 +237,22 @@ - (NSComparisonResult)compare:(DTVersion *)version - (NSString *)description { - return [NSString stringWithFormat:@"%d.%d.%d", (int)_majorVersion, (int)_minorVersion, (int)_maintenanceVersion]; + if (_build > 0) + { + return [NSString stringWithFormat:@"%d.%d.%d.%d", _major, _minor, _maintenance, _build]; + } + if (_maintenance > 0) + { + return [NSString stringWithFormat:@"%d.%d.%d", _major, _minor, _maintenance]; + } + return [NSString stringWithFormat:@"%d.%d", _major, _minor]; } +#pragma mark Properties +@synthesize major = _major; +@synthesize minor = _minor; +@synthesize maintenance = _maintenance; +@synthesize build = _build; -@synthesize majorVersion = _majorVersion; -@synthesize minorVersion = _minorVersion; -@synthesize maintenanceVersion = _maintenanceVersion; - @end diff --git a/DTFoundation.xcodeproj/project.pbxproj b/DTFoundation.xcodeproj/project.pbxproj index 57539ee4..a83afc0f 100644 --- a/DTFoundation.xcodeproj/project.pbxproj +++ b/DTFoundation.xcodeproj/project.pbxproj @@ -55,6 +55,9 @@ A73D5BAC155271FD0024BDB7 /* NSArray+DTError.h in Headers */ = {isa = PBXBuildFile; fileRef = A73D5BA9155271FD0024BDB7 /* NSArray+DTError.h */; settings = {ATTRIBUTES = (Public, ); }; }; A73D5BAD155271FD0024BDB7 /* NSArray+DTError.m in Sources */ = {isa = PBXBuildFile; fileRef = A73D5BAA155271FD0024BDB7 /* NSArray+DTError.m */; }; A73D5BAE155271FD0024BDB7 /* NSArray+DTError.m in Sources */ = {isa = PBXBuildFile; fileRef = A73D5BAA155271FD0024BDB7 /* NSArray+DTError.m */; }; + A747797215F78D630026ABA8 /* DTDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = A7D0AA43153C22B00020F18B /* DTDownload.m */; }; + A747797415F78DEA0026ABA8 /* DTActionSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = A7EE2A0C1582CBFC00BB06DE /* DTActionSheet.m */; }; + A747797515F78E3F0026ABA8 /* DTAsyncFileDeleter.m in Sources */ = {isa = PBXBuildFile; fileRef = A77DD39D14E648AD00F34B03 /* DTAsyncFileDeleter.m */; }; A7494DFB15418B3100BDDB7D /* DTDownloadCache.h in Headers */ = {isa = PBXBuildFile; fileRef = A7494DF915418B3100BDDB7D /* DTDownloadCache.h */; }; A7494DFC15418B3100BDDB7D /* DTDownloadCache.h in Headers */ = {isa = PBXBuildFile; fileRef = A7494DF915418B3100BDDB7D /* DTDownloadCache.h */; }; A7494E53154190F500BDDB7D /* DTCachedFile.h in Headers */ = {isa = PBXBuildFile; fileRef = A7494E51154190F500BDDB7D /* DTCachedFile.h */; }; @@ -1006,6 +1009,9 @@ A7D60FEF15D3B18A00AEDD1B /* DTHTMLParserTest.m in Sources */, A7D60FF015D3B1BD00AEDD1B /* DTVersion.m in Sources */, A7D60FF615D3B26F00AEDD1B /* DTHTMLParser.m in Sources */, + A747797215F78D630026ABA8 /* DTDownload.m in Sources */, + A747797415F78DEA0026ABA8 /* DTActionSheet.m in Sources */, + A747797515F78E3F0026ABA8 /* DTAsyncFileDeleter.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Test/Source/DTVersionTest.h b/Test/Source/DTVersionTest.h index aae51f29..9fd78377 100644 --- a/Test/Source/DTVersionTest.h +++ b/Test/Source/DTVersionTest.h @@ -16,5 +16,6 @@ - (void)testCreate; - (void)testEquals; - (void)testCompare; +- (void)testLessThan; @end diff --git a/Test/Source/DTVersionTest.m b/Test/Source/DTVersionTest.m index e87d00c6..82aaadd0 100644 --- a/Test/Source/DTVersionTest.m +++ b/Test/Source/DTVersionTest.m @@ -19,30 +19,44 @@ - (void)testCreate version = [DTVersion versionWithString:@"1.-1"]; STAssertNil(version, @"DTVersion object should not be create of an unsupported string"); + //version = [DTVersion versionWithString:@"1.2.1.1"]; + //STAssertNil(version, @"DTVersion object should not be create of an unsupported string"); + + version = [DTVersion versionWithString:@"1.2.3"]; STAssertNotNil(version, @"DTVersion object should be create"); - STAssertEquals(1, (int)version.majorVersion, @"version.major is not the correct value %d", version.majorVersion); - STAssertEquals(2, (int)version.minorVersion, @"version.minor is not the correct value %d", version.minorVersion); - STAssertEquals(3, (int)version.maintenanceVersion, @"version.maintenance is not the correct value %d", version.maintenanceVersion); + STAssertEquals(1, (int)version.major, @"version.major is not the correct value %d", version.major); + STAssertEquals(2, (int)version.minor, @"version.minor is not the correct value %d", version.minor); + STAssertEquals(3, (int)version.maintenance, @"version.maintenance is not the correct value %d", version.maintenance); version = [DTVersion versionWithString:@"2.9999"]; STAssertNotNil(version, @"DTVersion object should be create"); - STAssertEquals(2, (int)version.majorVersion, @"version.major is not the correct value %d", version.majorVersion); - STAssertEquals(9999, (int)version.minorVersion, @"version.minor is not the correct value %d", version.minorVersion); - STAssertEquals(0, (int)version.maintenanceVersion, @"version.maintenance is not the correct value %d", version.maintenanceVersion); + STAssertEquals(2, (int)version.major, @"version.major is not the correct value %d", version.major); + STAssertEquals(9999, (int)version.minor, @"version.minor is not the correct value %d", version.minor); + STAssertEquals(0, (int)version.maintenance, @"version.maintenance is not the correct value %d", version.maintenance); version = [DTVersion versionWithString:@"1"]; STAssertNotNil(version, @"DTVersion object should be create"); - STAssertEquals(1, (int)version.majorVersion, @"version.major is not the correct value %d", version.majorVersion); - STAssertEquals(0, (int)version.minorVersion, @"version.minor is not the correct value %d", version.minorVersion); - STAssertEquals(0, (int)version.maintenanceVersion, @"version.maintenance is not the correct value %d", version.maintenanceVersion); + STAssertEquals(1, (int)version.major, @"version.major is not the correct value %d", version.major); + STAssertEquals(0, (int)version.minor, @"version.minor is not the correct value %d", version.minor); + STAssertEquals(0, (int)version.maintenance, @"version.maintenance is not the correct value %d", version.maintenance); + + + version = [DTVersion versionWithString:@"1.2.3.4"]; + STAssertNotNil(version, @"DTVersion object should be create"); + STAssertEquals(1, (int)version.major, @"version.major is not the correct value %d", version.major); + STAssertEquals(2, (int)version.minor, @"version.minor is not the correct value %d", version.minor); + STAssertEquals(3, (int)version.maintenance, @"version.maintenance is not the correct value %d", version.maintenance); + STAssertEquals(4, (int)version.build, @"version.build is not the correct value %d", version.build); + + } - (void)testEquals { DTVersion *first = [DTVersion versionWithString:@"1.2.3"]; - DTVersion *second = [DTVersion versionWithString:@"1.2.3"]; + DTVersion *second = [DTVersion versionWithString:@"1.2.4"]; STAssertTrue([first isEqualToVersion:second], @"first version is not equal to second, but should"); STAssertTrue([first isEqual:second], @"first version is not equal to second, but should"); @@ -50,7 +64,6 @@ - (void)testEquals second = [DTVersion versionWithString:@"1.2"]; STAssertFalse([first isEqualToVersion:second], @"first version is equal to second, but should not"); STAssertFalse([first isEqual:second], @"first version is equal to second, but should not"); - first = [DTVersion versionWithString:@"1.0.0"]; second = [DTVersion versionWithString:@"1"]; @@ -60,16 +73,24 @@ - (void)testEquals second = [DTVersion versionWithString:@"1.0"]; STAssertTrue([first isEqualToVersion:second], @"first version is not equal to second, but should"); STAssertTrue([first isEqual:second], @"first version is not equal to second, but should"); + STAssertTrue([first isEqualToString:@"1.0.0"], @"first version is not equal to second, but should"); STAssertTrue([first isEqual:@"1.0.0"], @"first version is not equal to second, but should"); STAssertTrue([first isEqualToString:@"1.0"], @"first version is not equal to second, but should"); STAssertTrue([first isEqualToString:@"1"], @"first version is not equal to second, but should"); + STAssertTrue([first isEqual:@"1.0.0.0"], @"first version is not equal to second, but should"); STAssertFalse([first isEqualToString:@"1.2"], @"first version is equal to second, but should not"); STAssertFalse([first isEqualToString:@"1.1.1"], @"first version is equal to second, but should not"); STAssertFalse([first isEqualToString:@"foobar"], @"first version is equal to second, but should not"); STAssertFalse([first isEqualToString:@"0.0.0"], @"first version is equal to second, but should not"); + + + first = [DTVersion versionWithString:@"1.2.3.4"]; + second = [DTVersion versionWithString:@"1.2.3.4"]; + STAssertTrue([first isEqualToVersion:second], @"first version is not equal to second, but should"); + } @@ -93,7 +114,41 @@ - (void)testCompare second = [DTVersion versionWithString:@"0.9.9"]; STAssertEquals(NSOrderedDescending, [first compare:nil], @"%@ should be smaller then %@", first, second); + + second = [DTVersion versionWithString:@"0.9.9.0"]; + STAssertEquals(NSOrderedDescending, [first compare:nil], @"%@ should be smaller then %@", first, second); + +} + +- (void)testLessThan +{ + DTVersion *first = [DTVersion versionWithString:@"1.0"]; + DTVersion *second = [DTVersion versionWithString:@"2.0"]; + + STAssertTrue([first isLessThenVersion:second], @"first version is not less the second"); + STAssertFalse([second isLessThenVersion:first], @"second should not be less then first"); + + STAssertTrue([second isGreaterThenVersion:first], @"second version is not greater then first"); + + STAssertFalse([second isLessThenVersionString:@"2.0.0"], @"second should not be less then 2.0.0"); + STAssertFalse([second isLessThenVersionString:@"1.9.9"], @"second should not be less then 1.9.9"); + STAssertTrue([second isLessThenVersionString:@"2.0.1"], @"second should be less then 2.0.0"); } +- (void)testVersion +{ + DTVersion *first = [DTVersion versionWithString:@"8.00.047 build 010"]; + DTVersion *second = [DTVersion versionWithString:@"8.00.047"]; + + STAssertEquals(NSOrderedSame, [first compare:second], @"should be the same"); + + STAssertFalse([first isLessThenVersionString:@"8.00.047"], @"first version is not less than 8.00.047"); + + second = [DTVersion versionWithString:@"8.00.047 build 010"]; + NSLog(@"version %@", second); + STAssertEquals(NSOrderedSame, [first compare:second], @"should be the same"); + + +} @end