diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-01-27 13:45:48 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-02-02 15:38:47 -0500 |
commit | ed7af7cc923316749055d4be7486918d30ed8c59 (patch) | |
tree | fc49d0dd643168d712cd122e86e3031b98346777 | |
parent | 721d2547c6c2883b522740dc2b7ff420aeebb7e9 (diff) | |
download | mongo-ed7af7cc923316749055d4be7486918d30ed8c59.tar.gz |
SERVER-32367 Make the Command::parseNs* methods take StringData
-rw-r--r-- | src/mongo/db/catalog/capped_utils.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/commands.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/commands.h | 12 | ||||
-rw-r--r-- | src/mongo/db/commands/dbcommands.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/concurrency/d_concurrency.h | 9 | ||||
-rw-r--r-- | src/mongo/db/db_raii.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/db_raii.h | 5 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.h | 201 | ||||
-rw-r--r-- | src/mongo/db/namespace_string_test.cpp | 63 |
10 files changed, 129 insertions, 192 deletions
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp index 90af4fbca6d..90b36990e26 100644 --- a/src/mongo/db/catalog/capped_utils.cpp +++ b/src/mongo/db/catalog/capped_utils.cpp @@ -78,7 +78,7 @@ mongo::Status mongo::emptyCapped(OperationContext* opCtx, const NamespaceString& << collectionName.ns()); } - if (NamespaceString::virtualized(collectionName.ns())) { + if (collectionName.isVirtualized()) { return Status(ErrorCodes::IllegalOperation, str::stream() << "Cannot truncate a virtual collection: " << collectionName.ns()); diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index bcd9c3e1d4d..603e1faad33 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -95,8 +95,7 @@ BSONObj CommandHelpers::runCommandDirectly(OperationContext* opCtx, const OpMsgR return out.obj(); } -std::string CommandHelpers::parseNsFullyQualified(const std::string& dbname, - const BSONObj& cmdObj) { +std::string CommandHelpers::parseNsFullyQualified(StringData dbname, const BSONObj& cmdObj) { BSONElement first = cmdObj.firstElement(); uassert(ErrorCodes::BadValue, str::stream() << "collection name has invalid type " << typeName(first.type()), @@ -108,7 +107,7 @@ std::string CommandHelpers::parseNsFullyQualified(const std::string& dbname, return nss.ns(); } -NamespaceString CommandHelpers::parseNsCollectionRequired(const std::string& dbname, +NamespaceString CommandHelpers::parseNsCollectionRequired(StringData dbname, const BSONObj& cmdObj) { // Accepts both BSON String and Symbol for collection name per SERVER-16260 // TODO(kangas) remove Symbol support in MongoDB 3.0 after Ruby driver audit @@ -124,7 +123,7 @@ NamespaceString CommandHelpers::parseNsCollectionRequired(const std::string& dbn } NamespaceString CommandHelpers::parseNsOrUUID(OperationContext* opCtx, - const std::string& dbname, + StringData dbname, const BSONObj& cmdObj) { BSONElement first = cmdObj.firstElement(); if (first.type() == BinData && first.binDataType() == BinDataType::newUUID) { diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index 48cce22e3a6..762b87a87ca 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -50,30 +50,27 @@ namespace mongo { +class Command; class OperationContext; -class Timer; namespace mutablebson { class Document; } // namespace mutablebson -class Command; - // Various helpers unrelated to any single command or to the command registry. // Would be a namespace, but want to keep it closed rather than open. // Some of these may move to the BasicCommand shim if they are only for legacy implementations. struct CommandHelpers { // The type of the first field in 'cmdObj' must be mongo::String. The first field is // interpreted as a collection name. - static std::string parseNsFullyQualified(const std::string& dbname, const BSONObj& cmdObj); + static std::string parseNsFullyQualified(StringData dbname, const BSONObj& cmdObj); // The type of the first field in 'cmdObj' must be mongo::String or Symbol. // The first field is interpreted as a collection name. - static NamespaceString parseNsCollectionRequired(const std::string& dbname, - const BSONObj& cmdObj); + static NamespaceString parseNsCollectionRequired(StringData dbname, const BSONObj& cmdObj); static NamespaceString parseNsOrUUID(OperationContext* opCtx, - const std::string& dbname, + StringData dbname, const BSONObj& cmdObj); static Command* findCommand(StringData name); @@ -245,7 +242,6 @@ public: */ virtual bool supportsWriteConcern(const BSONObj& cmd) const = 0; - /** * Return true if only the admin ns has privileges to run this command. */ diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index 8f25ddcc13d..e469c641ec6 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -423,9 +423,9 @@ public: const BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) { - const NamespaceString nsToDrop = CommandHelpers::parseNsCollectionRequired(dbname, cmdObj); + const NamespaceString nsToDrop(CommandHelpers::parseNsCollectionRequired(dbname, cmdObj)); - if (NamespaceString::virtualized(nsToDrop.ns())) { + if (nsToDrop.isVirtualized()) { errmsg = "can't drop a virtual collection"; return false; } diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h index a3e18176949..76d7a0fa1e7 100644 --- a/src/mongo/db/concurrency/d_concurrency.h +++ b/src/mongo/db/concurrency/d_concurrency.h @@ -63,7 +63,6 @@ public: const bool _locksReleased; }; - /** * General purpose RAII wrapper for a resource managed by the lock manager * @@ -226,7 +225,6 @@ public: const bool _isOutermostLock; }; - /** * Global exclusive lock * @@ -244,7 +242,6 @@ public: } }; - /** * Global shared lock * @@ -262,7 +259,6 @@ public: } }; - /** * Database lock with support for collection- and document-level locking * @@ -304,7 +300,6 @@ public: GlobalLock _globalLock; }; - /** * Collection lock with support for document-level locking * @@ -361,7 +356,6 @@ public: bool _serialized; }; - /** * Turn on "parallel batch writer mode" by locking the global ParallelBatchWriterMode * resource in exclusive mode. This mode is off by default. @@ -381,4 +375,5 @@ public: const bool _orginalShouldConflict; }; }; -} + +} // namespace mongo diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index ee955eee546..bcaf3fb4ec3 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -35,7 +35,6 @@ #include "mongo/db/curop.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/collection_sharding_state.h" -#include "mongo/db/stats/top.h" namespace mongo { @@ -84,7 +83,7 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, opCtx, nss, MODE_IS, AutoGetCollection::ViewMode::kViewsForbidden, std::move(dbSLock)); // Note: this can yield. - _ensureMajorityCommittedSnapshotIsValid(nss, opCtx); + _ensureMajorityCommittedSnapshotIsValid(opCtx, nss); } } @@ -94,7 +93,7 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, _autoColl.emplace(opCtx, nss, MODE_IS, MODE_IS, viewMode); // Note: this can yield. - _ensureMajorityCommittedSnapshotIsValid(nss, opCtx); + _ensureMajorityCommittedSnapshotIsValid(opCtx, nss); } AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, @@ -104,10 +103,10 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, _autoColl.emplace(opCtx, nss, MODE_IS, viewMode, std::move(lock)); // Note: this can yield. - _ensureMajorityCommittedSnapshotIsValid(nss, opCtx); + _ensureMajorityCommittedSnapshotIsValid(opCtx, nss); } -void AutoGetCollectionForRead::_ensureMajorityCommittedSnapshotIsValid(const NamespaceString& nss, - OperationContext* opCtx) { +void AutoGetCollectionForRead::_ensureMajorityCommittedSnapshotIsValid(OperationContext* opCtx, + const NamespaceString& nss) { while (true) { auto coll = _autoColl->getCollection(); if (!coll) { diff --git a/src/mongo/db/db_raii.h b/src/mongo/db/db_raii.h index ec270c2f237..c6201b4fafe 100644 --- a/src/mongo/db/db_raii.h +++ b/src/mongo/db/db_raii.h @@ -101,6 +101,7 @@ public: const NamespaceString& nss, AutoGetCollection::ViewMode viewMode, Lock::DBLock lock); + Database* getDb() const { if (!_autoColl) { return nullptr; @@ -116,8 +117,8 @@ public: } private: - void _ensureMajorityCommittedSnapshotIsValid(const NamespaceString& nss, - OperationContext* opCtx); + void _ensureMajorityCommittedSnapshotIsValid(OperationContext* opCtx, + const NamespaceString& nss); boost::optional<AutoGetCollection> _autoColl; }; diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp index 73e54524fe8..581409e66a8 100644 --- a/src/mongo/db/namespace_string.cpp +++ b/src/mongo/db/namespace_string.cpp @@ -131,6 +131,11 @@ NamespaceString NamespaceString::getTargetNSForListIndexes() const { return NamespaceString(db(), coll().substr(listIndexesCursorNSPrefix.size())); } +std::string NamespaceString::getSisterNS(StringData local) const { + verify(local.size() && local[0] != '.'); + return db().toString() + "." + local.toString(); +} + boost::optional<NamespaceString> NamespaceString::getTargetNSForGloballyManagedNamespace() const { // Globally managed namespaces are of the form '$cmd.commandName.<targetNs>' or simply // '$cmd.commandName'. @@ -147,7 +152,7 @@ bool NamespaceString::isDropPendingNamespace() const { } NamespaceString NamespaceString::makeDropPendingNamespace(const repl::OpTime& opTime) const { - mongo::StringBuilder ss; + StringBuilder ss; ss << db() << "." << dropPendingNSPrefix; ss << opTime.getSecs() << "i" << opTime.getTimestamp().getInc() << "t" << opTime.getTerm(); ss << "." << coll(); diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index 2bc60d7ef97..35015e213bc 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -43,10 +43,6 @@ namespace mongo { const size_t MaxDatabaseNameLen = 128; // max str len for the db name, including null char -/* e.g. - NamespaceString ns("acme.orders"); - cout << ns.coll; // "orders" -*/ class NamespaceString { public: // Reserved system namespaces @@ -87,18 +83,45 @@ public: /** * Constructs an empty NamespaceString. */ - NamespaceString(); + NamespaceString() : _ns(), _dotIndex(std::string::npos) {} /** * Constructs a NamespaceString from the fully qualified namespace named in "ns". */ - explicit NamespaceString(StringData ns); + explicit NamespaceString(StringData ns) { + _ns = ns.toString(); // copy to our buffer + _dotIndex = _ns.find('.'); + uassert(ErrorCodes::InvalidNamespace, + "namespaces cannot have embedded null characters", + _ns.find('\0') == std::string::npos); + } /** * Constructs a NamespaceString for the given database and collection names. * "dbName" must not contain a ".", and "collectionName" must not start with one. */ - NamespaceString(StringData dbName, StringData collectionName); + NamespaceString(StringData dbName, StringData collectionName) + : _ns(dbName.size() + collectionName.size() + 1, '\0') { + uassert(ErrorCodes::InvalidNamespace, + "'.' is an invalid character in a database name", + dbName.find('.') == std::string::npos); + uassert(ErrorCodes::InvalidNamespace, + "Collection names cannot start with '.'", + collectionName.empty() || collectionName[0] != '.'); + + std::string::iterator it = std::copy(dbName.begin(), dbName.end(), _ns.begin()); + *it = '.'; + ++it; + it = std::copy(collectionName.begin(), collectionName.end(), it); + _dotIndex = dbName.size(); + + dassert(it == _ns.end()); + dassert(_ns[_dotIndex] == '.'); + + uassert(ErrorCodes::InvalidNamespace, + "namespaces cannot have embedded null characters", + _ns.find('\0') == std::string::npos); + } /** * Constructs the namespace '<dbName>.$cmd.aggregate', which we use as the namespace for @@ -119,8 +142,8 @@ public: static NamespaceString makeListIndexesNSS(StringData dbName, StringData collectionName); /** - * Note that these values are derived from the mmap_v1 implementation and that - * is the only reason they are constrained as such. + * Note that these values are derived from the mmap_v1 implementation and that is the only + * reason they are constrained as such. */ enum MaxNsLenValue { // Maximum possible length of name any namespace, including special ones like $extra. @@ -136,7 +159,8 @@ public: }; /** - * DollarInDbNameBehavior::allow is deprecated. + * NOTE: DollarInDbNameBehavior::allow is deprecated. + * * Please use DollarInDbNameBehavior::disallow and check explicitly for any DB names that must * contain a $. */ @@ -145,8 +169,15 @@ public: Allow, // Deprecated }; - StringData db() const; - StringData coll() const; + StringData db() const { + return _dotIndex == std::string::npos ? StringData() : StringData(_ns.c_str(), _dotIndex); + } + + StringData coll() const { + return _dotIndex == std::string::npos + ? StringData() + : StringData(_ns.c_str() + _dotIndex + 1, _ns.size() - 1 - _dotIndex); + } const std::string& ns() const { return _ns; @@ -181,7 +212,7 @@ public: return coll().startsWith("system."); } bool isLocal() const { - return db() == "local"; + return db() == kLocalDb; } bool isSystemDotIndexes() const { return coll() == "system.indexes"; @@ -193,10 +224,10 @@ public: return coll() == kSystemDotViewsCollectionName; } bool isAdminDotSystemDotVersion() const { - return ((db() == "admin") && (coll() == "system.version")); + return (db() == kAdminDb) && (coll() == "system.version"); } bool isConfigDB() const { - return db() == "config"; + return db() == kConfigDb; } bool isCommand() const { return coll() == "$cmd"; @@ -208,14 +239,22 @@ public: return special(_ns); } bool isOnInternalDb() const { - return internalDb(db()); + if (db() == kAdminDb) + return true; + if (db() == kLocalDb) + return true; + if (db() == kConfigDb) + return true; + return false; } bool isNormal() const { return normal(_ns); } - // Check if the NamespaceString references a special collection that cannot - // be used for generic data storage. + /** + * Returns whether the NamespaceString references a special collection that cannot be used for + * generic data storage. + */ bool isVirtualized() const { return virtualized(_ns); } @@ -286,51 +325,50 @@ public: NamespaceString getTargetNSForListIndexes() const; /** - * @return true if the namespace is valid. Special namespaces for internal use are considered as + * Returns true if the namespace is valid. Special namespaces for internal use are considered as * valid. */ bool isValid() const { return validDBName(db(), DollarInDbNameBehavior::Allow) && !coll().empty(); } - /** ( foo.bar ).getSisterNS( "blah" ) == foo.blah + /** + * NamespaceString("foo.bar").getSisterNS("blah") returns "foo.blah". */ std::string getSisterNS(StringData local) const; - // @return db() + ".system.indexes" - std::string getSystemIndexesCollection() const; + std::string getSystemIndexesCollection() const { + return db().toString() + ".system.indexes"; + } - // @return {db(), "$cmd"} - NamespaceString getCommandNS() const; + NamespaceString getCommandNS() const { + return {db(), "$cmd"}; + } /** * @return true if ns is 'normal'. A "$" is used for namespaces holding index data, * which do not contain BSON objects in their records. ("oplog.$main" is the exception) */ - static bool normal(StringData ns); + static bool normal(StringData ns) { + return !virtualized(ns); + } /** * @return true if the ns is an oplog one, otherwise false. */ - static bool oplog(StringData ns); - - static bool special(StringData ns); + static bool oplog(StringData ns) { + return ns.startsWith("local.oplog."); + } - // Check if `ns` references a special collection that cannot be used for - // generic data storage. - static bool virtualized(StringData ns); + static bool special(StringData ns) { + return !normal(ns) || ns.substr(ns.find('.')).startsWith(".system."); + } /** - * Returns true for DBs with special meaning to mongodb. + * Check if `ns` references a special collection that cannot be used for generic data storage. */ - static bool internalDb(StringData db) { - if (db == "admin") - return true; - if (db == "local") - return true; - if (db == "config") - return true; - return false; + static bool virtualized(StringData ns) { + return ns.find('$') != std::string::npos && ns != "local.oplog.$main"; } /** @@ -461,36 +499,6 @@ inline bool nsIsDbOnly(StringData ns) { return false; } -/** - * this can change, do not store on disk - */ -int nsDBHash(const std::string& ns); - -inline StringData NamespaceString::db() const { - return _dotIndex == std::string::npos ? StringData() : StringData(_ns.c_str(), _dotIndex); -} - -inline StringData NamespaceString::coll() const { - return _dotIndex == std::string::npos ? StringData() : StringData(_ns.c_str() + _dotIndex + 1, - _ns.size() - 1 - _dotIndex); -} - -inline bool NamespaceString::normal(StringData ns) { - return !virtualized(ns); -} - -inline bool NamespaceString::oplog(StringData ns) { - return ns.startsWith("local.oplog."); -} - -inline bool NamespaceString::special(StringData ns) { - return !normal(ns) || ns.substr(ns.find('.')).startsWith(".system."); -} - -inline bool NamespaceString::virtualized(StringData ns) { - return ns.find('$') != std::string::npos && ns != "local.oplog.$main"; -} - inline bool NamespaceString::validDBName(StringData db, DollarInDbNameBehavior behavior) { if (db.size() == 0 || db.size() >= 64) return false; @@ -553,59 +561,6 @@ inline bool NamespaceString::validCollectionName(StringData coll) { return true; } -inline NamespaceString::NamespaceString() : _ns(), _dotIndex(std::string::npos) {} -inline NamespaceString::NamespaceString(StringData nsIn) { - _ns = nsIn.toString(); // copy to our buffer - _dotIndex = _ns.find('.'); - uassert(ErrorCodes::InvalidNamespace, - "namespaces cannot have embedded null characters", - _ns.find('\0') == std::string::npos); -} - -inline NamespaceString::NamespaceString(StringData dbName, StringData collectionName) - : _ns(dbName.size() + collectionName.size() + 1, '\0') { - uassert(ErrorCodes::InvalidNamespace, - "'.' is an invalid character in a database name", - dbName.find('.') == std::string::npos); - uassert(ErrorCodes::InvalidNamespace, - "Collection names cannot start with '.'", - collectionName.empty() || collectionName[0] != '.'); - std::string::iterator it = std::copy(dbName.begin(), dbName.end(), _ns.begin()); - *it = '.'; - ++it; - it = std::copy(collectionName.begin(), collectionName.end(), it); - _dotIndex = dbName.size(); - dassert(it == _ns.end()); - dassert(_ns[_dotIndex] == '.'); - uassert(ErrorCodes::InvalidNamespace, - "namespaces cannot have embedded null characters", - _ns.find('\0') == std::string::npos); -} - -inline int nsDBHash(const std::string& ns) { - int hash = 7; - for (size_t i = 0; i < ns.size(); i++) { - if (ns[i] == '.') - break; - hash += 11 * (ns[i]); - hash *= 3; - } - return hash; -} - -inline std::string NamespaceString::getSisterNS(StringData local) const { - verify(local.size() && local[0] != '.'); - return db().toString() + "." + local.toString(); -} - -inline std::string NamespaceString::getSystemIndexesCollection() const { - return db().toString() + ".system.indexes"; -} - -inline NamespaceString NamespaceString::getCommandNS() const { - return {db(), "$cmd"}; -} - } // namespace mongo MONGO_HASH_NAMESPACE_START diff --git a/src/mongo/db/namespace_string_test.cpp b/src/mongo/db/namespace_string_test.cpp index c32c2c7bef8..5c4420f4ed3 100644 --- a/src/mongo/db/namespace_string_test.cpp +++ b/src/mongo/db/namespace_string_test.cpp @@ -1,6 +1,5 @@ -// namespacestring_test.cpp - -/* Copyright 2012 10gen Inc. +/** + * Copyright (C) 2018 MongoDB, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, @@ -18,23 +17,23 @@ * code of portions of this program with the OpenSSL library under certain * conditions as described in each individual source file and distribute * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects - * for all of the code used other than as permitted herein. If you modify - * file(s) with this exception, you may extend this exception to your - * version of the file(s), but you are not obligated to do so. If you do not - * wish to do so, delete this exception statement from your version. If you - * delete this exception statement from all source files in the program, - * then also delete it in the license file. + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. */ -#include "mongo/unittest/unittest.h" +#include "mongo/platform/basic.h" #include "mongo/db/namespace_string.h" #include "mongo/db/repl/optime.h" +#include "mongo/unittest/unittest.h" namespace mongo { - -using std::string; +namespace { TEST(NamespaceStringTest, Normal) { ASSERT(NamespaceString::normal("a")); @@ -313,27 +312,13 @@ TEST(NamespaceStringTest, CollectionValidNames) { ASSERT(!NamespaceString::validCollectionName("a\0b"_sd)); } -TEST(NamespaceStringTest, DBHash) { - ASSERT_EQUALS(nsDBHash("foo"), nsDBHash("foo")); - ASSERT_EQUALS(nsDBHash("foo"), nsDBHash("foo.a")); - ASSERT_EQUALS(nsDBHash("foo"), nsDBHash("foo.")); - - ASSERT_EQUALS(nsDBHash(""), nsDBHash("")); - ASSERT_EQUALS(nsDBHash(""), nsDBHash(".a")); - ASSERT_EQUALS(nsDBHash(""), nsDBHash(".")); - - ASSERT_NOT_EQUALS(nsDBHash("foo"), nsDBHash("food")); - ASSERT_NOT_EQUALS(nsDBHash("foo."), nsDBHash("food")); - ASSERT_NOT_EQUALS(nsDBHash("foo.d"), nsDBHash("food")); -} - TEST(NamespaceStringTest, nsToDatabase1) { ASSERT_EQUALS("foo", nsToDatabaseSubstring("foo.bar")); ASSERT_EQUALS("foo", nsToDatabaseSubstring("foo")); ASSERT_EQUALS("foo", nsToDatabase("foo.bar")); ASSERT_EQUALS("foo", nsToDatabase("foo")); - ASSERT_EQUALS("foo", nsToDatabase(string("foo.bar"))); - ASSERT_EQUALS("foo", nsToDatabase(string("foo"))); + ASSERT_EQUALS("foo", nsToDatabase(std::string("foo.bar"))); + ASSERT_EQUALS("foo", nsToDatabase(std::string("foo"))); } TEST(NamespaceStringTest, nsToDatabase2) { @@ -354,26 +339,26 @@ TEST(NamespaceStringTest, nsToDatabase2) { TEST(NamespaceStringTest, NamespaceStringParse1) { NamespaceString ns("a.b"); - ASSERT_EQUALS((string) "a", ns.db()); - ASSERT_EQUALS((string) "b", ns.coll()); + ASSERT_EQUALS(std::string("a"), ns.db()); + ASSERT_EQUALS(std::string("b"), ns.coll()); } TEST(NamespaceStringTest, NamespaceStringParse2) { NamespaceString ns("a.b.c"); - ASSERT_EQUALS((string) "a", ns.db()); - ASSERT_EQUALS((string) "b.c", ns.coll()); + ASSERT_EQUALS(std::string("a"), ns.db()); + ASSERT_EQUALS(std::string("b.c"), ns.coll()); } TEST(NamespaceStringTest, NamespaceStringParse3) { NamespaceString ns("abc"); - ASSERT_EQUALS((string) "", ns.db()); - ASSERT_EQUALS((string) "", ns.coll()); + ASSERT_EQUALS(std::string(""), ns.db()); + ASSERT_EQUALS(std::string(""), ns.coll()); } TEST(NamespaceStringTest, NamespaceStringParse4) { NamespaceString ns("abc."); - ASSERT_EQUALS((string) "abc", ns.db()); - ASSERT_EQUALS((string) "", ns.coll()); + ASSERT_EQUALS(std::string("abc"), ns.db()); + ASSERT_EQUALS(std::string(""), ns.coll()); } TEST(NamespaceStringTest, makeListCollectionsNSIsCorrect) { @@ -404,4 +389,6 @@ TEST(NamespaceStringTest, EmptyNSStringReturnsEmptyDb) { ASSERT_TRUE(nss.isEmpty()); ASSERT_EQ(nss.db(), StringData{}); } -} + +} // namespace +} // namespace mongo |