summaryrefslogtreecommitdiff
path: root/src/mongo/bson/mutable
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2016-05-17 10:16:59 -0400
committerGeert Bosch <geert@mongodb.com>2016-05-18 13:34:27 -0400
commit08258bc54ed53df7cda57330d473bfa1dfd90658 (patch)
treec772b40e4d63d06dea23e3b145c6880bd426fb10 /src/mongo/bson/mutable
parent66dc1f6a38932b894cdae77bd4b5f370a8d5a31a (diff)
downloadmongo-08258bc54ed53df7cda57330d473bfa1dfd90658.tar.gz
SERVER-23553 Remove Decimal128::enabled; now always true
Diffstat (limited to 'src/mongo/bson/mutable')
-rw-r--r--src/mongo/bson/mutable/mutable_bson_test.cpp204
1 files changed, 91 insertions, 113 deletions
diff --git a/src/mongo/bson/mutable/mutable_bson_test.cpp b/src/mongo/bson/mutable/mutable_bson_test.cpp
index 0ec8dfdbcd6..3c865cea71a 100644
--- a/src/mongo/bson/mutable/mutable_bson_test.cpp
+++ b/src/mongo/bson/mutable/mutable_bson_test.cpp
@@ -564,10 +564,8 @@ TEST(Element, setters) {
t0.setValueDouble(123.45);
ASSERT_EQUALS(mongo::NumberDouble, t0.getType());
- if (mongo::Decimal128::enabled) {
- t0.setValueDecimal(mongo::Decimal128("123.45E1234"));
- ASSERT_EQUALS(mongo::NumberDecimal, t0.getType());
- }
+ t0.setValueDecimal(mongo::Decimal128("123.45E1234"));
+ ASSERT_EQUALS(mongo::NumberDecimal, t0.getType());
t0.setValueOID(mongo::OID("47cc67093475061e3d95369d"));
ASSERT_EQUALS(mongo::jstOID, t0.getType());
@@ -614,40 +612,34 @@ TEST(Element, toString) {
}
TEST(DecimalType, createElement) {
- if (mongo::Decimal128::enabled) {
- mmb::Document doc;
+ mmb::Document doc;
- mmb::Element d0 = doc.makeElementDecimal("d0", mongo::Decimal128("12345"));
- ASSERT_TRUE(mongo::Decimal128("12345").isEqual(d0.getValueDecimal()));
- }
+ mmb::Element d0 = doc.makeElementDecimal("d0", mongo::Decimal128("12345"));
+ ASSERT_TRUE(mongo::Decimal128("12345").isEqual(d0.getValueDecimal()));
}
TEST(DecimalType, setElement) {
- if (mongo::Decimal128::enabled) {
- mmb::Document doc;
+ mmb::Document doc;
- mmb::Element d0 = doc.makeElementDecimal("d0", mongo::Decimal128("128"));
- d0.setValueDecimal(mongo::Decimal128("123456"));
- ASSERT_TRUE(mongo::Decimal128("123456").isEqual(d0.getValueDecimal()));
+ mmb::Element d0 = doc.makeElementDecimal("d0", mongo::Decimal128("128"));
+ d0.setValueDecimal(mongo::Decimal128("123456"));
+ ASSERT_TRUE(mongo::Decimal128("123456").isEqual(d0.getValueDecimal()));
- d0.setValueDouble(0.1);
- ASSERT_EQUALS(0.1, d0.getValueDouble());
- d0.setValueDecimal(mongo::Decimal128("23"));
- ASSERT_TRUE(mongo::Decimal128("23").isEqual(d0.getValueDecimal()));
- }
+ d0.setValueDouble(0.1);
+ ASSERT_EQUALS(0.1, d0.getValueDouble());
+ d0.setValueDecimal(mongo::Decimal128("23"));
+ ASSERT_TRUE(mongo::Decimal128("23").isEqual(d0.getValueDecimal()));
}
TEST(DecimalType, appendElement) {
- if (mongo::Decimal128::enabled) {
- mmb::Document doc;
+ mmb::Document doc;
- mmb::Element d0 = doc.makeElementObject("e0");
- d0.appendDecimal("precision", mongo::Decimal128(34));
+ mmb::Element d0 = doc.makeElementObject("e0");
+ d0.appendDecimal("precision", mongo::Decimal128(34));
- mmb::Element it = mmb::findFirstChildNamed(d0, "precision");
- ASSERT_TRUE(it.ok());
- ASSERT_TRUE(mongo::Decimal128(34).isEqual(it.getValueDecimal()));
- }
+ mmb::Element it = mmb::findFirstChildNamed(d0, "precision");
+ ASSERT_TRUE(it.ok());
+ ASSERT_TRUE(mongo::Decimal128(34).isEqual(it.getValueDecimal()));
}
TEST(TimestampType, createElement) {
@@ -716,12 +708,10 @@ TEST(SafeNumType, getSafeNum) {
num = t0.getValueSafeNum();
ASSERT_EQUALS(num, 123.456789);
- if (mongo::Decimal128::enabled) {
- t0.setValueDecimal(mongo::Decimal128("12345678.1234"));
- ASSERT_TRUE(mongo::Decimal128("12345678.1234").isEqual(t0.getValueDecimal()));
- num = t0.getValueSafeNum();
- ASSERT_EQUALS(num, mongo::Decimal128("12345678.1234"));
- }
+ t0.setValueDecimal(mongo::Decimal128("12345678.1234"));
+ ASSERT_TRUE(mongo::Decimal128("12345678.1234").isEqual(t0.getValueDecimal()));
+ num = t0.getValueSafeNum();
+ ASSERT_EQUALS(num, mongo::Decimal128("12345678.1234"));
}
TEST(SafeNumType, setSafeNum) {
@@ -814,11 +804,7 @@ static const char jsonSampleWithDecimal[] =
TEST(Serialization, RoundTrip) {
mongo::BSONObj obj;
- if (mongo::Decimal128::enabled) {
- obj = mongo::fromjson(jsonSampleWithDecimal);
- } else {
- obj = mongo::fromjson(jsonSample);
- }
+ obj = mongo::fromjson(jsonSampleWithDecimal);
mmb::Document doc(obj.copy());
mongo::BSONObj built = doc.getObject();
ASSERT_EQUALS(obj, built);
@@ -1387,10 +1373,8 @@ TEST(Element, IsNumeric) {
elt = doc.makeElementDouble("dummy", 42.0);
ASSERT_TRUE(elt.isNumeric());
- if (mongo::Decimal128::enabled) {
- elt = doc.makeElementDecimal("dummy", mongo::Decimal128(20));
- ASSERT_TRUE(elt.isNumeric());
- }
+ elt = doc.makeElementDecimal("dummy", mongo::Decimal128(20));
+ ASSERT_TRUE(elt.isNumeric());
}
TEST(Element, IsIntegral) {
@@ -1411,10 +1395,8 @@ TEST(Element, IsIntegral) {
elt = doc.makeElementDouble("dummy", 42.0);
ASSERT_FALSE(elt.isIntegral());
- if (mongo::Decimal128::enabled) {
- elt = doc.makeElementDecimal("dummy", mongo::Decimal128(20));
- ASSERT_FALSE(elt.isIntegral());
- }
+ elt = doc.makeElementDecimal("dummy", mongo::Decimal128(20));
+ ASSERT_FALSE(elt.isIntegral());
}
TEST(Document, ArraySerialization) {
@@ -2576,45 +2558,43 @@ TEST(TypeSupport, EncodingEquivalenceLong) {
}
TEST(TypeSupport, EncodingEquivalenceDecimal) {
- if (mongo::Decimal128::enabled) {
- mongo::BSONObjBuilder builder;
- const char name[] = "thing";
- const mongo::Decimal128 value1 = mongo::Decimal128(2);
- builder.append(name, value1);
- mongo::BSONObj source = builder.done();
- const mongo::BSONElement thing = source.firstElement();
- ASSERT_TRUE(thing.type() == mongo::NumberDecimal);
-
- mmb::Document doc;
-
- // Construct via direct call to append/make
- ASSERT_OK(doc.root().appendDecimal(name, value1));
- mmb::Element a = doc.root().rightChild();
- ASSERT_TRUE(a.ok());
- ASSERT_EQUALS(a.getType(), mongo::NumberDecimal);
- ASSERT_TRUE(a.hasValue());
- ASSERT_TRUE(value1.isEqual(mmb::ConstElement(a).getValueDecimal()));
-
- // Construct via call passong BSON element
- ASSERT_OK(doc.root().appendElement(thing));
- mmb::Element b = doc.root().rightChild();
- ASSERT_TRUE(b.ok());
- ASSERT_EQUALS(b.getType(), mongo::NumberDecimal);
- ASSERT_TRUE(b.hasValue());
-
- // Construct via setValue call
- ASSERT_OK(doc.root().appendNull(name));
- mmb::Element c = doc.root().rightChild();
- ASSERT_TRUE(c.ok());
- c.setValueDecimal(value1);
- ASSERT_EQUALS(c.getType(), mongo::NumberDecimal);
- ASSERT_TRUE(c.hasValue());
-
- // Ensure identity:
- ASSERT_TRUE(identical(thing, mmb::ConstElement(a).getValue()));
- ASSERT_TRUE(identical(a.getValue(), b.getValue()));
- ASSERT_TRUE(identical(b.getValue(), c.getValue()));
- }
+ mongo::BSONObjBuilder builder;
+ const char name[] = "thing";
+ const mongo::Decimal128 value1 = mongo::Decimal128(2);
+ builder.append(name, value1);
+ mongo::BSONObj source = builder.done();
+ const mongo::BSONElement thing = source.firstElement();
+ ASSERT_TRUE(thing.type() == mongo::NumberDecimal);
+
+ mmb::Document doc;
+
+ // Construct via direct call to append/make
+ ASSERT_OK(doc.root().appendDecimal(name, value1));
+ mmb::Element a = doc.root().rightChild();
+ ASSERT_TRUE(a.ok());
+ ASSERT_EQUALS(a.getType(), mongo::NumberDecimal);
+ ASSERT_TRUE(a.hasValue());
+ ASSERT_TRUE(value1.isEqual(mmb::ConstElement(a).getValueDecimal()));
+
+ // Construct via call passong BSON element
+ ASSERT_OK(doc.root().appendElement(thing));
+ mmb::Element b = doc.root().rightChild();
+ ASSERT_TRUE(b.ok());
+ ASSERT_EQUALS(b.getType(), mongo::NumberDecimal);
+ ASSERT_TRUE(b.hasValue());
+
+ // Construct via setValue call
+ ASSERT_OK(doc.root().appendNull(name));
+ mmb::Element c = doc.root().rightChild();
+ ASSERT_TRUE(c.ok());
+ c.setValueDecimal(value1);
+ ASSERT_EQUALS(c.getType(), mongo::NumberDecimal);
+ ASSERT_TRUE(c.hasValue());
+
+ // Ensure identity:
+ ASSERT_TRUE(identical(thing, mmb::ConstElement(a).getValue()));
+ ASSERT_TRUE(identical(a.getValue(), b.getValue()));
+ ASSERT_TRUE(identical(b.getValue(), c.getValue()));
}
TEST(TypeSupport, EncodingEquivalenceMinKey) {
@@ -3141,34 +3121,32 @@ TEST(DocumentInPlace, NumberDoubleLifecycle) {
}
TEST(DocumentInPlace, NumberDecimalLifecycle) {
- if (mongo::Decimal128::enabled) {
- const mongo::Decimal128 value1 = mongo::Decimal128(32);
- const mongo::Decimal128 value2 = mongo::Decimal128(2);
-
- mongo::BSONObj obj(BSON("x" << value1));
- mmb::Document doc(obj, mmb::Document::kInPlaceEnabled);
-
- mmb::Element x = doc.root().leftChild();
-
- mmb::DamageVector damages;
- const char* source = NULL;
-
- x.setValueDecimal(value2);
- ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
- ASSERT_EQUALS(1U, damages.size());
- apply(&obj, damages, source);
- ASSERT_TRUE(x.hasValue());
- ASSERT_TRUE(x.isType(mongo::NumberDecimal));
- ASSERT_TRUE(value2.isEqual(x.getValueDecimal()));
-
- // TODO: Re-enable when in-place updates to leaf elements is supported
- // x.setValueDecimal(value1);
- // ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
- // apply(&obj, damages, source);
- // ASSERT_TRUE(x.hasValue());
- // ASSERT_TRUE(x.isType(mongo::NumberDecimal));
- // ASSERT_TRUE(value1.isEqual(x.getValueDecimal()));
- }
+ const mongo::Decimal128 value1 = mongo::Decimal128(32);
+ const mongo::Decimal128 value2 = mongo::Decimal128(2);
+
+ mongo::BSONObj obj(BSON("x" << value1));
+ mmb::Document doc(obj, mmb::Document::kInPlaceEnabled);
+
+ mmb::Element x = doc.root().leftChild();
+
+ mmb::DamageVector damages;
+ const char* source = NULL;
+
+ x.setValueDecimal(value2);
+ ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
+ ASSERT_EQUALS(1U, damages.size());
+ apply(&obj, damages, source);
+ ASSERT_TRUE(x.hasValue());
+ ASSERT_TRUE(x.isType(mongo::NumberDecimal));
+ ASSERT_TRUE(value2.isEqual(x.getValueDecimal()));
+
+ // TODO: Re-enable when in-place updates to leaf elements is supported
+ // x.setValueDecimal(value1);
+ // ASSERT_TRUE(doc.getInPlaceUpdates(&damages, &source));
+ // apply(&obj, damages, source);
+ // ASSERT_TRUE(x.hasValue());
+ // ASSERT_TRUE(x.isType(mongo::NumberDecimal));
+ // ASSERT_TRUE(value1.isEqual(x.getValueDecimal()));
}
// Doubles and longs are the same size, 8 bytes, so we should be able to do in-place