|
static void
|
test_aggregate_clone (void)
|
{
|
mongoc_collection_t *collection;
|
mongoc_database_t *database;
|
mongoc_client_t *client;
|
mongoc_cursor_t *cursor, *cursor_before, *cursor_after;
|
const bson_t *doc;
|
bson_error_t error;
|
bool r;
|
int i;
|
|
client = test_framework_client_new ();
|
database = get_test_database (client);
|
collection = get_test_collection (client, "test_aggregate");
|
|
r = mongoc_collection_insert(collection, MONGOC_INSERT_NONE,
|
tmp_bson ("{'_id': 1}"), NULL, &error);
|
ASSERT_OR_PRINT (r, error);
|
r = mongoc_collection_insert(collection, MONGOC_INSERT_NONE,
|
tmp_bson ("{'_id': 2}"), NULL, &error);
|
ASSERT_OR_PRINT (r, error);
|
|
cursor = mongoc_collection_aggregate(collection, MONGOC_QUERY_NONE,
|
tmp_bson ("{}"), NULL, NULL);
|
cursor_before = mongoc_cursor_clone (cursor);
|
|
i = 0;
|
while (mongoc_cursor_next (cursor, &doc)) {
|
i++;
|
}
|
|
ASSERT_OR_PRINT (!mongoc_cursor_error (cursor, &error), error);
|
ASSERT_CMPINT (i, ==, 2);
|
|
i = 0;
|
while (mongoc_cursor_next (cursor_before, &doc)) {
|
i++;
|
}
|
|
ASSERT_OR_PRINT (!mongoc_cursor_error (cursor_before, &error), error);
|
ASSERT_CMPINT (i, ==, 2);
|
|
cursor_after = mongoc_cursor_clone (cursor);
|
i = 0;
|
while (mongoc_cursor_next (cursor_after, &doc)) {
|
i++;
|
}
|
|
ASSERT_OR_PRINT (!mongoc_cursor_error (cursor_after, &error), error);
|
ASSERT_CMPINT (i, ==, 2);
|
|
mongoc_cursor_destroy (cursor);
|
mongoc_cursor_destroy (cursor_before);
|
mongoc_cursor_destroy (cursor_after);
|
mongoc_collection_destroy(collection);
|
mongoc_database_destroy(database);
|
mongoc_client_destroy(client);
|
}
|