summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordcherniev <dcherniev@github.com>2016-12-12 12:47:43 +0200
committerdcherniev <dcherniev@github.com>2017-01-10 13:47:25 +0200
commit0a02193b854c4e0d7c1ef3c61d0f778fb4515a34 (patch)
tree048c53c7e65260bb801f3305add29a74012ef6d2
parent0292ff17af4f4a0f9f686a8c8ae66c4156197e61 (diff)
downloadsdl_core-0a02193b854c4e0d7c1ef3c61d0f778fb4515a34.tar.gz
Replace LastState onto mock object for UT
Replaced last_state variable onto corresponding mock object for TransportManagerDefault unit test. Enabled TransportManagerDefault unit test. Deleted unnecessary copy of app_info_storage2 file that was used only by TransportManagerDefault unit test. Related task : APPLINK-30284
-rw-r--r--src/components/transport_manager/test/CMakeLists.txt3
-rw-r--r--src/components/transport_manager/test/app_info_storage299
-rw-r--r--src/components/transport_manager/test/transport_manager_default_test.cc56
3 files changed, 47 insertions, 111 deletions
diff --git a/src/components/transport_manager/test/CMakeLists.txt b/src/components/transport_manager/test/CMakeLists.txt
index da20f1d43c..f12007fc37 100644
--- a/src/components/transport_manager/test/CMakeLists.txt
+++ b/src/components/transport_manager/test/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2015, Ford Motor Company
+# Copyright (c) 2017, Ford Motor Company
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -73,5 +73,4 @@ set(SOURCES
create_test("transport_manager_test" "${SOURCES}" "${LIBRARIES}")
file(COPY smartDeviceLink_test.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
-file(COPY app_info_storage2 DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
diff --git a/src/components/transport_manager/test/app_info_storage2 b/src/components/transport_manager/test/app_info_storage2
deleted file mode 100644
index 794c8b90bc..0000000000
--- a/src/components/transport_manager/test/app_info_storage2
+++ /dev/null
@@ -1,99 +0,0 @@
-{
- "TransportManager" : {
- "BluetoothAdapter" : null,
- "TcpAdapter" : {
- "devices" : [
- {
- "address" : "57.48.0.1",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name0"
- },
- {
- "address" : "57.48.0.2",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name1"
- },
- {
- "address" : "57.48.0.3",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name2"
- },
- {
- "address" : "57.48.0.4",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name3"
- },
- {
- "address" : "57.48.0.5",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name4"
- },
- {
- "address" : "57.48.0.6",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name5"
- },
- {
- "address" : "57.48.0.7",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name6"
- },
- {
- "address" : "57.48.0.8",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name7"
- },
- {
- "address" : "57.48.0.9",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name8"
- },
- {
- "address" : "57.48.0.10",
- "applications" : [
- {
- "port" : "12345"
- }
- ],
- "name" : "unique_device_name9"
- }
- ]
- }
- }
-}
diff --git a/src/components/transport_manager/test/transport_manager_default_test.cc b/src/components/transport_manager/test/transport_manager_default_test.cc
index 411a7697ec..e3bd0e7240 100644
--- a/src/components/transport_manager/test/transport_manager_default_test.cc
+++ b/src/components/transport_manager/test/transport_manager_default_test.cc
@@ -29,47 +29,83 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
+
#include "gtest/gtest.h"
#include "transport_manager/transport_manager.h"
#include "transport_manager/transport_manager_default.h"
-#include "resumption/last_state.h"
#include "transport_manager/mock_transport_manager_settings.h"
-#include "resumption/last_state_impl.h"
+#include "resumption/mock_last_state.h"
namespace test {
namespace components {
namespace transport_manager_test {
+using ::resumption::MockLastState;
using ::testing::Return;
+using ::testing::ReturnRef;
+using ::testing::NiceMock;
+
+namespace {
+const std::string kDeviceName = "name";
+const std::string kDeviceAddress = "address";
+const std::string kDeviceApplications = "applications";
+const std::string kApplicationPort = "port";
+const std::string kApplicationPortValue = "12345";
+const std::string kTransportManager = "TransportManager";
+const std::string kTcpAdapter = "TcpAdapter";
+const std::string kBluetoothAdapter = "BluetoothAdapter";
+const std::string kDevices = "devices";
+} // namespace
TEST(TestTransportManagerDefault, Init_LastStateNotUsed) {
MockTransportManagerSettings transport_manager_settings;
transport_manager::TransportManagerDefault transport_manager(
transport_manager_settings);
- resumption::LastStateImpl last_state("app_storage_folder",
- "app_info_storage2");
+
+ NiceMock<resumption::MockLastState> mock_last_state;
+ Json::Value custom_dictionary = Json::Value();
+
+ ON_CALL(mock_last_state, get_dictionary())
+ .WillByDefault(ReturnRef(custom_dictionary));
EXPECT_CALL(transport_manager_settings, use_last_state())
.WillRepeatedly(Return(false));
EXPECT_CALL(transport_manager_settings, transport_manager_tcp_adapter_port())
.WillRepeatedly(Return(1u));
- transport_manager.Init(last_state);
+
+ transport_manager.Init(mock_last_state);
+ transport_manager.Stop();
}
-TEST(TestTransportManagerDefault, DISABLED_Init_LastStateUsed) {
- // TODO (dcherniev) : investigate and fix SegFault issue
+TEST(TestTransportManagerDefault, Init_LastStateUsed) {
MockTransportManagerSettings transport_manager_settings;
transport_manager::TransportManagerDefault transport_manager(
transport_manager_settings);
- resumption::LastStateImpl last_state("app_storage_folder",
- "app_info_storage2");
+
+ NiceMock<resumption::MockLastState> mock_last_state;
+ Json::Value custom_dictionary;
+ Json::Value tcp_device;
+ tcp_device[kDeviceName] = "unique_tcp_device_name";
+ tcp_device[kDeviceAddress] = "57.48.0.1";
+ tcp_device[kDeviceApplications][0][kApplicationPort] = kApplicationPortValue;
+ Json::Value bluetooth_device;
+ bluetooth_device[kDeviceName] = "unique_bluetooth_device_name";
+ bluetooth_device[kDeviceAddress] = "57.48.0.2";
+ bluetooth_device[kDeviceApplications][0][kApplicationPort] =
+ kApplicationPortValue;
+ custom_dictionary[kTransportManager][kTcpAdapter][kDevices][0] = tcp_device;
+ custom_dictionary[kTransportManager][kBluetoothAdapter][kDevices][0] =
+ bluetooth_device;
+
+ ON_CALL(mock_last_state, get_dictionary())
+ .WillByDefault(ReturnRef(custom_dictionary));
EXPECT_CALL(transport_manager_settings, use_last_state())
.WillRepeatedly(Return(true));
EXPECT_CALL(transport_manager_settings, transport_manager_tcp_adapter_port())
.WillRepeatedly(Return(1u));
- transport_manager.Init(last_state);
+ transport_manager.Init(mock_last_state);
transport_manager.Stop();
}