summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonobjbuilder_test.cpp
diff options
context:
space:
mode:
authorAlya Berciu <alya.berciu@mongodb.com>2019-06-07 10:26:48 -0400
committerAlya Berciu <alya.berciu@mongodb.com>2019-07-03 12:53:07 -0400
commit990b2ef30d7b8fa4db6af6d79da80e3664df9c21 (patch)
tree6af2f09e7271d41e86f4228dd54f35aeade71171 /src/mongo/bson/bsonobjbuilder_test.cpp
parent5813046272efb614ac78beb68885f1cb0ec58425 (diff)
downloadmongo-990b2ef30d7b8fa4db6af6d79da80e3664df9c21.tar.gz
SERVER-9763 Remove BSONObjBuilder append unsigned method
Diffstat (limited to 'src/mongo/bson/bsonobjbuilder_test.cpp')
-rw-r--r--src/mongo/bson/bsonobjbuilder_test.cpp41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/mongo/bson/bsonobjbuilder_test.cpp b/src/mongo/bson/bsonobjbuilder_test.cpp
index a2522d04b58..c5854c38681 100644
--- a/src/mongo/bson/bsonobjbuilder_test.cpp
+++ b/src/mongo/bson/bsonobjbuilder_test.cpp
@@ -29,6 +29,8 @@
#include "mongo/platform/basic.h"
+#include <type_traits>
+
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/unittest/unittest.h"
@@ -73,35 +75,18 @@ TEST(BSONObjBuilderTest, AppendInt64T) {
ASSERT_EQ(obj["b"].Long(), 1ll << 40);
}
-/**
- * current conversion ranges in append(unsigned n)
- * dbl/int max/min in comments refer to max/min encodable constants
- * 0 <= n <= uint_max -----> int
- */
+template <typename T, typename = void>
+struct isUnsignedAppendable : std::false_type {};
-TEST(BSONObjBuilderTest, AppendUnsignedInt) {
- struct {
- unsigned int v;
- BSONType t;
- } data[] = {{0, mongo::NumberInt},
- {100, mongo::NumberInt},
- {maxEncodableInt, mongo::NumberInt},
- {maxEncodableInt + 1, mongo::NumberInt},
- {static_cast<unsigned int>(maxInt), mongo::NumberInt},
- {static_cast<unsigned int>(maxInt) + 1U, mongo::NumberInt},
- {(std::numeric_limits<unsigned int>::max)(), mongo::NumberInt},
- {0, mongo::Undefined}};
- for (int i = 0; data[i].t != mongo::Undefined; i++) {
- unsigned int v = data[i].v;
- BSONObjBuilder b;
- b.append("a", v);
- BSONObj o = b.obj();
- ASSERT_EQUALS(o.nFields(), 1);
- BSONElement e = o.getField("a");
- unsigned int n = e.numberLong();
- ASSERT_EQUALS(n, v);
- assertBSONTypeEquals(e.type(), data[i].t, v, i);
- }
+template <typename T>
+struct isUnsignedAppendable<T, std::void_t<decltype(BSONObjAppendFormat<T>::value)>>
+ : std::true_type {};
+
+TEST(BSONObjBuilderTest, AppendUnsignedIsForbidden) {
+ MONGO_STATIC_ASSERT(!isUnsignedAppendable<unsigned>::value);
+ MONGO_STATIC_ASSERT(!isUnsignedAppendable<unsigned long>::value);
+ MONGO_STATIC_ASSERT(!isUnsignedAppendable<unsigned long long>::value);
+ MONGO_STATIC_ASSERT(!isUnsignedAppendable<uint64_t>::value);
}
/**