Files
firebase-ios-sdk/Firestore/Example/Tests/Local/FSTReferenceSetTests.m
T
zxu 9ddf3637ac Firestore isEqual() on Public Types (#569)
* add bone code for new isEqual and unit test for old isEqual

*   add bone code for `FIRCollectionReference`, `FIRDocumentSnapshot`, `FIRFieldValue`, `FIRQuerySnapshot`, `FIRSnapshotMetadata`;
*   change inconsistenciness of `FIRFieldPath.isEqual` implementation;
*   add unit test (and file) for `FIRDocumentReferenceTest.m`, `FIRFieldPathTest.m`, `FIRQueryTests.testEquals`; `FIRGeoPoint` already has test and Blob is internal type.

* Implement isEqual for FIRCollectionReference

adding the working code and unit test.

* implement isEqual for FIRSnapshotMetadata

* Implement isEqual for FIRDocumentSnapshot

* Implement isEqual for FIRQuerySnapshot

* (un)implement `isEqual` for `FIRFieldValue`

Since `FIRFieldValue` both types are singleton, we do not need override `isEqual`. Add test to test the default `NSObject` `isEqual` works just fine.

* fix style with `scripts/style.sh`

* Implement hash for those with overridden isEqual without hash yet.

* refactor to use test helper functions -- FSTTestFirestore, FSTTestPath, FSTTestDocKey

* refactor using test helper `FSTTestDocSnapshot`, `FSTTestFieldPath`, `FSTTestQuery`, `FSTTestDoc`

* refactoring to use test helper method `FSTTestQuerySnapshot`,

* remove unneccessary nil-check, check isKindOfClass instead of isEqual

* refactoring: adding `FSTAPIHelpers.{h,m}`, `FSTTest{Collection,Document}Ref`,  better naming and style fix

* a file forgot in last commit

* mainly clean up import and some minor refactoring

* fix style via style.sh

* minor style fix

* add pragma ignored -Wnonnull
2017-12-19 13:47:04 -05:00

86 lines
2.8 KiB
Objective-C

/*
* Copyright 2017 Google
*
* 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 "Firestore/Source/Local/FSTReferenceSet.h"
#import <XCTest/XCTest.h>
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
#import "Firestore/Source/Model/FSTDocumentKey.h"
NS_ASSUME_NONNULL_BEGIN
@interface FSTReferenceSetTests : XCTestCase
@end
@implementation FSTReferenceSetTests
- (void)testAddOrRemoveReferences {
FSTDocumentKey *key = FSTTestDocKey(@"foo/bar");
FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init];
XCTAssertTrue([referenceSet isEmpty]);
XCTAssertFalse([referenceSet containsKey:key]);
[referenceSet addReferenceToKey:key forID:1];
XCTAssertTrue([referenceSet containsKey:key]);
XCTAssertFalse([referenceSet isEmpty]);
[referenceSet addReferenceToKey:key forID:2];
XCTAssertTrue([referenceSet containsKey:key]);
[referenceSet removeReferenceToKey:key forID:1];
XCTAssertTrue([referenceSet containsKey:key]);
[referenceSet removeReferenceToKey:key forID:3];
XCTAssertTrue([referenceSet containsKey:key]);
[referenceSet removeReferenceToKey:key forID:2];
XCTAssertFalse([referenceSet containsKey:key]);
XCTAssertTrue([referenceSet isEmpty]);
}
- (void)testRemoveAllReferencesForTargetID {
FSTDocumentKey *key1 = FSTTestDocKey(@"foo/bar");
FSTDocumentKey *key2 = FSTTestDocKey(@"foo/baz");
FSTDocumentKey *key3 = FSTTestDocKey(@"foo/blah");
FSTReferenceSet *referenceSet = [[FSTReferenceSet alloc] init];
[referenceSet addReferenceToKey:key1 forID:1];
[referenceSet addReferenceToKey:key2 forID:1];
[referenceSet addReferenceToKey:key3 forID:2];
XCTAssertFalse([referenceSet isEmpty]);
XCTAssertTrue([referenceSet containsKey:key1]);
XCTAssertTrue([referenceSet containsKey:key2]);
XCTAssertTrue([referenceSet containsKey:key3]);
[referenceSet removeReferencesForID:1];
XCTAssertFalse([referenceSet isEmpty]);
XCTAssertFalse([referenceSet containsKey:key1]);
XCTAssertFalse([referenceSet containsKey:key2]);
XCTAssertTrue([referenceSet containsKey:key3]);
[referenceSet removeReferencesForID:2];
XCTAssertTrue([referenceSet isEmpty]);
XCTAssertFalse([referenceSet containsKey:key1]);
XCTAssertFalse([referenceSet containsKey:key2]);
XCTAssertFalse([referenceSet containsKey:key3]);
}
@end
NS_ASSUME_NONNULL_END