From ed7af7cc923316749055d4be7486918d30ed8c59 Mon Sep 17 00:00:00 2001 From: Kaloian Manassiev Date: Sat, 27 Jan 2018 13:45:48 -0500 Subject: SERVER-32367 Make the Command::parseNs* methods take StringData --- src/mongo/db/namespace_string_test.cpp | 63 ++++++++++++++-------------------- 1 file changed, 25 insertions(+), 38 deletions(-) (limited to 'src/mongo/db/namespace_string_test.cpp') 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 -- cgit v1.2.1