diff options
Diffstat (limited to 'src/mongo/idl')
-rw-r--r-- | src/mongo/idl/idl_test.cpp | 37 | ||||
-rw-r--r-- | src/mongo/idl/unittest.idl | 13 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp index 5e1f71f31fe..a2855b5d810 100644 --- a/src/mongo/idl/idl_test.cpp +++ b/src/mongo/idl/idl_test.cpp @@ -232,9 +232,46 @@ TEST(IDLOneTypeTests, TestObjectLoopbackTest) { auto serializedDoc = builder.obj(); ASSERT_BSONOBJ_EQ(testDoc, serializedDoc); + + ASSERT_TRUE(one_new == testStruct); + ASSERT_FALSE(one_new < testStruct); } } +// Test we compare an object with optional BSONObjs correctly +TEST(IDLOneTypeTests, TestOptionalObjectTest) { + IDLParserErrorContext ctxt("root"); + + auto testValue = BSON("Hello" + << "World"); + auto testDoc = BSON("value" << testValue << "value2" << testValue << "opt_value" << testValue); + + auto element = testDoc.firstElement(); + ASSERT_EQUALS(element.type(), Object); + + auto testStruct = One_plain_optional_object::parse(ctxt, testDoc); + assert_same_types<decltype(testStruct.getValue()), const BSONObj&>(); + + ASSERT_BSONOBJ_EQ(testStruct.getValue(), testValue); + + One_plain_optional_object testEmptyStruct; + One_plain_optional_object testEmptyStruct2; + + // Make sure we match the operator semantics for std::optional + ASSERT_TRUE(testEmptyStruct == testEmptyStruct2); + ASSERT_FALSE(testEmptyStruct != testEmptyStruct2); + ASSERT_FALSE(testEmptyStruct < testEmptyStruct2); + + ASSERT_FALSE(testEmptyStruct == testStruct); + ASSERT_TRUE(testEmptyStruct != testStruct); + ASSERT_TRUE(testEmptyStruct < testStruct); + ASSERT_FALSE(testStruct < testEmptyStruct); + + ASSERT_TRUE(testStruct == testStruct); + ASSERT_FALSE(testStruct != testStruct); + ASSERT_FALSE(testStruct < testStruct); +} + // Test if a given value for a given bson document parses successfully or fails if the bson types // mismatch. template <typename ParserT, BSONType Parser_bson_type, typename TestT, BSONType Test_bson_type> diff --git a/src/mongo/idl/unittest.idl b/src/mongo/idl/unittest.idl index 846c4042fb0..ac25607aa6e 100644 --- a/src/mongo/idl/unittest.idl +++ b/src/mongo/idl/unittest.idl @@ -120,9 +120,22 @@ structs: one_plain_object: description: UnitTest for a single BSONObj + generate_comparison_operators: true fields: value: object + one_plain_optional_object: + description: UnitTest for optional BSONObj + generate_comparison_operators: true + fields: + value: object + value2: object + opt_value: + type: object + optional: true + opt_value2: + type: object + optional: true ################################################################################################## # |