Fix memory leak for unit_tests 65/204165/5
authorInkyun Kil <inkyun.kil@samsung.com>
Mon, 22 Apr 2019 02:29:37 +0000 (11:29 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Mon, 22 Apr 2019 22:54:13 +0000 (07:54 +0900)
Change-Id: I4c7071117f83181358576a35987ed104b08e9fd1
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
unit_tests/src/app_control_unittest.cc

index 059cfef2144fbb76c8d662e09660d0c47316cd17..8cef8bc125c17f7269ed5a6ef443d2b5bc9d1f97 100644 (file)
@@ -82,18 +82,22 @@ class AppControlTest : public testing::Test {
  */
 TEST_F(AppControlTest, app_control_create_from_uri_handle_p) {
   app_control_h app_control;
-  char *uri;
-  char *query_tag;
   int r = app_control_create_from_uri_handle(&app_control, uri_);
   EXPECT_EQ(r, APP_CONTROL_ERROR_NONE);
 
-  r = app_control_get_uri(app_control, &uri);
+  std::unique_ptr<std::remove_pointer<app_control_h>::type,
+    decltype(app_control_destroy)*> handle(app_control, app_control_destroy);
+
+  char *v;
+  r = app_control_get_uri(handle.get(), &v);
   EXPECT_EQ(r, APP_CONTROL_ERROR_NONE);
-  EXPECT_STREQ(uri, EXAM_URI1);
+  auto value = std::unique_ptr<char, decltype(std::free)*>(v, std::free);
+  EXPECT_EQ(std::string(value.get()), EXAM_URI1);
 
-  r = app_control_get_extra_data(app_control, "tag", &query_tag);
+  r = app_control_get_extra_data(handle.get(), "tag", &v);
   EXPECT_EQ(r, APP_CONTROL_ERROR_NONE);
-  EXPECT_STREQ(query_tag, "networking");
+  value = std::unique_ptr<char, decltype(std::free)*>(v, std::free);
+  EXPECT_EQ(std::string(value.get()), "networking");
 }
 
 /*
@@ -103,14 +107,18 @@ TEST_F(AppControlTest, app_control_create_from_uri_handle_p) {
  */
 TEST_F(AppControlTest, app_control_set_uri_by_handle_p) {
   app_control_h app_control;
-  char *uri;
   int r = app_control_create(&app_control);
   EXPECT_EQ(r, APP_CONTROL_URI_ERROR_NONE);
 
-  r = app_control_set_uri_by_handle(app_control, uri_);
+  std::unique_ptr<std::remove_pointer<app_control_h>::type,
+    decltype(app_control_destroy)*> handle(app_control, app_control_destroy);
+
+  r = app_control_set_uri_by_handle(handle.get(), uri_);
   EXPECT_EQ(r, APP_CONTROL_URI_ERROR_NONE);
 
-  r = app_control_get_uri(app_control, &uri);
+  char *v;
+  r = app_control_get_uri(handle.get(), &v);
   EXPECT_EQ(r, APP_CONTROL_ERROR_NONE);
-  EXPECT_STREQ(uri, EXAM_URI1);
+  auto value = std::unique_ptr<char, decltype(std::free)*>(v, std::free);
+  EXPECT_EQ(std::string(value.get()), EXAM_URI1);
 }