From fdc63bcea520c45440fc8693fd4d7b7719a5913d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 11 Aug 2021 11:51:25 +0800 Subject: [PATCH] test/common: build without "using namespace std" * add "std::" prefix in headers * add "using" declarations in .cc files. so we don't rely on "using namespace std" in one or more included headers. Signed-off-by: Kefu Chai --- src/test/common/Readahead.cc | 2 ++ src/test/common/Throttle.cc | 2 ++ src/test/common/dns_resolve.cc | 1 + src/test/common/get_command_descriptions.cc | 2 ++ src/test/common/test_cdc.cc | 2 ++ src/test/common/test_config.cc | 2 ++ src/test/common/test_context.cc | 2 ++ src/test/common/test_crc32c.cc | 2 +- src/test/common/test_option.cc | 2 ++ src/test/common/test_shared_cache.cc | 2 ++ src/test/common/test_sharedptr_registry.cc | 2 ++ src/test/common/test_time.cc | 1 + src/test/common/test_util.cc | 2 ++ 13 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/test/common/Readahead.cc b/src/test/common/Readahead.cc index 9b4e612849f..30402b02214 100644 --- a/src/test/common/Readahead.cc +++ b/src/test/common/Readahead.cc @@ -28,6 +28,8 @@ } \ } while(0) +using namespace std; + TEST(Readahead, random_access) { Readahead r; r.set_trigger_requests(2); diff --git a/src/test/common/Throttle.cc b/src/test/common/Throttle.cc index c5c984d99a7..b36d0a901de 100644 --- a/src/test/common/Throttle.cc +++ b/src/test/common/Throttle.cc @@ -33,6 +33,8 @@ #include "common/Throttle.h" #include "common/ceph_argparse.h" +using namespace std; + class ThrottleTest : public ::testing::Test { protected: diff --git a/src/test/common/dns_resolve.cc b/src/test/common/dns_resolve.cc index e5b1e5f7b9d..437004860fa 100644 --- a/src/test/common/dns_resolve.cc +++ b/src/test/common/dns_resolve.cc @@ -26,6 +26,7 @@ #define dout_subsys ceph_subsys_ +using namespace std; using ::testing::Return; using ::testing::_; diff --git a/src/test/common/get_command_descriptions.cc b/src/test/common/get_command_descriptions.cc index aef74066a03..b83605ec9bf 100644 --- a/src/test/common/get_command_descriptions.cc +++ b/src/test/common/get_command_descriptions.cc @@ -25,6 +25,8 @@ #include "common/ceph_argparse.h" #include "global/global_init.h" +using namespace std; + static void usage(ostream &out) { out << "usage: get_command_descriptions [options ...]" << std::endl; diff --git a/src/test/common/test_cdc.cc b/src/test/common/test_cdc.cc index 36047655ef7..620ecf4679f 100644 --- a/src/test/common/test_cdc.cc +++ b/src/test/common/test_cdc.cc @@ -11,6 +11,8 @@ #include "common/CDC.h" #include "gtest/gtest.h" +using namespace std; + class CDCTest : public ::testing::Test, public ::testing::WithParamInterface { public: diff --git a/src/test/common/test_config.cc b/src/test/common/test_config.cc index fe5e10c5b52..a70d567a434 100644 --- a/src/test/common/test_config.cc +++ b/src/test/common/test_config.cc @@ -24,6 +24,8 @@ #include "gtest/gtest.h" #include "common/hostname.h" +using namespace std; + extern std::string exec(const char* cmd); // defined in test_hostname.cc class test_config_proxy : public ConfigProxy, public ::testing::Test { diff --git a/src/test/common/test_context.cc b/src/test/common/test_context.cc index 8afdaec1f10..f95c0385303 100644 --- a/src/test/common/test_context.cc +++ b/src/test/common/test_context.cc @@ -26,6 +26,8 @@ #include "common/config_proxy.h" #include "log/Log.h" +using namespace std; + TEST(CephContext, do_command) { CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); diff --git a/src/test/common/test_crc32c.cc b/src/test/common/test_crc32c.cc index 67ec6726369..ff5d0019dba 100644 --- a/src/test/common/test_crc32c.cc +++ b/src/test/common/test_crc32c.cc @@ -293,7 +293,7 @@ double estimate_clock_resolution() double v = *(head++); double range=0; while (head != tail) { - range = max(range, *head - v); + range = std::max(range, *head - v); v = *head; head++; } diff --git a/src/test/common/test_option.cc b/src/test/common/test_option.cc index dd6bab651d9..a75f74dc96d 100644 --- a/src/test/common/test_option.cc +++ b/src/test/common/test_option.cc @@ -9,6 +9,8 @@ #include "common/options.h" +using namespace std; + TEST(Option, validate_min_max) { auto opt = Option{"foo", Option::TYPE_MILLISECS, Option::LEVEL_ADVANCED} diff --git a/src/test/common/test_shared_cache.cc b/src/test/common/test_shared_cache.cc index eeb526236c9..91120c7e59f 100644 --- a/src/test/common/test_shared_cache.cc +++ b/src/test/common/test_shared_cache.cc @@ -26,6 +26,8 @@ #include "common/Thread.h" #include "common/shared_cache.hpp" +using namespace std; + class SharedLRUTest : public SharedLRU { public: auto& get_lock() { return lock; } diff --git a/src/test/common/test_sharedptr_registry.cc b/src/test/common/test_sharedptr_registry.cc index 01d0a848994..9a856652ea9 100644 --- a/src/test/common/test_sharedptr_registry.cc +++ b/src/test/common/test_sharedptr_registry.cc @@ -26,6 +26,8 @@ #include "common/sharedptr_registry.hpp" #include "common/ceph_argparse.h" +using namespace std; + class SharedPtrRegistryTest : public SharedPtrRegistry { public: ceph::mutex &get_lock() { return lock; } diff --git a/src/test/common/test_time.cc b/src/test/common/test_time.cc index 2ce362b63c1..bc19ba573d1 100644 --- a/src/test/common/test_time.cc +++ b/src/test/common/test_time.cc @@ -20,6 +20,7 @@ #include "gtest/gtest.h" #include "include/stringify.h" +using namespace std; using ceph::real_clock; using ceph::real_time; diff --git a/src/test/common/test_util.cc b/src/test/common/test_util.cc index cfef2dbad76..6cc9906906a 100644 --- a/src/test/common/test_util.cc +++ b/src/test/common/test_util.cc @@ -18,6 +18,8 @@ #include "common/ceph_context.h" #include "include/util.h" +using namespace std; + namespace fs = std::filesystem; #if defined(__linux__) -- 2.39.5