Skip to content

Missing NSObject overrides and tests #9715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions FirebaseStorage/Sources/StorageListResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ import FirebaseStorageInternal
*/
@objc public let pageToken: String?

// MARK: - NSObject overrides

@objc override open func copy() -> Any {
return StorageListResult(impl.copy() as! FIRIMPLStorageListResult)
}

// MARK: - Internal APIs

internal let impl: FIRIMPLStorageListResult

internal init(_ impl: FIRIMPLStorageListResult) {
self.impl = impl
prefixes = impl.prefixes.map { StorageReference($0) }
items = impl.items.map { StorageReference($0) }
pageToken = impl.pageToken
Expand Down
21 changes: 21 additions & 0 deletions FirebaseStorage/Sources/StorageMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ import FirebaseStorageInternal
self.init(impl: FIRIMPLStorageMetadata(dictionary: dictionary)!)
}

// MARK: - NSObject overrides

@objc override open func copy() -> Any {
return StorageMetadata(impl: impl.copy() as! FIRIMPLStorageMetadata)
}

@objc override open func isEqual(_ object: Any?) -> Bool {
guard let ref = object as? StorageMetadata else {
return false
}
return impl.isEqual(ref.impl)
}

@objc override public var hash: Int {
return impl.hash
}

@objc override public var description: String {
return impl.description
}

// MARK: - Internal APIs

internal let impl: FIRIMPLStorageMetadata
Expand Down
60 changes: 60 additions & 0 deletions FirebaseStorage/Tests/Unit/StorageMetadataTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

import FirebaseStorage

import XCTest

class StorageMetadataTests: XCTestCase {
func testReflexiveMetadataEquality() {
let metaDict = ["bucket": "bucket", "name": "/path/to/file"]
let metadata0 = StorageMetadata(dictionary: metaDict)
let metadata1 = metadata0
XCTAssertEqual(metadata0, metadata1)
}

func testMetadataEquality() {
let metaDict = [
"bucket": "bucket",
"name": "/path/to/file",
"md5Hash": "d41d8cd98f00b204e9800998ecf8427e",
]
let metadata0 = StorageMetadata(dictionary: metaDict)
let metadata1 = StorageMetadata(dictionary: metaDict)
XCTAssertEqual(metadata0, metadata1)
}

func testMetadataMd5Inequality() {
let metaDict0 = ["md5Hash": "d41d8cd98f00b204e9800998ecf8427e"]
let metaDict1 = ["md5Hash": "d41d8cd98f00b204e9800998ecf8427f"]
let metadata0 = StorageMetadata(dictionary: metaDict0)
let metadata1 = StorageMetadata(dictionary: metaDict1)
XCTAssertNotEqual(metadata0, metadata1)
}

func testMetadataCopy() {
let metaDict = [
"bucket": "bucket",
"name": "/path/to/file",
"md5Hash": "d41d8cd98f00b204e9800998ecf8427e",
]
let metadata0 = StorageMetadata(dictionary: metaDict)
let metadata1 = metadata0.copy() as? StorageMetadata
// Verify that copied object has a new reference.
XCTAssertFalse(metadata0 === metadata1)
XCTAssertEqual(metadata0, metadata1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ - (void)testSameInstanceCustomBucket {
XCTAssertEqual(storage1, storage2);
}

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

- (void)testCopyMetadata {
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetMetadata"];
FIRStorageReference *ref = [self.storage.reference child:@"ios/public/1mb"];

[ref metadataWithCompletion:^(FIRStorageMetadata *metadata, NSError *error) {
XCTAssertNotNil(metadata, "Metadata should not be nil");
XCTAssertNil(error, "Error should be nil");
FIRStorageMetadata *metadata2 = metadata.copy;
XCTAssertNotEqual(metadata, metadata2);
XCTAssertEqualObjects(metadata, metadata2);
[expectation fulfill];
}];

[self waitForExpectations];
}

- (void)testDelete {
XCTestExpectation *expectation = [self expectationWithDescription:@"testDelete"];

Expand Down Expand Up @@ -829,6 +845,25 @@ - (void)testListFilesAtRoot {
[self waitForExpectations];
}

- (void)testCopyListResult {
XCTestExpectation *expectation = [self expectationWithDescription:@"testCopyListResult"];

FIRStorageReference *ref = [self.storage referenceWithPath:@""];

[ref listAllWithCompletion:^(FIRStorageListResult *_Nullable listResult,
NSError *_Nullable error) {
XCTAssertNotNil(listResult);
XCTAssertNil(error);
XCTAssertNil(listResult.pageToken);
FIRStorageListResult *listResult2 = listResult.copy;
XCTAssertEqual(listResult.pageToken, listResult2.pageToken);
XCTAssertNotEqual(listResult, listResult2);
[expectation fulfill];
}];

[self waitForExpectations];
}

- (void)waitForExpectations {
[self waitForExpectationsWithTimeout:kFIRStorageIntegrationTestTimeout
handler:^(NSError *_Nullable error) {
Expand Down