FSTAPIHelpers.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FIRCollectionReference;
  18. @class FIRDocumentReference;
  19. @class FIRDocumentSnapshot;
  20. @class FIRFirestore;
  21. @class FIRQuerySnapshot;
  22. /** Allow tests to just use an int literal for versions. */
  23. typedef int64_t FSTTestSnapshotVersion;
  24. NS_ASSUME_NONNULL_BEGIN
  25. #if __cplusplus
  26. extern "C" {
  27. #endif
  28. /** A convenience method for creating dummy singleton FIRFirestore for tests. */
  29. FIRFirestore *FSTTestFirestore();
  30. /** A convenience method for creating a doc snapshot for tests. */
  31. FIRDocumentSnapshot *FSTTestDocSnapshot(const char *path,
  32. FSTTestSnapshotVersion version,
  33. NSDictionary<NSString *, id> *_Nullable data,
  34. BOOL hasMutations,
  35. BOOL fromCache);
  36. /** A convenience method for creating a collection reference from a path string. */
  37. FIRCollectionReference *FSTTestCollectionRef(const char *path);
  38. /** A convenience method for creating a document reference from a path string. */
  39. FIRDocumentReference *FSTTestDocRef(const char *path);
  40. /**
  41. * A convenience method for creating a particular query snapshot for tests.
  42. *
  43. * @param path To be used in constructing the query.
  44. * @param oldDocs Provides the prior set of documents in the QuerySnapshot. Each dictionary entry
  45. * maps to a document, with the key being the document id, and the value being the document
  46. * contents.
  47. * @param docsToAdd Specifies data to be added into the query snapshot as of now. Each dictionary
  48. * entry maps to a document, with the key being the document id, and the value being the document
  49. * contents.
  50. * @param hasPendingWrites Whether the query snapshot has pending writes to the server.
  51. * @param fromCache Whether the query snapshot is cache result.
  52. * @param hasCachedResults Whether the query snapshot has results in the cache.
  53. * @return A query snapshot that consists of both sets of documents.
  54. */
  55. FIRQuerySnapshot *FSTTestQuerySnapshot(
  56. const char *path,
  57. NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs,
  58. NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
  59. BOOL hasPendingWrites,
  60. BOOL fromCache,
  61. BOOL hasCachedResults);
  62. #if __cplusplus
  63. } // extern "C"
  64. #endif
  65. @interface FSTNSExceptionUtil : NSObject
  66. + (BOOL)testForException:(void (^)(void))methodToTry
  67. reasonContains:(nonnull NSString *)message
  68. NS_SWIFT_NAME(testForException(_:reasonContains:));
  69. @end
  70. NS_ASSUME_NONNULL_END