FIRHeartbeatInfoTest.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 <GoogleUtilities/GULHeartbeatDateStorage.h>
  15. #import <XCTest/XCTest.h>
  16. #import "FirebaseCore/Sources/Private/FIRHeartbeatInfo.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. NSDateComponents *componentsToAdd = [[NSDateComponents alloc] init];
  26. componentsToAdd.day = -1;
  27. NSDate *dayAgo = [[NSCalendar currentCalendar] dateByAddingComponents:componentsToAdd
  28. toDate:[NSDate date]
  29. options:0];
  30. [self.dataStorage setHearbeatDate:dayAgo forTag:@"fire-iid"];
  31. [self.dataStorage setHearbeatDate:dayAgo forTag:@"GLOBAL"];
  32. }
  33. - (void)testCombinedHeartbeat {
  34. FIRHeartbeatInfoCode heartbeatCode = [FIRHeartbeatInfo heartbeatCodeForTag:@"fire-iid"];
  35. XCTAssertEqual(heartbeatCode, FIRHeartbeatInfoCodeCombined);
  36. }
  37. - (void)testSdkOnlyHeartbeat {
  38. [self.dataStorage setHearbeatDate:[NSDate date] forTag:@"GLOBAL"];
  39. FIRHeartbeatInfoCode heartbeatCode = [FIRHeartbeatInfo heartbeatCodeForTag:@"fire-iid"];
  40. XCTAssertEqual(heartbeatCode, FIRHeartbeatInfoCodeSDK);
  41. }
  42. - (void)testGlobalOnlyHeartbeat {
  43. [self.dataStorage setHearbeatDate:[NSDate date] forTag:@"fire-iid"];
  44. FIRHeartbeatInfoCode heartbeatCode = [FIRHeartbeatInfo heartbeatCodeForTag:@"fire-iid"];
  45. XCTAssertEqual(heartbeatCode, FIRHeartbeatInfoCodeGlobal);
  46. }
  47. - (void)testNoHeartbeat {
  48. [self.dataStorage setHearbeatDate:[NSDate date] forTag:@"fire-iid"];
  49. [self.dataStorage setHearbeatDate:[NSDate date] forTag:@"GLOBAL"];
  50. FIRHeartbeatInfoCode heartbeatCode = [FIRHeartbeatInfo heartbeatCodeForTag:@"fire-iid"];
  51. XCTAssertEqual(heartbeatCode, FIRHeartbeatInfoCodeNone);
  52. }
  53. @end