Skip to content

Commit

Permalink
fixup! UTs fix memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sniukalov committed Jun 4, 2020
1 parent 5f9174c commit be4a738
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MobileMessageHandlerTest : public testing::Test {

// Act
size_t payload_size = data.size();
const auto message = std::shared_ptr<Message>(HandleIncomingMessage(
const auto message = std::unique_ptr<Message>(HandleIncomingMessage(
protocol_version, json_plus_binary_data, payload_size));

// Checks
Expand All @@ -148,7 +148,7 @@ class MobileMessageHandlerTest : public testing::Test {
// Arrange
size_t payload_size = data.size();
size_t full_data_size = data.size() + PROTOCOL_HEADER_V2_SIZE;
const auto message = std::shared_ptr<Message>(
const auto message = std::unique_ptr<Message>(
HandleIncomingMessage(protocol_version, data, payload_size));

// Checks
Expand Down Expand Up @@ -197,7 +197,7 @@ class MobileMessageHandlerTest : public testing::Test {
MobileMessage message_to_send = CreateMessageForSending(
protocol_version, function_id, correlation_id, connection_key, data);
// Act
std::shared_ptr<RawMessage> result_message(
const std::unique_ptr<RawMessage> result_message(
MobileMessageHandler::HandleOutgoingMessageProtocol(message_to_send));

std::vector<uint8_t> full_data = joiner<std::vector<uint8_t> >(
Expand All @@ -218,9 +218,8 @@ class MobileMessageHandlerTest : public testing::Test {
void TestHandlingOutgoingMessageProtocolWithBinaryData(
const uint32_t protocol_version) {
// Arrange
application_manager::BinaryData* bin_dat =
new application_manager::BinaryData;
bin_dat->push_back('\a');
application_manager::BinaryData bin_dat;
bin_dat.push_back('\a');

const uint32_t function_id = 247u;
const uint32_t correlation_id = 92u;
Expand All @@ -231,16 +230,14 @@ class MobileMessageHandlerTest : public testing::Test {
correlation_id,
connection_key,
data,
bin_dat);
&bin_dat);
// Act
std::shared_ptr<RawMessage> result_message(
const std::unique_ptr<RawMessage> result_message(
MobileMessageHandler::HandleOutgoingMessageProtocol(message_to_send));
std::vector<uint8_t> full_data = joiner<std::vector<uint8_t> >(
binary_header, binary_header + PROTOCOL_HEADER_V2_SIZE, data);
size_t full_size =
sizeof(uint8_t) * full_data.size() + bin_dat->size() * sizeof(uint8_t);

delete bin_dat;
sizeof(uint8_t) * full_data.size() + bin_dat.size() * sizeof(uint8_t);

// Checks
EXPECT_EQ(protocol_version, result_message->protocol_version());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST(MobileMessageHandlerTestV1Test,
data_json.length(),
false);

std::shared_ptr<application_manager::Message> ptr(
const std::unique_ptr<application_manager::Message> ptr(
MobileMessageHandler::HandleIncomingMessageProtocol(message));

ASSERT_TRUE(ptr.get());
Expand All @@ -98,7 +98,7 @@ TEST(MobileMessageHandlerTestV1Test,
full_data.length(),
false);

const auto ptr = std::shared_ptr<application_manager::Message>(
const auto ptr = std::unique_ptr<application_manager::Message>(
MobileMessageHandler::HandleIncomingMessageProtocol(message));

ASSERT_TRUE(ptr.get());
Expand All @@ -121,7 +121,7 @@ TEST(MobileMessageHandlerTestV1Test,
message->set_json_message(data_json);
message->set_connection_key(connection_key_p1);

std::shared_ptr<RawMessage> ptr(
const std::unique_ptr<RawMessage> ptr(
MobileMessageHandler::HandleOutgoingMessageProtocol(message));

ASSERT_TRUE(ptr.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,58 @@ ResumptionDataTest::~ResumptionDataTest() {
delete submenu.second;
}

test_submenu_map.clear();

for (auto& command : test_commands_map) {
delete command.second;
}

test_commands_map.clear();

for (auto& choiceset : test_choiceset_map) {
delete choiceset.second;
}

test_choiceset_map.clear();

if (help_prompt_) {
delete help_prompt_;
help_prompt_ = nullptr;
}

if (timeout_prompt_) {
delete timeout_prompt_;
timeout_prompt_ = nullptr;
}

if (vr_help_) {
delete vr_help_;
vr_help_ = nullptr;
}

if (vr_help_title_) {
delete vr_help_title_;
vr_help_title_ = nullptr;
}

if (vr_synonyms_) {
delete vr_synonyms_;
vr_synonyms_ = nullptr;
}

if (keyboard_props_) {
delete keyboard_props_;
keyboard_props_ = nullptr;
}

if (menu_title_) {
delete menu_title_;
menu_title_ = nullptr;
}

if (menu_icon_) {
delete menu_icon_;
menu_icon_ = nullptr;
}
}

Expand Down

0 comments on commit be4a738

Please sign in to comment.