diff options
author | Arun Banala <arun.banala@mongodb.com> | 2020-06-24 18:08:15 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-07 18:40:46 +0000 |
commit | afe93cdc36df415f2f1bb22d580786075c368aa4 (patch) | |
tree | e97423896082bf4d892f2bebeab768939c9bf4bb /src/mongo/unittest/bson_test_util.cpp | |
parent | 2a8f91f240f9ec5cb5e47fcbb78a613985de6632 (diff) | |
download | mongo-afe93cdc36df415f2f1bb22d580786075c368aa4.tar.gz |
SERVER-47853 Add unit tests which combine diffing algorithm and application code
Diffstat (limited to 'src/mongo/unittest/bson_test_util.cpp')
-rw-r--r-- | src/mongo/unittest/bson_test_util.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mongo/unittest/bson_test_util.cpp b/src/mongo/unittest/bson_test_util.cpp index a1dbdeb931e..11f504a8f99 100644 --- a/src/mongo/unittest/bson_test_util.cpp +++ b/src/mongo/unittest/bson_test_util.cpp @@ -56,6 +56,26 @@ GENERATE_BSON_CMP_FUNC(BSONObj, GT, SimpleBSONObjComparator::kInstance, >); GENERATE_BSON_CMP_FUNC(BSONObj, GTE, SimpleBSONObjComparator::kInstance, >=); GENERATE_BSON_CMP_FUNC(BSONObj, NE, SimpleBSONObjComparator::kInstance, !=); +// This comparator checks for binary equality. Useful when logical equality (through woCompare()) is +// not strong enough. +class BSONObjBinaryComparator final : public BSONObj::ComparatorInterface { +public: + static const BSONObjBinaryComparator kInstance; + + /** + * The function only supports equals to operation. + */ + int compare(const BSONObj& lhs, const BSONObj& rhs) const final { + return !lhs.binaryEqual(rhs); + } + void hash_combine(size_t& seed, const BSONObj& toHash) const final { + MONGO_UNREACHABLE; + } +}; +const BSONObjBinaryComparator BSONObjBinaryComparator::kInstance{}; + +GENERATE_BSON_CMP_FUNC(BSONObj, BINARY_EQ, BSONObjBinaryComparator::kInstance, ==); + GENERATE_BSON_CMP_FUNC(BSONElement, EQ, SimpleBSONElementComparator::kInstance, ==); GENERATE_BSON_CMP_FUNC(BSONElement, LT, SimpleBSONElementComparator::kInstance, <); GENERATE_BSON_CMP_FUNC(BSONElement, LTE, SimpleBSONElementComparator::kInstance, <=); |