FIRHeartbeatInfoTest.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <FirebaseCore/FIRHeartbeatInfo.h>
  15. #import <GoogleUtilities/GULHeartbeatDateStorage.h>
  16. #import <XCTest/XCTest.h>
  17. @interface FIRHeartbeatInfoTest : XCTestCase
  18. @property(nonatomic, strong) GULHeartbeatDateStorage *dataStorage;
  19. @property(nonatomic, strong) NSMutableDictionary *dictionary;
  20. @end
  21. @implementation FIRHeartbeatInfoTest
  22. - (void)setUp {
  23. NSString *const kHeartbeatStorageFile = @"HEARTBEAT_INFO_STORAGE";
  24. self.dataStorage = [[GULHeartbeatDateStorage alloc] initWithFileName:kHeartbeatStorageFile];
  25. NSDate *pastTime = [NSDate dateWithTimeIntervalSinceNow:-996400];
  26. [self.dataStorage setHearbeatDate:pastTime forTag:@"fire-iid"];
  27. [self.dataStorage setHearbeatDate:pastTime forTag:@"GLOBAL"];
  28. }
  29. - (void)testCombinedHeartbeat {
  30. FIRHeartbeatInfoCode heartbeatCode = [FIRHeartbeatInfo heartbeatCodeForTag:@"fire-iid"];
  31. XCTAssertEqual(heartbeatCode, FIRHeartbeatInfoCodeCombined);
  32. }
  33. - (void)testSdkOnlyHeartbeat {
  34. [self.dataStorage setHearbeatDate:[NSDate date] forTag:@"GLOBAL"];
  35. FIRHeartbeatInfoCode heartbeatCode = [FIRHeartbeatInfo heartbeatCodeForTag:@"fire-iid"];
  36. XCTAssertEqual(heartbeatCode, FIRHeartbeatInfoCodeSDK);
  37. }
  38. - (void)testGlobalOnlyHeartbeat {
  39. [self.dataStorage setHearbeatDate:[NSDate date] forTag:@"fire-iid"];
  40. FIRHeartbeatInfoCode heartbeatCode = [FIRHeartbeatInfo heartbeatCodeForTag:@"fire-iid"];
  41. XCTAssertEqual(heartbeatCode, FIRHeartbeatInfoCodeGlobal);
  42. }
  43. - (void)testNoHeartbeat {
  44. [self.dataStorage setHearbeatDate:[NSDate date] forTag:@"fire-iid"];
  45. [self.dataStorage setHearbeatDate:[NSDate date] forTag:@"GLOBAL"];
  46. FIRHeartbeatInfoCode heartbeatCode = [FIRHeartbeatInfo heartbeatCodeForTag:@"fire-iid"];
  47. XCTAssertEqual(heartbeatCode, FIRHeartbeatInfoCodeNone);
  48. }
  49. @end