ObjCPPAPITests.mm 7.2 KB

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