diff options
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/bsonobjbuilder.h | 2 | ||||
-rw-r--r-- | src/mongo/bson/bsonobjbuilder_test.cpp | 35 |
2 files changed, 21 insertions, 16 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h index 1ec71249d7d..bd10a7b3d16 100644 --- a/src/mongo/bson/bsonobjbuilder.h +++ b/src/mongo/bson/bsonobjbuilder.h @@ -777,8 +777,6 @@ private: }; class BSONArrayBuilder { - MONGO_DISALLOW_COPYING(BSONArrayBuilder); - public: BSONArrayBuilder() : _i(0), _b() {} BSONArrayBuilder(BufBuilder& _b) : _i(0), _b(_b) {} diff --git a/src/mongo/bson/bsonobjbuilder_test.cpp b/src/mongo/bson/bsonobjbuilder_test.cpp index bef67573661..901b2d14965 100644 --- a/src/mongo/bson/bsonobjbuilder_test.cpp +++ b/src/mongo/bson/bsonobjbuilder_test.cpp @@ -26,26 +26,16 @@ * it in the license file. */ -/** - * tests for BSONObjBuilder - */ +#include "mongo/platform/basic.h" #include "mongo/db/jsobj.h" #include "mongo/db/json.h" - #include "mongo/unittest/unittest.h" -#include <sstream> namespace mongo { namespace { -using mongo::BSONElement; -using mongo::BSONObj; -using mongo::BSONObjBuilder; -using mongo::BSONType; -using mongo::BufBuilder; using std::string; -using std::stringstream; const long long maxEncodableInt = (1 << 30) - 1; const long long minEncodableInt = -maxEncodableInt; @@ -65,7 +55,7 @@ const long long minLongLong = (std::numeric_limits<long long>::min)(); template <typename T> void assertBSONTypeEquals(BSONType actual, BSONType expected, T value, int i) { if (expected != actual) { - stringstream ss; + std::stringstream ss; ss << "incorrect type in bson object for " << (i + 1) << "-th test value " << value << ". actual: " << mongo::typeName(actual) << "; expected: " << mongo::typeName(expected); @@ -74,7 +64,7 @@ void assertBSONTypeEquals(BSONType actual, BSONType expected, T value, int i) { } } -TEST(BSONObjBuilder, AppendInt64T) { +TEST(BSONObjBuilderTest, AppendInt64T) { auto obj = BSON("a" << int64_t{5} << "b" << int64_t{1ll << 40}); ASSERT_EQ(obj["a"].type(), NumberLong); ASSERT_EQ(obj["b"].type(), NumberLong); @@ -359,5 +349,22 @@ TEST(BSONObjBuilderTest, MovingANonOwningBSONObjBuilderWorks) { ASSERT_BSONOBJ_EQ(outer.obj(), BSON("nested" << BSON("a" << 1 << "b" << 2 << "c" << 3))); } -} // unnamed namespace +TEST(BSONArrayBuilderTest, MovingABSONArrayBuilderWorks) { + BSONObjBuilder bob; + bob.append("a", 1); + + BSONArrayBuilder initial(bob.subarrayStart("array")); + initial.append(1); + initial << "2"; + + BSONArrayBuilder moved(std::move(initial)); + moved.append(3); + moved << "4"; + + moved.done(); + + ASSERT_BSONOBJ_EQ(bob.obj(), BSON("a" << 1 << "array" << BSON_ARRAY(1 << "2" << 3 << "4"))); +} + +} // namespace } // namespace mongo |