summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2019-01-11 16:06:20 -0500
committerMark Benvenuto <mark.benvenuto@mongodb.com>2019-01-11 16:06:20 -0500
commit73bce03305b2aa8c94d2400ffdb848ccb0f27588 (patch)
treea524ccfeecfaa0161d439e1a75efb5cc7dd79f64 /src/mongo/idl
parent50012971bb889deb729175d176f8bc14a9b2d1a7 (diff)
downloadmongo-73bce03305b2aa8c94d2400ffdb848ccb0f27588.tar.gz
SERVER-38880 IDL relational comparison operators without std::tie()
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/idl_test.cpp37
-rw-r--r--src/mongo/idl/unittest.idl13
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
##################################################################################################
#