diff options
author | David Storch <david.storch@10gen.com> | 2016-08-22 16:41:50 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2016-08-23 17:42:08 -0400 |
commit | f3be5348457ff71185ca9fa137ab7c1a8e4761df (patch) | |
tree | e2bdc25fab6568d577cb14f9905d593c07ee86e4 /src/mongo/dbtests | |
parent | 6b5fd115d38582d8b349a5aad2c29867e69dc758 (diff) | |
download | mongo-f3be5348457ff71185ca9fa137ab7c1a8e4761df.tar.gz |
SERVER-24508 delete BSONObjCmp
Instead, use BSONObj::ComparatorInterface.
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r-- | src/mongo/dbtests/index_access_method_test.cpp | 100 | ||||
-rw-r--r-- | src/mongo/dbtests/jsobjtests.cpp | 19 | ||||
-rw-r--r-- | src/mongo/dbtests/namespacetests.cpp | 5 |
3 files changed, 78 insertions, 46 deletions
diff --git a/src/mongo/dbtests/index_access_method_test.cpp b/src/mongo/dbtests/index_access_method_test.cpp index 59c769d6e87..44ee0eddabd 100644 --- a/src/mongo/dbtests/index_access_method_test.cpp +++ b/src/mongo/dbtests/index_access_method_test.cpp @@ -29,6 +29,7 @@ #include "mongo/platform/basic.h" #include "mongo/bson/bsonobj.h" +#include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/db/index/index_access_method.h" #include "mongo/db/json.h" #include "mongo/unittest/unittest.h" @@ -39,38 +40,42 @@ namespace { using std::vector; TEST(IndexAccessMethodSetDifference, EmptyInputsShouldHaveNoDifference) { - BSONObjSet left{}; - BSONObjSet right{}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = bsonCmp.makeBSONObjSet(); + BSONObjSet right = bsonCmp.makeBSONObjSet(); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQ(0UL, diff.first.size()); ASSERT_EQ(0UL, diff.second.size()); } TEST(IndexAccessMethodSetDifference, EmptyLeftShouldHaveNoDifference) { - BSONObjSet left{}; - BSONObjSet right = {BSON("" << 0)}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = bsonCmp.makeBSONObjSet(); + BSONObjSet right = bsonCmp.makeBSONObjSet({BSON("" << 0)}); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQ(0UL, diff.first.size()); ASSERT_EQ(1UL, diff.second.size()); } TEST(IndexAccessMethodSetDifference, EmptyRightShouldReturnAllOfLeft) { - BSONObjSet left = {BSON("" << 0), BSON("" << 1)}; - BSONObjSet right{}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = bsonCmp.makeBSONObjSet({BSON("" << 0), BSON("" << 1)}); + BSONObjSet right = bsonCmp.makeBSONObjSet(); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQ(2UL, diff.first.size()); ASSERT_EQ(0UL, diff.second.size()); } TEST(IndexAccessMethodSetDifference, IdenticalSetsShouldHaveNoDifference) { - BSONObjSet left = {BSON("" << 0), - BSON("" - << "string"), - BSON("" << BSONNULL)}; - BSONObjSet right = {BSON("" << 0), - BSON("" - << "string"), - BSON("" << BSONNULL)}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = bsonCmp.makeBSONObjSet({BSON("" << 0), + BSON("" + << "string"), + BSON("" << BSONNULL)}); + BSONObjSet right = bsonCmp.makeBSONObjSet({BSON("" << 0), + BSON("" + << "string"), + BSON("" << BSONNULL)}); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQ(0UL, diff.first.size()); ASSERT_EQ(0UL, diff.second.size()); @@ -81,8 +86,9 @@ TEST(IndexAccessMethodSetDifference, IdenticalSetsShouldHaveNoDifference) { // void assertDistinct(BSONObj left, BSONObj right) { - BSONObjSet leftSet = {left}; - BSONObjSet rightSet = {right}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet leftSet = bsonCmp.makeBSONObjSet({left}); + BSONObjSet rightSet = bsonCmp.makeBSONObjSet({right}); auto diff = IndexAccessMethod::setDifference(leftSet, rightSet); ASSERT_EQ(1UL, diff.first.size()); ASSERT_EQ(1UL, diff.second.size()); @@ -120,46 +126,52 @@ TEST(IndexAccessMethodSetDifference, ZerosOfDifferentTypesAreNotEquivalent) { } TEST(IndexAccessMethodSetDifference, ShouldDetectOneDifferenceAmongManySimilarities) { - BSONObjSet left = {BSON("" << 0), - BSON("" - << "string"), - BSON("" << BSONNULL), - BSON("" << static_cast<long long>(1)), // This is different. - BSON("" << BSON("sub" - << "document")), - BSON("" << BSON_ARRAY(1 << "hi" << 42))}; - BSONObjSet right = {BSON("" << 0), - BSON("" - << "string"), - BSON("" << BSONNULL), - BSON("" << static_cast<double>(1.0)), // This is different. - BSON("" << BSON("sub" - << "document")), - BSON("" << BSON_ARRAY(1 << "hi" << 42))}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = + bsonCmp.makeBSONObjSet({BSON("" << 0), + BSON("" + << "string"), + BSON("" << BSONNULL), + BSON("" << static_cast<long long>(1)), // This is different. + BSON("" << BSON("sub" + << "document")), + BSON("" << BSON_ARRAY(1 << "hi" << 42))}); + BSONObjSet right = + bsonCmp.makeBSONObjSet({BSON("" << 0), + BSON("" + << "string"), + BSON("" << BSONNULL), + BSON("" << static_cast<double>(1.0)), // This is different. + BSON("" << BSON("sub" + << "document")), + BSON("" << BSON_ARRAY(1 << "hi" << 42))}); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQUALS(1UL, diff.first.size()); ASSERT_EQUALS(1UL, diff.second.size()); } TEST(IndexAccessMethodSetDifference, SingleObjInLeftShouldFindCorrespondingObjInRight) { - BSONObjSet left = {BSON("" << 2)}; - BSONObjSet right = {BSON("" << 1), BSON("" << 2), BSON("" << 3)}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = bsonCmp.makeBSONObjSet({BSON("" << 2)}); + BSONObjSet right = bsonCmp.makeBSONObjSet({BSON("" << 1), BSON("" << 2), BSON("" << 3)}); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQUALS(0UL, diff.first.size()); ASSERT_EQUALS(2UL, diff.second.size()); } TEST(IndexAccessMethodSetDifference, SingleObjInRightShouldFindCorrespondingObjInLeft) { - BSONObjSet left = {BSON("" << 1), BSON("" << 2), BSON("" << 3)}; - BSONObjSet right = {BSON("" << 2)}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = bsonCmp.makeBSONObjSet({BSON("" << 1), BSON("" << 2), BSON("" << 3)}); + BSONObjSet right = bsonCmp.makeBSONObjSet({BSON("" << 2)}); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQUALS(2UL, diff.first.size()); ASSERT_EQUALS(0UL, diff.second.size()); } TEST(IndexAccessMethodSetDifference, LeftSetAllSmallerThanRightShouldBeDisjoint) { - BSONObjSet left = {BSON("" << 1), BSON("" << 2), BSON("" << 3)}; - BSONObjSet right = {BSON("" << 4), BSON("" << 5), BSON("" << 6)}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = bsonCmp.makeBSONObjSet({BSON("" << 1), BSON("" << 2), BSON("" << 3)}); + BSONObjSet right = bsonCmp.makeBSONObjSet({BSON("" << 4), BSON("" << 5), BSON("" << 6)}); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQUALS(3UL, diff.first.size()); ASSERT_EQUALS(3UL, diff.second.size()); @@ -172,8 +184,9 @@ TEST(IndexAccessMethodSetDifference, LeftSetAllSmallerThanRightShouldBeDisjoint) } TEST(IndexAccessMethodSetDifference, LeftSetAllLargerThanRightShouldBeDisjoint) { - BSONObjSet left = {BSON("" << 4), BSON("" << 5), BSON("" << 6)}; - BSONObjSet right = {BSON("" << 1), BSON("" << 2), BSON("" << 3)}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = bsonCmp.makeBSONObjSet({BSON("" << 4), BSON("" << 5), BSON("" << 6)}); + BSONObjSet right = bsonCmp.makeBSONObjSet({BSON("" << 1), BSON("" << 2), BSON("" << 3)}); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQUALS(3UL, diff.first.size()); ASSERT_EQUALS(3UL, diff.second.size()); @@ -186,8 +199,11 @@ TEST(IndexAccessMethodSetDifference, LeftSetAllLargerThanRightShouldBeDisjoint) } TEST(IndexAccessMethodSetDifference, ShouldNotReportOverlapsFromNonDisjointSets) { - BSONObjSet left = {BSON("" << 0), BSON("" << 1), BSON("" << 4), BSON("" << 6)}; - BSONObjSet right = {BSON("" << -1), BSON("" << 1), BSON("" << 3), BSON("" << 4), BSON("" << 7)}; + SimpleBSONObjComparator bsonCmp; + BSONObjSet left = + bsonCmp.makeBSONObjSet({BSON("" << 0), BSON("" << 1), BSON("" << 4), BSON("" << 6)}); + BSONObjSet right = bsonCmp.makeBSONObjSet( + {BSON("" << -1), BSON("" << 1), BSON("" << 3), BSON("" << 4), BSON("" << 7)}); auto diff = IndexAccessMethod::setDifference(left, right); ASSERT_EQUALS(2UL, diff.first.size()); // 0, 6. ASSERT_EQUALS(3UL, diff.second.size()); // -1, 3, 7. diff --git a/src/mongo/dbtests/jsobjtests.cpp b/src/mongo/dbtests/jsobjtests.cpp index 34dff8ada09..72d18905a5f 100644 --- a/src/mongo/dbtests/jsobjtests.cpp +++ b/src/mongo/dbtests/jsobjtests.cpp @@ -36,6 +36,7 @@ #include <cmath> #include <iostream> +#include "mongo/bson/bsonobj_comparator.h" #include "mongo/bson/util/builder.h" #include "mongo/db/bson/dotted_path_support.h" #include "mongo/db/jsobj.h" @@ -59,6 +60,18 @@ using std::vector; namespace dps = ::mongo::dotted_path_support; +namespace { + +enum FieldCompareResult { + LEFT_SUBFIELD = -2, + LEFT_BEFORE = -1, + SAME = 0, + RIGHT_BEFORE = 1, + RIGHT_SUBFIELD = 2 +}; + +} // namespace + typedef std::map<std::string, BSONElement> BSONMap; BSONMap bson2map(const BSONObj& obj) { BSONMap m; @@ -1755,8 +1768,10 @@ public: } void test(BSONObj order, BSONObj l, BSONObj r, bool wanted) { - BSONObjCmp c(order); - bool got = c(l, r); + const StringData::ComparatorInterface* stringComparator = nullptr; + BSONObjComparator bsonCmp( + order, BSONObjComparator::FieldNamesMode::kConsider, stringComparator); + bool got = bsonCmp.makeLessThan()(l, r); if (got == wanted) return; cout << " order: " << order << " l: " << l << "r: " << r << " wanted: " << wanted diff --git a/src/mongo/dbtests/namespacetests.cpp b/src/mongo/dbtests/namespacetests.cpp index 479d7d2317c..7be6bdd1b24 100644 --- a/src/mongo/dbtests/namespacetests.cpp +++ b/src/mongo/dbtests/namespacetests.cpp @@ -35,6 +35,7 @@ #include <string> +#include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/client.h" @@ -100,7 +101,7 @@ public: BSONObj nullObj = BSON("a" << BSONNULL); // Call getKeys on the nullObj. - BSONObjSet nullFieldKeySet; + BSONObjSet nullFieldKeySet = SimpleBSONObjComparator::kInstance.makeBSONObjSet(); const CollatorInterface* collator = nullptr; ExpressionKeysPrivate::getHashKeys(nullObj, "a", 0, 0, false, collator, &nullFieldKeySet); BSONElement nullFieldFromKey = nullFieldKeySet.begin()->firstElement(); @@ -129,7 +130,7 @@ public: << 0x5eed)); BSONObj nullObj = BSON("a" << BSONNULL); - BSONObjSet nullFieldKeySet; + BSONObjSet nullFieldKeySet = SimpleBSONObjComparator::kInstance.makeBSONObjSet(); const CollatorInterface* collator = nullptr; ExpressionKeysPrivate::getHashKeys( nullObj, "a", 0x5eed, 0, false, collator, &nullFieldKeySet); |