@@ -734,6 +734,44 @@ test_cursor_new_invalid (void)
734
734
mongoc_client_destroy (client );
735
735
}
736
736
737
+ static void
738
+ test_cursor_new_static (void )
739
+ {
740
+ mongoc_client_t * client ;
741
+ bson_error_t error ;
742
+ mongoc_cursor_t * cursor ;
743
+ bson_t * bson_alloced ;
744
+ bson_t bson_static ;
745
+
746
+ bson_alloced = tmp_bson ("{ 'ok':1,"
747
+ " 'cursor': {"
748
+ " 'id': 0,"
749
+ " 'ns': 'test.foo',"
750
+ " 'firstBatch': [{'x': 1}, {'x': 2}]}}" );
751
+
752
+ ASSERT (bson_init_static (& bson_static ,
753
+ bson_get_data (bson_alloced ),
754
+ bson_alloced -> len ));
755
+
756
+ /* test heap-allocated bson */
757
+ client = test_framework_client_new ();
758
+ cursor = mongoc_cursor_new_from_command_reply (client ,
759
+ bson_copy (bson_alloced ),
760
+ 0 );
761
+
762
+ ASSERT (cursor );
763
+ ASSERT (!mongoc_cursor_error (cursor , & error ));
764
+ mongoc_cursor_destroy (cursor );
765
+
766
+ /* test static bson */
767
+ cursor = mongoc_cursor_new_from_command_reply (client , & bson_static , 0 );
768
+ ASSERT (cursor );
769
+ ASSERT (!mongoc_cursor_error (cursor , & error ));
770
+
771
+ mongoc_cursor_destroy (cursor );
772
+ mongoc_client_destroy (client );
773
+ }
774
+
737
775
738
776
static void
739
777
test_cursor_hint_errors (void )
@@ -1516,6 +1554,7 @@ test_cursor_install (TestSuite *suite)
1516
1554
test_cursor_new_from_find_batches , NULL , NULL ,
1517
1555
test_framework_skip_if_max_wire_version_less_than_4 );
1518
1556
TestSuite_AddLive (suite , "/Cursor/new_invalid" , test_cursor_new_invalid );
1557
+ TestSuite_AddLive (suite , "/Cursor/new_static" , test_cursor_new_static );
1519
1558
TestSuite_AddLive (suite , "/Cursor/hint/errors" , test_cursor_hint_errors );
1520
1559
TestSuite_Add (suite , "/Cursor/hint/single/secondary" , test_hint_single_secondary );
1521
1560
TestSuite_Add (suite , "/Cursor/hint/single/primary" , test_hint_single_primary );
0 commit comments