mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-10 22:45:59 +05:45
* Remove rarely used template argumnets from SortedMap/SortedSet * Remove unused STATUS_CHECK_OK * Rename QuerySnapshot::Listener to QuerySnapshotListener This makes the type something that can be forward declared. * Rename DocumentSnapshot::Listener to DocumentSnapshotListener This makes the type something that can be forward declared. * Rename ViewSnapshot::Listener to ViewSnapshotListener This makes the type something that can be forward declared. * Put most QueryListener implementation in .cc * Actually use sync_engine_callback.h * Add forward declaration headers for api, core, and model These centralize forward declarations, including declarations for some hard-to-forward-declare types. * Move includes of hard_assert.h out of other headers * Make testutil definitions out of line * Move definitions out-of-line * Move DocumentKey definitions out-of-line * Move definitions out-of-line * Shorten unnecessarily long namespace usages * Use default destructors where possible * Delete unused MutationBatch::kUnknown constant * Use forward declarations instead of IWYU * Misc fixups from Linux/GCC 9.2.1 * Fix testutil under VS 2017 Forward declarations of functions local to a function body end up generating unresolved externals. Reduce most of these back to just calling FieldValue::FromX methods.
143 lines
6.5 KiB
Objective-C
143 lines
6.5 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 <Foundation/Foundation.h>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "Firestore/core/src/firebase/firestore/model/model_fwd.h"
|
|
#include "absl/strings/string_view.h"
|
|
|
|
@class FIRGeoPoint;
|
|
@class FSTDocumentKeyReference;
|
|
@class FSTUserDataConverter;
|
|
|
|
namespace model = firebase::firestore::model;
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
/**
|
|
* Takes an array of "equality group" arrays and asserts that the compare: selector returns the
|
|
* same as compare: on the indexes of the "equality groups" (NSOrderedSame for items in the same
|
|
* group).
|
|
*/
|
|
#define FSTAssertComparisons(values) \
|
|
do { \
|
|
for (NSUInteger i = 0; i < [values count]; i++) { \
|
|
for (id left in values[i]) { \
|
|
for (NSUInteger j = 0; j < [values count]; j++) { \
|
|
for (id right in values[j]) { \
|
|
NSComparisonResult expected = [@(i) compare:@(j)]; \
|
|
NSComparisonResult result = [left compare:right]; \
|
|
NSComparisonResult inverseResult = [right compare:left]; \
|
|
XCTAssertEqual(result, expected, @"comparing %@ with %@ at (%lu, %lu)", left, right, \
|
|
(unsigned long)i, (unsigned long)j); \
|
|
XCTAssertEqual(inverseResult, -expected, @"comparing %@ with %@ at (%lu, %lu)", right, \
|
|
left, (unsigned long)j, (unsigned long)i); \
|
|
} \
|
|
} \
|
|
} \
|
|
} \
|
|
} while (0)
|
|
|
|
static NSString *kExceptionPrefix = @"FIRESTORE INTERNAL ASSERTION FAILED: ";
|
|
|
|
// Remove possible exception-prefix.
|
|
inline NSString *FSTRemoveExceptionPrefix(NSString *exception) {
|
|
if ([exception hasPrefix:kExceptionPrefix]) {
|
|
return [exception substringFromIndex:kExceptionPrefix.length];
|
|
} else {
|
|
return exception;
|
|
}
|
|
}
|
|
|
|
// Helper for validating API exceptions.
|
|
#define FSTAssertThrows(expression, exceptionReason, ...) \
|
|
do { \
|
|
BOOL didThrow = NO; \
|
|
@try { \
|
|
(void)(expression); \
|
|
} @catch (NSException * exception) { \
|
|
didThrow = YES; \
|
|
XCTAssertEqualObjects(FSTRemoveExceptionPrefix(exception.reason), \
|
|
FSTRemoveExceptionPrefix(exceptionReason)); \
|
|
} \
|
|
XCTAssertTrue(didThrow, ##__VA_ARGS__); \
|
|
} while (0)
|
|
|
|
/** Creates a new NSDate from components. Note that year, month, and day are all one-based. */
|
|
NSDate *FSTTestDate(int year, int month, int day, int hour, int minute, int second);
|
|
|
|
/**
|
|
* Creates a new NSData from the var args of bytes, must be terminated with a negative byte
|
|
*/
|
|
NSData *FSTTestData(int bytes, ...);
|
|
|
|
// Note that FIRGeoPoint is a model class in addition to an API class, so we put this helper here
|
|
// instead of FSTAPIHelpers.h
|
|
/** Creates a new GeoPoint from the latitude and longitude values */
|
|
FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude);
|
|
|
|
/** Creates a user data converter set up for a generic project. */
|
|
FSTUserDataConverter *FSTTestUserDataConverter();
|
|
|
|
/**
|
|
* Creates a new NSDateComponents from components. Note that year, month, and day are all
|
|
* one-based.
|
|
*/
|
|
NSDateComponents *FSTTestDateComponents(
|
|
int year, int month, int day, int hour, int minute, int second);
|
|
|
|
/** Wraps a plain value into an FieldValue instance. */
|
|
model::FieldValue FSTTestFieldValue(id _Nullable value);
|
|
|
|
/** Wraps a NSDictionary value into an ObjectValue instance. */
|
|
model::ObjectValue FSTTestObjectValue(NSDictionary<NSString *, id> *data);
|
|
|
|
/** A convenience method for creating document keys for tests. */
|
|
model::DocumentKey FSTTestDocKey(NSString *path);
|
|
|
|
/** Allow tests to just use an int literal for versions. */
|
|
typedef int64_t FSTTestSnapshotVersion;
|
|
|
|
/**
|
|
* A convenience method for creating a document reference from a path string.
|
|
*/
|
|
FSTDocumentKeyReference *FSTTestRef(std::string projectID, std::string databaseID, NSString *path);
|
|
|
|
/** Creates a set mutation for the document key at the given path. */
|
|
model::SetMutation FSTTestSetMutation(NSString *path, NSDictionary<NSString *, id> *values);
|
|
|
|
/** Creates a patch mutation for the document key at the given path. */
|
|
model::PatchMutation FSTTestPatchMutation(
|
|
absl::string_view path,
|
|
NSDictionary<NSString *, id> *values,
|
|
const std::vector<firebase::firestore::model::FieldPath> &updateMask);
|
|
|
|
/**
|
|
* Creates a TransformMutation by parsing any FIRFieldValue sentinels in the provided data. The
|
|
* data is expected to use dotted-notation for nested fields (i.e.
|
|
* @{ @"foo.bar": [FIRFieldValue ...] } and must not contain any non-sentinel data.
|
|
*/
|
|
model::TransformMutation FSTTestTransformMutation(NSString *path,
|
|
NSDictionary<NSString *, id> *data);
|
|
|
|
/** Creates a delete mutation for the document key at the given path. */
|
|
model::DeleteMutation FSTTestDeleteMutation(NSString *path);
|
|
|
|
NS_ASSUME_NONNULL_END
|