FIRTestComponents.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright 2018 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 "FIRTestComponents.h"
  15. #import <FirebaseCore/FIRComponent.h>
  16. #pragma mark - Standard Component
  17. @implementation FIRTestClass
  18. /// FIRTestProtocol conformance.
  19. - (void)doSomething {
  20. }
  21. /// FIRComponentRegistrant conformance.
  22. + (nonnull NSArray<FIRComponent *> *)componentsToRegister {
  23. FIRComponent *testComponent =
  24. [FIRComponent componentWithProtocol:@protocol(FIRTestProtocol)
  25. creationBlock:^id _Nullable(FIRComponentContainer *_Nonnull container,
  26. BOOL *_Nonnull isCacheable) {
  27. return [[FIRTestClass alloc] init];
  28. }];
  29. return @[ testComponent ];
  30. }
  31. /// FIRComponentLifecycleMaintainer conformance.
  32. - (void)appWillBeDeleted:(FIRApp *)app {
  33. }
  34. @end
  35. /// A test class that is a component registrant, a duplicate of FIRTestClass.
  36. @implementation FIRTestClassDuplicate
  37. - (void)doSomething {
  38. }
  39. /// FIRLibrary conformance.
  40. + (nonnull NSArray<FIRComponent *> *)componentsToRegister {
  41. FIRComponent *testComponent =
  42. [FIRComponent componentWithProtocol:@protocol(FIRTestProtocol)
  43. creationBlock:^id _Nullable(FIRComponentContainer *_Nonnull container,
  44. BOOL *_Nonnull isCacheable) {
  45. return [[FIRTestClassDuplicate alloc] init];
  46. }];
  47. return @[ testComponent ];
  48. }
  49. /// FIRComponentLifecycleMaintainer conformance.
  50. - (void)appWillBeDeleted:(FIRApp *)app {
  51. }
  52. @end
  53. #pragma mark - Eager Component
  54. @implementation FIRTestClassEagerCached
  55. /// FIRTestProtocolEager conformance.
  56. - (void)doSomethingFaster {
  57. }
  58. /// FIRLibrary conformance.
  59. + (nonnull NSArray<FIRComponent *> *)componentsToRegister {
  60. FIRComponent *testComponent = [FIRComponent
  61. componentWithProtocol:@protocol(FIRTestProtocolEagerCached)
  62. instantiationTiming:FIRInstantiationTimingAlwaysEager
  63. dependencies:@[]
  64. creationBlock:^id _Nullable(FIRComponentContainer *_Nonnull container,
  65. BOOL *_Nonnull isCacheable) {
  66. FIRTestClassEagerCached *instance = [[FIRTestClassEagerCached alloc] init];
  67. *isCacheable = YES;
  68. [instance doSomethingFaster];
  69. return instance;
  70. }];
  71. return @[ testComponent ];
  72. }
  73. /// FIRComponentLifecycleMaintainer conformance.
  74. - (void)appWillBeDeleted:(FIRApp *)app {
  75. }
  76. - (void)doSomething {
  77. }
  78. @end
  79. #pragma mark - Cached Component
  80. @implementation FIRTestClassCached
  81. /// FIRLibrary conformance.
  82. + (nonnull NSArray<FIRComponent *> *)componentsToRegister {
  83. FIRComponent *testComponent = [FIRComponent
  84. componentWithProtocol:@protocol(FIRTestProtocolCached)
  85. creationBlock:^id _Nullable(FIRComponentContainer *_Nonnull container,
  86. BOOL *_Nonnull isCacheable) {
  87. FIRTestClassCached *instanceToCache = [[FIRTestClassCached alloc] init];
  88. *isCacheable = YES;
  89. return instanceToCache;
  90. }];
  91. return @[ testComponent ];
  92. }
  93. /// FIRComponentLifecycleMaintainer conformance.
  94. - (void)appWillBeDeleted:(FIRApp *)app {
  95. }
  96. - (void)doSomething {
  97. }
  98. @end