@@ -490,6 +490,88 @@ test_insert (void)
490
490
}
491
491
492
492
493
+ static void
494
+ test_insert_null (void )
495
+ {
496
+ mongoc_collection_t * collection ;
497
+ mongoc_bulk_operation_t * bulk ;
498
+ mongoc_client_t * client ;
499
+ mongoc_cursor_t * cursor ;
500
+ bson_error_t error ;
501
+ bson_t reply ;
502
+ const bson_t * out ;
503
+ bool ret ;
504
+ bson_t doc ;
505
+ bson_t filter = BSON_INITIALIZER ;
506
+ bson_iter_t iter ;
507
+ uint32_t len ;
508
+
509
+ client = test_framework_client_new ();
510
+ ASSERT (client );
511
+
512
+ collection =
513
+ mongoc_client_get_collection (client , "test" , "test_null_insert" );
514
+ ASSERT (collection );
515
+
516
+ mongoc_collection_drop (collection , & error );
517
+
518
+ bson_init (& doc );
519
+ bson_append_utf8 (& doc , "hello" , 5 , "wor\0ld" , 6 );
520
+ ret = mongoc_collection_insert (
521
+ collection , MONGOC_INSERT_NONE , & doc , NULL , & error );
522
+ ASSERT_OR_PRINT (ret , error );
523
+
524
+ bulk = mongoc_collection_create_bulk_operation (collection , true, NULL );
525
+ mongoc_bulk_operation_insert (bulk , & doc );
526
+ ret = mongoc_bulk_operation_execute (bulk , & reply , & error );
527
+ ASSERT_OR_PRINT (ret , error );
528
+ ASSERT_MATCH (& reply ,
529
+ "{'nInserted': 1,"
530
+ " 'nMatched': 0,"
531
+ " 'nModified': 0,"
532
+ " 'nRemoved': 0,"
533
+ " 'nUpserted': 0,"
534
+ " 'writeErrors': []}" );
535
+ bson_destroy (& doc );
536
+ bson_destroy (& reply );
537
+
538
+ cursor = mongoc_collection_find_with_opts (collection , & filter , NULL , NULL );
539
+ ASSERT (mongoc_cursor_next (cursor , & out ));
540
+ ASSERT (bson_iter_init_find (& iter , out , "hello" ));
541
+ ASSERT (!memcmp (bson_iter_utf8 (& iter , & len ), "wor\0ld" , 6 ));
542
+ ASSERT_CMPINT (len , = = , 6 );
543
+
544
+ ASSERT (mongoc_cursor_next (cursor , & out ));
545
+ ASSERT (bson_iter_init_find (& iter , out , "hello" ));
546
+ ASSERT (!memcmp (bson_iter_utf8 (& iter , & len ), "wor\0ld" , 6 ));
547
+ ASSERT_CMPINT (len , = = , 6 );
548
+
549
+ mongoc_cursor_destroy (cursor );
550
+ mongoc_bulk_operation_destroy (bulk );
551
+
552
+ bulk = mongoc_collection_create_bulk_operation (collection , true, NULL );
553
+ mongoc_bulk_operation_remove_one (bulk , & doc );
554
+ ret = mongoc_bulk_operation_update_one_with_opts (
555
+ bulk , & doc , tmp_bson ("{'$set': {'x': 1}}" ), NULL , & error );
556
+ ASSERT_OR_PRINT (ret , error );
557
+ ret = mongoc_bulk_operation_execute (bulk , & reply , & error );
558
+ ASSERT_OR_PRINT (ret , error );
559
+ ASSERT_MATCH (& reply ,
560
+ "{'nInserted': 0,"
561
+ " 'nMatched': 1,"
562
+ " 'nModified': 1,"
563
+ " 'nRemoved': 1,"
564
+ " 'nUpserted': 0,"
565
+ " 'writeErrors': []}" );
566
+
567
+ bson_destroy (& filter );
568
+ bson_destroy (& reply );
569
+ mongoc_bulk_operation_destroy (bulk );
570
+ mongoc_collection_destroy (collection );
571
+ mongoc_client_destroy (client );
572
+ }
573
+
574
+
493
575
static void
494
576
test_insert_oversize (void * ctx )
495
577
{
@@ -4899,6 +4981,8 @@ test_collection_install (TestSuite *suite)
4899
4981
4900
4982
TestSuite_AddLive (suite , "/Collection/copy" , test_copy );
4901
4983
TestSuite_AddLive (suite , "/Collection/insert" , test_insert );
4984
+ TestSuite_AddLive (
4985
+ suite , "/Collection/insert/null_string" , test_insert_null );
4902
4986
TestSuite_AddFull (suite ,
4903
4987
"/Collection/insert/oversize" ,
4904
4988
test_insert_oversize ,
0 commit comments