FSTIntegrationTestCase.mm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /*
  2. * Copyright 2017 Google LLC
  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 "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
  17. #import <FirebaseFirestore/FIRCollectionReference.h>
  18. #import <FirebaseFirestore/FIRDocumentChange.h>
  19. #import <FirebaseFirestore/FIRDocumentReference.h>
  20. #import <FirebaseFirestore/FIRDocumentSnapshot.h>
  21. #import <FirebaseFirestore/FIRFirestore.h>
  22. #import <FirebaseFirestore/FIRFirestoreSettings.h>
  23. #import <FirebaseFirestore/FIRQuerySnapshot.h>
  24. #import <FirebaseFirestore/FIRSnapshotMetadata.h>
  25. #import <FirebaseFirestore/FIRTransaction.h>
  26. #include <memory>
  27. #include <string>
  28. #include <utility>
  29. #import "FirebaseCore/Extension/FIRAppInternal.h"
  30. #import "FirebaseCore/Extension/FIRLogger.h"
  31. #import "FirebaseCore/Extension/FIROptionsInternal.h"
  32. #import "Firestore/Example/Tests/Util/FIRFirestore+Testing.h"
  33. #import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
  34. #import "Firestore/Source/API/FIRAggregateQuery+Internal.h"
  35. #import "Firestore/Source/API/FIRFirestore+Internal.h"
  36. #include "Firestore/core/src/credentials/credentials_provider.h"
  37. #include "Firestore/core/src/credentials/empty_credentials_provider.h"
  38. #include "Firestore/core/src/credentials/user.h"
  39. #include "Firestore/core/src/local/leveldb_opener.h"
  40. #include "Firestore/core/src/model/database_id.h"
  41. #include "Firestore/core/src/remote/firebase_metadata_provider_apple.h"
  42. #include "Firestore/core/src/remote/grpc_connection.h"
  43. #include "Firestore/core/src/util/async_queue.h"
  44. #include "Firestore/core/src/util/autoid.h"
  45. #include "Firestore/core/src/util/filesystem.h"
  46. #include "Firestore/core/src/util/path.h"
  47. #include "Firestore/core/src/util/string_apple.h"
  48. #include "Firestore/core/test/unit/testutil/app_testing.h"
  49. #include "Firestore/core/test/unit/testutil/async_testing.h"
  50. #include "Firestore/core/test/unit/testutil/status_testing.h"
  51. #include "absl/memory/memory.h"
  52. using firebase::firestore::core::DatabaseInfo;
  53. using firebase::firestore::credentials::CredentialChangeListener;
  54. using firebase::firestore::credentials::EmptyAppCheckCredentialsProvider;
  55. using firebase::firestore::credentials::EmptyAuthCredentialsProvider;
  56. using firebase::firestore::credentials::User;
  57. using firebase::firestore::local::LevelDbOpener;
  58. using firebase::firestore::model::DatabaseId;
  59. using firebase::firestore::remote::FirebaseMetadataProviderApple;
  60. using firebase::firestore::testutil::AppForUnitTesting;
  61. using firebase::firestore::testutil::AsyncQueueForTesting;
  62. using firebase::firestore::util::AsyncQueue;
  63. using firebase::firestore::util::CreateAutoId;
  64. using firebase::firestore::util::Filesystem;
  65. using firebase::firestore::util::MakeString;
  66. using firebase::firestore::util::Path;
  67. using firebase::firestore::util::Status;
  68. using firebase::firestore::util::StatusOr;
  69. NS_ASSUME_NONNULL_BEGIN
  70. /**
  71. * Firestore databases can be subject to a ~30s "cold start" delay if they have not been used
  72. * recently, so before any tests run we "prime" the backend.
  73. */
  74. static const double kPrimingTimeout = 45.0;
  75. static NSString *defaultProjectId;
  76. static FIRFirestoreSettings *defaultSettings;
  77. static bool runningAgainstEmulator = false;
  78. // Behaves the same as `EmptyCredentialsProvider` except it can also trigger a user
  79. // change.
  80. class FakeAuthCredentialsProvider : public EmptyAuthCredentialsProvider {
  81. public:
  82. void SetCredentialChangeListener(CredentialChangeListener<User> changeListener) override {
  83. if (changeListener) {
  84. listener_ = std::move(changeListener);
  85. listener_(User::Unauthenticated());
  86. }
  87. }
  88. void ChangeUser(NSString *new_id) {
  89. if (listener_) {
  90. listener_(firebase::firestore::credentials::User::FromUid(new_id));
  91. }
  92. }
  93. private:
  94. CredentialChangeListener<User> listener_;
  95. };
  96. @implementation FSTIntegrationTestCase {
  97. NSMutableArray<FIRFirestore *> *_firestores;
  98. std::shared_ptr<EmptyAppCheckCredentialsProvider> _fakeAppCheckCredentialsProvider;
  99. std::shared_ptr<FakeAuthCredentialsProvider> _fakeAuthCredentialsProvider;
  100. }
  101. - (void)setUp {
  102. [super setUp];
  103. LoadXCTestCaseAwait();
  104. _fakeAppCheckCredentialsProvider = std::make_shared<EmptyAppCheckCredentialsProvider>();
  105. _fakeAuthCredentialsProvider = std::make_shared<FakeAuthCredentialsProvider>();
  106. [self clearPersistenceOnce];
  107. [self primeBackend];
  108. _firestores = [NSMutableArray array];
  109. self.db = [self firestore];
  110. self.eventAccumulator = [FSTEventAccumulator accumulatorForTest:self];
  111. }
  112. - (void)tearDown {
  113. @try {
  114. for (FIRFirestore *firestore in _firestores) {
  115. [self terminateFirestore:firestore];
  116. }
  117. } @finally {
  118. _firestores = nil;
  119. [super tearDown];
  120. }
  121. }
  122. /**
  123. * Clears persistence, but only the first time. This ensures that each test
  124. * run is isolated from the last test run, but doesn't allow tests to interfere
  125. * with each other.
  126. */
  127. - (void)clearPersistenceOnce {
  128. auto *fs = Filesystem::Default();
  129. static bool clearedPersistence = false;
  130. @synchronized([FSTIntegrationTestCase class]) {
  131. if (clearedPersistence) return;
  132. DatabaseInfo dbInfo;
  133. LevelDbOpener opener(dbInfo);
  134. StatusOr<Path> maybeLevelDBDir = opener.FirestoreAppDataDir();
  135. ASSERT_OK(maybeLevelDBDir.status());
  136. Path levelDBDir = std::move(maybeLevelDBDir).ValueOrDie();
  137. Status status = fs->RecursivelyRemove(levelDBDir);
  138. ASSERT_OK(status);
  139. clearedPersistence = true;
  140. }
  141. }
  142. - (FIRFirestore *)firestore {
  143. return [self firestoreWithProjectID:[FSTIntegrationTestCase projectID]];
  144. }
  145. /**
  146. * Figures out what kind of testing environment we're using, and sets up testing defaults to make
  147. * that work.
  148. *
  149. * Several configurations are supported:
  150. * * Mobile Harness, running periocally against prod and nightly, using live SSL certs
  151. * * Firestore emulator, running on localhost, with SSL disabled
  152. *
  153. * See Firestore/README.md for detailed setup instructions or comments below for which specific
  154. * values trigger which configurations.
  155. */
  156. + (void)setUpDefaults {
  157. if (defaultSettings) return;
  158. defaultSettings = [[FIRFirestoreSettings alloc] init];
  159. // Check for a MobileHarness configuration, running against nightly or prod, which have live
  160. // SSL certs.
  161. NSString *project = [[NSProcessInfo processInfo] environment][@"PROJECT_ID"];
  162. NSString *host = [[NSProcessInfo processInfo] environment][@"DATASTORE_HOST"];
  163. if (project && host) {
  164. defaultProjectId = project;
  165. defaultSettings.host = host;
  166. NSLog(@"Integration tests running against %@/%@", defaultSettings.host, defaultProjectId);
  167. return;
  168. }
  169. // Check for configuration of a prod project via GoogleServices-Info.plist.
  170. FIROptions *options = [FIROptions defaultOptions];
  171. if (options && ![options.projectID isEqualToString:@"abc-xyz-123"]) {
  172. defaultProjectId = options.projectID;
  173. if (host) {
  174. // Allow access to nightly or other hosts via this mechanism too.
  175. defaultSettings.host = host;
  176. }
  177. NSLog(@"Integration tests running against %@/%@", defaultSettings.host, defaultProjectId);
  178. return;
  179. }
  180. // Otherwise fall back on assuming the emulator or localhost.
  181. defaultProjectId = @"test-db";
  182. defaultSettings.host = @"localhost:8080";
  183. defaultSettings.sslEnabled = false;
  184. runningAgainstEmulator = true;
  185. NSLog(@"Integration tests running against the emulator at %@/%@", defaultSettings.host,
  186. defaultProjectId);
  187. }
  188. + (NSString *)projectID {
  189. if (!defaultProjectId) {
  190. [self setUpDefaults];
  191. }
  192. return defaultProjectId;
  193. }
  194. + (bool)isRunningAgainstEmulator {
  195. // The only way to determine whether or not we're running against the emulator is to figure out
  196. // which testing environment we're using. Essentially `setUpDefaults` determines
  197. // `runningAgainstEmulator` as a side effect.
  198. if (!defaultProjectId) {
  199. [self setUpDefaults];
  200. }
  201. return runningAgainstEmulator;
  202. }
  203. + (FIRFirestoreSettings *)settings {
  204. [self setUpDefaults];
  205. return defaultSettings;
  206. }
  207. - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {
  208. FIRApp *app = AppForUnitTesting(MakeString(projectID));
  209. return [self firestoreWithApp:app];
  210. }
  211. - (FIRFirestore *)firestoreWithApp:(FIRApp *)app {
  212. NSString *persistenceKey = [NSString stringWithFormat:@"db%lu", (unsigned long)_firestores.count];
  213. FIRSetLoggerLevel(FIRLoggerLevelDebug);
  214. std::string projectID = MakeString(app.options.projectID);
  215. FIRFirestore *firestore =
  216. [[FIRFirestore alloc] initWithDatabaseID:DatabaseId(projectID)
  217. persistenceKey:MakeString(persistenceKey)
  218. authCredentialsProvider:_fakeAuthCredentialsProvider
  219. appCheckCredentialsProvider:_fakeAppCheckCredentialsProvider
  220. workerQueue:AsyncQueueForTesting()
  221. firebaseMetadataProvider:absl::make_unique<FirebaseMetadataProviderApple>(app)
  222. firebaseApp:app
  223. instanceRegistry:nil];
  224. firestore.settings = [FSTIntegrationTestCase settings];
  225. [_firestores addObject:firestore];
  226. return firestore;
  227. }
  228. - (void)triggerUserChangeWithUid:(NSString *)uid {
  229. _fakeAuthCredentialsProvider->ChangeUser(uid);
  230. }
  231. - (void)primeBackend {
  232. static dispatch_once_t onceToken;
  233. dispatch_once(&onceToken, ^{
  234. [FSTIntegrationTestCase setUpDefaults];
  235. if (runningAgainstEmulator) {
  236. // Priming not required against the emulator.
  237. return;
  238. }
  239. FIRFirestore *db = [self firestore];
  240. XCTestExpectation *watchInitialized =
  241. [self expectationWithDescription:@"Prime backend: Watch initialized"];
  242. __block XCTestExpectation *watchUpdateReceived;
  243. FIRDocumentReference *docRef = [db documentWithPath:[self documentPath]];
  244. id<FIRListenerRegistration> listenerRegistration =
  245. [docRef addSnapshotListener:^(FIRDocumentSnapshot *snapshot, NSError *) {
  246. if ([snapshot[@"value"] isEqual:@"done"]) {
  247. [watchUpdateReceived fulfill];
  248. } else {
  249. [watchInitialized fulfill];
  250. }
  251. }];
  252. // Wait for watch to initialize and deliver first event.
  253. [self awaitExpectation:watchInitialized];
  254. watchUpdateReceived = [self expectationWithDescription:@"Prime backend: Watch update received"];
  255. // Use a transaction to perform a write without triggering any local events.
  256. [docRef.firestore
  257. runTransactionWithBlock:^id(FIRTransaction *transaction, NSError **) {
  258. [transaction setData:@{@"value" : @"done"} forDocument:docRef];
  259. return nil;
  260. }
  261. completion:^(id, NSError *){
  262. }];
  263. // Wait to see the write on the watch stream.
  264. [self waitForExpectationsWithTimeout:kPrimingTimeout
  265. handler:^(NSError *_Nullable expectationError) {
  266. if (expectationError) {
  267. XCTFail(@"Error waiting for prime backend: %@",
  268. expectationError);
  269. }
  270. }];
  271. [listenerRegistration remove];
  272. [self terminateFirestore:db];
  273. });
  274. }
  275. - (void)terminateFirestore:(FIRFirestore *)firestore {
  276. XCTestExpectation *expectation = [self expectationWithDescription:@"shutdown"];
  277. [firestore terminateWithCompletion:[self completionForExpectation:expectation]];
  278. [self awaitExpectation:expectation];
  279. }
  280. - (void)deleteApp:(FIRApp *)app {
  281. XCTestExpectation *expectation = [self expectationWithDescription:@"deleteApp"];
  282. [app deleteApp:^(BOOL completion) {
  283. XCTAssertTrue(completion);
  284. [expectation fulfill];
  285. }];
  286. [self awaitExpectation:expectation];
  287. }
  288. - (NSString *)documentPath {
  289. std::string autoId = CreateAutoId();
  290. return [NSString stringWithFormat:@"test-collection/%s", autoId.c_str()];
  291. }
  292. - (FIRDocumentReference *)documentRef {
  293. return [self.db documentWithPath:[self documentPath]];
  294. }
  295. - (FIRCollectionReference *)collectionRef {
  296. std::string autoId = CreateAutoId();
  297. NSString *collectionName = [NSString stringWithFormat:@"test-collection-%s", autoId.c_str()];
  298. return [self.db collectionWithPath:collectionName];
  299. }
  300. - (FIRCollectionReference *)collectionRefWithDocuments:
  301. (NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents {
  302. FIRCollectionReference *collection = [self collectionRef];
  303. // Use a different instance to write the documents
  304. [self writeAllDocuments:documents
  305. toCollection:[[self firestore] collectionWithPath:collection.path]];
  306. return collection;
  307. }
  308. - (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
  309. toCollection:(FIRCollectionReference *)collection {
  310. [documents enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary<NSString *, id> *value,
  311. BOOL *) {
  312. FIRDocumentReference *ref = [collection documentWithPath:key];
  313. [self writeDocumentRef:ref data:value];
  314. }];
  315. }
  316. - (void)readerAndWriterOnDocumentRef:(void (^)(FIRDocumentReference *readerRef,
  317. FIRDocumentReference *writerRef))action {
  318. FIRFirestore *reader = self.db; // for clarity
  319. FIRFirestore *writer = [self firestore];
  320. NSString *path = [self documentPath];
  321. FIRDocumentReference *readerRef = [reader documentWithPath:path];
  322. FIRDocumentReference *writerRef = [writer documentWithPath:path];
  323. action(readerRef, writerRef);
  324. }
  325. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref {
  326. return [self readDocumentForRef:ref source:FIRFirestoreSourceDefault];
  327. }
  328. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
  329. source:(FIRFirestoreSource)source {
  330. __block FIRDocumentSnapshot *result;
  331. XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
  332. [ref getDocumentWithSource:source
  333. completion:^(FIRDocumentSnapshot *doc, NSError *_Nullable error) {
  334. XCTAssertNil(error);
  335. result = doc;
  336. [expectation fulfill];
  337. }];
  338. [self awaitExpectation:expectation];
  339. return result;
  340. }
  341. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query {
  342. return [self readDocumentSetForRef:query source:FIRFirestoreSourceDefault];
  343. }
  344. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRFirestoreSource)source {
  345. if (query == nil) {
  346. XCTFail("Trying to read data from a nil query");
  347. }
  348. __block FIRQuerySnapshot *result;
  349. XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
  350. [query getDocumentsWithSource:source
  351. completion:^(FIRQuerySnapshot *documentSet, NSError *error) {
  352. XCTAssertNil(error);
  353. result = documentSet;
  354. [expectation fulfill];
  355. }];
  356. [self awaitExpectation:expectation];
  357. return result;
  358. }
  359. - (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)ref
  360. requireOnline:(BOOL)requireOnline {
  361. __block FIRDocumentSnapshot *result;
  362. XCTestExpectation *expectation = [self expectationWithDescription:@"listener"];
  363. id<FIRListenerRegistration> listener = [ref
  364. addSnapshotListenerWithIncludeMetadataChanges:YES
  365. listener:^(FIRDocumentSnapshot *snapshot,
  366. NSError *error) {
  367. XCTAssertNil(error);
  368. if (!requireOnline || !snapshot.metadata.fromCache) {
  369. result = snapshot;
  370. [expectation fulfill];
  371. }
  372. }];
  373. [self awaitExpectation:expectation];
  374. [listener remove];
  375. return result;
  376. }
  377. - (FIRAggregateQuerySnapshot *)readSnapshotForAggregate:(FIRAggregateQuery *)query {
  378. __block FIRAggregateQuerySnapshot *result;
  379. XCTestExpectation *expectation = [self expectationWithDescription:@"aggregate result"];
  380. [query aggregationWithSource:FIRAggregateSourceServer
  381. completion:^(FIRAggregateQuerySnapshot *snapshot, NSError *error) {
  382. XCTAssertNil(error);
  383. result = snapshot;
  384. [expectation fulfill];
  385. }];
  386. [self awaitExpectation:expectation];
  387. return result;
  388. }
  389. - (void)writeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
  390. XCTestExpectation *expectation = [self expectationWithDescription:@"setData"];
  391. [ref setData:data completion:[self completionForExpectation:expectation]];
  392. [self awaitExpectation:expectation];
  393. }
  394. - (void)updateDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<id, id> *)data {
  395. XCTestExpectation *expectation = [self expectationWithDescription:@"updateData"];
  396. [ref updateData:data completion:[self completionForExpectation:expectation]];
  397. [self awaitExpectation:expectation];
  398. }
  399. - (void)deleteDocumentRef:(FIRDocumentReference *)ref {
  400. XCTestExpectation *expectation = [self expectationWithDescription:@"deleteDocument"];
  401. [ref deleteDocumentWithCompletion:[self completionForExpectation:expectation]];
  402. [self awaitExpectation:expectation];
  403. }
  404. - (FIRDocumentReference *)addDocumentRef:(FIRCollectionReference *)ref
  405. data:(NSDictionary<NSString *, id> *)data {
  406. XCTestExpectation *expectation = [self expectationWithDescription:@"addDocument"];
  407. FIRDocumentReference *doc = [ref addDocumentWithData:data
  408. completion:[self completionForExpectation:expectation]];
  409. [self awaitExpectation:expectation];
  410. return doc;
  411. }
  412. - (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
  413. XCTestExpectation *expectation = [self expectationWithDescription:@"setDataWithMerge"];
  414. [ref setData:data merge:YES completion:[self completionForExpectation:expectation]];
  415. [self awaitExpectation:expectation];
  416. }
  417. - (void)mergeDocumentRef:(FIRDocumentReference *)ref
  418. data:(NSDictionary<NSString *, id> *)data
  419. fields:(NSArray<id> *)fields {
  420. XCTestExpectation *expectation = [self expectationWithDescription:@"setDataWithMerge"];
  421. [ref setData:data mergeFields:fields completion:[self completionForExpectation:expectation]];
  422. [self awaitExpectation:expectation];
  423. }
  424. - (void)disableNetwork {
  425. XCTestExpectation *expectation = [self expectationWithDescription:@"disableNetwork"];
  426. [self.db disableNetworkWithCompletion:[self completionForExpectation:expectation]];
  427. [self awaitExpectation:expectation];
  428. }
  429. - (void)enableNetwork {
  430. XCTestExpectation *expectation = [self expectationWithDescription:@"enableNetwork"];
  431. [self.db enableNetworkWithCompletion:[self completionForExpectation:expectation]];
  432. [self awaitExpectation:expectation];
  433. }
  434. - (const std::shared_ptr<AsyncQueue> &)queueForFirestore:(FIRFirestore *)firestore {
  435. return [firestore workerQueue];
  436. }
  437. - (void)waitUntil:(BOOL (^)())predicate {
  438. NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
  439. double waitSeconds = [self defaultExpectationWaitSeconds];
  440. while (!predicate() && ([NSDate timeIntervalSinceReferenceDate] - start < waitSeconds)) {
  441. // This waits for the next event or until the 100ms timeout is reached
  442. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
  443. beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  444. }
  445. if (!predicate()) {
  446. XCTFail(@"Timeout");
  447. }
  448. }
  449. extern "C" NSArray<NSDictionary<NSString *, id> *> *FIRQuerySnapshotGetData(
  450. FIRQuerySnapshot *docs) {
  451. NSMutableArray<NSDictionary<NSString *, id> *> *result = [NSMutableArray array];
  452. for (FIRDocumentSnapshot *doc in docs.documents) {
  453. [result addObject:doc.data];
  454. }
  455. return result;
  456. }
  457. extern "C" NSArray<NSString *> *FIRQuerySnapshotGetIDs(FIRQuerySnapshot *docs) {
  458. NSMutableArray<NSString *> *result = [NSMutableArray array];
  459. for (FIRDocumentSnapshot *doc in docs.documents) {
  460. [result addObject:doc.documentID];
  461. }
  462. return result;
  463. }
  464. extern "C" NSArray<NSArray<id> *> *FIRQuerySnapshotGetDocChangesData(FIRQuerySnapshot *docs) {
  465. NSMutableArray<NSMutableArray<id> *> *result = [NSMutableArray array];
  466. for (FIRDocumentChange *docChange in docs.documentChanges) {
  467. NSMutableArray<id> *docChangeData = [NSMutableArray array];
  468. [docChangeData addObject:@(docChange.type)];
  469. [docChangeData addObject:docChange.document.documentID];
  470. [docChangeData addObject:docChange.document.data];
  471. [result addObject:docChangeData];
  472. }
  473. return result;
  474. }
  475. @end
  476. NS_ASSUME_NONNULL_END