diff options
Diffstat (limited to 'SDL_Core/test/components/application_manager/rpc')
27 files changed, 3539 insertions, 0 deletions
diff --git a/SDL_Core/test/components/application_manager/rpc/CMakeLists.txt b/SDL_Core/test/components/application_manager/rpc/CMakeLists.txt new file mode 100644 index 000000000..24a060489 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/CMakeLists.txt @@ -0,0 +1,104 @@ +find_package(Gstreamer-1.0 REQUIRED) +find_package(Glib-2.0 REQUIRED) +#find_package(LibXML2 REQUIRED) + +# required to find 'glibconfig.h' +find_package(PkgConfig) +pkg_check_modules(GLIB2 REQUIRED glib-2.0) +add_definitions(${GLIB2_CFLAGS}) + +include_directories ( + ./include + ../../../../src/thirdPartyLibs/gmock-1.6.0/include + ../../../../src/thirdPartyLibs/gmock-1.6.0/gtest/include + ../../../../src/thirdPartyLibs/MessageBroker/include + ../../../../src/thirdPartyLibs/jsoncpp/include + ../../../../src/components/application_manager/include + ../../../../src/components/protocol_handler/include + ../../../../src/components/hmi_message_handler/include + #../../../../src/components/mobile_message_handler/include/ + ../../../../src/components/transport_manager/include + ../../../../src/components/connection_handler/include + ../../../../src/components/utils/include + ../../../../src/components/smart_objects/include + ../../../../src/components/request_watchdog/include + ../../../../src/components/media_manager/include + ../../../../src/components/formatters/include + ../../../../src/components/config_profile/include + ../../../../src/components/policies/include + #../../../../test/components/application_manager/rpc/include + ${GSTREAMER_gst_INCLUDE_DIR} + ${GLIB_glib_2_INCLUDE_DIR} + ${CMAKE_SOURCE_DIR}/src/components/ + ${CMAKE_BINARY_DIR}/src/components/ + #${LibXML2_INCLUDE_DIR} + ${CMAKE_SOURCE_DIR}/src/components/dbus/include +) + +set(LIBRARIES + gtest + gtest_main + gmock + gmock_main + ApplicationManager + HMI_API + MOBILE_API + SmartObjects + formatters + ProtocolHandler + connectionHandler + TransportManager + HMIMessageHandler + MessageBroker + MessageBrokerClient + MessageBrokerServer + Utils + encryption + jsoncpp + bluetooth + pthread + rt + avahi-client + avahi-common + ConfigProfile + #MobileMessageHandler + RequestWatchdog + MediaManager + Libusb-1.0.16 + #${LibXML2_LIBRARIES} -lxml2 +) + + +#file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +#file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/XmlTests/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/XmlTests/) +#file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/hmi_link DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + + + +#add_library("test_App_Manager" "./src/app_manager_test.cc") + +#add_library("test_Admin_App_Test" "./src/AdminAppTest.cc") +#add_library("test_G_Mock_Class_Container" "./src/GMockClassContainer.cc") +#add_library("test_G_Test_Ford" "./src/GTestFord.cc") +#add_library("test_Init_HMI" "./src/InitHMI.cc") +#add_library("test_HMI_Message_Handler_Tester" "./src/HMIMessageHandlerTester.cc") +#add_library("test_Mobile_Message_Handler_Tester" "./src/MobileMessageHandlerTester.cc") +#add_library("test_Check_Mobile_Message_Handler" "./src/CkeckMobileMessageHandler.cc") +#add_library("test_XmlParser" "./src/xmlParser.cc") + +add_library("test_App_Manager" + "./src/AdminAppTest.cc" + "./src/GMockClassContainer.cc" + "./src/GTestFord.cc" + "./src/ICheckClass.cc" + "./src/InitHMI.cc" + "./src/HMIMessageHandlerTester.cc" + #"./src/MobileMessageHandlerTester.cc" + #"./src/CkeckMobileMessageHandler.cc" + #"./src/testMobile.cc" + #"./src/xmlParser.cc" + #"./src/too_many_request_test_case.cc" + #"./src/too_many_pending_requests_test_case.cc" + "./src/addTest.cc" + "./src/initStartData.cc" + "./src/testHMI.cc") diff --git a/SDL_Core/test/components/application_manager/rpc/XmlTests/New.xml b/SDL_Core/test/components/application_manager/rpc/XmlTests/New.xml new file mode 100755 index 000000000..6547a5fec --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/XmlTests/New.xml @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="utf-8"?> +<file> + <type type="unit"/> + + <test testName="RegisterAppInterface_WithConditionalParams" pause="2000"> + + <params> + <Integer function_id = "1" /> + <Integer correlation_id = "1" /> + <Integer message_type = "0" /> + <Integer protocol_type = "0" /> + <Integer protocol_version = "2" /> + </params> + <message_params> + <syncMsgVersion> + <Integer majorVersion="2" /> + <Integer minorVersion="2" /> + </syncMsgVersion> + <String appName="SyncProxyTester" /> + <Vector name="ttsName"> + <TTSChunk> + <String text="SyncProxyTester"/> + <String type="TEXT"/> + </TTSChunk> + </Vector> + <String ngnMediaScreenAppName="SPT" /> + <Vector name="vrSynonyms"> + <String add="VR SyncProxyTester"/> + </Vector> + <Boolean isMediaApplication="true" /> + <String languageDesired="EN-US" /> + <String hmiDisplayLanguageDesired="EN-US" /> + <Vector name="appHMIType"> + <String add="DEFAULT"/> + </Vector> + <String appID="123456" /> + </message_params> + + <response> + <params> + <Integer function_id = "1" /> + <Integer correlation_id = "1" /> + <Integer message_type = "0" /> + <Integer protocol_type = "0" /> + <Integer protocol_version = "2" /> + </params> + <message_params> + <Boolean success = "true" /> + <String resultCode = "SUCCESS" /> + </message_params> + </response> + </test> +<!-- + <test testName="AddCommand_withParams" pause="2000"> + + <params> + <Integer function_id = "5" /> + <Integer correlation_id = "1" /> + <Integer message_type = "0" /> + <Integer protocol_type = "0" /> + <Integer protocol_version = "2" /> + </params> + <message_params> + <Integer cmdId="1234" /> + + <menuParams> + <Integer parentID = "0" /> + <String menuName = "Example" /> + </menuParams> + + <String appID="123456" /> + </message_params> + + <response> + <params> + <Integer function_id = "5" /> + <Integer correlation_id = "1" /> + <Integer message_type = "0" /> + <Integer protocol_type = "0" /> + <Integer protocol_version = "2" /> + </params> + <message_params> + <Boolean success = "true" /> + <String resultCode = "SUCCESS" /> + </message_params> + </response> + + </test> +--> +</file>
\ No newline at end of file diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/AdminAppTest.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/AdminAppTest.h new file mode 100644 index 000000000..707c6634c --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/AdminAppTest.h @@ -0,0 +1,150 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_ADMIN_APP_TEST_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_ADMIN_APP_TEST_H_ + +//Class replace TEST and Call's Gtest/Gmock of Google +#include "rpc/GTestFord.h" + +//Container singltone, have all class what called in GTestFord +#include "rpc/GMockClassContainer.h" + +//Interface class what called in GTestFord +#include "rpc/addTest.h" +#include "rpc/testHMI.h" +//#include "rpc/xmlParser.h" +#include "rpc/ICheckClass.h" +#include "rpc/initStartData.h" +#include "rpc/HMIMessageHandlerTester.h" + +#include "transport_manager/error.h" +#include "transport_manager/transport_adapter/transport_adapter_event.h" +#include "transport_manager/transport_adapter/transport_adapter_listener_impl.h" + +#include "utils/threads/thread_delegate.h" + + +using namespace application_manager; +using namespace std; +using namespace NsSmartDeviceLink::NsJSONHandler::strings; +using namespace NsSmartDeviceLink::NsSmartObjects; +//using namespace test::app_manager_test::xml_parser; +//namespace formatters = NsSmartDeviceLink::NsJSONHandler::Formatters; + +namespace test { + namespace app_manager_test{ + + /** + * @brief Main class for test + */ + class AdminAppTest : public threads::ThreadDelegate + { + public: + + //metods + + /** + * @brief Constructor + */ + AdminAppTest(); + + /** + * @brief Destructor + */ + ~AdminAppTest(); + + /** + * @brief Run method what creat XMLParser, read XML file + * creat necessary to us ICheckClass, add him to + * GMockClassContainer + * + * @param + * + * @return void + */ + void run(); + + /** + * @brief Set path to XML file + * + * @param string patch to XML file + * + * @return void + */ + inline void SetXmlPathToDir(const std::string& path); + + /** + * @brief Thread procedure. + */ + virtual void threadMain(); + + protected: + + private: + + //metods + + /** + * @brief Copy constructor + */ + AdminAppTest(const AdminAppTest &); + + + /** + * @brief Operator assignment + */ + AdminAppTest *operator=(const AdminAppTest &); + + //members + + /** + * @brief path to XML file + */ + //std::string xmlPathToDir; + + }; + + + inline void AdminAppTest::SetXmlPathToDir(const std::string& path) + { + //xmlPathToDir.clear(); + //xmlPathToDir.append(path); + } + } +} + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_ADMIN_APP_TEST_H_ + + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/CheckHMIMessageHandler.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/CheckHMIMessageHandler.h new file mode 100755 index 000000000..44313ac67 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/CheckHMIMessageHandler.h @@ -0,0 +1,125 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_CHECK_HMI_MESSAGE_HANDLER_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_CHECK_HMI_MESSAGE_HANDLER_H_ + +#include "rpc/ICheckClass.h" + +#include "hmi_message_handler/hmi_message_handler.h" +#include "protocol_handler/raw_message.h" + +#include "utils/shared_ptr.h" +#include "application_manager/application_manager_impl.h" + +namespace test{ + namespace HMI_Message_Handler_Tester{ + + typedef utils::SharedPtr<application_manager::Message> SP_AM_M; + /** + * @brief Test class for test request/response Mobile + */ + class CheckHMIMessageHandler: public ICheckClass + { + public: + /** + * @brief In argument name name_test_case,next name_test and got_response_ + * + * @param first - name test case, second - name test, third - SharedPrt message + * + * @return + */ + CheckHMIMessageHandler(const std::string& inUnitTestName, const std::string& inTestName, SP_AM_M &); + + /** + * @brief Destructor + */ + ~CheckHMIMessageHandler(); + + public: + /** + * @brief Calls Gtest func and check got response and expected response + * + * @param + * + * @return bool + */ + virtual bool check(); + + /** + * @brief set got_response_ + * + * @param first ref MobileMessage + * + * @return void + */ + void addMessage(const MobileMessage &); + + protected: + + private: + /** + * @brief Copy constructor + * + * @param first ref CheckMobileMessageHandler + */ + CheckHMIMessageHandler(const CheckMobileMessageHandler &); + + private: + /** + * @brief Operator assignment + * + * @param first ref CheckMobileMessageHandler + * + * @return point to CheckHMIMessageHandler + */ + CheckHMIMessageHandler *operator=(const CheckMobileMessageHandler &); + + private: + /** + * @brief Got responce from app. manager + */ + utils::SharedPtr<application_manager::Message> got_response_; + /** + * @brief Expected response from XML + */ + utils::SharedPtr<application_manager::Message> expected_response_; + }; + + }//namespace HMI_Message_Handler_Tester +}//namespace test + + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_CHECK_HMI_MESSAGE_HANDLER_H_ + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/GMockClassContainer.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/GMockClassContainer.h new file mode 100644 index 000000000..4c011d44c --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/GMockClassContainer.h @@ -0,0 +1,132 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_G_MOCK_CLASS_CONTAINER_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_G_MOCK_CLASS_CONTAINER_H_ + +//Class replace TEST and Call's Gtest/Gmock of Google +#include "rpc/ICheckClass.h" +//Gtest +#include "rpc/GTestFord.h" + +#include <vector> + +/** +* @briefContainer singltone, have all class what called in GTestFord +*/ +class GMockClassContainer +{ +public: + + /** + * @brief Return pointer to GMockClassContainer + * + * @param + * + * @return point to GMockClassContainer + */ + static GMockClassContainer *instance(); + + /** + * @brief Add new ICheckClass for TEST + * + * @param first param - class which called Gtest + * + * @return void + */ + void addTest(ICheckClass *); + +protected: + +private: + /** + * @brief Do GTestFord friend + */ + friend class GTestFord; + // metods + + /** + * @brief Constructor + * + * @param + * + * @return + */ + GMockClassContainer(); + + /** + * @brief Destructor + * + * @param + * + * @return + */ + ~GMockClassContainer(); + + /** + * @brief Copy constructor + * + * @param first - GMockClassContainer + * + * @return + */ + GMockClassContainer(const GMockClassContainer &); + + /** + * @brief Operator assignment + * + * @param first - GMockClassContainer + * + * @return + */ + GMockClassContainer *operator=(const GMockClassContainer &); + + /** + * @brief Get Test class. Need only for GTestFord + * + * @param number tets + * + * @return point to ICheckClass + */ + ICheckClass *getTest(int i); + + // members + /** + * @brief array Tests which launches Gtest/Gmock + */ + std::vector<ICheckClass *> mas_; +}; + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_G_MOCK_CLASS_CONTAINER_H_ + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/GTestFord.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/GTestFord.h new file mode 100644 index 000000000..865731e7d --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/GTestFord.h @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_G_TEST_FORD_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_G_TEST_FORD_H_ + + +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +#include "rpc/GMockClassContainer.h" + +/** +* @briefClass replace TEST and Call's Gtest/Gmock of Google +*/ +class GTestFord : public testing::Test +{ +public: + + //metods + + /** + * @brief Constructor + */ + GTestFord(); + + /** + * @brief Virtual Distructor + */ + virtual ~GTestFord(); + +protected: + +private: + + //metods + + /** + * @brief main function where the testing is executed + * + * @param + * + * @return void + */ + virtual void TestBody(); + + //members + + /** + * @brief Change pointer element to GMockClassContainer mas_ + */ + static int index; + +}; + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_G_TEST_FORD_H_ + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/HMIMessageHandlerTester.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/HMIMessageHandlerTester.h new file mode 100755 index 000000000..34981dd78 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/HMIMessageHandlerTester.h @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_HMI_MESSAGE_HANDLER_TEST_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_HMI_MESSAGE_HANDLER_TEST_H_ + +#include "utils/macro.h" +#include "hmi_message_handler/hmi_message_handler.h" + + +using namespace hmi_message_handler; + +namespace test{ + namespace HMI_Message_Handler_Tester{ + + /** + * @brief Redefinition HMIMessageHandler for test + */ + class HMIMessageHandlerTester: public HMIMessageHandler + { + public: + + /** + * @brief Constructor + */ + HMIMessageHandlerTester(); + + /** + * @brief Destructor + */ + ~HMIMessageHandlerTester(); + + public: + virtual void SendMessageToHMI(utils::SharedPtr<application_manager::Message> message); + virtual void OnMessageReceived(utils::SharedPtr<application_manager::Message> message); + virtual void OnErrorSending(utils::SharedPtr<application_manager::Message> message); + virtual void AddHMIMessageAdapter(HMIMessageAdapter* adapter); + virtual void RemoveHMIMessageAdapter(HMIMessageAdapter* adapter); + + protected: + + private: + + /** + * @brief Copy constructor + * + * @param first - ref HMIMessageHandlerTester + */ + HMIMessageHandlerTester(const HMIMessageHandlerTester &); + + private: + + /** + * @brief Operator assignment + * + * @param first - ref HMIMessageHandlerTester + * + * @return point to HMIMessageHandlerTester + */ + HMIMessageHandlerTester *operator=(const HMIMessageHandlerTester &); + + }; + + }// namespace HMI_Message_Handler_Tester +}//namespace test + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_HMI_MESSAGE_HANDLER_TEST_H_ + + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/ICheckClass.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/ICheckClass.h new file mode 100644 index 000000000..92ea55923 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/ICheckClass.h @@ -0,0 +1,152 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_I_CHECK_CLASS_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_I_CHECK_CLASS_H_ + +#include <string> + + +/** +* @brief Interface class what called in GTestFord +*/ +class ICheckClass +{ +public: + + /** + * @brief Constructor + * + * @param first - test case name + * @param second - test name + */ + ICheckClass(const std::string& inUnitTestName,const std::string& inTestName); + + /** + * @brief Calls Gtest func + * + * @param + * + * @return bool + */ + virtual bool check() = 0; + + /** + * @brief Virtual destructor + */ + virtual ~ICheckClass(); + +public: + + /** + * @brief Set unitTestName + * + * @param first - test case name + * + * @return void + */ + inline void SetUnitTestName(const std::string& unittestname); + + /** + * @brief Get test case name + * + * @param + * + * @return const std::string & + */ + inline const std::string& GetUnitTestName() const; + + /** + * @brief Set test name + * + * @param first - test name + * + * @return void + */ + inline void SetTestName(const std::string& testname); + + /** + * @brief Get test name + * + * @param + * + * @return const std::string & + */ + inline const std::string& GetTestName() const; + +protected: + + /** + * @brief Test case name + */ + std::string unitTestName_; + + /** + * @brief Test name + */ + std::string testName_; + +private: + +}; + + +void ICheckClass::SetUnitTestName(const std::string& unittestname) +{ + unitTestName_.clear(); + unitTestName_.append(unittestname); +} + + +const std::string& ICheckClass::GetUnitTestName() const +{ + return unitTestName_; +} + + +void ICheckClass::SetTestName(const std::string& testname) +{ + testName_.clear(); + testName_.append(testname); +} + + +const std::string& ICheckClass::GetTestName() const +{ + return testName_; +} + + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_I_CHECK_CLASS_H_ + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/InitHMI.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/InitHMI.h new file mode 100644 index 000000000..5fb1e644b --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/InitHMI.h @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_INIT_HMI_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_INIT_HMI_H_ + + +#include <string.h> +#include <dirent.h> +#include <stdio.h> + +#include <sys/stat.h> +#include <signal.h> +#include <fcntl.h> +#include <unistd.h> +#include <cstdio> +#include <cstdlib> +#include <vector> +#include <string> +#include <iostream> +#include <fstream> + + + +#include "utils/macro.h" +#include "utils/logger.h" +#include "utils/signals.h" +#include "config_profile/profile.h" +#include "networking.h" +#include "application_manager/message_helper.h" + + +using namespace NsSmartDeviceLink::NsSmartObjects; + +namespace InitializeHMI{ + /** + * @brief Patch to browser + */ + const char kBrowser[] = "/usr/bin/chromium-browser"; + /** + * @brief Browser name + */ + const char kBrowserName[] = "chromium-browser"; + /** + * @brief Browser params + */ + const char kBrowserParams[] = "--auth-schemes=basic,digest,ntlm"; + /** + * @brief Local host address + */ + const char kLocalHostAddress[] = "127.0.0.1"; + + /** + * @brief Initialize HTML based HMI. + * + * @return true if success otherwise false. + */ + bool InitHmi(); + + } + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_INIT_HMI_H_ + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/addTest.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/addTest.h new file mode 100644 index 000000000..a043bdc2b --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/addTest.h @@ -0,0 +1,103 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_ADDTEST_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_ADDTEST_H_ + +#include "rpc/ICheckClass.h" +#include "rpc/GMockClassContainer.h" +#include "rpc/noParamsFord.h" +#include "rpc/unaryFord.h" +#include "rpc/binaryFord.h" + + +/** +* @brief Add test to Gtest +* +* @param first - test case name, second - test name, third - functor, fourth - expected return value functor +* +* @return void +*/ +template<typename NoParamsFunc, typename ReturnValues> +void addTest(const std::string &testCaseName, const std::string &testName, NoParamsFunc func, ReturnValues ret) +{ + ICheckClass *test = new noParamsFuncFord<NoParamsFunc, ReturnValues>(testCaseName, testName, func, ret); + GMockClassContainer *container = GMockClassContainer::instance(); + + container->addTest(test); +} + +/** +* @brief Add test to Gtest +* +* @param first - test case name, second - test name, third - Unfunctor, fourth - first argument Unfanc, +* fifth - expected return value Unfunctor +* +* @return void +*/ +template <typename UnFunc, typename FirstArgument, typename ReturnValues> +void addTest(const std::string &testCaseName, const std::string testName, + UnFunc func, FirstArgument first, ReturnValues ret) +{ + ICheckClass *test = new unaryFuncFord<UnFunc,FirstArgument,ReturnValues>(testCaseName, testName, func, first, ret); + GMockClassContainer *container = GMockClassContainer::instance(); + + container->addTest(test); +} + + +/** +* @brief Add test to Gtest +* +* @param first - test case name, second - test name, third - Binfunctor, fourth - first argument Binfanc, +* fifth - second argument Binfanc, the 6th - expected return value Binfanc +* +* @return void +*/ +template <typename BinFunc, typename FirstArgument, typename SecondArgument, typename ReturnValues> +void addTest(const std::string &testCaseName, const std::string testName, + BinFunc func, FirstArgument first, SecondArgument second, ReturnValues ret) +{ + ICheckClass *test = new binaryFuncFord<BinFunc,FirstArgument,SecondArgument,ReturnValues>(testCaseName, testName, func, first, second, ret); + GMockClassContainer *container = GMockClassContainer::instance(); + + container->addTest(test); +} + + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_ADDTEST_H_ + + + + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/binaryFord.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/binaryFord.h new file mode 100644 index 000000000..cf6d848b5 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/binaryFord.h @@ -0,0 +1,160 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_BINARY_PREDICAT_FORD_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_BINARY_PREDICAT_FORD_H_ + +#include "rpc/ICheckClass.h" +/** + * @brief Need onli AddTest + */ +template <typename BinFunc, typename FirstArgument, typename SecondArgument, typename ReturnValues> +class binaryFuncFord: public ICheckClass +{ +public: + //methods + /** + * @brief Constructor + * + * @param first - test case name, second - test name, third - Binfunctor, fourth - first argument Binfanc, + * fifth - second argument Binfanc, the 6th - expected return value Binfanc + * + */ + binaryFuncFord(const std::string &testCaseName, const std::string &testName, + BinFunc func, FirstArgument first, SecondArgument second, ReturnValues ret); + + /** + * @brief Destructor + */ + ~binaryFuncFord(); + + /** + * @brief Calls Gtest func + * + * @param + * + * @return bool + */ + virtual bool check(); + +protected: + +private: + //methods + /** + * @brief copy constructor + * + * @param first - const ref binaryFuncFord + */ + binaryFuncFord(const binaryFuncFord &); + + /** + * @brief Operator assignment + * + * @param first - const ref binaryFuncFord + * + * @return point to binaryFuncFord + */ + binaryFuncFord &operator=(const binaryFuncFord &); + + //members + /** + * @brief BinFunc + */ + BinFunc func_; + + /** + * @brief FirstArgument + */ + FirstArgument first_; + + /** + * @brief SecondArgument + */ + SecondArgument second_; + + /** + * @brief ReturnValues + */ + ReturnValues ret_; +}; + + +template <typename BinFunc, typename FirstArgument, typename SecondArgument, typename ReturnValues> +binaryFuncFord<BinFunc,FirstArgument,SecondArgument,ReturnValues>::binaryFuncFord(const std::string &testCaseName, const std::string &testName, BinFunc func, FirstArgument first, SecondArgument second, ReturnValues ret) + :ICheckClass(testCaseName, testName) + ,func_(func) + ,first_(first) + ,second_(second) + ,ret_(ret) + +{ +} + + +template <typename BinFunc, typename FirstArgument, typename SecondArgument, typename ReturnValues> +binaryFuncFord<BinFunc,FirstArgument,SecondArgument,ReturnValues>::~binaryFuncFord() +{ +} + + +template <typename BinFunc, typename FirstArgument, typename SecondArgument, typename ReturnValues> +bool binaryFuncFord<BinFunc,FirstArgument,SecondArgument,ReturnValues>::check() +{ + return (ret_ == func_(first_,second_)); +} + + +template <typename BinFunc, typename FirstArgument, typename SecondArgument, typename ReturnValues> +binaryFuncFord<BinFunc,FirstArgument,SecondArgument,ReturnValues>::binaryFuncFord(const binaryFuncFord &in) + :ICheckClass(in.unitTestName, in.testName) +{ +} + + +template <typename BinFunc, typename FirstArgument, typename SecondArgument, typename ReturnValues> +binaryFuncFord<BinFunc,FirstArgument,SecondArgument,ReturnValues> & + binaryFuncFord<BinFunc,FirstArgument,SecondArgument,ReturnValues>::operator=(const binaryFuncFord &) +{ + return *this; +} + + + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_BINARY_PREDICAT_FORD_H_ + + + + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/initStartData.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/initStartData.h new file mode 100644 index 000000000..d2b4a602c --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/initStartData.h @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_INIT_START_DATA_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_INIT_START_DATA_H_ + +#include "rpc/InitHMI.h" + +#include "transport_manager/error.h" +#include "transport_manager/transport_adapter/transport_adapter_event.h" +#include "transport_manager/transport_adapter/transport_adapter_listener_impl.h" +#include "transport_manager/transport_adapter/transport_adapter_controller.h" +#include "transport_manager/transport_adapter/transport_adapter_impl.h" + +#include "transport_manager/transport_adapter/server_connection_factory.h" +#include "transport_manager/transport_adapter/client_connection_listener.h" + + +#include "transport_manager/tcp/tcp_connection_factory.h" +#include "transport_manager/tcp/tcp_client_listener.h" +#include "transport_manager/tcp/dnssd_service_browser.h" +#include "transport_manager/tcp/tcp_transport_adapter.h" + +#include "utils/logger.h" + +/** +* @brief Initialize TransportManager, ProtocolHandlerImpl, ConnectionHandlerImpl +* ApplicationManagerImpl, MessageBrokerAdapter +*/ +void initStartData(); + + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_INIT_START_DATA_H_ + + + + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/noParamsFord.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/noParamsFord.h new file mode 100644 index 000000000..c09a32da8 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/noParamsFord.h @@ -0,0 +1,149 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_NO_PARAMS_PREDICAT_FORD_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_NO_PARAMS_PREDICAT_FORD_H_ + +#include "rpc/ICheckClass.h" + + +/** + * @brief Need onli AddTest + */ +template <typename Func, typename ReturnValues> +class noParamsFuncFord: public ICheckClass +{ +public: + //methods + + /** + * @brief Constructor + * + * @param first - test case name, second - test name, third - functor, fourth - expected return value functor + * + */ + noParamsFuncFord(const std::string &testCaseName, const std::string &testName, Func inFunc, ReturnValues ret); + + + /** + * @brief Destructor + */ + ~noParamsFuncFord(); + + /** + * @brief Calls Gtest func + * + * @param + * + * @return bool + */ + virtual bool check(); + +protected: + +private: + //methods + /** + * @brief copy constructor + * + * @param first - const ref noParamsFuncFord + */ + noParamsFuncFord(const noParamsFuncFord &); + + /** + * @brief Operator assignment + * + * @param first - const ref noParamsFuncFord + * + * @return point to noParamsFuncFord + */ + noParamsFuncFord &operator=(const noParamsFuncFord &); + + //members + /** + * @brief functor + */ + Func func_; + + /** + * @brief ReturnValues + */ + ReturnValues ret_; +}; + + +template <typename Func, typename ReturnValues> +noParamsFuncFord<Func,ReturnValues>::noParamsFuncFord(const std::string &testCaseName, const std::string &testName, Func inFunc, ReturnValues ret) + :ICheckClass(testCaseName, testName) + ,func_(inFunc) + ,ret_(ret) +{ +} + + +template <typename Func, typename ReturnValues> +noParamsFuncFord<Func,ReturnValues>::~noParamsFuncFord() +{ +} + + +template <typename Func, typename ReturnValues> +bool noParamsFuncFord<Func,ReturnValues>::check() +{ + return (ret_ == func_()); +} + + +template <typename Func, typename ReturnValues> +noParamsFuncFord<Func,ReturnValues>::noParamsFuncFord(const noParamsFuncFord &in) + :ICheckClass(in.unitTestName, in.testName) +{ +} + + +template <typename Func, typename ReturnValues> +noParamsFuncFord<Func,ReturnValues> &noParamsFuncFord<Func,ReturnValues>::operator=(const noParamsFuncFord &) +{ + return *this; +} + + + + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_NO_PARAMS_PREDICAT_FORD_H_ + + + + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/testHMI.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/testHMI.h new file mode 100644 index 000000000..ddab2dcad --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/testHMI.h @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_TEST_HMI_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_TEST_HMI_H_ + +#include "application_manager/application_manager_impl.h" +#include "connection_handler/connection_handler_impl.h" +#include "smart_objects/smart_object.h" + + +#include "rpc/HMIMessageHandlerTester.h" +//#include "rpc/MobileMessageHandlerTester.h" + + +using namespace NsSmartDeviceLink::NsSmartObjects; +using namespace NsSmartDeviceLink::NsJSONHandler::strings; +using namespace application_manager; + +namespace test{ + namespace app_manager_test{ + /** + * @brief testHMI. Init Device. Updated Device List to connaction_handler, + * establish connaction. Registr Application. Send HMIRequest to + * ManageMobileCommand with params AddCommand + */ + void testHMI(); + + }//namespace app_manager_test +}//namespace test + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_TEST_HMI_H_ + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/unaryFord.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/unaryFord.h new file mode 100644 index 000000000..671276955 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/unaryFord.h @@ -0,0 +1,157 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_UNARY_PREDICAT_FORD_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_UNARY_PREDICAT_FORD_H_ + +#include "rpc/ICheckClass.h" + + +/** + * @brief Need onli AddTest + */ +template <typename UnFunc, typename FirstArgument, typename ReturnValues> +class unaryFuncFord: public ICheckClass +{ +public: + //methods + /** + * @brief Constructor + * + * @param first - test case name, second - test name, third - Unfunctor, fourth - first argument Unfunctor, + * fifth - expected return value Unfunctor + * + */ + unaryFuncFord(const std::string &testCaseName, const std::string &testName, + UnFunc inFunc, FirstArgument first, ReturnValues ret); + + /** + * @brief Destructor + */ + ~unaryFuncFord(); + + /** + * @brief Calls Gtest func + * + * @param + * + * @return bool + */ + virtual bool check(); + +protected: + +private: + //methods + + /** + * @brief copy constructor + * + * @param first - const ref unaryFuncFord + */ + unaryFuncFord(const unaryFuncFord &); + + /** + * @brief Operator assignment + * + * @param first - const ref unaryFuncFord + * + * @return point to unaryFuncFord + */ + unaryFuncFord &operator=(const unaryFuncFord &); + + //members + + /** + * @brief UnFunctor + */ + UnFunc func_; + + /** + * @brief FirstArgument + */ + FirstArgument first_; + + /** + * @brief ReturnValues + */ + ReturnValues ret_; +}; + + + +template <typename UnFunc, typename FirstArgument, typename ReturnValues> +unaryFuncFord<UnFunc,FirstArgument,ReturnValues>::unaryFuncFord(const std::string &testCaseName, const std::string &testName, + UnFunc inFunc, FirstArgument first, ReturnValues ret) + :ICheckClass(testCaseName, testName) + ,func_(inFunc) + ,first_(first) + ,ret_(ret) +{ +} + + +template <typename UnFunc, typename FirstArgument, typename ReturnValues> +unaryFuncFord<UnFunc,FirstArgument,ReturnValues>::~unaryFuncFord() +{ +} + + +template <typename UnFunc, typename FirstArgument, typename ReturnValues> +bool unaryFuncFord<UnFunc,FirstArgument,ReturnValues>::check() +{ + return (ret_ == func_(first_)); +} + + +template <typename UnFunc, typename FirstArgument, typename ReturnValues> +unaryFuncFord<UnFunc,FirstArgument,ReturnValues>::unaryFuncFord(const unaryFuncFord &in) + :ICheckClass(in.unitTestName, in.testName) +{ +} + + +template <typename UnFunc, typename FirstArgument, typename ReturnValues> +unaryFuncFord<UnFunc,FirstArgument,ReturnValues> &unaryFuncFord<UnFunc,FirstArgument,ReturnValues>::operator=(const unaryFuncFord &) +{ + return *this; +} + + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_UNARY_PREDICAT_FORD_H_ + + + + + diff --git a/SDL_Core/test/components/application_manager/rpc/include/rpc/xmlParser.h b/SDL_Core/test/components/application_manager/rpc/include/rpc/xmlParser.h new file mode 100755 index 000000000..58ec9f252 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/include/rpc/xmlParser.h @@ -0,0 +1,253 @@ +/** + * Copyright (c) 2013, 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_APPLICATION_MANAGER_RPC_INCLUDE_RPC_XML_PARSER_H_ +#define TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_XML_PARSER_H_ + +#include <string> +#include <dirent.h> +#include <map> +#include <algorithm> +#include <cstring> + +#include "smart_objects/smart_object.h" +#include "libxml/xmlreader.h" +#include "formatters/CFormatterJsonSDLRPCv2.hpp" +#include "formatters/formatter_json_rpc.h" + +using namespace NsSmartDeviceLink::NsJSONHandler::strings; +using namespace NsSmartDeviceLink::NsSmartObjects; +namespace jhs = NsSmartDeviceLink::NsJSONHandler::strings; +using namespace std; + +namespace test { +namespace app_manager_test { +namespace xml_parser { + + /** + *@brief Typedef for string params + */ + typedef std::map<std::string,std::string> SSMap; + + /** + *@brief Singleton class for parsing XML-file with requests + */ + class XmlParser + { + public: + static XmlParser* instance(); + + /** + *@brief Sets current dir path with XML-files + *@param std::string pith path + */ + void SetXmlDir(const std::string& path); + + /** + *@brief Gets current dir path with XML-files + *@return returns std::string with current path + */ + std::string GetXmlDir() const; + + /** + *@brief Gets current xml-file name + *@return returns std::string with current xml-file name + */ + std::string GetXmlFileName() const; + + /** + *@brief Opens a dir with xml-files + *@return true if succesfull, otherwise false + */ + bool OpenDir(); + + /** + *@brief Finds first xml-file in dir and then next xml-files + *@return true if succesfull, otherwise false + */ + bool NextXml(); + + /** + *@brief Reads current xml-file + *@return true if succesfull, otherwise false + */ + bool ReadXml(); + + /** + *@brief Closes current xml-file + */ + void CloseXml(); + + /** + *@brief Closes current dir with xml-files + */ + void CloseDir(); + + /** + *@brief Finds first and then next test nodes + *@return true if succesfull + */ + bool MoveToNextTestNode(); + + /** + *@brief Fill smartobject with test params + *@param SmartObject to fill + *@return true if succesfull + */ + bool GetRequestFromTest(SmartObject& so); + + private: + XmlParser(); + ~XmlParser(); + + private: + + /** + *@brief Finds first test node in xml-file + *@return true if succesfull + */ + bool FindFirstTestNode(); + + /** + *@brief Recursive function that finds test nodes + *@param xmlNode* to find in + *@param xmlNode*& found test node + *@return true if succesfull + */ + bool SearchInNodes(xmlNode* node,xmlNode*& testNode); + + /** + *@brief Moves to next test node + *@return true if succesfull + */ + bool NextTestNode(); + + /** + *@brief Reads test attributes and puts them into SmartObject + *@param SmartObject& to fill + */ + void SetTestAttributes(SmartObject& so); + + /** + *@brief Recursively fills smartobject with params in test node + *@param xmlNode* to start with + *@param SmartObject& to fill + */ + void PutParamsToSO(xmlNode* node,SmartObject& so); + + /** + *@brief Recursively puts vector param to smartobject + *@param xmlNode* vector node + *@param SmartObject& to fill + */ + void PutVectorToSO(xmlNode* node,SmartObject& so); + + /** + *@brief Puts an integer param in smartobject + *@param xmlAttr* pointer to parameter + *@param SmartObject& to put in + */ + void SetIntegerMsgParam(const xmlAttr* xmlParam,SmartObject& so); + + /** + *@brief Puts a boolean parameter in smartobject + *@param xmlAttr* pointer to parameter + *@param SmartObject& to put in + */ + void SetBooleanMsgParam(const xmlAttr* xmlParam,SmartObject& so); + + /** + *@brief Puts a string parameter in smartobject + *@param xmlAttr* pointer to parameter + *@param SmartObject& to put in + */ + void SetStringMsgParam(const xmlAttr* xmlParam,SmartObject& so); + + /** + *@brief just moves to next valid tag (not text tag or comment tag) + *@param xmlNode*& node to start from + */ + void MoveToTag(xmlNode*& node); + + /** + *@brief converts a xmlChar string to std::string + *@param xmlChar* string + *@return std::string with converted xmlChar string + */ + std::string ToString(const xmlChar* str); + + /** + *@brief veifies if a string has no invalid chars + *@param std::string& to check + *@return true if a string has no invalid chars, otherwise false + */ + bool VerifyString(const std::string& param); + + /** + *@brief checks if a string has only number chars and converts it to integer + *@param std::string& to check and convert + *@return converted value if a string has been converted, otherwise -1 + */ + int StrToInt(const std::string& param); + + /** + *@brief checks if a string consists only of "true" or "false" + *@param std::string& to check and convert + *@return if string consists of "true", returns true, other occations - false + */ + bool StrToBool(const std::string& param); + + + + std::string sXmlDir; + DIR* xmlDir; + dirent* xmlFile; + std::string sXmlFileName; + xmlDocPtr xmlDoc; + xmlNode* xmlTestNode; + + bool dirOpened; + bool xmlOpened; + bool xmlFileExists; + bool firstTestNodeFound; + + SSMap params; + }; +}//xml_parser +}//app_manager_test +}//test + + + +#endif //TEST_COMPONENTS_APPLICATION_MANAGER_RPC_INCLUDE_RPC_XML_PARSER_H_ + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/AdminAppTest.cc b/SDL_Core/test/components/application_manager/rpc/src/AdminAppTest.cc new file mode 100644 index 000000000..470b8f1d8 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/AdminAppTest.cc @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2013, 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. + */ + + +#include "rpc/AdminAppTest.h" +#include "../../../../../src/appMain/life_cycle.h" + + +namespace test { + namespace app_manager_test { + + AdminAppTest::AdminAppTest() + //xmlPathToDir() + { + } + + + AdminAppTest::~AdminAppTest() + { + } + + + void AdminAppTest::threadMain() + { + this->run(); + } + + + void AdminAppTest::run() + { + application_manager::ApplicationManagerImpl* app_manager_ = + application_manager::ApplicationManagerImpl::instance(); + + //Start init dependence appManagerImpl,HMIImpl,transport... + initStartData(); + + sleep(5); + printf("\n\n\n after init in Admin \n\n\n"); + ////////////////////////////////////////////// + //Test AddCommand + + testHMI(); + + app_manager_->UnregisterAllApplications(); + + ////////////////////////////////////////////// + //Test Mobile + + //testMobile(); + + ////////////////////////////////////////////// + //check add Test + + //addTest("www", "aaa", foo, 65); + + + ////////////////////////////////////////////// + + /* + too_many_request_test_case *requestTestCase = + new too_many_request_test_case("too_many_request_test_case", "first"); + + GMockClassContainer *container = GMockClassContainer::instance(); + + container->addTest(requestTestCase); + */ + + ////////////////////////////////////////////// + /* + too_many_pending_requests_test_case *requestPendingTestCase = new too_many_pending_requests_test_case("too_many_pending_requests_test_case", "first"); + + GMockClassContainer *container = GMockClassContainer::instance(); + + container->addTest(requestPendingTestCase); + */ + ////////////////////////////////////////////// + + + } + }//namespace app_manager_test +}//namespace test + + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/CkeckHMIMessageHandler.cc b/SDL_Core/test/components/application_manager/rpc/src/CkeckHMIMessageHandler.cc new file mode 100644 index 000000000..5542e9156 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/CkeckHMIMessageHandler.cc @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2013, 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. + */ + + +#include "rpc/CheckMobileMessageHandler.h" + +namespace test{ + namespace Mobile_Message_Handler_Tester{ + + CheckMobileMessageHandler::CheckMobileMessageHandler(const std::string &inUnitTestName, + const std::string &inTestName, + utils::SharedPtr<application_manager::Message> &inResponse) + :ICheckClass(inUnitTestName, inTestName) + //,flagRun_(false) + ,got_response_(new application_manager::Message()) + ,expected_response_(new application_manager::Message()) + { + *expected_response_ = *inResponse; + } + + + CheckMobileMessageHandler::~CheckMobileMessageHandler() + { + } + + + CheckMobileMessageHandler::CheckMobileMessageHandler(const CheckMobileMessageHandler &inCheck) + :ICheckClass(inCheck.unitTestName, inCheck.testName) + { + } + + + CheckMobileMessageHandler *CheckMobileMessageHandler::operator=(const CheckMobileMessageHandler &) + { + return this; + } + + + bool CheckMobileMessageHandler::check() + { + bool returnValues = true; + + printf("\n\n\n----------------------------------------\n\n"); + printf("EXPECTED_RESPONSE:\n\n"); + printf("correlation_id : %d\n",(*expected_response_).correlation_id()); + printf("function_id : %d\n",(*expected_response_).function_id()); + printf("connection_key : %d\n",(*expected_response_).connection_key()); + printf("type : %d\n",(*expected_response_).type()); + printf("protocol_version : %d\n",(*expected_response_).protocol_version()); + printf("json_message : %s\n\n",(*expected_response_).json_message().data()); + + printf("GOT_RESPONSE:\n\n"); + printf("correlation_id : %d\n",(*got_response_).correlation_id()); + printf("function_id : %d\n",(*got_response_).function_id()); + printf("connection_key : %d\n",(*got_response_).connection_key()); + printf("type : %d\n",(*got_response_).type()); + printf("protocol_version : %d\n",(*got_response_).protocol_version()); + printf("json_message : %s\n\n",(*got_response_).json_message().data()); + + printf("----------------------------------------\n\n"); + + + returnValues = returnValues && ((*expected_response_).correlation_id()==(*got_response_).correlation_id()); + //printf("%d\n",returnValues); + returnValues = returnValues && ((*expected_response_).function_id()==(*got_response_).function_id()); + //printf("%d\n",returnValues); + returnValues = returnValues && ((*expected_response_).connection_key()==(*got_response_).connection_key()); + //printf("%d\n",returnValues); + returnValues = returnValues && ((*expected_response_).protocol_version()==(*got_response_).protocol_version()); + //printf("%d\n",returnValues); + returnValues = returnValues && ((*expected_response_).json_message()==(*got_response_).json_message()); + //printf("%d\n",returnValues); + + return returnValues; + } + + + void CheckMobileMessageHandler::addMessage(const MobileMessage &inMessage) + { + *got_response_ = *inMessage; + + //flagRun_ = true; + } + + }//namespace Mobile_Message_Handler_Tester +}//namespace test + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/GMockClassContainer.cc b/SDL_Core/test/components/application_manager/rpc/src/GMockClassContainer.cc new file mode 100644 index 000000000..8458bdfbf --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/GMockClassContainer.cc @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2013, 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. + */ + +#include "rpc/GMockClassContainer.h" + + +GMockClassContainer::GMockClassContainer() +{ +} + + +GMockClassContainer::~GMockClassContainer() +{ +} + + +GMockClassContainer *GMockClassContainer::instance() +{ + static GMockClassContainer container; + return &container; +} + + +void GMockClassContainer::addTest(ICheckClass *inCheck) +{ + mas_.push_back(inCheck); + + testing::internal::MakeAndRegisterTestInfo(inCheck->GetUnitTestName().data(), + inCheck->GetTestName().data(), + 0, + 0, + testing::internal::GetTestTypeId(), + testing::Test::SetUpTestCase, + testing::Test::TearDownTestCase, + new testing::internal::TestFactoryImpl<GTestFord>); +} + + +ICheckClass *GMockClassContainer::getTest(int i) +{ + ICheckClass *returnValues = NULL; + + if (i <= mas_.size()) + { + returnValues = mas_[i]; + } + + return returnValues; +} + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/GTestFord.cc b/SDL_Core/test/components/application_manager/rpc/src/GTestFord.cc new file mode 100644 index 000000000..8725b0bcb --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/GTestFord.cc @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2013, 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. + */ + +#include "rpc/GTestFord.h" + +GTestFord::GTestFord() +{ +} + + +GTestFord::~GTestFord() +{ +} + + +int GTestFord::index = 0; + + +void GTestFord::TestBody() +{ + GMockClassContainer *container = GMockClassContainer::instance(); + + EXPECT_EQ( (container->getTest(index))->check(),true); + index++; +} + diff --git a/SDL_Core/test/components/application_manager/rpc/src/HMIMessageHandlerTester.cc b/SDL_Core/test/components/application_manager/rpc/src/HMIMessageHandlerTester.cc new file mode 100755 index 000000000..0407da522 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/HMIMessageHandlerTester.cc @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2013, 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. + */ + + +#include "rpc/HMIMessageHandlerTester.h" + + +namespace test{ + namespace HMI_Message_Handler_Tester{ + + + HMIMessageHandlerTester::HMIMessageHandlerTester() + { + } + + + HMIMessageHandlerTester::~HMIMessageHandlerTester() + { + } + + + HMIMessageHandlerTester::HMIMessageHandlerTester(const HMIMessageHandlerTester &) + { + } + + + HMIMessageHandlerTester *HMIMessageHandlerTester::operator=(const HMIMessageHandlerTester &) + { + return this; + } + + + + void HMIMessageHandlerTester::SendMessageToHMI(utils::SharedPtr<application_manager::Message> message) + { + printf("\n\n\n\n HMIMessageHandlerTester::SendMessageToHMI \n\n\n\n"); + + + + printf("correlation_id : %d\n",(*message).correlation_id()); + printf("function_id : %d\n",(*message).function_id()); + printf("connection_key : %d\n",(*message).connection_key()); + printf("type : %d\n",(*message).type()); + printf("protocol_version : %d\n",(*message).protocol_version()); + printf("json_message : %s\n\n",(*message).json_message().data()); + + } + + + void HMIMessageHandlerTester::OnMessageReceived(utils::SharedPtr<application_manager::Message> message) + { + printf("\n\n\n\n HMIMessageHandlerTester::OnMessageReceived \n\n\n\n"); + } + + + void HMIMessageHandlerTester::OnErrorSending(utils::SharedPtr<application_manager::Message> message) + { + printf("\n\n\n\n HMIMessageHandlerTester::OnErrorSending \n\n\n\n"); + } + + + void HMIMessageHandlerTester::AddHMIMessageAdapter(HMIMessageAdapter* adapter) + { + printf("\n\n\n\n HMIMessageHandlerTester::AddHMIMessageAdapter \n\n\n\n"); + } + + + void HMIMessageHandlerTester::RemoveHMIMessageAdapter(HMIMessageAdapter* adapter) + { + printf("\n\n\n\n HMIMessageHandlerTester::RemoveHMIMessageAdapter \n\n\n\n"); + } + + + + + }// namespace HMI_Message_Handler_Tester +}//namespace test + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/ICheckClass.cc b/SDL_Core/test/components/application_manager/rpc/src/ICheckClass.cc new file mode 100644 index 000000000..0c08fbe87 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/ICheckClass.cc @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2013, 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. + */ + + +#include <rpc/ICheckClass.h> + + +ICheckClass::ICheckClass(const std::string& inUnitTestName,const std::string& inTestName): + unitTestName_(inUnitTestName) + ,testName_(inTestName) +{ +} + + + +ICheckClass::~ICheckClass() +{ +} + + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/InitHMI.cc b/SDL_Core/test/components/application_manager/rpc/src/InitHMI.cc new file mode 100644 index 000000000..2534c40ad --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/InitHMI.cc @@ -0,0 +1,122 @@ +/** + * Copyright (c) 2013, 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. + */ + +#include "rpc/InitHMI.h" + +namespace InitializeHMI{ + log4cxx::LoggerPtr loggerInitHmi = log4cxx::LoggerPtr( + log4cxx::Logger::getLogger("test_InitHMI")); + + bool InitHmi(){ + + pid_t pid_hmi = 0; + struct stat sb; + if (stat("../src/appMain/hmi_link", &sb) == -1) { + LOG4CXX_INFO(loggerInitHmi, "File with HMI link doesn't exist!"); + return false; + } + + std::ifstream file_str; + file_str.open("../src/appMain/hmi_link"); + + if (!file_str.is_open()) { + LOG4CXX_INFO(loggerInitHmi, "File with HMI link was not opened!"); + return false; + } + + file_str.seekg(0, std::ios::end); + int length = file_str.tellg(); + file_str.seekg(0, std::ios::beg); + + char* raw_data = new char[length + 1]; + if (!raw_data) { + LOG4CXX_INFO(loggerInitHmi, "Memory allocation failed."); + return false; + } + + memset(raw_data, 0, length + 1); + file_str.getline(raw_data, length + 1); + std::string hmi_link = std::string(raw_data, strlen(raw_data)); + delete[] raw_data; + + + LOG4CXX_INFO(loggerInitHmi, "Input string:" << hmi_link << " length = " << hmi_link.size()); + file_str.close(); + + if (stat(hmi_link.c_str(), &sb) == -1) { + LOG4CXX_INFO(loggerInitHmi, "HMI index.html doesn't exist!"); + return false; + } + + // Create a child process. + pid_hmi = fork(); + + switch (pid_hmi) { + case -1: { // Error + LOG4CXX_INFO(loggerInitHmi, "fork() failed!"); + return false; + } + case 0: { // Child process + int fd_dev0 = open("/dev/null", O_RDWR, S_IWRITE); + if (0 > fd_dev0) { + LOG4CXX_WARN(loggerInitHmi, "Open dev0 failed!"); + return false; + } + // close input/output file descriptors. + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + + // move input/output to /dev/null. + dup2(fd_dev0, STDIN_FILENO); + dup2(fd_dev0, STDOUT_FILENO); + dup2(fd_dev0, STDERR_FILENO); + + // Execute the program. + execlp(kBrowser, kBrowserName, kBrowserParams, hmi_link.c_str(), + reinterpret_cast<char*>(0)); + LOG4CXX_WARN(loggerInitHmi, "execl() failed! Install chromium-browser!"); + + return true; + } + default: { /* Parent process */ + LOG4CXX_INFO(loggerInitHmi, "Process created with pid " << pid_hmi); + return true; + } + } + + + //return true; + } + +}//namespace InitializeHMI + diff --git a/SDL_Core/test/components/application_manager/rpc/src/addTest.cc b/SDL_Core/test/components/application_manager/rpc/src/addTest.cc new file mode 100644 index 000000000..58fe4e88a --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/addTest.cc @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2013, 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. + */ + +#include "rpc/addTest.h" + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/initStartData.cc b/SDL_Core/test/components/application_manager/rpc/src/initStartData.cc new file mode 100644 index 000000000..e95735989 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/initStartData.cc @@ -0,0 +1,229 @@ +/** + * Copyright (c) 2013, 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. + */ + +#include "rpc/initStartData.h" +#include "../../../../../src/appMain/life_cycle.h" + +void initStartData() +{ + transport_manager::TransportManager* transport_manager_; + protocol_handler::ProtocolHandlerImpl* protocol_handler_; + connection_handler::ConnectionHandlerImpl* connection_handler_; + application_manager::ApplicationManagerImpl* app_manager_; +#ifdef WEB_HMI + hmi_message_handler::MessageBrokerAdapter* mb_adapter_; +#endif +#ifdef QT_HMI + hmi_message_handler::DBusMessageAdapter* dbus_adapter_; +#endif + + //policies::PolicyManagerImpl* policy_manager_; + + media_manager::MediaManagerImpl* media_manager_; + + + //mobile_message_handler::MobileMessageHandlerImpl* mmh_; + hmi_message_handler::HMIMessageHandlerImpl* hmi_handler_; + + + log4cxx::PropertyConfigurator::configure("./../src/appMain/log4cxx.properties"); + + + + + // -------------------------------------------------------------------------- + // Third-Party components initialization. + //if (!main_namespace::LifeCycle::instance()->InitMessageBroker()) { + + // exit(EXIT_FAILURE); + //} + + + // -------------------------------------------------------------------------- + // Components initialization +// transport_manager::TransportManagerAttr tma; +// tma.disconnectTimeout = 1000; + transport_manager_ = + // new transport_manager::TransportManagerImpl(tma); + transport_manager::TransportManagerDefault::instance(); + DCHECK(transport_manager_); + + protocol_handler_ = + new protocol_handler::ProtocolHandlerImpl(transport_manager_); + DCHECK(protocol_handler_); + + //mmh_ = + // mobile_message_handler::MobileMessageHandlerImpl::instance(); + //DCHECK(mmh_); + + connection_handler_ = + connection_handler::ConnectionHandlerImpl::instance(); + DCHECK(connection_handler_); + + app_manager_ = + application_manager::ApplicationManagerImpl::instance(); + DCHECK(app_manager_); + + hmi_handler_ = + hmi_message_handler::HMIMessageHandlerImpl::instance(); + DCHECK(hmi_handler_); + + //policy_manager_ = policies::PolicyManagerImpl::instance(); + //DCHECK(policy_manager_); + + media_manager_ = media_manager::MediaManagerImpl::instance(); + + //////////////////////////////////////// + /* + //Add 25 december + printf("\n\n\n add device \n\n\n"); + transport_manager::DeviceHandle device_handler_test = 1; + std::string mac_address_test = "255.255.255.0"; + std::string name_test = "test_DeviceInfo"; + + transport_manager::ConnectionUID connection_id_test = 1; + + transport_manager::DeviceInfo device_info_test(device_handler_test, mac_address_test, name_test); + + std::vector<transport_manager::DeviceInfo> device_list_test; + device_list_test.push_back(device_info_test); + connection_handler_->OnDeviceListUpdated(device_list_test); + + + connection_handler_->OnConnectionEstablished(device_info_test, connection_id_test); + */ + //////////////////////////////////// + + + + //transport_manager_->SetProtocolHandler(protocol_handler_); + transport_manager_->AddEventListener(protocol_handler_); + transport_manager_->AddEventListener(connection_handler_); + //printf("\n\n\n after init transport_manager \n\n\n"); + + + hmi_handler_->set_message_observer(app_manager_); + //printf("\n\n\n after init hmi \n\n\n"); + + media_manager_->SetProtocolHandler(protocol_handler_); + //printf("\n\n\n after init media_manager \n\n\n"); + protocol_handler_->set_session_observer(connection_handler_); + //protocol_handler_->AddProtocolObserver(mmh_); + protocol_handler_->AddProtocolObserver(media_manager_); + protocol_handler_->AddProtocolObserver(app_manager_); + //printf("\n\n\n after init protocol_handler \n\n\n"); + connection_handler_->set_transport_manager(transport_manager_); + connection_handler_->set_connection_handler_observer(app_manager_); + //printf("\n\n\n after init connection_handler \n\n\n"); + //mmh_->set_protocol_handler(protocol_handler_); + //mmh_->AddMobileMessageListener(app_manager_); + //printf("\n\n\n after init mmh \n\n\n"); + // It's important to initialise TM after setting up listener chain + // [TM -> CH -> AM], otherwise some events from TM could arrive at nowhere + transport_manager_->Init(); + + //app_manager_->set_mobile_message_handler(mmh_); + app_manager_->set_connection_handler(connection_handler_); + app_manager_->set_hmi_message_handler(hmi_handler_); + app_manager_->set_protocol_handler(protocol_handler_); + + //app_manager_->set_policy_manager(policy_manager_); + + //printf("\n\n\n after init app \n\n\n"); + + if (profile::Profile::instance()->server_address() == + std::string(InitializeHMI::kLocalHostAddress)) { + + if (!InitializeHMI::InitHmi()) { + exit(EXIT_FAILURE); + } + + } + + printf("\n\n\n after first init \n\n\n"); + + + //transport_manager::transport_adapter::TransportAdapterController* TAC = + // new transport_manager::transport_adapter::TransportAdapterController; + + //transport_manager::transport_adapter::TcpTransportAdapter* ta = + // new transport_manager::transport_adapter::TcpTransportAdapter(); + + /* + transport_manager::transport_adapter::DnssdServiceBrowser* DSB = + new transport_manager::transport_adapter::DnssdServiceBrowser(ta); + + transport_manager::transport_adapter::ServerConnectionFactory* SCF = + new transport_manager::transport_adapter::TcpConnectionFactory(ta); + + transport_manager::transport_adapter::ClientConnectionListener* CCL = + new transport_manager::transport_adapter::TcpClientListener(ta,80); + */ + + //ta = new transport_manager::transport_adapter::TransportAdapter(DSB,SCF,CCL); + + //utils::SharedPtr<TransportAdapter> taSprt(ta); + + //transport_manager_->AddTransportAdapter(taSprt); + /* + + //transport_manager::transport_adapter:: + + utils::SharedPtr<protocol_handler::RawMessage> rawMessageSptr;//typedef utils::SharedPtr<protocol_handler::RawMessage> RawMessageSptr; + int type = 0;//TransportAdapterListenerImpl::EventTypeEnum::ON_SEARCH_DONE; + + transport_manager::DeviceUID DUID;//typedef std::string DeviceUID; + int app_handle = 0;//typedef int ApplicationHandle; + + transport_manager::BaseError *br = new transport_manager::BaseError; + transport_manager::TransportAdapterEvent *tae = + new transport_manager::TransportAdapterEvent(type, taSprt, DUID, app_handle, rawMessageSptr, br); + + transport_manager_->ReceiveEventFromDevice(*tae); + */ + +} + + + + + + + + + + + + + + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/testHMI.cc b/SDL_Core/test/components/application_manager/rpc/src/testHMI.cc new file mode 100644 index 000000000..a85b31cc3 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/testHMI.cc @@ -0,0 +1,249 @@ +/** + * Copyright (c) 2013, 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. + */ + +#include <unistd.h> +#include "rpc/testHMI.h" +#include "application_manager/application_impl.h" + +namespace test{ + namespace app_manager_test{ + void testHMI() + { + + printf("\n\n\n init param to HMI AddCommand \n\n\n"); + + + connection_handler::ConnectionHandlerImpl* connection_handler_ = + connection_handler::ConnectionHandlerImpl::instance(); + + + application_manager::ApplicationManagerImpl* app_manager_ = + application_manager::ApplicationManagerImpl::instance(); + + transport_manager::DeviceHandle device_handler_test = 1; + std::string mac_address_test = "255.255.255.0"; + std::string name_test = "test_DeviceInfo"; + + transport_manager::ConnectionUID connection_id_test = 1; + + transport_manager::DeviceInfo device_info_test(device_handler_test, mac_address_test, name_test); + + std::vector<transport_manager::DeviceInfo> device_list_test; + device_list_test.push_back(device_info_test); + connection_handler_->OnDeviceListUpdated(device_list_test); + + + connection_handler_->OnConnectionEstablished(device_info_test, connection_id_test); + + + ////////////////////////////////////////// + //HMICapabilities 14.1 + //HMICapabilities& hmi_capabilities = + // ApplicationManagerImpl::instance()->hmi_capabilities(); + + //hmi_capabilities. + //app_manager_->OnHMIStartedCooperation(); + HMICapabilities &hmi_capabilities = app_manager_->hmi_capabilities(); + hmi_capabilities.set_is_vr_cooperating(true); + hmi_capabilities.set_is_tts_cooperating(true); + hmi_capabilities.set_is_ui_cooperating(true); + hmi_capabilities.set_is_navi_cooperating(true); + hmi_capabilities.set_is_ivi_cooperating(true); + + hmi_capabilities.set_active_ui_language(hmi_apis::Common_Language::EN_US); + hmi_capabilities.set_active_vr_language(hmi_apis::Common_Language::EN_US); + hmi_capabilities.set_active_tts_language(hmi_apis::Common_Language::EN_US); + + SmartObject hmi_capa; + hmi_capabilities.set_ui_supported_languages(hmi_capa); + hmi_capabilities.set_tts_supported_languages(hmi_capa); + hmi_capabilities.set_vr_supported_languages(hmi_capa); + hmi_capabilities.set_vehicle_type(hmi_capa); + + + //////////////////////////////////////// + sleep(2); + printf("\n\n\n Registration Application \n\n\n"); + /////////////////////////////////////////////////// + /* + Reg app + + utils::SharedPtr<SmartObject> AppRegRequest(new SmartObject); + + (*AppRegRequest)[S_PARAMS][strings::connection_key] = 65537; + //(*AppRegRequest)[S_MSG_PARAMS][strings::menu_params][strings::menu_name] = "MenuName"; + (*AppRegRequest)[S_MSG_PARAMS][strings::app_name] = "SyncProxyTester"; + + + + (*AppRegRequest)[S_PARAMS][strings::function_id] = mobile_apis::FunctionID::RegisterAppInterfaceID; + (*AppRegRequest)[S_PARAMS][strings::message_type] = mobile_apis::messageType::request; + (*AppRegRequest)[S_PARAMS][strings::correlation_id] = 1; + + (*AppRegRequest)[S_MSG_PARAMS][strings::available] = true; + Application* appl = app_manager_->RegisterApplication(AppRegRequest); + */ + /////////////////////////////////// + //add to 23 december + + utils::SharedPtr<SmartObject> AppRegRequest(new SmartObject); + //test::Mobile_Message_Handler_Tester::MobileMessageHandlerTester* mobile_handler_test; + //mobile_handler_test = + // new test::Mobile_Message_Handler_Tester::MobileMessageHandlerTester; + + //app_manager_->set_mobile_message_handler(mobile_handler_test); + //////////////////////////////////// + //add 25 december + //app_manager_->set_active_vr_language(hmi_apis::Common_Language::EN_US); + //app_manager_->set_active_ui_language(hmi_apis::Common_Language::EN_US); + ///////////////////////////////////// + (*AppRegRequest)[S_PARAMS][strings::function_id] = mobile_apis::FunctionID::RegisterAppInterfaceID; + (*AppRegRequest)[S_PARAMS][strings::message_type] = mobile_apis::messageType::request; + (*AppRegRequest)[S_PARAMS][strings::correlation_id] = 1; + (*AppRegRequest)[S_PARAMS][strings::connection_key] = 65537; + + + (*AppRegRequest)[S_MSG_PARAMS][strings::app_name] = "SyncProxyTester"; + (*AppRegRequest)[S_MSG_PARAMS][strings::available] = true; + (*AppRegRequest)[S_MSG_PARAMS][strings::language_desired] = hmi_apis::Common_Language::EN_US; + (*AppRegRequest)[S_MSG_PARAMS][strings::hmi_display_language_desired] = hmi_apis::Common_Language::EN_US; + + + + //(*AppRegRequest)[S_MSG_PARAMS][strings::app_id] = "12345"; + //(*AppRegRequest)[S_MSG_PARAMS][strings::is_media_application] = true; + //(*AppRegRequest)[S_MSG_PARAMS][strings::vr_synonyms][0] = "VR SyncProxyTester"; + //(*AppRegRequest)[S_MSG_PARAMS][strings::ngn_media_screen_app_name] = "SPT"; + //(*AppRegRequest)[S_MSG_PARAMS][strings::tts_name][0]["text"] = "SyncProxyTester"; + //(*AppRegRequest)[S_MSG_PARAMS][strings::tts_name][0]["type"] = "TEXT"; + //(*AppRegRequest)[S_MSG_PARAMS][strings::app_hmi_type] = mobile_apis::AppHMIType::NAVIGATION; + //(*AppRegRequest)[S_MSG_PARAMS][strings::cmd_id] = 321; + //(*AppRegRequest)[S_MSG_PARAMS][strings::menu_params][strings::menu_name] = "MenuName"; + //(*AppRegRequest)[S_MSG_PARAMS][strings::language_desired] = hmi_apis::Common_Language::EN_US; + //(*AppRegRequest)[S_MSG_PARAMS][strings::hmi_display_language_desired] = hmi_apis::Common_Language::EN_US; + + + //MessageChaining* MesChain = app_manager_->AddMessageChain(connectKey, 1, 16, NULL, &(*AppRegRequest) ); + //printf("\n\n\n after MesChain \n\n\n"); + //app_manager_->AddMessageChain(connectKey,1,16,MesChain, &(*AppRegRequest) ); + //printf("\n\n\n after MesChain after\n\n\n"); + + //app_manager_->set_hmi_level(mobile_apis::HMILevel::HMI_BACKGROUND); + app_manager_->ManageMobileCommand(AppRegRequest); + /////////////////////////////////// + + + ApplicationSharedPtr appl = app_manager_->application(65537); + + //////////////////////////////////////// + sleep(5); + + + + printf("\n\n\n AddCommand Request \n\n\n"); + + test::HMI_Message_Handler_Tester::HMIMessageHandlerTester* hmi_handler_test; + + hmi_handler_test = new test::HMI_Message_Handler_Tester::HMIMessageHandlerTester; + + utils::SharedPtr<SmartObject> HMIRequest(new SmartObject); + + + + //NsSmartDeviceLink::NsJSONHandler::strings:: + //mobile_apis::FunctionID::RegisterAppInterfaceID; + + + (*HMIRequest)[S_PARAMS][strings::function_id] = mobile_apis::FunctionID::AddCommandID; + (*HMIRequest)[S_PARAMS][strings::correlation_id] = 1; + (*HMIRequest)[S_PARAMS][strings::message_type] = mobile_apis::messageType::request; + (*HMIRequest)[S_PARAMS][strings::protocol_type] = 0; + (*HMIRequest)[S_PARAMS][strings::protocol_version] = 2; + (*HMIRequest)[S_PARAMS][strings::connection_key] = appl->app_id(); + + (*HMIRequest)[S_MSG_PARAMS][strings::app_id] = "12345"; + (*HMIRequest)[S_MSG_PARAMS][strings::app_name] = "SyncProxyTester"; + + (*HMIRequest)[S_MSG_PARAMS][strings::cmd_id] = 321; + (*HMIRequest)[S_MSG_PARAMS][strings::success] = true; + (*HMIRequest)[S_MSG_PARAMS][strings::hmi_level] = 5; + + (*HMIRequest)[S_MSG_PARAMS][strings::language_desired] = hmi_apis::Common_Language::EN_US; + (*HMIRequest)[S_MSG_PARAMS][strings::hmi_display_language_desired] = hmi_apis::Common_Language::EN_US; + + (*HMIRequest)[S_MSG_PARAMS][strings::is_media_application] = true; + (*HMIRequest)[S_MSG_PARAMS][strings::device_name] = device_handler_test; + + //(*HMIRequest)[S_MSG_PARAMS][strings::menu_params][strings::vr_commands] = mobile_apis::Result::RETRY; + (*HMIRequest)[S_MSG_PARAMS][strings::menu_params][strings::menu_name] = "MenuName"; + + + /* + (*spRequest)[S_MSG_PARAMS][strings::sync_msg_version]["majorVersion"] = 2; + (*spRequest)[S_MSG_PARAMS][strings::sync_msg_version]["minorVersion"] = 2; + (*spRequest)[S_MSG_PARAMS][strings::tts_name][0]["text"] = "SyncProxyTester"; + (*spRequest)[S_MSG_PARAMS][strings::tts_name][0]["type"] = "TEXT"; + (*spRequest)[S_MSG_PARAMS][strings::ngn_media_screen_app_name] = "SPT"; + (*spRequest)[S_MSG_PARAMS][strings::vr_synonyms][0] = "VR SyncProxyTester"; + (*spRequest)[S_MSG_PARAMS][strings::is_media_application] = true; + (*spRequest)[S_MSG_PARAMS][strings::app_type][0] = "DEFAULT"; + + */ + + + app_manager_->set_hmi_message_handler(hmi_handler_test); + /* + ////////////////////////////////////// + //change 25 december + app_manager_->set_active_vr_language(hmi_apis::Common_Language::EN_US); + app_manager_->set_active_ui_language(hmi_apis::Common_Language::EN_US); + + ///////////////////////////////// + */ + //Application* appRegistr = app_manager_->application(appl->app_id()); + //if (appRegistr) + // printf("\n\n\n blablabla \n\n\n"); + + //appl->set_hmi_level(mobile_apis::HMILevel::HMI_BACKGROUND); + + app_manager_->ManageMobileCommand(HMIRequest); + + + sleep(5); + } + }//namespace app_manager_test +}//namespace test + + + + + diff --git a/SDL_Core/test/components/application_manager/rpc/src/xmlParser.cc b/SDL_Core/test/components/application_manager/rpc/src/xmlParser.cc new file mode 100755 index 000000000..47ab210f7 --- /dev/null +++ b/SDL_Core/test/components/application_manager/rpc/src/xmlParser.cc @@ -0,0 +1,394 @@ +/** + * Copyright (c) 2013, 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. + */ + +#include "rpc/xmlParser.h" + +namespace test +{ +namespace app_manager_test +{ +namespace xml_parser +{ + + const char* XML_TEST_NODE_NAME = "test"; + const char* XML_TEST_MESSAGE_REQUEST = "request"; + const char* XML_TEST_MESSAGE_RESPONSE = "response"; + + const char* XML_TEST_FUNCTION_PARAM_VECTOR = "Vector"; + const char* XML_TEST_FUNCTION_PARAM_BOOLEAN = "Boolean"; + const char* XML_TEST_FUNCTION_PARAM_STRING = "String"; + const char* XML_TEST_FUNCTION_PARAM_INTEGER = "Integer"; + + + XmlParser::XmlParser(): + sXmlDir() + ,xmlDir(0) + ,xmlFile(0) + ,xmlDoc(0) + ,sXmlFileName() + ,xmlTestNode(0) + ,dirOpened(false) + ,xmlOpened(false) + ,xmlFileExists(false) + ,firstTestNodeFound(false) + ,params() { + params.insert(SSMap::value_type("params",jhs::S_PARAMS)); + params.insert(SSMap::value_type("message_params",jhs::S_MSG_PARAMS)); + params.insert(SSMap::value_type("function_id",jhs::S_FUNCTION_ID)); + params.insert(SSMap::value_type("correlation_id",jhs::S_CORRELATION_ID)); + params.insert(SSMap::value_type("protocol_type",jhs::S_PROTOCOL_TYPE)); + params.insert(SSMap::value_type("protocol_version",jhs::S_PROTOCOL_VERSION)); + params.insert(SSMap::value_type("message_type",jhs::S_MESSAGE_TYPE)); + } + + XmlParser::~XmlParser() { + CloseDir(); + CloseXml(); + } + + XmlParser* XmlParser::instance() { + static XmlParser instance; + return &instance; + } + + void XmlParser::SetXmlDir(const std::string& path) { + sXmlDir.clear(); + sXmlDir.append(path); + } + + std::string XmlParser::GetXmlDir() const { + return sXmlDir; + } + + bool XmlParser::OpenDir() { + xmlDir = opendir(sXmlDir.data()); + if (xmlDir) { + return (dirOpened = true); + } + return (dirOpened = false); + } + + bool XmlParser::NextXml() { + if (!dirOpened) return false; + xmlFile = readdir(xmlDir); + if (xmlFile) { + sXmlFileName.clear(); + sXmlFileName.append(xmlFile->d_name); + return (xmlFileExists = true); + } + return (xmlFileExists = false); + } + + bool XmlParser::ReadXml() { + if (!xmlFileExists) return false; + + std::string filePath; + + filePath.clear(); + filePath.append(sXmlDir); + filePath.append("/"); + filePath.append(sXmlFileName); + + if (!sXmlFileName.compare(".") || !sXmlFileName.compare("..")) return false; + xmlDoc = xmlReadFile(filePath.data(),0,0); + if (xmlDoc) { + return (xmlOpened = true); + } + return (xmlOpened = false); + } + + void XmlParser::CloseXml() { + if (xmlOpened) xmlFreeDoc(xmlDoc); + xmlOpened = false; + firstTestNodeFound = false; + xmlFileExists = false; + } + + void XmlParser::CloseDir() { + CloseXml(); + if (dirOpened) closedir(xmlDir); + dirOpened = false; + } + + bool XmlParser::MoveToNextTestNode() { + if (!xmlOpened) return false; + if (!firstTestNodeFound) return (firstTestNodeFound = FindFirstTestNode()); + return NextTestNode(); + } + + bool XmlParser::GetRequestFromTest(SmartObject& so) { + if (!xmlOpened) return false; + xmlNode* xmlTestParams = xmlTestNode->children; + so = SmartType::SmartType_Null; + SetTestAttributes(so); + MoveToTag(xmlTestParams); + if (!xmlTestParams) return false; + PutParamsToSO(xmlTestParams,so); + return true; + } + + std::string XmlParser::GetXmlFileName() const { + return sXmlFileName; + } + + bool XmlParser::FindFirstTestNode() { + xmlNode* rootNode = xmlDoc->children; + return SearchInNodes(rootNode,xmlTestNode); + } + + bool XmlParser::SearchInNodes(xmlNode* node,xmlNode*& testNode) { + bool found = false; + std::string nodeName; + while (node) { + MoveToTag(node); + if (!node) break; + + found = found || SearchInNodes(node->children,testNode); + if (found) return found; + + nodeName.clear(); + nodeName.append(ToString(node->name)); + + if (!nodeName.compare(XML_TEST_NODE_NAME)) { + testNode = node; + return true; + } + node = node->next; + } + return false; + } + + bool XmlParser::NextTestNode() { + std::string nodeName; + xmlTestNode = xmlTestNode->next; + MoveToTag(xmlTestNode); + + if (!xmlTestNode) return false; + do { + nodeName.clear(); + nodeName.append(ToString(xmlTestNode->name)); + if (nodeName.compare(XML_TEST_NODE_NAME)) { + xmlTestNode = xmlTestNode->next; + } else { + break; + } + } + while (xmlTestNode); + if (!xmlTestNode) return false; + return true; + } + + + void XmlParser::SetTestAttributes(SmartObject& so) { + xmlAttr* xmlTestNodeAttr = xmlTestNode->properties; + std::string attrName; + std::string attrValue; + while (xmlTestNodeAttr) { + attrName.clear(); + attrName.append(ToString(xmlTestNodeAttr->name)); + attrValue.clear(); + attrValue.append(ToString(xmlTestNodeAttr->children->content)); + so[attrName] = attrValue; + xmlTestNodeAttr = xmlTestNodeAttr->next; + } + } + + void XmlParser::PutParamsToSO(xmlNode* node,SmartObject& so) { + std::string nodeName; + + while (node) { + MoveToTag(node); + if (!node) break; + + nodeName.clear(); + nodeName.append(ToString(node->name)); + + bool flag = true; + + if (!nodeName.compare(XML_TEST_FUNCTION_PARAM_STRING)) { + SetStringMsgParam(node->properties,so); + flag = false; + } + if (!nodeName.compare(XML_TEST_FUNCTION_PARAM_INTEGER)) { + SetIntegerMsgParam(node->properties,so); + flag = false; + } + if (!nodeName.compare(XML_TEST_FUNCTION_PARAM_BOOLEAN)) { + SetBooleanMsgParam(node->properties,so); + flag = false; + } + if (!nodeName.compare(XML_TEST_FUNCTION_PARAM_VECTOR)) { + if ((node->properties)&& + (node->properties->children)&& + (node->properties->children->content)) { + std::string vectorName(ToString(node->properties->children->content)); + PutVectorToSO(node->children,so[vectorName]); + } + flag = false; + } + if (flag) { + SSMap::iterator elem = params.find(nodeName); + if(elem!=params.end()) { + PutParamsToSO(node->children,so[elem->second]); + } else { + PutParamsToSO(node->children,so[nodeName]); + } + } + node = node->next; + } + } + + void XmlParser::PutVectorToSO(xmlNode* node,SmartObject& so) { + int index = 0; + while (node) { + MoveToTag(node); + if (!node) break; + + std::string nodeName(ToString(node->name)); + + bool flag = true; + if (!nodeName.compare(XML_TEST_FUNCTION_PARAM_STRING)) { + SetStringMsgParam(node->properties,so[index]); + flag = false; + } + if(flag) PutParamsToSO(node->children,so[index]); + index++; + node = node->next; + } + } + + void XmlParser::SetIntegerMsgParam(const xmlAttr* xmlParam,SmartObject& so) { + if (!xmlParam) return; + + std::string msgParam(ToString(xmlParam->name)); + if ((!xmlParam->children)||(!xmlParam->children->content)) return; + + std::string msgValue(ToString(xmlParam->children->content)); + + if (!VerifyString(msgParam)) return; + + so[msgParam] = StrToInt(msgValue); + } + + void XmlParser::SetBooleanMsgParam(const xmlAttr* xmlParam,SmartObject& so) { + if (!xmlParam) return; + + std::string msgParam(ToString(xmlParam->name)); + if ((!xmlParam->children)||(!xmlParam->children->content)) return; + + std::string msgValue(ToString(xmlParam->children->content)); + + if (!VerifyString(msgParam)) return; + + so[msgParam] = StrToBool(msgValue); + } + + void XmlParser::SetStringMsgParam(const xmlAttr* xmlParam,SmartObject& so) { + if (!xmlParam) return; + + std::string msgParam(ToString(xmlParam->name)); + if ((!xmlParam->children)||(!xmlParam->children->content)) return; + + std::string msgParamValue(ToString(xmlParam->children->content)); + + if (!VerifyString(msgParam)) return; + if (!VerifyString(msgParamValue)) return; + + SSMap::iterator elem = params.find(msgParam); + if (elem!=params.end()) { + so[elem->second] = msgParamValue; + return; + } + if (!msgParam.compare("add")) { + so = msgParamValue; + return; + } + so[msgParam] = msgParamValue; + } + + void XmlParser::MoveToTag(xmlNode*& node) { + while (node) { + if (XML_TEXT_NODE==node->type || XML_COMMENT_NODE==node->type) { + node = node->next; + } else { + break; + } + } + } + + std::string XmlParser::ToString(const xmlChar* str) { + return std::string((char*)str); + } + + bool XmlParser::VerifyString(const std::string& param) { + bool good = true; + const char invalidChars[7] = "\\/&\"<>"; + + for (int i=0;i<param.length();i++) { + if (strchr(invalidChars,param[i])) { + good = false; + break; + } + } + return good; + } + + int XmlParser::StrToInt(const std::string& param) { + bool good = true; + const char validChars[11] = "0123456789"; + int val = -1; + + for (int i=0;i<param.length();i++) { + if (!strchr(validChars,param[i])) { + good = false; + break; + } + } + if (good) val = atoi(param.data()); + + return val; + } + + bool XmlParser::StrToBool(const std::string& param) { + bool good = false; + std::string toCheck; + toCheck.clear(); + toCheck.append(param); + std::transform(toCheck.begin(),toCheck.end(),toCheck.begin(),::tolower); + + if (!toCheck.compare("true")) good = true; + return good; + } + +}//namespace xml_parser +}//namespace app_manager_test +}//namespace test |