diff options
author | pvysh9 <pvyshnevska@luxoft.com> | 2015-07-09 18:37:32 +0700 |
---|---|---|
committer | pvysh9 <pvyshnevska@luxoft.com> | 2015-07-09 18:37:32 +0700 |
commit | f5fab047ffdd6929ea7d4339ddf2f14fc9871049 (patch) | |
tree | 93e9d516aeb734cf22ac29c95449f3e18867330b | |
parent | 28a67285992db886e69704e4a2d4c38520614df2 (diff) | |
parent | f087c26ee8efbffbc44ee637545dc59166c1ee2a (diff) | |
download | sdl_core-f5fab047ffdd6929ea7d4339ddf2f14fc9871049.tar.gz |
Merge pull request #72 from CustomSDL/bugfixRSDL_B3.0.3
Bugfix
-rw-r--r-- | src/components/can_cooperation/test/include/mock_service_some_impl.h | 84 | ||||
-rw-r--r-- | src/components/can_cooperation/test/src/can_module_test.cc | 92 |
2 files changed, 50 insertions, 126 deletions
diff --git a/src/components/can_cooperation/test/include/mock_service_some_impl.h b/src/components/can_cooperation/test/include/mock_service_some_impl.h deleted file mode 100644 index dacc70757c..0000000000 --- a/src/components/can_cooperation/test/include/mock_service_some_impl.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2015, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef TEST_COMPONENTS_CAN_COOPERATION_INCLUDE_MOCK_SERVICE_SOME_IMPL_H_ -#define TEST_COMPONENTS_CAN_COOPERATION_INCLUDE_MOCK_SERVICE_SOME_IMPL_H_ - -#include "gmock/gmock.h" -#include "application_manager/service.h" - -namespace application_manager { - -class MockServiceSomeImpl : public Service { - public: - MOCK_METHOD1(CheckPolicyPermissions, - mobile_apis::Result::eType(MessagePtr msg)); - ApplicationSharedPtr GetApplication(ApplicationId app_id) { return app_; } - void set_app(ApplicationSharedPtr app) { app_ = app; } - MOCK_METHOD1(SendMessageToHMI, - void(const MessagePtr& message)); - MOCK_METHOD1(SendMessageToMobile, - void(const MessagePtr& message)); - MOCK_METHOD0(GetNextCorrelationID, - uint32_t()); - std::vector<ApplicationSharedPtr> GetApplications(AppExtensionUID uid) { - std::vector<ApplicationSharedPtr> v; v.push_back(app_); return v;} - MOCK_METHOD1(SubscribeToHMINotification, - void(const std::string& hmi_notification)); - MOCK_METHOD2(ChangeNotifyHMILevel, void(ApplicationSharedPtr app, - mobile_apis::HMILevel::eType level)); - MOCK_METHOD2(NotifyHMIAboutHMILevel, void(ApplicationSharedPtr app, - mobile_apis::HMILevel::eType level)); - MOCK_METHOD5(CheckAccess, - TypeAccess(const ApplicationId& app_id, - const SeatLocation& zone, - const std::string& module, - const std::string& rpc, - const std::vector<std::string>& params)); - MOCK_METHOD3(SetAccess, - void(const ApplicationId& app_id, - const std::string& module, - bool allowed)); - MOCK_METHOD1(ResetAccess, void(const ApplicationId& app_id)); - MOCK_METHOD1(ResetAccessByModule, void(const std::string& module)); - MOCK_METHOD1(SetPrimaryDevice, void(const uint32_t dev_id)); - MOCK_METHOD0(ResetPrimaryDevice, void()); - MOCK_CONST_METHOD0(PrimaryDevice, uint32_t()); - MOCK_METHOD1(SetRemoteControl, void(bool enabled)); - MOCK_CONST_METHOD0(IsRemoteControlAllowed, bool()); -private: - ApplicationSharedPtr app_; -}; - -} - // namespace application_manager - -#endif // TEST_COMPONENTS_CAN_COOPERATION_INCLUDE_MOCK_SERVICE_SOME_IMPL_H_ diff --git a/src/components/can_cooperation/test/src/can_module_test.cc b/src/components/can_cooperation/test/src/can_module_test.cc index d42259f13f..eb0f5ab3c4 100644 --- a/src/components/can_cooperation/test/src/can_module_test.cc +++ b/src/components/can_cooperation/test/src/can_module_test.cc @@ -34,12 +34,12 @@ #include "can_cooperation/can_module.h" #include "can_cooperation/can_app_extension.h" #include "can_cooperation/can_module_constants.h" +#include "can_cooperation/message_helper.h" #include "functional_module/module_observer.h" #include "mock_application.h" #include "mock_service.h" #include "mock_can_connection.h" #include "mock_application_some_impl.h" -#include "mock_service_some_impl.h" namespace smart_objects = NsSmartDeviceLink::NsSmartObjects; @@ -51,7 +51,6 @@ using application_manager::ServicePtr; using application_manager::MockService; using application_manager::MockApplication; using application_manager::MockApplicationSomeImpl; -using application_manager::MockServiceSomeImpl; using ::testing::_; using ::testing::NiceMock; @@ -119,12 +118,13 @@ TEST_F(CanModuleTest, ProcessMessageEmptyAppsList) { std::string json = "{\"jsonrpc\": \"2.0\", \"method\": \"RC.OnInteriorVehicleData\",\ \"params\": {\"moduleData\": {\"moduleType\": \"CLIMATE\",\ \"moduleZone\": {\"col\": 0,\"row\": 0,\"level\": 0,\"colspan\": 2,\ - \"rowspan\": 2, \"levelspan\": 1} }}}"; + \"rowspan\": 2, \"levelspan\": 1}, \"climateControlData\": {\"fanSpeed\": 100} }}}"; message->set_json_message(json); std::vector<application_manager::ApplicationSharedPtr> apps; - EXPECT_CALL(*mock_service, GetApplications(module->GetModuleID()) - ).Times(1).WillOnce(Return(apps)); + + ON_CALL(*mock_service, GetApplications(module->GetModuleID()) + ).WillByDefault(Return(apps)); EXPECT_CALL(*mock_service, SendMessageToMobile(_)).Times(0); EXPECT_EQ(ProcessResult::PROCESSED, module->ProcessMessage(message)); } @@ -140,23 +140,36 @@ TEST_F(CanModuleTest, ProcessMessagePass) { std::string json = "{\"jsonrpc\": \"2.0\", \"method\": \"RC.OnInteriorVehicleData\",\ \"params\": {\"moduleData\": {\"moduleType\": \"CLIMATE\",\ \"moduleZone\": {\"col\": 0,\"row\": 0,\"level\": 0,\"colspan\": 2,\ - \"rowspan\": 2, \"levelspan\": 1} }}}"; + \"rowspan\": 2, \"levelspan\": 1}, \"climateControlData\": {\"fanSpeed\": 100} }}}"; message->set_json_message(json); + Json::Value json_value = MessageHelper::StringToValue(json); + Json::Value moduleDescription; + + moduleDescription[message_params::kModuleType] = + json_value[json_keys::kParams][message_params::kModuleData] + [message_params::kModuleType]; + + moduleDescription[message_params::kModuleZone] = + json_value[json_keys::kParams][message_params::kModuleData] + [message_params::kModuleZone]; std::vector<application_manager::ApplicationSharedPtr> apps; - MockApplication* app = new MockApplication(); + NiceMock<MockApplication>* app = new NiceMock<MockApplication>(); application_manager::ApplicationSharedPtr app_ptr(app); apps.push_back(app_ptr); application_manager::AppExtensionUID uid = module->GetModuleID(); CANAppExtension* can_ext = new CANAppExtension(uid); can_ext->GiveControl(true); + + can_ext->SubscribeToInteriorVehicleData(moduleDescription); application_manager::AppExtensionPtr ext(can_ext); - EXPECT_CALL(*app, app_id()).Times(2).WillRepeatedly(Return(1)); - EXPECT_CALL(*mock_service, GetApplications(module->GetModuleID()) - ).Times(1).WillOnce(Return(apps)); + ON_CALL(*app, app_id()).WillByDefault(Return(1)); + ON_CALL(*mock_service, GetApplications(module->GetModuleID()) + ).WillByDefault(Return(apps)); EXPECT_CALL(*mock_service, GetApplication(_)).Times(1) .WillOnce(Return(app_ptr)); + EXPECT_CALL(*app, QueryInterface(_)).WillOnce(Return(ext)); EXPECT_CALL(*mock_service, CheckPolicyPermissions(_)).Times(1) .WillOnce(Return(mobile_apis::Result::eType::SUCCESS)); EXPECT_CALL(*mock_service, CheckAccess(1, _, _, "OnInteriorVehicleData", _)).Times(1) @@ -262,16 +275,13 @@ TEST_F(CanModuleTest, SetDriverDeviceOnRegister) { obj[0] = 10; app_ptr->set_app_types(obj); app_ptr->set_device(1); + std::vector<application_manager::ApplicationSharedPtr> apps; + apps.push_back(app_ptr); - NiceMock<MockServiceSomeImpl>* mock_service2 = new NiceMock<MockServiceSomeImpl>(); - mock_service2->set_app(app_ptr); - ServicePtr mock_service2_ptr(mock_service2); - module->set_service(mock_service2_ptr); - - ON_CALL(*mock_service2, PrimaryDevice()).WillByDefault(Return(1)); - - EXPECT_CALL(*mock_service2, NotifyHMIAboutHMILevel(app_ptr, _)).Times(1); - EXPECT_CALL(*mock_service2, PrimaryDevice()).Times(1); + ON_CALL(*mock_service, GetApplications(module->GetModuleID()) + ).WillByDefault(Return(apps)); + EXPECT_CALL(*mock_service, NotifyHMIAboutHMILevel(app_ptr, _)).Times(1); + EXPECT_CALL(*mock_service, PrimaryDevice()).Times(1).WillOnce(Return(1)); ASSERT_TRUE(module->IsAppForPlugin(app_ptr)); ASSERT_TRUE(application_manager::AppExtensionPtr::static_pointer_cast<CANAppExtension>( app_ptr->QueryInterface(module->GetModuleID()))->is_on_driver_device()); @@ -286,15 +296,13 @@ TEST_F(CanModuleTest, SetDriverDeviceOnRegisterFail) { app_ptr->set_app_types(obj); app_ptr->set_device(1); - NiceMock<MockServiceSomeImpl>* mock_service2 = new NiceMock<MockServiceSomeImpl>(); - mock_service2->set_app(app_ptr); - ServicePtr mock_service2_ptr(mock_service2); - module->set_service(mock_service2_ptr); - - ON_CALL(*mock_service2, PrimaryDevice()).WillByDefault(Return(0)); + std::vector<application_manager::ApplicationSharedPtr> apps; + apps.push_back(app_ptr); + ON_CALL(*mock_service, GetApplications(module->GetModuleID()) + ).WillByDefault(Return(apps)); - EXPECT_CALL(*mock_service2, NotifyHMIAboutHMILevel(app_ptr, _)).Times(1); - EXPECT_CALL(*mock_service2, PrimaryDevice()).Times(1); + EXPECT_CALL(*mock_service, NotifyHMIAboutHMILevel(app_ptr, _)).Times(1); + EXPECT_CALL(*mock_service, PrimaryDevice()).Times(1).WillOnce(Return(0)); ASSERT_TRUE(module->IsAppForPlugin(app_ptr)); ASSERT_FALSE(application_manager::AppExtensionPtr::static_pointer_cast<CANAppExtension>( app_ptr->QueryInterface(module->GetModuleID()))->is_on_driver_device()); @@ -327,12 +335,12 @@ TEST_F(CanModuleTest, ChangeDriverDevice) { CANAppExtension* ext = new CANAppExtension(module->GetModuleID()); app_ptr->AddExtension(ext); - NiceMock<MockServiceSomeImpl>* mock_service2 = new NiceMock<MockServiceSomeImpl>(); - mock_service2->set_app(app_ptr); - ServicePtr mock_service2_ptr(mock_service2); - module->set_service(mock_service2_ptr); + std::vector<application_manager::ApplicationSharedPtr> apps; + apps.push_back(app_ptr); + ON_CALL(*mock_service, GetApplications(module->GetModuleID()) + ).WillByDefault(Return(apps)); - EXPECT_CALL(*mock_service2, SetPrimaryDevice(1)).Times(1); + EXPECT_CALL(*mock_service, SetPrimaryDevice(1)).Times(1); CanModuleTest::HandleMessage(message); ASSERT_TRUE(ext->is_on_driver_device()); app_ptr->RemoveExtension(module->GetModuleID()); @@ -364,12 +372,12 @@ TEST_F(CanModuleTest, ChangeDriverDeviceOnOther) { CANAppExtension* ext = new CANAppExtension(module->GetModuleID()); app_ptr->AddExtension(ext); - NiceMock<MockServiceSomeImpl>* mock_service2 = new NiceMock<MockServiceSomeImpl>(); - mock_service2->set_app(app_ptr); - ServicePtr mock_service2_ptr(mock_service2); - module->set_service(mock_service2_ptr); + std::vector<application_manager::ApplicationSharedPtr> apps; + apps.push_back(app_ptr); + ON_CALL(*mock_service, GetApplications(module->GetModuleID()) + ).WillByDefault(Return(apps)); - EXPECT_CALL(*mock_service2, SetPrimaryDevice(1)).Times(1); + EXPECT_CALL(*mock_service, SetPrimaryDevice(1)).Times(1); CanModuleTest::HandleMessage(message); ASSERT_FALSE(ext->is_on_driver_device()); app_ptr->RemoveExtension(module->GetModuleID()); @@ -395,10 +403,10 @@ TEST_F(CanModuleTest, DeactivateApp) { app_ptr->AddExtension(ext); ext->set_is_on_driver_device(true); - NiceMock<MockServiceSomeImpl>* mock_service2 = new NiceMock<MockServiceSomeImpl>(); - mock_service2->set_app(app_ptr); - ServicePtr mock_service2_ptr(mock_service2); - module->set_service(mock_service2_ptr); + std::vector<application_manager::ApplicationSharedPtr> apps; + apps.push_back(app_ptr); + ON_CALL(*mock_service, GetApplications(module->GetModuleID()) + ).WillByDefault(Return(apps)); for (size_t i = 0; i < 6; ++ i) { Json::Value value(Json::ValueType::objectValue); @@ -412,7 +420,7 @@ TEST_F(CanModuleTest, DeactivateApp) { app_ptr->set_hmi_level(mobile_apis::HMILevel::eType::HMI_FULL); - EXPECT_CALL(*mock_service2, ChangeNotifyHMILevel(_, mobile_apis::HMILevel::eType::HMI_LIMITED)).Times(1); + EXPECT_CALL(*mock_service, ChangeNotifyHMILevel(_, mobile_apis::HMILevel::eType::HMI_LIMITED)).Times(1); CanModuleTest::HandleMessage(message); } app_ptr->RemoveExtension(module->GetModuleID()); |