summaryrefslogtreecommitdiff
path: root/src/components/transport_manager/test/transport_manager_default_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/transport_manager/test/transport_manager_default_test.cc')
-rw-r--r--src/components/transport_manager/test/transport_manager_default_test.cc89
1 files changed, 80 insertions, 9 deletions
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 8207737d93..d095a51cb6 100644
--- a/src/components/transport_manager/test/transport_manager_default_test.cc
+++ b/src/components/transport_manager/test/transport_manager_default_test.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Ford Motor Company
+ * Copyright (c) 2017, Ford Motor Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,44 +29,115 @@
* 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.h"
+#include "resumption/mock_last_state.h"
namespace test {
namespace components {
namespace transport_manager_test {
+using resumption_test::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 kApplicationRfcomm = "rfcomm_channel";
+const std::string kApplicationRfcommValue = "7";
+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::LastState last_state("app_storage_folder", "app_info_storage2");
+
+ NiceMock<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);
+ .WillRepeatedly(Return(12345u));
+
+ transport_manager.Init(mock_last_state);
+ transport_manager.Stop();
}
TEST(TestTransportManagerDefault, Init_LastStateUsed) {
MockTransportManagerSettings transport_manager_settings;
transport_manager::TransportManagerDefault transport_manager(
transport_manager_settings);
- resumption::LastState last_state("app_storage_folder", "app_info_storage2");
+
+ NiceMock<MockLastState> mock_last_state;
+ Json::Value custom_dictionary;
+ Json::Value tcp_device;
+ tcp_device[kDeviceName] = "unique_tcp_device_name";
+ tcp_device[kDeviceAddress] = "127.0.0.1";
+ tcp_device[kDeviceApplications][0][kApplicationPort] = kApplicationPortValue;
+ Json::Value bluetooth_device;
+ bluetooth_device[kDeviceName] = "unique_bluetooth_device_name";
+ bluetooth_device[kDeviceAddress] = "AB:CD:EF:GH:IJ:KL";
+ bluetooth_device[kDeviceApplications][0][kApplicationRfcomm] =
+ kApplicationRfcommValue;
+ 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));
+ .WillRepeatedly(Return(12345u));
+ transport_manager.Init(mock_last_state);
+ transport_manager.Stop();
+}
+
+TEST(TestTransportManagerDefault, Init_LastStateUsed_InvalidPort) {
+ MockTransportManagerSettings transport_manager_settings;
+ transport_manager::TransportManagerDefault transport_manager(
+ transport_manager_settings);
+
+ NiceMock<MockLastState> mock_last_state;
+ Json::Value custom_dictionary;
+ Json::Value tcp_device;
+ tcp_device[kDeviceName] = "unique_tcp_device_name";
+ tcp_device[kDeviceAddress] = "127.0.0.1";
+ tcp_device[kDeviceApplications][0][kApplicationPort] = "1";
+ Json::Value bluetooth_device;
+ bluetooth_device[kDeviceName] = "unique_bluetooth_device_name";
+ bluetooth_device[kDeviceAddress] = "AB:CD:EF:GH:IJ:KL";
+ bluetooth_device[kDeviceApplications][0][kApplicationRfcomm] =
+ kApplicationRfcommValue;
+ custom_dictionary[kTransportManager][kTcpAdapter][kDevices][0] = tcp_device;
+ custom_dictionary[kTransportManager][kBluetoothAdapter][kDevices][0] =
+ bluetooth_device;
- transport_manager.Init(last_state);
+ 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(mock_last_state);
transport_manager.Stop();
}