diff --git a/Example/Tests/ThingTypes/MHVTimeTests.m b/Example/Tests/ThingTypes/MHVTimeTests.m new file mode 100644 index 0000000..c18323d --- /dev/null +++ b/Example/Tests/ThingTypes/MHVTimeTests.m @@ -0,0 +1,96 @@ +// +// MHVTimeTests.m +// Copyright (c) 2017 Microsoft Corporation. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#import +#import "MHVTime.h" + +@interface MHVTimeTests : XCTestCase + +@end + +@implementation MHVTimeTests + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testEqualValues +{ + MHVTime *time1 = [[MHVTime alloc] initWithHour:10 minute:10]; + MHVTime *time2 = [[MHVTime alloc] initWithHour:10 minute:10]; + + XCTAssertTrue([time1 isEqual:time2], @"Times should be equal"); + XCTAssertTrue(time1.hash == time2.hash, @"Hashes should be equal"); +} + +- (void)testDifferentValues +{ + MHVTime *time1 = [[MHVTime alloc] initWithHour:10 minute:10]; + MHVTime *time2 = [[MHVTime alloc] initWithHour:10 minute:9]; + + XCTAssertFalse([time1 isEqual:time2], @"Times should not be equal"); + XCTAssertFalse(time1.hash == time2.hash, @"Hashes should not be equal"); +} + +- (void)testEqualValuesSeconds +{ + MHVTime *time1 = [[MHVTime alloc] initWithHour:12 minute:11 second:10]; + MHVTime *time2 = [[MHVTime alloc] initWithHour:12 minute:11 second:10]; + + XCTAssertTrue([time1 isEqual:time2], @"Times should be equal"); + XCTAssertTrue(time1.hash == time2.hash, @"Hashes should be equal"); +} + +- (void)testDifferentValuesSeconds +{ + MHVTime *time1 = [[MHVTime alloc] initWithHour:12 minute:11 second:10]; + MHVTime *time2 = [[MHVTime alloc] initWithHour:12 minute:11 second:9]; + + XCTAssertFalse([time1 isEqual:time2], @"Times should not be equal"); + XCTAssertFalse(time1.hash == time2.hash, @"Hashes should not be equal"); +} + +- (void)testEqualValuesMilliseconds +{ + MHVTime *time1 = [[MHVTime alloc] initWithHour:0 minute:0 second:0]; + MHVTime *time2 = [[MHVTime alloc] initWithHour:0 minute:0 second:0]; + [time1 setMillisecond:500]; + [time2 setMillisecond:500]; + + XCTAssertTrue([time1 isEqual:time2], @"Times should be equal"); + XCTAssertTrue(time1.hash == time2.hash, @"Hashes should be equal"); +} + +- (void)testDifferentValuesMilliseconds +{ + MHVTime *time1 = [[MHVTime alloc] initWithHour:23 minute:59 second:59]; + MHVTime *time2 = [[MHVTime alloc] initWithHour:23 minute:59 second:59]; + [time1 setMillisecond:9998]; + [time2 setMillisecond:9999]; + + XCTAssertFalse([time1 isEqual:time2], @"Times should not be equal"); + XCTAssertFalse(time1.hash == time2.hash, @"Hashes should not be equal"); +} + +@end diff --git a/Example/healthvault-ios-sdk.xcodeproj/project.pbxproj b/Example/healthvault-ios-sdk.xcodeproj/project.pbxproj index 770da74..4433d61 100644 --- a/Example/healthvault-ios-sdk.xcodeproj/project.pbxproj +++ b/Example/healthvault-ios-sdk.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 4C95AF051F0D6C2B00EA5A8F /* MHVThingCacheQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C95AF041F0D6C2B00EA5A8F /* MHVThingCacheQueryTests.m */; }; 4C95AF071F0D917D00EA5A8F /* MHVThingCacheDatabaseTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C95AF061F0D917D00EA5A8F /* MHVThingCacheDatabaseTests.m */; }; 4C95AF111F0EF20200EA5A8F /* MHVMockDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C95AEBB1F093F7D00EA5A8F /* MHVMockDatabase.m */; }; + 4C9BAD311F7C05F7002514A2 /* MHVTimeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C9BAD301F7C05F7002514A2 /* MHVTimeTests.m */; }; 4C9DC867EC28E0AB74E00107 /* Pods_healthvault_ios_sdk_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D0C259B6A86A74D53D73A37 /* Pods_healthvault_ios_sdk_Example.framework */; }; 4CC5FFE41EF81786003B8690 /* MHVBrowserAuthBrokerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC5FFE31EF81786003B8690 /* MHVBrowserAuthBrokerTests.m */; }; 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; @@ -145,6 +146,7 @@ 4C95AEC01F0A872700EA5A8F /* MHVThingCacheSynchronizerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHVThingCacheSynchronizerTests.m; sourceTree = ""; }; 4C95AF041F0D6C2B00EA5A8F /* MHVThingCacheQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHVThingCacheQueryTests.m; sourceTree = ""; }; 4C95AF061F0D917D00EA5A8F /* MHVThingCacheDatabaseTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHVThingCacheDatabaseTests.m; sourceTree = ""; }; + 4C9BAD301F7C05F7002514A2 /* MHVTimeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MHVTimeTests.m; sourceTree = ""; }; 4CC5FFE31EF81786003B8690 /* MHVBrowserAuthBrokerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHVBrowserAuthBrokerTests.m; sourceTree = ""; }; 6003F58A195388D20070C39A /* healthvault-ios-sdk_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "healthvault-ios-sdk_Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -647,6 +649,7 @@ A5DF654E1EF052DD009F5968 /* MHVPregnancyTests.m */, A5DF654F1EF052DD009F5968 /* MHVTaskThingTests.m */, A5DF65501EF052DD009F5968 /* MHVTaskTrackingEntryTests.m */, + 4C9BAD301F7C05F7002514A2 /* MHVTimeTests.m */, ); path = ThingTypes; sourceTree = ""; @@ -978,6 +981,7 @@ A5DF65771EF0533D009F5968 /* MHVConnectionTests.m in Sources */, A5DF65791EF05342009F5968 /* MHVLibTests.m in Sources */, 4CC5FFE41EF81786003B8690 /* MHVBrowserAuthBrokerTests.m in Sources */, + 4C9BAD311F7C05F7002514A2 /* MHVTimeTests.m in Sources */, A5DF657B1EF0534A009F5968 /* MHVHttpServiceTests.m in Sources */, A5DF65721EF05327009F5968 /* MHVShellAuthServiceTests.m in Sources */, 4C95AEC11F0A872700EA5A8F /* MHVThingCacheSynchronizerTests.m in Sources */, diff --git a/HealthVault/Classes/Types/MHVTime.m b/HealthVault/Classes/Types/MHVTime.m index 9a35dd2..0bb3691 100644 --- a/HealthVault/Classes/Types/MHVTime.m +++ b/HealthVault/Classes/Types/MHVTime.m @@ -383,13 +383,13 @@ static const xmlChar *x_element_millis = XMLSTRINGCONST("f"); MHVTime *time = (MHVTime *)object; - return self.hour == time.hour && self.minute == time.minute && self.second == time.second; + return self.hour == time.hour && self.minute == time.minute && self.second == time.second && self.millisecond == time.millisecond; } - (NSUInteger)hash { - //Convert to seconds for hash value - return self.hour * 3600 + self.minute * 60 + (self.hasSecond ? self.second : 0); + // Convert to millisecond for hash value + return self.hour * 3600000 + self.minute * 60000 + (self.hasSecond ? self.second * 1000 : 0) + (self.hasMillisecond ? self.millisecond : 0); } @end