@@ -283,6 +283,60 @@ test_write_concern_wtimeout_validity (void)
283
283
mongoc_write_concern_destroy (write_concern );
284
284
}
285
285
286
+ static void
287
+ _test_write_concern_from_iterator (const char * swc , bool ok )
288
+ {
289
+ bson_t * bson = tmp_bson (swc );
290
+ const bson_t * bson2 ;
291
+ mongoc_write_concern_t * wc ;
292
+ bson_iter_t iter ;
293
+
294
+ if (test_suite_debug_output ()) {
295
+ fprintf (stdout , " - %s\n" , swc );
296
+ fflush (stdout );
297
+ }
298
+
299
+ bson_iter_init_find (& iter , bson , "writeConcern" );
300
+ ASSERT_CMPINT ((int )_mongoc_write_concern_iter_is_valid (& iter ), = = , (int )ok );
301
+
302
+ wc = _mongoc_write_concern_new_from_iter (& iter );
303
+ bson2 = _mongoc_write_concern_get_bson (wc );
304
+ ASSERT (bson_compare (bson , bson2 ));
305
+ mongoc_write_concern_destroy (wc );
306
+ }
307
+
308
+ static void
309
+ test_write_concern_from_iterator (void )
310
+ {
311
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 'majority'}}" , true);
312
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 'majority', 'j': true}}" , true);
313
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 'sometag'}}" , true);
314
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 'sometag', 'j': true}}" , true);
315
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 'sometag', 'j': false}}" , true);
316
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 1, 'j': true}}" , true);
317
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 1, 'j': false}}" , true);
318
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 0, 'j': true}}" , false);
319
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 0, 'j': false}}" , true);
320
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 42}}" , true);
321
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 1}}" , true);
322
+ _test_write_concern_from_iterator ("{'writeConcern': {'j': true}}" , true);
323
+ _test_write_concern_from_iterator ("{'writeConcern': {'j': false}}" , true);
324
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': -3}}" , true);
325
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 'majority', 'wtimeout': 42}}" , true);
326
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 'sometag', 'wtimeout': 42}}" , true);
327
+ _test_write_concern_from_iterator ("{'writeConcern': {'wtimeout': 42}}" , true);
328
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 1, 'wtimeout': 42}}" , true);
329
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 0, 'wtimeout': 42}}" , true);
330
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': 1.0}}" , false);
331
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': {'some': 'stuff'}}}" , false);
332
+ _test_write_concern_from_iterator ("{'writeConcern': {'w': []}}" , false);
333
+ _test_write_concern_from_iterator ("{'writeConcern': {'wtimeout': 'never'}}" , false);
334
+ _test_write_concern_from_iterator ("{'writeConcern': {'j': 'never'}}" , false);
335
+ _test_write_concern_from_iterator ("{'writeConcern': {'j': 1.0}}" , false);
336
+ _test_write_concern_from_iterator ("{'writeConcern': {'fsync': 1.0}}" , false);
337
+ _test_write_concern_from_iterator ("{'writeConcern': {'fsync': true}}" , true);
338
+ }
339
+
286
340
287
341
void
288
342
test_write_concern_install (TestSuite * suite )
@@ -293,4 +347,5 @@ test_write_concern_install (TestSuite *suite)
293
347
TestSuite_Add (suite , "/WriteConcern/bson_includes_false_fsync_and_journal" , test_write_concern_bson_includes_false_fsync_and_journal );
294
348
TestSuite_Add (suite , "/WriteConcern/fsync_and_journal_gle_and_validity" , test_write_concern_fsync_and_journal_gle_and_validity );
295
349
TestSuite_Add (suite , "/WriteConcern/wtimeout_validity" , test_write_concern_wtimeout_validity );
350
+ TestSuite_Add (suite , "/WriteConcern/from_iterator" , test_write_concern_from_iterator );
296
351
}
0 commit comments