summaryrefslogtreecommitdiffstats
path: root/src/test/admin_socket.cc
diff options
context:
space:
mode:
authorYao Zongyou <yaozongyou@vip.qq.com>2017-12-25 04:32:54 +0100
committerYao Zongyou <yaozongyou@vip.qq.com>2017-12-25 04:32:54 +0100
commit045a9fde9e74d4d9253c1d8061cf12cf790c4f4f (patch)
tree3ac839855418e862e94721beb2976fe7805ad5aa /src/test/admin_socket.cc
parentMerge pull request #19580 from cbodley/wip-22473 (diff)
downloadceph-045a9fde9e74d4d9253c1d8061cf12cf790c4f4f.tar.xz
ceph-045a9fde9e74d4d9253c1d8061cf12cf790c4f4f.zip
test: fix unittest memory leak to make valgrind silence
Signed-off-by: Yao Zongyou <yaozongyou@vip.qq.com>
Diffstat (limited to 'src/test/admin_socket.cc')
-rw-r--r--src/test/admin_socket.cc36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/test/admin_socket.cc b/src/test/admin_socket.cc
index 2949400f84c..096893e0946 100644
--- a/src/test/admin_socket.cc
+++ b/src/test/admin_socket.cc
@@ -45,15 +45,13 @@ public:
};
TEST(AdminSocket, Teardown) {
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
AdminSocketTest asoct(asokc.get());
ASSERT_EQ(true, asoct.shutdown());
}
TEST(AdminSocket, TeardownSetup) {
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
AdminSocketTest asoct(asokc.get());
ASSERT_EQ(true, asoct.shutdown());
ASSERT_EQ(true, asoct.init(get_rand_socket_path()));
@@ -61,8 +59,7 @@ TEST(AdminSocket, TeardownSetup) {
}
TEST(AdminSocket, SendHelp) {
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
AdminSocketTest asoct(asokc.get());
ASSERT_EQ(true, asoct.shutdown());
ASSERT_EQ(true, asoct.init(get_rand_socket_path()));
@@ -93,8 +90,7 @@ TEST(AdminSocket, SendHelp) {
}
TEST(AdminSocket, SendNoOp) {
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
AdminSocketTest asoct(asokc.get());
ASSERT_EQ(true, asoct.shutdown());
ASSERT_EQ(true, asoct.init(get_rand_socket_path()));
@@ -106,8 +102,7 @@ TEST(AdminSocket, SendNoOp) {
}
TEST(AdminSocket, SendTooLongRequest) {
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
AdminSocketTest asoct(asokc.get());
ASSERT_EQ(true, asoct.shutdown());
ASSERT_EQ(true, asoct.init(get_rand_socket_path()));
@@ -138,13 +133,13 @@ class MyTest : public AdminSocketHook {
};
TEST(AdminSocket, RegisterCommand) {
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
+ std::unique_ptr<AdminSocketHook> my_test_asok = std::make_unique<MyTest>();
AdminSocketTest asoct(asokc.get());
ASSERT_EQ(true, asoct.shutdown());
ASSERT_EQ(true, asoct.init(get_rand_socket_path()));
AdminSocketClient client(get_rand_socket_path());
- ASSERT_EQ(0, asoct.m_asokc->register_command("test", "test", new MyTest(), ""));
+ ASSERT_EQ(0, asoct.m_asokc->register_command("test", "test", my_test_asok.get(), ""));
string result;
ASSERT_EQ("", client.do_request("{\"prefix\":\"test\"}", &result));
ASSERT_EQ("test|", result);
@@ -170,14 +165,15 @@ class MyTest2 : public AdminSocketHook {
};
TEST(AdminSocket, RegisterCommandPrefixes) {
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
+ std::unique_ptr<AdminSocketHook> my_test_asok = std::make_unique<MyTest>();
+ std::unique_ptr<AdminSocketHook> my_test2_asok = std::make_unique<MyTest2>();
AdminSocketTest asoct(asokc.get());
ASSERT_EQ(true, asoct.shutdown());
ASSERT_EQ(true, asoct.init(get_rand_socket_path()));
AdminSocketClient client(get_rand_socket_path());
- ASSERT_EQ(0, asoct.m_asokc->register_command("test", "test name=args,type=CephString,n=N", new MyTest(), ""));
- ASSERT_EQ(0, asoct.m_asokc->register_command("test command", "test command name=args,type=CephString,n=N", new MyTest2(), ""));
+ ASSERT_EQ(0, asoct.m_asokc->register_command("test", "test name=args,type=CephString,n=N", my_test_asok.get(), ""));
+ ASSERT_EQ(0, asoct.m_asokc->register_command("test command", "test command name=args,type=CephString,n=N", my_test2_asok.get(), ""));
string result;
ASSERT_EQ("", client.do_request("{\"prefix\":\"test\"}", &result));
ASSERT_EQ("test|", result);
@@ -213,8 +209,7 @@ public:
TEST(AdminSocketClient, Ping) {
string path = get_rand_socket_path();
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
AdminSocketClient client(path);
// no socket
{
@@ -267,8 +262,7 @@ TEST(AdminSocketClient, Ping) {
TEST(AdminSocket, bind_and_listen) {
string path = get_rand_socket_path();
- std::unique_ptr<AdminSocket>
- asokc(new AdminSocket(g_ceph_context));
+ std::unique_ptr<AdminSocket> asokc = std::make_unique<AdminSocket>(g_ceph_context);
AdminSocketTest asoct(asokc.get());
// successfull bind