Skip to content

Commit f075fdc

Browse files
authored
Missing NSObject overrides and tests (#9715)
1 parent 9c7f22a commit f075fdc

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

FirebaseStorage/Sources/StorageListResult.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,18 @@ import FirebaseStorageInternal
4141
*/
4242
@objc public let pageToken: String?
4343

44+
// MARK: - NSObject overrides
45+
46+
@objc override open func copy() -> Any {
47+
return StorageListResult(impl.copy() as! FIRIMPLStorageListResult)
48+
}
49+
50+
// MARK: - Internal APIs
51+
52+
internal let impl: FIRIMPLStorageListResult
53+
4454
internal init(_ impl: FIRIMPLStorageListResult) {
55+
self.impl = impl
4556
prefixes = impl.prefixes.map { StorageReference($0) }
4657
items = impl.items.map { StorageReference($0) }
4758
pageToken = impl.pageToken

FirebaseStorage/Sources/StorageMetadata.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,27 @@ import FirebaseStorageInternal
182182
self.init(impl: FIRIMPLStorageMetadata(dictionary: dictionary)!)
183183
}
184184

185+
// MARK: - NSObject overrides
186+
187+
@objc override open func copy() -> Any {
188+
return StorageMetadata(impl: impl.copy() as! FIRIMPLStorageMetadata)
189+
}
190+
191+
@objc override open func isEqual(_ object: Any?) -> Bool {
192+
guard let ref = object as? StorageMetadata else {
193+
return false
194+
}
195+
return impl.isEqual(ref.impl)
196+
}
197+
198+
@objc override public var hash: Int {
199+
return impl.hash
200+
}
201+
202+
@objc override public var description: String {
203+
return impl.description
204+
}
205+
185206
// MARK: - Internal APIs
186207

187208
internal let impl: FIRIMPLStorageMetadata
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
15+
import Foundation
16+
17+
import FirebaseStorage
18+
19+
import XCTest
20+
21+
class StorageMetadataTests: XCTestCase {
22+
func testReflexiveMetadataEquality() {
23+
let metaDict = ["bucket": "bucket", "name": "/path/to/file"]
24+
let metadata0 = StorageMetadata(dictionary: metaDict)
25+
let metadata1 = metadata0
26+
XCTAssertEqual(metadata0, metadata1)
27+
}
28+
29+
func testMetadataEquality() {
30+
let metaDict = [
31+
"bucket": "bucket",
32+
"name": "/path/to/file",
33+
"md5Hash": "d41d8cd98f00b204e9800998ecf8427e",
34+
]
35+
let metadata0 = StorageMetadata(dictionary: metaDict)
36+
let metadata1 = StorageMetadata(dictionary: metaDict)
37+
XCTAssertEqual(metadata0, metadata1)
38+
}
39+
40+
func testMetadataMd5Inequality() {
41+
let metaDict0 = ["md5Hash": "d41d8cd98f00b204e9800998ecf8427e"]
42+
let metaDict1 = ["md5Hash": "d41d8cd98f00b204e9800998ecf8427f"]
43+
let metadata0 = StorageMetadata(dictionary: metaDict0)
44+
let metadata1 = StorageMetadata(dictionary: metaDict1)
45+
XCTAssertNotEqual(metadata0, metadata1)
46+
}
47+
48+
func testMetadataCopy() {
49+
let metaDict = [
50+
"bucket": "bucket",
51+
"name": "/path/to/file",
52+
"md5Hash": "d41d8cd98f00b204e9800998ecf8427e",
53+
]
54+
let metadata0 = StorageMetadata(dictionary: metaDict)
55+
let metadata1 = metadata0.copy() as? StorageMetadata
56+
// Verify that copied object has a new reference.
57+
XCTAssertFalse(metadata0 === metadata1)
58+
XCTAssertEqual(metadata0, metadata1)
59+
}
60+
}

FirebaseStorageInternal/Tests/Integration/FIRStorageIntegrationTests.m

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ - (void)testSameInstanceCustomBucket {
149149
XCTAssertEqual(storage1, storage2);
150150
}
151151

152-
- (void)testDiffferentInstance {
152+
- (void)testDifferentInstance {
153153
FIRStorage *storage1 = [FIRStorage storageForApp:self.app];
154154
FIRStorage *storage2 = [FIRStorage storageForApp:self.app URL:@"gs://foo-bar.appspot.com"];
155155
XCTAssertNotEqual(storage1, storage2);
@@ -175,6 +175,22 @@ - (void)testGetMetadata {
175175
[self waitForExpectations];
176176
}
177177

178+
- (void)testCopyMetadata {
179+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetMetadata"];
180+
FIRStorageReference *ref = [self.storage.reference child:@"ios/public/1mb"];
181+
182+
[ref metadataWithCompletion:^(FIRStorageMetadata *metadata, NSError *error) {
183+
XCTAssertNotNil(metadata, "Metadata should not be nil");
184+
XCTAssertNil(error, "Error should be nil");
185+
FIRStorageMetadata *metadata2 = metadata.copy;
186+
XCTAssertNotEqual(metadata, metadata2);
187+
XCTAssertEqualObjects(metadata, metadata2);
188+
[expectation fulfill];
189+
}];
190+
191+
[self waitForExpectations];
192+
}
193+
178194
- (void)testDelete {
179195
XCTestExpectation *expectation = [self expectationWithDescription:@"testDelete"];
180196

@@ -829,6 +845,25 @@ - (void)testListFilesAtRoot {
829845
[self waitForExpectations];
830846
}
831847

848+
- (void)testCopyListResult {
849+
XCTestExpectation *expectation = [self expectationWithDescription:@"testCopyListResult"];
850+
851+
FIRStorageReference *ref = [self.storage referenceWithPath:@""];
852+
853+
[ref listAllWithCompletion:^(FIRStorageListResult *_Nullable listResult,
854+
NSError *_Nullable error) {
855+
XCTAssertNotNil(listResult);
856+
XCTAssertNil(error);
857+
XCTAssertNil(listResult.pageToken);
858+
FIRStorageListResult *listResult2 = listResult.copy;
859+
XCTAssertEqual(listResult.pageToken, listResult2.pageToken);
860+
XCTAssertNotEqual(listResult, listResult2);
861+
[expectation fulfill];
862+
}];
863+
864+
[self waitForExpectations];
865+
}
866+
832867
- (void)waitForExpectations {
833868
[self waitForExpectationsWithTimeout:kFIRStorageIntegrationTestTimeout
834869
handler:^(NSError *_Nullable error) {

0 commit comments

Comments
 (0)