summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorMilena Ivanova <milena.ivanova@mongodb.com>2021-04-26 16:04:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-28 19:50:35 +0000
commit2957e50d04bf5eb2d3ad2aabdd37f8a63b10835d (patch)
tree99b30696315d437b8cb128f82d139f714b839e92 /src/mongo/idl
parent193e8838d915a3609b1cda62301e4601bd48b34d (diff)
downloadmongo-2957e50d04bf5eb2d3ad2aabdd37f8a63b10835d.tar.gz
SERVER-55899 Add serialization/deserialization unit test for IDL optionalBool type
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/idl_test.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp
index 13879bb9ae9..e2f8cb030ea 100644
--- a/src/mongo/idl/idl_test.cpp
+++ b/src/mongo/idl/idl_test.cpp
@@ -3709,5 +3709,55 @@ TEST(IDLAccessCheck, TestComplexAccessCheck) {
verifyContract(ac, AccessCheckComplexPrivilege::kAuthorizationContract);
}
+TEST(IDLFieldTests, TestOptionalBoolField) {
+ IDLParserErrorContext ctxt("root");
+
+ {
+ auto testDoc = BSON("optBoolField" << true);
+ auto parsed = OptionalBool::parseFromBSON(testDoc.firstElement());
+ ASSERT_TRUE(parsed.has_value());
+ ASSERT_TRUE(parsed);
+ BSONObjBuilder serialized;
+ parsed.serializeToBSON("optBoolField", &serialized);
+ ASSERT_BSONOBJ_EQ(serialized.obj(), testDoc);
+ }
+
+ {
+ auto testDoc = BSON("optBoolField" << false);
+ auto parsed = OptionalBool::parseFromBSON(testDoc.firstElement());
+ ASSERT_TRUE(parsed.has_value());
+ ASSERT_FALSE(parsed);
+ BSONObjBuilder serialized;
+ parsed.serializeToBSON("optBoolField", &serialized);
+ ASSERT_BSONOBJ_EQ(serialized.obj(), testDoc);
+ }
+
+ {
+ auto testDoc = BSONObj();
+ auto parsed = OptionalBool::parseFromBSON(testDoc.firstElement());
+ ASSERT_FALSE(parsed.has_value());
+ ASSERT_FALSE(parsed);
+ BSONObjBuilder serialized;
+ parsed.serializeToBSON("", &serialized);
+ ASSERT_BSONOBJ_EQ(serialized.obj(), testDoc);
+ }
+
+ {
+ auto testDoc = BSON("optBoolField" << jstNULL);
+ ASSERT_THROWS(OptionalBool::parseFromBSON(testDoc.firstElement()), AssertionException);
+ }
+
+ {
+ auto testDoc = BSON("optBoolField" << BSONUndefined);
+ ASSERT_THROWS(OptionalBool::parseFromBSON(testDoc.firstElement()), AssertionException);
+ }
+
+ {
+ auto testDoc = BSON("optBoolField"
+ << "abc");
+ ASSERT_THROWS(OptionalBool::parseFromBSON(testDoc.firstElement()), AssertionException);
+ }
+}
+
} // namespace
} // namespace mongo