@@ -2446,7 +2446,8 @@ test_bson_binary_null_handling (void)
2446
2446
}
2447
2447
2448
2448
static void
2449
- test_bson_append_null_from_utf8_or_symbol (void ) {
2449
+ test_bson_append_null_from_utf8_or_symbol (void )
2450
+ {
2450
2451
bson_t bson ;
2451
2452
bson_iter_t iter ;
2452
2453
@@ -2461,6 +2462,46 @@ test_bson_append_null_from_utf8_or_symbol (void) {
2461
2462
bson_destroy (& bson );
2462
2463
}
2463
2464
2465
+ static void
2466
+ test_bson_as_json_string (void )
2467
+ {
2468
+ bson_t * all_types ;
2469
+ int i ;
2470
+ char * actual ;
2471
+ const char * expected =
2472
+ "{ \"double\" : { \"$numberDouble\" : \"1.0\" }, \"string\" : "
2473
+ "\"string_example\", \"document\" : { \"x\" : \"y\" }, \"document\" : [ "
2474
+ "\"x\" ], \"binary\" : { \"$binary\" : { \"base64\": \"ZGF0YQ==\", "
2475
+ "\"subType\" : \"00\" } }, \"undefined\" : { \"$undefined\" : true }, "
2476
+ "\"oid\" : { \"$oid\" : \"000000000000000000000000\" }, \"bool\" : true, "
2477
+ "\"datetime\" : { \"$date\" : { \"$numberLong\" : \"123\" } }, \"null\" "
2478
+ ": null, \"regex\" : { \"$regularExpression\" : { \"pattern\" : \"a+\", "
2479
+ "\"options\" : \"\" } }, \"dbpointer\" : { \"$dbPointer\" : { \"$ref\" : "
2480
+ "\"collection\", \"$id\" : { \"$oid\" : \"000000000000000000000000\" } } "
2481
+ "}, \"code\" : { \"$code\" : \"var x = 1;\" }, \"symbol\" : { "
2482
+ "\"$symbol\" : \"symbol_example\" }, \"code\" : { \"$code\" : \"var x = "
2483
+ "1;\" }, \"code_w_scope\" : { \"$code\" : \"var x = 1;\", \"$scope\" : { "
2484
+ "} }, \"int32\" : { \"$numberInt\" : \"1\" }, \"timestamp\" : { "
2485
+ "\"$timestamp\" : { \"t\" : 2, \"i\" : 3 } }, \"int64\" : { "
2486
+ "\"$numberLong\" : \"4\" }, \"decimal128\" : { \"$numberDecimal\" : "
2487
+ "\"1.23456789\" }, \"minkey\" : { \"$minKey\" : 1 }, \"maxkey\" : { "
2488
+ "\"$maxKey\" : 1 }, \"\" : { \"$numberInt\" : \"-1\" } }" ;
2489
+
2490
+ all_types = bson_with_all_types ();
2491
+ actual = bson_as_canonical_extended_json (all_types , NULL );
2492
+
2493
+ for (i = 0 ; i < strlen (expected ); i ++ ) {
2494
+ if (expected [i ] != actual [i ]) {
2495
+ test_error ("character mismatch at %d. Expected: %s, got %s" ,
2496
+ i ,
2497
+ expected ,
2498
+ actual );
2499
+ }
2500
+ }
2501
+
2502
+ bson_free (actual );
2503
+ }
2504
+
2464
2505
void
2465
2506
test_bson_install (TestSuite * suite )
2466
2507
{
@@ -2555,5 +2596,8 @@ test_bson_install (TestSuite *suite)
2555
2596
test_bson_iter_init_from_data_at_offset );
2556
2597
TestSuite_Add (
2557
2598
suite , "/bson/value/null_handling" , test_bson_binary_null_handling );
2558
- TestSuite_Add (suite , "/bson/append_null_from_utf8_or_symbol" , test_bson_append_null_from_utf8_or_symbol );
2599
+ TestSuite_Add (suite ,
2600
+ "/bson/append_null_from_utf8_or_symbol" ,
2601
+ test_bson_append_null_from_utf8_or_symbol );
2602
+ TestSuite_Add (suite , "/bson/as_json_string" , test_bson_as_json_string );
2559
2603
}
0 commit comments