ObjCAPITests.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // Copyright 2022 Google LLC
  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 <XCTest/XCTest.h>
  15. @import FirebaseCore;
  16. @import FirebaseStorage;
  17. @interface ObjCAPICoverage : XCTestCase
  18. @end
  19. @implementation ObjCAPICoverage
  20. - (void)FIRStorageApis {
  21. FIRApp *app = [FIRApp defaultApp];
  22. FIRStorage *storage = [FIRStorage storage];
  23. storage = [FIRStorage storageForApp:app];
  24. storage = [FIRStorage storageWithURL:@"my-url"];
  25. storage = [FIRStorage storageForApp:app URL:@"my-url"];
  26. app = [storage app];
  27. app = storage.app;
  28. [storage setMaxUploadRetryTime:[storage maxUploadRetryTime]];
  29. storage.maxUploadRetryTime = storage.maxUploadRetryTime + 1;
  30. [storage setMaxDownloadRetryTime:[storage maxDownloadRetryTime]];
  31. storage.maxDownloadRetryTime = storage.maxDownloadRetryTime + 1;
  32. [storage setMaxOperationRetryTime:[storage maxOperationRetryTime]];
  33. [storage setCallbackQueue:[storage callbackQueue]];
  34. FIRStorageReference *ref = [storage reference];
  35. ref = [storage referenceForURL:@"my-url"];
  36. ref = [storage referenceWithPath:@"my-path"];
  37. [storage useEmulatorWithHost:@"my-host" port:123];
  38. }
  39. - (void)FIRStorageReferenceApis {
  40. FIRStorageReference *ref = [[FIRStorage storage] reference];
  41. [ref storage];
  42. [ref bucket];
  43. [ref fullPath];
  44. [ref name];
  45. ref = [ref root];
  46. ref = [ref parent];
  47. ref = [ref child:@"path"];
  48. NSData *data = [NSData data];
  49. FIRStorageUploadTask *task = [ref putData:data];
  50. task = [ref putData:data metadata:nil];
  51. task = [ref putData:data
  52. metadata:nil
  53. completion:^(FIRStorageMetadata *_Nullable metadata, NSError *_Nullable error){
  54. }];
  55. NSURL *file = [NSURL URLWithString:@"my-url"];
  56. task = [ref putFile:file];
  57. task = [ref putFile:file metadata:nil];
  58. task = [ref putFile:file
  59. metadata:nil
  60. completion:^(FIRStorageMetadata *_Nullable metadata, NSError *_Nullable error){
  61. }];
  62. FIRStorageDownloadTask *task2 =
  63. [ref dataWithMaxSize:123
  64. completion:^(NSData *_Nullable data, NSError *_Nullable error){
  65. }];
  66. [ref downloadURLWithCompletion:^(NSURL *_Nullable URL, NSError *_Nullable error){
  67. }];
  68. task2 = [ref writeToFile:file];
  69. task2 = [ref writeToFile:file
  70. completion:^(NSURL *_Nullable URL, NSError *_Nullable error){
  71. }];
  72. [ref listAllWithCompletion:^(FIRStorageListResult *_Nonnull result, NSError *_Nullable error){
  73. }];
  74. [ref listWithMaxResults:123
  75. completion:^(FIRStorageListResult *_Nonnull result, NSError *_Nullable error){
  76. }];
  77. [ref listWithMaxResults:123
  78. pageToken:@"my token"
  79. completion:^(FIRStorageListResult *_Nonnull result, NSError *_Nullable error){
  80. }];
  81. [ref metadataWithCompletion:^(FIRStorageMetadata *_Nullable metadata, NSError *_Nullable error) {
  82. [ref updateMetadata:metadata
  83. completion:^(FIRStorageMetadata *_Nullable metadata, NSError *_Nullable error){
  84. }];
  85. }];
  86. [ref deleteWithCompletion:^(NSError *_Nullable error){
  87. }];
  88. }
  89. #ifdef COCOAPODS
  90. - (void)FIRStorageConstantsTypedefs {
  91. FIRStorageHandle __unused handle;
  92. FIRStorageVoidDataError __unused funcPtr1;
  93. FIRStorageVoidError __unused funcPtr2;
  94. FIRStorageVoidMetadata __unused funcPtr3;
  95. FIRStorageVoidMetadataError __unused funcPtr4;
  96. FIRStorageVoidSnapshot __unused funcPtr5;
  97. FIRStorageVoidURLError __unused funcPtr6;
  98. }
  99. #endif
  100. - (void)FIRStorageListResultApis:(FIRStorageListResult *)result {
  101. NSArray<FIRStorageReference *> __unused *prefixes = [result prefixes];
  102. NSArray<FIRStorageReference *> __unused *items = [result items];
  103. NSString __unused *token = [result pageToken];
  104. }
  105. - (FIRStorageTaskStatus)taskStatuses:(FIRStorageTaskStatus)status {
  106. switch (status) {
  107. case FIRStorageTaskStatusUnknown:
  108. case FIRStorageTaskStatusResume:
  109. case FIRStorageTaskStatusProgress:
  110. case FIRStorageTaskStatusPause:
  111. case FIRStorageTaskStatusSuccess:
  112. case FIRStorageTaskStatusFailure:
  113. return status;
  114. }
  115. }
  116. - (FIRStorageErrorCode)errorCodes:(NSError *)error {
  117. switch (error.code) {
  118. case FIRStorageErrorCodeUnknown:
  119. case FIRStorageErrorCodeObjectNotFound:
  120. case FIRStorageErrorCodeBucketNotFound:
  121. case FIRStorageErrorCodeProjectNotFound:
  122. case FIRStorageErrorCodeQuotaExceeded:
  123. case FIRStorageErrorCodeUnauthenticated:
  124. case FIRStorageErrorCodeUnauthorized:
  125. case FIRStorageErrorCodeRetryLimitExceeded:
  126. case FIRStorageErrorCodeNonMatchingChecksum:
  127. case FIRStorageErrorCodeDownloadSizeExceeded:
  128. case FIRStorageErrorCodeCancelled:
  129. case FIRStorageErrorCodeInvalidArgument:
  130. return error.code;
  131. }
  132. return error.code;
  133. }
  134. - (void)FIRStorageMetadataApis {
  135. FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] initWithDictionary:@{}];
  136. [metadata bucket];
  137. [metadata setCacheControl:[metadata cacheControl]];
  138. [metadata setContentDisposition:[metadata contentDisposition]];
  139. [metadata setContentEncoding:[metadata contentEncoding]];
  140. [metadata setContentLanguage:[metadata contentLanguage]];
  141. [metadata setContentType:[metadata contentType]];
  142. [metadata md5Hash];
  143. [metadata generation];
  144. [metadata setCustomMetadata:[metadata customMetadata]];
  145. [metadata metageneration];
  146. [metadata name];
  147. [metadata path];
  148. [metadata size];
  149. [metadata timeCreated];
  150. [metadata updated];
  151. #pragma clang diagnostic push
  152. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  153. [metadata storageReference];
  154. #pragma clang diagnostic pop
  155. FIRStorageMetadata __unused *ref2 = [metadata initWithDictionary:@{}];
  156. NSDictionary<NSString *, id> __unused *dict = [metadata dictionaryRepresentation];
  157. [metadata isFile];
  158. [metadata isFolder];
  159. }
  160. - (void)FIRStorageObservableTaskApis {
  161. FIRStorageReference *ref = [[FIRStorage storage] reference];
  162. FIRStorageObservableTask *task = [ref writeToFile:[NSURL URLWithString:@"my-url"]];
  163. NSString __unused *handle = [task observeStatus:FIRStorageTaskStatusPause
  164. handler:^(FIRStorageTaskSnapshot *_Nonnull snapshot){
  165. }];
  166. [task removeObserverWithHandle:@"handle"];
  167. [task removeAllObserversForStatus:FIRStorageTaskStatusUnknown];
  168. [task removeAllObservers];
  169. }
  170. - (void)FIRStorageTaskApis {
  171. FIRStorageReference *ref = [[FIRStorage storage] reference];
  172. FIRStorageTask *task = [ref writeToFile:[NSURL URLWithString:@"my-url"]];
  173. [task snapshot];
  174. }
  175. - (void)FIRStorageTaskManagementApis:(id<FIRStorageTaskManagement>)task {
  176. [task enqueue];
  177. [task pause];
  178. [task cancel];
  179. [task resume];
  180. }
  181. - (void)FIRStorageTaskSnapshotApis:(FIRStorageTaskSnapshot *)snapshot {
  182. [snapshot task];
  183. [snapshot metadata];
  184. [snapshot reference];
  185. [snapshot progress];
  186. [snapshot error];
  187. [snapshot status];
  188. }
  189. @end