GULHeartbeatDateStorageTest.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import "GoogleUtilities/Environment/Private/GULHeartbeatDateStorage.h"
  18. @interface GULHeartbeatDateStorageTest : XCTestCase
  19. @property(nonatomic) NSURL *fileURL;
  20. @property(nonatomic) GULHeartbeatDateStorage *storage;
  21. @end
  22. @implementation GULHeartbeatDateStorageTest
  23. - (void)setUp {
  24. NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(
  25. NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
  26. XCTAssertNotNil(documentsPath);
  27. NSURL *documentsURL = [NSURL fileURLWithPath:documentsPath];
  28. NSError *error;
  29. if (![documentsURL checkResourceIsReachableAndReturnError:&error]) {
  30. XCTAssert([[NSFileManager defaultManager] createDirectoryAtURL:documentsURL
  31. withIntermediateDirectories:YES
  32. attributes:nil
  33. error:&error],
  34. @"Error: %@", error);
  35. }
  36. self.storage = [[GULHeartbeatDateStorage alloc] initWithFileName:@"GULStorageHeartbeatTest"];
  37. }
  38. - (void)tearDown {
  39. [[NSFileManager defaultManager] removeItemAtURL:[self.storage fileURL] error:nil];
  40. self.storage = nil;
  41. }
  42. - (void)testHeartbeatDateForTag {
  43. NSDate *now = [NSDate date];
  44. [self.storage setHearbeatDate:now forTag:@"fire-iid"];
  45. XCTAssertEqual([now timeIntervalSinceReferenceDate],
  46. [[self.storage heartbeatDateForTag:@"fire-iid"] timeIntervalSinceReferenceDate]);
  47. }
  48. @end