diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/L1-tests.yml old mode 100644 new mode 100755 similarity index 95% rename from .github/workflows/unit-tests.yml rename to .github/workflows/L1-tests.yml index 78791e940f..b60b4dd68a --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/L1-tests.yml @@ -1,4 +1,4 @@ -name: unit-tests +name: l1-tests on: push: @@ -12,7 +12,7 @@ env: INTERFACES_REF: "930e01ec9aec8aa60254dec0be3beca932df63cd" jobs: - unit-tests: + l1-tests: name: Build and run unit tests runs-on: ubuntu-latest strategy: @@ -43,7 +43,7 @@ jobs: build/ThunderTools install !install/etc/WPEFramework/plugins - !install/usr/bin/RdkServicesTest + !install/usr/bin/RdkServicesL1Test !install/usr/include/gmock !install/usr/include/gtest !install/usr/lib/libgmockd.a @@ -238,11 +238,6 @@ jobs: -I ${{github.workspace}}/rdkservices/Tests/headers/ccec/drivers -I ${{github.workspace}}/rdkservices/Tests/headers/network -include ${{github.workspace}}/rdkservices/Tests/mocks/devicesettings.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Iarm.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Rfc.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/RBus.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Telemetry.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Udev.h -include ${{github.workspace}}/rdkservices/Tests/mocks/maintenanceMGR.h -include ${{github.workspace}}/rdkservices/Tests/mocks/pkg.h -include ${{github.workspace}}/rdkservices/Tests/mocks/secure_wrappermock.h @@ -281,7 +276,7 @@ jobs: -DPLUGIN_MESSENGER=ON -DPLUGIN_DEVICEINFO=ON -DPLUGIN_SYSTEMSERVICES=ON - -DRDK_SERVICES_TEST=ON + -DRDK_SERVICES_L1_TEST=ON -DPLUGIN_HDMIINPUT=ON -DPLUGIN_HDCPPROFILE=ON -DPLUGIN_NETWORK=ON @@ -345,7 +340,7 @@ jobs: run: > PATH=${{github.workspace}}/install/usr/bin:${PATH} LD_LIBRARY_PATH=${{github.workspace}}/install/usr/lib:${{github.workspace}}/install/usr/lib/wpeframework/plugins:${LD_LIBRARY_PATH} - RdkServicesTest + RdkServicesL1Test - name: Run unit tests with valgrind if: ${{ !env.ACT }} @@ -359,7 +354,7 @@ jobs: --show-reachable=yes --track-fds=yes --fair-sched=try - RdkServicesTest + RdkServicesL1Test - name: Generate coverage if: ${{ matrix.coverage == 'with-coverage' && !env.ACT }} @@ -375,7 +370,7 @@ jobs: '*/install/usr/include/*' '*/Tests/headers/*' '*/Tests/mocks/*' - '*/Tests/tests/*' + '*/Tests/L1Tests/tests/*' -o filtered_coverage.info && genhtml diff --git a/.github/workflows/L2-tests.yml b/.github/workflows/L2-tests.yml new file mode 100755 index 0000000000..093798e2ce --- /dev/null +++ b/.github/workflows/L2-tests.yml @@ -0,0 +1,323 @@ +name: l2-tests + +on: + push: + branches: [ main, 'sprint/**', 'release/**' ] + pull_request: + branches: [ main, 'sprint/**', 'release/**' ] + +env: + BUILD_TYPE: Debug + THUNDER_REF: "5e7c0b1ed3c3dd0fc31c86518a364388dc24273b" + INTERFACES_REF: "669d9c6e5ed7a5938ff26e1e7736adf485c7a205" + +jobs: + l2-tests: + name: Build and run L2 tests + runs-on: ubuntu-latest + strategy: + matrix: + compiler: [ gcc, clang ] + coverage: [ with-coverage, without-coverage ] + exclude: + - compiler: clang + coverage: with-coverage + - compiler: clang + coverage: without-coverage + - compiler: gcc + coverage: without-coverage + + steps: + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + - run: pip install jsonref + + - name: Set up CMake + uses: jwlawson/actions-setup-cmake@v1.13 + with: + cmake-version: '3.16.x' + + - name: Install packages + run: > + sudo apt update + && + sudo apt install -y libsqlite3-dev libcurl4-openssl-dev valgrind lcov clang libsystemd-dev libboost-all-dev libwebsocketpp-dev meson libcunit1 libcunit1-dev + + - name: Install GStreamer + run: | + sudo apt update + sudo apt install -y libunwind-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev + + - name: Build trevor-base64 + run: | + if [ ! -d "trower-base64" ]; then + git clone https://github.com/xmidt-org/trower-base64.git + fi + cd trower-base64 + meson setup --warnlevel 3 --werror build + ninja -C build + sudo ninja -C build install + + - name: Checkout Thunder + uses: actions/checkout@v3 + with: + repository: rdkcentral/Thunder + path: Thunder + ref: ${{env.THUNDER_REF}} + + - name: Checkout rdkservices + uses: actions/checkout@v3 + with: + path: rdkservices + + - name: Apply patch + run: > + cd "${{github.workspace}}/Thunder" + && + git apply "${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0001-RDK-30034-callsign.patch" + + - name: Build Thunder + run: > + cmake + -S "${{github.workspace}}/Thunder/Tools" + -B build/ThunderTools + -DEXCEPTIONS_ENABLE=ON + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + -DGENERIC_CMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + && + cmake --build build/ThunderTools -j8 + && + cmake --install build/ThunderTools + && + cmake + -S "${{github.workspace}}/Thunder" + -B build/Thunder + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + -DBUILD_TYPE=${{env.BUILD_TYPE}} + -DBINDING=127.0.0.1 + -DPORT=9998 + -DEXCEPTIONS_ENABLE=ON + && + cmake --build build/Thunder -j8 + && + cmake --install build/Thunder + + - name: Checkout ThunderInterfaces + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderInterfaces + path: ThunderInterfaces + ref: ${{env.INTERFACES_REF}} + + - name: Build ThunderInterfaces + run: > + cmake + -S "${{github.workspace}}/ThunderInterfaces" + -B build/ThunderInterfaces + -DEXCEPTIONS_ENABLE=ON + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + && + cmake --build build/ThunderInterfaces -j8 + && + cmake --install build/ThunderInterfaces + + - name: Generate external headers + # Empty headers to mute errors + run: > + cd "${{github.workspace}}/rdkservices/Tests/" + && + mkdir -p + headers + headers/rdk/ds + headers/rdk/iarmbus + headers/rdk/iarmmgrs-hal + headers/systemservices + headers/systemservices/proc + && + cd headers + && + touch + rdk/ds/host.hpp + rdk/ds/videoOutputPort.hpp + rdk/ds/audioOutputPort.hpp + rdk/ds/sleepMode.hpp + rdk/iarmbus/libIARM.h + rdk/iarmbus/libIBus.h + rdk/iarmbus/libIBusDaemon.h + rdk/iarmmgrs-hal/mfrMgr.h + rdk/iarmmgrs-hal/pwrMgr.h + rdk/iarmmgrs-hal/sysMgr.h + rfcapi.h + systemservices/proc/readproc.h + maintenanceMGR.h + pkg.h + && + cp -r /usr/include/gstreamer-1.0/gst /usr/include/glib-2.0/* /usr/lib/x86_64-linux-gnu/glib-2.0/include/* /usr/local/include/trower-base64/base64.h . + + - name: Set clang toolchain + if: ${{ matrix.compiler == 'clang' }} + run: echo "TOOLCHAIN_FILE=${{github.workspace}}/rdkservices/Tests/clang.cmake" >> $GITHUB_ENV + + - name: Set gcc/with-coverage toolchain + if: ${{ matrix.compiler == 'gcc' && matrix.coverage == 'with-coverage' && !env.ACT }} + run: echo "TOOLCHAIN_FILE=${{github.workspace}}/rdkservices/Tests/gcc-with-coverage.cmake" >> $GITHUB_ENV + + - name: Build mocks + run: > + cmake + -S "${{github.workspace}}/rdkservices/Tests/mocks" + -B build/mocks + -DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}" + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + -DCMAKE_CXX_FLAGS="-fPIC" + && + cmake --build build/mocks -j8 + && + cmake --install build/mocks + + + - name: Build rdkservices + run: > + cmake + -S "${{github.workspace}}/rdkservices" + -B build/rdkservices + -DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}" + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + -DCMAKE_CXX_FLAGS=" + -DEXCEPTIONS_ENABLE=ON + -fprofile-arcs + -ftest-coverage + -I ${{github.workspace}}/rdkservices/Tests/headers + -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/ds + -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/iarmbus + -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/iarmmgrs-hal + -I ${{github.workspace}}/rdkservices/Tests/headers/systemservices + -I ${{github.workspace}}/rdkservices/Tests/headers/systemservices/proc + -include ${{github.workspace}}/rdkservices/Tests/mocks/devicesettings.h + -include ${{github.workspace}}/rdkservices/Tests/mocks/Iarm.h + -include ${{github.workspace}}/rdkservices/Tests/mocks/Rfc.h + -include ${{github.workspace}}/rdkservices/Tests/mocks/maintenanceMGR.h + -include ${{github.workspace}}/rdkservices/Tests/mocks/pkg.h + -Wall -Werror -Wno-error=format= + -DUSE_IARMBUS + -DENABLE_THERMAL_PROTECTION" + -DCOMCAST_CONFIG=OFF + -DCMAKE_DISABLE_FIND_PACKAGE_DS=ON + -DCMAKE_DISABLE_FIND_PACKAGE_IARMBus=ON + -DCMAKE_DISABLE_FIND_PACKAGE_Udev=ON + -DCMAKE_DISABLE_FIND_PACKAGE_RFC=ON + -DCMAKE_DISABLE_FIND_PACKAGE_RBus=ON + -DPLUGIN_SYSTEMSERVICES=ON + -DPLUGIN_L2Tests=ON + -DRDK_SERVICE_L2_TEST=ON + -DDS_FOUND=ON + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + && + cmake --build build/rdkservices -j8 + && + cmake --install build/rdkservices + + - name: Set up files + run: > + sudo mkdir -p -m 777 + /opt/persistent + /opt/secure + /opt/secure/reboot + /opt/secure/persistent + /opt/secure/persistent/System + /opt/logs + /lib/rdk + /run/media/sda1/logs/PreviousLogs + /run/sda1/UsbTestFWUpdate + /run/sda1/UsbProdFWUpdate + /run/sda2 + && + sudo touch + /opt/standbyReason.txt + /opt/tmtryoptout + /opt/fwdnldstatus.txt + /opt/dcm.properties + /etc/device.properties + /etc/dcm.properties + /etc/authService.conf + /version.txt + /run/media/sda1/logs/PreviousLogs/logFile.txt + /run/sda1/HSTP11MWR_5.11p5s1_VBN_sdy.bin + /run/sda1/UsbTestFWUpdate/HSTP11MWR_3.11p5s1_VBN_sdy.bin + /run/sda1/UsbProdFWUpdate/HSTP11MWR_4.11p5s1_VBN_sdy.bin + /lib/rdk/getMaintenanceStartTime.sh + /tmp/opkg.conf + /tmp/system_service_temp.conf + && + sudo chmod 777 + /opt/standbyReason.txt + /opt/tmtryoptout + /opt/fwdnldstatus.txt + /opt/dcm.properties + /etc/device.properties + /etc/dcm.properties + /etc/authService.conf + /version.txt + /lib/rdk/getMaintenanceStartTime.sh + /tmp/opkg.conf + /tmp/system_service_temp.conf + + - name: Run unit tests without valgrind + run: > + PATH=${{github.workspace}}/install/usr/bin:${PATH} + LD_LIBRARY_PATH=${{github.workspace}}/install/usr/lib:${{github.workspace}}/install/usr/lib/wpeframework/plugins:${LD_LIBRARY_PATH} + RdkServicesL2Test + + - name: Run unit tests with valgrind + if: ${{ !env.ACT }} + run: > + PATH=${{github.workspace}}/install/usr/bin:${PATH} + LD_LIBRARY_PATH=${{github.workspace}}/install/usr/lib:${{github.workspace}}/install/usr/lib/wpeframework/plugins:${LD_LIBRARY_PATH} + valgrind + --tool=memcheck + --log-file=valgrind_log + --leak-check=yes + --show-reachable=yes + --track-fds=yes + --fair-sched=try + RdkServicesL2Test + + - name: Generate coverage + if: ${{ matrix.coverage == 'with-coverage' && !env.ACT }} + run: > + lcov -c + -o coverage.info + -d build/rdkservices + && + lcov + -r coverage.info + '/usr/include/*' + '*/build/rdkservices/_deps/*' + '*/install/usr/include/*' + '*/Tests/headers/*' + '*/Tests/mocks/*' + '*/Tests/L2Tests/*' + -o filtered_coverage.info + && + genhtml + -o coverage + -t "rdkservices coverage" + filtered_coverage.info + + - name: Upload artifacts + if: ${{ !env.ACT }} + uses: actions/upload-artifact@v3 + with: + name: artifacts + path: | + coverage/ + valgrind_log + if-no-files-found: warn diff --git a/CMakeLists.txt b/CMakeLists.txt index fd8fdadc0c..0c7fb082c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,10 @@ find_package(WPEFramework) # are located in the cmake directory. Include it in the search. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/") +if(RDK_SERVICE_L2_TEST) + include(l2tests.cmake) +endif() + option(COMCAST_CONFIG "Comcast services configuration" ON) if(COMCAST_CONFIG) include(services.cmake) @@ -32,8 +36,8 @@ endif() option(PLUGIN_OCICONTAINER "Include OCIContainer plugin" OFF) -if(RDK_SERVICES_TEST) - include(tests.cmake) +if(RDK_SERVICES_L1_TEST) + include(l1tests.cmake) endif() # Library installation section @@ -79,6 +83,11 @@ if(PLUGIN_SYSTEMSERVICES) add_subdirectory(SystemServices) endif() +if(RDK_SERVICE_L2_TEST) + add_subdirectory(Tests/L2Tests/L2TestsPlugin) + add_subdirectory(Tests/L2Tests) +endif() + if(PLUGIN_MAINTENANCEMANAGER) add_subdirectory(MaintenanceManager) endif() @@ -352,8 +361,8 @@ if(PLUGIN_RUSTADAPTER) add_subdirectory(RustAdapter) endif() -if(RDK_SERVICES_TEST) - add_subdirectory(Tests) +if(RDK_SERVICES_L1_TEST) + add_subdirectory(Tests/L1Tests) endif() if(PLUGIN_PERFORMANCEMETRICS) diff --git a/ControlService/CMakeLists.txt b/ControlService/CMakeLists.txt index 82bb0e12a2..a9c46487de 100644 --- a/ControlService/CMakeLists.txt +++ b/ControlService/CMakeLists.txt @@ -22,7 +22,7 @@ find_package(${NAMESPACE}Plugins REQUIRED) set(PLUGIN_CONTROLSERVICE_STARTUPORDER "" CACHE STRING "To configure startup order of ControlService plugin") -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) #add_subdirectory(test) endif () diff --git a/DataCapture/CMakeLists.txt b/DataCapture/CMakeLists.txt index 01fdfb7a43..cc1f0f63f2 100644 --- a/DataCapture/CMakeLists.txt +++ b/DataCapture/CMakeLists.txt @@ -31,7 +31,7 @@ set_target_properties(${MODULE_NAME} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_compile_options(${MODULE_NAME} PRIVATE -Wno-error) endif () diff --git a/FrameRate/CMakeLists.txt b/FrameRate/CMakeLists.txt index cd7c3aafca..5d0de00e94 100644 --- a/FrameRate/CMakeLists.txt +++ b/FrameRate/CMakeLists.txt @@ -32,7 +32,7 @@ set_target_properties(${MODULE_NAME} PROPERTIES target_compile_definitions(${MODULE_NAME} PRIVATE MODULE_NAME=Plugin_${PLUGIN_NAME}) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_compile_options(${MODULE_NAME} PRIVATE -Wno-error) endif () diff --git a/HdmiCec/CMakeLists.txt b/HdmiCec/CMakeLists.txt index 34c0577562..52474a6004 100644 --- a/HdmiCec/CMakeLists.txt +++ b/HdmiCec/CMakeLists.txt @@ -42,7 +42,7 @@ target_include_directories(${MODULE_NAME} PRIVATE ${DS_INCLUDE_DIRS}) target_link_libraries(${MODULE_NAME} PUBLIC ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES} ${CEC_LIBRARIES} ${DS_LIBRARIES} ) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_compile_options(${MODULE_NAME} PRIVATE -Wno-error=deprecated) endif () diff --git a/HdmiCecSink/CMakeLists.txt b/HdmiCecSink/CMakeLists.txt index 09b2d03f1a..3946425167 100644 --- a/HdmiCecSink/CMakeLists.txt +++ b/HdmiCecSink/CMakeLists.txt @@ -42,7 +42,7 @@ set_source_files_properties(HdmiCecSink.cpp PROPERTIES COMPILE_FLAGS "-fexceptio target_link_libraries(${MODULE_NAME} PUBLIC ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES} ${CEC_LIBRARIES} ${DS_LIBRARIES} ) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_compile_options(${MODULE_NAME} PRIVATE -Wno-error=deprecated) endif () diff --git a/HdmiCecSource/CMakeLists.txt b/HdmiCecSource/CMakeLists.txt index daabbee3e4..efaa3a1581 100644 --- a/HdmiCecSource/CMakeLists.txt +++ b/HdmiCecSource/CMakeLists.txt @@ -40,7 +40,7 @@ target_include_directories(${MODULE_NAME} PRIVATE ${DS_INCLUDE_DIRS}) target_link_libraries(${MODULE_NAME} PUBLIC ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES} ${CEC_LIBRARIES} ${DS_LIBRARIES} ) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_compile_options(${MODULE_NAME} PRIVATE -Wno-error=deprecated) endif () diff --git a/HdmiCec_2/CMakeLists.txt b/HdmiCec_2/CMakeLists.txt index 666a1e2b99..4ffdc96d89 100644 --- a/HdmiCec_2/CMakeLists.txt +++ b/HdmiCec_2/CMakeLists.txt @@ -40,7 +40,7 @@ target_include_directories(${MODULE_NAME} PRIVATE ${DS_INCLUDE_DIRS}) target_link_libraries(${MODULE_NAME} PUBLIC ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES} ${CEC_LIBRARIES} ${DS_LIBRARIES} ) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_compile_options(${MODULE_NAME} PRIVATE -Wno-error=deprecated) endif () diff --git a/Miracast/MiracastService/MiracastService.cpp b/Miracast/MiracastService/MiracastService.cpp index 8d863475c2..ac5f976f19 100644 --- a/Miracast/MiracastService/MiracastService.cpp +++ b/Miracast/MiracastService/MiracastService.cpp @@ -940,7 +940,7 @@ namespace WPEFramework { std::string friendlyName = ""; friendlyName = Result["friendlyName"].String(); - m_miracast_ctrler_obj->set_FriendlyName(friendlyName); + m_miracast_ctrler_obj->set_FriendlyName(friendlyName,m_isServiceEnabled); MIRACASTLOG_INFO("Miracast FriendlyName=%s", friendlyName.c_str()); return_value = true; } diff --git a/MotionDetection/CMakeLists.txt b/MotionDetection/CMakeLists.txt index bb6fbd52b5..4a6fbe3a44 100644 --- a/MotionDetection/CMakeLists.txt +++ b/MotionDetection/CMakeLists.txt @@ -33,11 +33,11 @@ set_target_properties(${MODULE_NAME} PROPERTIES target_include_directories(${MODULE_NAME} PRIVATE ../helpers) set_source_files_properties(MotionDetection.cpp PROPERTIES COMPILE_FLAGS "-fexceptions") -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins md-hal) -else(RDK_SERVICES_TEST) +else(RDK_SERVICES_L1_TEST) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins) -endif(RDK_SERVICES_TEST) +endif(RDK_SERVICES_L1_TEST) install(TARGETS ${MODULE_NAME} DESTINATION lib/${STORAGE_DIRECTORY}/plugins) diff --git a/NetworkManager/service/CMakeLists.txt b/NetworkManager/service/CMakeLists.txt index d2d9fc5c7d..f7a37d1fdb 100644 --- a/NetworkManager/service/CMakeLists.txt +++ b/NetworkManager/service/CMakeLists.txt @@ -78,7 +78,7 @@ add_library(${PLUGIN_IMPLEMENTATION} SHARED ) if(ENABLE_GNOME_NETWORKMANAGER) - target_sources(${PLUGIN_IMPLEMENTATION} PRIVATE NetworkManagerGnomeProxy.cpp) + target_sources(${PLUGIN_IMPLEMENTATION} PRIVATE NetworkManagerGnomeProxy.cpp NetworkManagerGnomeWIFI.cpp) target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBNM_INCLUDE_DIRS}) target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE ${LIBNM_LIBRARIES}) else() diff --git a/NetworkManager/service/NetworkConnectivity.h b/NetworkManager/service/NetworkConnectivity.h index 9e9d0d7d4b..59f319611b 100644 --- a/NetworkManager/service/NetworkConnectivity.h +++ b/NetworkManager/service/NetworkConnectivity.h @@ -7,8 +7,8 @@ #include #include #include -#include "NetworkManagerLogger.h" #include "Module.h" +#include "NetworkManagerLogger.h" #include "NetworkManagerImplementation.h" #define CAPTIVEPORTAL_MAX_LEN 512 diff --git a/NetworkManager/service/NetworkManagerGnomeProxy.cpp b/NetworkManager/service/NetworkManagerGnomeProxy.cpp index 5111cdb467..fad3b0570c 100755 --- a/NetworkManager/service/NetworkManagerGnomeProxy.cpp +++ b/NetworkManager/service/NetworkManagerGnomeProxy.cpp @@ -1,4 +1,5 @@ #include "NetworkManagerImplementation.h" +#include "NetworkManagerGnomeWIFI.h" #include #include #include @@ -15,6 +16,7 @@ namespace WPEFramework { namespace Plugin { + wifiManager *wifi = nullptr; const float signalStrengthThresholdExcellent = -50.0f; const float signalStrengthThresholdGood = -60.0f; const float signalStrengthThresholdFair = -67.0f; @@ -37,6 +39,7 @@ namespace WPEFramework return; } g_loop = g_main_loop_new(context, FALSE); + wifi = wifiManager::getInstance(); return; } @@ -608,18 +611,24 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::WiFiConnect(const WiFiConnectTo& ssid /* @in */) { uint32_t rc = Core::ERROR_RPC_CALL_FAILED; + if(wifi->wifiConnect(ssid.m_ssid.c_str(), ssid.m_passphrase.c_str(), ssid.m_securityMode)) + rc = Core::ERROR_NONE; return rc; } uint32_t NetworkManagerImplementation::WiFiDisconnect(void) { uint32_t rc = Core::ERROR_RPC_CALL_FAILED; + if(wifi->wifiDisconnect()) + rc = Core::ERROR_NONE; return rc; } uint32_t NetworkManagerImplementation::GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) { uint32_t rc = Core::ERROR_RPC_CALL_FAILED; + if(wifi->wifiConnectedSSIDInfo(ssidInfo)) + rc = Core::ERROR_NONE; return rc; } diff --git a/NetworkManager/service/NetworkManagerGnomeWIFI.cpp b/NetworkManager/service/NetworkManagerGnomeWIFI.cpp new file mode 100644 index 0000000000..a52d9e4b8c --- /dev/null +++ b/NetworkManager/service/NetworkManagerGnomeWIFI.cpp @@ -0,0 +1,727 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include +#include +#include +#include "NetworkManagerLogger.h" +#include "INetworkManager.h" +#include "NetworkManagerGnomeWIFI.h" + +namespace WPEFramework +{ + namespace Plugin + { + NMDevice* wifiManager::getNmDevice() + { + NMDevice *wifiDevice = NULL; + + GPtrArray *devices = const_cast(nm_client_get_devices(client)); + if (devices == NULL) { + NMLOG_ERROR("Failed to get device list."); + return wifiDevice; + } + + for (guint j = 0; j < devices->len; j++) { + NMDevice *device = NM_DEVICE(devices->pdata[j]); + if (nm_device_get_device_type(device) == NM_DEVICE_TYPE_WIFI) + { + wifiDevice = device; + //NMLOG_TRACE("Wireless Device found ifce : %s !", nm_device_get_iface (wifiDevice)); + break; + } + } + + if (wifiDevice == NULL || !NM_IS_DEVICE_WIFI(wifiDevice)) + { + NMLOG_ERROR("Wireless Device not found !"); + } + + return wifiDevice; + } + + /* Convert flags to string */ + static void apFlagsToString(guint32 flags, std::string &flagStr) + { + + flagStr = ""; + + if (flags & NM_802_11_AP_SEC_PAIR_WEP40) + flagStr += "pair_wpe40 "; + if (flags & NM_802_11_AP_SEC_PAIR_WEP104) + flagStr += "pair_wpe104 "; + if (flags & NM_802_11_AP_SEC_PAIR_TKIP) + flagStr += "pair_tkip "; + if (flags & NM_802_11_AP_SEC_PAIR_CCMP) + flagStr += "pair_ccmp "; + if (flags & NM_802_11_AP_SEC_GROUP_WEP40) + flagStr += "group_wpe40 "; + if (flags & NM_802_11_AP_SEC_GROUP_WEP104) + flagStr += "group_wpe104 "; + if (flags & NM_802_11_AP_SEC_GROUP_TKIP) + flagStr += "group_tkip "; + if (flags & NM_802_11_AP_SEC_GROUP_CCMP) + flagStr += "group_ccmp "; + if (flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) + flagStr += "psk "; + if (flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) + flagStr += "802.1X "; + if (flags & NM_802_11_AP_SEC_KEY_MGMT_SAE) + flagStr += "sae "; + if (flags & NM_802_11_AP_SEC_KEY_MGMT_OWE) + flagStr += "owe " ; + if (flags & NM_802_11_AP_SEC_KEY_MGMT_OWE_TM) + flagStr += "owe_transition_mode "; + if (flags & NM_802_11_AP_SEC_KEY_MGMT_EAP_SUITE_B_192) + flagStr += "wpa-eap-suite-b-192 "; + + if (flagStr.size() <= 0) + flagStr = "none"; + } + + bool static getConnectedSSID(NMDeviceWifi *wifiDevice, std::string& ssidin) + { + GBytes *ssid; + NMAccessPoint *activeAP = nm_device_wifi_get_active_access_point(wifiDevice); + if(activeAP == NULL) { + return false; + } + + ssid = nm_access_point_get_ssid(activeAP); + gsize size; + const guint8 *ssidData = static_cast(g_bytes_get_data(ssid, &size)); + std::string ssidTmp(reinterpret_cast(ssidData), size); + ssidin = ssidTmp; + NMLOG_INFO("connected ssid: %s", ssidin.c_str()); + return true; + } + + static void getApInfo(NMAccessPoint *AccessPoint, Exchange::INetworkManager::WiFiSSIDInfo &wifiInfo) + { + guint32 flags, wpaFlags, rsnFlags, freq, bitrate; + guint8 strength; + GBytes *ssid; + const char *hwaddr; + NM80211Mode mode; + /* Get AP properties */ + flags = nm_access_point_get_flags(AccessPoint); + wpaFlags = nm_access_point_get_wpa_flags(AccessPoint); + rsnFlags = nm_access_point_get_rsn_flags(AccessPoint); + ssid = nm_access_point_get_ssid(AccessPoint); + hwaddr = nm_access_point_get_bssid(AccessPoint); + freq = nm_access_point_get_frequency(AccessPoint); + mode = nm_access_point_get_mode(AccessPoint); + bitrate = nm_access_point_get_max_bitrate(AccessPoint); + strength = nm_access_point_get_strength(AccessPoint); + + switch(flags) + { + case NM_802_11_AP_FLAGS_NONE: + NMLOG_INFO("ap type : point has no special capabilities"); + break; + case NM_802_11_AP_FLAGS_PRIVACY: + NMLOG_INFO("ap type : access point requires authentication and encryption"); + break; + case NM_802_11_AP_FLAGS_WPS: + NMLOG_INFO("ap type : access point supports some WPS method"); + break; + case NM_802_11_AP_FLAGS_WPS_PBC: + NMLOG_INFO("ap type : access point supports push-button WPS"); + break; + case NM_802_11_AP_FLAGS_WPS_PIN: + NMLOG_INFO("ap type : access point supports PIN-based WPS"); + break; + default: + NMLOG_ERROR("ap type : 802.11 flags unknown!"); + } + + /* Convert to strings */ + if (ssid) { + gsize size; + const guint8 *ssidData = static_cast(g_bytes_get_data(ssid, &size)); + std::string ssidTmp(reinterpret_cast(ssidData), size); + wifiInfo.m_ssid = ssidTmp; + NMLOG_INFO("ssid: %s", wifiInfo.m_ssid.c_str()); + } + else + { + wifiInfo.m_ssid = "-----"; + NMLOG_TRACE("ssid: %s", wifiInfo.m_ssid.c_str()); + } + + wifiInfo.m_bssid = (hwaddr != nullptr) ? hwaddr : "-----"; + NMLOG_INFO("bssid: %s", wifiInfo.m_bssid.c_str()); + + + if (freq >= 2400 && freq < 5000) { + wifiInfo.m_frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_2_4_GHZ; + NMLOG_INFO("freq: WIFI_FREQUENCY_2_4_GHZ"); + } + else if (freq >= 5000 && freq < 6000) { + wifiInfo.m_frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_5_GHZ; + NMLOG_INFO("freq: WIFI_FREQUENCY_5_GHZ"); + } + else if (freq >= 6000) { + wifiInfo.m_frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_6_GHZ; + NMLOG_INFO("freq: WIFI_FREQUENCY_6_GHZ"); + } + else { + wifiInfo.m_frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_WHATEVER; + NMLOG_INFO("freq: No available !"); + } + + wifiInfo.m_rate = std::to_string(bitrate); + NMLOG_INFO("bitrate : %s kbit/s", wifiInfo.m_rate.c_str()); + + wifiInfo.m_signalStrength = std::to_string(static_cast(strength)); + NMLOG_INFO("sterngth: %s %%", wifiInfo.m_signalStrength.c_str()); + //TODO signal strenght to dBm + + std::string security_str = ""; + if ((flags == NM_802_11_AP_FLAGS_NONE) && (wpaFlags == NM_802_11_AP_SEC_NONE) && (rsnFlags == NM_802_11_AP_SEC_NONE)) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_NONE; + } + else if( (flags & NM_802_11_AP_FLAGS_PRIVACY) && ((wpaFlags & NM_802_11_AP_SEC_PAIR_WEP40) || (rsnFlags & NM_802_11_AP_SEC_PAIR_WEP40)) ) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WEP_64; + } + else if( (flags & NM_802_11_AP_FLAGS_PRIVACY) && ((wpaFlags & NM_802_11_AP_SEC_PAIR_WEP104) || (rsnFlags & NM_802_11_AP_SEC_PAIR_WEP104)) ) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WEP_128; + } + else if((wpaFlags & NM_802_11_AP_SEC_PAIR_TKIP) || (rsnFlags & NM_802_11_AP_SEC_PAIR_TKIP)) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_TKIP; + } + else if((wpaFlags & NM_802_11_AP_SEC_PAIR_CCMP) || (rsnFlags & NM_802_11_AP_SEC_PAIR_CCMP)) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_AES; + } + else if ((rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_PSK) && (rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_WPA2_ENTERPRISE; + } + else if(rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_PSK) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_WPA2_PSK; + } + else if((wpaFlags & NM_802_11_AP_SEC_GROUP_CCMP) || (rsnFlags & NM_802_11_AP_SEC_GROUP_CCMP)) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA2_PSK_AES; + } + else if((wpaFlags & NM_802_11_AP_SEC_GROUP_TKIP) || (rsnFlags & NM_802_11_AP_SEC_GROUP_TKIP)) + { + wifiInfo.m_securityMode = Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA2_PSK_TKIP; + } + else + { + NMLOG_WARNING("security mode not defined"); + } + + if (!(flags & NM_802_11_AP_FLAGS_PRIVACY) && (wpaFlags != NM_802_11_AP_SEC_NONE) && (rsnFlags != NM_802_11_AP_SEC_NONE)) + security_str += ("Encrypted: "); + + if ((flags & NM_802_11_AP_FLAGS_PRIVACY) && (wpaFlags == NM_802_11_AP_SEC_NONE) + && (rsnFlags == NM_802_11_AP_SEC_NONE)) + security_str += ("WEP "); + if (wpaFlags != NM_802_11_AP_SEC_NONE) + security_str += ("WPA "); + if ((rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_PSK) + || (rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { + security_str += ("WPA2 "); + } + if (rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_SAE) { + security_str += ("WPA3 "); + } + if ((rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_OWE) + || (rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_OWE_TM)) { + security_str += ("OWE "); + } + if ((wpaFlags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) + || (rsnFlags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { + security_str += ("802.1X "); + } + + NMLOG_INFO("security: %s", (security_str.size() > 0)? security_str.c_str(): "none"); + std::string flagStr; + apFlagsToString(wpaFlags, flagStr); + apFlagsToString(rsnFlags, flagStr); + NMLOG_INFO("WPA flags: %s", flagStr.c_str()); + NMLOG_INFO("RSN flags: %s", flagStr.c_str()); + NMLOG_TRACE("D-Bus path: %s", nm_object_get_path(NM_OBJECT(AccessPoint))); + NMLOG_INFO("Mode: %s", mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc": mode == NM_802_11_MODE_INFRA ? "Infrastructure": "Unknown"); + } + + bool wifiManager::isWifiConnected() + { + if(!createClientNewConnection()) + return false; + + NMDeviceWifi *wifiDevice = NM_DEVICE_WIFI(getNmDevice()); + if(wifiDevice == NULL) { + NMLOG_TRACE("NMDeviceWifi * NULL !"); + return false; + } + + NMAccessPoint *activeAP = nm_device_wifi_get_active_access_point(wifiDevice); + if(activeAP == NULL) { + NMLOG_ERROR("No active access point found !"); + return false; + } + else + NMLOG_TRACE("active access point found !"); + return true; + } + + bool wifiManager::wifiConnectedSSIDInfo(Exchange::INetworkManager::WiFiSSIDInfo &ssidinfo) + { + if(!createClientNewConnection()) + return false; + + NMDeviceWifi *wifiDevice = NM_DEVICE_WIFI(getNmDevice()); + if(wifiDevice == NULL) { + NMLOG_TRACE("NMDeviceWifi * NULL !"); + return false; + } + + NMAccessPoint *activeAP = nm_device_wifi_get_active_access_point(wifiDevice); + if(activeAP == NULL) { + NMLOG_ERROR("No active access point found !"); + return false; + } + else + NMLOG_TRACE("active access point found !"); + + getApInfo(activeAP, ssidinfo); + return true; + } + + static void wifiDisconnectCb(GObject *object, GAsyncResult *result, gpointer user_data) + { + NMDevice *device = NM_DEVICE(object); + GError *error = NULL; + wifiManager *_wifiManager = (static_cast(user_data)); + + NMLOG_TRACE("Disconnecting... "); + if (!nm_device_disconnect_finish(device, result, &error)) { + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + return; + + NMLOG_ERROR("Device '%s' (%s) disconnecting failed: %s", + nm_device_get_iface(device), + nm_object_get_path(NM_OBJECT(device)), + error->message); + g_error_free(error); + _wifiManager->quit(device); + } + } + + void static disconnectGsignalCb(NMDevice *device, GParamSpec *pspec, wifiManager *info) + { + if(NM_IS_DEVICE_WIFI(device)) + { + NMDeviceState state = nm_device_get_state(device); + switch(state) + { + case NM_DEVICE_STATE_DEACTIVATING: + NMLOG_INFO("Device '%s' successfully disconnecting", nm_device_get_iface(device)); + break; + case NM_DEVICE_STATE_DISCONNECTED: + NMLOG_INFO("Device '%s' successfully disconnected", nm_device_get_iface(device)); + info->quit(device); + break; + case NM_DEVICE_STATE_ACTIVATED: + NMLOG_INFO("Device '%s' successfully connected", nm_device_get_iface(device)); + info->quit(device); + case NM_DEVICE_STATE_FAILED: + NMLOG_INFO("Device '%s' Failed state", nm_device_get_iface(device)); + break; + default: + NMLOG_TRACE("Device state unknown"); + } + } + } + + static void connectGsignalCb(NMDevice *device, GParamSpec *pspec, wifiManager *info) + { + if(NM_IS_DEVICE_WIFI(device)) + { + NMDeviceState state = nm_device_get_state(device); + switch(state) + { + case NM_DEVICE_STATE_DEACTIVATING: + NMLOG_INFO("Device disconnecting"); + break; + case NM_DEVICE_STATE_DISCONNECTED: + NMLOG_INFO("Device '%s' successfully disconnected", nm_device_get_iface(device)); + break; + case NM_DEVICE_STATE_ACTIVATED: + NMLOG_INFO("Device '%s' successfully connected", nm_device_get_iface(device)); + info->quit(device); + case NM_DEVICE_STATE_FAILED: + //NMLOG_INFO("Device '%s' Failed state", nm_device_get_iface(device)); + default: + break; + } + } + } + + bool wifiManager::wifiDisconnect() + { + if(!createClientNewConnection()) + return false; + + NMDevice *wifiNMDevice = getNmDevice(); + if(wifiNMDevice == NULL) { + NMLOG_TRACE("NMDeviceWifi NULL !"); + return false; + } + + wifiDeviceStateGsignal = g_signal_connect(wifiNMDevice, "notify::" NM_DEVICE_STATE, G_CALLBACK(disconnectGsignalCb), this); + nm_device_disconnect_async(wifiNMDevice, NULL, wifiDisconnectCb, this); + wait(loop); + NMLOG_TRACE("Exit"); + return true; + } + + bool wifiManager::quit(NMDevice *wifiNMDevice) + { + if (wifiNMDevice && wifiDeviceStateGsignal > 0) { + g_signal_handler_disconnect(wifiNMDevice, wifiDeviceStateGsignal); + wifiDeviceStateGsignal = 0; + } + + if(!g_main_loop_is_running(loop)) { + NMLOG_ERROR("g_main_loop_is not running"); + return false; + } + + g_main_loop_quit(loop); + return false; + } + + bool wifiManager::wait(GMainLoop *loop) + { + if(g_main_loop_is_running(loop)) { + NMLOG_WARNING("g_main_loop_is running"); + return false; + } + g_main_loop_run(loop); + return true; + } + + static NMAccessPoint *checkSSIDAvailable(NMDevice *device, const GPtrArray *aps, const char *ssid) + { + NMAccessPoint *AccessPoint = NULL; + aps = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(device)); + for (guint i = 0; i < aps->len; i++) + { + NMAccessPoint *candidate_ap = static_cast(g_ptr_array_index(aps, i)); + if (ssid) + { + GBytes *ssidGBytes; + ssidGBytes = nm_access_point_get_ssid(candidate_ap); + if (!ssidGBytes) + continue; + gsize size; + const guint8 *ssidData = static_cast(g_bytes_get_data(ssidGBytes, &size)); + std::string ssidstr(reinterpret_cast(ssidData), size); + //g_bytes_unref(ssidGBytes); + NMLOG_TRACE("ssid < %s >", ssidstr.c_str()); + if (strcmp(ssid, ssidstr.c_str()) == 0) + { + AccessPoint = candidate_ap; + break; + } + } + } + + return AccessPoint; + } + + static void wifiConnectCb(GObject *client, GAsyncResult *result, gpointer user_data) + { + GError *error = NULL; + wifiManager *_wifiManager = (static_cast(user_data)); + + if (_wifiManager->createNewConnection) { + NMLOG_TRACE("nm_client_add_and_activate_connection_finish"); + nm_client_add_and_activate_connection_finish(NM_CLIENT(_wifiManager->client), result, &error); + } + else { + NMLOG_TRACE("nm_client_activate_connection_finish "); + nm_client_activate_connection_finish(NM_CLIENT(_wifiManager->client), result, &error); + } + + if (error) { + if (_wifiManager->createNewConnection) { + NMLOG_ERROR("Failed to add/activate new connection: %s", error->message); + } else { + NMLOG_ERROR("Failed to activate connection: %s", error->message); + } + g_main_loop_quit(_wifiManager->loop); + } + } + + static void wifiConnectionUpdate(GObject *source_object, GAsyncResult *res, gpointer user_data) + { + NMRemoteConnection *remote_con = NM_REMOTE_CONNECTION(source_object); + wifiManager *_wifiManager = (static_cast(user_data)); + GVariant *ret = NULL; + GError *error = NULL; + + ret = nm_remote_connection_update2_finish(remote_con, res, &error); + + if (!ret) { + NMLOG_ERROR("Error: %s.", error->message); + g_error_free(error); + _wifiManager->quit(NULL); + return; + } + _wifiManager->createNewConnection = false; // no need to create new connection + nm_client_activate_connection_async( + _wifiManager->client, NM_CONNECTION(remote_con), _wifiManager->wifidevice, _wifiManager->objectPath, NULL, wifiConnectCb, _wifiManager); + } + + bool wifiManager::createClientNewConnection() + { + GError *error = NULL; + if(client != nullptr) + { + g_object_unref(client); + client = nullptr; + } + + client = nm_client_new(NULL, &error); + if (!client || !loop) { + NMLOG_ERROR("Could not connect to NetworkManager: %s.", error->message); + g_error_free(error); + return false; + } + return true; + } + + bool wifiManager::wifiConnect(const char *ssid_in, const char* password_in, Exchange::INetworkManager::WIFISecurityMode security_in) + { + NMAccessPoint *AccessPoint = NULL; + GPtrArray *allaps = NULL; + const char *conName = ssid_in; + NMConnection *connection = NULL; + NMSettingConnection *s_con; + NMSettingWireless *s_wireless = NULL; + NMSettingWirelessSecurity *s_secure = NULL; + NM80211ApFlags apFlags; + NM80211ApSecurityFlags apWpaFlags; + NM80211ApSecurityFlags apRsnFlags; + const char *ifname = NULL; + const GPtrArray *availableConnections; + bool SSIDmatch = false; + Exchange::INetworkManager::WiFiSSIDInfo apinfo; + + if(!createClientNewConnection()) + return false; + + if (strlen(ssid_in) > 32) + { + NMLOG_WARNING("ssid length grater than 32"); + return false; + } + + NMDevice *device = NULL; + device = getNmDevice(); + if(device == NULL) + return false; + wifidevice = device; + + std::string activeSSID; + if(getConnectedSSID(NM_DEVICE_WIFI(wifidevice), activeSSID)) + { + if(strcmp(ssid_in, activeSSID.c_str()) == 0) + { + NMLOG_WARNING("ssid already connected !"); + return true; + } + else + { + NMLOG_WARNING("wifi already connected with %s AP", activeSSID.c_str()); + } + } + //NMLOG_TRACE("Wireless Device found ifce : %s !", ifname = nm_device_get_iface(device)); + AccessPoint = checkSSIDAvailable(device, allaps, ssid_in); + // TODO Scann hidden ssid also for lnf + if(AccessPoint == NULL) { + NMLOG_WARNING("No network with SSID '%s' found !", ssid_in); + return false; + } + + getApInfo(AccessPoint, apinfo); + + availableConnections = nm_device_get_available_connections(device); + for (guint i = 0; i < availableConnections->len; i++) + { + NMConnection *currentConnection = static_cast(g_ptr_array_index(availableConnections, i)); + const char *id = nm_connection_get_id(NM_CONNECTION(currentConnection)); + + if (conName) { + if (!id || strcmp(id, conName)) + continue; + + SSIDmatch = TRUE; + } + + if (nm_access_point_connection_valid(AccessPoint, NM_CONNECTION(currentConnection))) { + connection = g_object_ref(currentConnection); + NMLOG_INFO("Connection '%s' exists !", conName); + break; + } + } + + if (SSIDmatch && !connection) + { + NMLOG_ERROR("Connection '%s' exists but properties don't match.", conName); + //TODO Remove Connection + return false; + } + + if (!connection) + { + NMLOG_TRACE("creating new connection '%s' .", conName); + connection = nm_simple_connection_new(); + if (conName) { + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + const char *uuid = nm_utils_uuid_generate();; + + g_object_set(G_OBJECT(s_con), + NM_SETTING_CONNECTION_UUID, + uuid, + NM_SETTING_CONNECTION_ID, + conName, + NM_SETTING_CONNECTION_TYPE, + "802-11-wireless", + NULL); + } + + s_wireless = (NMSettingWireless *)nm_setting_wireless_new(); + GBytes *ssid = g_bytes_new(ssid_in, strlen(ssid_in)); + g_object_set(G_OBJECT(s_wireless), + NM_SETTING_WIRELESS_SSID, + ssid, + NULL); + //g_bytes_unref(ssid); + /* For lnf network need to include + * + * 'bssid' parameter is used to restrict the connection only to the BSSID + * g_object_set(s_wifi, NM_SETTING_WIRELESS_BSSID, bssid, NULL); + * g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_HIDDEN, hidden, NULL); + */ + nm_connection_add_setting(connection, NM_SETTING(s_wireless)); + } + + apFlags = nm_access_point_get_flags(AccessPoint); + apWpaFlags = nm_access_point_get_wpa_flags(AccessPoint); + apRsnFlags = nm_access_point_get_rsn_flags(AccessPoint); + + // check ap flag ty securti we supporting + if(apFlags != NM_802_11_AP_FLAGS_NONE && strlen(password_in) < 1 ) + { + NMLOG_ERROR("This ap(%s) security need password please add password!", ssid_in); + return false; + } + + if ( (apRsnFlags & NM_802_11_AP_SEC_KEY_MGMT_OWE) || (apRsnFlags & NM_802_11_AP_SEC_KEY_MGMT_OWE_TM) + || (apWpaFlags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)|| (apRsnFlags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) ) { + + NMLOG_ERROR("Ap wifi security OWE and 802 1X mode not supported"); + return false; + } + + if ((apFlags & NM_802_11_AP_FLAGS_PRIVACY) || (apWpaFlags != NM_802_11_AP_SEC_NONE )|| (apRsnFlags != NM_802_11_AP_SEC_NONE )) + { + std::string flagStr; + apFlagsToString(apWpaFlags, flagStr); + apFlagsToString(apRsnFlags, flagStr); + NMLOG_INFO("%s ap securtity mode ( %s) supported !", ssid_in, flagStr.c_str()); + + if (password_in) + { + s_secure = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_secure)); + + if (apWpaFlags == NM_802_11_AP_SEC_NONE && apRsnFlags == NM_802_11_AP_SEC_NONE) + { + nm_setting_wireless_security_set_wep_key(s_secure, 0, password_in); + NMLOG_ERROR("wifi security WEP mode not supported ! need to add wep-key-type"); + return false; + } + else if ((apWpaFlags & NM_802_11_AP_SEC_KEY_MGMT_PSK) + || (apRsnFlags & NM_802_11_AP_SEC_KEY_MGMT_PSK) || (apRsnFlags & NM_802_11_AP_SEC_KEY_MGMT_SAE)) { + + g_object_set(G_OBJECT(s_secure), NM_SETTING_WIRELESS_SECURITY_KEY_MGMT,"wpa-psk", NULL); + g_object_set(G_OBJECT(s_secure), NM_SETTING_WIRELESS_SECURITY_PSK, password_in, NULL); + } + } + else + { + NMLOG_ERROR("This AccessPoint(%s) need password please add password!", ssid_in); + return false; + } + } + else + { + /* for open network every flag value will be zero */ + if (apFlags == NM_802_11_AP_FLAGS_NONE && apWpaFlags == NM_802_11_AP_SEC_NONE && apRsnFlags == NM_802_11_AP_SEC_NONE) { + NMLOG_INFO("open network no password requied"); + } + else { + NMLOG_ERROR("wifi security mode not supported !"); + return false; + } + } + + objectPath = nm_object_get_path(NM_OBJECT(AccessPoint)); + wifiDeviceStateGsignal = g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(connectGsignalCb), this); + GVariant *nmDbusConnection = nm_connection_to_dbus(connection, NM_CONNECTION_SERIALIZE_ALL); + if (NM_IS_REMOTE_CONNECTION(connection)) + { + nm_remote_connection_update2(NM_REMOTE_CONNECTION(connection), + nmDbusConnection, + NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT, // autoconnect right away + NULL, + NULL, + wifiConnectionUpdate, + this); + } + else + { + createNewConnection = true; + nm_client_add_and_activate_connection_async(client, connection, device, objectPath, NULL, wifiConnectCb, this); + } + + wait(loop); + NMLOG_TRACE("Exit"); + return true; + } + } // namespace Plugin +} // namespace WPEFramework diff --git a/NetworkManager/service/NetworkManagerGnomeWIFI.h b/NetworkManager/service/NetworkManagerGnomeWIFI.h new file mode 100644 index 0000000000..e3ce0f3b88 --- /dev/null +++ b/NetworkManager/service/NetworkManagerGnomeWIFI.h @@ -0,0 +1,82 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2020 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include "NetworkManagerLogger.h" +#include "INetworkManager.h" +#include +#include +#include +#include +#include + +namespace WPEFramework +{ + namespace Plugin + { + class wifiManager + { + public: + static wifiManager* getInstance() + { + static wifiManager instance; + return &instance; + } + + bool isWifiConnected(); + bool wifiDisconnect(); + bool wifiConnectedSSIDInfo(Exchange::INetworkManager::WiFiSSIDInfo &ssidinfo); + bool wifiConnect(const char *ssid_in, const char* password_in, Exchange::INetworkManager::WIFISecurityMode security_in); + bool quit(NMDevice *wifiNMDevice); + bool wait(GMainLoop *loop); + private: + NMDevice *getNmDevice(); + + private: + wifiManager() : client(nullptr), loop(nullptr), createNewConnection(false) { + loop = g_main_loop_new(NULL, FALSE); + } + ~wifiManager() { + NMLOG_TRACE("~wifiManager"); + if(client != nullptr) + g_object_unref(client); + if (loop != NULL) { + g_main_loop_unref(loop); + loop = NULL; + } + } + + wifiManager(wifiManager const&) = delete; + void operator=(wifiManager const&) = delete; + + bool createClientNewConnection(); + + public: + NMClient *client; + GMainLoop *loop; + gboolean createNewConnection; + const char* objectPath; + NMDevice *wifidevice; + guint wifiDeviceStateGsignal = 0; + }; + } +} diff --git a/RDKShell/CMakeLists.txt b/RDKShell/CMakeLists.txt index 51ff7f6432..53a05d9927 100755 --- a/RDKShell/CMakeLists.txt +++ b/RDKShell/CMakeLists.txt @@ -80,11 +80,11 @@ set_source_files_properties(RDKShell.cpp PROPERTIES COMPILE_FLAGS "-fexceptions" set(RDKSHELL_INCLUDES $ENV{RDKSHELL_INCLUDES}) separate_arguments(RDKSHELL_INCLUDES) include_directories(BEFORE ${RDKSHELL_INCLUDES}) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins -lrdkshell ${PLUGIN_RDKSHELL_EXTRA_LIBRARIES}) -else(RDK_SERVICES_TEST) +else(RDK_SERVICES_L1_TEST) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${PLUGIN_RDKSHELL_EXTRA_LIBRARIES}) -endif(RDK_SERVICES_TEST) +endif(RDK_SERVICES_L1_TEST) install(TARGETS ${MODULE_NAME} DESTINATION lib/${STORAGE_DIRECTORY}/plugins) diff --git a/RemoteActionMapping/CMakeLists.txt b/RemoteActionMapping/CMakeLists.txt index 5469fc48c3..2d5a3fbf43 100644 --- a/RemoteActionMapping/CMakeLists.txt +++ b/RemoteActionMapping/CMakeLists.txt @@ -22,7 +22,7 @@ set(PLUGIN_REMOTEACTIONMAPPING_STARTUPORDER "" CACHE STRING "To configure startu find_package(${NAMESPACE}Plugins REQUIRED) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) #add_subdirectory(test) endif () diff --git a/ResourceManager/CMakeLists.txt b/ResourceManager/CMakeLists.txt index 8ff8264856..ae0639516f 100644 --- a/ResourceManager/CMakeLists.txt +++ b/ResourceManager/CMakeLists.txt @@ -40,11 +40,11 @@ set_source_files_properties(ResourceManager.cpp PROPERTIES COMPILE_FLAGS "-fexce set(RESOURCE_MANAGER_INCLUDES $ENV{RESOURCE_MANAGER_INCLUDES}) separate_arguments(RESOURCE_MANAGER_INCLUDES) include_directories(BEFORE ${RESOURCE_MANAGER_INCLUDES}) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins -lessosrmgr ${PLUGIN_RESOURCE_MANAGER_EXTRA_LIBRARIES}) -else(RDK_SERVICES_TEST) +else(RDK_SERVICES_L1_TEST) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${PLUGIN_RESOURCE_MANAGER_EXTRA_LIBRARIES}) -endif(RDK_SERVICES_TEST) +endif(RDK_SERVICES_L1_TEST) install(TARGETS ${MODULE_NAME} DESTINATION lib/${STORAGE_DIRECTORY}/plugins) diff --git a/SystemAudioPlayer/CMakeLists.txt b/SystemAudioPlayer/CMakeLists.txt index 7f834b21f2..18b56ddadf 100644 --- a/SystemAudioPlayer/CMakeLists.txt +++ b/SystemAudioPlayer/CMakeLists.txt @@ -67,7 +67,7 @@ elseif (BUILD_BROADCOM) PRIVATE impl/broadcom/SoC_abstraction.cpp ) -elseif (RDK_SERVICES_TEST) +elseif (RDK_SERVICES_L1_TEST) target_sources(${MODULE_NAME} PRIVATE test/SoC_abstraction.cpp diff --git a/SystemServices/CMakeLists.txt b/SystemServices/CMakeLists.txt index 043e37f0a2..1ac1ec0b39 100644 --- a/SystemServices/CMakeLists.txt +++ b/SystemServices/CMakeLists.txt @@ -44,7 +44,7 @@ set_target_properties(${MODULE_NAME} PROPERTIES target_compile_definitions(${MODULE_NAME} PRIVATE MODULE_NAME=Plugin_${PLUGIN_NAME}) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_compile_options(${MODULE_NAME} PRIVATE -Wno-error) endif () @@ -88,6 +88,18 @@ else (RFC_FOUND) message ("RFC lib required.") endif (RFC_FOUND) +if (RDK_SERVICE_L2_TEST) + message ("L2 test Enabled") + find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib) + if (TESTMOCKLIB_LIBRARIES) + message ("linking mock libraries ${TESTMOCKLIB_LIBRARIES} library") + target_link_libraries(${MODULE_NAME} PRIVATE ${TESTMOCKLIB_LIBRARIES}) + else (TESTMOCKLIB_LIBRARIES) + message ("Require ${TESTMOCKLIB_LIBRARIES} library") + endif (TESTMOCKLIB_LIBRARIES) +endif (RDK_SERVICES_L2_TEST) + + target_include_directories(${MODULE_NAME} PRIVATE ../helpers) target_include_directories(${MODULE_NAME} PRIVATE ./) diff --git a/Tests/CMakeLists.txt b/Tests/L1Tests/CMakeLists.txt old mode 100644 new mode 100755 similarity index 51% rename from Tests/CMakeLists.txt rename to Tests/L1Tests/CMakeLists.txt index 6d7a81bdbc..755758be84 --- a/Tests/CMakeLists.txt +++ b/Tests/L1Tests/CMakeLists.txt @@ -16,7 +16,7 @@ # limitations under the License. cmake_minimum_required(VERSION 3.8) -project(RdkServicesTest) +project(RdkServicesL1Test) set(CMAKE_CXX_STANDARD 11) @@ -31,11 +31,19 @@ FetchContent_MakeAvailable(googletest) file(GLOB TESTS tests/*.cpp) add_executable(${PROJECT_NAME} ${TESTS} - mocks/thunder/Module.cpp - mocks/Wraps.cpp - mocks/Dobby.cpp - mocks/rdkshell.cpp - mocks/opkgMock.cpp + ../mocks/Rfc.cpp + ../mocks/Iarm.cpp + ../mocks/RBus.cpp + ../mocks/MotionDetection.cpp + ../mocks/Telemetry.cpp + ../mocks/Udev.cpp + ../mocks/devicesettings.cpp + ../mocks/HdmiCec.cpp + ../mocks/thunder/Module.cpp + ../mocks/Wraps.cpp + ../mocks/Dobby.cpp + ../mocks/rdkshell.cpp + ../mocks/opkgMock.cpp ) set_source_files_properties( @@ -47,85 +55,85 @@ set_source_files_properties( tests/test_HdmiCec2.cpp tests/test_HdmiCecSource.cpp tests/test_FrontPanel.cpp - tests/test_HdmiCecSink.cpp + tests/test_HdmiCecSink.cpp PROPERTIES COMPILE_FLAGS "-fexceptions") -include_directories(../LocationSync - ../SecurityAgent - ../DeviceIdentification - ../DeviceDiagnostics - ../FrameRate - ../AVInput - ../Telemetry - ../ScreenCapture - ../DataCapture - ../UsbAccess - ../Timer - ../LoggingPreferences - ../UserPreferences - ../Messenger - ../DeviceInfo - ../helpers - ../SystemServices - ../HdmiInput - ../HdcpProfile - ../Network - ../WifiManager - ../TraceControl - ../Warehouse - ../ActivityMonitor - ../MotionDetection - ../CompositeInput - ../OCIContainer - ../HdmiCec - ../HdmiCec_2 - ../HdmiCecSource - ../XCast - ../FrontPanel - ../HdmiCecSink - ../RDKShell - ../MaintenanceManager - ../Packager - ../TextToSpeech - ../SystemAudioPlayer +include_directories(../../LocationSync + ../../SecurityAgent + ../../DeviceIdentification + ../../DeviceDiagnostics + ../../FrameRate + ../../AVInput + ../../Telemetry + ../../ScreenCapture + ../../DataCapture + ../../UsbAccess + ../../Timer + ../../LoggingPreferences + ../../UserPreferences + ../../Messenger + ../../DeviceInfo + ../../helpers + ../../SystemServices + ../../HdmiInput + ../../HdcpProfile + ../../Network + ../../WifiManager + ../../TraceControl + ../../Warehouse + ../../ActivityMonitor + ../../MotionDetection + ../../CompositeInput + ../../OCIContainer + ../../HdmiCec + ../../HdmiCec_2 + ../../HdmiCecSource + ../../XCast + ../../FrontPanel + ../../HdmiCecSink + ../../RDKShell + ../../MaintenanceManager + ../../Packager + ../../TextToSpeech + ../../SystemAudioPlayer ) -link_directories(../LocationSync - ../SecurityAgent - ../DeviceIdentification - ../DeviceDiagnostics - ../FrameRate - ../AVInput - ../Telemetry - ../ScreenCapture - ../DataCapture - ../UsbAccess - ../Timer - ../LoggingPreferences - ../SystemServices - ../UserPreferences - ../Messenger - ../DeviceInfo - ../HdmiInput - ../HdcpProfile - ../Network - ../WifiManager - ../TraceControl - ../Warehouse - ../ActivityMonitor - ../MotionDetection - ../CompositeInput - ../OCIContainer - ../HdmiCec - ../HdmiCec_2 - ../HdmiCecSource - ../XCast - ../FrontPanel - ../HdmiCecSink - ../RDKShell - ../MaintenanceManager - ../Packager - ../TextToSpeech - ../SystemAudioPlayer +link_directories(../../LocationSync + ../../SecurityAgent + ../../DeviceIdentification + ../../DeviceDiagnostics + ../../FrameRate + ../../AVInput + ../../Telemetry + ../../ScreenCapture + ../../DataCapture + ../../UsbAccess + ../../Timer + ../../LoggingPreferences + ../../SystemServices + ../../UserPreferences + ../../Messenger + ../../DeviceInfo + ../../HdmiInput + ../../HdcpProfile + ../../Network + ../../WifiManager + ../../TraceControl + ../../Warehouse + ../../ActivityMonitor + ../../MotionDetection + ../../CompositeInput + ../../OCIContainer + ../../HdmiCec + ../../HdmiCec_2 + ../../HdmiCecSource + ../../XCast + ../../FrontPanel + ../../HdmiCecSink + ../../RDKShell + ../../MaintenanceManager + ../../Packager + ../../TextToSpeech + ../../SystemAudioPlayer ) target_link_libraries(${PROJECT_NAME} @@ -162,22 +170,22 @@ target_link_libraries(${PROJECT_NAME} ${NAMESPACE}HdmiCecSource ${NAMESPACE}XCast ${NAMESPACE}FrontPanel - ${NAMESPACE}HdmiCecSink - ${NAMESPACE}RDKShell + ${NAMESPACE}HdmiCecSink + ${NAMESPACE}RDKShell ${NAMESPACE}MaintenanceManager ${NAMESPACE}Packager - ${NAMESPACE}TextToSpeech - ${NAMESPACE}SystemAudioPlayer + ${NAMESPACE}TextToSpeech + ${NAMESPACE}SystemAudioPlayer ) target_include_directories(${PROJECT_NAME} PUBLIC $ $ - mocks - mocks/devicesettings - mocks/thunder - ${CMAKE_CURRENT_SOURCE_DIR}/../OCIContainer/stubs + ../mocks + ../mocks/devicesettings + ../mocks/thunder + ${CMAKE_CURRENT_SOURCE_DIR}/../../OCIContainer/stubs ) install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/Tests/README.md b/Tests/L1Tests/README.md old mode 100644 new mode 100755 similarity index 88% rename from Tests/README.md rename to Tests/L1Tests/README.md index 59e210758a..551d048414 --- a/Tests/README.md +++ b/Tests/L1Tests/README.md @@ -24,7 +24,7 @@ Create a [personal access token](https://docs.github.com/en/authentication/keepi Invoke the workflow: ```shell script -act -W .github/workflows/unit-tests.yml -s GITHUB_TOKEN=[token] +act -W .github/workflows/l1-tests.yml -s GITHUB_TOKEN=[token] ``` `-r, --reuse` to reuse the container. @@ -38,11 +38,11 @@ docker exec -it /bin/bash ## FAQ ## -1. The commands to build and run tests are in [unit-tests.yml](../.github/workflows/unit-tests.yml). +1. The commands to build and run tests are in [l1-tests.yml](../.github/workflows/l1-tests.yml). For the queries on syntax please refer to the [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions). 2. External dependencies need to be mocked. - For each external header, add one into the [tests.cmake](../tests.cmake) (preserve the original path parts, if needed). + For each external header, add one into the [l1tests.cmake](../l1tests.cmake) (preserve the original path parts, if needed). For each external declaration, add one into the [mocks folder](./mocks). For the queries on mocks please refer to the [gMock Cookbook](http://google.github.io/googletest/gmock_cook_book.html). diff --git a/Tests/tests/test_AVInput.cpp b/Tests/L1Tests/tests/test_AVInput.cpp old mode 100644 new mode 100755 similarity index 83% rename from Tests/tests/test_AVInput.cpp rename to Tests/L1Tests/tests/test_AVInput.cpp index bd25641c41..6fde932441 --- a/Tests/tests/test_AVInput.cpp +++ b/Tests/L1Tests/tests/test_AVInput.cpp @@ -26,16 +26,22 @@ class AVInputTest : public ::testing::Test { class AVInputDsTest : public AVInputTest { protected: - NiceMock hdmiInputImplMock; + HdmiInputImplMock *p_hdmiInputImplMock = nullptr ; AVInputDsTest() : AVInputTest() { - device::HdmiInput::getInstance().impl = &hdmiInputImplMock; + p_hdmiInputImplMock = new NiceMock ; + device::HdmiInput::setImpl(p_hdmiInputImplMock); } virtual ~AVInputDsTest() override { - device::HdmiInput::getInstance().impl = nullptr; + device::HdmiInput::setImpl(nullptr); + if (p_hdmiInputImplMock != nullptr) + { + delete p_hdmiInputImplMock; + p_hdmiInputImplMock = nullptr; + } } }; @@ -56,7 +62,7 @@ TEST_F(AVInputTest, contentProtected) TEST_F(AVInputDsTest, numberOfInputs) { - ON_CALL(hdmiInputImplMock, getNumberOfInputs()) + ON_CALL(*p_hdmiInputImplMock, getNumberOfInputs()) .WillByDefault(::testing::Return(1)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("numberOfInputs"), _T("{}"), response)); @@ -65,7 +71,7 @@ TEST_F(AVInputDsTest, numberOfInputs) TEST_F(AVInputDsTest, currentVideoMode) { - ON_CALL(hdmiInputImplMock, getCurrentVideoMode()) + ON_CALL(*p_hdmiInputImplMock, getCurrentVideoMode()) .WillByDefault(::testing::Return(string("unknown"))); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("currentVideoMode"), _T("{}"), response)); diff --git a/Tests/tests/test_ActivityMonitor.cpp b/Tests/L1Tests/tests/test_ActivityMonitor.cpp old mode 100644 new mode 100755 similarity index 95% rename from Tests/tests/test_ActivityMonitor.cpp rename to Tests/L1Tests/tests/test_ActivityMonitor.cpp index da0fcc9abe..ae9ce3ef0b --- a/Tests/tests/test_ActivityMonitor.cpp +++ b/Tests/L1Tests/tests/test_ActivityMonitor.cpp @@ -17,7 +17,7 @@ * limitations under the License. **/ -#include "gtest/gtest.h" +#include #include "ActivityMonitor.h" @@ -29,6 +29,8 @@ using namespace WPEFramework; +using ::testing::NiceMock; + namespace { const string regFile = _T("/opt/waylandregistry.conf"); const uint8_t regFileData[] = "{\"waylandapps\":[{\"name\" : \"memcheck-amd64-\",\"binary\" : \"/usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-%\"}]}"; @@ -106,12 +108,13 @@ class ActivityMonitorEventTest : public ActivityMonitorTest { Core::JSONRPC::Message message; FactoriesImplementation factoriesImplementation; PluginHost::IDispatcher* dispatcher; - IarmBusImplMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; ActivityMonitorEventTest() : ActivityMonitorTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); PluginHost::IFactories::Assign(&factoriesImplementation); dispatcher = static_cast( @@ -120,7 +123,13 @@ class ActivityMonitorEventTest : public ActivityMonitorTest { } virtual ~ActivityMonitorEventTest() override { - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + dispatcher->Deactivate(); dispatcher->Release(); diff --git a/Tests/tests/test_CompositeInput.cpp b/Tests/L1Tests/tests/test_CompositeInput.cpp old mode 100644 new mode 100755 similarity index 88% rename from Tests/tests/test_CompositeInput.cpp rename to Tests/L1Tests/tests/test_CompositeInput.cpp index 3ce124093b..aa21b480e9 --- a/Tests/tests/test_CompositeInput.cpp +++ b/Tests/L1Tests/tests/test_CompositeInput.cpp @@ -11,7 +11,7 @@ using ::testing::Eq; class CompositeInputTest : public ::testing::Test { protected: - NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; Core::ProxyType plugin; Core::JSONRPC::Handler& handler; Core::JSONRPC::Connection connection; @@ -23,23 +23,29 @@ class CompositeInputTest : public ::testing::Test { , connection(1, 0) { } - virtual ~CompositeInputTest() + virtual ~CompositeInputTest() { } }; class CompositeInputDsTest : public CompositeInputTest { protected: - NiceMock compositeInputImplMock; + CompositeInputImplMock *p_compositeInputImplMock = nullptr ; CompositeInputDsTest() : CompositeInputTest() { - device::CompositeInput::getInstance().impl = &compositeInputImplMock; + p_compositeInputImplMock = new NiceMock ; + device::CompositeInput::setImpl(p_compositeInputImplMock); } virtual ~CompositeInputDsTest() override { - device::CompositeInput::getInstance().impl = nullptr; + device::CompositeInput::setImpl(nullptr); + if (p_compositeInputImplMock != nullptr) + { + delete p_compositeInputImplMock; + p_compositeInputImplMock = nullptr; + } } }; @@ -53,9 +59,10 @@ class CompositeInputInitializedTest : public CompositeInputTest { CompositeInputInitializedTest() : CompositeInputTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG)) { @@ -79,7 +86,12 @@ class CompositeInputInitializedTest : public CompositeInputTest { { plugin->Deinitialize(nullptr); - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } } }; @@ -112,23 +124,29 @@ class CompositeInputInitializedEventTest : public CompositeInputInitializedTest class CompositeInputInitializedEventDsTest : public CompositeInputInitializedEventTest { protected: - NiceMock compositeInputImplMock; + CompositeInputImplMock *p_compositeInputImplMock = nullptr ; CompositeInputInitializedEventDsTest() : CompositeInputInitializedEventTest() { - device::CompositeInput::getInstance().impl = &compositeInputImplMock; + p_compositeInputImplMock = new NiceMock ; + device::CompositeInput::setImpl(p_compositeInputImplMock); } virtual ~CompositeInputInitializedEventDsTest() override { - device::CompositeInput::getInstance().impl = nullptr; + device::CompositeInput::setImpl(nullptr); + if (p_compositeInputImplMock != nullptr) + { + delete p_compositeInputImplMock; + p_compositeInputImplMock = nullptr; + } } }; TEST_F(CompositeInputTest, RegisteredMethods) { - + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getCompositeInputDevices"))); EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("startCompositeInput"))); EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("stopCompositeInput"))); @@ -137,10 +155,10 @@ TEST_F(CompositeInputTest, RegisteredMethods) TEST_F(CompositeInputDsTest, getCompositeInputDevices) { - ON_CALL(compositeInputImplMock, getNumberOfInputs()) - .WillByDefault(::testing::Return(1)); - ON_CALL(compositeInputImplMock, isPortConnected(::testing::_)) - .WillByDefault(::testing::Return(true)); + ON_CALL(*p_compositeInputImplMock, getNumberOfInputs()) + .WillByDefault(::testing::Return(1)); + ON_CALL(*p_compositeInputImplMock, isPortConnected(::testing::_)) + .WillByDefault(::testing::Return(true)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getCompositeInputDevices"), _T("{}"), response)); EXPECT_EQ(response, string("{\"devices\":[{\"id\":0,\"locator\":\"cvbsin:\\/\\/localhost\\/deviceid\\/0\",\"connected\":\"true\"}],\"success\":true}")); } @@ -153,7 +171,7 @@ TEST_F(CompositeInputDsTest, startCompositeInputInvalid) TEST_F(CompositeInputDsTest, startCompositeInput) { - EXPECT_CALL(compositeInputImplMock, selectPort(::testing::_)) + EXPECT_CALL(*p_compositeInputImplMock, selectPort(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](int8_t Port) { @@ -172,10 +190,10 @@ TEST_F(CompositeInputDsTest, setVideoRectangleInvalid) TEST_F(CompositeInputDsTest, setVideoRectangle) { - EXPECT_CALL(compositeInputImplMock, scaleVideo(::testing::_,::testing::_,::testing::_,::testing::_)) + EXPECT_CALL(*p_compositeInputImplMock, scaleVideo(::testing::_,::testing::_,::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( - [](int32_t x, int32_t y, int32_t width, int32_t height) { + [](int32_t x, int32_t y, int32_t width, int32_t height) { })); @@ -186,9 +204,9 @@ TEST_F(CompositeInputDsTest, setVideoRectangle) TEST_F(CompositeInputInitializedEventDsTest, onDevicesChanged) { ASSERT_TRUE(dsCompositeEventHandler != nullptr); - ON_CALL(compositeInputImplMock, getNumberOfInputs()) + ON_CALL(*p_compositeInputImplMock, getNumberOfInputs()) .WillByDefault(::testing::Return(1)); - ON_CALL(compositeInputImplMock, isPortConnected(::testing::_)) + ON_CALL(*p_compositeInputImplMock, isPortConnected(::testing::_)) .WillByDefault(::testing::Return(true)); EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) diff --git a/Tests/tests/test_DataCapture.cpp b/Tests/L1Tests/tests/test_DataCapture.cpp old mode 100644 new mode 100755 similarity index 95% rename from Tests/tests/test_DataCapture.cpp rename to Tests/L1Tests/tests/test_DataCapture.cpp index 65c3139290..58c3511b28 --- a/Tests/tests/test_DataCapture.cpp +++ b/Tests/L1Tests/tests/test_DataCapture.cpp @@ -27,6 +27,8 @@ #include "IarmBusMock.h" #include "ServiceMock.h" +using ::testing::NiceMock; + namespace { const std::string iarmName = _T("Thunder_Plugins"); constexpr const char answer[16] = "TESTING STREAM!"; @@ -110,12 +112,14 @@ class DataCaptureTest : public Test { class DataCaptureInitializedTest : public DataCaptureTest { protected: - NiceMock iarmBusImplMock_; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; DataCaptureInitializedTest() : DataCaptureTest() { - IarmBus::getInstance().impl = &iarmBusImplMock_; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + EXPECT_EQ(string(""), dataCapture_->Initialize(nullptr)); } @@ -123,7 +127,13 @@ class DataCaptureInitializedTest : public DataCaptureTest { { dataCapture_->Deinitialize(nullptr); - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + } }; @@ -132,7 +142,7 @@ class DataCaptureInitializedEnableAudioCaptureTest : public DataCaptureInitializ DataCaptureInitializedEnableAudioCaptureTest() : DataCaptureInitializedTest() { - ON_CALL(iarmBusImplMock_, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARMBUS_AUDIOCAPTUREMGR_OPEN) == 0) { @@ -207,7 +217,7 @@ TEST_F(DataCaptureTest, ShouldReturnErrorWhenParamsAreEmpty) TEST_F(DataCaptureInitializedEnableAudioCaptureTest, ShouldTurnOnAudioCapture) { - ON_CALL(iarmBusImplMock_, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARMBUS_AUDIOCAPTUREMGR_REQUEST_SAMPLE) == 0) { @@ -228,7 +238,7 @@ TEST_F(DataCaptureInitializedEnableAudioCaptureTest, ShouldTurnOnAudioCapture) TEST_F(DataCaptureInitializedEnableAudioCaptureTest, ShouldTurnOffAudioCapture) { - ON_CALL(iarmBusImplMock_, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARMBUS_AUDIOCAPTUREMGR_STOP) == 0) { @@ -288,7 +298,7 @@ TEST_F(DataCaptureInitializedEnableAudioCaptureEventTest, DISABLED_ShouldUploadD return Core::ERROR_NONE; }); - ON_CALL(iarmBusImplMock_, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARMBUS_AUDIOCAPTUREMGR_REQUEST_SAMPLE) == 0) { diff --git a/Tests/tests/test_DeviceAudioCapabilities.cpp b/Tests/L1Tests/tests/test_DeviceAudioCapabilities.cpp old mode 100644 new mode 100755 similarity index 74% rename from Tests/tests/test_DeviceAudioCapabilities.cpp rename to Tests/L1Tests/tests/test_DeviceAudioCapabilities.cpp index 937051e9dc..f087ff394f --- a/Tests/tests/test_DeviceAudioCapabilities.cpp +++ b/Tests/L1Tests/tests/test_DeviceAudioCapabilities.cpp @@ -15,32 +15,44 @@ using ::testing::NiceMock; class DeviceAudioCapabilitiesTest : public ::testing::Test { protected: - NiceMock iarmBusImplMock; - ManagerImplMock managerImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ManagerImplMock *p_managerImplMock = nullptr ; Core::ProxyType deviceAudioCapabilities; Exchange::IDeviceAudioCapabilities* interface; DeviceAudioCapabilitiesTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; - device::Manager::getInstance().impl = &managerImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + p_managerImplMock = new NiceMock ; + device::Manager::setImpl(p_managerImplMock); - EXPECT_CALL(managerImplMock, Initialize()) + EXPECT_CALL(*p_managerImplMock, Initialize()) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Return()); deviceAudioCapabilities = Core::ProxyType::Create(); interface = static_cast( - deviceAudioCapabilities->QueryInterface(Exchange::IDeviceAudioCapabilities::ID)); + deviceAudioCapabilities->QueryInterface(Exchange::IDeviceAudioCapabilities::ID)); } virtual ~DeviceAudioCapabilitiesTest() { interface->Release(); - IarmBus::getInstance().impl = nullptr; - device::Manager::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } } virtual void SetUp() @@ -56,31 +68,44 @@ class DeviceAudioCapabilitiesTest : public ::testing::Test { class DeviceAudioCapabilitiesDsTest : public DeviceAudioCapabilitiesTest { protected: - NiceMock hostImplMock; + HostImplMock *p_hostImplMock = nullptr ; + AudioOutputPortMock *p_audioOutputPortMock = nullptr ; DeviceAudioCapabilitiesDsTest() : DeviceAudioCapabilitiesTest() { - device::Host::getInstance().impl = &hostImplMock; + p_hostImplMock = new NiceMock ; + device::Host::setImpl(p_hostImplMock); + p_audioOutputPortMock = new NiceMock ; + device::AudioOutputPort::setImpl(p_audioOutputPortMock); } virtual ~DeviceAudioCapabilitiesDsTest() override { - device::Host::getInstance().impl = nullptr; + device::AudioOutputPort::setImpl(nullptr); + if (p_audioOutputPortMock != nullptr) + { + delete p_audioOutputPortMock; + p_audioOutputPortMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } } }; TEST_F(DeviceAudioCapabilitiesDsTest, SupportedAudioPorts) { - NiceMock audioOutputPortMock; device::AudioOutputPort audioOutputPort; - audioOutputPort.impl = &audioOutputPortMock; RPC::IStringIterator* supportedAudioPorts = nullptr; string audioPort(_T("HDMI0")); string element; - ON_CALL(audioOutputPortMock, getName()) + ON_CALL(*p_audioOutputPortMock, getName()) .WillByDefault(::testing::ReturnRef(audioPort)); - ON_CALL(hostImplMock, getAudioOutputPorts()) + ON_CALL(*p_hostImplMock, getAudioOutputPorts()) .WillByDefault(::testing::Return(device::List({ audioOutputPort }))); EXPECT_EQ(Core::ERROR_NONE, interface->SupportedAudioPorts(supportedAudioPorts)); @@ -93,23 +118,21 @@ TEST_F(DeviceAudioCapabilitiesDsTest, SupportedAudioPorts) TEST_F(DeviceAudioCapabilitiesDsTest, AudioCapabilities_noParam) { - NiceMock audioOutputPortMock; device::AudioOutputPort audioOutputPort; - audioOutputPort.impl = &audioOutputPortMock; Exchange::IDeviceAudioCapabilities::IAudioCapabilityIterator* audioCapabilities = nullptr; string audioPort(_T("HDMI0")); Exchange::IDeviceAudioCapabilities::AudioCapability element; - ON_CALL(audioOutputPortMock, getAudioCapabilities(::testing::_)) + ON_CALL(*p_audioOutputPortMock, getAudioCapabilities(::testing::_)) .WillByDefault(::testing::Invoke( [&](int* capabilities) { ASSERT_TRUE(capabilities != nullptr); EXPECT_EQ(*capabilities, dsAUDIOSUPPORT_NONE); *capabilities = dsAUDIOSUPPORT_ATMOS | dsAUDIOSUPPORT_DDPLUS; })); - ON_CALL(hostImplMock, getDefaultAudioPortName()) + ON_CALL(*p_hostImplMock, getDefaultAudioPortName()) .WillByDefault(::testing::Return(audioPort)); - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(audioOutputPort)); EXPECT_EQ(Core::ERROR_NONE, interface->AudioCapabilities(string(), audioCapabilities)); @@ -124,23 +147,21 @@ TEST_F(DeviceAudioCapabilitiesDsTest, AudioCapabilities_noParam) TEST_F(DeviceAudioCapabilitiesDsTest, MS12Capabilities_noParam) { - NiceMock audioOutputPortMock; device::AudioOutputPort audioOutputPort; - audioOutputPort.impl = &audioOutputPortMock; Exchange::IDeviceAudioCapabilities::IMS12CapabilityIterator* ms12Capabilities = nullptr; string audioPort(_T("HDMI0")); Exchange::IDeviceAudioCapabilities::MS12Capability element; - ON_CALL(audioOutputPortMock, getMS12Capabilities(::testing::_)) + ON_CALL(*p_audioOutputPortMock, getMS12Capabilities(::testing::_)) .WillByDefault(::testing::Invoke( [&](int* capabilities) { ASSERT_TRUE(capabilities != nullptr); EXPECT_EQ(*capabilities, dsMS12SUPPORT_NONE); *capabilities = dsMS12SUPPORT_DolbyVolume | dsMS12SUPPORT_InteligentEqualizer; })); - ON_CALL(hostImplMock, getDefaultAudioPortName()) + ON_CALL(*p_hostImplMock, getDefaultAudioPortName()) .WillByDefault(::testing::Return(audioPort)); - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(audioOutputPort)); EXPECT_EQ(Core::ERROR_NONE, interface->MS12Capabilities(string(), ms12Capabilities)); @@ -155,19 +176,17 @@ TEST_F(DeviceAudioCapabilitiesDsTest, MS12Capabilities_noParam) TEST_F(DeviceAudioCapabilitiesDsTest, SupportedMS12AudioProfiles_noParam) { - NiceMock audioOutputPortMock; device::AudioOutputPort audioOutputPort; - audioOutputPort.impl = &audioOutputPortMock; RPC::IStringIterator* supportedMS12AudioProfiles = nullptr; string audioPort(_T("HDMI0")); string audioPortMS12AudioProfile(_T("Movie")); string element; - ON_CALL(audioOutputPortMock, getMS12AudioProfileList()) + ON_CALL(*p_audioOutputPortMock, getMS12AudioProfileList()) .WillByDefault(::testing::Return(std::vector({ audioPortMS12AudioProfile }))); - ON_CALL(hostImplMock, getDefaultAudioPortName()) + ON_CALL(*p_hostImplMock, getDefaultAudioPortName()) .WillByDefault(::testing::Return(audioPort)); - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(audioOutputPort)); EXPECT_EQ(Core::ERROR_NONE, interface->SupportedMS12AudioProfiles(string(), supportedMS12AudioProfiles)); @@ -182,7 +201,7 @@ TEST_F(DeviceAudioCapabilitiesDsTest, SupportedAudioPorts_exception) { RPC::IStringIterator* supportedAudioPorts = nullptr; - ON_CALL(hostImplMock, getAudioOutputPorts()) + ON_CALL(*p_hostImplMock, getAudioOutputPorts()) .WillByDefault(::testing::Invoke( [&]() -> device::List { throw device::Exception("test"); @@ -196,7 +215,7 @@ TEST_F(DeviceAudioCapabilitiesDsTest, AudioCapabilities_HDMI0_exception) { Exchange::IDeviceAudioCapabilities::IAudioCapabilityIterator* audioCapabilities = nullptr; - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::AudioOutputPort& { EXPECT_EQ(name, _T("HDMI0")); @@ -211,7 +230,7 @@ TEST_F(DeviceAudioCapabilitiesDsTest, MS12Capabilities_HDMI0_exception) { Exchange::IDeviceAudioCapabilities::IMS12CapabilityIterator* ms12Capabilities = nullptr; - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::AudioOutputPort& { EXPECT_EQ(name, _T("HDMI0")); @@ -226,7 +245,7 @@ TEST_F(DeviceAudioCapabilitiesDsTest, SupportedMS12AudioProfiles_HDMI0_exception { RPC::IStringIterator* supportedMS12AudioProfiles = nullptr; - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::AudioOutputPort& { EXPECT_EQ(name, _T("HDMI0")); diff --git a/Tests/tests/test_DeviceDiagnostics.cpp b/Tests/L1Tests/tests/test_DeviceDiagnostics.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_DeviceDiagnostics.cpp rename to Tests/L1Tests/tests/test_DeviceDiagnostics.cpp diff --git a/Tests/tests/test_DeviceIdentification.cpp b/Tests/L1Tests/tests/test_DeviceIdentification.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_DeviceIdentification.cpp rename to Tests/L1Tests/tests/test_DeviceIdentification.cpp diff --git a/Tests/tests/test_DeviceInfo.cpp b/Tests/L1Tests/tests/test_DeviceInfo.cpp old mode 100644 new mode 100755 similarity index 82% rename from Tests/tests/test_DeviceInfo.cpp rename to Tests/L1Tests/tests/test_DeviceInfo.cpp index 884a1655e2..498ff55a4a --- a/Tests/tests/test_DeviceInfo.cpp +++ b/Tests/L1Tests/tests/test_DeviceInfo.cpp @@ -12,13 +12,14 @@ using ::testing::NiceMock; class DeviceInfoTest : public ::testing::Test { protected: - NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; Core::ProxyType deviceInfoImplementation; Exchange::IDeviceInfo* interface; DeviceInfoTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); deviceInfoImplementation = Core::ProxyType::Create(); @@ -28,7 +29,12 @@ class DeviceInfoTest : public ::testing::Test { virtual ~DeviceInfoTest() { interface->Release(); - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } } virtual void SetUp() diff --git a/Tests/tests/test_DeviceInfoJsonRpc.cpp b/Tests/L1Tests/tests/test_DeviceInfoJsonRpc.cpp old mode 100644 new mode 100755 similarity index 72% rename from Tests/tests/test_DeviceInfoJsonRpc.cpp rename to Tests/L1Tests/tests/test_DeviceInfoJsonRpc.cpp index bdd8f90ff6..b512131de1 --- a/Tests/tests/test_DeviceInfoJsonRpc.cpp +++ b/Tests/L1Tests/tests/test_DeviceInfoJsonRpc.cpp @@ -42,16 +42,19 @@ class DeviceInfoJsonRpcTest : public ::testing::Test { class DeviceInfoJsonRpcInitializedTest : public DeviceInfoJsonRpcTest { protected: - NiceMock iarmBusImplMock; - NiceMock managerImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ManagerImplMock *p_managerImplMock = nullptr ; NiceMock service; Core::Sink> subSystem; DeviceInfoJsonRpcInitializedTest() : DeviceInfoJsonRpcTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; - device::Manager::getInstance().impl = &managerImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_managerImplMock = new NiceMock ; + device::Manager::setImpl(p_managerImplMock); ON_CALL(service, ConfigLine()) .WillByDefault(::testing::Return("{\"root\":{\"mode\":\"Off\"}}")); @@ -71,38 +74,97 @@ class DeviceInfoJsonRpcInitializedTest : public DeviceInfoJsonRpcTest { { plugin->Deinitialize(&service); - IarmBus::getInstance().impl = nullptr; - device::Manager::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } } }; class DeviceInfoJsonRpcInitializedDsTest : public DeviceInfoJsonRpcInitializedTest { protected: - NiceMock hostImplMock; + HostImplMock *p_hostImplMock = nullptr ; + AudioOutputPortMock *p_audioOutputPortMock = nullptr ; + VideoResolutionMock *p_videoResolutionMock = nullptr ; + VideoOutputPortMock *p_videoOutputPortMock = nullptr ; DeviceInfoJsonRpcInitializedDsTest() : DeviceInfoJsonRpcInitializedTest() { - device::Host::getInstance().impl = &hostImplMock; + p_hostImplMock = new NiceMock ; + device::Host::setImpl(p_hostImplMock); + p_audioOutputPortMock = new NiceMock ; + device::AudioOutputPort::setImpl(p_audioOutputPortMock); + + p_videoResolutionMock = new NiceMock ; + device::VideoResolution::setImpl(p_videoResolutionMock); + p_videoOutputPortMock = new NiceMock ; + device::VideoOutputPort::setImpl(p_videoOutputPortMock); } virtual ~DeviceInfoJsonRpcInitializedDsTest() override { - device::Host::getInstance().impl = nullptr; + device::AudioOutputPort::setImpl(nullptr); + if (p_audioOutputPortMock != nullptr) + { + delete p_audioOutputPortMock; + p_audioOutputPortMock = nullptr; + } + device::VideoResolution::setImpl(nullptr); + if (p_videoResolutionMock != nullptr) + { + delete p_videoResolutionMock; + p_videoResolutionMock = nullptr; + } + device::VideoOutputPort::setImpl(nullptr); + if (p_videoOutputPortMock != nullptr) + { + delete p_videoOutputPortMock; + p_videoOutputPortMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } } }; class DeviceInfoJsonRpcInitializedDsVideoOutputTest : public DeviceInfoJsonRpcInitializedDsTest { protected: - NiceMock videoOutputPortConfigImplMock; + VideoOutputPortConfigImplMock *p_videoOutputPortConfigImplMock = nullptr ; + VideoOutputPortTypeMock *p_videoOutputPortTypeMock = nullptr ; DeviceInfoJsonRpcInitializedDsVideoOutputTest() : DeviceInfoJsonRpcInitializedDsTest() { - device::VideoOutputPortConfig::getInstance().impl = &videoOutputPortConfigImplMock; + p_videoOutputPortConfigImplMock = new NiceMock ; + device::VideoOutputPortConfig::setImpl(p_videoOutputPortConfigImplMock); + p_videoOutputPortTypeMock = new NiceMock ; + device::VideoOutputPortType::setImpl(p_videoOutputPortTypeMock); } virtual ~DeviceInfoJsonRpcInitializedDsVideoOutputTest() override { - device::VideoOutputPortConfig::getInstance().impl = nullptr; + device::VideoOutputPortType::setImpl(nullptr); + if (p_videoOutputPortTypeMock != nullptr) + { + delete p_videoOutputPortTypeMock; + p_videoOutputPortTypeMock = nullptr; + } + device::VideoOutputPortConfig::setImpl(nullptr); + if (p_videoOutputPortConfigImplMock != nullptr) + { + delete p_videoOutputPortConfigImplMock; + p_videoOutputPortConfigImplMock = nullptr; + } } }; @@ -212,14 +274,12 @@ TEST_F(DeviceInfoJsonRpcInitializedTest, devicetype) TEST_F(DeviceInfoJsonRpcInitializedDsTest, supportedaudioports) { - NiceMock audioOutputPortMock; device::AudioOutputPort audioOutputPort; - audioOutputPort.impl = &audioOutputPortMock; string audioPort(_T("HDMI0")); - ON_CALL(audioOutputPortMock, getName()) + ON_CALL(*p_audioOutputPortMock, getName()) .WillByDefault(::testing::ReturnRef(audioPort)); - ON_CALL(hostImplMock, getAudioOutputPorts()) + ON_CALL(*p_hostImplMock, getAudioOutputPorts()) .WillByDefault(::testing::Return(device::List({ audioOutputPort }))); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("supportedaudioports"), _T(""), response)); @@ -228,14 +288,12 @@ TEST_F(DeviceInfoJsonRpcInitializedDsTest, supportedaudioports) TEST_F(DeviceInfoJsonRpcInitializedDsTest, supportedvideodisplays) { - NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; string videoPort(_T("HDMI0")); - ON_CALL(videoOutputPortMock, getName()) + ON_CALL(*p_videoOutputPortMock, getName()) .WillByDefault(::testing::ReturnRef(videoPort)); - ON_CALL(hostImplMock, getVideoOutputPorts()) + ON_CALL(*p_hostImplMock, getVideoOutputPorts()) .WillByDefault(::testing::Return(device::List({ videoOutputPort }))); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("supportedvideodisplays"), _T(""), response)); @@ -244,7 +302,7 @@ TEST_F(DeviceInfoJsonRpcInitializedDsTest, supportedvideodisplays) TEST_F(DeviceInfoJsonRpcInitializedDsTest, hostedid) { - ON_CALL(hostImplMock, getHostEDID(::testing::_)) + ON_CALL(*p_hostImplMock, getHostEDID(::testing::_)) .WillByDefault(::testing::Invoke( [&](std::vector& edid) { edid = { 't', 'e', 's', 't' }; @@ -256,22 +314,18 @@ TEST_F(DeviceInfoJsonRpcInitializedDsTest, hostedid) TEST_F(DeviceInfoJsonRpcInitializedDsTest, defaultresolution) { - NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - NiceMock videoResolutionMock; device::VideoResolution videoResolution; - videoResolution.impl = &videoResolutionMock; string videoPort(_T("HDMI0")); string videoPortDefaultResolution(_T("1080p")); - ON_CALL(videoResolutionMock, getName()) + ON_CALL(*p_videoResolutionMock, getName()) .WillByDefault(::testing::ReturnRef(videoPortDefaultResolution)); - ON_CALL(videoOutputPortMock, getDefaultResolution()) + ON_CALL(*p_videoOutputPortMock, getDefaultResolution()) .WillByDefault(::testing::ReturnRef(videoResolution)); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(hostImplMock, getVideoOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("defaultresolution"), _T(""), response)); @@ -280,31 +334,25 @@ TEST_F(DeviceInfoJsonRpcInitializedDsTest, defaultresolution) TEST_F(DeviceInfoJsonRpcInitializedDsVideoOutputTest, supportedresolutions) { - NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - NiceMock videoOutputPortTypeMock; device::VideoOutputPortType videoOutputPortType; - videoOutputPortType.impl = &videoOutputPortTypeMock; - NiceMock videoResolutionMock; device::VideoResolution videoResolution; - videoResolution.impl = &videoResolutionMock; string videoPort(_T("HDMI0")); string videoPortSupportedResolution(_T("1080p")); - ON_CALL(videoResolutionMock, getName()) + ON_CALL(*p_videoResolutionMock, getName()) .WillByDefault(::testing::ReturnRef(videoPortSupportedResolution)); - ON_CALL(videoOutputPortTypeMock, getSupportedResolutions()) + ON_CALL(*p_videoOutputPortTypeMock, getSupportedResolutions()) .WillByDefault(::testing::Return(device::List({ videoResolution }))); - ON_CALL(videoOutputPortTypeMock, getId()) + ON_CALL(*p_videoOutputPortTypeMock, getId()) .WillByDefault(::testing::Return(0)); - ON_CALL(videoOutputPortMock, getType()) + ON_CALL(*p_videoOutputPortMock, getType()) .WillByDefault(::testing::ReturnRef(videoOutputPortType)); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(hostImplMock, getVideoOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); - ON_CALL(videoOutputPortConfigImplMock, getPortType(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPortType(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPortType)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("supportedresolutions"), _T(""), response)); @@ -313,16 +361,14 @@ TEST_F(DeviceInfoJsonRpcInitializedDsVideoOutputTest, supportedresolutions) TEST_F(DeviceInfoJsonRpcInitializedDsVideoOutputTest, supportedhdcp) { - NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; string videoPort(_T("HDMI0")); - ON_CALL(videoOutputPortMock, getHDCPProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("supportedhdcp"), _T(""), response)); @@ -331,21 +377,20 @@ TEST_F(DeviceInfoJsonRpcInitializedDsVideoOutputTest, supportedhdcp) TEST_F(DeviceInfoJsonRpcInitializedDsTest, audiocapabilities) { - NiceMock audioOutputPortMock; - device::AudioOutputPort audioOutputPort; - audioOutputPort.impl = &audioOutputPortMock; + device::AudioOutputPort audioOutputPort; + string audioPort(_T("HDMI0")); - ON_CALL(audioOutputPortMock, getAudioCapabilities(::testing::_)) + ON_CALL(*p_audioOutputPortMock, getAudioCapabilities(::testing::_)) .WillByDefault(::testing::Invoke( [&](int* capabilities) { ASSERT_TRUE(capabilities != nullptr); EXPECT_EQ(*capabilities, dsAUDIOSUPPORT_NONE); *capabilities = dsAUDIOSUPPORT_ATMOS | dsAUDIOSUPPORT_DD | dsAUDIOSUPPORT_DDPLUS | dsAUDIOSUPPORT_DAD | dsAUDIOSUPPORT_DAPv2 | dsAUDIOSUPPORT_MS12; })); - ON_CALL(hostImplMock, getDefaultAudioPortName()) + ON_CALL(*p_hostImplMock, getDefaultAudioPortName()) .WillByDefault(::testing::Return(audioPort)); - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(audioOutputPort)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("audiocapabilities"), _T(""), response)); @@ -354,21 +399,20 @@ TEST_F(DeviceInfoJsonRpcInitializedDsTest, audiocapabilities) TEST_F(DeviceInfoJsonRpcInitializedDsTest, ms12capabilities) { - NiceMock audioOutputPortMock; - device::AudioOutputPort audioOutputPort; - audioOutputPort.impl = &audioOutputPortMock; + device::AudioOutputPort audioOutputPort; + string audioPort(_T("HDMI0")); - ON_CALL(audioOutputPortMock, getMS12Capabilities(::testing::_)) + ON_CALL(*p_audioOutputPortMock, getMS12Capabilities(::testing::_)) .WillByDefault(::testing::Invoke( [&](int* capabilities) { ASSERT_TRUE(capabilities != nullptr); EXPECT_EQ(*capabilities, dsMS12SUPPORT_NONE); *capabilities = dsMS12SUPPORT_DolbyVolume | dsMS12SUPPORT_InteligentEqualizer | dsMS12SUPPORT_DialogueEnhancer; })); - ON_CALL(hostImplMock, getDefaultAudioPortName()) + ON_CALL(*p_hostImplMock, getDefaultAudioPortName()) .WillByDefault(::testing::Return(audioPort)); - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(audioOutputPort)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("ms12capabilities"), _T(""), response)); @@ -377,17 +421,16 @@ TEST_F(DeviceInfoJsonRpcInitializedDsTest, ms12capabilities) TEST_F(DeviceInfoJsonRpcInitializedDsTest, supportedms12audioprofiles) { - NiceMock audioOutputPortMock; - device::AudioOutputPort audioOutputPort; - audioOutputPort.impl = &audioOutputPortMock; + device::AudioOutputPort audioOutputPort; + string audioPort(_T("HDMI0")); string audioPortMS12AudioProfile(_T("Movie")); - ON_CALL(audioOutputPortMock, getMS12AudioProfileList()) + ON_CALL(*p_audioOutputPortMock, getMS12AudioProfileList()) .WillByDefault(::testing::Return(std::vector({ audioPortMS12AudioProfile }))); - ON_CALL(hostImplMock, getDefaultAudioPortName()) + ON_CALL(*p_hostImplMock, getDefaultAudioPortName()) .WillByDefault(::testing::Return(audioPort)); - ON_CALL(hostImplMock, getAudioOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getAudioOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(audioOutputPort)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("supportedms12audioprofiles"), _T(""), response)); diff --git a/Tests/tests/test_DeviceInfoWeb.cpp b/Tests/L1Tests/tests/test_DeviceInfoWeb.cpp old mode 100644 new mode 100755 similarity index 92% rename from Tests/tests/test_DeviceInfoWeb.cpp rename to Tests/L1Tests/tests/test_DeviceInfoWeb.cpp index 1b348d2618..f94f1976f9 --- a/Tests/tests/test_DeviceInfoWeb.cpp +++ b/Tests/L1Tests/tests/test_DeviceInfoWeb.cpp @@ -46,8 +46,8 @@ class DeviceInfoWebTest : public ::testing::Test { class DeviceInfoWebInitializedTest : public DeviceInfoWebTest { protected: NiceMock factoriesImplementation; - NiceMock iarmBusImplMock; - NiceMock managerImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ManagerImplMock *p_managerImplMock = nullptr ; NiceMock service; Core::Sink> subSystem; @@ -55,8 +55,10 @@ class DeviceInfoWebInitializedTest : public DeviceInfoWebTest { : DeviceInfoWebTest() { PluginHost::IFactories::Assign(&factoriesImplementation); - IarmBus::getInstance().impl = &iarmBusImplMock; - device::Manager::getInstance().impl = &managerImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + p_managerImplMock = new NiceMock ; + device::Manager::setImpl(p_managerImplMock); ON_CALL(service, ConfigLine()) .WillByDefault(::testing::Return("{\"root\":{\"mode\":\"Off\"}}")); @@ -77,8 +79,18 @@ class DeviceInfoWebInitializedTest : public DeviceInfoWebTest { plugin->Deinitialize(&service); PluginHost::IFactories::Assign(nullptr); - IarmBus::getInstance().impl = nullptr; - device::Manager::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } } }; diff --git a/Tests/tests/test_DeviceVideoCapabilities.cpp b/Tests/L1Tests/tests/test_DeviceVideoCapabilities.cpp old mode 100644 new mode 100755 similarity index 64% rename from Tests/tests/test_DeviceVideoCapabilities.cpp rename to Tests/L1Tests/tests/test_DeviceVideoCapabilities.cpp index 085703a943..43818dce9c --- a/Tests/tests/test_DeviceVideoCapabilities.cpp +++ b/Tests/L1Tests/tests/test_DeviceVideoCapabilities.cpp @@ -18,17 +18,20 @@ using ::testing::NiceMock; class DeviceVideoCapabilitiesTest : public ::testing::Test { protected: - NiceMock iarmBusImplMock; - ManagerImplMock managerImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ManagerImplMock *p_managerImplMock = nullptr ; Core::ProxyType deviceVideoCapabilities; Exchange::IDeviceVideoCapabilities* interface; DeviceVideoCapabilitiesTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; - device::Manager::getInstance().impl = &managerImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); - EXPECT_CALL(managerImplMock, Initialize()) + p_managerImplMock = new NiceMock ; + device::Manager::setImpl(p_managerImplMock); + + EXPECT_CALL(*p_managerImplMock, Initialize()) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Return()); @@ -41,8 +44,18 @@ class DeviceVideoCapabilitiesTest : public ::testing::Test { { interface->Release(); - IarmBus::getInstance().impl = nullptr; - device::Manager::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } } virtual void SetUp() @@ -58,34 +71,75 @@ class DeviceVideoCapabilitiesTest : public ::testing::Test { class DeviceVideoCapabilitiesDsTest : public DeviceVideoCapabilitiesTest { protected: - NiceMock hostImplMock; - NiceMock videoOutputPortConfigImplMock; + HostImplMock *p_hostImplMock = nullptr ; + VideoOutputPortConfigImplMock *p_videoOutputPortConfigImplMock = nullptr ; + VideoOutputPortTypeMock *p_videoOutputPortTypeMock = nullptr ; + VideoOutputPortMock *p_videoOutputPortMock = nullptr ; + VideoResolutionMock *p_videoResolutionMock = nullptr ; DeviceVideoCapabilitiesDsTest() : DeviceVideoCapabilitiesTest() { - device::Host::getInstance().impl = &hostImplMock; - device::VideoOutputPortConfig::getInstance().impl = &videoOutputPortConfigImplMock; + p_hostImplMock = new NiceMock ; + device::Host::setImpl(p_hostImplMock); + + p_videoOutputPortConfigImplMock = new NiceMock ; + device::VideoOutputPortConfig::setImpl(p_videoOutputPortConfigImplMock); + + p_videoOutputPortTypeMock = new NiceMock ; + device::VideoOutputPortType::setImpl(p_videoOutputPortTypeMock); + + p_videoResolutionMock = new NiceMock ; + device::VideoResolution::setImpl(p_videoResolutionMock); + + p_videoOutputPortMock = new NiceMock ; + device::VideoOutputPort::setImpl(p_videoOutputPortMock); } virtual ~DeviceVideoCapabilitiesDsTest() override { - device::Host::getInstance().impl = nullptr; - device::VideoOutputPortConfig::getInstance().impl = nullptr; + device::VideoResolution::setImpl(nullptr); + if (p_videoResolutionMock != nullptr) + { + delete p_videoResolutionMock; + p_videoResolutionMock = nullptr; + } + device::VideoOutputPortType::setImpl(nullptr); + if (p_videoOutputPortTypeMock != nullptr) + { + delete p_videoOutputPortTypeMock; + p_videoOutputPortTypeMock = nullptr; + } + device::VideoOutputPort::setImpl(nullptr); + if (p_videoOutputPortMock != nullptr) + { + delete p_videoOutputPortMock; + p_videoOutputPortMock = nullptr; + } + device::VideoOutputPortConfig::setImpl(nullptr); + if (p_videoOutputPortConfigImplMock != nullptr) + { + delete p_videoOutputPortConfigImplMock; + p_videoOutputPortConfigImplMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } } }; TEST_F(DeviceVideoCapabilitiesDsTest, SupportedVideoDisplays) { - NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; RPC::IStringIterator* supportedVideoDisplays = nullptr; string videoPort(_T("HDMI0")); string element; - ON_CALL(videoOutputPortMock, getName()) + ON_CALL(*p_videoOutputPortMock, getName()) .WillByDefault(::testing::ReturnRef(videoPort)); - ON_CALL(hostImplMock, getVideoOutputPorts()) + ON_CALL(*p_hostImplMock, getVideoOutputPorts()) .WillByDefault(::testing::Return(device::List({ videoOutputPort }))); EXPECT_EQ(Core::ERROR_NONE, interface->SupportedVideoDisplays(supportedVideoDisplays)); @@ -100,7 +154,7 @@ TEST_F(DeviceVideoCapabilitiesDsTest, HostEDID) { string edid; - ON_CALL(hostImplMock, getHostEDID(::testing::_)) + ON_CALL(*p_hostImplMock, getHostEDID(::testing::_)) .WillByDefault(::testing::Invoke( [&](std::vector& edid) { edid = { 't', 'e', 's', 't' }; @@ -114,21 +168,18 @@ TEST_F(DeviceVideoCapabilitiesDsTest, DefaultResolution_noParam) { NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - NiceMock videoResolutionMock; device::VideoResolution videoResolution; - videoResolution.impl = &videoResolutionMock; string videoPort(_T("HDMI0")); string videoPortDefaultResolution(_T("1080p")); string defaultResolution; - ON_CALL(videoResolutionMock, getName()) + ON_CALL(*p_videoResolutionMock, getName()) .WillByDefault(::testing::ReturnRef(videoPortDefaultResolution)); - ON_CALL(videoOutputPortMock, getDefaultResolution()) + ON_CALL(*p_videoOutputPortMock, getDefaultResolution()) .WillByDefault(::testing::ReturnRef(videoResolution)); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(hostImplMock, getVideoOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); EXPECT_EQ(Core::ERROR_NONE, interface->DefaultResolution(string(), defaultResolution)); @@ -139,31 +190,26 @@ TEST_F(DeviceVideoCapabilitiesDsTest, SupportedResolutions_noParam) { NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - NiceMock videoOutputPortTypeMock; device::VideoOutputPortType videoOutputPortType; - videoOutputPortType.impl = &videoOutputPortTypeMock; - NiceMock videoResolutionMock; device::VideoResolution videoResolution; - videoResolution.impl = &videoResolutionMock; RPC::IStringIterator* supportedResolutions = nullptr; string videoPort(_T("HDMI0")); string videoPortSupportedResolution(_T("1080p")); string element; - ON_CALL(videoResolutionMock, getName()) + ON_CALL(*p_videoResolutionMock, getName()) .WillByDefault(::testing::ReturnRef(videoPortSupportedResolution)); - ON_CALL(videoOutputPortTypeMock, getSupportedResolutions()) + ON_CALL(*p_videoOutputPortTypeMock, getSupportedResolutions()) .WillByDefault(::testing::Return(device::List({ videoResolution }))); - ON_CALL(videoOutputPortTypeMock, getId()) + ON_CALL(*p_videoOutputPortTypeMock, getId()) .WillByDefault(::testing::Return(0)); - ON_CALL(videoOutputPortMock, getType()) + ON_CALL(*p_videoOutputPortMock, getType()) .WillByDefault(::testing::ReturnRef(videoOutputPortType)); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(hostImplMock, getVideoOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); - ON_CALL(videoOutputPortConfigImplMock, getPortType(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPortType(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPortType)); EXPECT_EQ(Core::ERROR_NONE, interface->SupportedResolutions(string(), supportedResolutions)); @@ -178,15 +224,14 @@ TEST_F(DeviceVideoCapabilitiesDsTest, SupportedHdcp_noParam) { NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; string videoPort(_T("HDMI0")); auto supportedHDCPVersion = Exchange::IDeviceVideoCapabilities::CopyProtection::HDCP_UNAVAILABLE; - ON_CALL(videoOutputPortMock, getHDCPProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); EXPECT_EQ(Core::ERROR_NONE, interface->SupportedHdcp(string(), supportedHDCPVersion)); @@ -197,7 +242,7 @@ TEST_F(DeviceVideoCapabilitiesDsTest, SupportedVideoDisplays_exception) { RPC::IStringIterator* supportedVideoDisplays = nullptr; - ON_CALL(hostImplMock, getVideoOutputPorts()) + ON_CALL(*p_hostImplMock, getVideoOutputPorts()) .WillByDefault(::testing::Invoke( [&]() -> device::List { throw device::Exception("test"); @@ -211,7 +256,7 @@ TEST_F(DeviceVideoCapabilitiesDsTest, HostEDID_exception) { string edid; - ON_CALL(hostImplMock, getHostEDID(::testing::_)) + ON_CALL(*p_hostImplMock, getHostEDID(::testing::_)) .WillByDefault(::testing::Invoke( [&](std::vector& edid) { throw device::Exception("test"); @@ -225,7 +270,7 @@ TEST_F(DeviceVideoCapabilitiesDsTest, DefaultResolution_HDMI0_exception) { string defaultResolution; - ON_CALL(hostImplMock, getVideoOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::VideoOutputPort& { EXPECT_EQ(name, _T("HDMI0")); @@ -240,7 +285,7 @@ TEST_F(DeviceVideoCapabilitiesDsTest, SupportedResolutions_HDMI0_exception) { RPC::IStringIterator* supportedResolutions = nullptr; - ON_CALL(hostImplMock, getVideoOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::VideoOutputPort& { EXPECT_EQ(name, _T("HDMI0")); @@ -255,7 +300,7 @@ TEST_F(DeviceVideoCapabilitiesDsTest, SupportedHdcp_HDMI0_exception) { auto supportedHDCPVersion = Exchange::IDeviceVideoCapabilities::CopyProtection::HDCP_UNAVAILABLE; - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::VideoOutputPort& { EXPECT_EQ(name, _T("HDMI0")); diff --git a/Tests/tests/test_FirmwareVersion.cpp b/Tests/L1Tests/tests/test_FirmwareVersion.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_FirmwareVersion.cpp rename to Tests/L1Tests/tests/test_FirmwareVersion.cpp diff --git a/Tests/tests/test_FrameRate.cpp b/Tests/L1Tests/tests/test_FrameRate.cpp old mode 100644 new mode 100755 similarity index 85% rename from Tests/tests/test_FrameRate.cpp rename to Tests/L1Tests/tests/test_FrameRate.cpp index 0150ae8e6f..682ba7fb9f --- a/Tests/tests/test_FrameRate.cpp +++ b/Tests/L1Tests/tests/test_FrameRate.cpp @@ -32,16 +32,17 @@ class FrameRateTest : public ::testing::Test { class FrameRateInitializedTest : public FrameRateTest { protected: - NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; IARM_EventHandler_t FrameRatePreChange; IARM_EventHandler_t FrameRatePostChange; FrameRateInitializedTest() : FrameRateTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; + p_iarmBusImplMock = new NiceMock ; - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + IarmBus::setImpl(p_iarmBusImplMock); + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_DISPLAY_FRAMRATE_PRECHANGE)) { @@ -59,7 +60,12 @@ class FrameRateInitializedTest : public FrameRateTest { { plugin->Deinitialize(nullptr); - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } } }; @@ -90,22 +96,36 @@ class FrameRateInitializedEventTest : public FrameRateInitializedTest { class FrameRateDsTest : public FrameRateTest { protected: - HostImplMock hostImplMock; - VideoDeviceMock videoDeviceMock; - device::VideoDevice videoDevice; + HostImplMock *p_hostImplMock = nullptr; + VideoDeviceMock *p_videoDeviceMock = nullptr; FrameRateDsTest() : FrameRateTest() { - device::Host::getInstance().impl = &hostImplMock; - videoDevice.impl = &videoDeviceMock; + p_hostImplMock = new NiceMock ; + device::Host::setImpl(p_hostImplMock); - ON_CALL(hostImplMock, getVideoDevices()) + device::VideoDevice videoDevice; + p_videoDeviceMock = new NiceMock ; + device::VideoDevice::setImpl(p_videoDeviceMock); + + ON_CALL(*p_hostImplMock, getVideoDevices()) .WillByDefault(::testing::Return(device::List({ videoDevice }))); } virtual ~FrameRateDsTest() override { - device::Host::getInstance().impl = nullptr; + device::VideoDevice::setImpl(nullptr); + if (p_videoDeviceMock != nullptr) + { + delete p_videoDeviceMock; + p_videoDeviceMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } } }; @@ -138,7 +158,7 @@ TEST_F(FrameRateTest, setCollectionFrequency_startFpsCollection_stopFpsCollectio */ TEST_F(FrameRateDsTest, DISABLED_setFrmMode) { - ON_CALL(videoDeviceMock, setFRFMode(::testing::_)) + ON_CALL(*p_videoDeviceMock, setFRFMode(::testing::_)) .WillByDefault(::testing::Invoke( [&](int param) { EXPECT_EQ(param, 0); @@ -154,7 +174,7 @@ TEST_F(FrameRateDsTest, DISABLED_setFrmMode) */ TEST_F(FrameRateDsTest, DISABLED_getFrmMode) { - ON_CALL(videoDeviceMock, getFRFMode(::testing::_)) + ON_CALL(*p_videoDeviceMock, getFRFMode(::testing::_)) .WillByDefault(::testing::Invoke( [&](int* param) { *param = 0; @@ -170,7 +190,7 @@ TEST_F(FrameRateDsTest, DISABLED_getFrmMode) */ TEST_F(FrameRateDsTest, DISABLED_setDisplayFrameRate) { - ON_CALL(videoDeviceMock, setDisplayframerate(::testing::_)) + ON_CALL(*p_videoDeviceMock, setDisplayframerate(::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* param) { EXPECT_EQ(param, string("3840x2160px48")); @@ -186,7 +206,7 @@ TEST_F(FrameRateDsTest, DISABLED_setDisplayFrameRate) */ TEST_F(FrameRateDsTest, DISABLED_getDisplayFrameRate) { - ON_CALL(videoDeviceMock, getCurrentDisframerate(::testing::_)) + ON_CALL(*p_videoDeviceMock, getCurrentDisframerate(::testing::_)) .WillByDefault(::testing::Invoke( [&](char* param) { string framerate("3840x2160px48"); diff --git a/Tests/tests/test_FrontPanel.cpp b/Tests/L1Tests/tests/test_FrontPanel.cpp old mode 100644 new mode 100755 similarity index 84% rename from Tests/tests/test_FrontPanel.cpp rename to Tests/L1Tests/tests/test_FrontPanel.cpp index acbad09eb2..98b2988eaf --- a/Tests/tests/test_FrontPanel.cpp +++ b/Tests/L1Tests/tests/test_FrontPanel.cpp @@ -36,38 +36,46 @@ class FrontPanelTest : public ::testing::Test { class FrontPanelDsTest : public FrontPanelTest { protected: testing::NiceMock frontPanelIndicatorMock; - testing::NiceMock colorImplMock; - testing::NiceMock frontPanelTextDisplayMock; testing::NiceMock frontPanelTextDisplayIndicatorMock; - testing::NiceMock frontPanelConfigImplMock; + FrontPanelConfigMock *p_frontPanelConfigImplMock = nullptr; + FrontPanelTextDisplayMock *p_frontPanelTextDisplayMock = nullptr; FrontPanelDsTest() : FrontPanelTest() { device::FrontPanelIndicator::getInstance().impl = &frontPanelIndicatorMock; - device::FrontPanelConfig::getInstance().impl = &frontPanelConfigImplMock; - device::FrontPanelTextDisplay::getInstance().impl = &frontPanelTextDisplayMock; + p_frontPanelConfigImplMock = new testing::NiceMock ; + device::FrontPanelConfig::setImpl(p_frontPanelConfigImplMock); + p_frontPanelTextDisplayMock = new testing::NiceMock ; + device::FrontPanelTextDisplay::setImpl(p_frontPanelTextDisplayMock); device::FrontPanelTextDisplay::getInstance().FrontPanelIndicator::impl = &frontPanelTextDisplayIndicatorMock; - } virtual ~FrontPanelDsTest() override { device::FrontPanelIndicator::getInstance().impl = nullptr; - device::FrontPanelConfig::getInstance().impl = nullptr; - device::FrontPanelTextDisplay::getInstance().impl = nullptr; device::FrontPanelTextDisplay::getInstance().FrontPanelIndicator::impl = nullptr; - + if (p_frontPanelTextDisplayMock != nullptr) + { + delete p_frontPanelTextDisplayMock; + p_frontPanelTextDisplayMock = nullptr; + } + if (p_frontPanelConfigImplMock != nullptr) + { + delete p_frontPanelConfigImplMock; + p_frontPanelConfigImplMock = nullptr; + } } }; class FrontPanelInitializedTest : public FrontPanelTest { protected: - testing::NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + FrontPanelConfigMock *p_frontPanelConfigImplMock = nullptr; + FrontPanelTextDisplayMock *p_frontPanelTextDisplayMock = nullptr; + IARM_EventHandler_t dsPanelEventHandler; - testing::NiceMock frontPanelConfigImplMock; testing::NiceMock frontPanelIndicatorMock; - testing::NiceMock frontPanelTextDisplayMock; testing::NiceMock frontPanelTextDisplayIndicatorMock; IARM_EventHandler_t dsFrontPanelModeChange; @@ -76,13 +84,17 @@ class FrontPanelInitializedTest : public FrontPanelTest { : FrontPanelTest() { - - IarmBus::getInstance().impl = &iarmBusImplMock; - device::FrontPanelConfig::getInstance().impl = &frontPanelConfigImplMock; + p_iarmBusImplMock = new testing::NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + p_frontPanelConfigImplMock = new testing::NiceMock ; + device::FrontPanelConfig::setImpl(p_frontPanelConfigImplMock); + device::FrontPanelIndicator::getInstance().impl = &frontPanelIndicatorMock; - device::FrontPanelTextDisplay::getInstance().impl = &frontPanelTextDisplayMock; device::FrontPanelTextDisplay::getInstance().FrontPanelIndicator::impl = &frontPanelTextDisplayIndicatorMock; + p_frontPanelTextDisplayMock = new testing::NiceMock ; + device::FrontPanelTextDisplay::setImpl(p_frontPanelTextDisplayMock); + //Needs to be set at initiative time, as the function gets called when FrontPanel is intialized. ON_CALL(frontPanelIndicatorMock, getInstanceString) .WillByDefault(::testing::Invoke( @@ -91,12 +103,11 @@ class FrontPanelInitializedTest : public FrontPanelTest { return device::FrontPanelIndicator::getInstance(); })); - ON_CALL(frontPanelConfigImplMock, getIndicators()) + ON_CALL(*p_frontPanelConfigImplMock, getIndicators()) .WillByDefault(::testing::Return(device::List({ device::FrontPanelIndicator::getInstance() }))); - - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_PWRMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_PWRMGR_EVENT_MODECHANGED)) { @@ -111,16 +122,31 @@ class FrontPanelInitializedTest : public FrontPanelTest { } virtual ~FrontPanelInitializedTest() override { - device::FrontPanelConfig::getInstance().impl = nullptr; device::FrontPanelIndicator::getInstance().impl = nullptr; - device::FrontPanelTextDisplay::getInstance().impl = nullptr; device::FrontPanelTextDisplay::getInstance().FrontPanelIndicator::impl = nullptr; - plugin->Deinitialize(nullptr); + plugin->Deinitialize(nullptr); //Clearing out out of scope variables, and setting initDone to 0. Plugin::CFrontPanel::initDone = 0; - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::FrontPanelTextDisplay::setImpl(nullptr); + if (p_frontPanelTextDisplayMock != nullptr) + { + delete p_frontPanelTextDisplayMock; + p_frontPanelTextDisplayMock = nullptr; + } + device::FrontPanelConfig::setImpl(nullptr); + if (p_frontPanelConfigImplMock != nullptr) + { + delete p_frontPanelConfigImplMock; + p_frontPanelConfigImplMock = nullptr; + } } }; @@ -153,24 +179,29 @@ class FrontPanelInitializedEventTest : public FrontPanelInitializedTest { class FrontPanelInitializedEventDsTest : public FrontPanelInitializedEventTest { protected: - testing::NiceMock colorImplMock; + ColorMock *p_colorImplMock = nullptr ; FrontPanelInitializedEventDsTest() : FrontPanelInitializedEventTest() { - device::FrontPanelIndicator::Color::getInstance().impl = &colorImplMock; + p_colorImplMock = new testing::NiceMock ; + device::FrontPanelIndicator::Color::setImpl(p_colorImplMock); //Variable that needs to be set is set through this call IARM_Bus_PWRMgr_EventData_t eventData; eventData.data.state.newState =IARM_BUS_PWRMGR_POWERSTATE_ON; eventData.data.state.curState =IARM_BUS_PWRMGR_POWERSTATE_STANDBY; dsFrontPanelModeChange(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_EVENT_MODECHANGED, &eventData , 0); - } virtual ~FrontPanelInitializedEventDsTest() override { - device::FrontPanelIndicator::Color::getInstance().impl = nullptr; + device::FrontPanelIndicator::Color::setImpl(nullptr); + if (p_colorImplMock != nullptr) + { + delete p_colorImplMock; + p_colorImplMock = nullptr; + } } }; @@ -202,7 +233,6 @@ TEST_F(FrontPanelInitializedEventDsTest, setBrightnessWIndex) return device::FrontPanelIndicator::getInstance(); })); - ON_CALL(frontPanelIndicatorMock, getName()) .WillByDefault(::testing::Return("Power")); @@ -219,7 +249,7 @@ TEST_F(FrontPanelInitializedEventDsTest, setBrightnessWIndex) } TEST_F(FrontPanelInitializedEventDsTest, setBrightnessClock) { - ON_CALL(frontPanelTextDisplayMock, getInstanceByName) + ON_CALL(*p_frontPanelTextDisplayMock, getInstanceByName) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::FrontPanelTextDisplay& { EXPECT_EQ("Text", name); @@ -228,12 +258,12 @@ TEST_F(FrontPanelInitializedEventDsTest, setBrightnessClock) - ON_CALL(frontPanelConfigImplMock, getIndicators()) + ON_CALL(*p_frontPanelConfigImplMock, getIndicators()) .WillByDefault(::testing::Return(device::List({device::FrontPanelIndicator::getInstance()}))); ON_CALL(frontPanelIndicatorMock, getName()) .WillByDefault(::testing::Return("red")); - EXPECT_CALL(frontPanelTextDisplayMock, setTextBrightness(::testing::_)) + EXPECT_CALL(*p_frontPanelTextDisplayMock, setTextBrightness(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](int brightness) { @@ -253,7 +283,7 @@ TEST_F(FrontPanelInitializedEventDsTest, setBrightness) EXPECT_EQ("Power", name); return device::FrontPanelIndicator::getInstance(); })); - + ON_CALL(frontPanelIndicatorMock, getName()) .WillByDefault(::testing::Return("Power")); @@ -263,7 +293,6 @@ TEST_F(FrontPanelInitializedEventDsTest, setBrightness) [&](int brightness, bool toPersist) { EXPECT_EQ(brightness, 1); })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setBrightness"), _T("{\"brightness\": 1}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); @@ -302,7 +331,7 @@ TEST_F(FrontPanelInitializedEventDsTest, getBrightnessOtherName) TEST_F(FrontPanelInitializedEventDsTest, getBrightnessWIndexClock) { - ON_CALL(frontPanelTextDisplayMock, getInstanceByName) + ON_CALL(*p_frontPanelTextDisplayMock, getInstanceByName) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::FrontPanelTextDisplay& { EXPECT_EQ("Text", name); @@ -310,7 +339,7 @@ TEST_F(FrontPanelInitializedEventDsTest, getBrightnessWIndexClock) })); - ON_CALL(frontPanelTextDisplayMock, getTextBrightness()) + ON_CALL(*p_frontPanelTextDisplayMock, getTextBrightness()) .WillByDefault(::testing::Return(50)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getBrightness"), _T("{\"index\": \"clock_led\"}"), response)); @@ -335,14 +364,14 @@ TEST_F(FrontPanelInitializedEventDsTest, getBrightness) TEST_F(FrontPanelInitializedEventDsTest, getClockBrightness) { - ON_CALL(frontPanelTextDisplayMock, getInstanceByName) + ON_CALL(*p_frontPanelTextDisplayMock, getInstanceByName) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::FrontPanelTextDisplay& { EXPECT_EQ("Text", name); return device::FrontPanelTextDisplay::getInstance(); })); - ON_CALL(frontPanelTextDisplayMock, getTextBrightness()) + ON_CALL(*p_frontPanelTextDisplayMock, getTextBrightness()) .WillByDefault(::testing::Return(50)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getClockBrightness"), _T(""), response)); EXPECT_EQ(response, string("{\"brightness\":50,\"success\":true}")); @@ -351,7 +380,7 @@ TEST_F(FrontPanelInitializedEventDsTest, getClockBrightness) TEST_F(FrontPanelInitializedEventDsTest, setClockBrightness) { - ON_CALL(frontPanelTextDisplayMock, getInstanceByName) + ON_CALL(*p_frontPanelTextDisplayMock, getInstanceByName) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::FrontPanelTextDisplay& { EXPECT_EQ("Text", name); @@ -359,18 +388,17 @@ TEST_F(FrontPanelInitializedEventDsTest, setClockBrightness) })); - ON_CALL(frontPanelConfigImplMock, getIndicators()) + ON_CALL(*p_frontPanelConfigImplMock, getIndicators()) .WillByDefault(::testing::Return(device::List({device::FrontPanelIndicator::getInstance()}))); ON_CALL(frontPanelIndicatorMock, getName()) .WillByDefault(::testing::Return("red")); - EXPECT_CALL(frontPanelTextDisplayMock, setTextBrightness(::testing::_)) + EXPECT_CALL(*p_frontPanelTextDisplayMock, setTextBrightness(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](int brightness) { EXPECT_EQ(brightness, 1); })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setClockBrightness"), _T("{\"brightness\": 1}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); @@ -378,16 +406,15 @@ TEST_F(FrontPanelInitializedEventDsTest, setClockBrightness) TEST_F(FrontPanelInitializedEventDsTest, getFrontPanelLights) { - - ON_CALL(frontPanelConfigImplMock, getIndicators()) + ON_CALL(*p_frontPanelConfigImplMock, getIndicators()) .WillByDefault(::testing::Return(device::List({ device::FrontPanelIndicator::getInstance() }))); ON_CALL(frontPanelIndicatorMock, getBrightnessLevels(::testing::_,::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int &levels,int &min,int &max) { levels=1; - min=0; - max=2; + min=0; + max=2; })); ON_CALL(frontPanelTextDisplayIndicatorMock, getBrightnessLevels(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( @@ -397,17 +424,16 @@ TEST_F(FrontPanelInitializedEventDsTest, getFrontPanelLights) max = 2; })); - ON_CALL(frontPanelConfigImplMock, getTextDisplays()) + ON_CALL(*p_frontPanelConfigImplMock, getTextDisplays()) .WillByDefault(::testing::Return(device::List({ device::FrontPanelTextDisplay::getInstance() }))); ON_CALL(frontPanelTextDisplayIndicatorMock, getName()) .WillByDefault(::testing::Return("Text")); - ON_CALL(colorImplMock, getName()) + ON_CALL(*p_colorImplMock, getName()) .WillByDefault(::testing::Return("white")); - - int test = 0; + int test = 0; - ON_CALL(frontPanelConfigImplMock, getTextDisplay(test)) + ON_CALL(*p_frontPanelConfigImplMock, getTextDisplay(test)) .WillByDefault(::testing::ReturnRef(device::FrontPanelTextDisplay::getInstance())); ON_CALL(frontPanelIndicatorMock, getName()) @@ -426,19 +452,18 @@ TEST_F(FrontPanelInitializedEventDsTest, getPreferences) } TEST_F(FrontPanelInitializedEventDsTest, is24HourClock) -{ +{ std::string test = "Text"; - - ON_CALL(frontPanelConfigImplMock, getTextDisplay(test)) + ON_CALL(*p_frontPanelConfigImplMock, getTextDisplay(test)) .WillByDefault(::testing::ReturnRef(device::FrontPanelTextDisplay::getInstance())); - ON_CALL(frontPanelTextDisplayMock, getCurrentTimeFormat()) + ON_CALL(*p_frontPanelTextDisplayMock, getCurrentTimeFormat()) .WillByDefault(::testing::Return(dsFPD_TIME_12_HOUR)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("is24HourClock"), _T(""), response)); EXPECT_EQ(response, string("{\"is24Hour\":false,\"success\":true}")); - ON_CALL(frontPanelTextDisplayMock, getCurrentTimeFormat()) + ON_CALL(*p_frontPanelTextDisplayMock, getCurrentTimeFormat()) .WillByDefault(::testing::Return(dsFPD_TIME_24_HOUR)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("is24HourClock"), _T(""), response)); @@ -511,7 +536,7 @@ TEST_F(FrontPanelInitializedEventDsTest, powerLedOffRecord) TEST_F(FrontPanelInitializedEventDsTest, powerLedOnPower) { - ON_CALL(frontPanelConfigImplMock, getIndicators()) + ON_CALL(*p_frontPanelConfigImplMock, getIndicators()) .WillByDefault(::testing::Return(device::List({device::FrontPanelIndicator::getInstance()}))); ON_CALL(frontPanelIndicatorMock, getName()) .WillByDefault(::testing::Return("red")); @@ -551,11 +576,11 @@ TEST_F(FrontPanelInitializedEventDsTest, set24HourClock) { std::string test = "Text"; - ON_CALL(frontPanelConfigImplMock, getTextDisplay(test)) + ON_CALL(*p_frontPanelConfigImplMock, getTextDisplay(test)) .WillByDefault(::testing::ReturnRef(device::FrontPanelTextDisplay::getInstance())); - ON_CALL(frontPanelTextDisplayMock, getCurrentTimeFormat()) + ON_CALL(*p_frontPanelTextDisplayMock, getCurrentTimeFormat()) .WillByDefault(::testing::Return(dsFPD_TIME_24_HOUR)); - EXPECT_CALL(frontPanelTextDisplayMock, setTimeFormat(::testing::_)) + EXPECT_CALL(*p_frontPanelTextDisplayMock, setTimeFormat(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](const int iTimeFormat) { @@ -579,7 +604,7 @@ TEST_F(FrontPanelInitializedEventDsTest, setBlink) ON_CALL(frontPanelIndicatorMock, getBrightness()) .WillByDefault(::testing::Return(50)); - ON_CALL(frontPanelTextDisplayMock, getTextBrightness()) + ON_CALL(*p_frontPanelTextDisplayMock, getTextBrightness()) .WillByDefault(::testing::Return(50)); ON_CALL(frontPanelIndicatorMock, getName()) @@ -589,13 +614,11 @@ TEST_F(FrontPanelInitializedEventDsTest, setBlink) .Times(1) .WillOnce(::testing::Invoke( [&](uint32_t color, bool persist) { - EXPECT_EQ(color, 131586); })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setBlink"), _T("{\"blinkInfo\": {\"ledIndicator\": \"power_led\", \"iterations\": 10, \"pattern\": [{\"brightness\": 50, \"duration\": 100, \"red\": 2, \"green\":2, \"blue\":2}]}}"), response)); - - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(FrontPanelInitializedEventDsTest, setClockTestPattern) @@ -608,11 +631,7 @@ TEST_F(FrontPanelInitializedEventDsTest, setClockTestPattern) return device::FrontPanelIndicator::getInstance(); })); - - testing::NiceMock colorMock; - device::FrontPanelIndicator::Color::getInstance().impl = &colorMock; - - ON_CALL(colorMock, getInstanceByName) + ON_CALL(*p_colorImplMock, getInstanceByName) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::FrontPanelIndicator::Color& { EXPECT_EQ("red", name); @@ -621,15 +640,13 @@ TEST_F(FrontPanelInitializedEventDsTest, setClockTestPattern) std::string test = "Text"; - ON_CALL(frontPanelConfigImplMock, getTextDisplay(test)) + ON_CALL(*p_frontPanelConfigImplMock, getTextDisplay(test)) .WillByDefault(::testing::ReturnRef(device::FrontPanelTextDisplay::getInstance())); - ON_CALL(frontPanelTextDisplayMock, getTextBrightness()) + ON_CALL(*p_frontPanelTextDisplayMock, getTextBrightness()) .WillByDefault(::testing::Return(100)); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setClockTestPattern"), _T("{\"show\": true, \"timeInterval\": 4}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setClockTestPattern"), _T("{\"show\": false, \"timeInterval\": 4}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); @@ -647,7 +664,7 @@ TEST_F(FrontPanelInitializedEventDsTest, setLEDMode1) ON_CALL(frontPanelIndicatorMock, getName()) .WillByDefault(::testing::Return("Power")); - + EXPECT_CALL(frontPanelIndicatorMock, setColorInt(::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( @@ -668,7 +685,6 @@ TEST_F(FrontPanelInitializedEventDsTest, setLEDMode2) EXPECT_EQ("Power", name); return device::FrontPanelIndicator::getInstance(); })); - EXPECT_CALL(frontPanelIndicatorMock, setColorInt(::testing::_, ::testing::_)) .Times(1) diff --git a/Tests/tests/test_HdcpProfile.cpp b/Tests/L1Tests/tests/test_HdcpProfile.cpp old mode 100644 new mode 100755 similarity index 74% rename from Tests/tests/test_HdcpProfile.cpp rename to Tests/L1Tests/tests/test_HdcpProfile.cpp index 97562e5d25..e72311f9e0 --- a/Tests/tests/test_HdcpProfile.cpp +++ b/Tests/L1Tests/tests/test_HdcpProfile.cpp @@ -36,19 +36,40 @@ class HDCPProfileTest : public ::testing::Test { class HDCPProfileDsTest : public HDCPProfileTest { protected: - NiceMock hostImplMock; - NiceMock videoOutputPortConfigImplMock; + HostImplMock *p_hostImplMock = nullptr ; + VideoOutputPortConfigImplMock *p_videoOutputPortConfigImplMock = nullptr ; + VideoOutputPortMock *p_videoOutputPortMock = nullptr ; HDCPProfileDsTest() : HDCPProfileTest() { - device::Host::getInstance().impl = &hostImplMock; - device::VideoOutputPortConfig::getInstance().impl = &videoOutputPortConfigImplMock; + p_hostImplMock = new NiceMock ; + device::Host::setImpl(p_hostImplMock); + p_videoOutputPortConfigImplMock = new NiceMock ; + device::VideoOutputPortConfig::setImpl(p_videoOutputPortConfigImplMock); + p_videoOutputPortMock = new NiceMock ; + device::VideoOutputPort::setImpl(p_videoOutputPortMock); } virtual ~HDCPProfileDsTest() override { - device::Host::getInstance().impl = nullptr; - device::VideoOutputPortConfig::getInstance().impl = nullptr; + device::VideoOutputPort::setImpl(nullptr); + if (p_videoOutputPortMock != nullptr) + { + delete p_videoOutputPortMock; + p_videoOutputPortMock = nullptr; + } + device::VideoOutputPortConfig::setImpl(nullptr); + if (p_videoOutputPortConfigImplMock != nullptr) + { + delete p_videoOutputPortConfigImplMock; + p_videoOutputPortConfigImplMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } } }; @@ -80,21 +101,23 @@ class HDCPProfileEventTest : public HDCPProfileDsTest { class HDCPProfileEventIarmTest : public HDCPProfileEventTest { protected: - NiceMock iarmBusImplMock; - ManagerImplMock managerImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ManagerImplMock *p_managerImplMock = nullptr ; IARM_EventHandler_t dsHdmiEventHandler; HDCPProfileEventIarmTest() : HDCPProfileEventTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; - device::Manager::getInstance().impl = &managerImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + p_managerImplMock = new NiceMock ; + device::Manager::setImpl(p_managerImplMock); - EXPECT_CALL(managerImplMock, Initialize()) + EXPECT_CALL(*p_managerImplMock, Initialize()) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Return()); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG)) { @@ -112,8 +135,18 @@ class HDCPProfileEventIarmTest : public HDCPProfileEventTest { virtual ~HDCPProfileEventIarmTest() override { plugin->Deinitialize(&service); - IarmBus::getInstance().impl = nullptr; - device::Manager::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } } }; @@ -125,28 +158,25 @@ TEST_F(HDCPProfileTest, RegisteredMethods) TEST_F(HDCPProfileDsTest, getHDCPStatus_isConnected_false) { - NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - string videoPort(_T("HDMI0")); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); - ON_CALL(videoOutputPortMock, isDisplayConnected()) + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) .WillByDefault(::testing::Return(false)); - ON_CALL(videoOutputPortMock, getHDCPProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(videoOutputPortMock, getHDCPStatus()) + ON_CALL(*p_videoOutputPortMock, getHDCPStatus()) .WillByDefault(::testing::Return(dsHDCP_STATUS_UNPOWERED)); - ON_CALL(videoOutputPortMock, isContentProtected()) + ON_CALL(*p_videoOutputPortMock, isContentProtected()) .WillByDefault(::testing::Return(0)); - ON_CALL(videoOutputPortMock, getHDCPReceiverProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPReceiverProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_MAX)); - ON_CALL(videoOutputPortMock, getHDCPCurrentProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPCurrentProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_MAX)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getHDCPStatus"), _T(""), response)); @@ -169,26 +199,24 @@ TEST_F(HDCPProfileDsTest, getHDCPStatus_isConnected_true) { NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - string videoPort(_T("HDMI0")); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); - ON_CALL(videoOutputPortMock, isDisplayConnected()) + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) .WillByDefault(::testing::Return(true)); - ON_CALL(videoOutputPortMock, getHDCPProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(videoOutputPortMock, getHDCPStatus()) + ON_CALL(*p_videoOutputPortMock, getHDCPStatus()) .WillByDefault(::testing::Return(dsHDCP_STATUS_AUTHENTICATED)); - ON_CALL(videoOutputPortMock, isContentProtected()) + ON_CALL(*p_videoOutputPortMock, isContentProtected()) .WillByDefault(::testing::Return(true)); - ON_CALL(videoOutputPortMock, getHDCPReceiverProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPReceiverProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(videoOutputPortMock, getHDCPCurrentProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPCurrentProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getHDCPStatus"), _T(""), response)); @@ -211,16 +239,14 @@ TEST_F(HDCPProfileDsTest, getSettopHDCPSupport_Hdcp_v1x) { NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - string videoPort(_T("HDMI0")); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); - ON_CALL(videoOutputPortMock, getHDCPProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_1X)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSettopHDCPSupport"), _T(""), response)); @@ -235,16 +261,14 @@ TEST_F(HDCPProfileDsTest, getSettopHDCPSupport_Hdcp_v2x) { NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - string videoPort(_T("HDMI0")); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); - ON_CALL(videoOutputPortMock, getHDCPProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSettopHDCPSupport"), _T(""), response)); @@ -263,26 +287,24 @@ TEST_F(HDCPProfileEventIarmTest, onDisplayConnectionChanged) NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; - string videoPort(_T("HDMI0")); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); - ON_CALL(videoOutputPortMock, isDisplayConnected()) + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) .WillByDefault(::testing::Return(true)); - ON_CALL(videoOutputPortMock, getHDCPProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(videoOutputPortMock, getHDCPStatus()) + ON_CALL(*p_videoOutputPortMock, getHDCPStatus()) .WillByDefault(::testing::Return(dsHDCP_STATUS_AUTHENTICATED)); - ON_CALL(videoOutputPortMock, isContentProtected()) + ON_CALL(*p_videoOutputPortMock, isContentProtected()) .WillByDefault(::testing::Return(true)); - ON_CALL(videoOutputPortMock, getHDCPReceiverProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPReceiverProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(videoOutputPortMock, getHDCPCurrentProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPCurrentProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) @@ -334,27 +356,26 @@ TEST_F(HDCPProfileEventIarmTest, onHdmiOutputHDCPStatusEvent) NiceMock videoOutputPortMock; device::VideoOutputPort videoOutputPort; - videoOutputPort.impl = &videoOutputPortMock; string videoPort(_T("HDMI0")); - ON_CALL(hostImplMock, getDefaultVideoPortName()) + ON_CALL(*p_hostImplMock, getDefaultVideoPortName()) .WillByDefault(::testing::Return(videoPort)); - ON_CALL(videoOutputPortConfigImplMock, getPort(::testing::_)) + ON_CALL(*p_videoOutputPortConfigImplMock, getPort(::testing::_)) .WillByDefault(::testing::ReturnRef(videoOutputPort)); - ON_CALL(videoOutputPortMock, isDisplayConnected()) + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) .WillByDefault(::testing::Return(true)); - ON_CALL(videoOutputPortMock, getHDCPProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(videoOutputPortMock, getHDCPStatus()) + ON_CALL(*p_videoOutputPortMock, getHDCPStatus()) .WillByDefault(::testing::Return(dsHDCP_STATUS_AUTHENTICATED)); - ON_CALL(videoOutputPortMock, isContentProtected()) + ON_CALL(*p_videoOutputPortMock, isContentProtected()) .WillByDefault(::testing::Return(true)); - ON_CALL(videoOutputPortMock, getHDCPReceiverProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPReceiverProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - ON_CALL(videoOutputPortMock, getHDCPCurrentProtocol()) + ON_CALL(*p_videoOutputPortMock, getHDCPCurrentProtocol()) .WillByDefault(::testing::Return(dsHDCP_VERSION_2X)); - + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( @@ -377,19 +398,19 @@ TEST_F(HDCPProfileEventIarmTest, onHdmiOutputHDCPStatusEvent) "\"currentHDCPVersion\":\"2.2\"" "\\}" "\\}" - "\\}"))); + "\\}"))); onDisplayConnectionChanged.SetEvent(); return Core::ERROR_NONE; })); - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARM_BUS_PWRMGR_API_GetPowerState) == 0) { auto* param = static_cast(arg); - param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; + param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; } return IARM_RESULT_SUCCESS; }); diff --git a/Tests/tests/test_HdmiCec.cpp b/Tests/L1Tests/tests/test_HdmiCec.cpp old mode 100644 new mode 100755 similarity index 82% rename from Tests/tests/test_HdmiCec.cpp rename to Tests/L1Tests/tests/test_HdmiCec.cpp index 00e12f70bf..c3b4610b56 --- a/Tests/tests/test_HdmiCec.cpp +++ b/Tests/L1Tests/tests/test_HdmiCec.cpp @@ -29,6 +29,7 @@ #include "devicesettings.h" #include "HdmiCecMock.h" using namespace WPEFramework; +using ::testing::NiceMock; class HdmiCecTest : public ::testing::Test { protected: @@ -47,38 +48,56 @@ class HdmiCecTest : public ::testing::Test { }; class HdmiCecDsTest : public HdmiCecTest { protected: - testing::NiceMock libCCECImplMock; - testing::NiceMock connectionImplMock; + LibCCECImplMock *p_libCCECImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; HdmiCecDsTest() : HdmiCecTest() { - LibCCEC::getInstance().impl = &libCCECImplMock; - Connection::getInstance().impl = &connectionImplMock; + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + + p_connectionImplMock = new testing::NiceMock ; + Connection::setImpl(p_connectionImplMock); + } virtual ~HdmiCecDsTest() override { - LibCCEC::getInstance().impl = nullptr; - Connection::getInstance().impl = nullptr; + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + Connection::setImpl(nullptr); + if (p_connectionImplMock != nullptr) + { + delete p_connectionImplMock; + p_connectionImplMock = nullptr; + } } }; class HdmiCecInitializedTest : public HdmiCecTest { protected: - testing::NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; IARM_EventHandler_t cecMgrEventHandler; IARM_EventHandler_t dsHdmiEventHandler; - testing::NiceMock libCCECImplMock; - testing::NiceMock connectionImplMock; - - + LibCCECImplMock *p_libCCECImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; + HdmiCecInitializedTest() : HdmiCecTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; - LibCCEC::getInstance().impl = &libCCECImplMock; - Connection::getInstance().impl = &connectionImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + + p_connectionImplMock = new testing::NiceMock ; + Connection::setImpl(p_connectionImplMock); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_DAEMON_INITIALIZED)) { @@ -107,9 +126,24 @@ class HdmiCecInitializedTest : public HdmiCecTest { { plugin->Deinitialize(nullptr); - IarmBus::getInstance().impl = nullptr; - LibCCEC::getInstance().impl = nullptr; - Connection::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + Connection::setImpl(nullptr); + if (p_connectionImplMock != nullptr) + { + delete p_connectionImplMock; + p_connectionImplMock = nullptr; + } //Turning off HdmiCec. otherwise we get segementation faults as things memory early while threads are still running EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": false}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); @@ -122,12 +156,11 @@ class HdmiCecInitializedEventTest : public HdmiCecInitializedTest { Core::JSONRPC::Message message; FactoriesImplementation factoriesImplementation; PluginHost::IDispatcher* dispatcher; - HdmiCecInitializedEventTest() : HdmiCecInitializedTest() { - PluginHost::IFactories::Assign(&factoriesImplementation); + PluginHost::IFactories::Assign(&factoriesImplementation); dispatcher = static_cast( plugin->QueryInterface(PluginHost::IDispatcher::ID)); @@ -193,7 +226,7 @@ TEST_F(HdmiCecInitializedTest, getActiveSourceStatusFalse) TEST_F(HdmiCecInitializedTest, getCECAddress) { - EXPECT_CALL(libCCECImplMock, getPhysicalAddress(::testing::_)) + EXPECT_CALL(*p_libCCECImplMock, getPhysicalAddress(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](uint32_t *physAddress) { @@ -214,7 +247,7 @@ TEST_F(HdmiCecInitializedTest, getCECAddress) TEST_F(HdmiCecInitializedEventTest, cecAddressesChanged) { - EXPECT_CALL(libCCECImplMock, getPhysicalAddress(::testing::_)) + EXPECT_CALL(*p_libCCECImplMock, getPhysicalAddress(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](uint32_t *physAddress) { diff --git a/Tests/tests/test_HdmiCec2.cpp b/Tests/L1Tests/tests/test_HdmiCec2.cpp old mode 100644 new mode 100755 similarity index 76% rename from Tests/tests/test_HdmiCec2.cpp rename to Tests/L1Tests/tests/test_HdmiCec2.cpp index a237057583..5852829a1c --- a/Tests/tests/test_HdmiCec2.cpp +++ b/Tests/L1Tests/tests/test_HdmiCec2.cpp @@ -57,76 +57,95 @@ class HdmiCec_2Test : public ::testing::Test { }; class HdmiCec_2DsTest : public HdmiCec_2Test { protected: - testing::NiceMock libCCECImplMock; - testing::NiceMock connectionImplMock; + LibCCECImplMock *p_libCCECImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; HdmiCec_2DsTest() : HdmiCec_2Test() { - LibCCEC::getInstance().impl = &libCCECImplMock; + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); } virtual ~HdmiCec_2DsTest() override { - LibCCEC::getInstance().impl = nullptr; + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } } }; class HdmiCec_2InitializedTest : public HdmiCec_2Test { protected: - testing::NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ManagerImplMock *p_managerImplMock = nullptr ; + HostImplMock *p_hostImplMock = nullptr ; + LibCCECImplMock *p_libCCECImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; + VideoOutputPortMock *p_videoOutputPortMock = nullptr ; + MessageEncoderMock *p_messageEncoderMock = nullptr ; + IARM_EventHandler_t cecMgrEventHandler; IARM_EventHandler_t dsHdmiEventHandler; IARM_EventHandler_t pwrMgrEventHandler; - testing::NiceMock libCCECImplMock; - - testing::NiceMock managerImplMock; - testing::NiceMock hostImplMock; - - testing::NiceMock connectionImplMock; - testing::NiceMock videoOutputPortMock; - testing::NiceMock messageEncoderMock; - testing::NiceMock displayMock; - + DisplayMock *p_displayMock = nullptr ; HdmiCec_2InitializedTest() : HdmiCec_2Test() { - IarmBus::getInstance().impl = &iarmBusImplMock; - device::Manager::getInstance().impl = &managerImplMock; - device::Host::getInstance().impl = &hostImplMock; - LibCCEC::getInstance().impl = &libCCECImplMock; - MessageEncoder::getInstance().impl = &messageEncoderMock; - Connection::getInstance().impl = &connectionImplMock; - device::VideoOutputPort::getInstance().impl = &videoOutputPortMock;; - device::Display::getInstance().impl = &displayMock; + p_iarmBusImplMock = new testing::NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_hostImplMock = new testing::NiceMock ; + device::Host::setImpl(p_hostImplMock); + + p_managerImplMock = new testing::NiceMock ; + device::Manager::setImpl(p_managerImplMock); + + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + + p_messageEncoderMock = new testing::NiceMock ; + MessageEncoder::setImpl(p_messageEncoderMock); + + p_connectionImplMock = new testing::NiceMock ; + Connection::setImpl(p_connectionImplMock); + + p_videoOutputPortMock = new testing::NiceMock ; + device::VideoOutputPort::setImpl(p_videoOutputPortMock); + + p_displayMock = new testing::NiceMock ; + device::Display::setImpl(p_displayMock); //OnCall required for intialize to run properly - ON_CALL(hostImplMock, getVideoOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(device::VideoOutputPort::getInstance())); - ON_CALL(videoOutputPortMock, getDisplay()) + ON_CALL(*p_videoOutputPortMock, getDisplay()) .WillByDefault(::testing::ReturnRef(device::Display::getInstance())); - ON_CALL(videoOutputPortMock, isDisplayConnected()) + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) .WillByDefault(::testing::Return(true)); - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::ReturnRef(CECFrame::getInstance())); - ON_CALL(displayMock, getEDIDBytes(::testing::_)) + ON_CALL(*p_displayMock, getEDIDBytes(::testing::_)) .WillByDefault(::testing::Invoke( [&](std::vector &edidVec2) { edidVec2 = std::vector({ 't', 'e', 's', 't' }); - })); + })); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_DAEMON_INITIALIZED)) { EXPECT_TRUE(handler != nullptr); cecMgrEventHandler = handler; } - if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_STATUS_UPDATED)) { + if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_STATUS_UPDATED)) { EXPECT_TRUE(handler != nullptr); cecMgrEventHandler = handler; } @@ -142,12 +161,12 @@ class HdmiCec_2InitializedTest : public HdmiCec_2Test { return IARM_RESULT_SUCCESS; })); - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARM_BUS_PWRMGR_API_GetPowerState) == 0) { auto* param = static_cast(arg); - param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; + param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; } return IARM_RESULT_SUCCESS; }); @@ -155,35 +174,74 @@ class HdmiCec_2InitializedTest : public HdmiCec_2Test { EXPECT_EQ(string(""), plugin->Initialize(nullptr)); //Set enabled needs to be - ON_CALL(libCCECImplMock, getLogicalAddress(::testing::_)) + ON_CALL(*p_libCCECImplMock, getLogicalAddress(::testing::_)) .WillByDefault(::testing::Return(1)); - ON_CALL(connectionImplMock, open()) + ON_CALL(*p_connectionImplMock, open()) .WillByDefault(::testing::Return()); - ON_CALL(connectionImplMock, addFrameListener(::testing::_)) + ON_CALL(*p_connectionImplMock, addFrameListener(::testing::_)) .WillByDefault(::testing::Return()); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": true}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); - + } virtual ~HdmiCec_2InitializedTest() override { int lCounter = 0; while ((Plugin::HdmiCec_2::_instance->deviceList[0].m_isOSDNameUpdated) && (lCounter < (2*10))) { //sleep for 2sec. - usleep (100 * 1000); //sleep for 100 milli sec - lCounter ++; - } + usleep (100 * 1000); //sleep for 100 milli sec + lCounter ++; + } EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": false}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); plugin->Deinitialize(nullptr); - device::Manager::getInstance().impl = nullptr; - device::Host::getInstance().impl = nullptr; - LibCCEC::getInstance().impl = nullptr; - MessageEncoder::getInstance().impl = nullptr; - IarmBus::getInstance().impl = nullptr; - Connection::getInstance().impl = nullptr; - device::Display::getInstance().impl = nullptr; - - + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + device::Display::setImpl(nullptr); + if (p_displayMock != nullptr) + { + delete p_displayMock; + p_displayMock = nullptr; + } + device::VideoOutputPort::setImpl(nullptr); + if (p_videoOutputPortMock != nullptr) + { + delete p_videoOutputPortMock; + p_videoOutputPortMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + Connection::setImpl(nullptr); + if (p_connectionImplMock != nullptr) + { + delete p_connectionImplMock; + p_connectionImplMock = nullptr; + } + MessageEncoder::setImpl(nullptr); + if (p_messageEncoderMock != nullptr) + { + delete p_messageEncoderMock; + p_messageEncoderMock = nullptr; + } } }; @@ -193,12 +251,11 @@ class HdmiCec_2InitializedEventTest : public HdmiCec_2InitializedTest { Core::JSONRPC::Message message; FactoriesImplementation factoriesImplementation; PluginHost::IDispatcher* dispatcher; - HdmiCec_2InitializedEventTest() : HdmiCec_2InitializedTest() { - PluginHost::IFactories::Assign(&factoriesImplementation); + PluginHost::IFactories::Assign(&factoriesImplementation); dispatcher = static_cast( plugin->QueryInterface(PluginHost::IDispatcher::ID)); @@ -210,7 +267,7 @@ class HdmiCec_2InitializedEventTest : public HdmiCec_2InitializedTest { dispatcher->Deactivate(); dispatcher->Release(); PluginHost::IFactories::Assign(nullptr); - + } }; @@ -230,7 +287,7 @@ TEST_F(HdmiCec_2Test, RegisteredMethods) EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOSDName"))); EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOTPEnabled"))); EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setVendorId"))); - + } TEST_F(HdmiCec_2DsTest, getEnabledFalse) @@ -256,7 +313,7 @@ TEST_F(HdmiCec_2InitializedTest, getActiveSourceStatusTrue) EXPECT_EQ(response, string("{\"success\":true}")); //Sets Activesource to true - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("performOTPAction"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("performOTPAction"), _T("{\"enabled\": true}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); @@ -275,13 +332,13 @@ TEST_F(HdmiCec_2InitializedTest, getActiveSourceStatusFalse) TEST_F(HdmiCec_2InitializedTest, getDeviceList) -{ +{ int iCounter = 0; //Checking to see if one of the values has been filled in (as the rest get filled in at the same time, and waiting if its not. while ((!Plugin::HdmiCec_2::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. - usleep (100 * 1000); //sleep for 100 milli sec - iCounter ++; - } + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } const char* val = "TEST"; OSDName name = OSDName(val); @@ -298,7 +355,6 @@ TEST_F(HdmiCec_2InitializedTest, getDeviceList) proc.process(osdName, header); //calls the process that sets osdName for LogicalAddress = 1 proc.process(vendorid, header); //calls the process that sets vendorID for LogicalAddress = 1 - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"osdName\":\"TEST\",\"vendorID\":\"123\"},{\"logicalAddress\":2,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":3,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":4,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":5,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":6,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":7,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":8,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":9,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":10,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":11,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":12,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":13,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":14,\"osdName\":\"NA\",\"vendorID\":\"000\"}],\"success\":true}"))); @@ -316,7 +372,6 @@ TEST_F(HdmiCec_2InitializedTest, getOTPEnabled) EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOTPEnabled"), _T("{}"), response)); EXPECT_EQ(response, string("{\"enabled\":true,\"success\":true}")); - } @@ -359,22 +414,20 @@ TEST_F(HdmiCec_2InitializedTest, setOTPEnabled) } - - TEST_F(HdmiCec_2InitializedTest, sendKeyPressEventUp) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_VOLUME_UP ); return CECFrame::getInstance(); })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 65}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent2) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_VOLUME_DOWN ); @@ -386,7 +439,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent2) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent3) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_MUTE ); @@ -397,7 +450,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent3) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent4) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_UP ); @@ -408,7 +461,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent4) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent5) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_DOWN ); @@ -416,11 +469,11 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent5) })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 2}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); - + } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent6) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_LEFT ); @@ -432,7 +485,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent6) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent7) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_RIGHT ); @@ -444,7 +497,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent7) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent8) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_SELECT ); @@ -455,7 +508,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent8) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent9) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_HOME ); @@ -467,7 +520,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent9) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent10) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_BACK ); @@ -479,7 +532,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent10) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent11) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_0 ); @@ -491,7 +544,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent11) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent12) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_1 ); @@ -503,7 +556,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent12) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent13) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_2 ); @@ -515,7 +568,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent13) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent14) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_3 ); @@ -527,7 +580,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent14) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent15) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_4 ); @@ -539,7 +592,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent15) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent16) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_5 ); @@ -551,7 +604,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent16) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent17) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_6 ); @@ -563,7 +616,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent17) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent18) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_7 ); @@ -576,7 +629,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent18) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent19) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_8 ); @@ -588,7 +641,7 @@ TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent19) } TEST_F(HdmiCec_2InitializedTest, sendKeyPressEvent20) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_9 ); diff --git a/Tests/tests/test_HdmiCecSink.cpp b/Tests/L1Tests/tests/test_HdmiCecSink.cpp old mode 100644 new mode 100755 similarity index 82% rename from Tests/tests/test_HdmiCecSink.cpp rename to Tests/L1Tests/tests/test_HdmiCecSink.cpp index ce71bb3ed3..89e7023ef9 --- a/Tests/tests/test_HdmiCecSink.cpp +++ b/Tests/L1Tests/tests/test_HdmiCecSink.cpp @@ -14,13 +14,15 @@ using ::testing::NiceMock; class HdmiCecSinkTest : public ::testing::Test { protected: + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ConnectionImplMock *p_connectionImplMock = nullptr ; + MessageEncoderMock *p_messageEncoderMock = nullptr ; + LibCCECImplMock *p_libCCECImplMock = nullptr ; + RfcApiImplMock *p_rfcApiImplMock = nullptr ; + WrapsImplMock *p_wrapsImplMock = nullptr ; Core::ProxyType plugin; Core::JSONRPC::Handler& handler; Core::JSONRPC::Connection connection; - NiceMock libCCECImplMock; - NiceMock iarmBusImplMock; - NiceMock connectionImplMock; - NiceMock messageEncoderMock; NiceMock rfcApiImplMock; NiceMock wrapsImplMock; IARM_EventHandler_t pwrMgrModeChangeEventHandler; @@ -33,32 +35,43 @@ class HdmiCecSinkTest : public ::testing::Test { , handler(*(plugin)) , connection(1, 0) { - IarmBus::getInstance().impl = &iarmBusImplMock; - LibCCEC::getInstance().impl = &libCCECImplMock; - Connection::getInstance().impl = &connectionImplMock; - MessageEncoder::getInstance().impl = &messageEncoderMock; - RfcApi::getInstance().impl = &rfcApiImplMock; - Wraps::getInstance().impl = &wrapsImplMock; /*Set up mock for fopen; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + + p_messageEncoderMock = new testing::NiceMock ; + MessageEncoder::setImpl(p_messageEncoderMock); + + p_connectionImplMock = new testing::NiceMock ; + Connection::setImpl(p_connectionImplMock); + + p_rfcApiImplMock = new testing::NiceMock ; + RfcApi::setImpl(p_rfcApiImplMock); + + p_wrapsImplMock = new testing::NiceMock ; + Wraps::setImpl(p_wrapsImplMock); /*Set up mock for fopen; to use the mock implementation/the default behavior of the fopen function from Wraps class.*/ - ON_CALL(connectionImplMock, poll(::testing::_, ::testing::_)) + ON_CALL(*p_connectionImplMock, poll(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const LogicalAddress &from, const Throw_e &doThrow) { throw CECNoAckException(); })); - EXPECT_CALL(libCCECImplMock, getPhysicalAddress(::testing::_)) + EXPECT_CALL(*p_libCCECImplMock, getPhysicalAddress(::testing::_)) .WillRepeatedly(::testing::Invoke( [&](uint32_t *physAddress) { *physAddress = (uint32_t)0x12345678; })); - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::ReturnRef(CECFrame::getInstance())); - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::ReturnRef(CECFrame::getInstance())); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_PWRMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_PWRMGR_EVENT_MODECHANGED)) { @@ -76,7 +89,7 @@ class HdmiCecSinkTest : public ::testing::Test { return IARM_RESULT_SUCCESS; })); - ON_CALL(connectionImplMock, open()) + ON_CALL(*p_connectionImplMock, open()) .WillByDefault(::testing::Return()); EXPECT_EQ(string(""), plugin->Initialize(nullptr)); @@ -85,22 +98,55 @@ class HdmiCecSinkTest : public ::testing::Test { virtual ~HdmiCecSinkTest() override { plugin->Deinitialize(nullptr); - IarmBus::getInstance().impl = nullptr; - LibCCEC::getInstance().impl = nullptr; - Connection::getInstance().impl = nullptr; - MessageEncoder::getInstance().impl = nullptr; - RfcApi::getInstance().impl = nullptr; - Wraps::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + Connection::setImpl(nullptr); + if (p_connectionImplMock != nullptr) + { + delete p_connectionImplMock; + p_connectionImplMock = nullptr; + } + MessageEncoder::setImpl(nullptr); + if (p_messageEncoderMock != nullptr) + { + delete p_messageEncoderMock; + p_messageEncoderMock = nullptr; + } + + RfcApi::setImpl(nullptr); + if (p_rfcApiImplMock != nullptr) + { + delete p_rfcApiImplMock; + p_rfcApiImplMock = nullptr; + } + + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + } }; class HdmiCecSinkDsTest : public HdmiCecSinkTest { protected: string response; - + HdmiCecSinkDsTest(): HdmiCecSinkTest() { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARM_BUS_PWRMGR_API_GetPowerState) == 0) { @@ -123,7 +169,7 @@ class HdmiCecSinkDsTest : public HdmiCecSinkTest { } return IARM_RESULT_SUCCESS; }); - + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": true}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); } @@ -225,7 +271,7 @@ TEST_F(HdmiCecSinkDsTest, setActivePathMissingParam) TEST_F(HdmiCecSinkDsTest, setActivePath) { - EXPECT_CALL(connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) .WillRepeatedly(::testing::Invoke( [&](const LogicalAddress &to, const CECFrame &frame, int timeout) { EXPECT_EQ(to.toInt(), LogicalAddress::BROADCAST); @@ -246,7 +292,7 @@ TEST_F(HdmiCecSinkDsTest, setRoutingChange) { std::this_thread::sleep_for(std::chrono::seconds(30)); - EXPECT_CALL(connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) .WillRepeatedly(::testing::Invoke( [&](const LogicalAddress &to, const CECFrame &frame, int timeout) { EXPECT_EQ(to.toInt(), LogicalAddress::BROADCAST); @@ -265,7 +311,7 @@ TEST_F(HdmiCecSinkDsTest, setMenuLanguageInvalidParam) TEST_F(HdmiCecSinkDsTest, setMenuLanguage) { - EXPECT_CALL(connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_connectionImplMock, sendTo(::testing::_, ::testing::_, ::testing::_)) .WillRepeatedly(::testing::Invoke( [&](const LogicalAddress &to, const CECFrame &frame, int timeout) { EXPECT_LE(to.toInt(), LogicalAddress::BROADCAST); @@ -329,7 +375,7 @@ TEST_F(HdmiCecSinkInitializedEventDsTest, HdmiCecEnableStatus) ASSERT_TRUE(dsHdmiCecSinkEventHandler != nullptr); IARM_Bus_CECMgr_Status_Updated_Param_t eventData; dsHdmiCecSinkEventHandler(IARM_BUS_CECMGR_NAME, IARM_BUS_CECMGR_EVENT_DAEMON_INITIALIZED, &eventData , 0); - + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getEnabled"), _T("{}"), response)); EXPECT_EQ(response, string("{\"enabled\":true,\"success\":true}")); } diff --git a/Tests/tests/test_HdmiCecSource.cpp b/Tests/L1Tests/tests/test_HdmiCecSource.cpp old mode 100644 new mode 100755 similarity index 76% rename from Tests/tests/test_HdmiCecSource.cpp rename to Tests/L1Tests/tests/test_HdmiCecSource.cpp index 6eb6e3c968..5449d8fc2d --- a/Tests/tests/test_HdmiCecSource.cpp +++ b/Tests/L1Tests/tests/test_HdmiCecSource.cpp @@ -57,76 +57,96 @@ class HdmiCecSourceTest : public ::testing::Test { }; class HdmiCecSourceDsTest : public HdmiCecSourceTest { protected: - testing::NiceMock libCCECImplMock; - testing::NiceMock connectionImplMock; + LibCCECImplMock *p_libCCECImplMock = nullptr ; + HdmiCecSourceDsTest() : HdmiCecSourceTest() { - LibCCEC::getInstance().impl = &libCCECImplMock; + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); } virtual ~HdmiCecSourceDsTest() override { - LibCCEC::getInstance().impl = nullptr; + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } } }; class HdmiCecSourceInitializedTest : public HdmiCecSourceTest { protected: - testing::NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; IARM_EventHandler_t cecMgrEventHandler; IARM_EventHandler_t dsHdmiEventHandler; IARM_EventHandler_t pwrMgrEventHandler; - testing::NiceMock libCCECImplMock; + LibCCECImplMock *p_libCCECImplMock = nullptr ; - testing::NiceMock managerImplMock; - testing::NiceMock hostImplMock; + ManagerImplMock *p_managerImplMock = nullptr ; + HostImplMock *p_hostImplMock = nullptr ; - testing::NiceMock connectionImplMock; - testing::NiceMock videoOutputPortMock; + ConnectionImplMock *p_connectionImplMock = nullptr ; + VideoOutputPortMock *p_videoOutputPortMock = nullptr ; - testing::NiceMock messageEncoderMock; - testing::NiceMock displayMock; - + MessageEncoderMock *p_messageEncoderMock = nullptr ; + DisplayMock *p_displayMock = nullptr ; HdmiCecSourceInitializedTest() : HdmiCecSourceTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; - device::Manager::getInstance().impl = &managerImplMock; - device::Host::getInstance().impl = &hostImplMock; - LibCCEC::getInstance().impl = &libCCECImplMock; - MessageEncoder::getInstance().impl = &messageEncoderMock; - Connection::getInstance().impl = &connectionImplMock; - device::VideoOutputPort::getInstance().impl = &videoOutputPortMock;; - device::Display::getInstance().impl = &displayMock; + p_iarmBusImplMock = new testing::NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_hostImplMock = new testing::NiceMock ; + device::Host::setImpl(p_hostImplMock); + + p_managerImplMock = new testing::NiceMock ; + device::Manager::setImpl(p_managerImplMock); + + p_libCCECImplMock = new testing::NiceMock ; + LibCCEC::setImpl(p_libCCECImplMock); + + p_messageEncoderMock = new testing::NiceMock ; + MessageEncoder::setImpl(p_messageEncoderMock); + + p_connectionImplMock = new testing::NiceMock ; + Connection::setImpl(p_connectionImplMock); + + p_videoOutputPortMock = new testing::NiceMock ; + device::VideoOutputPort::setImpl(p_videoOutputPortMock); + + p_displayMock = new testing::NiceMock ; + device::Display::setImpl(p_displayMock); //OnCall required for intialize to run properly - ON_CALL(hostImplMock, getVideoOutputPort(::testing::_)) + ON_CALL(*p_hostImplMock, getVideoOutputPort(::testing::_)) .WillByDefault(::testing::ReturnRef(device::VideoOutputPort::getInstance())); - ON_CALL(videoOutputPortMock, getDisplay()) + ON_CALL(*p_videoOutputPortMock, getDisplay()) .WillByDefault(::testing::ReturnRef(device::Display::getInstance())); - ON_CALL(videoOutputPortMock, isDisplayConnected()) + ON_CALL(*p_videoOutputPortMock, isDisplayConnected()) .WillByDefault(::testing::Return(true)); - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::ReturnRef(CECFrame::getInstance())); - ON_CALL(displayMock, getEDIDBytes(::testing::_)) + ON_CALL(*p_displayMock, getEDIDBytes(::testing::_)) .WillByDefault(::testing::Invoke( [&](std::vector &edidVec2) { edidVec2 = std::vector({ 't', 'e', 's', 't' }); - })); + })); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_DAEMON_INITIALIZED)) { EXPECT_TRUE(handler != nullptr); cecMgrEventHandler = handler; } - if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_STATUS_UPDATED)) { + if ((string(IARM_BUS_CECMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_CECMGR_EVENT_STATUS_UPDATED)) { EXPECT_TRUE(handler != nullptr); cecMgrEventHandler = handler; } @@ -142,12 +162,12 @@ class HdmiCecSourceInitializedTest : public HdmiCecSourceTest { return IARM_RESULT_SUCCESS; })); - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARM_BUS_PWRMGR_API_GetPowerState) == 0) { auto* param = static_cast(arg); - param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; + param->curState = IARM_BUS_PWRMGR_POWERSTATE_ON; } return IARM_RESULT_SUCCESS; }); @@ -155,36 +175,74 @@ class HdmiCecSourceInitializedTest : public HdmiCecSourceTest { EXPECT_EQ(string(""), plugin->Initialize(nullptr)); //Set enabled needs to be - ON_CALL(libCCECImplMock, getLogicalAddress(::testing::_)) + ON_CALL(*p_libCCECImplMock, getLogicalAddress(::testing::_)) .WillByDefault(::testing::Return(1)); - ON_CALL(connectionImplMock, open()) + ON_CALL(*p_connectionImplMock, open()) .WillByDefault(::testing::Return()); - ON_CALL(connectionImplMock, addFrameListener(::testing::_)) + ON_CALL(*p_connectionImplMock, addFrameListener(::testing::_)) .WillByDefault(::testing::Return()); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": true}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); - + } virtual ~HdmiCecSourceInitializedTest() override { int lCounter = 0; while ((Plugin::HdmiCecSource::_instance->deviceList[0].m_isOSDNameUpdated) && (lCounter < (2*10))) { //sleep for 2sec. - usleep (100 * 1000); //sleep for 100 milli sec - lCounter ++; - } + usleep (100 * 1000); //sleep for 100 milli sec + lCounter ++; + } EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": false}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); plugin->Deinitialize(nullptr); - device::Manager::getInstance().impl = nullptr; - device::Host::getInstance().impl = nullptr; - LibCCEC::getInstance().impl = nullptr; - MessageEncoder::getInstance().impl = nullptr; - IarmBus::getInstance().impl = nullptr; - Connection::getInstance().impl = nullptr; - device::Display::getInstance().impl = nullptr; - - - + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + LibCCEC::setImpl(nullptr); + if (p_libCCECImplMock != nullptr) + { + delete p_libCCECImplMock; + p_libCCECImplMock = nullptr; + } + Connection::setImpl(nullptr); + if (p_connectionImplMock != nullptr) + { + delete p_connectionImplMock; + p_connectionImplMock = nullptr; + } + MessageEncoder::setImpl(nullptr); + if (p_messageEncoderMock != nullptr) + { + delete p_messageEncoderMock; + p_messageEncoderMock = nullptr; + } + device::Display::setImpl(nullptr); + if (p_displayMock != nullptr) + { + delete p_displayMock; + p_displayMock = nullptr; + } + device::VideoOutputPort::setImpl(nullptr); + if (p_videoOutputPortMock != nullptr) + { + delete p_videoOutputPortMock; + p_videoOutputPortMock = nullptr; + } + device::Manager::setImpl(nullptr); + if (p_managerImplMock != nullptr) + { + delete p_managerImplMock; + p_managerImplMock = nullptr; + } + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } } }; class HdmiCecSourceInitializedEventTest : public HdmiCecSourceInitializedTest { @@ -193,15 +251,14 @@ class HdmiCecSourceInitializedEventTest : public HdmiCecSourceInitializedTest { Core::JSONRPC::Message message; FactoriesImplementation factoriesImplementation; PluginHost::IDispatcher* dispatcher; - HdmiCecSourceInitializedEventTest() : HdmiCecSourceInitializedTest() { - PluginHost::IFactories::Assign(&factoriesImplementation); + PluginHost::IFactories::Assign(&factoriesImplementation); dispatcher = static_cast( - plugin->QueryInterface(PluginHost::IDispatcher::ID)); + plugin->QueryInterface(PluginHost::IDispatcher::ID)); dispatcher->Activate(&service); } @@ -210,7 +267,7 @@ class HdmiCecSourceInitializedEventTest : public HdmiCecSourceInitializedTest { dispatcher->Deactivate(); dispatcher->Release(); PluginHost::IFactories::Assign(nullptr); - + } }; @@ -230,7 +287,7 @@ TEST_F(HdmiCecSourceTest, RegisteredMethods) EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOSDName"))); EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setOTPEnabled"))); EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setVendorId"))); - + } TEST_F(HdmiCecSourceDsTest, getEnabledFalse) @@ -256,7 +313,7 @@ TEST_F(HdmiCecSourceInitializedTest, getActiveSourceStatusTrue) EXPECT_EQ(response, string("{\"success\":true}")); //Sets Activesource to true - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("performOTPAction"), _T("{\"enabled\": true}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("performOTPAction"), _T("{\"enabled\": true}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); @@ -275,13 +332,13 @@ TEST_F(HdmiCecSourceInitializedTest, getActiveSourceStatusFalse) TEST_F(HdmiCecSourceInitializedTest, getDeviceList) -{ +{ int iCounter = 0; //Checking to see if one of the values has been filled in (as the rest get filled in at the same time, and waiting if its not. while ((!Plugin::HdmiCecSource::_instance->deviceList[0].m_isOSDNameUpdated) && (iCounter < (2*10))) { //sleep for 2sec. - usleep (100 * 1000); //sleep for 100 milli sec - iCounter ++; - } + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } const char* val = "TEST"; OSDName name = OSDName(val); @@ -298,7 +355,6 @@ TEST_F(HdmiCecSourceInitializedTest, getDeviceList) proc.process(osdName, header); //calls the process that sets osdName for LogicalAddress = 1 proc.process(vendorid, header); //calls the process that sets vendorID for LogicalAddress = 1 - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceList"), _T(""), response)); EXPECT_EQ(response, string(_T("{\"numberofdevices\":14,\"deviceList\":[{\"logicalAddress\":1,\"osdName\":\"TEST\",\"vendorID\":\"123\"},{\"logicalAddress\":2,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":3,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":4,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":5,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":6,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":7,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":8,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":9,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":10,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":11,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":12,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":13,\"osdName\":\"NA\",\"vendorID\":\"000\"},{\"logicalAddress\":14,\"osdName\":\"NA\",\"vendorID\":\"000\"}],\"success\":true}"))); @@ -312,11 +368,9 @@ TEST_F(HdmiCecSourceInitializedTest, getOTPEnabled) EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setOTPEnabled"), _T("{\"enabled\": true}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOTPEnabled"), _T("{}"), response)); EXPECT_EQ(response, string("{\"enabled\":true,\"success\":true}")); - } @@ -363,18 +417,18 @@ TEST_F(HdmiCecSourceInitializedTest, setOTPEnabled) TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEventUp) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_VOLUME_UP ); return CECFrame::getInstance(); })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 65}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent2) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_VOLUME_DOWN ); @@ -386,7 +440,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent2) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent3) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_MUTE ); @@ -397,7 +451,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent3) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent4) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_UP ); @@ -408,7 +462,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent4) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent5) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_DOWN ); @@ -416,11 +470,11 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent5) })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("sendKeyPressEvent"), _T("{\"logicalAddress\": 0, \"keyCode\": 2}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); - + } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent6) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_LEFT ); @@ -432,7 +486,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent6) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent7) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_RIGHT ); @@ -444,7 +498,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent7) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent8) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_SELECT ); @@ -455,7 +509,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent8) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent9) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_HOME ); @@ -467,7 +521,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent9) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent10) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_BACK ); @@ -479,7 +533,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent10) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent11) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_0 ); @@ -491,7 +545,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent11) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent12) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_1 ); @@ -503,7 +557,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent12) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent13) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_2 ); @@ -515,7 +569,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent13) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent14) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_3 ); @@ -527,7 +581,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent14) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent15) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_4 ); @@ -539,7 +593,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent15) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent16) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_5 ); @@ -551,7 +605,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent16) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent17) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_6 ); @@ -563,7 +617,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent17) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent18) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_7 ); @@ -576,7 +630,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent18) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent19) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_8 ); @@ -588,7 +642,7 @@ TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent19) } TEST_F(HdmiCecSourceInitializedTest, sendKeyPressEvent20) { - ON_CALL(messageEncoderMock, encode(::testing::Matcher(::testing::_))) + ON_CALL(*p_messageEncoderMock, encode(::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const UserControlPressed& m) -> CECFrame& { EXPECT_EQ(m.uiCommand.toInt(),UICommand::UI_COMMAND_NUM_9 ); diff --git a/Tests/tests/test_HdmiInput.cpp b/Tests/L1Tests/tests/test_HdmiInput.cpp old mode 100644 new mode 100755 similarity index 89% rename from Tests/tests/test_HdmiInput.cpp rename to Tests/L1Tests/tests/test_HdmiInput.cpp index a6f22d18fa..34067c8513 --- a/Tests/tests/test_HdmiInput.cpp +++ b/Tests/L1Tests/tests/test_HdmiInput.cpp @@ -34,22 +34,28 @@ class HdmiInputTest : public ::testing::Test { class HdmiInputDsTest : public HdmiInputTest { protected: - NiceMock hdmiInputImplMock; + HdmiInputImplMock *p_hdmiInputImplMock = nullptr ; HdmiInputDsTest() : HdmiInputTest() { - device::HdmiInput::getInstance().impl = &hdmiInputImplMock; + p_hdmiInputImplMock = new NiceMock ; + device::HdmiInput::setImpl(p_hdmiInputImplMock); } virtual ~HdmiInputDsTest() override { - device::HdmiInput::getInstance().impl = nullptr; + device::HdmiInput::setImpl(nullptr); + if (p_hdmiInputImplMock != nullptr) + { + delete p_hdmiInputImplMock; + p_hdmiInputImplMock = nullptr; + } } }; class HdmiInputInitializedTest : public HdmiInputTest { protected: - NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; IARM_EventHandler_t dsHdmiEventHandler; IARM_EventHandler_t dsHdmiStatusEventHandler; IARM_EventHandler_t dsHdmiSignalStatusEventHandler; @@ -62,15 +68,16 @@ class HdmiInputInitializedTest : public HdmiInputTest { HdmiInputInitializedTest() : HdmiInputTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); - EXPECT_CALL(service, QueryInterfaceByCallsign(::testing::_, ::testing::_)) + EXPECT_CALL(service, QueryInterfaceByCallsign(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const uint32_t, const string& name) -> void* { return nullptr; })); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG)) { @@ -102,7 +109,12 @@ class HdmiInputInitializedTest : public HdmiInputTest { { plugin->Deinitialize(&service); - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } } }; @@ -135,22 +147,26 @@ class HdmiInputInitializedEventTest : public HdmiInputInitializedTest { class HdmiInputInitializedEventDsTest : public HdmiInputInitializedEventTest { protected: - NiceMock hdmiInputImplMock; + HdmiInputImplMock *p_hdmiInputImplMock = nullptr ; HdmiInputInitializedEventDsTest() : HdmiInputInitializedEventTest() { - device::HdmiInput::getInstance().impl = &hdmiInputImplMock; + p_hdmiInputImplMock = new NiceMock ; + device::HdmiInput::setImpl(p_hdmiInputImplMock); } virtual ~HdmiInputInitializedEventDsTest() override { - device::HdmiInput::getInstance().impl = nullptr; + device::HdmiInput::setImpl(nullptr); + if (p_hdmiInputImplMock != nullptr) + { + delete p_hdmiInputImplMock; + p_hdmiInputImplMock = nullptr; + } } }; - - TEST_F(HdmiInputTest, RegisteredMethods) { EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getHDMIInputDevices"))); @@ -179,9 +195,9 @@ TEST_F(HdmiInputTest, RegisteredMethods) TEST_F(HdmiInputDsTest, getHDMIInputDevices) { - ON_CALL(hdmiInputImplMock, getNumberOfInputs()) + ON_CALL(*p_hdmiInputImplMock, getNumberOfInputs()) .WillByDefault(::testing::Return(1)); - ON_CALL(hdmiInputImplMock, isPortConnected(::testing::_)) + ON_CALL(*p_hdmiInputImplMock, isPortConnected(::testing::_)) .WillByDefault(::testing::Return(true)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getHDMIInputDevices"), _T("{}"), response)); EXPECT_EQ(response, string("{\"devices\":[{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"connected\":\"true\"}],\"success\":true}")); @@ -203,64 +219,64 @@ TEST_F(HdmiInputDsTest, writeEDID) TEST_F(HdmiInputDsTest, writeEDIDInvalid) { - ON_CALL(hdmiInputImplMock, getEDIDBytesInfo(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getEDIDBytesInfo(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, std::vector &edidVec2) { edidVec2 = std::vector({ 't', 'e', 's', 't' }); - })); + })); EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("readEDID"), _T("{\"deviceId\": \"b\"}"), response)); EXPECT_EQ(response, string("")); } TEST_F(HdmiInputDsTest, readEDID) { - ON_CALL(hdmiInputImplMock, getEDIDBytesInfo(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getEDIDBytesInfo(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, std::vector &edidVec2) { edidVec2 = std::vector({ 't', 'e', 's', 't' }); - })); + })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("readEDID"), _T("{\"deviceId\": 0}"), response)); EXPECT_EQ(response, string("{\"EDID\":\"dGVzdA==\",\"success\":true}")); } TEST_F(HdmiInputDsTest, getRawHDMISPD) { - ON_CALL(hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, std::vector& edidVec2) { edidVec2 = { 't', 'e', 's', 't' }; - })); + })); EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("getRawHDMISPD"), _T("{\"portId\":0}"), response)); EXPECT_EQ(response, string("{\"HDMISPD\":\"dGVzdA\",\"success\":true}")); } TEST_F(HdmiInputDsTest, getRawHDMISPDInvalid) { - ON_CALL(hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, std::vector& edidVec2) { edidVec2 = { 't', 'e', 's', 't' }; - })); + })); EXPECT_EQ(Core::ERROR_GENERAL, handlerV2.Invoke(connection, _T("getRawHDMISPD"), _T("{\"portId\":\"b\"}"), response)); EXPECT_EQ(response, string("")); } TEST_F(HdmiInputDsTest, getHDMISPD) { - ON_CALL(hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, std::vector& edidVec2) { edidVec2 = {'0','1','2','n', 'p', '1','2','3','4','5','6','7',0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',0,'q','r'}; - })); + })); EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("getHDMISPD"), _T("{\"portId\":0}"), response)); EXPECT_EQ(response, string("{\"HDMISPD\":\"Packet Type:30,Version:49,Length:50,vendor name:1234567,product des:abcdefghijklmno,source info:71\",\"success\":true}")); } TEST_F(HdmiInputDsTest, getHDMISPDInvalid) { - ON_CALL(hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getHDMISPDInfo(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, std::vector& edidVec2) { edidVec2 = {'0','1','2','n', 'p', '0'}; - })); + })); EXPECT_EQ(Core::ERROR_GENERAL, handlerV2.Invoke(connection, _T("getHDMISPD"), _T("{\"portId\":\"b\"}"), response)); EXPECT_EQ(response, string("")); } @@ -296,17 +312,17 @@ TEST_F(HdmiInputDsTest, getEdidVersionInvalid) } TEST_F(HdmiInputDsTest, getEdidVersionVer14) { - ON_CALL(hdmiInputImplMock, getEdidVersion(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getEdidVersion(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iPort, int *edidVersion) { *edidVersion = 0; - })); + })); EXPECT_EQ(Core::ERROR_NONE, handlerV2.Invoke(connection, _T("getEdidVersion"), _T("{\"portId\": \"0\"}"), response)); EXPECT_EQ(response, string("{\"edidVersion\":\"HDMI1.4\",\"success\":true}")); } TEST_F(HdmiInputDsTest, getEdidVersionVer20) { - ON_CALL(hdmiInputImplMock, getEdidVersion(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getEdidVersion(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iPort, int *edidVersion) { *edidVersion = 1; @@ -324,44 +340,44 @@ TEST_F(HdmiInputDsTest, startHdmiInputInvalid) TEST_F(HdmiInputDsTest, startHdmiInput) { EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startHdmiInput"), _T("{\"portId\": \"0\"}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(HdmiInputDsTest, stopHdmiInput) { EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("stopHdmiInput"), _T("{}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(HdmiInputDsTest, setVideoRectangleInvalid) { EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setVideoRectangle"), _T("{\"x\": \"b\",\"y\": 0,\"w\": 1920,\"h\": 1080}"), response)); - EXPECT_EQ(response, string("")); + EXPECT_EQ(response, string("")); } TEST_F(HdmiInputDsTest, setVideoRectangle) { EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setVideoRectangle"), _T("{\"x\": 0,\"y\": 0,\"w\": 1920,\"h\": 1080}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(HdmiInputDsTest, getSupportedGameFeatures) { - ON_CALL(hdmiInputImplMock, getSupportedGameFeatures(::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getSupportedGameFeatures(::testing::_)) .WillByDefault(::testing::Invoke( [&](std::vector &supportedFeatures) { supportedFeatures = {"ALLM"}; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSupportedGameFeatures"), _T("{\"supportedGameFeatures\": \"ALLM\"}"), response)); - EXPECT_EQ(response, string("{\"supportedGameFeatures\":[\"ALLM\"],\"success\":true}")); + EXPECT_EQ(response, string("{\"supportedGameFeatures\":[\"ALLM\"],\"success\":true}")); } TEST_F(HdmiInputDsTest, getHdmiGameFeatureStatusInvalidPort) { - ON_CALL(hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, bool *allm) { *allm = true; @@ -372,31 +388,31 @@ TEST_F(HdmiInputDsTest, getHdmiGameFeatureStatusInvalidPort) TEST_F(HdmiInputDsTest, getHdmiGameFeatureStatus) { - ON_CALL(hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, bool *allm) { *allm = true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getHdmiGameFeatureStatus"), _T("{\"portId\": \"0\",\"gameFeature\": \"ALLM\"}"), response)); - EXPECT_EQ(response, string("{\"mode\":true,\"success\":true}")); + EXPECT_EQ(response, string("{\"mode\":true,\"success\":true}")); } TEST_F(HdmiInputDsTest, getHdmiGameFeatureStatusInvalidFeature) { - ON_CALL(hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) + ON_CALL(*p_hdmiInputImplMock, getHdmiALLMStatus(::testing::_,::testing::_)) .WillByDefault(::testing::Invoke( [&](int iport, bool *allm) { *allm = true; })); EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getHdmiGameFeatureStatus"), _T("{\"portId\": \"0\",\"gameFeature\": \"Invalid\"}"), response)); - EXPECT_EQ(response, string("")); + EXPECT_EQ(response, string("")); } TEST_F(HdmiInputInitializedEventDsTest, onDevicesChanged) { ASSERT_TRUE(dsHdmiEventHandler != nullptr); - ON_CALL(hdmiInputImplMock, getNumberOfInputs()) + ON_CALL(*p_hdmiInputImplMock, getNumberOfInputs()) .WillByDefault(::testing::Return(1)); - ON_CALL(hdmiInputImplMock, isPortConnected(::testing::_)) + ON_CALL(*p_hdmiInputImplMock, isPortConnected(::testing::_)) .WillByDefault(::testing::Return(true)); EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) @@ -413,12 +429,12 @@ TEST_F(HdmiInputInitializedEventDsTest, onDevicesChanged) IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_connect.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_connect.isPortConnected = true; + eventData.data.hdmi_in_connect.isPortConnected = true; handler.Subscribe(0, _T("onDevicesChanged"), _T("client.events.onDevicesChanged"), message); dsHdmiEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG, &eventData , 0); - handler.Unsubscribe(0, _T("onDevicesChanged"), _T("client.events.onDevicesChanged"), message); + handler.Unsubscribe(0, _T("onDevicesChanged"), _T("client.events.onDevicesChanged"), message); } TEST_F(HdmiInputInitializedEventDsTest, onInputStatusChangeOn) @@ -437,10 +453,10 @@ TEST_F(HdmiInputInitializedEventDsTest, onInputStatusChangeOn) EXPECT_EQ(response, string("{\"success\":true}")); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_status.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_status.isPresented = true; + eventData.data.hdmi_in_status.isPresented = true; handler.Subscribe(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); dsHdmiStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS, &eventData , 0); - handler.Unsubscribe(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); + handler.Unsubscribe(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); } TEST_F(HdmiInputInitializedEventDsTest, onInputStatusChangeOff) { @@ -458,10 +474,10 @@ TEST_F(HdmiInputInitializedEventDsTest, onInputStatusChangeOff) EXPECT_EQ(response, string("{\"success\":true}")); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_status.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_status.isPresented = false; + eventData.data.hdmi_in_status.isPresented = false; handler.Subscribe(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); dsHdmiStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS, &eventData , 0); - handler.Unsubscribe(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); + handler.Unsubscribe(0, _T("onInputStatusChanged"), _T("client.events.onInputStatusChanged"), message); } TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedStable) { @@ -477,10 +493,10 @@ TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedStable) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_STABLE; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_STABLE; handler.Subscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); - handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); } TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedNoSignal) { @@ -496,10 +512,10 @@ TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedNoSignal) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_NOSIGNAL; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_NOSIGNAL; handler.Subscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); - handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); } TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedUnstable) { @@ -515,10 +531,10 @@ TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedUnstable) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_UNSTABLE; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_UNSTABLE; handler.Subscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); - handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); } TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedNotSupported) { @@ -534,10 +550,10 @@ TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedNotSupported) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_NOTSUPPORTED; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_NOTSUPPORTED; handler.Subscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); - handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); } TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedDefault) { @@ -553,10 +569,10 @@ TEST_F(HdmiInputInitializedEventDsTest, onSignalChangedDefault) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_sig_status.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_MAX; + eventData.data.hdmi_in_sig_status.status = dsHDMI_IN_SIGNAL_STATUS_MAX; handler.Subscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); dsHdmiSignalStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, &eventData , 0); - handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); + handler.Unsubscribe(0, _T("onSignalChanged"), _T("client.events.onSignalChanged"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate1) @@ -573,12 +589,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate1) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_1920x1080; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_59dot94; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_1920x1080; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_59dot94; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate2) { @@ -594,12 +610,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate2) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_720x480; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_24; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_720x480; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_24; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate3) { @@ -615,12 +631,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate3) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_720x576; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_25; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_720x576; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_25; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate4) { @@ -636,12 +652,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate4) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_3840x2160; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_30; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_3840x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_30; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate5) { @@ -657,12 +673,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate5) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_50; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_50; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate6) { @@ -678,12 +694,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate6) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_60; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_60; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate7) { @@ -699,12 +715,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate7) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_23dot98; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_23dot98; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate8) { @@ -720,12 +736,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate8) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_29dot97; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_4096x2160; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_29dot97; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate9) { @@ -741,12 +757,12 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdate9) })); IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_1280x720; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; - eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_29dot97; + eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_1280x720; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.frameRate = dsVIDEO_FRAMERATE_29dot97; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdateDefault) { @@ -763,11 +779,11 @@ TEST_F(HdmiInputInitializedEventDsTest, videoStreamInfoUpdateDefault) IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_video_mode.port =dsHDMI_IN_PORT_0; eventData.data.hdmi_in_video_mode.resolution.pixelResolution = dsVIDEO_PIXELRES_MAX; - eventData.data.hdmi_in_video_mode.resolution.interlaced = true; + eventData.data.hdmi_in_video_mode.resolution.interlaced = true; eventData.data.hdmi_in_video_mode.resolution.frameRate= dsVIDEO_FRAMERATE_MAX; handler.Subscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); dsHdmiVideoModeEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, &eventData , 0); - handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); + handler.Unsubscribe(0, _T("videoStreamInfoUpdate"), _T("client.events.videoStreamInfoUpdate"), message); } TEST_F(HdmiInputInitializedEventDsTest, hdmiGameFeatureStatusUpdate) { @@ -787,10 +803,10 @@ TEST_F(HdmiInputInitializedEventDsTest, hdmiGameFeatureStatusUpdate) IARM_Bus_DSMgr_EventData_t eventData; eventData.data.hdmi_in_allm_mode.port =dsHDMI_IN_PORT_0; - eventData.data.hdmi_in_allm_mode.allm_mode = true; + eventData.data.hdmi_in_allm_mode.allm_mode = true; handler.Subscribe(0, _T("hdmiGameFeatureStatusUpdate"), _T("client.events.hdmiGameFeatureStatusUpdate"), message); dsHdmiGameFeatureStatusEventHandler(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_EVENT_HDMI_IN_ALLM_STATUS, &eventData , 0); - handler.Unsubscribe(0, _T("hdmiGameFeatureStatusUpdate"), _T("client.events.hdmiGameFeatureStatusUpdate"), message); + handler.Unsubscribe(0, _T("hdmiGameFeatureStatusUpdate"), _T("client.events.hdmiGameFeatureStatusUpdate"), message); } diff --git a/Tests/tests/test_JSON.cpp b/Tests/L1Tests/tests/test_JSON.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_JSON.cpp rename to Tests/L1Tests/tests/test_JSON.cpp diff --git a/Tests/tests/test_LocationSync.cpp b/Tests/L1Tests/tests/test_LocationSync.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_LocationSync.cpp rename to Tests/L1Tests/tests/test_LocationSync.cpp diff --git a/Tests/tests/test_LoggingPreferences.cpp b/Tests/L1Tests/tests/test_LoggingPreferences.cpp old mode 100644 new mode 100755 similarity index 94% rename from Tests/tests/test_LoggingPreferences.cpp rename to Tests/L1Tests/tests/test_LoggingPreferences.cpp index 86c204ed90..73f2c157ac --- a/Tests/tests/test_LoggingPreferences.cpp +++ b/Tests/L1Tests/tests/test_LoggingPreferences.cpp @@ -48,12 +48,14 @@ class LoggingPreferencesTest : public ::testing::Test { class LoggingPreferencesInitializedTest : public LoggingPreferencesTest { protected: - NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; LoggingPreferencesInitializedTest() : LoggingPreferencesTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + EXPECT_EQ(string(""), plugin->Initialize(nullptr)); } @@ -61,7 +63,13 @@ class LoggingPreferencesInitializedTest : public LoggingPreferencesTest { { plugin->Deinitialize(nullptr); - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + } }; @@ -103,7 +111,7 @@ TEST_F(LoggingPreferencesTest, paramsMissing) TEST_F(LoggingPreferencesInitializedTest, getKeystrokeMask) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARM_BUS_SYSMGR_API_GetKeyCodeLoggingPref) == 0) { @@ -121,7 +129,7 @@ TEST_F(LoggingPreferencesInitializedEventTest, enableKeystrokeMask) { Core::Event onKeystrokeMaskEnabledChange(false, true); - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARM_BUS_SYSMGR_API_GetKeyCodeLoggingPref) == 0) { @@ -165,7 +173,7 @@ TEST_F(LoggingPreferencesInitializedEventTest, disbleKeystrokeMask) { Core::Event onKeystrokeMaskEnabledChange(false, true); - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARM_BUS_SYSMGR_API_GetKeyCodeLoggingPref) == 0) { @@ -204,7 +212,7 @@ TEST_F(LoggingPreferencesInitializedEventTest, disbleKeystrokeMask) TEST_F(LoggingPreferencesInitializedTest, errorCases) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { if (strcmp(methodName, IARM_BUS_SYSMGR_API_GetKeyCodeLoggingPref) == 0) { diff --git a/Tests/tests/test_MaintenanceManager.cpp b/Tests/L1Tests/tests/test_MaintenanceManager.cpp old mode 100644 new mode 100755 similarity index 79% rename from Tests/tests/test_MaintenanceManager.cpp rename to Tests/L1Tests/tests/test_MaintenanceManager.cpp index 149f2dac8c..80d19271d1 --- a/Tests/tests/test_MaintenanceManager.cpp +++ b/Tests/L1Tests/tests/test_MaintenanceManager.cpp @@ -48,25 +48,48 @@ class MaintenanceManagerTest : public Test { Core::JSONRPC::Handler& handler_; Core::JSONRPC::Connection connection_; string response_; - NiceMock iarmBusImplMock_; - NiceMock rfcApiImplMock; - NiceMock wrapsImplMock; - + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + RfcApiImplMock *p_rfcApiImplMock = nullptr ; + WrapsImplMock *p_wrapsImplMock = nullptr ; + MaintenanceManagerTest() : plugin_(Core::ProxyType::Create()) , handler_(*plugin_) , connection_(1, 0) { - IarmBus::getInstance().impl = &iarmBusImplMock_; - RfcApi::getInstance().impl = &rfcApiImplMock; - Wraps::getInstance().impl = &wrapsImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_rfcApiImplMock = new testing::NiceMock ; + RfcApi::setImpl(p_rfcApiImplMock); + + p_wrapsImplMock = new testing::NiceMock ; + Wraps::setImpl(p_wrapsImplMock); } virtual ~MaintenanceManagerTest() override { - IarmBus::getInstance().impl = nullptr; - RfcApi::getInstance().impl = nullptr; - Wraps::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + + RfcApi::setImpl(nullptr); + if (p_rfcApiImplMock != nullptr) + { + delete p_rfcApiImplMock; + p_rfcApiImplMock = nullptr; + } + + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + } }; @@ -93,14 +116,14 @@ class MaintenanceManagerInitializedEventTest : public MaintenanceManagerTest { MaintenanceManagerInitializedEventTest() : MaintenanceManagerTest() { - - EXPECT_CALL(iarmBusImplMock_, IARM_Bus_RegisterEventHandler(StrEq(IARM_BUS_MAINTENANCE_MGR_NAME),IARM_BUS_MAINTENANCEMGR_EVENT_UPDATE, _)) + + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(StrEq(IARM_BUS_MAINTENANCE_MGR_NAME),IARM_BUS_MAINTENANCEMGR_EVENT_UPDATE, _)) .WillOnce(Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { controlEventHandler_ = handler; return IARM_RESULT_SUCCESS; })); - EXPECT_CALL(iarmBusImplMock_, IARM_Bus_RegisterEventHandler(StrEq(IARM_BUS_MAINTENANCE_MGR_NAME), IARM_BUS_DCM_NEW_START_TIME_EVENT, _)) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(StrEq(IARM_BUS_MAINTENANCE_MGR_NAME), IARM_BUS_DCM_NEW_START_TIME_EVENT, _)) .WillRepeatedly(Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { EXPECT_TRUE(isValidCtrlmRcuIarmEvent(eventId)); @@ -135,47 +158,48 @@ TEST_F(MaintenanceManagerTest, RegisteredMethods) TEST_F(MaintenanceManagerTest, setMaintenanceMode) { - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { - pstParamData->type = WDMP_BOOLEAN; - strncpy(pstParamData->value, "true", MAX_PARAM_LEN); + pstParamData->type = WDMP_BOOLEAN; + strncpy(pstParamData->value, "true", MAX_PARAM_LEN); return WDMP_SUCCESS; })); + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"FOREGROUND\",\"optOut\":\"IGNORE_UPDATE\"}"), response_)); EXPECT_EQ(response_, "{\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); EXPECT_EQ(response_, "{\"maintenanceMode\":\"FOREGROUND\",\"optOut\":\"IGNORE_UPDATE\",\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"FOREGROUND\",\"optOut\":\"ENFORCE_OPTOUT\"}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"FOREGROUND\",\"optOut\":\"ENFORCE_OPTOUT\"}"), response_)); EXPECT_EQ(response_, "{\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); EXPECT_EQ(response_, "{\"maintenanceMode\":\"FOREGROUND\",\"optOut\":\"ENFORCE_OPTOUT\",\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"FOREGROUND\",\"optOut\":\"BYPASS_OPTOUT\"}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"FOREGROUND\",\"optOut\":\"BYPASS_OPTOUT\"}"), response_)); EXPECT_EQ(response_, "{\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); EXPECT_EQ(response_, "{\"maintenanceMode\":\"FOREGROUND\",\"optOut\":\"BYPASS_OPTOUT\",\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"IGNORE_UPDATE\"}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"IGNORE_UPDATE\"}"), response_)); EXPECT_EQ(response_, "{\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); EXPECT_EQ(response_, "{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"IGNORE_UPDATE\",\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"ENFORCE_OPTOUT\"}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"ENFORCE_OPTOUT\"}"), response_)); EXPECT_EQ(response_, "{\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); EXPECT_EQ(response_, "{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"ENFORCE_OPTOUT\",\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"BYPASS_OPTOUT\"}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.setMaintenanceMode"), _T("{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"BYPASS_OPTOUT\"}"), response_)); EXPECT_EQ(response_, "{\"success\":true}"); - - EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); + + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("org.rdk.MaintenanceManager.1.getMaintenanceMode"), _T("{}"), response_)); EXPECT_EQ(response_, "{\"maintenanceMode\":\"BACKGROUND\",\"optOut\":\"BYPASS_OPTOUT\",\"success\":true}"); } @@ -346,29 +370,28 @@ TEST_F(MaintenanceManagerInitializedEventTest, stopMaintenanceRFCEnable) TEST_F(MaintenanceManagerTest, getMaintenanceStartTime) { - const char *deviceInfoScript = "/lib/rdk/getMaintenanceStartTime.sh"; + const char *deviceInfoScript = "/lib/rdk/getMaintenanceStartTime.sh"; - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { EXPECT_EQ(string(command), string(_T("/lib/rdk/getMaintenanceStartTime.sh &"))); return __real_popen(deviceInfoScript, type); })); - ON_CALL(wrapsImplMock, pclose(::testing::_)) + ON_CALL(*p_wrapsImplMock, pclose(::testing::_)) .WillByDefault(::testing::Invoke( [&](FILE* pipe){ return __real_pclose(pipe); })); - std::this_thread::sleep_for(std::chrono::seconds(2)); - - - //Create fake device info script & Invoke getDeviceInfo + std::this_thread::sleep_for(std::chrono::seconds(2)); + +//Create fake device info script & Invoke getDeviceInfo ofstream file(deviceInfoScript); file << "echo \"123456789\"\n"; file.close(); - + EXPECT_EQ(Core::ERROR_NONE, handler_.Invoke(connection_, _T("getMaintenanceStartTime"), _T("{}"), response_)); EXPECT_EQ(response_, "{\"maintenanceStartTime\":123456789,\"success\":true}"); - + } diff --git a/Tests/tests/test_Messenger.cpp b/Tests/L1Tests/tests/test_Messenger.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_Messenger.cpp rename to Tests/L1Tests/tests/test_Messenger.cpp diff --git a/Tests/tests/test_MotionDetection.cpp b/Tests/L1Tests/tests/test_MotionDetection.cpp old mode 100644 new mode 100755 similarity index 77% rename from Tests/tests/test_MotionDetection.cpp rename to Tests/L1Tests/tests/test_MotionDetection.cpp index 480f084cb7..e57a6ad8f9 --- a/Tests/tests/test_MotionDetection.cpp +++ b/Tests/L1Tests/tests/test_MotionDetection.cpp @@ -32,21 +32,22 @@ class MotionDetectionTest : public ::testing::Test { class MotionDetectionEventTest : public MotionDetectionTest { protected: - NiceMock motionDetectionImplMock; + MotionDetectionImplMock *p_motionDetectionImplMock = nullptr ; MotionDetectionEventTest() : MotionDetectionTest() { - MotionDetection::getInstance().impl = &motionDetectionImplMock; + p_motionDetectionImplMock = new NiceMock ; + MotionDetection::setImpl(p_motionDetectionImplMock); - ON_CALL(motionDetectionImplMock, MOTION_DETECTION_Platform_Init()) + ON_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_Platform_Init()) .WillByDefault(::testing::Return(MOTION_DETECTION_RESULT_SUCCESS)); - ON_CALL(motionDetectionImplMock, MOTION_DETECTION_RegisterEventCallback(::testing::_)) + ON_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_RegisterEventCallback(::testing::_)) .WillByDefault(::testing::Return(MOTION_DETECTION_RESULT_SUCCESS)); - ON_CALL(motionDetectionImplMock, MOTION_DETECTION_DisarmMotionDetector(::testing::_)) + ON_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_DisarmMotionDetector(::testing::_)) .WillByDefault(::testing::Return(MOTION_DETECTION_RESULT_SUCCESS)); EXPECT_EQ(string(""), plugin->Initialize(nullptr)); @@ -56,6 +57,12 @@ class MotionDetectionEventTest : public MotionDetectionTest { { plugin->Deinitialize(nullptr); + MotionDetection::setImpl(nullptr); + if (p_motionDetectionImplMock != nullptr) + { + delete p_motionDetectionImplMock; + p_motionDetectionImplMock = nullptr; + } } }; @@ -75,11 +82,11 @@ TEST_F(MotionDetectionTest, RegisteredMethods) TEST_F(MotionDetectionEventTest, getMotionDetectors) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_GetMotionDetectors(::testing::_)) - .Times(1) - .WillOnce(::testing::Invoke( - [](MOTION_DETECTION_CurrentSensorSettings_t *pSensorStatus) { - + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_GetMotionDetectors(::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [](MOTION_DETECTION_CurrentSensorSettings_t *pSensorStatus) { + memset(pSensorStatus, 0, sizeof(MOTION_DETECTION_CurrentSensorSettings_t)); strcpy(pSensorStatus->m_sensorIndex, MOTION_DETECTOR); @@ -88,7 +95,7 @@ TEST_F(MotionDetectionEventTest, getMotionDetectors) pSensorStatus->m_sensorDistance = MOTION_DETECTION_DISTANCE; pSensorStatus->m_sensorAngle = MOTION_DETECTION_ANGLE; pSensorStatus->m_sensitivityMode = 2; - + strcpy(pSensorStatus->m_sensitivity[SENSITIVITY_IDENTIFIER_1], STR_SENSITIVITY_LOW); strcpy(pSensorStatus->m_sensitivity[SENSITIVITY_IDENTIFIER_2], STR_SENSITIVITY_MEDIUM); strcpy(pSensorStatus->m_sensitivity[SENSITIVITY_IDENTIFIER_3], STR_SENSITIVITY_HIGH); @@ -102,10 +109,10 @@ TEST_F(MotionDetectionEventTest, getMotionDetectors) TEST_F(MotionDetectionEventTest, armmotiondetected) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_ArmMotionDetector(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_ArmMotionDetector(::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( - [](MOTION_DETECTION_Mode_t mode,std::string index) { + [](MOTION_DETECTION_Mode_t mode,std::string index) { return MOTION_DETECTION_RESULT_SUCCESS; })); @@ -115,10 +122,10 @@ TEST_F(MotionDetectionEventTest, armmotiondetected) TEST_F(MotionDetectionEventTest, armmotiondetectedInvalid) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_ArmMotionDetector(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_ArmMotionDetector(::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( - [](MOTION_DETECTION_Mode_t mode, std::string index) { + [](MOTION_DETECTION_Mode_t mode, std::string index) { return MOTION_DETECTION_RESULT_INDEX_ERROR; })); @@ -128,9 +135,9 @@ TEST_F(MotionDetectionEventTest, armmotiondetectedInvalid) TEST_F(MotionDetectionEventTest, disarm) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_DisarmMotionDetector(::testing::_)) - .Times(1) - .WillOnce(::testing::Invoke( + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_DisarmMotionDetector(::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( [](std::string index) { return MOTION_DETECTION_RESULT_SUCCESS; })); @@ -141,7 +148,7 @@ TEST_F(MotionDetectionEventTest, disarm) TEST_F(MotionDetectionEventTest, disarmInvalid) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_DisarmMotionDetector(::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_DisarmMotionDetector(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](std::string index) { @@ -155,7 +162,7 @@ TEST_F(MotionDetectionEventTest, disarmInvalid) TEST_F(MotionDetectionEventTest, isarmed) { - EXPECT_CALL(motionDetectionImplMock,MOTION_DETECTION_IsMotionDetectorArmed(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock,MOTION_DETECTION_IsMotionDetectorArmed(::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](std::string index, bool *isArmed) { @@ -170,10 +177,10 @@ TEST_F(MotionDetectionEventTest, isarmed) TEST_F(MotionDetectionEventTest, isarmedInvalid) { - EXPECT_CALL(motionDetectionImplMock,MOTION_DETECTION_IsMotionDetectorArmed(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock,MOTION_DETECTION_IsMotionDetectorArmed(::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( - [](std::string index, bool *isArmed) { + [](std::string index, bool *isArmed) { return MOTION_DETECTION_RESULT_INDEX_ERROR; })); @@ -184,7 +191,7 @@ TEST_F(MotionDetectionEventTest, isarmedInvalid) TEST_F(MotionDetectionEventTest, setNoMotionPeriod) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_SetNoMotionPeriod(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_SetNoMotionPeriod(::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](std::string index, unsigned int period) { @@ -198,10 +205,10 @@ TEST_F(MotionDetectionEventTest, setNoMotionPeriod) TEST_F(MotionDetectionEventTest, setNoMotionPeriodInvalid) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_SetNoMotionPeriod(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_SetNoMotionPeriod(::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( - [](std::string index, unsigned int period) { + [](std::string index, unsigned int period) { return MOTION_DETECTION_RESULT_INDEX_ERROR; })); @@ -212,10 +219,10 @@ TEST_F(MotionDetectionEventTest, setNoMotionPeriodInvalid) TEST_F(MotionDetectionEventTest, getNoMotionPeriod) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_GetNoMotionPeriod(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_GetNoMotionPeriod(::testing::_,::testing::_)) .Times(1) - .WillOnce(::testing::Invoke( - [](std::string index, unsigned int *noMotionPeriod) { + .WillOnce(::testing::Invoke( + [](std::string index, unsigned int *noMotionPeriod) { *noMotionPeriod =(unsigned int)10; return MOTION_DETECTION_RESULT_SUCCESS; })); @@ -226,7 +233,7 @@ TEST_F(MotionDetectionEventTest, getNoMotionPeriod) TEST_F(MotionDetectionEventTest, getNoMotionPeriodInvalid) { - EXPECT_CALL(motionDetectionImplMock, MOTION_DETECTION_GetNoMotionPeriod(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock, MOTION_DETECTION_GetNoMotionPeriod(::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](std::string index, unsigned int *noMotionPeriod) { @@ -239,7 +246,7 @@ TEST_F(MotionDetectionEventTest, getNoMotionPeriodInvalid) TEST_F(MotionDetectionEventTest, setSensitivity) { - EXPECT_CALL(motionDetectionImplMock,MOTION_DETECTION_SetSensitivity(::testing::_,::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock,MOTION_DETECTION_SetSensitivity(::testing::_,::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](std::string index, std::string sensitivity, int inferredMode) { @@ -259,7 +266,7 @@ TEST_F(MotionDetectionEventTest, setSensitivityInvalid) TEST_F(MotionDetectionEventTest, getSensitivity) { - EXPECT_CALL(motionDetectionImplMock,MOTION_DETECTION_GetSensitivity(::testing::_,::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock,MOTION_DETECTION_GetSensitivity(::testing::_,::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](std::string index, char** sensitivity, int* currentMode) { @@ -276,7 +283,7 @@ TEST_F(MotionDetectionEventTest, getSensitivity) TEST_F(MotionDetectionEventTest, getSensitivityInvalid) { - EXPECT_CALL(motionDetectionImplMock,MOTION_DETECTION_GetSensitivity(::testing::_,::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock,MOTION_DETECTION_GetSensitivity(::testing::_,::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](std::string index, char** sensitivity, int* currentMode) { @@ -300,7 +307,7 @@ TEST_F(MotionDetectionEventTest, getLastMotionEventElapsedTime) TEST_F(MotionDetectionEventTest, setMotionEventsActivePeriod) { - EXPECT_CALL(motionDetectionImplMock,MOTION_DETECTION_SetActivePeriod(::testing::_,::testing::_)) + EXPECT_CALL(*p_motionDetectionImplMock,MOTION_DETECTION_SetActivePeriod(::testing::_,::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](std::string index, MOTION_DETECTION_TimeRange_t timeSet) { diff --git a/Tests/tests/test_Network.cpp b/Tests/L1Tests/tests/test_Network.cpp old mode 100644 new mode 100755 similarity index 95% rename from Tests/tests/test_Network.cpp rename to Tests/L1Tests/tests/test_Network.cpp index 48c8859dbe..9db8a1fc8e --- a/Tests/tests/test_Network.cpp +++ b/Tests/L1Tests/tests/test_Network.cpp @@ -19,13 +19,16 @@ extern "C" FILE* __real_popen(const char* command, const char* type); class NetworkTestBase : public ::testing::Test { public: - NiceMock wrapsImplMock; - NiceMock iarmBusImplMock; + WrapsImplMock *p_wrapsImplMock = nullptr ; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; NetworkTestBase() { - Wraps::getInstance().impl = &wrapsImplMock; - IarmBus::getInstance().impl = &iarmBusImplMock; + p_wrapsImplMock = new NiceMock ; + Wraps::setImpl(p_wrapsImplMock); + + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); ofstream file("/etc/device.properties"); file << "DEVICE_TYPE=mediaclient\n"; @@ -36,7 +39,7 @@ class NetworkTestBase : public ::testing::Test { file <<"ETHERNET_INTERFACE=eth0\n"; file.close(); - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { return __real_popen(command, type); @@ -64,7 +67,7 @@ class NetworkTest : public NetworkTestBase { IARM_EventHandler_t interfaceIpaddress; IARM_EventHandler_t defaultInterface; - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call_with_IPCTimeout) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call_with_IPCTimeout) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen, int timeout) { @@ -73,7 +76,7 @@ class NetworkTest : public NetworkTestBase { return IARM_RESULT_SUCCESS; }); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_NM_SRV_MGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS)) { @@ -96,8 +99,19 @@ class NetworkTest : public NetworkTestBase { virtual ~NetworkTest() override { - Wraps::getInstance().impl = nullptr; - IarmBus::getInstance().impl = nullptr; + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } } }; @@ -154,7 +168,7 @@ TEST_F(NetworkTest, RegisteredMethods) TEST_F(NetworkTest, getStbIp) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -173,7 +187,7 @@ TEST_F(NetworkTest, getStbIp) TEST_F(NetworkTest, getStbIp_cache) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -194,7 +208,7 @@ TEST_F(NetworkTest, getStbIp_cache) TEST_F(NetworkTest, getNullStbIp) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -212,7 +226,7 @@ TEST_F(NetworkTest, getNullStbIp) TEST_F(NetworkTest, getFailedStbIp) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -230,7 +244,7 @@ TEST_F(NetworkTest, getFailedStbIp) TEST_F(NetworkTest, getInterfaces) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -238,7 +252,7 @@ TEST_F(NetworkTest, getInterfaces) EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getInterfaceList))); auto param = static_cast(arg); - param->size = 1; + param->size = 1; memcpy(¶m->interfaces[0].name, "eth0", sizeof("eth0")); memcpy(¶m->interfaces[0].mac, "AA:AA:AA:AA:AA:AA", sizeof("AA:AA:AA:AA:AA:AA")); param->interfaces[0].flags = 69699; @@ -246,16 +260,16 @@ TEST_F(NetworkTest, getInterfaces) return IARM_RESULT_SUCCESS; }); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInterfaces"), _T("{}"), response)); - EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); - EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"macAddress\":\"AA:AA:AA:AA:AA:AA\""))); - EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"enabled\":true"))); - EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"connected\":true"))); - EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"macAddress\":\"AA:AA:AA:AA:AA:AA\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"enabled\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"connected\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); } TEST_F(NetworkTest, getInterfacesFailed) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -269,7 +283,7 @@ TEST_F(NetworkTest, getInterfacesFailed) TEST_F(NetworkTest, isInterfaceEnabled) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -278,7 +292,7 @@ TEST_F(NetworkTest, isInterfaceEnabled) auto param = static_cast(arg); memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); - param->isInterfaceEnabled = true; + param->isInterfaceEnabled = true; EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); EXPECT_EQ(param->isInterfaceEnabled, true); @@ -292,7 +306,7 @@ TEST_F(NetworkTest, isInterfaceEnabled) TEST_F(NetworkTest, isInterfaceEnabled_failed) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -313,7 +327,7 @@ TEST_F(NetworkTest, isInterfaceEnabled_failed) TEST_F(NetworkTest, getDefaultInterface) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -332,7 +346,7 @@ TEST_F(NetworkTest, getDefaultInterface) TEST_F(NetworkTest, getDefaultInterface_cache) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -354,7 +368,7 @@ TEST_F(NetworkTest, getDefaultInterface_cache) TEST_F(NetworkTest, isInterfaceEnabled_WrongIface) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -375,7 +389,7 @@ TEST_F(NetworkTest, isInterfaceEnabled_WrongIface) TEST_F(NetworkTest, isInterfaceEnabled_Fail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -396,7 +410,7 @@ TEST_F(NetworkTest, isInterfaceEnabled_Fail) TEST_F(NetworkTest, getIPSettings) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -404,12 +418,12 @@ TEST_F(NetworkTest, getIPSettings) EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); auto param = static_cast(arg); - memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); memcpy(¶m->ipversion, "IPV4", sizeof("IPV4")); param->autoconfig = true; memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); - memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); @@ -438,7 +452,7 @@ TEST_F(NetworkTest, getIPSettings) TEST_F(NetworkTest, getIP6Settings) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -480,7 +494,7 @@ TEST_F(NetworkTest, getIP6Settings) TEST_F(NetworkTest, getIPSettings_wifi) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -523,7 +537,7 @@ TEST_F(NetworkTest, getIPSettings_wifi) TEST_F(NetworkTest, getIP6Settings_wifi) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -566,7 +580,7 @@ TEST_F(NetworkTest, getIP6Settings_wifi) TEST_F(NetworkTest, getIPSettings_Failed) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -599,7 +613,7 @@ TEST_F(NetworkTest, getIPSettings_Failed) TEST_F(NetworkTest, getIPSettings_WrongIface) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -632,7 +646,7 @@ TEST_F(NetworkTest, getIPSettings_WrongIface) TEST_F(NetworkTest, getPublicIP) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -652,7 +666,7 @@ TEST_F(NetworkTest, getPublicIP) TEST_F(NetworkTest, setInterfaceEnabled) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -667,7 +681,7 @@ TEST_F(NetworkTest, setInterfaceEnabled) TEST_F(NetworkTest, setInterfaceEnabled_Failed) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -681,7 +695,7 @@ TEST_F(NetworkTest, setInterfaceEnabled_Failed) TEST_F(NetworkTest, setInterfaceEnabled_WrongIface) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -696,7 +710,7 @@ TEST_F(NetworkTest, setInterfaceEnabled_WrongIface) TEST_F(NetworkTest, getSTBIPFamily) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -733,7 +747,7 @@ TEST_F(NetworkTest, getSTBIPFamily) TEST_F(NetworkTest, getSTBIPFamily_Error) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -768,7 +782,7 @@ TEST_F(NetworkTest, getSTBIPFamily_Error) TEST_F(NetworkTest, getSTBIPFamily_Failed) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -801,7 +815,7 @@ TEST_F(NetworkTest, getSTBIPFamily_Failed) TEST_F(NetworkTest, setDefaultInterface) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -816,7 +830,7 @@ TEST_F(NetworkTest, setDefaultInterface) TEST_F(NetworkTest, setDefaultInterface_WrongIface) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -830,7 +844,7 @@ TEST_F(NetworkTest, setDefaultInterface_WrongIface) TEST_F(NetworkTest, setDefaultInterface_failed) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -844,7 +858,7 @@ TEST_F(NetworkTest, setDefaultInterface_failed) TEST_F(NetworkTest, setIPSettings) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -884,7 +898,7 @@ TEST_F(NetworkTest, setIPSettings) // TEST_F(NetworkTest, trace_fail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -902,7 +916,7 @@ TEST_F(NetworkTest, trace_fail) TEST_F(NetworkTest, trace_noiface) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -940,7 +954,7 @@ TEST_F(NetworkTest, trace_noiface) TEST_F(NetworkTest, traceNamedEndpoint_noendoint) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -959,7 +973,7 @@ TEST_F(NetworkTest, traceNamedEndpoint_noendoint) TEST_F(NetworkTest, traceNamedEndpoint_fail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1007,7 +1021,7 @@ TEST_F(NetworkTest, getNamedEndpoints) TEST_F(NetworkTest, pingNamedEndpoint_noarg) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1026,7 +1040,7 @@ TEST_F(NetworkTest, pingNamedEndpoint_noarg) TEST_F(NetworkTest, pingNamedEndpoint_fail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1068,7 +1082,7 @@ TEST_F(NetworkTest, pingNamedEndpoint_fail) TEST_F(NetworkTest, ping_noendpoint) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1087,7 +1101,7 @@ TEST_F(NetworkTest, ping_noendpoint) TEST_F(NetworkTest, ping_fail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1105,7 +1119,7 @@ TEST_F(NetworkTest, ping_fail) TEST_F(NetworkTest, ping_fail1) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1225,7 +1239,7 @@ TEST_F(NetworkTest, setStunEndPoint) TEST_F(NetworkTest, configurePNI) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1238,7 +1252,7 @@ TEST_F(NetworkTest, configurePNI) TEST_F(NetworkTest, configurePNI_fail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1251,7 +1265,7 @@ TEST_F(NetworkTest, configurePNI_fail) TEST_F(NetworkInitializedEventTest, onInterfaceStatusChanged) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { diff --git a/Tests/tests/test_OCIContainer.cpp b/Tests/L1Tests/tests/test_OCIContainer.cpp old mode 100644 new mode 100755 similarity index 83% rename from Tests/tests/test_OCIContainer.cpp rename to Tests/L1Tests/tests/test_OCIContainer.cpp index e3860b5ba0..b7257a565c --- a/Tests/tests/test_OCIContainer.cpp +++ b/Tests/L1Tests/tests/test_OCIContainer.cpp @@ -27,19 +27,22 @@ class OCIContainerTest : public ::testing::Test { class OCIContainerInitializedTest : public OCIContainerTest { protected: NiceMock service; - DobbyProxyMock dobbymock; - IpcServiceMock ipcservicemock; + DobbyProxyMock *p_dobbymock = nullptr ; + IpcServiceMock *p_ipcservicemock = nullptr ; OCIContainerInitializedTest() : OCIContainerTest() { - DobbyProxy::getInstance().impl = &dobbymock; - IpcService::getInstance().impl = &ipcservicemock; + p_dobbymock = new NiceMock ; + DobbyProxy::setImpl(p_dobbymock); - EXPECT_CALL(ipcservicemock, start()) + p_ipcservicemock = new NiceMock ; + IpcService::setImpl(p_ipcservicemock); + + EXPECT_CALL(*p_ipcservicemock, start()) .WillOnce(::testing::Return(true)); - EXPECT_CALL(dobbymock, registerListener(::testing::_, ::testing::_)) + EXPECT_CALL(*p_dobbymock, registerListener(::testing::_, ::testing::_)) .WillOnce(::testing::Return(5)); EXPECT_EQ(string(""), plugin->Initialize(&service)); @@ -47,10 +50,22 @@ class OCIContainerInitializedTest : public OCIContainerTest { virtual ~OCIContainerInitializedTest() override { - EXPECT_CALL(dobbymock, unregisterListener(5)) + EXPECT_CALL(*p_dobbymock, unregisterListener(5)) .WillOnce(::testing::Return()); plugin->Deinitialize(&service); + DobbyProxy::setImpl(nullptr); + if (p_dobbymock != nullptr) + { + delete p_dobbymock; + p_dobbymock = nullptr; + } + IpcService::setImpl(nullptr); + if (p_ipcservicemock != nullptr) + { + delete p_ipcservicemock; + p_ipcservicemock = nullptr; + } } }; @@ -72,7 +87,7 @@ TEST_F(OCIContainerTest, RegisteredMethods) TEST_F(OCIContainerInitializedTest, listContainersTest) { std::list> containerslist = {{91, "com.bskyb.epgui"},{94, "Netflix"}}; - EXPECT_CALL(dobbymock, listContainers()) + EXPECT_CALL(*p_dobbymock, listContainers()) .WillOnce(::testing::Return(containerslist)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("listContainers"), _T("{}"), response)); @@ -82,10 +97,10 @@ TEST_F(OCIContainerInitializedTest, listContainersTest) TEST_F(OCIContainerInitializedTest, getContainerStateTest) { std::list> containerslist = {{91, "com.bskyb.epgui"},{94, "Netflix"}}; - EXPECT_CALL(dobbymock, listContainers()) + EXPECT_CALL(*p_dobbymock, listContainers()) .WillOnce(::testing::Return(containerslist)); - EXPECT_CALL(dobbymock, getContainerState(91)) + EXPECT_CALL(*p_dobbymock, getContainerState(91)) .WillOnce(::testing::Return(IDobbyProxyEvents::ContainerState::Running)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getContainerState"), _T("{" @@ -97,10 +112,10 @@ TEST_F(OCIContainerInitializedTest, getContainerStateTest) TEST_F(OCIContainerInitializedTest, getContainerInfoTest) { std::list> containerslist = {{91, "com.bskyb.epgui"},{94, "Netflix"}}; - EXPECT_CALL(dobbymock, listContainers()) + EXPECT_CALL(*p_dobbymock, listContainers()) .WillOnce(::testing::Return(containerslist)); - EXPECT_CALL(dobbymock, getContainerInfo(91)) + EXPECT_CALL(*p_dobbymock, getContainerInfo(91)) .WillOnce(::testing::Return("{\"cpu\":{\"usage\" :{\"percpu\" :[3661526845,3773518079,4484546066,4700379608]," "\"total\" : 16619970598}},\"gpu\":{\"memory\" :{\"failcnt\" : 0,\"limit\" : 209715200,\"max\" : 3911680,\"usage\" : 0}}," "\"id\":\"Cobalt-0\",\"ion\":{\"heaps\" :{\"ion.\" :{\"failcnt\" : null,\"limit\" : null,\"max\" : null,\"usage\" : null}}}," @@ -133,7 +148,7 @@ TEST_F(OCIContainerInitializedTest, getContainerInfoTest) TEST_F(OCIContainerInitializedTest, startContainerTest) { - EXPECT_CALL(dobbymock, startContainerFromBundle(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_dobbymock, startContainerFromBundle(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .WillOnce(::testing::Return(91)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startContainer"), _T("{" @@ -144,7 +159,7 @@ TEST_F(OCIContainerInitializedTest, startContainerTest) TEST_F(OCIContainerInitializedTest, startContainerFromDobbySpecTest) { - EXPECT_CALL(dobbymock, startContainerFromSpec(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_dobbymock, startContainerFromSpec(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .WillOnce(::testing::Return(91)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startContainerFromDobbySpec"), _T("{" @@ -156,10 +171,10 @@ TEST_F(OCIContainerInitializedTest, startContainerFromDobbySpecTest) TEST_F(OCIContainerInitializedTest, stopContainerTest) { std::list> containerslist = {{91, "com.bskyb.epgui"},{94, "Netflix"}}; - EXPECT_CALL(dobbymock, listContainers()) + EXPECT_CALL(*p_dobbymock, listContainers()) .WillOnce(::testing::Return(containerslist)); - EXPECT_CALL(dobbymock, stopContainer(91, ::testing::_)) + EXPECT_CALL(*p_dobbymock, stopContainer(91, ::testing::_)) .WillOnce(::testing::Return(true)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("stopContainer"), _T("{" @@ -170,10 +185,10 @@ TEST_F(OCIContainerInitializedTest, stopContainerTest) TEST_F(OCIContainerInitializedTest, pauseContainerTest) { std::list> containerslist = {{91, "com.bskyb.epgui"},{94, "Netflix"}}; - EXPECT_CALL(dobbymock, listContainers()) + EXPECT_CALL(*p_dobbymock, listContainers()) .WillOnce(::testing::Return(containerslist)); - EXPECT_CALL(dobbymock, pauseContainer(91)) + EXPECT_CALL(*p_dobbymock, pauseContainer(91)) .WillOnce(::testing::Return(true)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("pauseContainer"), _T("{" @@ -184,10 +199,10 @@ TEST_F(OCIContainerInitializedTest, pauseContainerTest) TEST_F(OCIContainerInitializedTest, resumeContainerTest) { std::list> containerslist = {{91, "com.bskyb.epgui"},{94, "Netflix"}}; - EXPECT_CALL(dobbymock, listContainers()) + EXPECT_CALL(*p_dobbymock, listContainers()) .WillOnce(::testing::Return(containerslist)); - EXPECT_CALL(dobbymock, resumeContainer(91)) + EXPECT_CALL(*p_dobbymock, resumeContainer(91)) .WillOnce(::testing::Return(true)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("resumeContainer"), _T("{" @@ -198,10 +213,10 @@ TEST_F(OCIContainerInitializedTest, resumeContainerTest) TEST_F(OCIContainerInitializedTest, executeCommandTest) { std::list> containerslist = {{91, "com.bskyb.epgui"},{94, "Netflix"}}; - EXPECT_CALL(dobbymock, listContainers()) + EXPECT_CALL(*p_dobbymock, listContainers()) .WillOnce(::testing::Return(containerslist)); - EXPECT_CALL(dobbymock, execInContainer(91, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_dobbymock, execInContainer(91, ::testing::_, ::testing::_)) .WillOnce(::testing::Return(true)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("executeCommand"), _T("{" diff --git a/Tests/tests/test_Packager.cpp b/Tests/L1Tests/tests/test_Packager.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_Packager.cpp rename to Tests/L1Tests/tests/test_Packager.cpp diff --git a/Tests/tests/test_RDKShell.cpp b/Tests/L1Tests/tests/test_RDKShell.cpp old mode 100644 new mode 100755 similarity index 70% rename from Tests/tests/test_RDKShell.cpp rename to Tests/L1Tests/tests/test_RDKShell.cpp index b68a897201..11f7163605 --- a/Tests/tests/test_RDKShell.cpp +++ b/Tests/L1Tests/tests/test_RDKShell.cpp @@ -13,9 +13,9 @@ class RDKShellTest : public ::testing::Test { Core::JSONRPC::Handler& handler; Core::JSONRPC::Connection connection; Core::JSONRPC::Message message; - testing::NiceMock RDKShellmock; - testing::NiceMock compositormock; - testing::NiceMock rdkshellapimock; + RDKShellImplMock *p_rdkShellImplMock = nullptr ; + CompositorImplMock *p_compositorImplMock = nullptr ; + RdkShellApiImplMock *p_rdkShellApiImplMock = nullptr ; string response; RDKShellTest() @@ -23,18 +23,39 @@ class RDKShellTest : public ::testing::Test { , handler(*(plugin)) , connection(1, 0) { - RdkShell::CompositorController::getInstance().impl = &compositormock; - RdkShell::RdkShellApi::getInstance().impl = &rdkshellapimock; - RDKShell::getInstance().impl = &RDKShellmock; + p_rdkShellApiImplMock = new testing::NiceMock ; + RdkShell::RdkShellApi::setImpl(p_rdkShellApiImplMock); + + p_compositorImplMock = new testing::NiceMock ; + RdkShell::CompositorController::setImpl(p_compositorImplMock); + + p_rdkShellImplMock = new testing::NiceMock ; + RDKShell::setImpl(p_rdkShellImplMock); } virtual ~RDKShellTest() - { - RdkShell::CompositorController::getInstance().impl = nullptr; - RdkShell::RdkShellApi::getInstance().impl = nullptr; - RDKShell::getInstance().impl = nullptr; - } + { + RdkShell::RdkShellApi::setImpl(nullptr); + if (p_rdkShellApiImplMock != nullptr) + { + delete p_rdkShellApiImplMock; + p_rdkShellApiImplMock = nullptr; + } + + RDKShell::setImpl(nullptr); + if (p_rdkShellImplMock != nullptr) + { + delete p_rdkShellImplMock; + p_rdkShellImplMock = nullptr; + } + RdkShell::CompositorController::setImpl(nullptr); + if (p_compositorImplMock != nullptr) + { + delete p_compositorImplMock; + p_compositorImplMock = nullptr; + } + } }; - + TEST_F(RDKShellTest, RegisteredMethods){ EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("addAnimation"))); @@ -123,11 +144,11 @@ TEST_F(RDKShellTest, RegisteredMethods){ } TEST_F(RDKShellTest, enableInputEvents) { - ON_CALL(compositormock, enableInputEvents(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, enableInputEvents(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, bool enable){ - EXPECT_EQ(client, string("searchanddiscovery")); - EXPECT_EQ(enable, true); + EXPECT_EQ(client, string("searchanddiscovery")); + EXPECT_EQ(enable, true); return true; })); @@ -141,13 +162,13 @@ TEST_F(RDKShellTest, enableInputEvents) TEST_F(RDKShellTest, getClients) { - ON_CALL(compositormock, getClients(::testing::_)) + ON_CALL(*p_compositorImplMock, getClients(::testing::_)) .WillByDefault(::testing::Invoke( [](std::vector& clients){ clients.push_back("org.rdk.Netflix"); clients.push_back("org.rdk.RDKBrowser2"); clients.push_back("Test1"); - clients.push_back("Test2"); + clients.push_back("Test2"); return true; })); @@ -155,35 +176,35 @@ TEST_F(RDKShellTest, getClients) EXPECT_EQ(response, string("{" "\"clients\":[" "\"org.rdk.Netflix\"," - "\"org.rdk.RDKBrowser2\"," - "\"Test1\"," - "\"Test2\"" + "\"org.rdk.RDKBrowser2\"," + "\"Test1\"," + "\"Test2\"" "]," "\"success\":true" - "}")); + "}")); } TEST_F(RDKShellTest, keyRepeatConfig) { - ON_CALL(compositormock, setKeyRepeatConfig(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, setKeyRepeatConfig(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](bool enabled, int32_t initialDelay, int32_t repeatInterval){ EXPECT_EQ(enabled, true); - EXPECT_EQ(initialDelay, 500); - EXPECT_EQ(repeatInterval, 250); + EXPECT_EQ(initialDelay, 500); + EXPECT_EQ(repeatInterval, 250); return true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("keyRepeatConfig"), _T("{" "\"enabled\":true," - "\"initialDelay\":500," - "\"repeatInterval\":250}"), response)); + "\"initialDelay\":500," + "\"repeatInterval\":250}"), response)); } TEST_F(RDKShellTest, resetinactivity) { - ON_CALL(compositormock, resetInactivityTime()) + ON_CALL(*p_compositorImplMock, resetInactivityTime()) .WillByDefault(::testing::Invoke( [&](){ })); @@ -194,16 +215,16 @@ TEST_F(RDKShellTest, resetinactivity) TEST_F(RDKShellTest, launchApplication) { - ON_CALL(compositormock, launchApplication(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( - [](const std::string& client, const std::string& uri, const std::string& mimeType, bool topmost, bool focus){ + ON_CALL(*p_compositorImplMock, launchApplication(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [](const std::string& client, const std::string& uri, const std::string& mimeType, bool topmost, bool focus){ EXPECT_EQ(client, string("testApp")); - EXPECT_EQ(uri, string("/usr/bin/westeros_test")); - EXPECT_EQ(mimeType, string("application/native")); - EXPECT_EQ(topmost, false); - EXPECT_EQ(focus, false); - return true; - })); + EXPECT_EQ(uri, string("/usr/bin/westeros_test")); + EXPECT_EQ(mimeType, string("application/native")); + EXPECT_EQ(topmost, false); + EXPECT_EQ(focus, false); + return true; + })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("launchApplication"), _T("{\"client\": \"testApp\"," "\"uri\": \"/usr/bin/westeros_test\"," "\"mimeType\": \"application/native\"}"), response)); @@ -211,49 +232,49 @@ TEST_F(RDKShellTest, launchApplication) TEST_F(RDKShellTest, suspendApplication) { - ON_CALL(compositormock, suspendApplication(::testing::_)) + ON_CALL(*p_compositorImplMock, suspendApplication(::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client){ EXPECT_EQ(client, string("HtmlApp")); return true; })); - ON_CALL(compositormock, setVisibility(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, setVisibility(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, const bool visible){ EXPECT_EQ(client, string("HtmlApp")); - EXPECT_EQ(visible, false); + EXPECT_EQ(visible, false); return true; })); - ON_CALL(compositormock, getMimeType(::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( - [&](const string& client, string& mimeType){ - mimeType = RDKSHELL_APPLICATION_MIME_TYPE_NATIVE; - return true; - })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("suspendApplication"), _T("{\"client\": \"HtmlApp\"}"), response)); + ON_CALL(*p_compositorImplMock, getMimeType(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const string& client, string& mimeType){ + mimeType = RDKSHELL_APPLICATION_MIME_TYPE_NATIVE; + return true; + })); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("suspendApplication"), _T("{\"client\": \"HtmlApp\"}"), response)); } TEST_F(RDKShellTest, resumeApplication) { - ON_CALL(compositormock, resumeApplication(::testing::_)) + ON_CALL(*p_compositorImplMock, resumeApplication(::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client){ EXPECT_EQ(client, string("HtmlApp")); return true; })); - ON_CALL(compositormock, setVisibility(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, setVisibility(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, const bool visible){ EXPECT_EQ(client, string("HtmlApp")); EXPECT_EQ(visible, true); return true; })); - ON_CALL(compositormock, getMimeType(::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( - [&](const string& client, string& mimeType){ - mimeType = RDKSHELL_APPLICATION_MIME_TYPE_NATIVE; - return true; - })); + ON_CALL(*p_compositorImplMock, getMimeType(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const string& client, string& mimeType){ + mimeType = RDKSHELL_APPLICATION_MIME_TYPE_NATIVE; + return true; + })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("resumeApplication"), _T("{\"client\": \"HtmlApp\"}"), response)); } @@ -261,7 +282,7 @@ TEST_F(RDKShellTest, resumeApplication) TEST_F(RDKShellTest, getGraphicsFrameRate) { EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getGraphicsFrameRate"), _T("{}"), response)); - EXPECT_EQ(response, _T("{\"framerate\":40,\"success\":true}")); + EXPECT_EQ(response, _T("{\"framerate\":40,\"success\":true}")); } TEST_F(RDKShellTest, setGraphicsFrameRate) @@ -272,25 +293,25 @@ TEST_F(RDKShellTest, setGraphicsFrameRate) TEST_F(RDKShellTest, showFullScreenImage) { - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("showFullScreenImage"), _T("{\"path\":\"tmp\netflix.png\"}"), response)); - EXPECT_EQ(response, _T("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("showFullScreenImage"), _T("{\"path\":\"tmp\netflix.png\"}"), response)); + EXPECT_EQ(response, _T("{\"success\":true}")); } TEST_F(RDKShellTest, hideFullScreenImage) { - ON_CALL(compositormock, hideFullScreenImage()) + ON_CALL(*p_compositorImplMock, hideFullScreenImage()) .WillByDefault(::testing::Return(true)); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("hideFullScreenImage"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("hideFullScreenImage"), _T("{}"), response)); EXPECT_EQ(response, _T("{\"success\":true}")); } TEST_F(RDKShellTest, setvisibility) { - ON_CALL(compositormock, setVisibility(::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, setVisibility(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client, const bool visible){ - EXPECT_EQ(client, string("org.rdk.Netflix")); - EXPECT_EQ(visible, true); + EXPECT_EQ(client, string("org.rdk.Netflix")); + EXPECT_EQ(visible, true); return true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setVisibility"), _T("{\"client\": \"org.rdk.Netflix\"," @@ -301,11 +322,11 @@ TEST_F(RDKShellTest, setvisibility) TEST_F(RDKShellTest, getVisibility) { - ON_CALL(compositormock, getVisibility(::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, getVisibility(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client, bool& visible){ bool x = true; - visible = x; + visible = x; return true; })); @@ -316,14 +337,14 @@ TEST_F(RDKShellTest, getVisibility) TEST_F(RDKShellTest, getSystemMemory) { - EXPECT_CALL(rdkshellapimock, systemRam(::testing::_, ::testing::_, ::testing::_, ::testing::_)) - .Times(1) + EXPECT_CALL(*p_rdkShellApiImplMock, systemRam(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .Times(1) .WillOnce(::testing::Invoke( [&](uint32_t& freeKb, uint32_t& totalKb, uint32_t& availableKb, uint32_t& usedSwapKb) { - freeKb = 994056; - totalKb = 2830092; - usedSwapKb = 0; - availableKb = 764628; + freeKb = 994056; + totalKb = 2830092; + usedSwapKb = 0; + availableKb = 764628; return true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSystemMemory"), _T("{}"), response)); @@ -331,7 +352,7 @@ TEST_F(RDKShellTest, getSystemMemory) "\"freeRam\":994056," "\"swapRam\":0," "\"totalRam\":2830092," - "\"availablememory\":764628," + "\"availablememory\":764628," "\"success\":true" "}")); } @@ -339,32 +360,32 @@ TEST_F(RDKShellTest, getSystemMemory) TEST_F(RDKShellTest, setBounds) { - ON_CALL(compositormock, setBounds(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, setBounds(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client, const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height){ - EXPECT_EQ(client, string("org.rdk.Netflix")); - EXPECT_EQ(x, 0); - EXPECT_EQ(y, 0); + EXPECT_EQ(client, string("org.rdk.Netflix")); + EXPECT_EQ(x, 0); + EXPECT_EQ(y, 0); return true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setBounds"), _T("{\"client\": \"org.rdk.Netflix\"," "\"callsign\": \"org.rdk.Netflix\",\"x\":0,\"y\":0,\"w\":1920,\"h\":1080}"),response)); - EXPECT_EQ(response, _T("{\"success\":true}")); + EXPECT_EQ(response, _T("{\"success\":true}")); } TEST_F(RDKShellTest, getBounds) { - ON_CALL(compositormock, getBounds(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, getBounds(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, uint32_t &x, uint32_t &y, uint32_t &width, uint32_t &height){ - x = 0; + x = 0; y = 0; - width = 1920; - height = 1080; + width = 1920; + height = 1080; return true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getBounds"), _T("{\"client\": \"org.rdk.Netflix\"," - "\"callsign\": \"org.rdk.Netflix\"}"), response)); + "\"callsign\": \"org.rdk.Netflix\"}"), response)); EXPECT_EQ(response, string("{" "\"bounds\":{" "\"x\":0," @@ -378,8 +399,8 @@ TEST_F(RDKShellTest, getBounds) TEST_F(RDKShellTest, setCursorSize) { - ON_CALL(compositormock, setCursorSize(::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, setCursorSize(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](uint32_t width, uint32_t height){ EXPECT_EQ(width, 255); EXPECT_EQ(height, 255); @@ -390,7 +411,7 @@ TEST_F(RDKShellTest, setCursorSize) } TEST_F(RDKShellTest, getCursorSize) { - ON_CALL(compositormock, getCursorSize(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, getCursorSize(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](uint32_t& width, uint32_t& height){ width = 255; @@ -404,14 +425,14 @@ TEST_F(RDKShellTest, getCursorSize) TEST_F(RDKShellTest, showCursor) { - ON_CALL(compositormock, showCursor()) + ON_CALL(*p_compositorImplMock, showCursor()) .WillByDefault(::testing::Return(true)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("showCursor"), _T("{}"),response)); EXPECT_EQ(response, _T("{\"success\":true}")); } TEST_F(RDKShellTest, hideCursor) { - ON_CALL(compositormock, hideCursor()) + ON_CALL(*p_compositorImplMock, hideCursor()) .WillByDefault(::testing::Return(true)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("hideCursor"), _T("{}"), response)); EXPECT_EQ(response, _T("{\"success\":true}")); @@ -419,11 +440,11 @@ TEST_F(RDKShellTest, hideCursor) TEST_F(RDKShellTest, setLogLevel) { - ON_CALL(compositormock, setLogLevel(::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, setLogLevel(::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string level){ - EXPECT_EQ(level, string("DEBUG")); - return true; + EXPECT_EQ(level, string("DEBUG")); + return true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setLogLevel"), _T("{\"logLevel\": \"DEBUG\"}"), response)); @@ -431,86 +452,86 @@ TEST_F(RDKShellTest, setLogLevel) TEST_F(RDKShellTest, getLogLevel) { - ON_CALL(compositormock, getLogLevel(::testing::_)) + ON_CALL(*p_compositorImplMock, getLogLevel(::testing::_)) .WillByDefault(::testing::Invoke( [](std::string& level){ - std::string a = "DEBUG"; - level = a; + std::string a = "DEBUG"; + level = a; return true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getLogLevel"), _T("{}"), response)); - EXPECT_EQ(response, _T("{\"logLevel\":\"DEBUG\",\"success\":true}")); + EXPECT_EQ(response, _T("{\"logLevel\":\"DEBUG\",\"success\":true}")); } TEST_F(RDKShellTest, enablekeyRepeat) { - ON_CALL(compositormock, enableKeyRepeats(::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, enableKeyRepeats(::testing::_)) + .WillByDefault(::testing::Invoke( [](bool enable){ EXPECT_EQ(enable, true); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("enableKeyRepeats"), _T("{\"enable\":true}"), response)); - EXPECT_EQ(response, _T("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("enableKeyRepeats"), _T("{\"enable\":true}"), response)); + EXPECT_EQ(response, _T("{\"success\":true}")); } TEST_F(RDKShellTest, getKeyRepeatsEnabled) { - ON_CALL(compositormock, getKeyRepeatsEnabled(::testing::_)) + ON_CALL(*p_compositorImplMock, getKeyRepeatsEnabled(::testing::_)) .WillByDefault(::testing::Invoke( [](bool& enable){ enable = true; return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getKeyRepeatsEnabled"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getKeyRepeatsEnabled"), _T("{}"), response)); EXPECT_EQ(response, _T("{\"keyRepeat\":true,\"success\":true}")); } TEST_F(RDKShellTest, setScreenResolution) { - ON_CALL(compositormock, setScreenResolution(::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, setScreenResolution(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](const uint32_t width, const uint32_t height){ EXPECT_EQ(width, 1920); EXPECT_EQ(height, 1080); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setScreenResolution"), _T("{\"w\":1920,\"h\":1080}"), response)); - EXPECT_EQ(response, _T("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setScreenResolution"), _T("{\"w\":1920,\"h\":1080}"), response)); + EXPECT_EQ(response, _T("{\"success\":true}")); } TEST_F(RDKShellTest, getScreenResolution) { - ON_CALL(compositormock, getScreenResolution(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, getScreenResolution(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](uint32_t &width, uint32_t &height){ width = 1920; height = 1080; return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getScreenResolution"), _T("{}"), response)); - EXPECT_EQ(response, _T("{\"w\":1920,\"h\":1080,\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getScreenResolution"), _T("{}"), response)); + EXPECT_EQ(response, _T("{\"w\":1920,\"h\":1080,\"success\":true}")); } TEST_F(RDKShellTest, setVirtualResolution) { - ON_CALL(compositormock, setVirtualResolution(::testing::_, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, setVirtualResolution(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client, const uint32_t virtualWidth, const uint32_t virtualHeight){ - EXPECT_EQ(client, string("org.rdk.Netflix")); + EXPECT_EQ(client, string("org.rdk.Netflix")); EXPECT_EQ(virtualWidth, 1920); EXPECT_EQ(virtualHeight, 1080); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setVirtualResolution"), _T("{\"client\":\"org.rdk.Netflix\",\"width\":1920,\"height\":1080}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setVirtualResolution"), _T("{\"client\":\"org.rdk.Netflix\",\"width\":1920,\"height\":1080}"), response)); EXPECT_EQ(response, _T("{\"success\":true}")); } TEST_F(RDKShellTest, getVirtualResolution) { - ON_CALL(compositormock, getVirtualResolution(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, getVirtualResolution(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, uint32_t &virtualWidth, uint32_t &virtualHeight){ virtualWidth = 1920; @@ -525,27 +546,27 @@ TEST_F(RDKShellTest, getVirtualResolution) TEST_F(RDKShellTest, ScaleToFit) { - ON_CALL(compositormock, scaleToFit(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, scaleToFit(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, const int32_t x, const int32_t y, const uint32_t width, const uint32_t height){ EXPECT_EQ(client, string("org.rdk.Netflix")); - EXPECT_EQ(x, 0); - EXPECT_EQ(y, 0); - EXPECT_EQ(width, 1920); - EXPECT_EQ(height, 1080); - return true; + EXPECT_EQ(x, 0); + EXPECT_EQ(y, 0); + EXPECT_EQ(width, 1920); + EXPECT_EQ(height, 1080); + return true; })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("scaleToFit"), _T("{\"client\": \"org.rdk.Netflix\"," "\"callsign\": \"org.rdk.Netflix\"," "\"x\":0,\"y\":0,\"w\":1920,\"h\":1080}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, hideAllClients) { - ON_CALL(compositormock, getClients(::testing::_)) + ON_CALL(*p_compositorImplMock, getClients(::testing::_)) .WillByDefault(::testing::Invoke( [](std::vector& clients){ clients.push_back("org.rdk.Netflix"); @@ -554,49 +575,48 @@ TEST_F(RDKShellTest, hideAllClients) clients.push_back("Test2"); return true; })); - ON_CALL(compositormock, setVisibility(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, setVisibility(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, const bool visible){ EXPECT_EQ(visible, false); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("hideAllClients"), _T("{\"hide\":true}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("hideAllClients"), _T("{\"hide\":true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, ignoreKeyInputs) { - ON_CALL(compositormock, ignoreKeyInputs(::testing::_)) + ON_CALL(*p_compositorImplMock, ignoreKeyInputs(::testing::_)) .WillByDefault(::testing::Invoke( [](bool ignore){ EXPECT_EQ(ignore, false); return true; - })); + })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("ignoreKeyInputs"), _T("{\"ignore\":false}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, moveToFront) { - - ON_CALL(compositormock, moveToFront(::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, moveToFront(::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client) { EXPECT_EQ(client, string("org.rdk.Netflix")); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("moveToFront"), _T("{\"client\": \"org.rdk.Netflix\"," + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("moveToFront"), _T("{\"client\": \"org.rdk.Netflix\"," "\"callsign\": \"org.rdk.Netflix\"}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, moveToBack) { - ON_CALL(compositormock, moveToBack(::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, moveToBack(::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client) { EXPECT_EQ(client, string("org.rdk.Netflix")); return true; @@ -604,71 +624,70 @@ TEST_F(RDKShellTest, moveToBack) EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("moveToBack"), _T("{\"client\": \"org.rdk.Netflix\"," "\"callsign\": \"org.rdk.Netflix\"}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, moveBehind) { - ON_CALL(compositormock, moveBehind(::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, moveBehind(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client, const std::string& target) { EXPECT_EQ(client, string("org.rdk.Netflix")); - EXPECT_EQ(target, string("org.rdk.RDKBrowser2")); + EXPECT_EQ(target, string("org.rdk.RDKBrowser2")); return true; })); - ON_CALL(compositormock, getClients(::testing::_)) + ON_CALL(*p_compositorImplMock, getClients(::testing::_)) .WillByDefault(::testing::Invoke( [](std::vector& clients){ clients.push_back("org.rdk.Netflix"); clients.push_back("org.rdk.RDKBrowser2"); - clients.push_back("Test2"); + clients.push_back("Test2"); return true; - })); + })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("moveBehind"), _T("{\"client\": \"org.rdk.Netflix\"," "\"target\": \"org.rdk.RDKBrowser2\"}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, getOpacity) { - ON_CALL(compositormock, getOpacity(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, getOpacity(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, unsigned int& opacity) { opacity = 100; return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOpacity"), _T("{\"client\": \"org.rdk.Netflix\"}"), response)); - EXPECT_EQ(response, string("{\"opacity\":100,\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getOpacity"), _T("{\"client\": \"org.rdk.Netflix\"}"), response)); + EXPECT_EQ(response, string("{\"opacity\":100,\"success\":true}")); } TEST_F(RDKShellTest, setFocus) { - ON_CALL(compositormock, setFocus(::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, setFocus(::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client){ EXPECT_EQ(client, string("org.rdk.Netflix")); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setFocus"), _T("{\"client\": \"org.rdk.Netflix\"}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, removeKeyIntercepts) { - ON_CALL(compositormock, removeKeyIntercept(::testing::_, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, removeKeyIntercept(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client, const uint32_t& keyCode, const uint32_t& flags){ EXPECT_EQ(client, string("org.rdk.Netflix")); EXPECT_EQ(keyCode, 10); EXPECT_EQ(flags, RDKSHELL_FLAGS_SHIFT); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("removeKeyIntercept"), _T("{" + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("removeKeyIntercept"), _T("{" "\"keyCode\": 10," "\"modifiers\": [" " \"shift\"" @@ -676,40 +695,40 @@ TEST_F(RDKShellTest, removeKeyIntercepts) "\"client\": \"org.rdk.Netflix\"," "\"callsign\": \"org.rdk.Netflix\"" "}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, removeKeyListeners) { - ON_CALL(compositormock, removeKeyListener(::testing::_, ::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke( + ON_CALL(*p_compositorImplMock, removeKeyListener(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( [](const std::string& client, const uint32_t& keyCode, const uint32_t& flags){ EXPECT_EQ(client, string("org.rdk.Netflix")); - EXPECT_EQ(keyCode, 10); - EXPECT_EQ(flags, RDKSHELL_FLAGS_SHIFT); + EXPECT_EQ(keyCode, 10); + EXPECT_EQ(flags, RDKSHELL_FLAGS_SHIFT); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("removeKeyListener"), _T("{" + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("removeKeyListener"), _T("{" "\"client\": \"org.rdk.Netflix\"," "\"callsign\": \"org.rdk.Netflix\"," "\"keys\": [" "{" "\"keyCode\": 10," - "\"nativekeyCode\": 10," + "\"nativekeyCode\": 10," "\"modifiers\": [" "\"shift\"" "]," - "\"activate\": false," + "\"activate\": false," "\"propagate\": true" "}" "]" "}"), response)); - EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(response, string("{\"success\":true}")); } TEST_F(RDKShellTest, removeKeyMetadataListener) { - ON_CALL(compositormock, removeKeyMetadataListener(::testing::_)) + ON_CALL(*p_compositorImplMock, removeKeyMetadataListener(::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client){ EXPECT_EQ(client, string("org.rdk.Netflix")); @@ -722,34 +741,34 @@ TEST_F(RDKShellTest, removeKeyMetadataListener) TEST_F(RDKShellTest, injectKey) { - ON_CALL(compositormock, injectKey(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, injectKey(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( - [](const uint32_t& keyCode, const uint32_t& flags) { + [](const uint32_t& keyCode, const uint32_t& flags) { EXPECT_EQ(keyCode, 10); EXPECT_EQ(flags, RDKSHELL_FLAGS_SHIFT); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("injectKey"), _T("{\"keyCode\": 10, \"modifiers\": [\"shift\"]}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("injectKey"), _T("{\"keyCode\": 10, \"modifiers\": [\"shift\"]}"), response)); } TEST_F(RDKShellTest, getZOrder) { - ON_CALL(compositormock, getZOrder(::testing::_)) + ON_CALL(*p_compositorImplMock, getZOrder(::testing::_)) .WillByDefault(::testing::Invoke( [](std::vector& clients){ clients.push_back("org.rdk.Netflix"); clients.push_back("org.rdk.RDKBrowser2"); - clients.push_back("Test1"); - clients.push_back("Test2"); + clients.push_back("Test1"); + clients.push_back("Test2"); return true; })); - EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getZOrder"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getZOrder"), _T("{}"), response)); EXPECT_EQ(response, string("{" "\"clients\":[" "\"org.rdk.Netflix\"," "\"org.rdk.RDKBrowser2\"," - "\"Test1\"," + "\"Test1\"," "\"Test2\"" "]," "\"success\":true" @@ -758,13 +777,13 @@ TEST_F(RDKShellTest, getZOrder) TEST_F(RDKShellTest, setHolePunch) { - ON_CALL(compositormock, setHolePunch(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, setHolePunch(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( - [](const std::string& client, const bool holePunch){ - EXPECT_EQ(client, string("org.rdk.Netflix")); - EXPECT_EQ(holePunch, true); - return true; - })); + [](const std::string& client, const bool holePunch){ + EXPECT_EQ(client, string("org.rdk.Netflix")); + EXPECT_EQ(holePunch, true); + return true; + })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setHolePunch"), _T("{\"client\": \"org.rdk.Netflix\"," "\"callsign\": \"org.rdk.Netflix\"," "\"holePunch\": true}"), response)); @@ -774,7 +793,7 @@ TEST_F(RDKShellTest, setHolePunch) TEST_F(RDKShellTest, getHolePunch) { - ON_CALL(compositormock, getHolePunch(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, getHolePunch(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, bool& holePunch){ holePunch = true; @@ -790,11 +809,11 @@ TEST_F(RDKShellTest, getHolePunch) TEST_F(RDKShellTest, getScale) { - ON_CALL(compositormock, getScale(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, getScale(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, double &scaleX, double &scaleY){ scaleX = 1.0; - scaleY = 1.0; + scaleY = 1.0; return true; })); @@ -805,7 +824,7 @@ TEST_F(RDKShellTest, getScale) TEST_F(RDKShellTest, enableVirtualDisplay) { - ON_CALL(compositormock, enableVirtualDisplay(::testing::_, ::testing::_)) + ON_CALL(*p_compositorImplMock, enableVirtualDisplay(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](const std::string& client, const bool enable){ EXPECT_EQ(client, string("org.rdk.Netflix")); @@ -814,14 +833,14 @@ TEST_F(RDKShellTest, enableVirtualDisplay) })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("enableVirtualDisplay"), _T("{\"client\": \"org.rdk.Netflix\"," - "\"callsign\": \"org.rdk.Netflix\"," + "\"callsign\": \"org.rdk.Netflix\"," "\"enable\": true}"), response)); EXPECT_EQ(response, _T("{\"success\":true}")); } TEST_F(RDKShellTest, enableInactivityReporting) { - ON_CALL(compositormock, enableInactivityReporting(::testing::_)) + ON_CALL(*p_compositorImplMock, enableInactivityReporting(::testing::_)) .WillByDefault(::testing::Invoke( [](const bool enable){ EXPECT_EQ(enable, true); diff --git a/Tests/tests/test_ScreenCapture.cpp b/Tests/L1Tests/tests/test_ScreenCapture.cpp old mode 100644 new mode 100755 similarity index 98% rename from Tests/tests/test_ScreenCapture.cpp rename to Tests/L1Tests/tests/test_ScreenCapture.cpp index dfb78233e8..07f086c28d --- a/Tests/tests/test_ScreenCapture.cpp +++ b/Tests/L1Tests/tests/test_ScreenCapture.cpp @@ -41,7 +41,7 @@ class ScreenCaptureEventTest : public ScreenCaptureTest { PluginHost::IFactories::Assign(&factoriesImplementation); dispatcher = static_cast( - plugin->QueryInterface(PluginHost::IDispatcher::ID)); + plugin->QueryInterface(PluginHost::IDispatcher::ID)); dispatcher->Activate(&service); } virtual ~ScreenCaptureEventTest() override diff --git a/Tests/tests/test_SecurityAgent.cpp b/Tests/L1Tests/tests/test_SecurityAgent.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_SecurityAgent.cpp rename to Tests/L1Tests/tests/test_SecurityAgent.cpp diff --git a/Tests/tests/test_SystemAudioPlayer.cpp b/Tests/L1Tests/tests/test_SystemAudioPlayer.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_SystemAudioPlayer.cpp rename to Tests/L1Tests/tests/test_SystemAudioPlayer.cpp diff --git a/Tests/tests/test_SystemServices.cpp b/Tests/L1Tests/tests/test_SystemServices.cpp old mode 100644 new mode 100755 similarity index 96% rename from Tests/tests/test_SystemServices.cpp rename to Tests/L1Tests/tests/test_SystemServices.cpp index 192f27a716..f2f3355882 --- a/Tests/tests/test_SystemServices.cpp +++ b/Tests/L1Tests/tests/test_SystemServices.cpp @@ -45,28 +45,70 @@ class SystemServicesTest : public ::testing::Test { Core::JSONRPC::Handler& handler; Core::JSONRPC::Connection connection; string response; - NiceMock rfcApiImplMock; - NiceMock wrapsImplMock; - NiceMock iarmBusImplMock; - NiceMock hostImplMock; + RfcApiImplMock *p_rfcApiImplMock = nullptr; + IarmBusImplMock *p_iarmBusImplMock = nullptr; + WrapsImplMock *p_wrapsImplMock = nullptr; + SleepModeMock *p_sleepModeMock = nullptr; + HostImplMock *p_hostImplMock = nullptr; SystemServicesTest() : plugin(Core::ProxyType::Create()) , handler(*plugin) , connection(1, 0) { - RfcApi::getInstance().impl = &rfcApiImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - IarmBus::getInstance().impl = &iarmBusImplMock; - device::Host::getInstance().impl = &hostImplMock; + p_rfcApiImplMock = new NiceMock ; + RfcApi::setImpl(p_rfcApiImplMock); + + p_wrapsImplMock = new NiceMock ; + Wraps::setImpl(p_wrapsImplMock); + + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_hostImplMock = new NiceMock ; + device::Host::setImpl(p_hostImplMock); + + p_sleepModeMock = new NiceMock ; + device::SleepMode::setImpl(p_sleepModeMock); + } virtual ~SystemServicesTest() override { - RfcApi::getInstance().impl = nullptr; - Wraps::getInstance().impl = nullptr; - IarmBus::getInstance().impl = nullptr; - device::Host::getInstance().impl = nullptr; + RfcApi::setImpl(nullptr); + if (p_rfcApiImplMock != nullptr) + { + delete p_rfcApiImplMock; + p_rfcApiImplMock = nullptr; + } + + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + + device::SleepMode::setImpl(nullptr); + if (p_sleepModeMock != nullptr) + { + delete p_sleepModeMock; + p_sleepModeMock = nullptr; + } + + device::Host::setImpl(nullptr); + if (p_hostImplMock != nullptr) + { + delete p_hostImplMock; + p_hostImplMock = nullptr; + } } }; @@ -83,7 +125,7 @@ class SystemServicesEventTest : public SystemServicesTest { PluginHost::IFactories::Assign(&factoriesImplementation); dispatcher = static_cast( - plugin->QueryInterface(PluginHost::IDispatcher::ID)); + plugin->QueryInterface(PluginHost::IDispatcher::ID)); dispatcher->Activate(&service); } @@ -106,7 +148,7 @@ class SystemServicesEventIarmTest : public SystemServicesEventTest { SystemServicesEventIarmTest() : SystemServicesEventTest() { - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_SYSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_SYSMGR_EVENT_SYSTEMSTATE)) { @@ -120,7 +162,7 @@ class SystemServicesEventIarmTest : public SystemServicesEventTest { } return IARM_RESULT_SUCCESS; })); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterCall(::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterCall(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* methodName, IARM_BusCall_t handler) { if (string(IARM_BUS_COMMON_API_SysModeChange) == string(methodName)) { @@ -247,7 +289,7 @@ TEST_F(SystemServicesEventTest, PendingReboot) handler.Subscribe(0, _T("onFirmwarePendingReboot"), _T("org.rdk.System"), message); - EXPECT_CALL(rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { @@ -266,7 +308,7 @@ TEST_F(SystemServicesEventTest, PendingReboot) TEST_F(SystemServicesTest, AutoReboot) { - EXPECT_CALL(rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { @@ -282,7 +324,7 @@ TEST_F(SystemServicesTest, AutoReboot) TEST_F(SystemServicesTest, RebootDelay) { - EXPECT_CALL(rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { @@ -695,7 +737,7 @@ TEST_F(SystemServicesTest, SystemVersions) TEST_F(SystemServicesTest, MocaStatus) { - ON_CALL(wrapsImplMock, system(::testing::_)) + ON_CALL(*p_wrapsImplMock, system(::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command) { EXPECT_EQ(string(command), string(_T("/etc/init.d/moca_init start"))); @@ -719,7 +761,7 @@ TEST_F(SystemServicesTest, MocaStatus) TEST_F(SystemServicesTest, updateFirmware) { - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -740,7 +782,7 @@ TEST_F(SystemServicesTest, Mode) EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setMode"), _T("{\"modeInfo\":{}}"), response)); EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setMode"), _T("{\"modeInfo\":{\"mode\":\"unknown\",\"duration\":0}}"), response)); - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DAEMON_NAME))); @@ -748,7 +790,7 @@ TEST_F(SystemServicesTest, Mode) return IARM_RESULT_SUCCESS; }); - ON_CALL(wrapsImplMock, system(::testing::_)) + ON_CALL(*p_wrapsImplMock, system(::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command) { EXPECT_EQ(string(command), string(_T("rm -f /opt/warehouse_mode_active"))); @@ -766,7 +808,7 @@ TEST_F(SystemServicesTest, setDeepSleepTimer) { EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setDeepSleepTimer"), _T("{}"), response)); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -783,7 +825,7 @@ TEST_F(SystemServicesTest, setNetworkStandbyMode) { EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setNetworkStandbyMode"), _T("{}"), response)); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -809,7 +851,7 @@ TEST_F(SystemServicesTest, getsetFriendlyName) TEST_F(SystemServicesTest, getNetworkStandbyMode) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); @@ -826,16 +868,14 @@ TEST_F(SystemServicesTest, getNetworkStandbyMode) TEST_F(SystemServicesTest, setPreferredStandbyMode) { device::SleepMode mode; - NiceMock sleepModeMock; - device::SleepMode::getInstance().impl = &sleepModeMock; - ON_CALL(sleepModeMock, getInstanceByName) + ON_CALL(*p_sleepModeMock, getInstanceByName) .WillByDefault(::testing::Invoke( [&](const std::string& name) -> device::SleepMode& { EXPECT_EQ(name, "LIGHT_SLEEP"); return mode; })); - EXPECT_CALL(hostImplMock, setPreferredSleepMode) + EXPECT_CALL(*p_hostImplMock, setPreferredSleepMode) .Times(2) .WillOnce(::testing::Return(0)) .WillOnce(::testing::Invoke( @@ -852,19 +892,18 @@ TEST_F(SystemServicesTest, setPreferredStandbyMode) TEST_F(SystemServicesTest, getPreferredStandbyMode) { device::SleepMode mode; - NiceMock sleepModeMock; - mode.impl = &sleepModeMock; + string sleepModeString(_T("DEEP_SLEEP")); - ON_CALL(hostImplMock, getPreferredSleepMode) + ON_CALL(*p_hostImplMock, getPreferredSleepMode) .WillByDefault(::testing::Return(mode)); - ON_CALL(sleepModeMock, toString) + ON_CALL(*p_sleepModeMock, toString) .WillByDefault(::testing::ReturnRef(sleepModeString)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPreferredStandbyMode"), _T("{}"), response)); EXPECT_EQ(response, string("{\"preferredStandbyMode\":\"DEEP_SLEEP\",\"success\":true}")); - ON_CALL(hostImplMock, getPreferredSleepMode) + ON_CALL(*p_hostImplMock, getPreferredSleepMode) .WillByDefault(::testing::Invoke( []() -> device::SleepMode { throw device::Exception("test"); @@ -876,19 +915,17 @@ TEST_F(SystemServicesTest, getPreferredStandbyMode) TEST_F(SystemServicesTest, getAvailableStandbyModes) { device::SleepMode mode; - NiceMock sleepModeMock; - mode.impl = &sleepModeMock; string sleepModeString(_T("DEEP_SLEEP")); - ON_CALL(hostImplMock, getAvailableSleepModes) + ON_CALL(*p_hostImplMock, getAvailableSleepModes) .WillByDefault(::testing::Return(std::vector({ mode }))); - ON_CALL(sleepModeMock, toString) + ON_CALL(*p_sleepModeMock, toString) .WillByDefault(::testing::ReturnRef(sleepModeString)); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getAvailableStandbyModes"), _T("{}"), response)); EXPECT_EQ(response, string("{\"supportedStandbyModes\":[\"DEEP_SLEEP\"],\"success\":true}")); - ON_CALL(hostImplMock, getAvailableSleepModes) + ON_CALL(*p_hostImplMock, getAvailableSleepModes) .WillByDefault(::testing::Invoke( []() -> device::List { throw device::Exception("test"); @@ -918,7 +955,7 @@ TEST_F(SystemServicesTest, getAvailableStandbyModes) */ TEST_F(SystemServicesTest, getWakeupReasonFailure) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -940,7 +977,7 @@ TEST_F(SystemServicesTest, getWakeupReasonFailure) TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_IR) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -963,7 +1000,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_IR) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_RCU_BT) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -987,7 +1024,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_RCU_BT) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_RCU_RF4CE) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1011,7 +1048,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_RCU_RF4CE) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_GPIO) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1035,7 +1072,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_GPIO) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_LAN) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1059,7 +1096,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_LAN) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_WLAN) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1083,7 +1120,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_WLAN) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_TIMER) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1107,7 +1144,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_TIMER) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_FRONT_PANEL) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1131,7 +1168,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_FRONT_PANEL) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_WATCHDOG) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1155,7 +1192,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_WATCHDOG) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_SOFTWARE_RESET) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1179,7 +1216,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_SOFTWARE_RES */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_THERMAL_RESET) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1203,7 +1240,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_THERMAL_RESE */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_WARM_RESET) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1227,7 +1264,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_WARM_RESET) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_COLDBOOT) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1251,7 +1288,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_COLDBOOT) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_STR_AUTH_FAILURE) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1275,7 +1312,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_STR_AUTH_FAI */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_CEC) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1299,7 +1336,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_CEC) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_PRESENCE) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1323,7 +1360,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_PRESENCE) */ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_VOICE) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1341,7 +1378,7 @@ TEST_F(SystemServicesTest, getWakeupReasonSuccess_When_WAKEUPREASON_VOICE) TEST_F(SystemServicesTest, getLastWakeupKeyCode) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_DEEPSLEEPMGR_NAME))); @@ -1765,7 +1802,7 @@ extern "C" FILE* __real_popen(const char* command, const char* type); TEST_F(SystemServicesTest, getTimeZones) { - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { EXPECT_THAT(string(command), ::testing::MatchesRegex("zdump \\/usr\\/share\\/zoneinfo/.+")); @@ -1788,7 +1825,7 @@ TEST_F(SystemServicesTest, getLastDeepSleepReason) TEST_F(SystemServicesTest, getCoreTemperature) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); @@ -1805,7 +1842,7 @@ TEST_F(SystemServicesTest, getCoreTemperature) TEST_F(SystemServicesTest, getTemperatureThresholds) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); @@ -1827,7 +1864,7 @@ TEST_F(SystemServicesTest, getTemperatureThresholds) TEST_F(SystemServicesTest, setTemperatureThresholds) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1846,7 +1883,7 @@ TEST_F(SystemServicesTest, setTemperatureThresholds) TEST_F(SystemServicesTest, getOvertempGraceInterval) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); @@ -1863,7 +1900,7 @@ TEST_F(SystemServicesTest, getOvertempGraceInterval) TEST_F(SystemServicesTest, setOvertempGraceInterval) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1885,7 +1922,7 @@ TEST_F(SystemServicesTest, getRFCConfig) EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getRFCConfig"), _T("{\"rfclist\":[]}"), response)); EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getRFCConfig"), _T("{\"rfclist\":[\"#@!\"]}"), response)); - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { EXPECT_EQ(string(pcCallerID), string("SystemServices")); @@ -1910,7 +1947,7 @@ TEST_F(SystemServicesTest, enableXREConnectionRetention) TEST_F(SystemServicesTest, getPowerState) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); @@ -1972,7 +2009,7 @@ TEST_F(SystemServicesTest, setPowerStateFailed_with_invalidpowerstate) */ TEST_F(SystemServicesTest, setPowerStateFailed_when_Bus_call_fails) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -1994,7 +2031,7 @@ TEST_F(SystemServicesTest, setPowerStateFailed_with_invalidpowerstate) */ TEST_F(SystemServicesTest, setPowerStateSuccess_when_powerstate_ON) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -2019,7 +2056,7 @@ TEST_F(SystemServicesTest, setPowerStateSuccess_when_powerstate_ON) */ TEST_F(SystemServicesTest, setPowerStateSuccess_when_powerstate_Light_sleep) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -2045,16 +2082,14 @@ TEST_F(SystemServicesTest, setPowerStateSuccess_when_powerstate_Light_sleep) TEST_F(SystemServicesTest, setPowerStateSuccess_when_powerstate_STANDBY_withValidInstance) { device::SleepMode mode; - NiceMock sleepModeMock; - mode.impl = &sleepModeMock; string sleepModeString(_T("STANDBY")); - ON_CALL(hostImplMock, getPreferredSleepMode) + ON_CALL(*p_hostImplMock, getPreferredSleepMode) .WillByDefault(::testing::Return(mode)); - ON_CALL(sleepModeMock, toString) + ON_CALL(*p_sleepModeMock, toString) .WillByDefault(::testing::ReturnRef(sleepModeString)); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -2081,7 +2116,7 @@ TEST_F(SystemServicesTest, setPowerStateSuccess_when_powerstate_STANDBY_withVali TEST_F(SystemServicesTest, setPowerStateSuccess_when_powerstate_STANDBY_withoutValidInstance) { WPEFramework::Plugin::SystemServices::_instance = nullptr; - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -2107,16 +2142,14 @@ TEST_F(SystemServicesTest, setPowerStateSuccess_when_powerstate_STANDBY_withoutV TEST_F(SystemServicesTest, setPowerStateSuccess_with_PreferedStandbyMode) { device::SleepMode mode; - NiceMock sleepModeMock; - mode.impl = &sleepModeMock; string sleepModeString(_T("DEEP_SLEEP")); - ON_CALL(hostImplMock, getPreferredSleepMode) + ON_CALL(*p_hostImplMock, getPreferredSleepMode) .WillByDefault(::testing::Return(mode)); - ON_CALL(sleepModeMock, toString) + ON_CALL(*p_sleepModeMock, toString) .WillByDefault(::testing::ReturnRef(sleepModeString)); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -2144,7 +2177,7 @@ TEST_F(SystemServicesTest, getPowerStateIsManagedByDevice) TEST_F(SystemServicesTest, getPowerStateBeforeReboot) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); @@ -2160,7 +2193,7 @@ TEST_F(SystemServicesTest, getPowerStateBeforeReboot) TEST_F(SystemServicesTest, setWakeupSrcConfiguration) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -2216,7 +2249,7 @@ TEST_F(SystemServicesTest, deletePersistentPath) })); ON_CALL(amazonService, PersistentPath()) .WillByDefault(::testing::Return(amazonPersistentPath)); - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](const char* command) { @@ -2301,7 +2334,7 @@ TEST_F(SystemServicesEventIarmTest, onSystemPowerStateChanged_PowerState_ON_To_L { Core::Event onSystemPowerStateChanged(false, true); - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { pstParamData->type = WDMP_BOOLEAN; @@ -2351,7 +2384,7 @@ TEST_F(SystemServicesEventIarmTest, onSystemPowerStateChanged_PowerState_ON_To_L TEST_F(SystemServicesEventIarmTest, onSystemPowerStateChanged_PowerState_STANDBY_To_LIGHTSLEEP) { Core::Event onSystemPowerStateChanged(false, true); - EXPECT_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .Times(0); EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) .Times(1) @@ -2399,7 +2432,7 @@ TEST_F(SystemServicesEventIarmTest, onSystemPowerStateChanged_PowerState_ON_To_D Core::File file(uploadStbLogFile); file.Create(); - EXPECT_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .Times(0); std::ofstream deviceProperties("/etc/device.properties"); @@ -2607,7 +2640,7 @@ TEST_F(SystemServicesTest, getDeviceInfoFailed_OnMissingKeyValueInDeviceProperty */ TEST_F(SystemServicesTest, getDeviceInfoFailed_OnManufactureDataReadAPIFailed) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); @@ -2651,7 +2684,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_onMakeParameter) TEST_F(SystemServicesTest, getDeviceInfoSuccess_onValidInput) { - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -2679,7 +2712,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_onValidInput) */ TEST_F(SystemServicesTest, getDeviceInfoSuccess_onQueryParamHardwareId) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); @@ -2706,7 +2739,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_onQueryParamHardwareId) */ TEST_F(SystemServicesTest, getDeviceInfoSuccess_onQueryParamFriendlyIdOrModelName) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); @@ -2737,7 +2770,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_getCachedHardwareId) { //Below IARM_Bus_Call function is called for saving the retrieved data //in member variables [cached value] & setting the corresponding flags to true - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); @@ -2754,7 +2787,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_getCachedHardwareId) //To confirm that the retrieved data is cached Data; //sets an expectation that the IARM_Bus_Call function should not be called during this sequence - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceInfo"), _T("{\"params\":hardwareID}"), response)); @@ -2774,7 +2807,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_getCachedModelName) { //Below IARM_Bus_Call function is called for saving the retrieved data //in member variables [cached value] & setting the corresponding flags to true - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); @@ -2791,7 +2824,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_getCachedModelName) //To confirm that the retrieved data is cached Data; //sets an expectation that the IARM_Bus_Call function should not be called during this sequence - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDeviceInfo"), _T("{\"params\":modelName}"), response)); @@ -2824,7 +2857,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_onQueryParameterHasNoLabelParam) "model_number=SKXI11ANS\n" "wifi_mac=D4:52:EE:32:A3:B1\"\n"; - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { EXPECT_EQ(string(command), string(_T("sh /lib/rdk/getDeviceDetails.sh read"))); @@ -2873,7 +2906,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_onNoValueForQueryParameter) "model_number=SKXI11ANS\n" "wifi_mac=D4:52:EE:32:A3:B1\"\n"; - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { EXPECT_EQ(string(command), string(_T("sh /lib/rdk/getDeviceDetails.sh read"))); @@ -2921,7 +2954,7 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_OnSpecificKeyValueParsing) "imageVersion=SKXI11ANS_VBN_23Q1_sprint_20230129224229sdy_SYNA_CI\n" "model_number=SKXI11ANS\n" "wifi_mac=D4:52:EE:32:A3:B1\"\n"; - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { EXPECT_EQ(string(command), string(_T("sh /lib/rdk/getDeviceDetails.sh read"))); @@ -2967,9 +3000,9 @@ TEST_F(SystemServicesTest, getDeviceInfoSuccess_OnSpecificKeyValueParsing) */ TEST_F(SystemServicesTest, requestSystemRebootSuccess_NrdPluginAppNotRunning) { - ON_CALL(wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) + ON_CALL(*p_wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) .WillByDefault(::testing::Return(-1)); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -2992,11 +3025,11 @@ TEST_F(SystemServicesTest, requestSystemRebootSuccess_NrdPluginAppNotRunning) */ TEST_F(SystemServicesTest, requestSystemRebootSuccess_NrdPluginAppShutdownFailed) { - ON_CALL(wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) + ON_CALL(*p_wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) .WillByDefault(::testing::Return(0)); - ON_CALL(wrapsImplMock, system(::testing::StrEq("pkill nrdPluginApp"))) + ON_CALL(*p_wrapsImplMock, system(::testing::StrEq("pkill nrdPluginApp"))) .WillByDefault(::testing::Return(-1)); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -3017,11 +3050,11 @@ TEST_F(SystemServicesTest, requestSystemRebootSuccess_NrdPluginAppShutdownFailed */ TEST_F(SystemServicesTest, requestSystemRebootSuccess_NrdPluginAppShutdownSuccess) { - ON_CALL(wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) + ON_CALL(*p_wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) .WillByDefault(::testing::Return(0)); - ON_CALL(wrapsImplMock, system(::testing::StrEq("pkill nrdPluginApp"))) + ON_CALL(*p_wrapsImplMock, system(::testing::StrEq("pkill nrdPluginApp"))) .WillByDefault(::testing::Return(0)); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -3045,10 +3078,10 @@ TEST_F(SystemServicesTest, requestSystemRebootSuccess_withoutReason) { // Ignore the application shutdown process here because it would add extra time // to the test execution and is not relevant to this particular test case. - ON_CALL(wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) + ON_CALL(*p_wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) .WillByDefault(::testing::Return(-1)); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -3072,10 +3105,10 @@ TEST_F(SystemServicesTest, requestSystemRebootSuccess_withReason) { // Ignore the application shutdown process here because it would add extra time // to the test execution and is not relevant to this particular test case. - ON_CALL(wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) + ON_CALL(*p_wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) .WillByDefault(::testing::Return(-1)); - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); @@ -3105,9 +3138,9 @@ TEST_F(SystemServicesTest, requestSystemRebootSuccess_onRebootBusAPIFailed) { // Ignore the application shutdown process here because it would add extra time // to the test execution and is not relevant to this particular test case. - ON_CALL(wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) + ON_CALL(*p_wrapsImplMock, system(::testing::StrEq("pgrep nrdPluginApp"))) .WillByDefault(::testing::Return(-1)); - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); @@ -3169,7 +3202,7 @@ TEST_F(SystemServicesTest, getStateInfoFailed_OnInvalidQueryParam) */ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamChannelMap) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -3194,7 +3227,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamChannelMap) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCardDisconnected) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.card.disconnected}"), response)); EXPECT_EQ(response, string("{\"com.comcast.card.disconnected\":0,\"success\":true}")); @@ -3211,7 +3244,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCardDisconnected) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamTuneReady) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.tune_ready}"), response)); EXPECT_EQ(response, string("{\"com.comcast.tune_ready\":0,\"success\":true}")); @@ -3228,7 +3261,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamTuneReady) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCmac) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.cmac}"), response)); EXPECT_EQ(response, string("{\"com.comcast.cmac\":0,\"success\":true}")); @@ -3245,7 +3278,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCmac) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCardMotoEntitlements) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.card.moto.entitlements}"), response)); EXPECT_EQ(response, string("{\"com.comcast.card.moto.entitlements\":0,\"success\":true}")); @@ -3262,7 +3295,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCardMotoEntitlements) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCardMotoHrvRx) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.card.moto.hrv_rx}"), response)); EXPECT_EQ(response, string("{\"com.comcast.card.moto.hrv_rx\":0,\"success\":true}")); @@ -3279,7 +3312,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCardMotoHrvRx) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCardCiscoStatus) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.card.cisco.status}"), response)); EXPECT_EQ(response, string("{\"com.comcast.card.cisco.status\":0,\"success\":true}")); @@ -3296,7 +3329,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCardCiscoStatus) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamVideoPresenting) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.video_presenting}"), response)); EXPECT_EQ(response, string("{\"com.comcast.video_presenting\":0,\"success\":true}")); @@ -3313,7 +3346,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamVideoPresenting) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamHdmiOut) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.hdmi_out}"), response)); EXPECT_EQ(response, string("{\"com.comcast.hdmi_out\":0,\"success\":true}")); @@ -3330,7 +3363,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamHdmiOut) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamHdcpEnabled) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.hdcp_enabled}"), response)); EXPECT_EQ(response, string("{\"com.comcast.hdcp_enabled\":0,\"success\":true}")); @@ -3347,7 +3380,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamHdcpEnabled) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamHdmiEdidRead) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.hdmi_edid_read}"), response)); EXPECT_EQ(response, string("{\"com.comcast.hdmi_edid_read\":0,\"success\":true}")); @@ -3364,7 +3397,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamHdmiEdidRead) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamFirmwareDownload) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.firmware_download}"), response)); EXPECT_EQ(response, string("{\"com.comcast.firmware_download\":0,\"success\":true}")); @@ -3381,7 +3414,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamFirmwareDownload) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamTimeSource) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.time_source}"), response)); EXPECT_EQ(response, string("{\"com.comcast.time_source\":0,\"success\":true}")); @@ -3398,7 +3431,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamTimeSource) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamTimeZoneAvailable) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.time_zone_available}"), response)); EXPECT_EQ(response, string("{\"com.comcast.time_zone_available\":0,\"success\":true}")); @@ -3415,7 +3448,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamTimeZoneAvailable) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCaSystem) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.ca_system}"), response)); EXPECT_EQ(response, string("{\"com.comcast.ca_system\":0,\"success\":true}")); @@ -3432,7 +3465,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCaSystem) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamEstbIp) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.estb_ip}"), response)); EXPECT_EQ(response, string("{\"com.comcast.estb_ip\":0,\"success\":true}")); @@ -3449,7 +3482,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamEstbIp) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamEcmIp) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.ecm_ip}"), response)); EXPECT_EQ(response, string("{\"com.comcast.ecm_ip\":0,\"success\":true}")); @@ -3466,7 +3499,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamEcmIp) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamLanIp) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.lan_ip}"), response)); EXPECT_EQ(response, string("{\"com.comcast.lan_ip\":0,\"success\":true}")); @@ -3483,7 +3516,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamLanIp) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamMoca) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.moca}"), response)); EXPECT_EQ(response, string("{\"com.comcast.moca\":0,\"success\":true}")); @@ -3500,7 +3533,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamMoca) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamDocsis) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.docsis}"), response)); EXPECT_EQ(response, string("{\"com.comcast.docsis\":0,\"success\":true}")); @@ -3517,7 +3550,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamDocsis) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamDsgBroadcastTunnel) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.dsg_broadcast_tunnel}"), response)); EXPECT_EQ(response, string("{\"com.comcast.dsg_broadcast_tunnel\":0,\"success\":true}")); @@ -3534,7 +3567,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamDsgBroadcastTunnel) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamDsgCaTunnel) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.dsg_ca_tunnel}"), response)); EXPECT_EQ(response, string("{\"com.comcast.dsg_ca_tunnel\":0,\"success\":true}")); @@ -3551,7 +3584,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamDsgCaTunnel) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCableCard) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.cable_card}"), response)); EXPECT_EQ(response, string("{\"com.comcast.cable_card\":0,\"success\":true}")); @@ -3568,7 +3601,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCableCard) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCableCardDownload) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.cable_card_download}"), response)); EXPECT_EQ(response, string("{\"com.comcast.cable_card_download\":0,\"success\":true}")); @@ -3585,7 +3618,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCableCardDownload) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCvrSubsystem) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.cvr_subsystem}"), response)); EXPECT_EQ(response, string("{\"com.comcast.cvr_subsystem\":0,\"success\":true}")); @@ -3602,7 +3635,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamCvrSubsystem) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamDownload) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.download}"), response)); EXPECT_EQ(response, string("{\"com.comcast.download\":0,\"success\":true}")); @@ -3619,7 +3652,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamDownload) TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamVodAd) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStateInfo"), _T("{\"param\":com.comcast.vod_ad}"), response)); EXPECT_EQ(response, string("{\"com.comcast.vod_ad\":0,\"success\":true}")); @@ -3650,7 +3683,7 @@ TEST_F(SystemServicesTest, getStateInfoSuccess_onQueryParamVodAd) TEST_F(SystemServicesTest, setBootLoaderPatternFailed_OnEmptyParamList) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setBootLoaderPattern"), _T("{}"), response)); @@ -3667,7 +3700,7 @@ TEST_F(SystemServicesTest, setBootLoaderPatternFailed_OnEmptyParamList) TEST_F(SystemServicesTest, setBootLoaderPatternFailed_Oninvalidpattern) { /*sets the expectation that IARM_Bus_Call should not be called*/ - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setBootLoaderPattern"), _T("{\"pattern\":SILENT_LED_OFF}"), response)); } @@ -3684,7 +3717,7 @@ TEST_F(SystemServicesTest, setBootLoaderPatternFailed_Oninvalidpattern) */ TEST_F(SystemServicesTest, setBootLoaderPatternSuccess_onPatterntypeNORMAL) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -3710,7 +3743,7 @@ TEST_F(SystemServicesTest, setBootLoaderPatternSuccess_onPatterntypeNORMAL) */ TEST_F(SystemServicesTest, setBootLoaderPatternSuccess_onPatterntypeSILENT) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -3737,7 +3770,7 @@ TEST_F(SystemServicesTest, setBootLoaderPatternSuccess_onPatterntypeSILENT) TEST_F(SystemServicesTest, setBootLoaderPatternSuccess_onPatterntypeSILENTLEDON) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -3776,10 +3809,10 @@ TEST_F(SystemServicesTest, setBootLoaderPatternSuccess_onPatterntypeSILENTLEDON) TEST_F(SystemServicesTest,getMacAddressesFailed_WhenFileNotExist) { const string deviceInfoScript = _T("/lib/rdk/getDeviceDetails.sh"); - Core::File file(deviceInfoScript); - remove("/lib/rdk/getDeviceDetails.sh"); + Core::File file(deviceInfoScript); + remove("/lib/rdk/getDeviceDetails.sh"); EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getMacAddresses"), _T("{}"), response)); - file.Destroy(); + file.Destroy(); } /** @@ -3793,10 +3826,10 @@ TEST_F(SystemServicesEventTest, onMacAddressesRetrieved) { Core::Event onMacAddressesRetreived(false, true); const string deviceInfoScript = _T("/lib/rdk/getDeviceDetails.sh"); - Core::File file(deviceInfoScript); - file.Create(); + Core::File file(deviceInfoScript); + file.Create(); - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { const char* valueToReturn = NULL; @@ -3869,7 +3902,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WithHttpStatusCode4 std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_VBN_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -3901,8 +3934,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WithHttpStatusCode4 EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -3918,7 +3951,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WithHttpStatusCode4 std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_VBN_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -3950,8 +3983,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WithHttpStatusCode4 EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -3967,7 +4000,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WithHttpStatusCodeO std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_VBN_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -3999,7 +4032,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WithHttpStatusCodeO EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); @@ -4016,7 +4049,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvPROD) std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_PROD_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4048,8 +4081,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvPROD) EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4065,7 +4098,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvDev) std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_VBN_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4098,8 +4131,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvDev) EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4115,7 +4148,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvVBN) std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_VBN_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4148,8 +4181,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvVBN) EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4165,7 +4198,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvCqa) std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_VBN_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4198,8 +4231,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvCqa) EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4215,7 +4248,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvNotProdWitho std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_VBN_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4247,8 +4280,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenEnvNotProdWitho EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4269,7 +4302,7 @@ TEST_F(SystemServicesEventTest, OnFirmwareUpdateInfoReceived_WhenEnvNotProdWithC file2.Destroy(); file2.Create(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4300,8 +4333,8 @@ TEST_F(SystemServicesEventTest, OnFirmwareUpdateInfoReceived_WhenEnvNotProdWithC EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4324,7 +4357,7 @@ TEST_F(SystemServicesEventTest, OnFirmwareUpdateInfoReceived_WhenEnvNotProdWithC file2.Create(); file2.Write(swUpdateUrl, sizeof(swUpdateUrl)); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4355,7 +4388,7 @@ TEST_F(SystemServicesEventTest, OnFirmwareUpdateInfoReceived_WhenEnvNotProdWithC EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - // Clear file contents + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4387,8 +4420,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WithoutHttpStatusCo EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4404,7 +4437,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenResponseEmpty) std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_PROD_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4436,8 +4469,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenResponseEmpty) EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4453,7 +4486,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenErrorInParsingR std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_PROD_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4485,8 +4518,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenErrorInParsingR EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4502,7 +4535,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenInvalidResponse std::ofstream fileVer("/version.txt"); fileVer << "imagename:PX051AEI_PROD_2203_sprint_20220331225312sdy_NG"; fileVer.close(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4534,8 +4567,8 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenInvalidResponse EXPECT_EQ(response, string("{\"asyncResponse\":true,\"success\":true}")); EXPECT_EQ(Core::ERROR_NONE, onFirmwareUpdateInfoReceived.Lock()); handler.Unsubscribe(0, _T("onFirmwareUpdateInfoReceived"), _T("org.rdk.System"), message); - - // Clear file contents + + // Clear file contents fileVer.open("/version.txt", std::ofstream::out | std::ofstream::trunc); fileVer.close(); } @@ -4562,7 +4595,7 @@ TEST_F(SystemServicesEventTest, onFirmwareUpdateInfoReceived_WhenInvalidResponse */ TEST_F(SystemServicesTest, clearLastDeepSleepReasonFailed_WhenFileFailedToRemove) { - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4585,10 +4618,10 @@ TEST_F(SystemServicesTest, clearLastDeepSleepReasonFailed_WhenPcloseFailed) { //popen mock returns a fake file pointer value. FILE* fakePipe = reinterpret_cast(0x1234); - EXPECT_CALL(wrapsImplMock, popen(testing::_, testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(testing::_, testing::_)) .WillOnce(testing::Return(fakePipe)); //pclose mock returns -1 to simulate a failure to close the file - EXPECT_CALL(wrapsImplMock, pclose(fakePipe)) + EXPECT_CALL(*p_wrapsImplMock, pclose(fakePipe)) .WillOnce(testing::Return(-1)); EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("clearLastDeepSleepReason"), _T("{}"), response)); @@ -4604,7 +4637,7 @@ TEST_F(SystemServicesTest, clearLastDeepSleepReasonFailed_WhenPcloseFailed) */ TEST_F(SystemServicesTest, clearLastDeepSleepReasonSuccess_whenFileSuccessfullyRemoved) { - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -4717,7 +4750,7 @@ TEST_F(SystemServicesTest, getXconfParamsSuccess_withAllXConfparams) file.close(); //model information - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { EXPECT_EQ(string(command), string(_T("PATH=${PATH}:/sbin:/usr/sbin /lib/rdk/getDeviceDetails.sh read"))); @@ -4822,7 +4855,7 @@ TEST_F(SystemServicesTest, getXconfParamsSuccess_onFirmvalueQA) TEST_F(SystemServicesTest, getMfgSerialNumberFailed_whenBusCallFailed) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); @@ -4845,7 +4878,7 @@ TEST_F(SystemServicesTest, getMfgSerialNumberFailed_whenBusCallFailed) */ TEST_F(SystemServicesTest, getMfgSerialNumberSuccess_whenBusCallSuccess) { - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); @@ -4874,7 +4907,7 @@ TEST_F(SystemServicesTest, getMfgSerialNumberSuccess_getCachedMfgSerialNumber) { //Below IARM_Bus_Call function is called for saving the retrieved data //in member variables [cached value] - ON_CALL(iarmBusImplMock, IARM_Bus_Call) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); @@ -4891,7 +4924,7 @@ TEST_F(SystemServicesTest, getMfgSerialNumberSuccess_getCachedMfgSerialNumber) EXPECT_EQ(response, string("{\"mfgSerialNumber\":\"F00020CE000003\",\"success\":true}")); //To confirm that the retrieved data is cached Data; //sets an expectation that the IARM_Bus_Call function should not be called during this sequence - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(0); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getMfgSerialNumber"), _T("{}"), response)); @@ -4921,7 +4954,7 @@ TEST_F(SystemServicesTest, getMfgSerialNumberSuccess_getCachedMfgSerialNumber) */ TEST_F(SystemServicesTest, getSerialNumberTR069Failed_OnGetRFCParameterFailed) { - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { return WDMP_FAILURE; @@ -4940,7 +4973,7 @@ TEST_F(SystemServicesTest, getSerialNumberTR069Failed_OnGetRFCParameterFailed) */ TEST_F(SystemServicesTest, getSerialNumberTR069Success_OnGetRFCParameterSuccess) { - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { // Define the expected serial number @@ -4993,7 +5026,7 @@ TEST_F(SystemServicesTest, getSerialNumberSnmpFailed_WhenTmpSerialNumberFileNotE std::remove("/tmp/.STB_SER_NO"); EXPECT_TRUE(Core::File(string(_T("/lib/rdk/getStateDetails.sh"))).Exists()); - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](const char* command) { @@ -5022,7 +5055,7 @@ TEST_F(SystemServicesTest, getSerialNumberSnmpSuccess_whenSerialNumberIsInTmpFil file2.close(); EXPECT_TRUE(Core::File(string(_T("/lib/rdk/getStateDetails.sh"))).Exists()); - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](const char* command) { @@ -5523,7 +5556,7 @@ TEST_F(SystemServicesTest, getPlatformConfigurationSuccess_withDispatcherInvokeE TEST_F(SystemServicesTest, uploadLogFailed_whenGetFilenameFailed) { - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -5562,7 +5595,7 @@ TEST_F(SystemServicesTest, uploadLogFailed_withBadUrl) TEST_F(SystemServicesTest, uploadLogFailed_whenArchieveLogsFailed) { const string logArchievedPath = _T("/tmp/test_mac_Logs_" + currentDateTimeUtc("%m-%d-%y-%I-%M%p") + ".tgz"); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -5594,7 +5627,7 @@ TEST_F(SystemServicesTest, uploadLogSuccess_withValidURL) Core::File file(logArchievedPath); file.Create(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -5627,7 +5660,7 @@ TEST_F(SystemServicesTest, uploadLogSuccess_WithDefaultURL) Core::File file(logArchievedPath); file.Create(); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -5709,7 +5742,7 @@ TEST_F(SystemServicesTest, uploadLogsAsyncFailed_WhenDcmFileNotExist) file.Create(); EXPECT_TRUE(Core::File(string(_T("/lib/rdk/uploadSTBLogs.sh"))).Exists()); - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { pstParamData->type = WDMP_BOOLEAN; @@ -5752,7 +5785,7 @@ TEST_F(SystemServicesTest, uploadLogsAsyncSuccess_WithBuildTypeProd) file.Create(); EXPECT_TRUE(Core::File(string(_T("/lib/rdk/uploadSTBLogs.sh"))).Exists()); - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { pstParamData->type = WDMP_BOOLEAN; @@ -5804,7 +5837,7 @@ TEST_F(SystemServicesTest, uploadLogsAsyncSuccess_WhenDcmFileExist) file.Create(); EXPECT_TRUE(Core::File(string(_T("/lib/rdk/uploadSTBLogs.sh"))).Exists()); - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { pstParamData->type = WDMP_BOOLEAN; @@ -5862,7 +5895,7 @@ TEST_F(SystemServicesTest, uploadLogsAsyncSuccess_WhenDcmFileExist) */ TEST_F(SystemServicesTest, abortLogUploadFailure_whenUploadLogScriptNotRunning) { - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { return __real_popen(command, type); @@ -5885,7 +5918,7 @@ TEST_F(SystemServicesTest, abortLogUploadSuccess) file.Create(); EXPECT_TRUE(Core::File(string(_T("/lib/rdk/uploadSTBLogs.sh"))).Exists()); - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { pstParamData->type = WDMP_BOOLEAN; @@ -5908,10 +5941,10 @@ TEST_F(SystemServicesTest, abortLogUploadSuccess) tmpDcmSettings.close(); EXPECT_TRUE(Core::File(string(_T("/tmp/DCMSettings.conf"))).Exists()); - //uploadLogsAsync method is invoked first to ensure that m_uploadLogsPid is assigned a value other than -1. + //uploadLogsAsync method is invoked first to ensure that m_uploadLogsPid is assigned a value other than -1. EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("uploadLogsAsync"), _T("{}"), response)); - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { return __real_popen(command, type); @@ -5948,7 +5981,7 @@ TEST_F(SystemServicesEventIarmTest, onLogUploadSuccess_withUploadStatusSuccess) file.Create(); - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { pstParamData->type = WDMP_BOOLEAN; @@ -6026,7 +6059,7 @@ TEST_F(SystemServicesEventIarmTest, onLogUploadSuccess_withAbortStatusSuccess) file.Create(); - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { pstParamData->type = WDMP_BOOLEAN; diff --git a/Tests/tests/test_Telemetry.cpp b/Tests/L1Tests/tests/test_Telemetry.cpp old mode 100644 new mode 100755 similarity index 82% rename from Tests/tests/test_Telemetry.cpp rename to Tests/L1Tests/tests/test_Telemetry.cpp index a296eee6f5..49203d7ddc --- a/Tests/tests/test_Telemetry.cpp +++ b/Tests/L1Tests/tests/test_Telemetry.cpp @@ -21,25 +21,31 @@ using ::testing::NiceMock; class T2Test : public ::testing::Test { protected: - TelemetryApiImplMock telemetryApiImplMock; + TelemetryApiImplMock *p_telemetryApiImplMock = nullptr ; T2Test() { - TelemetryApi::getInstance().impl = &telemetryApiImplMock; + p_telemetryApiImplMock = new NiceMock ; + TelemetryApi::setImpl(p_telemetryApiImplMock); - EXPECT_CALL(telemetryApiImplMock, t2_init(::testing::_)) + EXPECT_CALL(*p_telemetryApiImplMock, t2_init(::testing::_)) .Times(1); } virtual ~T2Test() { - TelemetryApi::getInstance().impl = nullptr; + TelemetryApi::setImpl(nullptr); + if (p_telemetryApiImplMock != nullptr) + { + delete p_telemetryApiImplMock; + p_telemetryApiImplMock = nullptr; + } } }; class TelemetryTest : public T2Test { protected: NiceMock service; - NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; Core::ProxyType plugin; Core::JSONRPC::Handler& handler; Core::JSONRPC::Connection connection; @@ -52,10 +58,11 @@ class TelemetryTest : public T2Test { , handler(*plugin) , connection(1, 0) { - IarmBus::getInstance().impl = &iarmBusImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); Core::Directory(t2PpersistentFolder.c_str()).Destroy(true); - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_PWRMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_PWRMGR_EVENT_MODECHANGED)) { @@ -68,22 +75,33 @@ class TelemetryTest : public T2Test { } virtual ~TelemetryTest() override { - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } } }; class TelemetryRfcTest : public TelemetryTest { protected: - RfcApiImplMock rfcApiImplMock; + RfcApiImplMock *p_rfcApiImplMock = nullptr ; TelemetryRfcTest() : TelemetryTest() { - RfcApi::getInstance().impl = &rfcApiImplMock; + p_rfcApiImplMock = new NiceMock ; + RfcApi::setImpl(p_rfcApiImplMock); } virtual ~TelemetryRfcTest() override { - RfcApi::getInstance().impl = nullptr; + RfcApi::setImpl(nullptr); + if (p_rfcApiImplMock != nullptr) + { + delete p_rfcApiImplMock; + p_rfcApiImplMock = nullptr; + } } }; @@ -95,7 +113,7 @@ class TelemetryRBusTest : public TelemetryTest { FactoriesImplementation factoriesImplementation; PluginHost::IDispatcher* dispatcher; - RBusApiImplMock rBusApiImplMock; + RBusApiImplMock *p_rBusApiImplMock = nullptr; TelemetryRBusTest() : TelemetryTest() @@ -103,14 +121,20 @@ class TelemetryRBusTest : public TelemetryTest { PluginHost::IFactories::Assign(&factoriesImplementation); dispatcher = static_cast( - plugin->QueryInterface(PluginHost::IDispatcher::ID)); + plugin->QueryInterface(PluginHost::IDispatcher::ID)); dispatcher->Activate(&service); - RBusApi::getInstance().impl = &rBusApiImplMock; + p_rBusApiImplMock = new NiceMock ; + RBusApi::setImpl(p_rBusApiImplMock); } virtual ~TelemetryRBusTest() override { - RBusApi::getInstance().impl = nullptr; + RBusApi::setImpl(nullptr); + if (p_rBusApiImplMock != nullptr) + { + delete p_rBusApiImplMock; + p_rBusApiImplMock = nullptr; + } dispatcher->Deactivate(); dispatcher->Release(); @@ -134,7 +158,7 @@ TEST_F(TelemetryRfcTest, InitializeDefaultProfile) "\"t2PersistentFolder\":\"/tmp/.t2reportprofiles/\"," "\"defaultProfilesFile\":\"/tmp/DefaultProfile.json\"" "}")); - EXPECT_CALL(rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { @@ -164,7 +188,7 @@ TEST_F(TelemetryRfcTest, InitializeDefaultProfileRFCFailure) "\"t2PersistentFolder\":\"/tmp/.t2reportprofiles/\"," "\"defaultProfilesFile\":\"/tmp/DefaultProfile.json\"" "}")); - EXPECT_CALL(rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { @@ -222,7 +246,7 @@ TEST_F(TelemetryRfcTest, Plugin) ON_CALL(service, ConfigLine()) .WillByDefault( ::testing::Return("{}")); - EXPECT_CALL(rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(3) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { @@ -246,7 +270,7 @@ TEST_F(TelemetryRfcTest, Plugin) return WDMP_SUCCESS; })); - EXPECT_CALL(telemetryApiImplMock, t2_event_s(::testing::_, ::testing::_)) + EXPECT_CALL(*p_telemetryApiImplMock, t2_event_s(::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](char* marker, char* value) { @@ -274,7 +298,7 @@ TEST_F(TelemetryRfcTest, Plugin) TEST_F(TelemetryRBusTest, uploadLogsRbusOpenFailure) { - EXPECT_CALL(rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](rbusHandle_t* handle, char const* componentName) { @@ -292,18 +316,18 @@ TEST_F(TelemetryRBusTest, uploadLogsRbusOpenFailure) TEST_F(TelemetryRBusTest, uploadLogsRbusMethodFailure) { - ON_CALL(rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); - EXPECT_CALL(rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) { return RBUS_ERROR_BUS_ERROR; })); - ON_CALL(rBusApiImplMock, rbus_close(::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_close(::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); @@ -320,11 +344,11 @@ TEST_F(TelemetryRBusTest, uploadLogsCallbackFailed) struct _rbusObject rbObject; - ON_CALL(rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); - EXPECT_CALL(rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) { @@ -333,7 +357,7 @@ TEST_F(TelemetryRBusTest, uploadLogsCallbackFailed) return RBUS_ERROR_SUCCESS; })); - ON_CALL(rBusApiImplMock, rbus_close(::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_close(::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); @@ -371,11 +395,11 @@ TEST_F(TelemetryRBusTest, uploadLogsGetValueFailure) struct _rbusObject rbObject; - ON_CALL(rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); - EXPECT_CALL(rBusApiImplMock, rbusObject_GetValue(::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbusObject_GetValue(::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](rbusObject_t object, char const* name) { @@ -384,7 +408,7 @@ TEST_F(TelemetryRBusTest, uploadLogsGetValueFailure) return nullptr; })); - ON_CALL(rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) { callback(handle, methodName, RBUS_ERROR_SUCCESS, &rbObject); @@ -392,7 +416,7 @@ TEST_F(TelemetryRBusTest, uploadLogsGetValueFailure) return RBUS_ERROR_SUCCESS; })); - ON_CALL(rBusApiImplMock, rbus_close(::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_close(::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); @@ -431,11 +455,11 @@ TEST_F(TelemetryRBusTest, uploadLogsFailure) struct _rbusObject rbObject; struct _rbusValue rbValue; - ON_CALL(rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); - EXPECT_CALL(rBusApiImplMock, rbusValue_GetString(::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbusValue_GetString(::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](rbusValue_t value, int* len) { @@ -443,7 +467,7 @@ TEST_F(TelemetryRBusTest, uploadLogsFailure) return "FAILURE"; })); - ON_CALL(rBusApiImplMock, rbusObject_GetValue(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbusObject_GetValue(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](rbusObject_t object, char const* name) { EXPECT_EQ(object, &rbObject); @@ -451,7 +475,7 @@ TEST_F(TelemetryRBusTest, uploadLogsFailure) return &rbValue; })); - EXPECT_CALL(rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) { @@ -460,7 +484,7 @@ TEST_F(TelemetryRBusTest, uploadLogsFailure) return RBUS_ERROR_SUCCESS; })); - ON_CALL(rBusApiImplMock, rbus_close(::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_close(::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); @@ -499,15 +523,15 @@ TEST_F(TelemetryRBusTest, uploadLogs) struct _rbusObject rbObject; struct _rbusValue rbValue; - ON_CALL(rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); - ON_CALL(rBusApiImplMock, rbusValue_GetString(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbusValue_GetString(::testing::_, ::testing::_)) .WillByDefault( ::testing::Return( "SUCCESS")); - ON_CALL(rBusApiImplMock, rbusObject_GetValue(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbusObject_GetValue(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](rbusObject_t object, char const* name) { EXPECT_EQ(object, &rbObject); @@ -515,7 +539,7 @@ TEST_F(TelemetryRBusTest, uploadLogs) return &rbValue; })); - EXPECT_CALL(rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) { @@ -524,7 +548,7 @@ TEST_F(TelemetryRBusTest, uploadLogs) return RBUS_ERROR_SUCCESS; })); - ON_CALL(rBusApiImplMock, rbus_close(::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_close(::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); @@ -558,11 +582,11 @@ TEST_F(TelemetryRBusTest, uploadLogs) TEST_F(TelemetryRBusTest, uploadLogsOnStandby) { - ON_CALL(rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); - EXPECT_CALL(rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) { @@ -570,7 +594,7 @@ TEST_F(TelemetryRBusTest, uploadLogsOnStandby) return RBUS_ERROR_SUCCESS; })); - ON_CALL(rBusApiImplMock, rbus_close(::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_close(::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); @@ -588,11 +612,11 @@ TEST_F(TelemetryRBusTest, uploadLogsOnStandby) TEST_F(TelemetryRBusTest, uploadLogsOnDeepSleep) { - ON_CALL(rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_open(::testing::_, ::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); - EXPECT_CALL(rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rBusApiImplMock, rbusMethod_InvokeAsync(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) { @@ -600,7 +624,7 @@ TEST_F(TelemetryRBusTest, uploadLogsOnDeepSleep) return RBUS_ERROR_SUCCESS; })); - ON_CALL(rBusApiImplMock, rbus_close(::testing::_)) + ON_CALL(*p_rBusApiImplMock, rbus_close(::testing::_)) .WillByDefault( ::testing::Return(RBUS_ERROR_SUCCESS)); diff --git a/Tests/tests/test_TextToSpeech.cpp b/Tests/L1Tests/tests/test_TextToSpeech.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_TextToSpeech.cpp rename to Tests/L1Tests/tests/test_TextToSpeech.cpp diff --git a/Tests/tests/test_Timer.cpp b/Tests/L1Tests/tests/test_Timer.cpp old mode 100644 new mode 100755 similarity index 96% rename from Tests/tests/test_Timer.cpp rename to Tests/L1Tests/tests/test_Timer.cpp index 43e1ced6f9..85d40322a3 --- a/Tests/tests/test_Timer.cpp +++ b/Tests/L1Tests/tests/test_Timer.cpp @@ -26,6 +26,7 @@ #include "ServiceMock.h" using namespace WPEFramework; +using ::testing::NiceMock; class TimerTest : public ::testing::Test { protected: @@ -45,12 +46,13 @@ class TimerTest : public ::testing::Test { class TimerInitializedTest : public TimerTest { protected: - IarmBusImplMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; TimerInitializedTest() : TimerTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); EXPECT_EQ(string(""), plugin->Initialize(nullptr)); } @@ -58,7 +60,13 @@ class TimerInitializedTest : public TimerTest { { plugin->Deinitialize(nullptr); - IarmBus::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + } }; diff --git a/Tests/tests/test_TraceControlJsonRpc.cpp b/Tests/L1Tests/tests/test_TraceControlJsonRpc.cpp old mode 100644 new mode 100755 similarity index 92% rename from Tests/tests/test_TraceControlJsonRpc.cpp rename to Tests/L1Tests/tests/test_TraceControlJsonRpc.cpp index fc31ae5b37..53b07a71f2 --- a/Tests/tests/test_TraceControlJsonRpc.cpp +++ b/Tests/L1Tests/tests/test_TraceControlJsonRpc.cpp @@ -7,6 +7,7 @@ #include "WrapsMock.h" using namespace WPEFramework; +using ::testing::NiceMock; namespace { const string callSign = _T("TraceControl"); @@ -19,7 +20,7 @@ class TraceControlJsonRpcTest : public ::testing::Test { Core::ProxyType plugin; Core::JSONRPC::Handler& handler; Core::JSONRPC::Connection connection; - WrapsImplMock wrapsImplMock; + WrapsImplMock *p_wrapsImplMock = nullptr ; string response; TraceControlJsonRpcTest() @@ -28,12 +29,19 @@ class TraceControlJsonRpcTest : public ::testing::Test { , connection(1, 0) { Trace::TraceUnit::Instance().Open(volatilePath); - Wraps::getInstance().impl = &wrapsImplMock; + p_wrapsImplMock = new testing::NiceMock ; + Wraps::setImpl(p_wrapsImplMock); } virtual ~TraceControlJsonRpcTest() { - Wraps::getInstance().impl = nullptr; + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + plugin.Release(); Trace::TraceUnit::Instance().Close(); } @@ -84,7 +92,7 @@ TEST_F(TraceControlJsonRpcTest, registeredMethods) */ TEST_F(TraceControlJsonRpcInitializedTest, DISABLED_jsonRpc) { - EXPECT_CALL(wrapsImplMock, syslog(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, syslog(::testing::_, ::testing::_, ::testing::_)) .WillOnce(::testing::Return()); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("status"), _T("{}"), response)); @@ -133,7 +141,7 @@ TEST_F(TraceControlJsonRpcInitializedTest, DISABLED_jsonRpc) */ TEST_F(TraceControlJsonRpcInitializedTest, DISABLED_syslogFormat) { - EXPECT_CALL(wrapsImplMock, syslog(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, syslog(::testing::_, ::testing::_, ::testing::_)) .WillOnce(::testing::Invoke( [&](int pri, const char* fmt, va_list args) -> void { EXPECT_EQ(LOG_NOTICE, pri); diff --git a/Tests/tests/test_TraceControlWeb.cpp b/Tests/L1Tests/tests/test_TraceControlWeb.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_TraceControlWeb.cpp rename to Tests/L1Tests/tests/test_TraceControlWeb.cpp diff --git a/Tests/tests/test_UsbAccess.cpp b/Tests/L1Tests/tests/test_UsbAccess.cpp old mode 100644 new mode 100755 similarity index 81% rename from Tests/tests/test_UsbAccess.cpp rename to Tests/L1Tests/tests/test_UsbAccess.cpp index 80392705d7..8dbe73ab3e --- a/Tests/tests/test_UsbAccess.cpp +++ b/Tests/L1Tests/tests/test_UsbAccess.cpp @@ -24,31 +24,54 @@ class UsbAccessTest : public ::testing::Test { Core::ProxyType plugin; Core::JSONRPC::Handler& handler; Core::JSONRPC::Connection connection; - Core::JSONRPC::Message message; + Core::JSONRPC::Message message; string response; - NiceMock udevImplMock; - NiceMock wrapsImplMock; - NiceMock iarmBusImplMock; + UdevImplMock *p_udevImplMock = nullptr ; + WrapsImplMock *p_wrapsImplMock = nullptr ; + IarmBusImplMock *p_iarmBusImplMock = nullptr; UsbAccessTest() : plugin(Core::ProxyType::Create()) , handler(*(plugin)) , connection(1, 0) { - /*In order to ensure consistent behavior across all test APIs, + /*In order to ensure consistent behavior across all test APIs, the "/etc/device.properties" file is opened only once*/ std::ofstream file("/etc/device.properties"); file << "MODEL_NUM=HSTP11MWR"; file.close(); - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - IarmBus::getInstance().impl = &iarmBusImplMock; + p_wrapsImplMock = new testing::NiceMock ; + Wraps::setImpl(p_wrapsImplMock); + + p_udevImplMock = new testing::NiceMock ; + Udev::setImpl(p_udevImplMock); + + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + } virtual ~UsbAccessTest() override { - Wraps::getInstance().impl = nullptr; - Udev::getInstance().impl = nullptr; - IarmBus::getInstance().impl = nullptr; + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + + Udev::setImpl(nullptr); + if (p_udevImplMock != nullptr) + { + delete p_udevImplMock; + p_udevImplMock = nullptr; + } + + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } } }; @@ -85,7 +108,7 @@ class UsbAccessEventIarmTest : public UsbAccessEventTest { UsbAccessEventIarmTest() : UsbAccessEventTest() { - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { if ((string(IARM_BUS_SYSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_SYSMGR_EVENT_USB_MOUNT_CHANGED)) { @@ -138,10 +161,7 @@ extern "C" FILE* __real_popen(const char* command, const char* type); TEST_F(UsbAccessTest, UpdateFirmware) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - - EXPECT_CALL(wrapsImplMock, v_secure_system(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, v_secure_system(::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](const char* command, va_list args) { @@ -204,14 +224,11 @@ TEST_F(UsbAccessTest, getFileListFailure_BadRequest) */ TEST_F(UsbAccessTest, getFileListFailure_whenDeviceListEmpty) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(nullptr)); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -239,24 +256,22 @@ TEST_F(UsbAccessTest, getFileListFailure_whenDeviceListEmpty) */ TEST_F(UsbAccessTest, getFileListFailure_when_setmntentNull) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, setmntent(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, setmntent(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -277,24 +292,21 @@ TEST_F(UsbAccessTest, getFileListFailure_when_setmntentNull) */ TEST_F(UsbAccessTest, getFileListFailure_when_getmntentNull) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { return static_cast(NULL); @@ -313,24 +325,22 @@ TEST_F(UsbAccessTest, getFileListFailure_when_getmntentNull) */ TEST_F(UsbAccessTest, getFileListFailure_when_devNodNotFound) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -368,24 +378,22 @@ TEST_F(UsbAccessTest, getFileListFailure_when_devNodNotFound) */ TEST_F(UsbAccessTest, getFileListSuccess_whenAbsPathFound) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -410,7 +418,9 @@ TEST_F(UsbAccessTest, getFileListSuccess_whenAbsPathFound) })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getFileList"), _T("{\"path\":\"/run/media/sda1/logs/PreviousLogs\"}"), response)); - EXPECT_EQ(response, string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\\/PreviousLogs\",\"contents\":[{\"name\":\".\",\"t\":\"d\"},{\"name\":\"..\",\"t\":\"d\"},{\"name\":\"logFile.txt\",\"t\":\"f\"}],\"success\":true}")); + bool res1 = (response.compare(string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\\/PreviousLogs\",\"contents\":[{\"name\":\"logFile.txt\",\"t\":\"f\"},{\"name\":\"..\",\"t\":\"d\"},{\"name\":\".\",\"t\":\"d\"}],\"success\":true}")) == 0); + bool res2 = (response.compare(string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\\/PreviousLogs\",\"contents\":[{\"name\":\".\",\"t\":\"d\"},{\"name\":\"..\",\"t\":\"d\"},{\"name\":\"logFile.txt\",\"t\":\"f\"}],\"success\":true}")) == 0); + EXPECT_EQ(res1 || res2, true); } /** @@ -425,25 +435,23 @@ TEST_F(UsbAccessTest, getFileListSuccess_whenAbsPathFound) */ TEST_F(UsbAccessTest, getFileListSuccess_withoutPath) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -468,7 +476,9 @@ TEST_F(UsbAccessTest, getFileListSuccess_withoutPath) })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getFileList"), _T("{\"path\":}"), response)); - EXPECT_EQ(response, string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\",\"contents\":[{\"name\":\".\",\"t\":\"d\"},{\"name\":\"..\",\"t\":\"d\"},{\"name\":\"PreviousLogs\",\"t\":\"d\"}],\"success\":true}")); + bool res1 = (response.compare(string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\",\"contents\":[{\"name\":\"..\",\"t\":\"d\"},{\"name\":\"PreviousLogs\",\"t\":\"d\"},{\"name\":\".\",\"t\":\"d\"}],\"success\":true}")) == 0); + bool res2 = (response.compare(string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\",\"contents\":[{\"name\":\".\",\"t\":\"d\"},{\"name\":\"..\",\"t\":\"d\"},{\"name\":\"PreviousLogs\",\"t\":\"d\"}],\"success\":true}")) == 0); + EXPECT_EQ(res1 || res2, true); } /** @@ -484,25 +494,22 @@ TEST_F(UsbAccessTest, getFileListSuccess_withoutPath) */ TEST_F(UsbAccessTest, getFileListSuccess_withRelativePathParam) { - - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -529,7 +536,9 @@ TEST_F(UsbAccessTest, getFileListSuccess_withRelativePathParam) })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getFileList"), _T("{\"path\":\"sda1/logs/PreviousLogs\"}"), response)); - EXPECT_EQ(response, string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\\/PreviousLogs\",\"contents\":[{\"name\":\".\",\"t\":\"d\"},{\"name\":\"..\",\"t\":\"d\"},{\"name\":\"logFile.txt\",\"t\":\"f\"}],\"success\":true}")); + bool res1 = (response.compare(string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\\/PreviousLogs\",\"contents\":[{\"name\":\"logFile.txt\",\"t\":\"f\"},{\"name\":\"..\",\"t\":\"d\"},{\"name\":\".\",\"t\":\"d\"}],\"success\":true}")) == 0); + bool res2 = (response.compare(string("{\"path\":\"\\/run\\/media\\/sda1\\/logs\\/PreviousLogs\",\"contents\":[{\"name\":\".\",\"t\":\"d\"},{\"name\":\"..\",\"t\":\"d\"},{\"name\":\"logFile.txt\",\"t\":\"f\"}],\"success\":true}")) == 0); + EXPECT_EQ(res1 || res2, true); } /** * @brief : getFileList when absolute path is found @@ -547,25 +556,22 @@ TEST_F(UsbAccessTest, getFileListSuccess_withSpecialCharacters) std::string filePath = directory + fileName; std::ofstream fileStream(filePath); } - - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -626,24 +632,22 @@ for (const auto& fileName1 :fileNames) { */ TEST_F(UsbAccessTest, getMountedFailure_when_setmntentNull) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, setmntent(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, setmntent(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -665,24 +669,22 @@ TEST_F(UsbAccessTest, getMountedFailure_when_setmntentNull) */ TEST_F(UsbAccessTest, getMountedSuccess_when_getmntentNull) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { return static_cast(NULL); @@ -701,14 +703,11 @@ TEST_F(UsbAccessTest, getMountedSuccess_when_getmntentNull) */ TEST_F(UsbAccessTest, getMountedSuccess_whenDeviceListEmpty) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(nullptr)); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -737,24 +736,22 @@ TEST_F(UsbAccessTest, getMountedSuccess_whenDeviceListEmpty) */ TEST_F(UsbAccessTest, getMountedSuccess_when_devNodNotFound) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -793,25 +790,23 @@ TEST_F(UsbAccessTest, getMountedSuccess_when_devNodNotFound) */ TEST_F(UsbAccessTest, getMountedSuccess_withUSBMountPath) { - Udev::getInstance().impl = &udevImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -861,21 +856,22 @@ TEST_F(UsbAccessTest, getMountedSuccess_withUSBMountPath) */ TEST_F(UsbAccessTest, getAvailableFirmwareFilesFailed_whenSetmntentValueNull) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, setmntent(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, setmntent(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -896,22 +892,23 @@ TEST_F(UsbAccessTest, getAvailableFirmwareFilesFailed_whenSetmntentValueNull) */ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_when_getmntentNull) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { return static_cast(NULL); @@ -931,10 +928,11 @@ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_when_getmntentNull) */ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_whenDeviceListEmpty) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(nullptr)); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -965,21 +963,22 @@ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_whenDeviceListEmpty) */ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_when_devNodNotFound) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1017,21 +1016,22 @@ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_when_devNodNotFound) */ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_withoutBinfiles) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda2")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda2")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1061,21 +1061,22 @@ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_withoutBinfiles) */ TEST_F(UsbAccessTest, getAvailableFirmwareFilesSuccess_withBinFiles) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1136,21 +1137,21 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_whenSetmntentValueNull) { Core::Event onArchiveLogs(false, true); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, setmntent(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, setmntent(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -1188,21 +1189,21 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_whengetmntentNull) { Core::Event onArchiveLogs(false, true); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { return static_cast(NULL); @@ -1238,21 +1239,21 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_when_devNodNotFound) { Core::Event onArchiveLogs(false, true); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1299,21 +1300,21 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_when_pathParamNotFoundInMountedp { Core::Event onArchiveLogs(false, true); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1360,21 +1361,21 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_when_FileFailedtoOpen) { Core::Event onArchiveLogs(false, true); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1391,7 +1392,7 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_when_FileFailedtoOpen) } })); - EXPECT_CALL(wrapsImplMock, v_secure_popen(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, v_secure_popen(::testing::_, ::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char *direction, const char *command, va_list args) { @@ -1404,7 +1405,7 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_when_FileFailedtoOpen) return nullptr; })); - ON_CALL(wrapsImplMock, v_secure_pclose(::testing::_)) + ON_CALL(*p_wrapsImplMock, v_secure_pclose(::testing::_)) .WillByDefault(::testing::Invoke( [&](FILE* pipe){ return -1; @@ -1440,21 +1441,21 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_when_FileFailedtoTerminate) { Core::Event onArchiveLogs(false, true); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1471,7 +1472,7 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_when_FileFailedtoTerminate) } })); - EXPECT_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) .WillRepeatedly(::testing::Invoke( [&](const char* command, const char* type) { @@ -1479,7 +1480,7 @@ TEST_F(UsbAccessEventTest, onArchiveLogsFailure_when_FileFailedtoTerminate) return __real_popen(command, type); })); - ON_CALL(wrapsImplMock, v_secure_pclose(::testing::_)) + ON_CALL(*p_wrapsImplMock, v_secure_pclose(::testing::_)) .WillByDefault(::testing::Invoke( [&](FILE* pipe){ return -1; @@ -1516,21 +1517,21 @@ TEST_F(UsbAccessEventTest, archiveLogsSuccess_When_pathParamisEmpty) { Core::Event onArchiveLogs(false, true); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1547,7 +1548,7 @@ TEST_F(UsbAccessEventTest, archiveLogsSuccess_When_pathParamisEmpty) } })); - ON_CALL(wrapsImplMock, v_secure_popen(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, v_secure_popen(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char *direction, const char *command, va_list args) -> FILE* { const char* valueToReturn = NULL; @@ -1601,21 +1602,21 @@ TEST_F(UsbAccessEventTest, archiveLogsSuccess_onValidPath) { Core::Event onArchiveLogs(false, true); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1632,7 +1633,7 @@ TEST_F(UsbAccessEventTest, archiveLogsSuccess_onValidPath) } })); - ON_CALL(wrapsImplMock, v_secure_popen(::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, v_secure_popen(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char *direction, const char *command, va_list args) -> FILE* { const char* valueToReturn = NULL; @@ -1713,22 +1714,22 @@ TEST_F(UsbAccessTest, createLinkFailed_when_LinkExistInthePathParam) //To simulate a symbolicLink already exist in the pathParam symlink("/run/media/sda1", "/tmp/usbdrive"); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1763,22 +1764,22 @@ TEST_F(UsbAccessTest, createLinkFailed_withEmptyParam_LinkExistIntheFirstUsbMoun //To simulate symbolicLink already exist in the pathParam symlink("/run/media/sda1", "/tmp/usbdrive"); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1812,22 +1813,23 @@ TEST_F(UsbAccessTest, createLinkFailed_withEmptyParam_LinkExistIntheFirstUsbMoun */ TEST_F(UsbAccessTest, createLinkFailed_with_m_CreatedLinkIds_bLink_NOT_Exists) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1847,21 +1849,21 @@ TEST_F(UsbAccessTest, createLinkFailed_with_m_CreatedLinkIds_bLink_NOT_Exists) EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("createLink"), _T("{}"), response)); std::remove("/tmp/usbdrive"); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1891,22 +1893,23 @@ TEST_F(UsbAccessTest, createLinkFailed_with_m_CreatedLinkIds_bLink_NOT_Exists) */ TEST_F(UsbAccessTest, createLinkSuccess_whenReadLinkFailed_withPathParam) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1940,22 +1943,23 @@ TEST_F(UsbAccessTest, createLinkSuccess_whenReadLinkFailed_withPathParam) */ TEST_F(UsbAccessTest, createLinkSuccess_whenReadLinkFailed_withoutPathParam) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -1989,22 +1993,23 @@ TEST_F(UsbAccessTest, createLinkSuccess_whenReadLinkFailed_withoutPathParam) */ TEST_F(UsbAccessTest, createLinkSuccess_with_m_CreatedLinkIds_bLink_NOT_Exists_CreatedLinkForFor1stUsb) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -2028,21 +2033,21 @@ TEST_F(UsbAccessTest, createLinkSuccess_with_m_CreatedLinkIds_bLink_NOT_Exists_C *and need to loop through the stored m_CreatedLinkIds map to see if it already has the link.*/ std::remove("/tmp/usbdrive"); - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -2097,22 +2102,22 @@ TEST_F(UsbAccessTest, getLinkSuccess_WhenNoSymLink) */ TEST_F(UsbAccessTest, getLinkSuccess_whenSymLinkExist) { - EXPECT_CALL(udevImplMock, udev_enumerate_get_list_entry(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_enumerate_get_list_entry(testing::_)) .WillOnce(testing::Return(reinterpret_cast(0x3))); - EXPECT_CALL(udevImplMock, udev_list_entry_get_name(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_list_entry_get_name(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_parent_with_subsystem_devtype(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(reinterpret_cast(0x5))); - EXPECT_CALL(udevImplMock, udev_device_get_devtype(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devtype(testing::_)) .WillRepeatedly(testing::Return("disk")); - EXPECT_CALL(udevImplMock, udev_device_get_devnode(testing::_)) + EXPECT_CALL(*p_udevImplMock, udev_device_get_devnode(testing::_)) .WillRepeatedly(testing::Return("/dev/sda1")); - EXPECT_CALL(wrapsImplMock, getmntent(testing::_)) + EXPECT_CALL(*p_wrapsImplMock, getmntent(testing::_)) .WillRepeatedly(::testing::Invoke( [&](FILE*) -> struct mntent* { static struct mntent entry1; @@ -2298,4 +2303,4 @@ TEST_F(UsbAccessEventIarmTest, onUSBMountChangedSuccess) handler.Unsubscribe(0, _T("onUSBMountChanged"), _T("org.rdk.System"), message); } -/*Test cases for onUSBMountChanged ends here*/ \ No newline at end of file +/*Test cases for onUSBMountChanged ends here*/ diff --git a/Tests/tests/test_UserPreferences.cpp b/Tests/L1Tests/tests/test_UserPreferences.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_UserPreferences.cpp rename to Tests/L1Tests/tests/test_UserPreferences.cpp diff --git a/Tests/tests/test_UtilsFile.cpp b/Tests/L1Tests/tests/test_UtilsFile.cpp old mode 100644 new mode 100755 similarity index 100% rename from Tests/tests/test_UtilsFile.cpp rename to Tests/L1Tests/tests/test_UtilsFile.cpp diff --git a/Tests/tests/test_Warehouse.cpp b/Tests/L1Tests/tests/test_Warehouse.cpp old mode 100644 new mode 100755 similarity index 92% rename from Tests/tests/test_Warehouse.cpp rename to Tests/L1Tests/tests/test_Warehouse.cpp index 612c5ec56d..cb15005c99 --- a/Tests/tests/test_Warehouse.cpp +++ b/Tests/L1Tests/tests/test_Warehouse.cpp @@ -54,18 +54,26 @@ class WarehouseTest : public ::testing::Test { class WarehouseInitializedTest : public WarehouseTest { protected: - NiceMock iarmBusImplMock; - NiceMock rfcApiImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + RfcApiImplMock *p_rfcApiImplMock = nullptr ; NiceMock wrapsImplMock; + WrapsImplMock *p_wrapsImplMock = nullptr ; + IARM_EventHandler_t whMgrStatusChangeEventsHandler; WarehouseInitializedTest() : WarehouseTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; - RfcApi::getInstance().impl = &rfcApiImplMock; - Wraps::getInstance().impl = &wrapsImplMock; - EXPECT_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_rfcApiImplMock = new NiceMock ; + RfcApi::setImpl(p_rfcApiImplMock); + + p_wrapsImplMock = new NiceMock ; + Wraps::setImpl(p_wrapsImplMock); + + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { @@ -79,9 +87,26 @@ class WarehouseInitializedTest : public WarehouseTest { virtual ~WarehouseInitializedTest() override { plugin->Deinitialize(nullptr); - IarmBus::getInstance().impl = nullptr; - RfcApi::getInstance().impl = nullptr; - Wraps::getInstance().impl = nullptr; + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + + RfcApi::setImpl(nullptr); + if (p_rfcApiImplMock != nullptr) + { + delete p_rfcApiImplMock; + p_rfcApiImplMock = nullptr; + } + + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } } }; @@ -156,7 +181,7 @@ class WarehouseResetDeviceTest : public WarehouseEventTest { TEST_F(WarehouseResetDeviceTest, ColdFactoryResetDevice) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -174,7 +199,7 @@ TEST_F(WarehouseResetDeviceTest, ColdFactoryResetDevice) TEST_F(WarehouseResetDeviceTest, FactoryResetDevice) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -191,7 +216,7 @@ TEST_F(WarehouseResetDeviceTest, FactoryResetDevice) TEST_F(WarehouseResetDeviceTest, UserFactoryResetDevice) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -208,7 +233,7 @@ TEST_F(WarehouseResetDeviceTest, UserFactoryResetDevice) TEST_F(WarehouseResetDeviceTest, WarehouseClearResetDevice) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -226,7 +251,7 @@ TEST_F(WarehouseResetDeviceTest, WarehouseClearResetDevice) TEST_F(WarehouseInitializedTest, WarehouseClearResetDeviceNoResponse) { Core::Event resetCallRxed(false, true); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [&](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -244,7 +269,7 @@ TEST_F(WarehouseInitializedTest, WarehouseClearResetDeviceNoResponse) TEST_F(WarehouseResetDeviceTest, GenericResetDevice) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -262,7 +287,7 @@ TEST_F(WarehouseResetDeviceTest, GenericResetDevice) TEST_F(WarehouseInitializedTest, GenericResetDeviceNoResponse) { Core::Event resetCallRxed(false, true); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [&](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -313,7 +338,7 @@ class WarehouseResetDeviceFailureTest : public WarehouseEventTest { TEST_F(WarehouseResetDeviceFailureTest, UserFactoryResetDeviceFailure) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -334,7 +359,7 @@ TEST_F(WarehouseResetDeviceTest, ColdFactoryResetDevicePwrMgr2RFCEnabled) //Enable Power manager 2 plugin->m_isPwrMgr2RFCEnabled = true; - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(4) .WillOnce(::testing::Invoke( [](const char* command) { @@ -356,7 +381,7 @@ TEST_F(WarehouseResetDeviceTest, FactoryResetDevicePwrMgr2RFCEnabled) //Enable Power manager 2 plugin->m_isPwrMgr2RFCEnabled = true; - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(3) .WillOnce(::testing::Invoke( [](const char* command) { @@ -378,7 +403,7 @@ TEST_F(WarehouseResetDeviceTest, UserFactoryResetDevicePwrMgr2RFCEnabled) //Enable Power manager 2 plugin->m_isPwrMgr2RFCEnabled = true; - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(3) .WillOnce(::testing::Return(Core::ERROR_NONE)) .WillOnce(::testing::Return(Core::ERROR_NONE)) @@ -401,7 +426,7 @@ TEST_F(WarehouseResetDeviceTest, WarehouseClearResetDevicePwrMgr2RFCEnabled) //Enable Power manager 2 plugin->m_isPwrMgr2RFCEnabled = true; - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(4) .WillOnce(::testing::Return(Core::ERROR_NONE)) .WillOnce(::testing::Return(Core::ERROR_NONE)) @@ -426,7 +451,7 @@ TEST_F(WarehouseInitializedTest, WarehouseClearResetDeviceNoResponsePwrMgr2RFCEn //Enable Power manager 2 plugin->m_isPwrMgr2RFCEnabled = true; - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(2) .WillOnce(::testing::Return(Core::ERROR_NONE)) .WillOnce(::testing::Invoke( @@ -449,7 +474,7 @@ TEST_F(WarehouseResetDeviceTest, GenericResetDevicePwrMgr2RFCEnabled) //Enable Power manager 2 plugin->m_isPwrMgr2RFCEnabled = true; - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(4) .WillOnce(::testing::Return(Core::ERROR_NONE)) .WillOnce(::testing::Return(Core::ERROR_NONE)) @@ -474,7 +499,7 @@ TEST_F(WarehouseInitializedTest, GenericResetDeviceNoResponsePwrMgr2RFCEnabled) //Enable Power manager 2 plugin->m_isPwrMgr2RFCEnabled = true; - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(2) .WillOnce(::testing::Return(Core::ERROR_NONE)) .WillOnce(::testing::Invoke( @@ -497,7 +522,7 @@ TEST_F(WarehouseResetDeviceFailureTest, UserFactoryResetDeviceFailurePwrMgr2RFCE //Enable Power manager 2 plugin->m_isPwrMgr2RFCEnabled = true; - EXPECT_CALL(wrapsImplMock, system(::testing::_)) + EXPECT_CALL(*p_wrapsImplMock, system(::testing::_)) .Times(2) .WillOnce(::testing::Return(Core::ERROR_NONE)) .WillOnce(::testing::Invoke( @@ -525,7 +550,7 @@ TEST_F(WarehouseInitializedTest, internalResetFailPassPhrase) TEST_F(WarehouseInitializedTest, internalResetScriptFail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -545,7 +570,7 @@ TEST_F(WarehouseInitializedTest, internalResetScriptFail) TEST_F(WarehouseInitializedTest, internalReset) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -566,7 +591,7 @@ TEST_F(WarehouseInitializedTest, internalReset) TEST_F(WarehouseInitializedTest, lightResetScriptFail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -586,7 +611,7 @@ TEST_F(WarehouseInitializedTest, lightResetScriptFail) TEST_F(WarehouseInitializedTest, lightReset) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(1) .WillOnce( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -642,7 +667,7 @@ TEST_F(WarehouseInitializedTest, isClean) TEST_F(WarehouseInitializedTest, executeHardwareTest) { - EXPECT_CALL(rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(2) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { @@ -668,7 +693,7 @@ TEST_F(WarehouseInitializedTest, executeHardwareTest) TEST_F(WarehouseInitializedTest, getHardwareTestResults) { - EXPECT_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { @@ -677,7 +702,7 @@ TEST_F(WarehouseInitializedTest, getHardwareTestResults) strncpy(pstParamData->value, "test", sizeof(pstParamData->value)); return WDMP_SUCCESS; })); - EXPECT_CALL(rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + EXPECT_CALL(*p_rfcApiImplMock, setRFCParameter(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(1) .WillOnce(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { @@ -708,13 +733,13 @@ TEST_F(WarehouseInitializedTest, getDeviceInfo) "model_number=ABC123ADS\n" "wifi_mac=12:34:56:78:90:AB\"\n"; - ON_CALL(wrapsImplMock, popen(::testing::_, ::testing::_)) + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* command, const char* type) -> FILE* { EXPECT_EQ(string(command), string(_T("sh /lib/rdk/getDeviceDetails.sh read"))); return __real_popen(command, type); })); - ON_CALL(wrapsImplMock, pclose(::testing::_)) + ON_CALL(*p_wrapsImplMock, pclose(::testing::_)) .WillByDefault(::testing::Invoke( [&](FILE* pipe){ return __real_pclose(pipe); diff --git a/Tests/tests/test_WifiManager.cpp b/Tests/L1Tests/tests/test_WifiManager.cpp old mode 100644 new mode 100755 similarity index 92% rename from Tests/tests/test_WifiManager.cpp rename to Tests/L1Tests/tests/test_WifiManager.cpp index f0b3dd9023..99b8e54616 --- a/Tests/tests/test_WifiManager.cpp +++ b/Tests/L1Tests/tests/test_WifiManager.cpp @@ -19,8 +19,9 @@ class WifiManagerTest : public ::testing::Test { Core::JSONRPC::Connection connection; string response; Core::JSONRPC::Message message; - WrapsImplMock wrapsImplMock; + WrapsImplMock *p_wrapsImplMock = nullptr ; NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; ServiceMock services; WifiManagerTest() @@ -28,13 +29,27 @@ class WifiManagerTest : public ::testing::Test { , handler(*(plugin)) , connection(1, 0) { - Wraps::getInstance().impl = &wrapsImplMock; - IarmBus::getInstance().impl = &iarmBusImplMock; + p_wrapsImplMock = new NiceMock ; + Wraps::setImpl(p_wrapsImplMock); + + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); } virtual ~WifiManagerTest() override { - Wraps::getInstance().impl = nullptr; - IarmBus::getInstance().impl = nullptr; + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } } }; @@ -88,7 +103,7 @@ TEST_F(WifiManagerTest, TestedAPIsShouldExist) TEST_F(WifiManagerTest, setEnabled) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -104,7 +119,7 @@ TEST_F(WifiManagerTest, setEnabled) TEST_F(WifiManagerTest, getCurrentState) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -121,7 +136,7 @@ TEST_F(WifiManagerTest, getCurrentState) TEST_F(WifiManagerTest, getPairedSSID) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -138,7 +153,7 @@ TEST_F(WifiManagerTest, getPairedSSID) TEST_F(WifiManagerTest, getPairedSSIDi_cache) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -157,7 +172,7 @@ TEST_F(WifiManagerTest, getPairedSSIDi_cache) TEST_F(WifiManagerTest, getPairedSSID_failed) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -173,7 +188,7 @@ TEST_F(WifiManagerTest, getPairedSSID_failed) TEST_F(WifiManagerTest, getPairedSSIDInfo) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -193,7 +208,7 @@ TEST_F(WifiManagerTest, getPairedSSIDInfo) TEST_F(WifiManagerTest, getPairedSSIDInfo_cache) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -217,7 +232,7 @@ TEST_F(WifiManagerTest, getPairedSSIDInfo_cache) TEST_F(WifiManagerTest, getPairedSSIDInfo_fail) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -235,7 +250,7 @@ TEST_F(WifiManagerTest, getPairedSSIDInfo_fail) TEST_F(WifiManagerTest, getConnectedSSID) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -263,7 +278,7 @@ TEST_F(WifiManagerTest, getConnectedSSID) TEST_F(WifiManagerTest, connect) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -282,7 +297,7 @@ TEST_F(WifiManagerTest, connect) TEST_F(WifiManagerTest, disconnect) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -298,7 +313,7 @@ TEST_F(WifiManagerTest, disconnect) TEST_F(WifiManagerTest, saveSSID) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -317,7 +332,7 @@ TEST_F(WifiManagerTest, saveSSID) TEST_F(WifiManagerTest, clearSSID) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -333,7 +348,7 @@ TEST_F(WifiManagerTest, clearSSID) TEST_F(WifiManagerTest, isPaired) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -350,7 +365,7 @@ TEST_F(WifiManagerTest, isPaired) TEST_F(WifiManagerTest, isPaired_cache) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -369,7 +384,7 @@ TEST_F(WifiManagerTest, isPaired_cache) TEST_F(WifiManagerTest, startScan) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -381,7 +396,7 @@ TEST_F(WifiManagerTest, startScan) EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startScan"), _T("{\"incremental\": false,\"ssid\": \"...\",\"frequency\": \"...\"}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -396,7 +411,7 @@ TEST_F(WifiManagerTest, startScan) TEST_F(WifiManagerTest, stopScan) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -411,7 +426,7 @@ TEST_F(WifiManagerTest, stopScan) TEST_F(WifiManagerTest, cancelWPSPairing) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -426,7 +441,7 @@ TEST_F(WifiManagerTest, cancelWPSPairing) TEST_F(WifiManagerTest, initiateWPSPairing) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { @@ -441,7 +456,7 @@ TEST_F(WifiManagerTest, initiateWPSPairing) TEST_F(WifiManagerTest, initiateWPSPairing2) { - EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { diff --git a/Tests/tests/test_XCast.cpp b/Tests/L1Tests/tests/test_XCast.cpp old mode 100644 new mode 100755 similarity index 84% rename from Tests/tests/test_XCast.cpp rename to Tests/L1Tests/tests/test_XCast.cpp index 1e6031a241..1fb8888e9e --- a/Tests/tests/test_XCast.cpp +++ b/Tests/L1Tests/tests/test_XCast.cpp @@ -36,7 +36,7 @@ #include "ServiceMock.h" #include "DispatcherMock.h" -//Required, xdialCastObj cannot be moved into the .h, as we don't +//Required, xdialCastObj cannot be moved into the .h, as we don't //want header includes to have access to the object #include "RtXcastConnector.cpp" @@ -47,12 +47,14 @@ using ::testing::Eq; class XCastPreLoad : public ::testing::Test { protected: - NiceMock rfcApiImplMock; + RfcApiImplMock *p_rfcApiImplMock = nullptr ; - XCastPreLoad() + XCastPreLoad() { - RfcApi::getInstance().impl = &rfcApiImplMock; - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + p_rfcApiImplMock = new NiceMock ; + RfcApi::setImpl(p_rfcApiImplMock); + + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { EXPECT_EQ(string(pcCallerID), string("Xcast")); @@ -63,6 +65,16 @@ class XCastPreLoad : public ::testing::Test { })); } + virtual ~XCastPreLoad() override + { + RfcApi::setImpl(nullptr); + if (p_rfcApiImplMock != nullptr) + { + delete p_rfcApiImplMock; + p_rfcApiImplMock = nullptr; + } + } + }; class XCastTest : public XCastPreLoad { @@ -78,7 +90,7 @@ class XCastTest : public XCastPreLoad { , handler(*(plugin)) , connection(1, 0) { - + } virtual ~XCastTest() = default; @@ -86,43 +98,56 @@ class XCastTest : public XCastPreLoad { class XCastDsTest : public XCastTest { protected: - NiceMock rtBaseMock; + rtObjectBaseMock *p_rtBaseMock = nullptr ; XCastDsTest() : XCastTest() { - rtObjectBase::getInstance().impl = &rtBaseMock; + rtObjectBase::setImpl(p_rtBaseMock); } virtual ~XCastDsTest() override { - rtObjectBase::getInstance().impl = nullptr; + rtObjectBase::setImpl(nullptr); + if (p_rtBaseMock != nullptr) + { + delete p_rtBaseMock; + p_rtBaseMock = nullptr; + } } }; class XCastInitializedTest : public XCastTest { protected: - NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; IARM_EventHandler_t dsHdmiEventHandler; IARM_EventHandler_t dsHdmiStatusEventHandler; IARM_EventHandler_t dsHdmiSignalStatusEventHandler; IARM_EventHandler_t dsHdmiVideoModeEventHandler; IARM_EventHandler_t dsHdmiGameFeatureStatusEventHandler; - NiceMock rtFloatingMock; - NiceMock rtBaseMock; - NiceMock rtRefMock; - NiceMock rtArrayMock; + floatingRtFunctionsMock *p_rtFloatingMock = nullptr ; + rtObjectBaseMock *p_rtBaseMock = nullptr ; + rtObjectRefMock *p_rtRefMock = nullptr ; + rtArrayObjectMock *p_rtArrayMock = nullptr ; NiceMock service; XCastInitializedTest() : XCastTest() { - IarmBus::getInstance().impl = &iarmBusImplMock; - rtObjectBase::getInstance().impl = &rtBaseMock; - rtObjectRef::getInstance().impl = &rtRefMock; - floatingRtFunctions::getInstance().impl = &rtFloatingMock; - RfcApi::getInstance().impl = &rfcApiImplMock; - rtArrayObject::getInstance().impl = &rtArrayMock; + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + p_rtBaseMock = new NiceMock ; + rtObjectBase::setImpl(p_rtBaseMock); + + p_rtRefMock = new NiceMock ; + rtObjectRef::setImpl(p_rtRefMock); + + p_rtFloatingMock = new NiceMock ; + floatingRtFunctions::setImpl(p_rtFloatingMock); + + p_rtArrayMock = new NiceMock ; + rtArrayObject::setImpl(p_rtArrayMock); EXPECT_CALL(service, QueryInterfaceByCallsign(::testing::_, ::testing::_)) .Times(::testing::AnyNumber()) @@ -130,16 +155,16 @@ class XCastInitializedTest : public XCastTest { [&](const uint32_t, const string& name) -> void* { return nullptr; })); - - ON_CALL(rtFloatingMock, rtRemoteLocateObject(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + + ON_CALL(*p_rtFloatingMock, rtRemoteLocateObject(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](rtRemoteEnvironment *env, const char* str, rtObjectRef& obj, int x, remoteDisconnectCallback back, void *cbdata=NULL) { rtIObject rtIObj; obj = &rtIObj; return RT_OK; - })); - - ON_CALL(rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + })); + + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { EXPECT_EQ(string(pcCallerID), string("Xcast")); @@ -148,9 +173,9 @@ class XCastInitializedTest : public XCastTest { pstParamData->type = WDMP_BOOLEAN; return WDMP_SUCCESS; })); - - ON_CALL(iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { /*if ((string(IARM_BUS_PWRMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_PWRMGR_API_GetPowerState)) { @@ -159,7 +184,7 @@ class XCastInitializedTest : public XCastTest { }*/ return IARM_RESULT_SUCCESS; })); - ON_CALL(iarmBusImplMock, IARM_Bus_Call(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call(::testing::_, ::testing::_, ::testing::_, ::testing::_)) .WillByDefault( [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { auto* param = static_cast(arg); @@ -168,7 +193,7 @@ class XCastInitializedTest : public XCastTest { }); - ON_CALL(rtRefMock, send(::testing::_, ::testing::_,::testing::_)) + ON_CALL(*p_rtRefMock, send(::testing::_, ::testing::_,::testing::_)) .WillByDefault( [](const char* messageName, const char* method, rtFunctionCallback* callback) { delete callback; @@ -181,9 +206,9 @@ class XCastInitializedTest : public XCastTest { //Wait until threads populate xdialCastObj. int iCounter = 0; while ((xdialCastObj == NULL) && (iCounter < (5*10))) { //sleep for 2sec. - usleep (100 * 1000); //sleep for 100 milli sec - iCounter ++; - } + usleep (100 * 1000); //sleep for 100 milli sec + iCounter ++; + } //required to enable some backend processes for certain functions. EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enabled\": true}"), response)); @@ -192,12 +217,41 @@ class XCastInitializedTest : public XCastTest { virtual ~XCastInitializedTest() override { plugin->Deinitialize(&service); - RfcApi::getInstance().impl = nullptr; - floatingRtFunctions::getInstance().impl = nullptr; - rtObjectBase::getInstance().impl = nullptr; - IarmBus::getInstance().impl = nullptr; - rtObjectRef::getInstance().impl = nullptr; - rtArrayObject::getInstance().impl = nullptr; + + floatingRtFunctions::setImpl(nullptr); + if (p_rtFloatingMock != nullptr) + { + delete p_rtFloatingMock; + p_rtFloatingMock = nullptr; + } + + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + + rtObjectBase::setImpl(nullptr); + if (p_rtBaseMock != nullptr) + { + delete p_rtBaseMock; + p_rtBaseMock = nullptr; + } + + rtObjectRef::setImpl(nullptr); + if (p_rtRefMock != nullptr) + { + delete p_rtRefMock; + p_rtRefMock = nullptr; + } + + rtArrayObject::setImpl(nullptr); + if (p_rtArrayMock != nullptr) + { + delete p_rtArrayMock; + p_rtArrayMock = nullptr; + } } }; @@ -215,7 +269,7 @@ class XCastInitializedEventTest : public XCastInitializedTest { PluginHost::IFactories::Assign(&factoriesImplementation); dispatcher = static_cast( - plugin->QueryInterface(PluginHost::IDispatcher::ID)); + plugin->QueryInterface(PluginHost::IDispatcher::ID)); dispatcher->Activate(&service); } @@ -277,7 +331,7 @@ TEST_F(XCastDsTest, getsetStandbyBehavoir) TEST_F(XCastInitializedTest, onApplicationStateChanged) { - EXPECT_CALL(rtBaseMock, set(::testing::_, ::testing::Matcher(::testing::_))) + EXPECT_CALL(*p_rtBaseMock, set(::testing::_, ::testing::Matcher(::testing::_))) .WillOnce(::testing::Invoke( [](const char* name, const char* value) { std::string cnv = value; @@ -305,8 +359,8 @@ TEST_F(XCastInitializedTest, onApplicationStateChanged) .WillRepeatedly(::testing::Invoke( [](const char* name, const char* value) { return RT_OK; - })); - ON_CALL(rtRefMock, send(::testing::_, ::testing::Matcher(::testing::_))) + })); + ON_CALL(*p_rtRefMock, send(::testing::_, ::testing::Matcher(::testing::_))) .WillByDefault(::testing::Invoke( [](const char* messageName, rtObjectRef& ref) { delete ref.mRef; @@ -314,12 +368,12 @@ TEST_F(XCastInitializedTest, onApplicationStateChanged) })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("onApplicationStateChanged"), _T("{\"applicationName\": \"NetflixApp\", \"state\":\"running\", \"applicationId\": \"1234\", \"error\": \"\"}"), response)); EXPECT_EQ(response, string("{\"success\":true}")); - + } TEST_F(XCastInitializedTest, getProtocolVersionInitialized) { - ON_CALL(rtBaseMock, sendReturns(::testing::_, ::testing::_)) + ON_CALL(*p_rtBaseMock, sendReturns(::testing::_, ::testing::_)) .WillByDefault(::testing::Invoke( [&](const char* messageName, rtString& result) { @@ -327,7 +381,7 @@ TEST_F(XCastInitializedTest, getProtocolVersionInitialized) result = tmp.c_str(); return RT_OK; - })); + })); EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getProtocolVersion"), _T("{}"), response)); EXPECT_EQ(response, string("{\"version\":\"test\",\"success\":true}")); } @@ -341,7 +395,7 @@ TEST_F(XCastInitializedTest, unregisterApplications) TEST_F(XCastInitializedTest, unRegisterAllApplications) { - EXPECT_CALL(rtArrayMock, pushBack(::testing::Matcher(::testing::_))) + EXPECT_CALL(*p_rtArrayMock, pushBack(::testing::Matcher(::testing::_))) .WillOnce(::testing::Invoke( [](const char* value) { std::string strValue = value; @@ -389,7 +443,7 @@ TEST_F(XCastInitializedTest, unRegisterAllApplications) EXPECT_EQ("netflix.com", strValue); })); //Last three are the ones remaining afte youtube has been unregistered. - EXPECT_CALL(rtBaseMock, set(::testing::_, ::testing::Matcher(::testing::_))) + EXPECT_CALL(*p_rtBaseMock, set(::testing::_, ::testing::Matcher(::testing::_))) .WillOnce(::testing::Invoke( [](const char* name, bool value) { bool testBool = true; @@ -424,7 +478,7 @@ TEST_F(XCastInitializedTest, unRegisterAllApplications) TEST_F(XCastInitializedTest, registerApplications) { - EXPECT_CALL(rtArrayMock, pushBack(::testing::Matcher(::testing::_))) + EXPECT_CALL(*p_rtArrayMock, pushBack(::testing::Matcher(::testing::_))) .WillOnce(::testing::Invoke( [](const char* value) { std::string strValue = value; @@ -456,7 +510,7 @@ TEST_F(XCastInitializedTest, registerApplications) EXPECT_EQ("netflix.com", strValue); })); //Last three are the ones remaining afte youtube has been unregistered. - EXPECT_CALL(rtBaseMock, set(::testing::_, ::testing::Matcher(::testing::_))) + EXPECT_CALL(*p_rtBaseMock, set(::testing::_, ::testing::Matcher(::testing::_))) .WillOnce(::testing::Invoke( [](const char* name, bool value) { bool testBool = true; @@ -491,10 +545,10 @@ TEST_F(XCastInitializedEventTest, onApplicationHideRequest) EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onApplicationHideRequest\",\"params\":{\"applicationName\":\"NetflixApp\",\"applicationId\":\"1234\"}}"))); return Core::ERROR_NONE; })); - + handler.Subscribe(0, _T("onApplicationHideRequest"), _T("client.events"), message); plugin->onXcastApplicationHideRequest("Netflix", "1234"); - handler.Unsubscribe(0, _T("onApplicationHideRequest"), _T("client.events"), message); + handler.Unsubscribe(0, _T("onApplicationHideRequest"), _T("client.events"), message); } TEST_F(XCastInitializedEventTest, onApplicationStateRequest) { @@ -507,10 +561,10 @@ TEST_F(XCastInitializedEventTest, onApplicationStateRequest) EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onApplicationStateRequest\",\"params\":{\"applicationName\":\"NetflixApp\",\"applicationId\":\"1234\"}}"))); return Core::ERROR_NONE; })); - + handler.Subscribe(0, _T("onApplicationStateRequest"), _T("client.events"), message); plugin->onXcastApplicationStateRequest("Netflix", "1234"); - handler.Unsubscribe(0, _T("onApplicationStateRequest"), _T("client.events"), message); + handler.Unsubscribe(0, _T("onApplicationStateRequest"), _T("client.events"), message); } TEST_F(XCastInitializedEventTest, onApplicationLaunchRequest) { @@ -523,10 +577,10 @@ TEST_F(XCastInitializedEventTest, onApplicationLaunchRequest) EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onApplicationLaunchRequest\",\"params\":{\"applicationName\":\"Netflix\",\"parameters\":{\"url\":\"1234\"}}}"))); return Core::ERROR_NONE; })); - + handler.Subscribe(0, _T("onApplicationLaunchRequest"), _T("client.events"), message); plugin->onXcastApplicationLaunchRequest("Netflix", "1234"); - handler.Unsubscribe(0, _T("onApplicationLaunchRequest"), _T("client.events"), message); + handler.Unsubscribe(0, _T("onApplicationLaunchRequest"), _T("client.events"), message); } TEST_F(XCastInitializedEventTest, onApplicationResumeRequest) { @@ -539,10 +593,10 @@ TEST_F(XCastInitializedEventTest, onApplicationResumeRequest) EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onApplicationResumeRequest\",\"params\":{\"applicationName\":\"NetflixApp\",\"applicationId\":\"1234\"}}"))); return Core::ERROR_NONE; })); - + handler.Subscribe(0, _T("onApplicationResumeRequest"), _T("client.events"), message); plugin->onXcastApplicationResumeRequest("Netflix", "1234"); - handler.Unsubscribe(0, _T("onApplicationResumeRequest"), _T("client.events"), message); + handler.Unsubscribe(0, _T("onApplicationResumeRequest"), _T("client.events"), message); } TEST_F(XCastInitializedEventTest, onApplicationStopRequest) { @@ -555,8 +609,8 @@ TEST_F(XCastInitializedEventTest, onApplicationStopRequest) EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"client.events.onApplicationStopRequest\",\"params\":{\"applicationName\":\"Netflix\",\"applicationId\":\"1234\"}}"))); return Core::ERROR_NONE; })); - + handler.Subscribe(0, _T("onApplicationStopRequest"), _T("client.events"), message); plugin->onXcastApplicationStopRequest("Netflix", "1234"); - handler.Unsubscribe(0, _T("onApplicationStopRequest"), _T("client.events"), message); + handler.Unsubscribe(0, _T("onApplicationStopRequest"), _T("client.events"), message); } diff --git a/Tests/L2Tests/CMakeLists.txt b/Tests/L2Tests/CMakeLists.txt new file mode 100755 index 0000000000..7ae983eaaa --- /dev/null +++ b/Tests/L2Tests/CMakeLists.txt @@ -0,0 +1,66 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.8) +project(RdkServicesL2Test) + +set(CMAKE_CXX_STANDARD 11) +set(THUNDER_PORT 9998) +set(TEST_COMPLETION_TIMEOUT 600000) +find_package(${NAMESPACE}Plugins REQUIRED) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip +) +FetchContent_MakeAvailable(googletest) + +add_executable(${PROJECT_NAME} + L2testController.cpp + L2testController.h + Module.cpp + ) + +set_source_files_properties( + L2testController.cpp + L2testController.h + Module.cpp + PROPERTIES COMPILE_FLAGS "-fexceptions") + +target_link_libraries(${PROJECT_NAME} + gmock_main + ${CMAKE_INSTALL_PREFIX}/lib/libWPEFrameworkCore.so + ${CMAKE_INSTALL_PREFIX}/lib/libWPEFrameworkProtocols.so + ${CMAKE_INSTALL_PREFIX}/lib/libWPEFrameworkTracing.so + ${CMAKE_INSTALL_PREFIX}/lib/libTestMocklib.so + ) + +target_compile_definitions(${PROJECT_NAME} + PRIVATE + CMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" + THUNDER_PORT="${THUNDER_PORT}" + TEST_COMPLETION_TIMEOUT=${TEST_COMPLETION_TIMEOUT} + ) + +target_include_directories(${PROJECT_NAME} + PRIVATE + $ + ${CMAKE_INSTALL_PREFIX}/include/WPEFramework + ) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/Tests/L2Tests/L2TestsPlugin/CHANGELOG.md b/Tests/L2Tests/L2TestsPlugin/CHANGELOG.md new file mode 100755 index 0000000000..36fdbf265d --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/CHANGELOG.md @@ -0,0 +1,19 @@ +All notable changes to this RDK Service will be documented in this file. + + Each RDK Service has a CHANGELOG file that contains all changes done so far. When version is updated, add a entry in the CHANGELOG.md at the top with user friendly information on what was changed with the new version. Please don't mention JIRA tickets in CHANGELOG. + + Please Add entry in the CHANGELOG for each version change and indicate the type of change with these labels: + Added for new features. + Changed for changes in existing functionality. + Deprecated for soon-to-be removed features. + Removed for now removed features. + Fixed for any bug fixes. + Security in case of vulnerabilities. + + Changes in CHANGELOG should be updated when commits are added to the main or release branches. There should be one CHANGELOG entry per JIRA Ticket. This is not enforced on sprint branches since there could be multiple changes for the same JIRA ticket during development. + + For more details, refer to versioning section under Main README. + +## [1.0.0] - 2023-10-03 +### Added +- New RDK Service L2tests to run L2framework tests for RDK services diff --git a/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt b/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt new file mode 100755 index 0000000000..4b38d073e7 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt @@ -0,0 +1,61 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +set(PLUGIN_NAME L2Tests) +set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) +set(THUNDER_PORT 9998) +find_package(${NAMESPACE}Plugins REQUIRED) + +add_library(${MODULE_NAME} SHARED + Module.cpp + L2Tests.cpp + L2TestsMock.cpp + tests/SystemService_L2Test.cpp + tests/UsbAccess_L2Test.cpp) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + +target_compile_definitions(${MODULE_NAME} + PRIVATE + MODULE_NAME=Plugin_${PLUGIN_NAME} + THUNDER_PORT="${THUNDER_PORT}") + +target_compile_options(${MODULE_NAME} PRIVATE -Wno-error) +target_link_libraries(${MODULE_NAME} PRIVATE gmock_main ${NAMESPACE}Plugins::${NAMESPACE}Plugins) + +find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib) +if (TESTMOCKLIB_LIBRARIES) + message ("Found mock library - ${TESTMOCKLIB_LIBRARIES}") + target_link_libraries(${MODULE_NAME} PRIVATE ${TESTMOCKLIB_LIBRARIES}) +else (TESTMOCKLIB_LIBRARIES) + message ("Require ${TESTMOCKLIB_LIBRARIES} library") +endif (TESTMOCKLIB_LIBRARIES) + +target_include_directories(${MODULE_NAME} PRIVATE ../../../helpers) +target_include_directories(${MODULE_NAME} PRIVATE ./) +target_include_directories(${MODULE_NAME} PRIVATE ../../mocks) + +install(TARGETS ${MODULE_NAME} + DESTINATION lib/${STORAGE_DIRECTORY}/plugins) + +write_config(${PLUGIN_NAME}) + + + diff --git a/Tests/L2Tests/L2TestsPlugin/L2Tests.config b/Tests/L2Tests/L2TestsPlugin/L2Tests.config new file mode 100755 index 0000000000..dcf5d7ff64 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/L2Tests.config @@ -0,0 +1,2 @@ +set(autostart true) +set (callsign "org.rdk.L2Tests") diff --git a/Tests/L2Tests/L2TestsPlugin/L2Tests.cpp b/Tests/L2Tests/L2TestsPlugin/L2Tests.cpp new file mode 100755 index 0000000000..077397ea7c --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/L2Tests.cpp @@ -0,0 +1,96 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#include +#include + +#include "Module.h" +#include "L2Tests.h" +#include "UtilsJsonRpc.h" + +#define API_VERSION_NUMBER_MAJOR 1 +#define API_VERSION_NUMBER_MINOR 0 +#define API_VERSION_NUMBER_PATCH 0 + +using namespace WPEFramework; + +// TODO: remove this +#define registerMethod(...) for (uint8_t i = 1; GetHandler(i); i++) GetHandler(i)->Register(__VA_ARGS__) +namespace WPEFramework +{ + namespace { + + static Plugin::Metadata metadata( + // Version (Major, Minor, Patch) + API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH, + // Preconditions + {}, + // Terminations + {}, + // Controls + {} + ); + } + + namespace Plugin + { + SERVICE_REGISTRATION(L2Tests, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); + + L2Tests::L2Tests() + : PluginHost::JSONRPC() + { + + Register("PerformL2Tests", &L2Tests::PerformL2Tests, this); + ::testing::InitGoogleTest(); + } + + L2Tests::~L2Tests() + { + LOGINFO("L2 test plugin is terminating\n"); + } + + const string L2Tests::Initialize(PluginHost::IShell* /* service */) + { + return (string()); + } + + void L2Tests::Deinitialize(PluginHost::IShell* /* service */) + { + + } + + uint32_t L2Tests::PerformL2Tests(const JsonObject& parameters, JsonObject& response) + { + uint32_t status; + + /* Options are passed in params if user wants to set gtest filter to run specific suite */ + if(parameters.HasLabel("test_suite_list")) + { + const std::string &message = parameters["test_suite_list"].String(); + LOGINFO("Paramaters passed for gtest filter: :%s\n", + message.c_str()); + ::testing::GTEST_FLAG(filter) = message; + } + status = RUN_ALL_TESTS(); + LOGINFO("Completed running L2 tests and running status = %d\n",status); + + return status; + } + } +} + diff --git a/Tests/L2Tests/L2TestsPlugin/L2Tests.h b/Tests/L2Tests/L2TestsPlugin/L2Tests.h new file mode 100755 index 0000000000..617eac012a --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/L2Tests.h @@ -0,0 +1,52 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#pragma once + +#include "Module.h" +#include + +#include + +namespace WPEFramework { +namespace Plugin { + class L2Tests : public PluginHost::IPlugin, public PluginHost::JSONRPC { + + public: + BEGIN_INTERFACE_MAP(L2Tests) + INTERFACE_ENTRY(PluginHost::IPlugin) + INTERFACE_ENTRY(PluginHost::IDispatcher) + END_INTERFACE_MAP + L2Tests(); + ~L2Tests() override; + + // IPlugin methods + virtual const string Initialize(PluginHost::IShell* service) override; + virtual void Deinitialize(PluginHost::IShell* service) override; + virtual string Information() const override { return {}; } + + + private: + + L2Tests(const L2Tests&) = delete; + L2Tests& operator=(const L2Tests&) = delete; + // JsonRpc methods + uint32_t PerformL2Tests(const JsonObject& parameters, JsonObject& response); + }; + } //namespace Plugin +} //namespace WPEFramework diff --git a/Tests/L2Tests/L2TestsPlugin/L2Tests.json b/Tests/L2Tests/L2TestsPlugin/L2Tests.json new file mode 100755 index 0000000000..6a480bcf45 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/L2Tests.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://raw.githubusercontent.com/rdkcentral/rdkservices/main/Tools/json_generator/schemas/interface.schema.json", + "jsonrpc": "2.0", + "info": { + "title": "L2Tests API", + "class": "L2Tests", + "description": "The L2Tests plugin provides an interface to start L2 tests." + }, + "common": { + "$ref": "../common/common.json" + }, + "methods": { + "PerformL2Tests": { + "summary": "Start L2 google tests for all RDKServices", + "params": { + "type": "object", + "properties":{ + "test_suite_list": { + "summary": "RDK service name", + "type": "string", + "example": "System" + } + } + }, + "result":{ + "type":"object", + "properties": { + "Success": { + "summary": "Value zero for no error", + "type": "integer", + "example": "0" + } + } + } + } + } +} diff --git a/Tests/L2Tests/L2TestsPlugin/L2TestsAPI.md b/Tests/L2Tests/L2TestsPlugin/L2TestsAPI.md new file mode 100755 index 0000000000..91c98668e8 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/L2TestsAPI.md @@ -0,0 +1,99 @@ + + +# L2Tests API + +**Version: [1.0.0](https://github.com/rdkcentral/rdkservices/blob/main/L2Tests/CHANGELOG.md)** + +A L2Tests plugin for Thunder framework. + +### Table of Contents + +- [Abbreviation, Acronyms and Terms](#head.Abbreviation,_Acronyms_and_Terms) +- [Description](#head.Description) +- [Configuration](#head.Configuration) +- [Methods](#head.Methods) + + +# Abbreviation, Acronyms and Terms + +[[Refer to this link](userguide/aat.md)] + + +# Description + +The L2Tests plugin provides an interface to start L2 tests. + +The plugin is designed to be loaded and executed within the Thunder framework. For more information about the framework refer to [[Thunder](#ref.Thunder)]. + + +# Configuration + +The table below lists configuration options of the plugin. + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| classname | string | Class name: *L2Tests* | +| autostart | boolean | Determines if the plugin shall be started automatically along with the framework | + + +# Methods + +The following methods are provided by the L2Tests plugin: + +L2Tests interface methods: + +| Method | Description | +| :-------- | :-------- | +| [PerformL2Tests](#method.PerformL2Tests) | Start L2 google tests for all RDKServices | + + + +## *PerformL2Tests [method](#head.Methods)* + +Start L2 google tests for all RDKServices. + +### Events + +No Events + +### Parameters + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| params | object | | +| params.test_suite_list | string | RDK service name | + +### Result + +| Name | Type | Description | +| :-------- | :-------- | :-------- | +| result | object | | +| result.Success | integer | Value zero for no error | + +### Example + +#### Request + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "method": "L2Tests.PerformL2Tests", + "params": { + "test_suite_list": "System" + } +} +``` + +#### Response + +```json +{ + "jsonrpc": "2.0", + "id": 42, + "result": { + "Success": 0 + } +} +``` + diff --git a/Tests/L2Tests/L2TestsPlugin/L2TestsMock.cpp b/Tests/L2Tests/L2TestsPlugin/L2TestsMock.cpp new file mode 100755 index 0000000000..d349823447 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/L2TestsMock.cpp @@ -0,0 +1,136 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#include +#include + +#include "L2TestsMock.h" + + +#define TEST_CALLSIGN _T("org.rdk.L2Tests.1") /* Test module callsign. */ +#define INVOKE_TIMEOUT 1000 /* Method invoke timeout in milliseconds. */ +#define THUNDER_ADDRESS _T("127.0.0.1:") +#define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); + +#ifndef THUNDER_PORT +#define THUNDER_PORT "9998" +#endif + +using namespace WPEFramework; + +/* L2TestMock consturctor */ +L2TestMocks::L2TestMocks() +{ + p_rfcApiImplMock = new NiceMock ; + p_iarmBusImplMock = new NiceMock ; + + IarmBus::setImpl(p_iarmBusImplMock); + RfcApi::setImpl(p_rfcApiImplMock); + + thunder_address = THUNDER_ADDRESS + std::string(THUNDER_PORT); + (void)Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), thunder_address); +} + +/* L2TestMock Destructor */ +L2TestMocks::~L2TestMocks() +{ + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + RfcApi::setImpl(nullptr); + if (p_rfcApiImplMock != nullptr) + { + delete p_rfcApiImplMock; + p_rfcApiImplMock = nullptr; + } +} + +/** + * @brief Invoke a service method + * + * @param[in] callsign Service callsign + * @param[in] method Method name + * @param[in] params Method parameters + * @param[out] results Method results + * @return Zero (Core::ERROR_NONE) on succes or another value on error + */ +uint32_t L2TestMocks::InvokeServiceMethod(const char *callsign, const char *method, JsonObject ¶ms, JsonObject &results) +{ + + JSONRPC::LinkType jsonrpc(std::string(callsign), TEST_CALLSIGN); + std::string message; + std::string reply; + uint32_t status = Core::ERROR_NONE; + + params.ToString(message); + TEST_LOG("Invoking %s.%s, parameters %s\n", callsign, method, message.c_str()); + + results = JsonObject(); + status = jsonrpc.Invoke(INVOKE_TIMEOUT, std::string(method), params, results); + + results.ToString(reply); + TEST_LOG("Status %u, results %s", status, reply.c_str()); + + return status; +} + +/** +* @brief Activate a service plugin +* +* @param[in] callsign Service callsign +* @return Zero (Core::ERROR_NONE) on succes or another value on error +*/ +uint32_t L2TestMocks::ActivateService(const char *callsign) +{ + JsonObject params; + JsonObject result; + uint32_t status = Core::ERROR_GENERAL; + + if(callsign != NULL) + { + params["callsign"] = callsign; + status = InvokeServiceMethod("Controller.1", "activate", params, result); + } + + return status; +} + +/** +* @brief Deactivate a service plugin +* +* @param[in] callsign Service callsign +* @return Zero (Core::ERROR_NONE) on succes or another value on error +*/ +uint32_t L2TestMocks::DeactivateService(const char *callsign) +{ + JsonObject params; + JsonObject result; + uint32_t status = Core::ERROR_GENERAL; + + if(callsign != NULL) + { + params["callsign"] = callsign; + status = InvokeServiceMethod("Controller.1", "deactivate", params, result); + } + return status; +} + + diff --git a/Tests/L2Tests/L2TestsPlugin/L2TestsMock.h b/Tests/L2Tests/L2TestsPlugin/L2TestsMock.h new file mode 100755 index 0000000000..24650bad52 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/L2TestsMock.h @@ -0,0 +1,71 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#pragma once + +#include + +#include +#include +#include "UtilsJsonRpc.h" + +#include "IarmBusMock.h" +#include "RfcApiMock.h" + +using ::testing::NiceMock; +using namespace WPEFramework; + +class L2TestMocks : public ::testing::Test { +protected: + RfcApiImplMock *p_rfcApiImplMock = nullptr ; + RfcApi *p_rfcApi = nullptr ; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + std::string thunder_address; + + L2TestMocks(); + virtual ~L2TestMocks(); + + /** + * @brief Invoke a service method + * + * @param[in] callsign Service callsign + * @param[in] method Method name + * @param[in] params Method parameters + * @param[out] results Method results + * @return Zero (Core::ERROR_NONE) on succes or another value on error + */ + uint32_t InvokeServiceMethod(const char *callsign, const char *method, JsonObject ¶ms, JsonObject &results); + + /** + * @brief Activate a service plugin + * + * @param[in] callsign Service callsign + * @return Zero (Core::ERROR_NONE) on succes or another value on error + */ + uint32_t ActivateService(const char *callsign); + + /** + * @brief Deactivate a service plugin + * + * @param[in] callsign Service callsign + * @return Zero (Core::ERROR_NONE) on succes or another value on error + */ + uint32_t DeactivateService(const char *callsign); + +}; + diff --git a/Tests/L2Tests/L2TestsPlugin/L2TestsPlugin.json b/Tests/L2Tests/L2TestsPlugin/L2TestsPlugin.json new file mode 100755 index 0000000000..fad86347ff --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/L2TestsPlugin.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://raw.githubusercontent.com/rdkcentral/rdkservices/main/Tools/json_generator/schemas/plugin.schema.json", + "info": { + "title": "L2Tests Plugin", + "callsign": "org.rdk.L2Tests", + "locator": "libWPEFrameworkL2Tests.so", + "status": "alpha", + "description": "The L2 Tests plugin" + }, + "interface": { + "$ref": "L2Tests.json#" + } +} diff --git a/Tests/L2Tests/L2TestsPlugin/Module.cpp b/Tests/L2Tests/L2TestsPlugin/Module.cpp new file mode 100755 index 0000000000..6c2ac3b4aa --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/Module.cpp @@ -0,0 +1,21 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#include "Module.h" +MODULE_NAME_DECLARATION(BUILD_REFERENCE) + diff --git a/Tests/L2Tests/L2TestsPlugin/Module.h b/Tests/L2Tests/L2TestsPlugin/Module.h new file mode 100755 index 0000000000..7531487bc3 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/Module.h @@ -0,0 +1,32 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#ifndef __MODULE_PLUGIN_L2TESTS_H +#define __MODULE_PLUGIN_L2TESTS_H + +#ifndef MODULE_NAME +#define MODULE_NAME Plugin_L2Tests +#endif + +#include + +#undef EXTERNAL +#define EXTERNAL + +#endif // __MODULE_PLUGIN_L2TESTS_H + diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemService_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemService_L2Test.cpp new file mode 100755 index 0000000000..1d55860633 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemService_L2Test.cpp @@ -0,0 +1,443 @@ +#include +#include +#include "L2Tests.h" +#include "L2TestsMock.h" +#include +#include +#include + +#define JSON_TIMEOUT (1000) +#define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); +#define SYSTEM_CALLSIGN _T("org.rdk.System.1") +#define L2TEST_CALLSIGN _T("L2tests.1") + +using ::testing::NiceMock; +using namespace WPEFramework; +using testing::StrictMock; + +typedef enum : uint32_t { + SYSTEMSERVICEL2TEST_SYSTEMSTATE_CHANGED = 0x00000001, + SYSTEMSERVICEL2TEST_THERMALSTATE_CHANGED=0x00000002, + SYSTEMSERVICEL2TEST_LOGUPLOADSTATE_CHANGED=0x00000004, + SYSTEMSERVICEL2TEST_STATE_INVALID = 0x00000000 +}SystemServiceL2test_async_events_t; +/** + * @brief Internal test mock class + * + * Note that this is for internal test use only and doesn't mock any actual + * concrete interface. + */ +class AsyncHandlerMock +{ + public: + AsyncHandlerMock() + { + } + + MOCK_METHOD(void, onTemperatureThresholdChanged, (const JsonObject &message)); + MOCK_METHOD(void, onLogUploadChanged, (const JsonObject &message)); + MOCK_METHOD(void, onSystemPowerStateChanged, (const JsonObject &message)); +}; + +/* Systemservice L2 test class declaration */ +class SystemService_L2Test : public L2TestMocks { +protected: + IARM_EventHandler_t systemStateChanged = nullptr; + IARM_EventHandler_t thermMgrEventsHandler = nullptr; + IARM_EventHandler_t powerEventHandler = nullptr; + + SystemService_L2Test(); + virtual ~SystemService_L2Test() override; + + public: + /** + * @brief called when Temperature threshold + * changed notification received from IARM + */ + void onTemperatureThresholdChanged(const JsonObject &message); + + /** + * @brief called when Uploadlog status + * changed notification received because of state change + */ + void onLogUploadChanged(const JsonObject &message); + + /** + * @brief called when System state + * changed notification received from IARM + */ + void onSystemPowerStateChanged(const JsonObject &message); + + /** + * @brief waits for various status change on asynchronous calls + */ + uint32_t WaitForRequestStatus(uint32_t timeout_ms,SystemServiceL2test_async_events_t expected_status); + + private: + /** @brief Mutex */ + std::mutex m_mutex; + + /** @brief Condition variable */ + std::condition_variable m_condition_variable; + + /** @brief Event signalled flag */ + uint32_t m_event_signalled; +}; + + +/** + * @brief Constructor for SystemServices L2 test class + */ +SystemService_L2Test::SystemService_L2Test() + : L2TestMocks() +{ + uint32_t status = Core::ERROR_GENERAL; + m_event_signalled = SYSTEMSERVICEL2TEST_STATE_INVALID; + + /* Set all the asynchronouse event handler with IARM bus to handle various events*/ + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { + if ((string(IARM_BUS_SYSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_SYSMGR_EVENT_SYSTEMSTATE)) { + systemStateChanged = handler; + } + if ((string(IARM_BUS_PWRMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_PWRMGR_EVENT_THERMAL_MODECHANGED)) { + thermMgrEventsHandler = handler; + } + if ((string(IARM_BUS_PWRMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_PWRMGR_EVENT_MODECHANGED)) { + powerEventHandler = handler; + } + return IARM_RESULT_SUCCESS; + })); + + /* Activate plugin in constructor */ + status = ActivateService("org.rdk.System"); + EXPECT_EQ(Core::ERROR_NONE, status); + +} + +/** + * @brief Destructor for SystemServices L2 test class + */ +SystemService_L2Test::~SystemService_L2Test() +{ + uint32_t status = Core::ERROR_GENERAL; + m_event_signalled = SYSTEMSERVICEL2TEST_STATE_INVALID; + + status = DeactivateService("org.rdk.System"); + EXPECT_EQ(Core::ERROR_NONE, status); +} + +/** + * @brief called when Temperature threshold + * changed notification received from IARM + * + * @param[in] message from system service on the change + */ +void SystemService_L2Test::onTemperatureThresholdChanged(const JsonObject &message) +{ + TEST_LOG("onTemperatureThresholdChanged event triggered ***\n"); + std::unique_lock lock(m_mutex); + + std::string str; + message.ToString(str); + + TEST_LOG("onTemperatureThresholdChanged received: %s\n", str.c_str()); + + /* Notify the requester thread. */ + m_event_signalled |= SYSTEMSERVICEL2TEST_THERMALSTATE_CHANGED; + m_condition_variable.notify_one(); +} + +/** + * @brief called when Uploadlog status + * changed notification received because of state change + * + * @param[in] message from system service on the change + */ +void SystemService_L2Test::onLogUploadChanged(const JsonObject &message) +{ + TEST_LOG("onLogUploadChanged event triggered ******\n"); + std::unique_lock lock(m_mutex); + + std::string str; + message.ToString(str); + + TEST_LOG("onLogUploadChanged received: %s\n", str.c_str()); + + /* Notify the requester thread. */ + m_event_signalled |= SYSTEMSERVICEL2TEST_LOGUPLOADSTATE_CHANGED; + m_condition_variable.notify_one(); +} + +/** + * @brief called when System state + * changed notification received from IARM + * + * @param[in] message from system service on the change + */ +void SystemService_L2Test::onSystemPowerStateChanged(const JsonObject &message) +{ + TEST_LOG("onSystemPowerStateChanged event triggered ******\n"); + std::unique_lock lock(m_mutex); + + std::string str; + message.ToString(str); + + TEST_LOG("onSystemPowerStateChanged received: %s\n", str.c_str()); + + /* Notify the requester thread. */ + m_event_signalled |= SYSTEMSERVICEL2TEST_SYSTEMSTATE_CHANGED;; + m_condition_variable.notify_one(); +} + +/** + * @brief waits for various status change on asynchronous calls + * + * @param[in] timeout_ms timeout for waiting + */ +uint32_t SystemService_L2Test::WaitForRequestStatus(uint32_t timeout_ms,SystemServiceL2test_async_events_t expected_status) +{ + std::unique_lock lock(m_mutex); + auto now = std::chrono::system_clock::now(); + std::chrono::milliseconds timeout(timeout_ms); + uint32_t signalled = SYSTEMSERVICEL2TEST_STATE_INVALID; + + while (!(expected_status & m_event_signalled)) + { + if (m_condition_variable.wait_until(lock, now + timeout) == std::cv_status::timeout) + { + TEST_LOG("Timeout waiting for request status event"); + break; + } + } + + signalled = m_event_signalled; + + return signalled; +} + + +/** + * @brief Compare two request status objects + * + * @param[in] data Expected value + * @return true if the argument and data match, false otherwise + */ +MATCHER_P(MatchRequestStatus, data, "") +{ + bool match = true; + std::string expected; + std::string actual; + + data.ToString(expected); + arg.ToString(actual); + TEST_LOG(" rec = %s, arg = %s",expected.c_str(),actual.c_str()); + EXPECT_STREQ(expected.c_str(),actual.c_str()); + + return match; +} + +/******************************************************** +************Test case Details ************************** +** 1. Get temperature from systemservice +** 2. Set temperature threshold +** 3. Temperature threshold change event triggered from IARM +** 4. Verify that threshold change event is notified +*******************************************************/ + +TEST_F(SystemService_L2Test,SystemServiceGetSetTemperature) +{ + JSONRPC::LinkType jsonrpc(SYSTEM_CALLSIGN, L2TEST_CALLSIGN); + StrictMock async_handler; + uint32_t status = Core::ERROR_GENERAL; + JsonObject params,thresholds; + JsonObject result; + uint32_t signalled = SYSTEMSERVICEL2TEST_STATE_INVALID; + std::string message; + JsonObject expected_status; + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + . WillByDefault( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_PWRMGR_API_GetThermalState))); + auto param = static_cast(arg); + param->curTemperature = 100; + return IARM_RESULT_SUCCESS; + }); + + status = InvokeServiceMethod("org.rdk.System.1", "getCoreTemperature", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + + EXPECT_TRUE(result["success"].Boolean()); + EXPECT_STREQ("100.000000", result["temperature"].Value().c_str()); + + /* errorCode and errorDescription should not be set */ + EXPECT_FALSE(result.HasLabel("errorCode")); + EXPECT_FALSE(result.HasLabel("errorDescription")); + + /* Register for temperature threshold change event. */ + status = jsonrpc.Subscribe(JSON_TIMEOUT, + _T("onTemperatureThresholdChanged"), + &AsyncHandlerMock::onTemperatureThresholdChanged, + &async_handler); + + EXPECT_EQ(Core::ERROR_NONE, status); + + /* Set Threshold */ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_PWRMGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_PWRMGR_API_SetTemperatureThresholds))); + auto param = static_cast(arg); + EXPECT_EQ(param->tempHigh, 95); + EXPECT_EQ(param->tempCritical, 99); + return IARM_RESULT_SUCCESS; + }); + + thresholds["WARN"] = 95; + thresholds["MAX"] = 99; + params["thresholds"] = thresholds; + + status = InvokeServiceMethod("org.rdk.System.1", "setTemperatureThresholds", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + + EXPECT_TRUE(result["success"].Boolean()); + + /* errorCode and errorDescription should not be set */ + EXPECT_FALSE(result.HasLabel("errorCode")); + EXPECT_FALSE(result.HasLabel("errorDescription")); + + + /* Request status for TempThreashold. */ + message = "{\"thresholdType\":\"WARN\",\"exceeded\":true,\"temperature\":\"100.000000\"}"; + expected_status.FromString(message); + EXPECT_CALL(async_handler, onTemperatureThresholdChanged(MatchRequestStatus(expected_status))) + .WillOnce(Invoke(this, &SystemService_L2Test::onTemperatureThresholdChanged)); + + IARM_Bus_PWRMgr_EventData_t param; + param.data.therm.newLevel = IARM_BUS_PWRMGR_TEMPERATURE_HIGH; + param.data.therm.curLevel = IARM_BUS_PWRMGR_TEMPERATURE_NORMAL; + param.data.therm.curTemperature = 100; + thermMgrEventsHandler(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_EVENT_THERMAL_MODECHANGED, ¶m, 0); + + signalled = WaitForRequestStatus(JSON_TIMEOUT,SYSTEMSERVICEL2TEST_THERMALSTATE_CHANGED); + EXPECT_TRUE(signalled & SYSTEMSERVICEL2TEST_THERMALSTATE_CHANGED); + + /* Unregister for events. */ + jsonrpc.Unsubscribe(JSON_TIMEOUT, _T("onTemperatureThresholdChanged")); +} + +/******************************************************** +************Test case Details ************************** +** 1. Start Log upload +** 2. Subscribe for powerstate change +** 3. Subscribe for LoguploadUpdates +** 4. Trigger system power state change from ON -> DEEP_SLEEP +** 5. Verify UPLOAD_ABORTED event triggered because of power state +** 6. Verify Systemstate event triggered and verify the response +*******************************************************/ +TEST_F(SystemService_L2Test,SystemServiceUploadLogsAndSystemPowerStateChange) +{ + JSONRPC::LinkType jsonrpc(SYSTEM_CALLSIGN,L2TEST_CALLSIGN); + StrictMock async_handler; + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + uint32_t signalled = SYSTEMSERVICEL2TEST_STATE_INVALID; + std::string message; + JsonObject expected_status; + + const string uploadStbLogFile = _T("/lib/rdk/uploadSTBLogs.sh"); + Core::File file(uploadStbLogFile); + file.Create(); + EXPECT_TRUE(Core::File(string(_T("/lib/rdk/uploadSTBLogs.sh"))).Exists()); + + ON_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) { + pstParamData->type = WDMP_BOOLEAN; + strncpy(pstParamData->value, "true", sizeof(pstParamData->value)); + return WDMP_SUCCESS; + })); + + + std::ofstream deviceProperties("/etc/device.properties"); + deviceProperties << "BUILD_TYPE=dev\n"; + deviceProperties << "FORCE_MTLS=true\n"; + deviceProperties.close(); + EXPECT_TRUE(Core::File(string(_T("/etc/device.properties"))).Exists()); + + std::ofstream dcmPropertiesFile("/opt/dcm.properties"); + dcmPropertiesFile << "LOG_SERVER=logs.xcal.tv\n"; + dcmPropertiesFile << "DCM_LOG_SERVER=stblogger.ccp.xcal.tv\n"; + dcmPropertiesFile << "DCM_LOG_SERVER_URL=https://xconf.xcal.tv/loguploader/getSettings\n"; + dcmPropertiesFile << "DCM_SCP_SERVER=stbscp.ccp.xcal.tv\n"; + dcmPropertiesFile << "HTTP_UPLOAD_LINK=https://ssr.ccp.xcal.tv/cgi-bin/S3.cgi\n"; + dcmPropertiesFile << "DCA_UPLOAD_URL=https://stbrtl.r53.xcal.tv\n"; + dcmPropertiesFile.close(); + EXPECT_TRUE(Core::File(string(_T("/opt/dcm.properties"))).Exists()); + + std::ofstream tmpDcmSettings("/tmp/DCMSettings.conf"); + tmpDcmSettings << "LogUploadSettings:UploadRepository:uploadProtocol=https\n"; + tmpDcmSettings << "LogUploadSettings:UploadRepository:URL=https://example.com/upload\n"; + tmpDcmSettings << "LogUploadSettings:UploadOnReboot=true\n"; + tmpDcmSettings.close(); + EXPECT_TRUE(Core::File(string(_T("/tmp/DCMSettings.conf"))).Exists()); + + status = InvokeServiceMethod("org.rdk.System.1", "uploadLogsAsync", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + + EXPECT_TRUE(result["success"].Boolean()); + + /* errorCode and errorDescription should not be set */ + EXPECT_FALSE(result.HasLabel("errorCode")); + EXPECT_FALSE(result.HasLabel("errorDescription")); + + /* Register for abortlog event. */ + status = jsonrpc.Subscribe(JSON_TIMEOUT, + _T("onLogUpload"), + &AsyncHandlerMock::onLogUploadChanged, + &async_handler); + + EXPECT_EQ(Core::ERROR_NONE, status); + + /* Register for Powerstate change event. */ + status = jsonrpc.Subscribe(JSON_TIMEOUT, + _T("onSystemPowerStateChanged"), + &AsyncHandlerMock::onSystemPowerStateChanged, + &async_handler); + + EXPECT_EQ(Core::ERROR_NONE, status); + + /* Request status for Onlogupload. */ + message = "{\"logUploadStatus\":\"UPLOAD_ABORTED\"}"; + expected_status.FromString(message); + EXPECT_CALL(async_handler, onLogUploadChanged(MatchRequestStatus(expected_status))) + .WillOnce(Invoke(this, &SystemService_L2Test::onLogUploadChanged)); + + /* Request status for Onlogupload. */ + message = "{\"powerState\":\"DEEP_SLEEP\",\"currentPowerState\":\"ON\"}"; + expected_status.FromString(message); + EXPECT_CALL(async_handler, onSystemPowerStateChanged(MatchRequestStatus(expected_status))) + .WillOnce(Invoke(this, &SystemService_L2Test::onSystemPowerStateChanged)); + + IARM_Bus_PWRMgr_EventData_t param; + param.data.state.curState = IARM_BUS_PWRMGR_POWERSTATE_ON; + param.data.state.newState = IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP; + powerEventHandler(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_EVENT_MODECHANGED, ¶m, 0); + + signalled = WaitForRequestStatus(JSON_TIMEOUT,SYSTEMSERVICEL2TEST_LOGUPLOADSTATE_CHANGED); + EXPECT_TRUE(signalled & SYSTEMSERVICEL2TEST_LOGUPLOADSTATE_CHANGED); + + signalled = WaitForRequestStatus(JSON_TIMEOUT,SYSTEMSERVICEL2TEST_SYSTEMSTATE_CHANGED); + EXPECT_TRUE(signalled & SYSTEMSERVICEL2TEST_SYSTEMSTATE_CHANGED); + + /* Unregister for events. */ + jsonrpc.Unsubscribe(JSON_TIMEOUT, _T("onLogUpload")); + jsonrpc.Unsubscribe(JSON_TIMEOUT, _T("onSystemPowerStateChanged")); + +} diff --git a/Tests/L2Tests/L2TestsPlugin/tests/UsbAccess_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/UsbAccess_L2Test.cpp new file mode 100755 index 0000000000..a2d319ccbe --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/tests/UsbAccess_L2Test.cpp @@ -0,0 +1,12 @@ +#include +#include +#include "L2Tests.h" +#include "L2TestsMock.h" + +using ::testing::NiceMock; + +class UsbAccess_L2test : public L2TestMocks { +}; +TEST_F(UsbAccess_L2test, test1) +{ +} diff --git a/Tests/L2Tests/L2testController.cpp b/Tests/L2Tests/L2testController.cpp new file mode 100755 index 0000000000..7b2ddf9a71 --- /dev/null +++ b/Tests/L2Tests/L2testController.cpp @@ -0,0 +1,207 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#include +#include +#include +#include "Module.h" +#include +#include +#include "L2testController.h" + +#ifndef CMAKE_INSTALL_PREFIX +#error CMAKE_INSTALL_PREFIX must be defined +#endif + +#define L2TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); + +#define THUNDER_ACCESS _T("THUNDER_ACCESS") /* WPEFramework network address variable. */ +#define THUNDER_ADDRESS "127.0.0.1" /* WPEFramework network address. */ +#define THUNDER_ADDRESS_LENGTH 25 /* WPEFramework network address length in bytes. */ +#ifndef THUNDER_PORT +#define THUNDER_PORT "9998" /* Default WPEFramework port (as a string). */ +#endif +#define TEST_CALLSIGN _T("thunder_tests.1") /* Test module callsign. */ +#define L2TEST_CALLSIGN _T("org.rdk.L2Tests.1") /* L2 Test module callsign. */ +#define THUNDER_CMD_LENGTH 1024 /* Command length to run thunder in isolation . */ + +#ifndef TEST_COMPLETION_TIMEOUT +#define TEST_COMPLETION_TIMEOUT 600000 /* Overall L2 Test completion timeout in milliseconds. */ +#endif + +using namespace WPEFramework; +// initializing instancePtr with NULL +L2testController* L2testController ::instancePtr = NULL; + + +L2testController* L2testController::getInstance() +{ + /*If there is no instance of class + then we can create an instance */ + if (instancePtr == NULL) + { + instancePtr = new L2testController(); + return instancePtr; + } + else + { + /* if instancePtr != NULL that means + the class already have an instance. + So, we are returning that instance + and not creating new one.*/ + return instancePtr; + } +} +bool L2testController::StartThunder() +{ + char command[THUNDER_CMD_LENGTH]; + char address[THUNDER_ADDRESS_LENGTH]; + + /* Spawn the Thunder process. */ + snprintf(command, sizeof(command), "WPEFramework -c %s/../etc/WPEFramework/config.json", CMAKE_INSTALL_PREFIX); + m_fp = popen(command, "w"); + if (nullptr == m_fp) + { + printf("Failed to start WPEFramework. Ensure that PATH and LD_LIRARY_PATH are set\n" + "For example:\n" + "$ export PATH=`pwd`/install/usr/bin:$PATH\n" + "$ export LD_LIBRARY_PATH=`pwd`/install/usr/lib:$LD_LIBRARY_PATH\n"); + return false; + } + + /* Allow time for the server to start. */ + (void)sleep(1U); + + /* Configure the JSONRPC connection, as the test starts before WPEFramework. */ + snprintf(address, sizeof(address), "%s:%s", THUNDER_ADDRESS, THUNDER_PORT); + WPEFramework::Core::SystemInfo::SetEnvironment(THUNDER_ACCESS, address); + + return true; +} + +void L2testController::StopThunder() +{ + + if (nullptr != m_fp) + { + /* Terminate the Thunder process and wait for it to exit. */ + fprintf(m_fp, "Q\n"); + (void)pclose(m_fp); + m_fp = nullptr; + } + +} + +/** + * @brief Initialize L2 test, calls first method of L2Tests plugin + * + * @param[in] params Method parameters + * @param[out] results Method results + * @return Zero (Core::ERROR_NONE) on succes or another value on error + */ +uint32_t L2testController::PerformL2Tests(JsonObject ¶ms, JsonObject &results) +{ + JSONRPC::LinkType jsonrpc(std::string(L2TEST_CALLSIGN), TEST_CALLSIGN); + std::string message; + std::string reply; + uint32_t status = Core::ERROR_GENERAL; + + params.ToString(message); + L2TEST_LOG("Invoking %s.parameters %s", L2TEST_CALLSIGN, message.c_str()); + + results = JsonObject(); + status = jsonrpc.Invoke(TEST_COMPLETION_TIMEOUT, std::string(_T("PerformL2Tests")), params, results); + + results.ToString(reply); + L2TEST_LOG("Status %u, results %s", status, reply.c_str()); + + return status; +} + +int main(int argc, char **argv) +{ + JsonObject params; + JsonObject result; + uint32_t status = Core::ERROR_GENERAL; + int arguments=1; + std::string message; + int return_status = -1; + L2testController* L2testobj + = L2testController ::getInstance(); + + + L2TEST_LOG("Starting Thunder"); + if (false == L2testobj->StartThunder()) + { + L2TEST_LOG("Failed to start thunder \n"); + return return_status; + } + + L2TEST_LOG("Argument count = %d\n",argc); + + /* L2 tests can be run with different options + ** RdkServicesL2Test - To run all suits + ** RdkServicesL2Test TestSuiteXXXX (seperated with space ) + ** Ex: RdkServicesL2Test Systemservice_L2test --> Runs only systemservice suite test + ** RdkServicesL2Test Systemservice_L2test UsbAccess_L2test--> Runs systemservice and UsbAccesssuite tests + **/ + if(argc > 1) /* First argument is always executable */ + { + + /* To run gtest for specific suite we need to provide gtest filter. + ** Filter is set inside L2test plugin, so we are sending it as paramter. + ** Filters can be in following format + ** ::testing::GTEST_FLAG(filter) = "Testsuit1*:Testsuite2*" + **/ + + message = std::string(argv[arguments]) + std::string("*"); + L2TEST_LOG("Argument passed = %s, message = %s\n",argv[arguments],message.c_str()); + arguments++; + while(argumentsPerformL2Tests(params, result); + if(status != Core::ERROR_NONE) + { + L2TEST_LOG("Issue with starting L2 test in test plugin"); + } + else + { + L2TEST_LOG("Successfully ran L2 tests"); + return_status = 0; + } + + L2TEST_LOG("Stoppng Thunder"); + L2testobj->StopThunder(); + + return return_status; + +} + diff --git a/Tests/L2Tests/L2testController.h b/Tests/L2Tests/L2testController.h new file mode 100755 index 0000000000..2b6865ebab --- /dev/null +++ b/Tests/L2Tests/L2testController.h @@ -0,0 +1,71 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#ifndef L2TEST_CONTROLLER_H +#define L2TEST_CONTROLLER_H + +using namespace WPEFramework; + +class L2testController +{ + private: + static L2testController* instancePtr; + L2testController(){ + m_fp = NULL; + } + ~L2testController() { + } + /** @brief Pipe file to send commands to the WPEFramework process. */ + FILE *m_fp; + + public: + // deleting copy constructor + L2testController(const L2testController& obj) = delete; + L2testController& operator=(const L2testController&) = delete; + + /** + * @brief Getting the class instance + * + */ + static L2testController* getInstance(); + + /** + * @brief Spawn Thunder process in isolation + * + */ + bool StartThunder(); + + /** + * @brief Stops thunder + * + */ + void StopThunder(); + + /** + * @brief Perform L2 test, calls first method of L2Tests plugin + * + * @param[in] method Method name + * @param[in] params Method parameters + * @param[out] results Method results + * @return Zero (Core::ERROR_NONE) on succes or another value on error + */ + uint32_t PerformL2Tests(JsonObject ¶ms, JsonObject &results); + +}; + +#endif /* L2TEST_CONTROLLER_H */ diff --git a/Tests/L2Tests/Module.cpp b/Tests/L2Tests/Module.cpp new file mode 100755 index 0000000000..6c2ac3b4aa --- /dev/null +++ b/Tests/L2Tests/Module.cpp @@ -0,0 +1,21 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#include "Module.h" +MODULE_NAME_DECLARATION(BUILD_REFERENCE) + diff --git a/Tests/L2Tests/Module.h b/Tests/L2Tests/Module.h new file mode 100755 index 0000000000..ad2fb9a691 --- /dev/null +++ b/Tests/L2Tests/Module.h @@ -0,0 +1,28 @@ +/* If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +#ifndef MODULE_THUNDER_TESTS_H +#define MODULE_THUNDER_TESTS_H +#ifndef MODULE_NAME +#define MODULE_NAME thunder_tests +#endif +#include +#undef EXTERNAL +#define EXTERNAL +#endif // MODULE_THUNDER_TESTS_H + diff --git a/Tests/L2Tests/README.md b/Tests/L2Tests/README.md new file mode 100755 index 0000000000..51f0ca1c87 --- /dev/null +++ b/Tests/L2Tests/README.md @@ -0,0 +1,89 @@ +#RDK services L2 Tests # + +## How to run locally ## + +Install [act](https://github.com/nektos/act) and docker: + +##### Ubuntu ##### + +```shell script +curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash +sudo apt update +sudo apt -y install docker.io +``` + +##### macOS ##### + +```shell script +brew install act +brew install --cask docker +``` + +Create a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). + +Invoke the workflow: + +```shell script +act -W .github/workflows/L2-tests.yml -s GITHUB_TOKEN=[token] +``` + +`-r, --reuse` to reuse the container. + +Get a bash shell in the container, if needed: + +```shell script +docker ps +docker exec -it /bin/bash +``` + +## FAQ ## + +1. The commands to build and run tests are in [L2-tests.yml](../../.github/workflows/L2-tests.yml). + For the queries on syntax please refer to the [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions). + +2. External dependencies need to be mocked. + For each external header, add one into the [l2tests.cmake](../../l2tests.cmake) (preserve the original path parts, if needed). + For each external declaration, add one into the [mocks folder](../mocks). + For the queries on mocks please refer to the [gMock Cookbook](http://google.github.io/googletest/gmock_cook_book.html). + +3. For the queries on how to write tests please refer to the [GoogleTest User’s Guide](https://google.github.io/googletest/). + Common recommendations: + - Tests should be fast. + - Tests should be independent and repeatable. + - Find the L2 usecase/logic from your plugin which you can test. Isolate each use case from other use cases. + - Implement the Arrange-Act-Assert patterns for each step in a use case. + If two or more tests operate on similar data, use a test fixture. + Use `ON_CALL` by default, and only use `EXPECT_CALL` when intend to verify that the call is made. + +4. To add L2 tests for a RDK service + Required steps: + - Set plugin ON by default in [l2tests.cmake](../../l2tests.cmake) + Example : set(PLUGIN_SYSTEMSERVICES ON) + + - Add required empty headers,definitions and mock files in [l2tests.cmake](../../l2tests.cmake) to pass compilation for the added plugin + - Update yml file as well to enable the plugin. + Example : -DPLUGIN_SYSTEMSERVICES=ON + + - Add new L2 test file for the plugin in folder rdkservices/L2Tests/tests with name Pluginname_L2tests + Example : SystemServices_L2test.cpp + + - Add a class (with pluginname_L2tests as name) which inherits the mock class for getting all the mocks required by plugin. + Example :class Systemservice_L2test : public L2TestMocks + + - Add Test fixtures for each usecase. + +5. To run L2 tests for specific suite (plugin) + During test/code development, we often do not want to run all the tests. Instead, to save time, we can use the following method to run specified test suite(s). + + Required steps: + - In yml file in the step where it runs the L2test binary RDKServiceL2test add the test suite name you want to run + Example : + a. If we want to run single suite + RDKServicesL2test System (this is internally considered as 'System*' and gtest framework runs all tests added with suite name starting with 'System') + b. If we want to run multiple suites + RDKServicesL2test System Usb (this is internally considered as 'System*:Usb*' and gtest framework runs all tests added with suite name starting with 'System' and all tests with suite name starting with 'Usb') + + + Note: TEST_COMPLETION_TIMEOUT specifies a time limit for completing the specified tests. This can be increased/decreased by changing the value in [CMakeLists.txt](./CMakeLists.txt). + + diff --git a/Tests/L2Tests/patches/0001-RDK-30034-callsign.patch b/Tests/L2Tests/patches/0001-RDK-30034-callsign.patch new file mode 100755 index 0000000000..9843735d20 --- /dev/null +++ b/Tests/L2Tests/patches/0001-RDK-30034-callsign.patch @@ -0,0 +1,25 @@ +From 627f4073157fec9abc42334fcc3c96ca3da7d11a Mon Sep 17 00:00:00 2001 +From: Venkataprasad Karna +Date: Thu, 7 Jan 2021 06:31:21 +0000 +Subject: [PATCH] setting proper callsign + +--- + Source/websocket/JSONRPCLink.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Source/websocket/JSONRPCLink.h b/Source/websocket/JSONRPCLink.h +index 3eb8b079..e057e930 100644 +--- a/Source/websocket/JSONRPCLink.h ++++ b/Source/websocket/JSONRPCLink.h +@@ -594,7 +594,7 @@ namespace JSONRPC { + _localSpace = localCallsign; + } + +- uint8_t version = Core::JSONRPC::Message::Version(_callsign); ++ uint8_t version = Core::JSONRPC::Message::Version(callsign + '.'); + if( version != static_cast(~0) ) { + _versionstring = '.' + Core::NumberType(version).Text(); + } +-- +2.24.0 + diff --git a/Tests/mocks/CMakeLists.txt b/Tests/mocks/CMakeLists.txt new file mode 100755 index 0000000000..13fffa3c6a --- /dev/null +++ b/Tests/mocks/CMakeLists.txt @@ -0,0 +1,44 @@ +#if not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 Synamedia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.8) +set(MODULE_NAME TestMocklib) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip +) +FetchContent_MakeAvailable(googletest) + + +add_library(${MODULE_NAME} SHARED + Rfc.cpp + Iarm.cpp + Wraps.cpp +) +target_link_libraries(${MODULE_NAME} PRIVATE gmock_main) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + + +install(TARGETS ${MODULE_NAME} + DESTINATION lib) + + diff --git a/Tests/mocks/Dobby.cpp b/Tests/mocks/Dobby.cpp index 99918604e5..8093142ef4 100644 --- a/Tests/mocks/Dobby.cpp +++ b/Tests/mocks/Dobby.cpp @@ -1,6 +1,192 @@ #include "Dobby.h" +#include std::shared_ptr AI_IPC::createIpcService(const std::string& address, const std::string& serviceName, int defaultTimeoutMs) { return std::make_shared(address, serviceName, defaultTimeoutMs); -} \ No newline at end of file +} + + IDobbyProxy* DobbyProxy::impl = nullptr; + + DobbyProxy::DobbyProxy() {} + + void DobbyProxy::setImpl(IDobbyProxy* newImpl) + { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; + } + + DobbyProxy::DobbyProxy(const std::shared_ptr& ipcService, + const std::string& serviceName, + const std::string& objectName) + { + } + bool DobbyProxy::shutdown() const + { + EXPECT_NE(impl, nullptr); + return impl->shutdown(); + } + + bool DobbyProxy::ping() const + { + EXPECT_NE(impl, nullptr); + return impl->ping(); + } + + bool DobbyProxy::isAlive(const std::chrono::milliseconds& timeout) const + { + EXPECT_NE(impl, nullptr); + return impl->isAlive(timeout); + } + + bool DobbyProxy::setLogMethod(uint32_t method, int pipeFd) const + { + EXPECT_NE(impl, nullptr); + return impl->setLogMethod(method, pipeFd); + } + + bool DobbyProxy::setLogLevel(int level) const + { + EXPECT_NE(impl, nullptr); + return impl->setLogLevel(level); + } + + bool DobbyProxy::setAIDbusAddress(bool privateBus, + const std::string& address) const + { + EXPECT_NE(impl, nullptr); + return impl->setAIDbusAddress(privateBus, address); + } + + // Control interface + int32_t DobbyProxy::startContainerFromSpec(const std::string& id, + const std::string& jsonSpec, + const std::list& files, + const std::string& command , + const std::string& displaySocket , + const std::vector& envVars ) const + { + EXPECT_NE(impl, nullptr); + return impl->startContainerFromSpec(id, jsonSpec, files, command, displaySocket, envVars); + } + + + int32_t DobbyProxy::startContainerFromBundle(const std::string& id, + const std::string& bundlePath, + const std::list& files, + const std::string& command , + const std::string& displaySocket, + const std::vector& envVars ) const + { + EXPECT_NE(impl, nullptr); + return impl->startContainerFromBundle(id, bundlePath, files, command, displaySocket, envVars); + } + + bool DobbyProxy::stopContainer(int32_t cd, bool withPrejudice) const + { + EXPECT_NE(impl, nullptr); + return impl->stopContainer(cd, withPrejudice); + } + + bool DobbyProxy::pauseContainer(int32_t cd) const + { + EXPECT_NE(impl, nullptr); + return impl->pauseContainer(cd); + } + + bool DobbyProxy::resumeContainer(int32_t cd) const + { + EXPECT_NE(impl, nullptr); + return impl->resumeContainer(cd); + } + + bool DobbyProxy::execInContainer(int32_t cd, + const std::string& options, + const std::string& command) const + { + EXPECT_NE(impl, nullptr); + return impl->execInContainer(cd, options, command); + } + + int DobbyProxy::getContainerState(int32_t cd) const + { + EXPECT_NE(impl, nullptr); + return impl->getContainerState(cd); + } + + int DobbyProxy::registerListener(const StateChangeListener &listener, const void* cbParams) + { + EXPECT_NE(impl, nullptr); + return impl->registerListener(listener, cbParams); + } + + void DobbyProxy::unregisterListener(int tag) + { + EXPECT_NE(impl, nullptr); + impl->unregisterListener(tag); + } + + std::string DobbyProxy::getContainerInfo(int32_t descriptor) const + { + EXPECT_NE(impl, nullptr); + return impl->getContainerInfo(descriptor); + } + + std::list> DobbyProxy::listContainers() const + { + EXPECT_NE(impl, nullptr); + return impl->listContainers(); + } + + AI_IPC::IIpcService* IpcService::impl = nullptr; + + IpcService::IpcService() {} + + IpcService::IpcService(const std::string& dbusAddress, const std::string& serviceName, int defaultTimeoutMs) + { + } + + void IpcService::setImpl(AI_IPC::IIpcService* newImpl) + { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; + } + + bool IpcService::isValid() const + { + EXPECT_NE(impl, nullptr); + return impl->isValid(); + } + + void IpcService::flush() + { + EXPECT_NE(impl, nullptr); + return impl->flush(); + } + + bool IpcService::start() + { + EXPECT_NE(impl, nullptr); + return impl->start(); + } + + bool IpcService::stop() + { + EXPECT_NE(impl, nullptr); + return impl->stop(); + } + + bool IpcService::isServiceAvailable(const std::string& serviceName) const + { + EXPECT_NE(impl, nullptr); + return impl->isServiceAvailable(serviceName); + } + + std::string IpcService::getBusAddress() const + { + EXPECT_NE(impl, nullptr); + return impl->getBusAddress(); + } + diff --git a/Tests/mocks/Dobby.h b/Tests/mocks/Dobby.h index 3a8401f6d1..ad4fb1d682 100644 --- a/Tests/mocks/Dobby.h +++ b/Tests/mocks/Dobby.h @@ -44,52 +44,19 @@ std::shared_ptr createIpcService(const std::string& address, const class IpcService : public AI_IPC::IIpcService , public std::enable_shared_from_this { +protected: + static IIpcService* impl; public: - static IpcService& getInstance() - { - static IpcService instance; - return instance; - } - - IIpcService* impl; - - IpcService(const std::string& dbusAddress, const std::string& serviceName, int defaultTimeoutMs = -1) - { - } - - IpcService() - { - } - - bool isValid() const - { - return getInstance().impl->isValid(); - } - - void flush() - { - return getInstance().impl->flush(); - } - - bool start() - { - return getInstance().impl->start(); - } - - bool stop() - { - return getInstance().impl->stop(); - } - - bool isServiceAvailable(const std::string& serviceName) const - { - return getInstance().impl->isServiceAvailable(serviceName); - } - - std::string getBusAddress() const - { - return getInstance().impl->getBusAddress(); - } + IpcService(); + IpcService(const IpcService &obj) = delete; + static void setImpl(IIpcService* newImpl); + IpcService(const std::string& dbusAddress, const std::string& serviceName, int defaultTimeoutMs = -1); + bool isValid() const ; + void flush(); + bool start(); + bool stop(); + bool isServiceAvailable(const std::string& serviceName) const; + std::string getBusAddress() const; }; class IDobbyProxyEvents { @@ -167,56 +134,22 @@ class IDobbyProxy { class DobbyProxy : public IDobbyProxy { protected: - + static IDobbyProxy* impl; public: - static DobbyProxy& getInstance() - { - static DobbyProxy instance; - return instance; - } - - IDobbyProxy* impl; - - DobbyProxy() - { - } - + DobbyProxy(); + DobbyProxy(const DobbyProxy &obj) = delete; + static void setImpl(IDobbyProxy* newImpl); DobbyProxy(const std::shared_ptr& ipcService, const std::string& serviceName, - const std::string& objectName) - { - } - - bool shutdown() const - { - return getInstance().impl->shutdown(); - } - - bool ping() const - { - return getInstance().impl->ping(); - } - - bool isAlive(const std::chrono::milliseconds& timeout) const - { - return getInstance().impl->isAlive(timeout); - } - - bool setLogMethod(uint32_t method, int pipeFd) const - { - return getInstance().impl->setLogMethod(method, pipeFd); - } - - bool setLogLevel(int level) const - { - return getInstance().impl->setLogLevel(level); - } + const std::string& objectName); + bool shutdown() const; + bool ping() const; + bool isAlive(const std::chrono::milliseconds& timeout) const; + bool setLogMethod(uint32_t method, int pipeFd) const; + bool setLogLevel(int level) const; bool setAIDbusAddress(bool privateBus, - const std::string& address) const - { - return getInstance().impl->setAIDbusAddress(privateBus, address); - } + const std::string& address) const; public: // Control interface @@ -225,68 +158,24 @@ class DobbyProxy : public IDobbyProxy { const std::list& files, const std::string& command = "", const std::string& displaySocket = "", - const std::vector& envVars = std::vector()) const - { - return getInstance().impl->startContainerFromSpec(id, jsonSpec, files, command, displaySocket, envVars); - } - - - int32_t startContainerFromBundle(const std::string& id, + const std::vector& envVars = std::vector()) const; + int32_t startContainerFromBundle(const std::string& id, const std::string& bundlePath, const std::list& files, const std::string& command = "", const std::string& displaySocket = "", - const std::vector& envVars = std::vector()) const - { - return getInstance().impl->startContainerFromBundle(id, bundlePath, files, command, displaySocket, envVars); - } - - bool stopContainer(int32_t cd, bool withPrejudice) const - { - return getInstance().impl->stopContainer(cd, withPrejudice); - } - - bool pauseContainer(int32_t cd) const - { - return getInstance().impl->pauseContainer(cd); - } - - bool resumeContainer(int32_t cd) const - { - return getInstance().impl->resumeContainer(cd); - } - + const std::vector& envVars = std::vector()) const; + bool stopContainer(int32_t cd, bool withPrejudice) const; + bool pauseContainer(int32_t cd) const; + bool resumeContainer(int32_t cd) const; bool execInContainer(int32_t cd, const std::string& options, - const std::string& command) const - { - return getInstance().impl->execInContainer(cd, options, command); - } - - int getContainerState(int32_t cd) const - { - return getInstance().impl->getContainerState(cd); - } - - int registerListener(const StateChangeListener &listener, const void* cbParams) - { - return getInstance().impl->registerListener(listener, cbParams); - } - - void unregisterListener(int tag) - { - getInstance().impl->unregisterListener(tag); - } - - std::string getContainerInfo(int32_t descriptor) const - { - return getInstance().impl->getContainerInfo(descriptor); - } - - std::list> listContainers() const - { - return getInstance().impl->listContainers(); - } + const std::string& command) const; + int getContainerState(int32_t cd) const; + int registerListener(const StateChangeListener &listener, const void* cbParams); + void unregisterListener(int tag); + std::string getContainerInfo(int32_t descriptor) const; + std::list> listContainers() const; private: diff --git a/Tests/mocks/HdmiCec.cpp b/Tests/mocks/HdmiCec.cpp new file mode 100755 index 0000000000..645b53b57a --- /dev/null +++ b/Tests/mocks/HdmiCec.cpp @@ -0,0 +1,159 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "HdmiCec.h" +#include + +MessageDecoderImpl* MessageDecoder::impl = nullptr; + +MessageDecoder::MessageDecoder(MessageProcessor& proc) + : processor(proc) {} + +void MessageDecoder::setImpl(MessageDecoderImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +void MessageDecoder::decode(const CECFrame& in) { + EXPECT_NE(impl, nullptr); + return impl->decode(in); +} + + +ConnectionImpl* Connection::impl = nullptr; + +Connection::Connection(const LogicalAddress& source, bool opened, const std::string& name) {} + +Connection& Connection::getInstance() { + static Connection instance; + return instance; +} + +void Connection::setImpl(ConnectionImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +void Connection::open() { + EXPECT_NE(impl, nullptr); + return impl->open(); +} + +void Connection::close() { + EXPECT_NE(impl, nullptr); + return impl->close(); +} +void Connection::addFrameListener(FrameListener* listener) { + EXPECT_NE(impl, nullptr); + return impl->addFrameListener(listener); +} + +void Connection::ping(const LogicalAddress& from, const LogicalAddress& to, const Throw_e& doThrow) { + EXPECT_NE(impl, nullptr); + return impl->ping(from, to, doThrow); +} + +void Connection::sendToAsync(const LogicalAddress& to, const CECFrame& frame) { + EXPECT_NE(impl, nullptr); + return impl->sendToAsync(to, frame); +} + +void Connection::sendTo(const LogicalAddress& to, const CECFrame& frame) { + EXPECT_NE(impl, nullptr); + return impl->sendTo(to, frame); +} + +void Connection::sendTo(const LogicalAddress& to, const CECFrame& frame, int timeout) { + EXPECT_NE(impl, nullptr); + return impl->sendTo(to, frame, timeout); +} + +void Connection::poll(const LogicalAddress& from, const Throw_e& doThrow) { + EXPECT_NE(impl, nullptr); + return impl->poll(from, doThrow); +} + +void Connection::sendAsync(const CECFrame &frame){ + EXPECT_NE(impl, nullptr); + return impl->sendAsync(frame); +} + +void Connection::setSource(LogicalAddress& from) { +} + + +LibCCECImpl* LibCCEC::impl = nullptr; + +LibCCEC& LibCCEC::getInstance() { + static LibCCEC instance; + return instance; +} + +void LibCCEC::setImpl(LibCCECImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} +void LibCCEC::init(const char* name) { + EXPECT_NE(impl, nullptr); + impl->init(name); +} + +void LibCCEC::init() { + EXPECT_NE(impl, nullptr); + impl->init(); +} + +void LibCCEC::term() { +} + +void LibCCEC::getPhysicalAddress(uint32_t* physicalAddress) { + EXPECT_NE(impl, nullptr); + impl->getPhysicalAddress(physicalAddress); +} + +int LibCCEC::addLogicalAddress(const LogicalAddress& source) { + EXPECT_NE(impl, nullptr); + return impl->addLogicalAddress(source); +} + +int LibCCEC::getLogicalAddress(int devType) { + EXPECT_NE(impl, nullptr); + return impl->getLogicalAddress(devType); +} + +MessageEncoderImpl* MessageEncoder::impl = nullptr; + +void MessageEncoder::setImpl(MessageEncoderImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +CECFrame& MessageEncoder::encode(const UserControlPressed m) { + EXPECT_NE(impl, nullptr); + return impl->encode(m); +} + +CECFrame& MessageEncoder::encode(const DataBlock m) { + EXPECT_NE(impl, nullptr); + return impl->encode(m); +} diff --git a/Tests/mocks/HdmiCec.h b/Tests/mocks/HdmiCec.h index 9b18722cec..6d8122ef01 100644 --- a/Tests/mocks/HdmiCec.h +++ b/Tests/mocks/HdmiCec.h @@ -25,13 +25,13 @@ enum { REPORT_ARC_TERMINATED = 0XC2, REQUEST_ARC_INITIATION = 0XC3, REQUEST_ARC_TERMINATION = 0XC4, - REQUEST_CURRENT_LATENCY = 0xA7, - REPORT_CURRENT_LATENCY = 0xA8, + REQUEST_CURRENT_LATENCY = 0xA7, + REPORT_CURRENT_LATENCY = 0xA8, ROUTING_CHANGE = 0x80, - ROUTING_INFORMATION = 0x81, - SET_STREAM_PATH = 0x86, - GIVE_FEATURES = 0xA5, - REPORT_FEATURES = 0xA6 + ROUTING_INFORMATION = 0x81, + SET_STREAM_PATH = 0x86, + GIVE_FEATURES = 0xA5, + REPORT_FEATURES = 0xA6 }; typedef struct _dsHdmiInGetNumberOfInputsParam_t { @@ -90,8 +90,8 @@ class CECFrame { void getBuffer(const uint8_t** buf, size_t* len) const { - *len = this->len_; - *buf = this->buf_; + *len = this->len_; + *buf = this->buf_; } private: @@ -103,8 +103,8 @@ class CECBytes { protected: std::vector str; CECBytes(const uint8_t val){ - str.push_back(val); - } + str.push_back(val); + } CECBytes(const uint8_t* buf, size_t len) { if(buf && len){ for(size_t i =0; i < len; i++){ @@ -194,13 +194,13 @@ class DeviceType : public CECBytes { enum { TV = 0x0, - RECORDING_DEVICE, - RESERVED, - TUNER, - PLAYBACK_DEVICE, - AUDIO_SYSTEM, - PURE_CEC_SWITCH, - VIDEO_PROCESSOR, + RECORDING_DEVICE, + RESERVED, + TUNER, + PLAYBACK_DEVICE, + AUDIO_SYSTEM, + PURE_CEC_SWITCH, + VIDEO_PROCESSOR, }; DeviceType(const CECFrame& frame, size_t startPos) @@ -314,13 +314,13 @@ class LogicalAddress : public CECBytes { LogicalAddress(int addr = UNREGISTERED) : CECBytes((uint8_t)addr){}; - int toInt() const + int toInt() const { return str[0]; } int getType(void) const { - static int _type[] = { + static int _type[] = { DeviceType::TV, DeviceType::RECORDING_DEVICE, DeviceType::RECORDING_DEVICE, @@ -339,14 +339,14 @@ class LogicalAddress : public CECBytes { DeviceType::RESERVED, }; return _type[str[0]]; - } + } }; class Version : public CECBytes { public: enum { V_1_4 = 0x05, - V_2_0 = 0x06 + V_2_0 = 0x06 }; Version(int version) @@ -788,15 +788,14 @@ class MessageDecoderImpl { class MessageDecoder { private: MessageProcessor& processor; +protected: + static MessageDecoderImpl* impl; -public: - MessageDecoderImpl* impl; - MessageDecoder(MessageProcessor& proc) - : processor(proc){}; - void decode(const CECFrame& in) { - return impl->decode(in); - } +public: + static void setImpl(MessageDecoderImpl* newImpl); + MessageDecoder(MessageProcessor& proc); + void decode(const CECFrame& in); }; class SetOSDName : public DataBlock { @@ -844,54 +843,23 @@ class ConnectionImpl { }; class Connection { -public: - ConnectionImpl* impl; - - Connection(const LogicalAddress& source = LogicalAddress::UNREGISTERED, bool opened = true, const std::string& name = "") {} - - static Connection& getInstance() { - static Connection instance; - return instance; - }; - - void open(void) { - return getInstance().impl->open(); - } - - void close(void) { - return getInstance().impl->close(); - } - - void addFrameListener(FrameListener* listener) { - return getInstance().impl->addFrameListener(listener); - } - - void ping(const LogicalAddress& from, const LogicalAddress& to, const Throw_e& doThrow) { - return getInstance().impl->ping(from, to, doThrow); - } - - void sendToAsync(const LogicalAddress& to, const CECFrame& frame) { - return getInstance().impl->sendToAsync(to, frame); - } - - void sendTo(const LogicalAddress& to, const CECFrame& frame) { - return getInstance().impl->sendTo(to, frame); - } - - void sendTo(const LogicalAddress& to, const CECFrame& frame, int timeout) { - return getInstance().impl->sendTo(to, frame, timeout); - } - - void poll(const LogicalAddress& from, const Throw_e& doThrow) { - return getInstance().impl->poll(from, doThrow); - } - - void sendAsync(const CECFrame &frame){ - return getInstance().impl->sendAsync(frame); - } +protected: + static ConnectionImpl* impl; - void setSource(LogicalAddress& from) { - } +public: + Connection(const LogicalAddress& source = LogicalAddress::UNREGISTERED, bool opened = true, const std::string& name = ""); + static Connection& getInstance(); + static void setImpl(ConnectionImpl* newImpl); + void open(); + void close(); + void addFrameListener(FrameListener* listener); + void ping(const LogicalAddress& from, const LogicalAddress& to, const Throw_e& doThrow); + void sendToAsync(const LogicalAddress& to, const CECFrame& frame); + void sendTo(const LogicalAddress& to, const CECFrame& frame); + void sendTo(const LogicalAddress& to, const CECFrame& frame, int timeout); + void poll(const LogicalAddress& from, const Throw_e& doThrow); + void sendAsync(const CECFrame& frame); + void setSource(LogicalAddress& from); }; class SystemAudioModeRequest : public DataBlock { @@ -919,38 +887,18 @@ class LibCCECImpl { }; class LibCCEC { +protected: + static LibCCECImpl* impl; public: - LibCCEC(void){}; - - static LibCCEC& getInstance(){ - static LibCCEC instance; - return instance; - }; - - LibCCECImpl* impl; - void init(const char* name){ - return impl->init(name); - } - - void init(){ - return impl->init(); - } - - void term(){ - return; - } - - void getPhysicalAddress(uint32_t* physicalAddress){ - return impl->getPhysicalAddress(physicalAddress); - } - - int addLogicalAddress(const LogicalAddress& source){ - return impl->addLogicalAddress(source); - } + static LibCCEC& getInstance(); + static void setImpl(LibCCECImpl* newImpl); - int getLogicalAddress(int devType){ - return impl->getLogicalAddress(devType); - } + void init(const char* name); + void init(); + void term(); + void getPhysicalAddress(uint32_t* physicalAddress); + int addLogicalAddress(const LogicalAddress& source); + int getLogicalAddress(int devType); }; class RequestArcInitiation : public DataBlock { @@ -976,7 +924,7 @@ class ReportArcTermination : public DataBlock { class RequestCurrentLatency : public DataBlock { public: - Op_t opCode(void) const {return REQUEST_CURRENT_LATENCY;} + Op_t opCode(void) const {return REQUEST_CURRENT_LATENCY;} RequestCurrentLatency(const PhysicalAddress &physicaladdres = {0xf,0xf,0xf,0xf} ): physicaladdress(physicaladdres) {} PhysicalAddress physicaladdress; }; @@ -995,29 +943,21 @@ class MessageEncoderImpl { }; class MessageEncoder { +protected: + static MessageEncoderImpl* impl; public: - MessageEncoderImpl* impl; - MessageEncoder(){}; - static MessageEncoder& getInstance() - { - static MessageEncoder instance; - return instance; - } - CECFrame& encode(const UserControlPressed m) - { - return getInstance().impl->encode(m); - } - CECFrame& encode(const DataBlock m) - { - return getInstance().impl->encode(m); - } + + static void setImpl(MessageEncoderImpl* newImpl); + + CECFrame& encode(const UserControlPressed m); + CECFrame& encode(const DataBlock m); }; class IOException : public Exception { - public: - virtual const char* what() const throw() - { - return "IO Exception.."; - } + public: + virtual const char* what() const throw() + { + return "IO Exception.."; + } }; diff --git a/Tests/mocks/Iarm.cpp b/Tests/mocks/Iarm.cpp new file mode 100755 index 0000000000..63afa6f610 --- /dev/null +++ b/Tests/mocks/Iarm.cpp @@ -0,0 +1,104 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "Iarm.h" +#include + +IarmBusImpl* IarmBus::impl = nullptr; + +IarmBus::IarmBus() {} + +void IarmBus::setImpl(IarmBusImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +IARM_Result_t IarmBus::IARM_Bus_Init(const char* name) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_Init(name); +} + +IARM_Result_t IarmBus::IARM_Bus_Connect() +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_Connect(); +} + +IARM_Result_t IarmBus::IARM_Bus_IsConnected(const char* memberName, int* isRegistered) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_IsConnected(memberName, isRegistered); +} + +IARM_Result_t IarmBus::IARM_Bus_RegisterEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_RegisterEventHandler(ownerName, eventId, handler); +} + +IARM_Result_t IarmBus::IARM_Bus_UnRegisterEventHandler(const char* ownerName, IARM_EventId_t eventId) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_UnRegisterEventHandler(ownerName, eventId); +} + +IARM_Result_t IarmBus::IARM_Bus_RemoveEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_RemoveEventHandler(ownerName, eventId, handler); +} + +IARM_Result_t IarmBus::IARM_Bus_Call(const char* ownerName, const char* methodName, void* arg, size_t argLen) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_Call(ownerName, methodName, arg, argLen); +} + +IARM_Result_t IarmBus::IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_BroadcastEvent(ownerName, eventId, arg, argLen); +} + + +IARM_Result_t IarmBus::IARM_Bus_RegisterCall(const char* methodName, IARM_BusCall_t handler) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_RegisterCall(methodName, handler); +} + +IARM_Result_t IarmBus::IARM_Bus_Call_with_IPCTimeout(const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_Call_with_IPCTimeout(ownerName, methodName, arg, argLen, timeout); +} + +IARM_Result_t (*IARM_Bus_Init)(const char*) = &IarmBus::IARM_Bus_Init; +IARM_Result_t (*IARM_Bus_Connect)() = &IarmBus::IARM_Bus_Connect; +IARM_Result_t (*IARM_Bus_IsConnected)(const char*,int*) = &IarmBus::IARM_Bus_IsConnected; +IARM_Result_t (*IARM_Bus_RegisterEventHandler)(const char*,IARM_EventId_t,IARM_EventHandler_t) = &IarmBus::IARM_Bus_RegisterEventHandler; +IARM_Result_t (*IARM_Bus_UnRegisterEventHandler)(const char*,IARM_EventId_t) = &IarmBus::IARM_Bus_UnRegisterEventHandler; +IARM_Result_t (*IARM_Bus_RemoveEventHandler)(const char*,IARM_EventId_t,IARM_EventHandler_t) = &IarmBus::IARM_Bus_RemoveEventHandler; +IARM_Result_t (*IARM_Bus_Call)(const char*,const char*,void*,size_t) = &IarmBus::IARM_Bus_Call; +IARM_Result_t (*IARM_Bus_BroadcastEvent)(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) = &IarmBus::IARM_Bus_BroadcastEvent; +IARM_Result_t (*IARM_Bus_RegisterCall)(const char*,IARM_BusCall_t) = &IarmBus::IARM_Bus_RegisterCall; +IARM_Result_t (*IARM_Bus_Call_with_IPCTimeout)(const char*,const char*,void*,size_t,int) = &IarmBus::IARM_Bus_Call_with_IPCTimeout; diff --git a/Tests/mocks/Iarm.h b/Tests/mocks/Iarm.h index b8dfe13878..724515f3da 100644 --- a/Tests/mocks/Iarm.h +++ b/Tests/mocks/Iarm.h @@ -28,82 +28,41 @@ class IarmBusImpl { virtual IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char* ownerName, IARM_EventId_t eventId) = 0; virtual IARM_Result_t IARM_Bus_RemoveEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) = 0; virtual IARM_Result_t IARM_Bus_Call(const char* ownerName, const char* methodName, void* arg, size_t argLen) = 0; - virtual IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) = 0; + virtual IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) = 0; virtual IARM_Result_t IARM_Bus_RegisterCall(const char* methodName, IARM_BusCall_t handler) = 0; virtual IARM_Result_t IARM_Bus_Call_with_IPCTimeout(const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout) = 0; }; class IarmBus { +protected: + static IarmBusImpl* impl; public: - static IarmBus& getInstance() - { - static IarmBus instance; - return instance; - } - - IarmBusImpl* impl; - - static IARM_Result_t IARM_Bus_Init(const char* name) - { - return getInstance().impl->IARM_Bus_Init(name); - } - - static IARM_Result_t IARM_Bus_Connect() - { - return getInstance().impl->IARM_Bus_Connect(); - } - - static IARM_Result_t IARM_Bus_IsConnected(const char* memberName, int* isRegistered) - { - return getInstance().impl->IARM_Bus_IsConnected(memberName, isRegistered); - } - - static IARM_Result_t IARM_Bus_RegisterEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) - { - return getInstance().impl->IARM_Bus_RegisterEventHandler(ownerName, eventId, handler); - } - - static IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char* ownerName, IARM_EventId_t eventId) - { - return getInstance().impl->IARM_Bus_UnRegisterEventHandler(ownerName, eventId); - } - - static IARM_Result_t IARM_Bus_RemoveEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) - { - return getInstance().impl->IARM_Bus_RemoveEventHandler(ownerName, eventId, handler); - } - - static IARM_Result_t IARM_Bus_Call(const char* ownerName, const char* methodName, void* arg, size_t argLen) - { - return getInstance().impl->IARM_Bus_Call(ownerName, methodName, arg, argLen); - } - - static IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) - { - return getInstance().impl->IARM_Bus_BroadcastEvent(ownerName, eventId, arg, argLen); - } - - static IARM_Result_t IARM_Bus_RegisterCall(const char* methodName, IARM_BusCall_t handler) - { - return getInstance().impl->IARM_Bus_RegisterCall(methodName, handler); - } - - static IARM_Result_t IARM_Bus_Call_with_IPCTimeout(const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout) - { - return getInstance().impl->IARM_Bus_Call_with_IPCTimeout(ownerName, methodName, arg, argLen, timeout); - } + IarmBus(); + IarmBus(const IarmBus &obj) = delete; // deleted copy constructor so that copy of the instance cannot be created. + static void setImpl(IarmBusImpl* newImpl); + static IARM_Result_t IARM_Bus_Init(const char* name); + static IARM_Result_t IARM_Bus_Connect(); + static IARM_Result_t IARM_Bus_IsConnected(const char* memberName, int* isRegistered); + static IARM_Result_t IARM_Bus_RegisterEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler); + static IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char* ownerName, IARM_EventId_t eventId); + static IARM_Result_t IARM_Bus_RemoveEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler); + static IARM_Result_t IARM_Bus_Call(const char* ownerName, const char* methodName, void* arg, size_t argLen); + static IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) ; + + static IARM_Result_t IARM_Bus_RegisterCall(const char* methodName, IARM_BusCall_t handler); + static IARM_Result_t IARM_Bus_Call_with_IPCTimeout(const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout); }; -constexpr auto IARM_Bus_Init = &IarmBus::IARM_Bus_Init; -constexpr auto IARM_Bus_Connect = &IarmBus::IARM_Bus_Connect; -constexpr auto IARM_Bus_IsConnected = &IarmBus::IARM_Bus_IsConnected; -constexpr auto IARM_Bus_RegisterEventHandler = &IarmBus::IARM_Bus_RegisterEventHandler; -constexpr auto IARM_Bus_UnRegisterEventHandler = &IarmBus::IARM_Bus_UnRegisterEventHandler; -constexpr auto IARM_Bus_RemoveEventHandler = &IarmBus::IARM_Bus_RemoveEventHandler; -constexpr auto IARM_Bus_Call = &IarmBus::IARM_Bus_Call; -constexpr auto IARM_Bus_BroadcastEvent = &IarmBus::IARM_Bus_BroadcastEvent; -constexpr auto IARM_Bus_RegisterCall = &IarmBus::IARM_Bus_RegisterCall; -constexpr auto IARM_Bus_Call_with_IPCTimeout = &IarmBus::IARM_Bus_Call_with_IPCTimeout; +extern IARM_Result_t (*IARM_Bus_Init)(const char*); +extern IARM_Result_t (*IARM_Bus_Connect)(); +extern IARM_Result_t (*IARM_Bus_IsConnected)(const char*,int*); +extern IARM_Result_t (*IARM_Bus_RegisterEventHandler)(const char*,IARM_EventId_t,IARM_EventHandler_t); +extern IARM_Result_t (*IARM_Bus_UnRegisterEventHandler)(const char*,IARM_EventId_t); +extern IARM_Result_t (*IARM_Bus_RemoveEventHandler)(const char*,IARM_EventId_t,IARM_EventHandler_t); +extern IARM_Result_t (*IARM_Bus_Call)(const char*,const char*,void*,size_t); +extern IARM_Result_t (*IARM_Bus_BroadcastEvent)(const char *,IARM_EventId_t,void *,size_t); +extern IARM_Result_t (*IARM_Bus_RegisterCall)(const char*,IARM_BusCall_t); +extern IARM_Result_t (*IARM_Bus_Call_with_IPCTimeout)(const char*,const char*,void*,size_t,int); #define IARM_BUS_COMMON_API_SysModeChange "SysModeChange" diff --git a/Tests/mocks/IarmBusMock.h b/Tests/mocks/IarmBusMock.h index b8a0c41644..61d1c51367 100644 --- a/Tests/mocks/IarmBusMock.h +++ b/Tests/mocks/IarmBusMock.h @@ -43,6 +43,6 @@ class IarmBusImplMock : public IarmBusImpl { MOCK_METHOD(IARM_Result_t, IARM_Bus_RemoveEventHandler, (const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler), (override)); MOCK_METHOD(IARM_Result_t, IARM_Bus_Call, (const char* ownerName, const char* methodName, void* arg, size_t argLen), (override)); MOCK_METHOD(IARM_Result_t, IARM_Bus_RegisterCall, (const char* methodName, IARM_BusCall_t handler), (override)); - MOCK_METHOD(IARM_Result_t, IARM_Bus_BroadcastEvent, (const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_BroadcastEvent, (const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen), (override)); MOCK_METHOD(IARM_Result_t, IARM_Bus_Call_with_IPCTimeout, (const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout), (override)); }; diff --git a/Tests/mocks/MotionDetection.cpp b/Tests/mocks/MotionDetection.cpp new file mode 100755 index 0000000000..a62f768dc8 --- /dev/null +++ b/Tests/mocks/MotionDetection.cpp @@ -0,0 +1,124 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "MotionDetection.h" +#include + +MotionDetectionImpl* MotionDetection::impl = nullptr; + +MotionDetection::MotionDetection() {} + +void MotionDetection::setImpl(MotionDetectionImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_Platform_Init() +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_Platform_Init(); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_Platform_Term() +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_Platform_Term(); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_RegisterEventCallback(MOTION_DETECTION_OnMotionEventCallback motionEvent) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_RegisterEventCallback(motionEvent); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_GetMotionDetectors(MOTION_DETECTION_CurrentSensorSettings_t* motionDetectors) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_GetMotionDetectors(motionDetectors); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_ArmMotionDetector(MOTION_DETECTION_Mode_t mode, std::string index) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_ArmMotionDetector(mode, index); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_DisarmMotionDetector(std::string index) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_DisarmMotionDetector(index); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_IsMotionDetectorArmed(std::string index, bool* armState) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_IsMotionDetectorArmed(index, armState); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_SetNoMotionPeriod(std::string index, int period) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_SetNoMotionPeriod(index, period); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_GetNoMotionPeriod(std::string index, unsigned int* period) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_GetNoMotionPeriod(index, period); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_SetSensitivity(std::string index, std::string sensitivity, int inferredMode ) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_SetSensitivity(index, sensitivity, inferredMode); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_GetSensitivity(std::string index, char** sensitivity, int* currentMode) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_GetSensitivity(index, sensitivity, currentMode); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_SetActivePeriod(std::string index, MOTION_DETECTION_TimeRange_t timeSet) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_SetActivePeriod(index, timeSet); +} + +MOTION_DETECTION_Result_t MotionDetection::MOTION_DETECTION_GetActivePeriod(MOTION_DETECTION_TimeRange_t* timeSet) +{ + EXPECT_NE(impl, nullptr); + return impl->MOTION_DETECTION_GetActivePeriod(timeSet); +} + +MOTION_DETECTION_Result_t(*MOTION_DETECTION_Platform_Init)() = &MotionDetection::MOTION_DETECTION_Platform_Init; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_Platform_Term)() = &MotionDetection::MOTION_DETECTION_Platform_Term; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_RegisterEventCallback)(MOTION_DETECTION_OnMotionEventCallback) = &MotionDetection::MOTION_DETECTION_RegisterEventCallback; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_GetMotionDetectors)(MOTION_DETECTION_CurrentSensorSettings_t*) = &MotionDetection::MOTION_DETECTION_GetMotionDetectors; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_ArmMotionDetector)(MOTION_DETECTION_Mode_t, std::string) = &MotionDetection::MOTION_DETECTION_ArmMotionDetector; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_DisarmMotionDetector)(std::string) = &MotionDetection::MOTION_DETECTION_DisarmMotionDetector; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_IsMotionDetectorArmed)(std::string, bool*) = &MotionDetection::MOTION_DETECTION_IsMotionDetectorArmed; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_SetNoMotionPeriod)(std::string, int) = &MotionDetection::MOTION_DETECTION_SetNoMotionPeriod; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_GetNoMotionPeriod)(std::string, unsigned int*) = &MotionDetection::MOTION_DETECTION_GetNoMotionPeriod; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_SetSensitivity)(std::string, std::string, int) = &MotionDetection::MOTION_DETECTION_SetSensitivity; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_GetSensitivity)(std::string, char**, int*) = &MotionDetection::MOTION_DETECTION_GetSensitivity; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_SetActivePeriod)(std::string, MOTION_DETECTION_TimeRange_t) = &MotionDetection::MOTION_DETECTION_SetActivePeriod; +MOTION_DETECTION_Result_t(*MOTION_DETECTION_GetActivePeriod)(MOTION_DETECTION_TimeRange_t*) = &MotionDetection::MOTION_DETECTION_GetActivePeriod; diff --git a/Tests/mocks/MotionDetection.h b/Tests/mocks/MotionDetection.h index 2b549fa2c7..fc0773977d 100644 --- a/Tests/mocks/MotionDetection.h +++ b/Tests/mocks/MotionDetection.h @@ -96,93 +96,39 @@ class MotionDetectionImpl { }; class MotionDetection { +protected: + static MotionDetectionImpl* impl; public: - static MotionDetection& getInstance() - { - static MotionDetection instance; - return instance; - } - - MotionDetectionImpl* impl; - - static MOTION_DETECTION_Result_t MOTION_DETECTION_Platform_Init() - { - return getInstance().impl->MOTION_DETECTION_Platform_Init(); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_Platform_Term() - { - return getInstance().impl->MOTION_DETECTION_Platform_Term(); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_RegisterEventCallback(MOTION_DETECTION_OnMotionEventCallback motionEvent) - { - return getInstance().impl->MOTION_DETECTION_RegisterEventCallback(motionEvent); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_GetMotionDetectors(MOTION_DETECTION_CurrentSensorSettings_t* motionDetectors) - { - return getInstance().impl->MOTION_DETECTION_GetMotionDetectors(motionDetectors); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_ArmMotionDetector(MOTION_DETECTION_Mode_t mode, std::string index) - { - return getInstance().impl->MOTION_DETECTION_ArmMotionDetector(mode, index); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_DisarmMotionDetector(std::string index) - { - return getInstance().impl->MOTION_DETECTION_DisarmMotionDetector(index); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_IsMotionDetectorArmed(std::string index, bool* armState) - { - return getInstance().impl->MOTION_DETECTION_IsMotionDetectorArmed(index, armState); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_SetNoMotionPeriod(std::string index, int period) - { - return getInstance().impl->MOTION_DETECTION_SetNoMotionPeriod(index, period); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_GetNoMotionPeriod(std::string index, unsigned int* period) - { - return getInstance().impl->MOTION_DETECTION_GetNoMotionPeriod(index, period); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_SetSensitivity(std::string index, std::string sensitivity, int inferredMode ) - { - return getInstance().impl->MOTION_DETECTION_SetSensitivity(index, sensitivity, inferredMode); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_GetSensitivity(std::string index, char** sensitivity, int* currentMode) - { - return getInstance().impl->MOTION_DETECTION_GetSensitivity(index, sensitivity, currentMode); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_SetActivePeriod(std::string index, MOTION_DETECTION_TimeRange_t timeSet) - { - return getInstance().impl->MOTION_DETECTION_SetActivePeriod(index, timeSet); - } - - static MOTION_DETECTION_Result_t MOTION_DETECTION_GetActivePeriod(MOTION_DETECTION_TimeRange_t* timeSet) - { - return getInstance().impl->MOTION_DETECTION_GetActivePeriod(timeSet); - } + MotionDetection(); + MotionDetection(const MotionDetection &obj) = delete; + static void setImpl(MotionDetectionImpl* newImpl); + static MOTION_DETECTION_Result_t MOTION_DETECTION_Platform_Init(); + static MOTION_DETECTION_Result_t MOTION_DETECTION_Platform_Term(); + static MOTION_DETECTION_Result_t MOTION_DETECTION_RegisterEventCallback(MOTION_DETECTION_OnMotionEventCallback motionEvent); + static MOTION_DETECTION_Result_t MOTION_DETECTION_GetMotionDetectors(MOTION_DETECTION_CurrentSensorSettings_t* motionDetectors); + static MOTION_DETECTION_Result_t MOTION_DETECTION_ArmMotionDetector(MOTION_DETECTION_Mode_t mode, std::string index); + static MOTION_DETECTION_Result_t MOTION_DETECTION_DisarmMotionDetector(std::string index); + static MOTION_DETECTION_Result_t MOTION_DETECTION_IsMotionDetectorArmed(std::string index, bool* armState); + static MOTION_DETECTION_Result_t MOTION_DETECTION_SetNoMotionPeriod(std::string index, int period); + static MOTION_DETECTION_Result_t MOTION_DETECTION_GetNoMotionPeriod(std::string index, unsigned int* period); + static MOTION_DETECTION_Result_t MOTION_DETECTION_SetSensitivity(std::string index, std::string sensitivity, int inferredMode ); + static MOTION_DETECTION_Result_t MOTION_DETECTION_GetSensitivity(std::string index, char** sensitivity, int* currentMode); + static MOTION_DETECTION_Result_t MOTION_DETECTION_SetActivePeriod(std::string index, MOTION_DETECTION_TimeRange_t timeSet); + static MOTION_DETECTION_Result_t MOTION_DETECTION_GetActivePeriod(MOTION_DETECTION_TimeRange_t* timeSet); }; - -constexpr auto MOTION_DETECTION_Platform_Init = &MotionDetection::MOTION_DETECTION_Platform_Init; -constexpr auto MOTION_DETECTION_Platform_Term = &MotionDetection::MOTION_DETECTION_Platform_Term; -constexpr auto MOTION_DETECTION_RegisterEventCallback = &MotionDetection::MOTION_DETECTION_RegisterEventCallback; -constexpr auto MOTION_DETECTION_GetMotionDetectors = &MotionDetection::MOTION_DETECTION_GetMotionDetectors; -constexpr auto MOTION_DETECTION_ArmMotionDetector = &MotionDetection::MOTION_DETECTION_ArmMotionDetector; -constexpr auto MOTION_DETECTION_DisarmMotionDetector = &MotionDetection::MOTION_DETECTION_DisarmMotionDetector; -constexpr auto MOTION_DETECTION_IsMotionDetectorArmed = &MotionDetection::MOTION_DETECTION_IsMotionDetectorArmed; -constexpr auto MOTION_DETECTION_SetNoMotionPeriod = &MotionDetection::MOTION_DETECTION_SetNoMotionPeriod; -constexpr auto MOTION_DETECTION_GetNoMotionPeriod = &MotionDetection::MOTION_DETECTION_GetNoMotionPeriod; -constexpr auto MOTION_DETECTION_SetSensitivity = &MotionDetection::MOTION_DETECTION_SetSensitivity; -constexpr auto MOTION_DETECTION_GetSensitivity = &MotionDetection::MOTION_DETECTION_GetSensitivity; -constexpr auto MOTION_DETECTION_SetActivePeriod = &MotionDetection::MOTION_DETECTION_SetActivePeriod; -constexpr auto MOTION_DETECTION_GetActivePeriod = &MotionDetection::MOTION_DETECTION_GetActivePeriod; +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_Platform_Init)(); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_Platform_Init)(); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_Platform_Term)(); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_RegisterEventCallback)(MOTION_DETECTION_OnMotionEventCallback motionEvent); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_GetMotionDetectors)(MOTION_DETECTION_CurrentSensorSettings_t* motionDetectors); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_ArmMotionDetector)(MOTION_DETECTION_Mode_t mode, std::string index); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_DisarmMotionDetector)(std::string index); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_IsMotionDetectorArmed)(std::string index, bool* armState); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_SetNoMotionPeriod)(std::string index, int period); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_GetNoMotionPeriod)(std::string index, unsigned int* period); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_SetSensitivity)(std::string, std::string, int); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_GetSensitivity)(std::string, char**, int*); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_SetActivePeriod)(std::string, MOTION_DETECTION_TimeRange_t); +extern MOTION_DETECTION_Result_t(*MOTION_DETECTION_GetActivePeriod)(MOTION_DETECTION_TimeRange_t*); diff --git a/Tests/mocks/RBus.cpp b/Tests/mocks/RBus.cpp new file mode 100755 index 0000000000..9399a556bd --- /dev/null +++ b/Tests/mocks/RBus.cpp @@ -0,0 +1,67 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "RBus.h" +#include + +RBusApiImpl* RBusApi::impl = nullptr; + +RBusApi::RBusApi() {} + +void RBusApi::setImpl(RBusApiImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +rbusError_t RBusApi::rbus_open(rbusHandle_t* handle, char const* componentName) +{ + EXPECT_NE(impl, nullptr); + return impl->rbus_open(handle, componentName); +} + +rbusError_t RBusApi::rbusMethod_InvokeAsync(rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) +{ + EXPECT_NE(impl, nullptr); + return impl->rbusMethod_InvokeAsync(handle, methodName, inParams, callback, timeout); +} + +rbusValue_t RBusApi::rbusObject_GetValue(rbusObject_t object, char const* name) +{ + EXPECT_NE(impl, nullptr); + return impl->rbusObject_GetValue(object, name); +} + +char const* RBusApi::rbusValue_GetString(rbusValue_t value, int* len) +{ + EXPECT_NE(impl, nullptr); + return impl->rbusValue_GetString(value, len); +} + +rbusError_t RBusApi::rbus_close(rbusHandle_t handle) +{ + EXPECT_NE(impl, nullptr); + return impl->rbus_close(handle); +} +rbusError_t (*rbus_open)(rbusHandle_t*,char const* ) = &RBusApi::rbus_open; +rbusError_t (*rbusMethod_InvokeAsync)(rbusHandle_t,char const*, rbusObject_t,rbusMethodAsyncRespHandler_t,int)= &RBusApi::rbusMethod_InvokeAsync; +rbusValue_t (*rbusObject_GetValue)(rbusObject_t,char const*) = &RBusApi::rbusObject_GetValue; +char const* (*rbusValue_GetString)(rbusValue_t,int*) = &RBusApi::rbusValue_GetString; +rbusError_t (*rbus_close)(rbusHandle_t) = &RBusApi::rbus_close; diff --git a/Tests/mocks/RBus.h b/Tests/mocks/RBus.h index c3f498a735..2b6ac48b3c 100644 --- a/Tests/mocks/RBus.h +++ b/Tests/mocks/RBus.h @@ -38,43 +38,24 @@ class RBusApiImpl { }; class RBusApi { -public: - static RBusApi& getInstance() - { - static RBusApi instance; - return instance; - } - - RBusApiImpl* impl; - - static rbusError_t rbus_open(rbusHandle_t* handle, char const* componentName) - { - return getInstance().impl->rbus_open(handle, componentName); - } - - static rbusError_t rbusMethod_InvokeAsync(rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout) - { - return getInstance().impl->rbusMethod_InvokeAsync(handle, methodName, inParams, callback, timeout); - } +protected: + static RBusApiImpl* impl; - static rbusValue_t rbusObject_GetValue(rbusObject_t object, char const* name) - { - return getInstance().impl->rbusObject_GetValue(object, name); - } - - static char const* rbusValue_GetString(rbusValue_t value, int* len) - { - return getInstance().impl->rbusValue_GetString(value, len); - } +public: - static rbusError_t rbus_close(rbusHandle_t handle) - { - return getInstance().impl->rbus_close(handle); - } + RBusApi(); + RBusApi(const RBusApi &obj) = delete; + static void setImpl(RBusApiImpl* newImpl); + static rbusError_t rbus_open(rbusHandle_t* handle, char const* componentName); + static rbusError_t rbusMethod_InvokeAsync(rbusHandle_t handle, char const* methodName, rbusObject_t inParams, rbusMethodAsyncRespHandler_t callback, int timeout); + static rbusValue_t rbusObject_GetValue(rbusObject_t object, char const* name); + static char const* rbusValue_GetString(rbusValue_t value, int* len); + static rbusError_t rbus_close(rbusHandle_t handle); }; -constexpr auto rbus_open = &RBusApi::rbus_open; -constexpr auto rbusMethod_InvokeAsync = &RBusApi::rbusMethod_InvokeAsync; -constexpr auto rbusObject_GetValue = &RBusApi::rbusObject_GetValue; -constexpr auto rbusValue_GetString = &RBusApi::rbusValue_GetString; -constexpr auto rbus_close = &RBusApi::rbus_close; +extern rbusError_t (*rbus_open)(rbusHandle_t*,char const* ); +extern rbusError_t (*rbusMethod_InvokeAsync)(rbusHandle_t,char const*, rbusObject_t,rbusMethodAsyncRespHandler_t,int); +extern rbusValue_t (*rbusObject_GetValue)(rbusObject_t,char const*); +extern char const* (*rbusValue_GetString)(rbusValue_t,int*); +extern rbusError_t (*rbus_close)(rbusHandle_t); + diff --git a/Tests/mocks/Rfc.cpp b/Tests/mocks/Rfc.cpp new file mode 100755 index 0000000000..2dc46103bf --- /dev/null +++ b/Tests/mocks/Rfc.cpp @@ -0,0 +1,54 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "Rfc.h" +#include + +RfcApiImpl* RfcApi::impl = nullptr; + +RfcApi::RfcApi() {} + +void RfcApi::setImpl(RfcApiImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +WDMP_STATUS RfcApi::getRFCParameter(char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) +{ + EXPECT_NE(impl, nullptr); + return impl->getRFCParameter(pcCallerID, pcParameterName, pstParamData); +} + +WDMP_STATUS RfcApi::setRFCParameter(char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) +{ + EXPECT_NE(impl, nullptr); + return impl->setRFCParameter(pcCallerID, pcParameterName, pcParameterValue, eDataType); +} + +const char* RfcApi::getRFCErrorString(WDMP_STATUS code) +{ + EXPECT_NE(impl, nullptr); + return impl->getRFCErrorString(code); +} + +WDMP_STATUS (*getRFCParameter)(char*,const char*,RFC_ParamData_t*) = &RfcApi::getRFCParameter; +WDMP_STATUS (*setRFCParameter)(char*,const char*,const char*,DATA_TYPE) = &RfcApi::setRFCParameter; +const char* (*getRFCErrorString)(WDMP_STATUS) = &RfcApi::getRFCErrorString; diff --git a/Tests/mocks/Rfc.h b/Tests/mocks/Rfc.h index 92b6d26c78..45bd4d0afe 100644 --- a/Tests/mocks/Rfc.h +++ b/Tests/mocks/Rfc.h @@ -76,31 +76,20 @@ class RfcApiImpl { }; class RfcApi { -public: - static RfcApi& getInstance() - { - static RfcApi instance; - return instance; - } - - RfcApiImpl* impl; - - static WDMP_STATUS getRFCParameter(char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) - { - return getInstance().impl->getRFCParameter(pcCallerID, pcParameterName, pstParamData); - } - static WDMP_STATUS setRFCParameter(char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) - { - return getInstance().impl->setRFCParameter(pcCallerID, pcParameterName, pcParameterValue, eDataType); - } +protected: + static RfcApiImpl* impl; - static const char* getRFCErrorString(WDMP_STATUS code) - { - return getInstance().impl->getRFCErrorString(code); - } +public: + RfcApi(); + RfcApi(const RfcApi &obj) = delete; // deleted copy constructor so that copy of the instance cannot be created. + static void setImpl(RfcApiImpl* newImpl); + static WDMP_STATUS getRFCParameter(char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData); + static WDMP_STATUS setRFCParameter(char* pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType); + static const char* getRFCErrorString(WDMP_STATUS code); }; -constexpr auto getRFCParameter = &RfcApi::getRFCParameter; -constexpr auto setRFCParameter = &RfcApi::setRFCParameter; -constexpr auto getRFCErrorString = &RfcApi::getRFCErrorString; +extern WDMP_STATUS (*getRFCParameter)(char*,const char*,RFC_ParamData_t*); +extern WDMP_STATUS (*setRFCParameter)(char*,const char*,const char*,DATA_TYPE); +extern const char* (*getRFCErrorString)(WDMP_STATUS); + diff --git a/Tests/mocks/Telemetry.cpp b/Tests/mocks/Telemetry.cpp new file mode 100755 index 0000000000..3900fccd46 --- /dev/null +++ b/Tests/mocks/Telemetry.cpp @@ -0,0 +1,46 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "Telemetry.h" +#include + +TelemetryApiImpl* TelemetryApi::impl = nullptr; + +TelemetryApi::TelemetryApi() {} + +void TelemetryApi::setImpl(TelemetryApiImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +void TelemetryApi::t2_init(char* component) +{ + EXPECT_NE(impl, nullptr); + impl->t2_init(component); +} + +T2ERROR TelemetryApi::t2_event_s(char* marker, char* value) +{ + EXPECT_NE(impl, nullptr); + return impl->t2_event_s(marker, value); +} +void (*t2_init)(char*) = &TelemetryApi::t2_init; +T2ERROR (*t2_event_s)(char*,char*) = &TelemetryApi::t2_event_s; diff --git a/Tests/mocks/Telemetry.h b/Tests/mocks/Telemetry.h index f9ba3d2da1..59af9dc3d6 100644 --- a/Tests/mocks/Telemetry.h +++ b/Tests/mocks/Telemetry.h @@ -21,25 +21,16 @@ class TelemetryApiImpl { }; class TelemetryApi { +protected: + static TelemetryApiImpl* impl; public: - TelemetryApiImpl* impl; - - static TelemetryApi& getInstance() - { - static TelemetryApi instance; - return instance; - } - - static void t2_init(char* component) - { - getInstance().impl->t2_init(component); - } - - static T2ERROR t2_event_s(char* marker, char* value) - { - return getInstance().impl->t2_event_s(marker, value); - } + TelemetryApi(); + TelemetryApi(const TelemetryApi &obj) = delete; + static void setImpl(TelemetryApiImpl* newImpl); + static void t2_init(char* component); + static T2ERROR t2_event_s(char* marker, char* value); }; -constexpr auto t2_init = &TelemetryApi::t2_init; -constexpr auto t2_event_s = &TelemetryApi::t2_event_s; +extern void (*t2_init)(char*); +extern T2ERROR (*t2_event_s)(char*,char*); + diff --git a/Tests/mocks/Udev.cpp b/Tests/mocks/Udev.cpp new file mode 100755 index 0000000000..a6b8638b5b --- /dev/null +++ b/Tests/mocks/Udev.cpp @@ -0,0 +1,124 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "Udev.h" +#include + +UdevImpl* Udev::impl = nullptr; + +Udev::Udev() {} + + void Udev::setImpl(UdevImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +struct udev* Udev::udev_new() +{ + EXPECT_NE(impl, nullptr); + return impl->udev_new(); +} + +udev_enumerate* Udev::udev_enumerate_new(struct udev* udev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_new(udev); +} + +void Udev::udev_enumerate_add_match_subsystem(struct udev_enumerate* enumerate, const char* subsystem) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_add_match_subsystem(enumerate, subsystem); +} + +void Udev::udev_enumerate_scan_devices(struct udev_enumerate* enumerate) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_scan_devices(enumerate); +} + +struct udev_list_entry* Udev::udev_enumerate_get_list_entry(struct udev_enumerate* enumerate) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_get_list_entry(enumerate); +} + +void Udev::udev_enumerate_unref(struct udev_enumerate* enumerate) + { + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_unref(enumerate); +} + +void Udev::udev_unref(struct udev* udev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_unref(udev); +} + +const char* Udev::udev_list_entry_get_name(struct udev_list_entry* entry) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_list_entry_get_name(entry); +} + +struct udev_device* Udev::udev_device_new_from_syspath(struct udev* udev, const char* path) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_new_from_syspath(udev, path); +} + +void Udev::udev_device_unref(struct udev_device* dev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_unref(dev); +} + +struct udev_device* Udev::udev_device_get_parent_with_subsystem_devtype(struct udev_device* dev, const char* subsystem, const char* devtype) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_get_parent_with_subsystem_devtype(dev, subsystem, devtype); +} + +const char* Udev::udev_device_get_devtype(struct udev_device* dev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_get_devtype(dev); +} + +const char* Udev::udev_device_get_devnode(struct udev_device* dev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_get_devnode(dev); +} + +struct udev* (*udev_new)() = &Udev::udev_new; +udev_enumerate* (*udev_enumerate_new)(struct udev*) = &Udev::udev_enumerate_new; +void (*udev_enumerate_add_match_subsystem)(struct udev_enumerate*, const char*) = &Udev::udev_enumerate_add_match_subsystem; +void (*udev_enumerate_scan_devices)(struct udev_enumerate*) = &Udev::udev_enumerate_scan_devices; +struct udev_list_entry* (*udev_enumerate_get_list_entry)(struct udev_enumerate*) = &Udev::udev_enumerate_get_list_entry; +void (*udev_enumerate_unref)(struct udev_enumerate*) = &Udev::udev_enumerate_unref; +void (*udev_unref)(struct udev*) = &Udev::udev_unref; +const char* (*udev_list_entry_get_name)(struct udev_list_entry*) = &Udev::udev_list_entry_get_name; +struct udev_device* (*udev_device_new_from_syspath)(struct udev*, const char*) = &Udev::udev_device_new_from_syspath; +void (*udev_device_unref)(struct udev_device*) = &Udev::udev_device_unref; +struct udev_device* (*udev_device_get_parent_with_subsystem_devtype)(struct udev_device*, const char*, const char*) = &Udev::udev_device_get_parent_with_subsystem_devtype; +const char* (*udev_device_get_devtype)(struct udev_device*) = &Udev::udev_device_get_devtype; +const char* (*udev_device_get_devnode)(struct udev_device*) = &Udev::udev_device_get_devnode; diff --git a/Tests/mocks/Udev.h b/Tests/mocks/Udev.h index 4f97aff6e3..a9681734be 100644 --- a/Tests/mocks/Udev.h +++ b/Tests/mocks/Udev.h @@ -32,94 +32,40 @@ class UdevImpl { }; class Udev { +protected: + static UdevImpl* impl; public: - static Udev& getInstance() - { - static Udev instance; - return instance; - } - - UdevImpl* impl; - - static struct udev* udev_new() - { - return getInstance().impl->udev_new(); - } - - static udev_enumerate* udev_enumerate_new(struct udev* udev) - { - return getInstance().impl->udev_enumerate_new(udev); - } - - static void udev_enumerate_add_match_subsystem(struct udev_enumerate* enumerate, const char* subsystem) - { - return getInstance().impl->udev_enumerate_add_match_subsystem(enumerate, subsystem); - } - - static void udev_enumerate_scan_devices(struct udev_enumerate* enumerate) - { - return getInstance().impl->udev_enumerate_scan_devices(enumerate); - } - - static struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate* enumerate) - { - return getInstance().impl->udev_enumerate_get_list_entry(enumerate); - } - - static void udev_enumerate_unref(struct udev_enumerate* enumerate) - { - return getInstance().impl->udev_enumerate_unref(enumerate); - } - - static void udev_unref(struct udev* udev) - { - return getInstance().impl->udev_unref(udev); - } - - static const char* udev_list_entry_get_name(struct udev_list_entry* entry) - { - return getInstance().impl->udev_list_entry_get_name(entry); - } - - static struct udev_device* udev_device_new_from_syspath(struct udev* udev, const char* path) - { - return getInstance().impl->udev_device_new_from_syspath(udev, path); - } - - static void udev_device_unref(struct udev_device* dev) - { - return getInstance().impl->udev_device_unref(dev); - } - - static struct udev_device* udev_device_get_parent_with_subsystem_devtype(struct udev_device* dev, const char* subsystem, const char* devtype) - { - return getInstance().impl->udev_device_get_parent_with_subsystem_devtype(dev, subsystem, devtype); - } - - static const char* udev_device_get_devtype(struct udev_device* dev) - { - return getInstance().impl->udev_device_get_devtype(dev); - } - - static const char* udev_device_get_devnode(struct udev_device* dev) - { - return getInstance().impl->udev_device_get_devnode(dev); - } + Udev(); + Udev(const Udev &obj) = delete; + static void setImpl(UdevImpl* newImpl); + static struct udev* udev_new(); + static udev_enumerate* udev_enumerate_new(struct udev* udev); + static void udev_enumerate_add_match_subsystem(struct udev_enumerate* enumerate, const char* subsystem); + static void udev_enumerate_scan_devices(struct udev_enumerate* enumerate); + static struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate* enumerate); + static void udev_enumerate_unref(struct udev_enumerate* enumerate); + static void udev_unref(struct udev* udev); + static const char* udev_list_entry_get_name(struct udev_list_entry* entry); + static struct udev_device* udev_device_new_from_syspath(struct udev* udev, const char* path); + static void udev_device_unref(struct udev_device* dev); + static struct udev_device* udev_device_get_parent_with_subsystem_devtype(struct udev_device* dev, const char* subsystem, const char* devtype); + static const char* udev_device_get_devtype(struct udev_device* dev); + static const char* udev_device_get_devnode(struct udev_device* dev); }; -constexpr auto udev_new = &Udev::udev_new; -constexpr auto udev_enumerate_new = &Udev::udev_enumerate_new; -constexpr auto udev_enumerate_add_match_subsystem = &Udev::udev_enumerate_add_match_subsystem; -constexpr auto udev_enumerate_scan_devices = &Udev::udev_enumerate_scan_devices; -constexpr auto udev_enumerate_get_list_entry = &Udev::udev_enumerate_get_list_entry; -constexpr auto udev_enumerate_unref = &Udev::udev_enumerate_unref; -constexpr auto udev_unref = &Udev::udev_unref; -constexpr auto udev_list_entry_get_name = &Udev::udev_list_entry_get_name; -constexpr auto udev_device_new_from_syspath = &Udev::udev_device_new_from_syspath; -constexpr auto udev_device_unref = &Udev::udev_device_unref; -constexpr auto udev_device_get_parent_with_subsystem_devtype = &Udev::udev_device_get_parent_with_subsystem_devtype; -constexpr auto udev_device_get_devtype = &Udev::udev_device_get_devtype; -constexpr auto udev_device_get_devnode = &Udev::udev_device_get_devnode; +extern struct udev* (*udev_new)(); +extern udev_enumerate* (*udev_enumerate_new)(struct udev*); +extern void (*udev_enumerate_add_match_subsystem)(struct udev_enumerate*, const char*); +extern void (*udev_enumerate_scan_devices)(struct udev_enumerate*); +extern struct udev_list_entry* (*udev_enumerate_get_list_entry)(struct udev_enumerate*); +extern void (*udev_enumerate_unref)(struct udev_enumerate*); +extern void (*udev_unref)(struct udev*); +extern const char* (*udev_list_entry_get_name)(struct udev_list_entry*); +extern struct udev_device* (*udev_device_new_from_syspath)(struct udev*, const char*); +extern void (*udev_device_unref)(struct udev_device*); +extern struct udev_device* (*udev_device_get_parent_with_subsystem_devtype)(struct udev_device*, const char*, const char*); +extern const char* (*udev_device_get_devtype)(struct udev_device*); +extern const char* (*udev_device_get_devnode)(struct udev_device*); #define udev_list_entry_foreach(list_entry, first_entry) \ for (list_entry = first_entry; \ diff --git a/Tests/mocks/Wraps.cpp b/Tests/mocks/Wraps.cpp index fbbd36f0d6..10367cea02 100644 --- a/Tests/mocks/Wraps.cpp +++ b/Tests/mocks/Wraps.cpp @@ -2,6 +2,7 @@ #include #include "Wraps.h" #include +#include extern "C" int __wrap_system(const char* command) { @@ -63,4 +64,76 @@ extern "C" int __wrap_v_secure_system(const char *command, ...) ret = Wraps::getInstance().v_secure_system(command, args); va_end(args); return ret; -} \ No newline at end of file +} + +WrapsImpl* Wraps::impl = nullptr; + +Wraps::Wraps() {} + +void Wraps::setImpl(WrapsImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +Wraps& Wraps::getInstance() +{ + static Wraps instance; + return instance; +} + +int Wraps::system(const char* command) +{ + EXPECT_NE(impl, nullptr); + return impl->system(command); +} + +FILE* Wraps::popen(const char* command, const char* type) +{ + EXPECT_NE(impl, nullptr); + return impl->popen(command, type); +} + +int Wraps::pclose(FILE* pipe) +{ + EXPECT_NE(impl, nullptr); + return impl->pclose(pipe); +} + +void Wraps::syslog(int pri, const char* fmt, va_list args) +{ + EXPECT_NE(impl, nullptr); + impl->syslog(pri, fmt, args); +} + +FILE* Wraps::setmntent(const char* command, const char* type) +{ + EXPECT_NE(impl, nullptr); + return impl->setmntent(command,type); +} + +struct mntent* Wraps::getmntent(FILE* pipe) +{ + EXPECT_NE(impl, nullptr); + return impl->getmntent(pipe); +} + +FILE * Wraps::v_secure_popen(const char *direction, const char *command, va_list args) +{ + EXPECT_NE(impl, nullptr); + return impl->v_secure_popen(direction, command, args); +} + +int Wraps::v_secure_pclose(FILE *file) +{ + EXPECT_NE(impl, nullptr); + return impl->v_secure_pclose(file); +} + +int Wraps::v_secure_system(const char *command, va_list args) +{ + EXPECT_NE(impl, nullptr); + return impl->v_secure_system(command,args); +} + diff --git a/Tests/mocks/Wraps.h b/Tests/mocks/Wraps.h index 2dbf14b40c..93672b914a 100644 --- a/Tests/mocks/Wraps.h +++ b/Tests/mocks/Wraps.h @@ -2,7 +2,7 @@ #include #include -#include +#include "secure_wrappermock.h" class WrapsImpl { public: @@ -20,56 +20,30 @@ class WrapsImpl { }; class Wraps { +protected: + static WrapsImpl* impl; + public: - static Wraps& getInstance() - { - static Wraps instance; - return instance; - } + Wraps(); + Wraps(const Wraps &obj) = delete; + static void setImpl(WrapsImpl* newImpl); + static Wraps& getInstance(); + + static int system(const char* command); - WrapsImpl* impl; + static FILE* popen(const char* command, const char* type); - static int system(const char* command) - { - return getInstance().impl->system(command); - } + static int pclose(FILE* pipe); - static FILE* popen(const char* command, const char* type) - { - return getInstance().impl->popen(command, type); - } + static void syslog(int pri, const char* fmt, va_list args); - static int pclose(FILE* pipe) - { - return getInstance().impl->pclose(pipe); - } - - static void syslog(int pri, const char* fmt, va_list args) - { - getInstance().impl->syslog(pri, fmt, args); - } + static FILE* setmntent(const char* command, const char* type); - static FILE* setmntent(const char* command, const char* type) - { - return getInstance().impl->setmntent(command, type); - } + static struct mntent* getmntent(FILE* pipe); - static struct mntent* getmntent(FILE* pipe) - { - return getInstance().impl->getmntent(pipe); - } + static FILE *v_secure_popen(const char *direction, const char *command, va_list args); - static FILE *v_secure_popen(const char *direction, const char *command, va_list args) - { - return getInstance().impl->v_secure_popen(direction, command, args); - } + static int v_secure_pclose(FILE *file); - static int v_secure_pclose(FILE *file) - { - return getInstance().impl->v_secure_pclose(file); - } - static int v_secure_system(const char *command, va_list args) - { - return getInstance().impl->v_secure_system(command,args); - } -}; \ No newline at end of file + static int v_secure_system(const char *command, va_list args); +}; diff --git a/Tests/mocks/devicesettings.cpp b/Tests/mocks/devicesettings.cpp new file mode 100755 index 0000000000..cb798cae7b --- /dev/null +++ b/Tests/mocks/devicesettings.cpp @@ -0,0 +1,863 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "devicesettings.h" +#include + +namespace device +{ +AudioOutputPortImpl* AudioOutputPort::impl = nullptr; + +AudioOutputPort::AudioOutputPort() {} + +void AudioOutputPort::setImpl(AudioOutputPortImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +AudioOutputPort& AudioOutputPort::getInstance() { + static AudioOutputPort instance; + return instance; +} + +const std::string& AudioOutputPort::getName() const { + EXPECT_NE(impl, nullptr); + return impl->getName(); +} + +std::vector AudioOutputPort::getMS12AudioProfileList() const { + EXPECT_NE(impl, nullptr); + return impl->getMS12AudioProfileList(); +} + +void AudioOutputPort::getAudioCapabilities(int* capabilities) { + EXPECT_NE(impl, nullptr); + impl->getAudioCapabilities(capabilities); +} + +void AudioOutputPort::getMS12Capabilities(int* capabilities) { + EXPECT_NE(impl, nullptr); + impl->getMS12Capabilities(capabilities); +} + +bool AudioOutputPort::isAudioMSDecode() { + EXPECT_NE(impl, nullptr); + return impl->isAudioMSDecode(); +} + +CompositeInputImpl* CompositeInput::impl = nullptr; + +CompositeInput::CompositeInput() {} + +void CompositeInput::setImpl(CompositeInputImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +CompositeInput& CompositeInput::getInstance() { + static CompositeInput instance; + return instance; +} + +uint8_t CompositeInput::getNumberOfInputs() const { + EXPECT_NE(impl, nullptr); + return impl->getNumberOfInputs(); +} + +bool CompositeInput::isPortConnected(int8_t port) const { + EXPECT_NE(impl, nullptr); + return impl->isPortConnected(port); +} + +void CompositeInput::selectPort(int8_t port) const { + EXPECT_NE(impl, nullptr); + impl->selectPort(port); +} + +void CompositeInput::scaleVideo(int32_t x, int32_t y, int32_t width, int32_t height) const { + EXPECT_NE(impl, nullptr); + impl->scaleVideo(x, y, width, height); +} + + +HdmiInputImpl* HdmiInput::impl = nullptr; + +HdmiInput::HdmiInput() {} + +void HdmiInput::setImpl(HdmiInputImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +HdmiInput& HdmiInput::getInstance() { + static HdmiInput instance; + return instance; +} + +uint8_t HdmiInput::getNumberOfInputs() const { + EXPECT_NE(impl, nullptr); + return impl->getNumberOfInputs(); +} + +bool HdmiInput::isPortConnected(int8_t port) const { + EXPECT_NE(impl, nullptr); + return impl->isPortConnected(port); +} + +std::string HdmiInput::getCurrentVideoMode() const { + EXPECT_NE(impl, nullptr); + return impl->getCurrentVideoMode(); +} + +/*void HdmiInput::selectPort(int8_t port) const { + EXPECT_NE(impl, nullptr); + impl->selectPort(port); +}*/ + +void HdmiInput::selectPort(int8_t Port,bool audioMix , int videoPlane ,bool topMost ) const { + EXPECT_NE(impl, nullptr); + impl->selectPort(Port,audioMix,videoPlane,topMost); +} + +void HdmiInput::scaleVideo(int32_t x, int32_t y, int32_t width, int32_t height) const { + EXPECT_NE(impl, nullptr); + impl->scaleVideo(x, y, width, height); +} + +void HdmiInput::getEDIDBytesInfo(int iHdmiPort, std::vector& edid) const { + EXPECT_NE(impl, nullptr); + impl->getEDIDBytesInfo(iHdmiPort, edid); +} + +void HdmiInput::getHDMISPDInfo(int iHdmiPort, std::vector& data) const { + EXPECT_NE(impl, nullptr); + impl->getHDMISPDInfo(iHdmiPort, data); +} + +void HdmiInput::setEdidVersion(int iHdmiPort, int iEdidVersion) const { + EXPECT_NE(impl, nullptr); + impl->setEdidVersion(iHdmiPort, iEdidVersion); +} + +void HdmiInput::getEdidVersion(int iHdmiPort, int* iEdidVersion) const { + EXPECT_NE(impl, nullptr); + impl->getEdidVersion(iHdmiPort, iEdidVersion); +} + +void HdmiInput::getHdmiALLMStatus(int iHdmiPort, bool* allmStatus) const { + EXPECT_NE(impl, nullptr); + impl->getHdmiALLMStatus(iHdmiPort, allmStatus); +} + +void HdmiInput::getSupportedGameFeatures(std::vector& featureList) const { + EXPECT_NE(impl, nullptr); + impl->getSupportedGameFeatures(featureList); +} + + void HdmiInput::setEdid2AllmSupport(int iport, bool allmSupport) const { + EXPECT_NE(impl, nullptr); + impl->setEdid2AllmSupport(iport,allmSupport); +} + + void HdmiInput::getAVLatency(int *audio_output_delay, int *video_latency) const { + EXPECT_NE(impl, nullptr); + impl->getAVLatency(audio_output_delay,video_latency); +} + + + void HdmiInput::getEdid2AllmSupport(int iport, bool *allmSupport) const { + EXPECT_NE(impl, nullptr); + impl->getEdid2AllmSupport(iport,allmSupport); +} + +SleepModeImpl* SleepMode::impl = nullptr; + +SleepMode::SleepMode() {} + +void SleepMode::setImpl(SleepModeImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +SleepMode& SleepMode::getInstance() { + static SleepMode instance; + return instance; +} + +SleepMode& SleepMode::getInstance(int id) { + EXPECT_NE(impl, nullptr); + return impl->getInstanceById(id); +} + +SleepMode& SleepMode::getInstance(const std::string &name) { + EXPECT_NE(impl, nullptr); + return impl->getInstanceByName(name); +} + +List SleepMode::getSleepModes() { + EXPECT_NE(impl, nullptr); + return impl->getSleepModes(); +} + +const std::string& SleepMode::toString() const { + EXPECT_NE(impl, nullptr); + return impl->toString(); +} + +VideoDeviceImpl* VideoDevice::impl = nullptr; + +VideoDevice::VideoDevice() {} + +void VideoDevice::setImpl(VideoDeviceImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +VideoDevice& VideoDevice::getInstance() { + static VideoDevice instance; + return instance; +} + +int VideoDevice::getFRFMode(int* frfmode) const { + EXPECT_NE(impl, nullptr); + return impl->getFRFMode(frfmode); +} + +int VideoDevice::setFRFMode(int frfmode) const { + EXPECT_NE(impl, nullptr); + return impl->setFRFMode(frfmode); +} + +int VideoDevice::getCurrentDisframerate(char* framerate) const { + EXPECT_NE(impl, nullptr); + return impl->getCurrentDisframerate(framerate); +} + +int VideoDevice::setDisplayframerate(const char* framerate) const { + EXPECT_NE(impl, nullptr); + return impl->setDisplayframerate(framerate); +} + + +VideoResolutionImpl* VideoResolution::impl = nullptr; + +void VideoResolution::setImpl(VideoResolutionImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} +const std::string& VideoResolution::getName() const { + return impl->getName(); +} + +VideoOutputPortTypeImpl* VideoOutputPortType::impl = nullptr; +VideoOutputPortType::VideoOutputPortType(){} + +void VideoOutputPortType::setImpl(VideoOutputPortTypeImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +int VideoOutputPortType::getId() const { + EXPECT_NE(impl, nullptr); + return impl->getId(); +} + +const List VideoOutputPortType::getSupportedResolutions() const { + EXPECT_NE(impl, nullptr); + return impl->getSupportedResolutions(); +} + + +DisplayImpl* Display::impl = nullptr; + + +void Display::setImpl(DisplayImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +Display& Display::getInstance() { + static Display instance; + return instance; +} + +void Display::getEDIDBytes(std::vector& edid) { + EXPECT_NE(impl, nullptr); + impl->getEDIDBytes(edid); +} + +VideoOutputPortImpl* VideoOutputPort::impl = nullptr; + +VideoOutputPort::VideoOutputPort() {} + +void VideoOutputPort::setImpl(VideoOutputPortImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +VideoOutputPort& VideoOutputPort::getInstance() { + static VideoOutputPort instance; + return instance; +} + +const VideoOutputPortType& VideoOutputPort::getType() const { + EXPECT_NE(impl, nullptr); + return impl->getType(); +} + +const std::string& VideoOutputPort::getName() const { + EXPECT_NE(impl, nullptr); + return impl->getName(); +} + +const VideoResolution& VideoOutputPort::getDefaultResolution() const { + EXPECT_NE(impl, nullptr); + return impl->getDefaultResolution(); +} + +int VideoOutputPort::getHDCPProtocol() { + EXPECT_NE(impl, nullptr); + return impl->getHDCPProtocol(); +} + +int VideoOutputPort::getHDCPReceiverProtocol() { + EXPECT_NE(impl, nullptr); + return impl->getHDCPReceiverProtocol(); +} + +int VideoOutputPort::getHDCPCurrentProtocol() { + EXPECT_NE(impl, nullptr); + return impl->getHDCPCurrentProtocol(); +} + +int VideoOutputPort::getHDCPStatus() { + EXPECT_NE(impl, nullptr); + return impl->getHDCPStatus(); +} + +AudioOutputPort& VideoOutputPort::getAudioOutputPort() { + EXPECT_NE(impl, nullptr); + return impl->getAudioOutputPort(); +} + +bool VideoOutputPort::isDisplayConnected() { + EXPECT_NE(impl, nullptr); + return impl->isDisplayConnected(); +} + +bool VideoOutputPort::isContentProtected() { + EXPECT_NE(impl, nullptr); + return impl->isContentProtected(); +} + +Display& VideoOutputPort::getDisplay() { + EXPECT_NE(impl, nullptr); + return impl->getDisplay(); +} + +VideoOutputPortConfigImpl* VideoOutputPortConfig::impl = nullptr; + +VideoOutputPortConfig::VideoOutputPortConfig() {} + +void VideoOutputPortConfig::setImpl(VideoOutputPortConfigImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +VideoOutputPortConfig& VideoOutputPortConfig::getInstance() { + static VideoOutputPortConfig instance; + return instance; +} + +VideoOutputPortType& VideoOutputPortConfig::getPortType(int id) { + EXPECT_NE(impl, nullptr); + return impl->getPortType(id); +} + +VideoOutputPort& VideoOutputPortConfig::getPort(const std::string& name) { + EXPECT_NE(impl, nullptr); + return impl->getPort(name); +} + +ManagerImpl* Manager::impl = nullptr; + +Manager::Manager() {} + +void Manager::setImpl(ManagerImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +Manager& Manager::getInstance() { + static Manager instance; + return instance; +} + +void Manager::Initialize() { + EXPECT_NE(impl, nullptr); + impl->Initialize(); +} + +void Manager::DeInitialize() { + EXPECT_NE(impl, nullptr); + impl->DeInitialize(); +} + +HostImpl* Host::impl = nullptr; + + +void Host::setImpl(HostImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +Host& Host::getInstance() { + static Host instance; + return instance; +} + +SleepMode Host::getPreferredSleepMode() { + EXPECT_NE(impl, nullptr); + return impl->getPreferredSleepMode(); +} + +int Host::setPreferredSleepMode(const SleepMode mode) { + EXPECT_NE(impl, nullptr); + return impl->setPreferredSleepMode(mode); +} + +List Host::getAvailableSleepModes() { + EXPECT_NE(impl, nullptr); + return impl->getAvailableSleepModes(); +} + +List Host::getVideoOutputPorts() { + EXPECT_NE(impl, nullptr); + return impl->getVideoOutputPorts(); +} + +List Host::getAudioOutputPorts() { + EXPECT_NE(impl, nullptr); + return impl->getAudioOutputPorts(); +} + +List Host::getVideoDevices() { + EXPECT_NE(impl, nullptr); + return impl->getVideoDevices(); +} + +VideoOutputPort& Host::getVideoOutputPort(const std::string& name) { + EXPECT_NE(impl, nullptr); + return impl->getVideoOutputPort(name); +} + +AudioOutputPort& Host::getAudioOutputPort(const std::string& name) { + EXPECT_NE(impl, nullptr); + return impl->getAudioOutputPort(name); +} + +void Host::getHostEDID(std::vector& edid) const { + EXPECT_NE(impl, nullptr); + return impl->getHostEDID(edid); +} + +std::string Host::getDefaultVideoPortName() { + EXPECT_NE(impl, nullptr); + return impl->getDefaultVideoPortName(); +} + +std::string Host::getDefaultAudioPortName() { + EXPECT_NE(impl, nullptr); + return impl->getDefaultAudioPortName(); +} + +FrontPanelIndicator::ColorImpl* FrontPanelIndicator::Color::impl = nullptr; + +FrontPanelIndicator::Color::Color() {} + +void FrontPanelIndicator::Color::setImpl(ColorImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +FrontPanelIndicator::Color& FrontPanelIndicator::Color::getInstance() { + static Color instance; + return instance; +} + +const FrontPanelIndicator::Color& FrontPanelIndicator::Color::getInstance(int id) { + EXPECT_NE(impl, nullptr); + return impl->getInstanceById(id); +} + +const FrontPanelIndicator::Color& FrontPanelIndicator::Color::getInstance(const std::string& name) { + EXPECT_NE(impl, nullptr); + return impl->getInstanceByName(name); +} + +const int FrontPanelIndicator::Color::kWhite = dsFPD_COLOR_WHITE; + +std::string FrontPanelIndicator::Color::getName() const { + EXPECT_NE(impl, nullptr); + return impl->getName(); +} + +FrontPanelIndicator::Color::~Color() {} + + +FrontPanelTextDisplayImpl* FrontPanelTextDisplay::impl = nullptr; + +FrontPanelTextDisplay::FrontPanelTextDisplay() {} + +void FrontPanelTextDisplay::setImpl(FrontPanelTextDisplayImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +FrontPanelTextDisplay& FrontPanelTextDisplay::getInstance(const std::string& name) { + EXPECT_NE(impl, nullptr); + return impl->getInstanceByName(name); +} + +FrontPanelTextDisplay& FrontPanelTextDisplay::getInstance(int id) { + EXPECT_NE(impl, nullptr); + return impl->getInstanceById(id); +} + +FrontPanelTextDisplay& FrontPanelTextDisplay::getInstance() { + static FrontPanelTextDisplay instance; + return instance; +} + +const int FrontPanelTextDisplay::kModeClock12Hr = dsFPD_TIME_12_HOUR; +const int FrontPanelTextDisplay::kModeClock24Hr = dsFPD_TIME_24_HOUR; + +int FrontPanelTextDisplay::getCurrentTimeFormat() const { + EXPECT_NE(impl, nullptr); + return impl->getCurrentTimeFormat(); +} + +void FrontPanelTextDisplay::setTimeFormat(const int iTimeFormat) { + EXPECT_NE(impl, nullptr); + impl->setTimeFormat(iTimeFormat); +} + +void FrontPanelTextDisplay::setText(const std::string text) { + EXPECT_NE(impl, nullptr); + impl->setText(text); +} + +void FrontPanelTextDisplay::setMode(int mode) { + EXPECT_NE(impl, nullptr); + impl->setMode(mode); +} + +int FrontPanelTextDisplay::getTextBrightness() const { + EXPECT_NE(impl, nullptr); + return impl->getTextBrightness(); +} + +void FrontPanelTextDisplay::setTextBrightness(const int brightness) const { + EXPECT_NE(impl, nullptr); + impl->setTextBrightness(brightness); +} + +FrontPanelConfigImpl* FrontPanelConfig::impl = nullptr; + +FrontPanelConfig::FrontPanelConfig() {} + +void FrontPanelConfig::setImpl(FrontPanelConfigImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +FrontPanelConfig& FrontPanelConfig::getInstance() { + static FrontPanelConfig instance; + return instance; +} + +List FrontPanelConfig::getIndicators() { + EXPECT_NE(impl, nullptr); + return impl->getIndicators(); +} + +FrontPanelTextDisplay& FrontPanelConfig::getTextDisplay(const std::string& name) { + EXPECT_NE(impl, nullptr); + return impl->getTextDisplay(name); +} + +List FrontPanelConfig::getTextDisplays() { + EXPECT_NE(impl, nullptr); + return impl->getTextDisplays(); +} + +FrontPanelTextDisplay& FrontPanelConfig::getTextDisplay(int id) { + EXPECT_NE(impl, nullptr); + return impl->getTextDisplay(id); +} + +FrontPanelTextDisplay& FrontPanelConfig::getTextDisplay() const { + EXPECT_NE(impl, nullptr); + return impl->getTextDisplay(); +} +} + +rtObjectBaseImpl* rtObjectBase::impl = nullptr; +rtObjectBase& rtObjectBase::getInstance() { + static rtObjectBase instance; + return instance; +} + +void rtObjectBase::setImpl(rtObjectBaseImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +rtError rtObjectBase::set(const char* name, const char* value) { + EXPECT_NE(impl, nullptr); + return impl->set(name, value); +} + +rtError rtObjectBase::set(const char* name, bool value) { + EXPECT_NE(impl, nullptr); + return impl->set(name, value); +} + +rtError rtObjectBase::set(const char* name, const rtValue& value) { + EXPECT_NE(impl, nullptr); + return impl->set(name, value); +} + + +rtObjectRefImpl* rtObjectRef::impl = nullptr; + +rtObjectRef& rtObjectRef::getInstance() { + static rtObjectRef instance; + return instance; +} + +void rtObjectRef::setImpl(rtObjectRefImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} +rtObjectRef::rtObjectRef() {} + +rtObjectRef::rtObjectRef(const rtObjectRef&) = default; + +rtObjectRef::rtObjectRef(const rtMapObject* o) { + delete o; + o = nullptr; +} + +rtObjectRef& rtObjectRef::operator=(rtMapObject* o) { + delete o; + o = nullptr; + return *this; +} + +rtObjectRef& rtObjectRef::operator=(const rtObjectRef&) { + return *this; +} + +rtObjectRef& rtObjectRef::operator=(rtIObject* o) { + asn(o); + return *this; +} + +rtObjectRef& rtObjectRef::operator=(rtObjectRef&&) = default; + +rtError rtObjectRef::send(const char* messageName) { + EXPECT_NE(impl, nullptr); + return impl->send(messageName); +} + +rtError rtObjectRef::send(const char* messageName, const char* method, rtFunctionCallback* callback) { + EXPECT_NE(impl, nullptr); + return impl->send(messageName, method, callback); +} + +rtError rtObjectRef::send(const char* messageName, const rtValue& arg1) { + EXPECT_NE(impl, nullptr); + return impl->send(messageName, arg1); +} + +rtError rtObjectRef::send(const char* messageName, rtObjectRef& base) { + EXPECT_NE(impl, nullptr); + return impl->send(messageName, base); +} + +rtObjectRef::~rtObjectRef() {} + +rtValueImpl* rtValue::impl = nullptr; + +rtValue& rtValue::getInstance() { + static rtValue instance; + return instance; +} + +rtValue::rtValue() = default; + +rtValue::rtValue(bool v) : mValue({ .boolValue = v }) {} + +rtValue::rtValue(const char* v) : mValue({ .stringValue = v }) {} + +rtValue::rtValue(const rtString& v) : mValue({ .stringValue = v.cString() }) {} + +rtValue::rtValue(rtIObject* v) { + if (v) { + delete v; + v = nullptr; + } +} + +rtValue::rtValue(const rtObjectRef& v) {} + +rtValue::rtValue(const rtValue& other) { + mValue = other.mValue; +} + +rtValue::~rtValue() {} + +rtValue& rtValue::operator=(bool v) { + mValue.boolValue = v; + return *this; +} + +rtValue& rtValue::operator=(const char* v) { + mValue.stringValue = v; + return *this; +} + +rtValue& rtValue::operator=(const rtString& v) { + mValue.stringValue = v.cString(); + return *this; +} + +rtValue& rtValue::operator=(const rtIObject* v) { + delete v; + v = nullptr; + return *this; +} + +rtValue& rtValue::operator=(const rtObjectRef& v) { + return *this; +} + +rtValue& rtValue::operator=(const rtValue& other) { + if (this != &other) { + mValue = other.mValue; + } + return *this; +} + +void rtValue::setImpl(rtValueImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +rtObjectRef rtValue::toObject() const { + rtObjectRef v; + return v; +} + +void rtValue::setString(const char* v) { + mValue.stringValue = v; +} + +void rtValue::setString(const rtString& v) { + mValue.stringValue = v.cString(); +} + + +rtArrayObjectImpl* rtArrayObject::impl = nullptr; + +rtArrayObject& rtArrayObject::getInstance() { + static rtArrayObject instance; + return instance; +} + +void rtArrayObject::pushBack(const char* v) { + EXPECT_NE(impl, nullptr); + impl->pushBack(v); +} + +void rtArrayObject::pushBack(rtValue v) { + EXPECT_NE(impl, nullptr); + impl->pushBack(v); +} + +void rtArrayObject::setImpl(rtArrayObjectImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +floatingRtFunctionsImpl* floatingRtFunctions::impl = nullptr; +floatingRtFunctions& floatingRtFunctions::getInstance() +{ + static floatingRtFunctions instance; + return instance; +} +void floatingRtFunctions::setImpl(floatingRtFunctionsImpl* newImpl) { + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +rtError rtRemoteProcessSingleItem() { + return floatingRtFunctions::getInstance().impl->rtRemoteProcessSingleItem(); +} + +rtError rtRemoteLocateObject(rtRemoteEnvironment* env, const char* str, rtObjectRef& obj, int x, remoteDisconnectCallback back, void* cbdata) { + return floatingRtFunctions::getInstance().impl->rtRemoteLocateObject(env, str, obj, x, back, cbdata); +} + +rtRemoteEnvironment* rtEnvironmentGetGlobal() { + return floatingRtFunctions::getInstance().impl->rtEnvironmentGetGlobal(); +} + +rtError rtRemoteInit(rtRemoteEnvironment* env) { + return floatingRtFunctions::getInstance().impl->rtRemoteInit(env); +} + +rtError rtRemoteShutdown(rtRemoteEnvironment* env) { + return floatingRtFunctions::getInstance().impl->rtRemoteShutdown(env); +} + +char* rtStrError(rtError err) { + return floatingRtFunctions::getInstance().impl->rtStrError(err); +} diff --git a/Tests/mocks/devicesettings.h b/Tests/mocks/devicesettings.h index 588d5e9850..051f65b3e1 100644 --- a/Tests/mocks/devicesettings.h +++ b/Tests/mocks/devicesettings.h @@ -416,15 +416,15 @@ typedef struct _DSMgr_EventData_t { dsHdmiInPort_t port; bool allm_mode; } hdmi_in_allm_mode; /*HDMI in ALLM Mode change*/ - struct _HDMI_IN_CONTENT_TYPE_DATA{ + struct _HDMI_IN_CONTENT_TYPE_DATA{ dsHdmiInPort_t port; dsAviContentType_t aviContentType; }hdmi_in_content_type; - struct _HDMI_IN_AV_LATENCY{ + struct _HDMI_IN_AV_LATENCY{ int audio_output_delay; int video_latency; }hdmi_in_av_latency; /*HDMI in AVLatency change*/ - struct _DISPLAY_FRAMERATE_CHANGE { + struct _DISPLAY_FRAMERATE_CHANGE { char framerate[20]; }DisplayFrameRateChange; } data; @@ -444,8 +444,8 @@ typedef uint32_t dsFPDColor_t; #define dsFPD_COLOR_WHITE dsFPDColor_Make(0xFF, 0xFF, 0xFF) typedef struct _dsFPDColorConfig_t{ - int id; - dsFPDColor_t color; + int id; + dsFPDColor_t color; }dsFPDColorConfig_t; namespace device { @@ -505,33 +505,19 @@ class AudioOutputPortImpl { }; class AudioOutputPort { -public: - AudioOutputPortImpl* impl; - - const std::string& getName() const - { - return impl->getName(); - } - - std::vector getMS12AudioProfileList() const - { - return impl->getMS12AudioProfileList(); - } - - void getAudioCapabilities(int* capabilities) - { - return impl->getAudioCapabilities(capabilities); - } +protected: + static AudioOutputPortImpl* impl; - void getMS12Capabilities(int* capabilities) - { - return impl->getMS12Capabilities(capabilities); - } - - bool isAudioMSDecode() - { - return impl->isAudioMSDecode(); - } +public: + AudioOutputPort(); + static void setImpl(AudioOutputPortImpl* newImpl); + static AudioOutputPort& getInstance(); + + const std::string& getName() const; + std::vector getMS12AudioProfileList() const; + void getAudioCapabilities(int* capabilities); + void getMS12Capabilities(int* capabilities); + bool isAudioMSDecode(); }; } @@ -547,31 +533,18 @@ class CompositeInputImpl { }; class CompositeInput { -public: - static CompositeInput& getInstance() - { - static CompositeInput instance; - return instance; - } - - CompositeInputImpl* impl; +protected: + static CompositeInputImpl* impl; - uint8_t getNumberOfInputs() const - { - return impl->getNumberOfInputs(); - } - bool isPortConnected(int8_t Port) const - { - return impl->isPortConnected(Port); - } - void selectPort(int8_t Port) const - { - return impl->selectPort(Port); - } - void scaleVideo(int32_t x, int32_t y, int32_t width, int32_t height) const - { - return impl->scaleVideo(x, y, width, height); - } +public: + CompositeInput(); + static void setImpl(CompositeInputImpl* newImpl); + static CompositeInput& getInstance(); + + uint8_t getNumberOfInputs() const; + bool isPortConnected(int8_t port) const; + void selectPort(int8_t port) const; + void scaleVideo(int32_t x, int32_t y, int32_t width, int32_t height) const; }; } @@ -600,72 +573,29 @@ class HdmiInputImpl { }; class HdmiInput { -public: - static HdmiInput& getInstance() - { - static HdmiInput instance; - return instance; - } +protected: + static HdmiInputImpl* impl; - HdmiInputImpl* impl; - - uint8_t getNumberOfInputs() const - { - return impl->getNumberOfInputs(); - } - bool isPortConnected(int8_t Port) const - { - return impl->isPortConnected(Port); - } - std::string getCurrentVideoMode() const - { - return impl->getCurrentVideoMode(); - } - void selectPort(int8_t Port,bool audioMix = false,int videoPlane = 0,bool topMost = false) const - { - return impl->selectPort(Port,audioMix,videoPlane,topMost); - } - void scaleVideo(int32_t x, int32_t y, int32_t width, int32_t height) const - { - return impl->scaleVideo(x, y, width, height); - } - void getEDIDBytesInfo(int iHdmiPort, std::vector& edid) const - { - return impl->getEDIDBytesInfo(iHdmiPort, edid); - } - void getHDMISPDInfo(int iHdmiPort, std::vector& data) const - { - return impl->getHDMISPDInfo(iHdmiPort, data); - } - void setEdidVersion(int iHdmiPort, int iEdidVersion) const - { - return impl->setEdidVersion(iHdmiPort, iEdidVersion); - } - void getEdidVersion(int iHdmiPort, int* iEdidVersion) const - { - return impl->getEdidVersion(iHdmiPort, iEdidVersion); - } - - void getHdmiALLMStatus(int iHdmiPort, bool* allmStatus) const - { - return impl->getHdmiALLMStatus(iHdmiPort, allmStatus); - } - void getSupportedGameFeatures(std::vector& featureList) const - { - return impl->getSupportedGameFeatures(featureList); - } - void getAVLatency(int *audio_output_delay, int *video_latency) const - { - return impl->getAVLatency(audio_output_delay,video_latency); - } - void setEdid2AllmSupport(int iport, bool allmSupport) const - { - return impl->setEdid2AllmSupport(iport,allmSupport); - } - void getEdid2AllmSupport(int iport, bool *allmSupport) const - { - return impl->getEdid2AllmSupport(iport,allmSupport); - } +public: + HdmiInput(); + static void setImpl(HdmiInputImpl* newImpl); + static HdmiInput& getInstance(); // Changed return type + + uint8_t getNumberOfInputs() const; + bool isPortConnected(int8_t port) const; + std::string getCurrentVideoMode() const; + void selectPort(int8_t Port,bool audioMix = false, int videoPlane = 0,bool topMost = false) const; + void scaleVideo(int32_t x, int32_t y, int32_t width, int32_t height) const; + void getEDIDBytesInfo(int iHdmiPort, std::vector& edid) const; + void getHDMISPDInfo(int iHdmiPort, std::vector& data) const; + void setEdidVersion(int iHdmiPort, int iEdidVersion) const; + void getEdidVersion(int iHdmiPort, int* iEdidVersion) const; + + void getHdmiALLMStatus(int iHdmiPort, bool* allmStatus) const; + void getSupportedGameFeatures(std::vector& featureList) const; + void getAVLatency(int *audio_output_delay, int *video_latency)const; + void setEdid2AllmSupport(int iport, bool allmSupport) const; + void getEdid2AllmSupport(int iport, bool *allmSupport) const; }; } @@ -682,34 +612,19 @@ class SleepModeImpl { }; class SleepMode { -public: - SleepModeImpl* impl; +protected: + static SleepModeImpl* impl; - static SleepMode& getInstance() - { - static SleepMode instance; - return instance; - } - - static SleepMode& getInstance(int id) - { - return getInstance().impl->getInstanceById(id); - } - - static SleepMode& getInstance(const std::string &name) - { - return getInstance().impl->getInstanceByName(name); - } +public: + SleepMode(); + static void setImpl(SleepModeImpl* newImpl); - List getSleepModes() - { - return impl->getSleepModes(); - } + static SleepMode& getInstance(); + static SleepMode& getInstance(int id); + static SleepMode& getInstance(const std::string &name); - const std::string& toString() const - { - return impl->toString(); - } + List getSleepModes(); + const std::string& toString() const; }; } @@ -726,28 +641,19 @@ class VideoDeviceImpl { }; class VideoDevice { -public: - VideoDeviceImpl* impl; - - int getFRFMode(int* frfmode) const - { - return impl->getFRFMode(frfmode); - } +protected: + static VideoDeviceImpl* impl; - int setFRFMode(int frfmode) const - { - return impl->setFRFMode(frfmode); - } +public: + VideoDevice(); - int getCurrentDisframerate(char* framerate) const - { - return impl->getCurrentDisframerate(framerate); - } + static void setImpl(VideoDeviceImpl* newImpl); + static VideoDevice& getInstance(); - int setDisplayframerate(const char* framerate) const - { - return impl->setDisplayframerate(framerate); - } + int getFRFMode(int* frfmode) const; + int setFRFMode(int frfmode) const; + int getCurrentDisframerate(char* framerate) const; + int setDisplayframerate(const char* framerate) const; }; } @@ -762,13 +668,12 @@ class VideoResolutionImpl { }; class VideoResolution { -public: - VideoResolutionImpl* impl; +protected: + static VideoResolutionImpl* impl; - const std::string& getName() const - { - return impl->getName(); - } +public: + static void setImpl(VideoResolutionImpl* newImpl); + const std::string& getName() const; }; } @@ -784,44 +689,38 @@ class VideoOutputPortTypeImpl { }; class VideoOutputPortType { +protected: + static VideoOutputPortTypeImpl* impl; + public: - VideoOutputPortTypeImpl* impl; + VideoOutputPortType(); - int getId() const - { - return impl->getId(); - } + static void setImpl(VideoOutputPortTypeImpl* newImpl); - const List getSupportedResolutions() const - { - return impl->getSupportedResolutions(); - } + int getId() const; + const List getSupportedResolutions() const; }; } namespace device{ - class DisplayImpl{ - public: - virtual ~DisplayImpl() = default; - - virtual void getEDIDBytes(std::vector &edid) const = 0; - }; - class Display{ - public: - DisplayImpl* impl; - static Display& getInstance() - { - static Display instance; - return instance; - } + class DisplayImpl{ + public: + virtual ~DisplayImpl() = default; + + virtual void getEDIDBytes(std::vector &edid) const = 0; + }; + class Display { + protected: + static DisplayImpl* impl; - void getEDIDBytes(std::vector &edid){ - return impl->getEDIDBytes(edid); - } + public: + static void setImpl(DisplayImpl* newImpl); + static Display& getInstance(); - }; + void getEDIDBytes(std::vector& edid); +}; } @@ -846,67 +745,27 @@ class VideoOutputPortImpl { }; class VideoOutputPort { -public: - VideoOutputPortImpl* impl; - - static VideoOutputPort& getInstance() - { - static VideoOutputPort instance; - return instance; - } - - const VideoOutputPortType& getType() const - { - return impl->getType(); - } - - const std::string& getName() const - { - return impl->getName(); - } +protected: + static VideoOutputPortImpl* impl; - const VideoResolution& getDefaultResolution() const - { - return impl->getDefaultResolution(); - } - - int getHDCPProtocol() - { - return impl->getHDCPProtocol(); - } - - int getHDCPReceiverProtocol() - { - return impl->getHDCPReceiverProtocol(); - } - - int getHDCPCurrentProtocol() - { - return impl->getHDCPCurrentProtocol(); - } - - int getHDCPStatus() - { - return impl->getHDCPStatus(); - } - - AudioOutputPort& getAudioOutputPort() - { - return impl->getAudioOutputPort(); - } - - bool isDisplayConnected() - { - return impl->isDisplayConnected(); - } +public: + VideoOutputPort(); + + static void setImpl(VideoOutputPortImpl* newImpl); + static VideoOutputPort& getInstance(); + + const VideoOutputPortType& getType() const; + const std::string& getName() const; + const VideoResolution& getDefaultResolution() const; + int getHDCPProtocol(); + int getHDCPReceiverProtocol(); + int getHDCPCurrentProtocol(); + int getHDCPStatus(); + AudioOutputPort& getAudioOutputPort(); + bool isDisplayConnected(); + bool isContentProtected(); + Display& getDisplay(); - bool isContentProtected() - { - return impl->isContentProtected(); - } - Display& getDisplay(){ - return impl->getDisplay(); - } }; } @@ -922,24 +781,17 @@ class VideoOutputPortConfigImpl { }; class VideoOutputPortConfig { +protected: + static VideoOutputPortConfigImpl* impl; + public: - static VideoOutputPortConfig& getInstance() - { - static VideoOutputPortConfig instance; - return instance; - } + VideoOutputPortConfig(); - VideoOutputPortConfigImpl* impl; + static void setImpl(VideoOutputPortConfigImpl* newImpl); + static VideoOutputPortConfig& getInstance(); - VideoOutputPortType& getPortType(int id) - { - return impl->getPortType(id); - } - - VideoOutputPort& getPort(const std::string& name) - { - return impl->getPort(name); - } + VideoOutputPortType& getPortType(int id); + VideoOutputPort& getPort(const std::string& name); }; } @@ -954,24 +806,17 @@ class ManagerImpl { namespace device { class Manager { +protected: + static ManagerImpl* impl; + public: - static Manager& getInstance() - { - static Manager instance; - return instance; - } + Manager(); - ManagerImpl* impl; + static void setImpl(ManagerImpl* newImpl); + static Manager& getInstance(); - static void Initialize() - { - return getInstance().impl->Initialize(); - } - - static void DeInitialize() - { - return getInstance().impl->DeInitialize(); - } + static void Initialize(); + static void DeInitialize(); }; } @@ -994,69 +839,24 @@ class HostImpl { }; class Host { -public: - static Host& getInstance() - { - static Host instance; - return instance; - } - - HostImpl* impl; - - SleepMode getPreferredSleepMode() - { - return impl->getPreferredSleepMode(); - } - - int setPreferredSleepMode(const SleepMode mode) - { - return impl->setPreferredSleepMode(mode); - } - - List getAvailableSleepModes() - { - return impl->getAvailableSleepModes(); - } - - List getVideoOutputPorts() - { - return impl->getVideoOutputPorts(); - } +protected: + static HostImpl* impl; - List getAudioOutputPorts() - { - return impl->getAudioOutputPorts(); - } - - List getVideoDevices() - { - return impl->getVideoDevices(); - } - - VideoOutputPort& getVideoOutputPort(const std::string& name) - { - return impl->getVideoOutputPort(name); - } - - AudioOutputPort& getAudioOutputPort(const std::string& name) - { - return impl->getAudioOutputPort(name); - } - - void getHostEDID(std::vector& edid) const - { - return impl->getHostEDID(edid); - } - - std::string getDefaultVideoPortName() - { - return impl->getDefaultVideoPortName(); - } - - std::string getDefaultAudioPortName() - { - return impl->getDefaultAudioPortName(); - } +public: + static void setImpl(HostImpl* newImpl); + static Host& getInstance(); + + SleepMode getPreferredSleepMode(); + int setPreferredSleepMode(const SleepMode mode); + List getAvailableSleepModes(); + List getVideoOutputPorts(); + List getAudioOutputPorts(); + List getVideoDevices(); + VideoOutputPort& getVideoOutputPort(const std::string& name); + AudioOutputPort& getAudioOutputPort(const std::string& name); + void getHostEDID(std::vector& edid) const; + std::string getDefaultVideoPortName(); + std::string getDefaultAudioPortName(); }; } @@ -1074,30 +874,21 @@ class FrontPanelIndicator { }; class Color { - public: - static Color& getInstance() - { - static Color instance; - return instance; - } +protected: + static ColorImpl* impl; + +public: + Color(); - ColorImpl* impl; + static void setImpl(ColorImpl* newImpl); + static Color& getInstance(); + static const Color& getInstance(int id); + static const Color& getInstance(const std::string& name); - static const Color& getInstance(int id) - { - return getInstance().impl->getInstanceById(id); - } - static const Color& getInstance(const std::string& name) - { - return getInstance().impl->getInstanceByName(name); - } - static const int kWhite = dsFPD_COLOR_WHITE; + static const int kWhite; - std::string getName() const - { - return impl->getName(); - } - virtual ~Color(){}; + std::string getName() const; + virtual ~Color(); }; static FrontPanelIndicator& getInstance() @@ -1108,23 +899,23 @@ class FrontPanelIndicator { class FrontPanelIndicatorImpl { public: - virtual ~FrontPanelIndicatorImpl() = default; + virtual ~FrontPanelIndicatorImpl() = default; virtual FrontPanelIndicator& getInstanceInt(int id) = 0; virtual FrontPanelIndicator& getInstanceString(const std::string& name) = 0; - virtual void setState(const bool bState) const = 0; + virtual void setState(const bool bState) const = 0; virtual std::string getName() const = 0; virtual void setBrightness(const int brightness, const bool toPersist) const = 0; - virtual int getBrightness() const = 0; + virtual int getBrightness() const = 0; virtual void setColor(const Color &newColor, const bool toPersist) const = 0; virtual void setColorInt(const uint32_t color, const bool toPersist) const = 0; virtual void getBrightnessLevels(int &levels,int &min,int &max) const = 0; - virtual int getColorMode() const = 0; - virtual std::string getColorName() const = 0; - virtual List getSupportedColors() const =0; + virtual int getColorMode() const = 0; + virtual std::string getColorName() const = 0; + virtual List getSupportedColors() const =0; }; FrontPanelIndicatorImpl* impl; - + static FrontPanelIndicator& getInstance(int id) { return getInstance().impl->getInstanceInt(id); @@ -1160,12 +951,12 @@ class FrontPanelIndicator { return impl->setColorInt(color, toPersist); } void getBrightnessLevels(int &levels,int &min,int &max) const - { - return impl->getBrightnessLevels( levels, min, max); + { + return impl->getBrightnessLevels( levels, min, max); } List getSupportedColors() { - return impl->getSupportedColors(); + return impl->getSupportedColors(); } int getColorMode() const { @@ -1188,49 +979,26 @@ class FrontPanelTextDisplayImpl { }; class FrontPanelTextDisplay : public FrontPanelIndicator{ -public: - static const int kModeClock12Hr = dsFPD_TIME_12_HOUR; - static const int kModeClock24Hr = dsFPD_TIME_24_HOUR; - - FrontPanelTextDisplayImpl* impl; +protected: + static FrontPanelTextDisplayImpl* impl; - int getCurrentTimeFormat() const - { - return impl->getCurrentTimeFormat(); - } - void setTimeFormat(const int iTimeFormat) - { - return impl->setTimeFormat(iTimeFormat); - } - static FrontPanelTextDisplay& getInstance(const std::string& name) - { - return getInstance().impl->getInstanceByName(name); - } - static FrontPanelTextDisplay& getInstance(int id) - { - return getInstance().impl->getInstanceById(id); - } - static FrontPanelTextDisplay& getInstance() - { - static FrontPanelTextDisplay instance; - return instance; - } - void setText(const std::string text) - { - return impl->setText(text); - } - void setMode(int mode) - { - return impl->setMode(mode); - } - int getTextBrightness() const - { - return impl->getTextBrightness(); - } - void setTextBrightness(const int brightness) const - { - return impl->setTextBrightness(brightness); - } +public: + FrontPanelTextDisplay(); + + static void setImpl(FrontPanelTextDisplayImpl* newImpl); + + int getCurrentTimeFormat() const; + void setTimeFormat(const int iTimeFormat); + static FrontPanelTextDisplay& getInstance(const std::string& name); + static FrontPanelTextDisplay& getInstance(int id); + static FrontPanelTextDisplay& getInstance(); + static const int kModeClock12Hr; + static const int kModeClock24Hr; + + void setText(const std::string text); + void setMode(int mode); + int getTextBrightness() const; + void setTextBrightness(const int brightness) const; }; class FrontPanelConfig; @@ -1245,34 +1013,20 @@ class FrontPanelConfigImpl { }; class FrontPanelConfig { +protected: + static FrontPanelConfigImpl* impl; + public: - FrontPanelConfigImpl* impl; + FrontPanelConfig(); - static FrontPanelConfig& getInstance() - { - static FrontPanelConfig instance; - return instance; - } - List getIndicators() - { - return impl->getIndicators(); - } - FrontPanelTextDisplay& getTextDisplay(const std::string &name) - { - return impl->getTextDisplay(name); - } - List getTextDisplays() - { - return impl->getTextDisplays(); - } - FrontPanelTextDisplay& getTextDisplay(int id) - { - return impl->getTextDisplay(id); - } - FrontPanelTextDisplay& getTextDisplay() const - { - return impl->getTextDisplay(); - } + static void setImpl(FrontPanelConfigImpl* newImpl); + static FrontPanelConfig& getInstance(); + + List getIndicators(); + FrontPanelTextDisplay& getTextDisplay(const std::string& name); + List getTextDisplays(); + FrontPanelTextDisplay& getTextDisplay(int id); + FrontPanelTextDisplay& getTextDisplay() const; }; } @@ -1391,32 +1145,28 @@ class rtObjectBaseImpl{ }; class rtObjectBase{ - public: - rtObjectBaseImpl* impl; - static rtObjectBase& getInstance() - { - static rtObjectBase instance; - return instance; - } - rtError set(const char* name, const char* value){ - return getInstance().impl->set(name, value); - } - rtError set(const char* name, bool value){ - return getInstance().impl->set(name, value); - } - rtError set(const char* name, const rtValue& value){ - return getInstance().impl->set(name, value); - } - +protected: + static rtObjectBaseImpl* impl; +public: + + static rtObjectBase& getInstance(); + static void setImpl(rtObjectBaseImpl* newImpl); + + rtError set(const char* name, const char* value); + rtError set(const char* name, bool value); + rtError set(const char* name, const rtValue& value); + + //To avoid linker issues with templated code, the complete definition of this + //templated function is included in this header file instead of separating it to .cpp template - rtError sendReturns(const char* messageName, T& result){ - return getInstance().impl->sendReturns(messageName, result); + rtError sendReturns(const char* messageName, T& result) { + return impl->sendReturns(messageName, result); } template T get(const char* name) { - return getInstance().impl->get(name); - }; + return impl->get(name); + } virtual ~rtObjectBase() = default; }; @@ -1437,35 +1187,38 @@ class rtObjectRefImpl{ }; class rtObjectRef : public rtRef, public rtObjectBase{ - public: - rtObjectRefImpl* impl; - static rtObjectRef& getInstance() - { - static rtObjectRef instance; - return instance; - } - rtObjectRef(){} - rtObjectRef(const rtObjectRef&) = default; - rtObjectRef(const rtMapObject* o) {delete o; o = nullptr; }; - rtObjectRef& operator=(rtMapObject* o){delete o; o = nullptr; return *this;}; - rtObjectRef& operator=(const rtObjectRef&){return *this;}; - rtObjectRef& operator=(rtIObject* o){asn(o);return *this;}; - rtObjectRef& operator=(rtObjectRef&&) = default; - - rtError send(const char* messageName){ - return getInstance().impl->send(messageName); - } - rtError send(const char* messageName, const char* method, rtFunctionCallback* callback){ - return getInstance().impl->send(messageName, method, callback); - } - rtError send(const char* messageName, const rtValue& arg1){ - return getInstance().impl->send(messageName, arg1); - } - rtError send(const char* messageName, rtObjectRef& base){ - return getInstance().impl->send(messageName, base); - } - virtual ~rtObjectRef(){ - } +protected: + static rtObjectRefImpl* impl; +public: + + + static rtObjectRef& getInstance(); + + static void setImpl(rtObjectRefImpl* newImpl); + + rtObjectRef(); + + rtObjectRef(const rtObjectRef&); + + rtObjectRef(const rtMapObject* o); + + rtObjectRef& operator=(rtMapObject* o); + + rtObjectRef& operator=(const rtObjectRef&); + + rtObjectRef& operator=(rtIObject* o); + + rtObjectRef& operator=(rtObjectRef&&); + + rtError send(const char* messageName); + + rtError send(const char* messageName, const char* method, rtFunctionCallback* callback); + + rtError send(const char* messageName, const rtValue& arg1); + + rtError send(const char* messageName, rtObjectRef& base); + virtual ~rtObjectRef(); + }; class rtArrayObject; @@ -1485,45 +1238,34 @@ class rtValueImpl{ class rtValue { + protected: + static rtValueImpl* impl; public: rtValue_ mValue; - rtValueImpl* impl; - static rtValue& getInstance() - { - static rtValue instance; - return instance; - } - rtValue(){} - rtValue(bool v){mValue.boolValue =v;} - rtValue(const char* v){mValue.stringValue = (char*)v;} - rtValue(const rtString& v){mValue.stringValue = v.cString();} - rtValue(rtIObject* v){ - if(v){ - delete v; - v = nullptr; - } - } - rtValue(const rtObjectRef& v){} - rtValue(const rtValue& v){} - ~rtValue(){} - rtValue& operator=(bool v) { mValue.boolValue = v; return *this; } - rtValue& operator=(const char* v) { mValue.stringValue = (char*)v; return *this; } - rtValue& operator=(const rtString& v) { mValue.stringValue = v.cString(); return *this; } - rtValue& operator=(const rtIObject* v) { delete v; v = nullptr; return *this; } - rtValue& operator=(const rtObjectRef& v) { return *this; } - rtValue& operator=(const rtValue& v) { return *this; } - - rtObjectRef toObject() const { - rtObjectRef v; - return v; - } - void setString (const char* v){ - mValue.stringValue = (char*)v; - } - void setString (const rtString& v){ - mValue.stringValue = v.cString(); - } - + + static rtValue& getInstance(); + static void setImpl(rtValueImpl* newImpl); + + rtValue(); + rtValue(bool v); + rtValue(const char* v); + rtValue(const rtString& v); + rtValue(rtIObject* v); + + rtValue(const rtObjectRef& v); + rtValue(const rtValue& v); + ~rtValue(); + rtValue& operator=(bool v); + rtValue& operator=(const char* v); + rtValue& operator=(const rtString& v); + rtValue& operator=(const rtIObject* v); + rtValue& operator=(const rtObjectRef& v); + rtValue& operator=(const rtValue& v); + + rtObjectRef toObject() const; + void setString (const char* v); + void setString (const rtString& v); + }; class rtArrayObjectImpl{ @@ -1534,19 +1276,14 @@ class rtArrayObjectImpl{ class rtArrayObject : public rtObjectBase, public rtIObject{ - public: - rtArrayObjectImpl* impl; - static rtArrayObject& getInstance() - { - static rtArrayObject instance; - return instance; - } - void pushBack(const char* v){ - getInstance().impl->pushBack(v); - } - void pushBack(rtValue v){ - getInstance().impl->pushBack(v); - } +protected: + static rtArrayObjectImpl* impl; +public: + static rtArrayObject& getInstance(); + static void setImpl(rtArrayObjectImpl* newImpl); + + void pushBack(const char* v); + void pushBack(rtValue v); virtual ~rtArrayObject() = default; }; @@ -1569,32 +1306,17 @@ class floatingRtFunctionsImpl{ }; class floatingRtFunctions{ - public: - floatingRtFunctionsImpl* impl; - static floatingRtFunctions& getInstance() - { - static floatingRtFunctions instance; - return instance; - } - +public: + static floatingRtFunctionsImpl* impl; + static floatingRtFunctions& getInstance(); + static void setImpl(floatingRtFunctionsImpl* newImpl); }; -inline rtError rtRemoteProcessSingleItem(){ - return floatingRtFunctions::getInstance().impl->rtRemoteProcessSingleItem(); -} -inline rtError rtRemoteLocateObject(rtRemoteEnvironment *env, const char* str, rtObjectRef& obj, int x, remoteDisconnectCallback back, void *cbdata=NULL){ - return floatingRtFunctions::getInstance().impl->rtRemoteLocateObject(env, str, obj, x, back, cbdata); -} -inline rtRemoteEnvironment* rtEnvironmentGetGlobal(){ - return floatingRtFunctions::getInstance().impl->rtEnvironmentGetGlobal(); -} -inline rtError rtRemoteInit(rtRemoteEnvironment *env){ - return floatingRtFunctions::getInstance().impl->rtRemoteInit(env); -} -inline rtError rtRemoteShutdown(rtRemoteEnvironment *env){ - return floatingRtFunctions::getInstance().impl->rtRemoteShutdown(env); -} -inline char* rtStrError(rtError err){ - return floatingRtFunctions::getInstance().impl->rtStrError(err); -} + rtError rtRemoteProcessSingleItem(); + rtError rtRemoteLocateObject(rtRemoteEnvironment* env, const char* str, rtObjectRef& obj, int x, remoteDisconnectCallback back, void* cbdata = nullptr); + rtRemoteEnvironment* rtEnvironmentGetGlobal(); + rtError rtRemoteInit(rtRemoteEnvironment* env); + rtError rtRemoteShutdown(rtRemoteEnvironment* env); + char* rtStrError(rtError err); + diff --git a/Tests/mocks/rdkshell.cpp b/Tests/mocks/rdkshell.cpp index 13f7231024..1895c580f2 100644 --- a/Tests/mocks/rdkshell.cpp +++ b/Tests/mocks/rdkshell.cpp @@ -1,5 +1,582 @@ #include "rdkshell.h" +#include #define RDKSHELL_FPS 40 int gCurrentFramerate = RDKSHELL_FPS; +RDKShellImpl* RDKShell::impl = nullptr; + +RDKShell::RDKShell() {} + +void RDKShell::setImpl(RDKShellImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + + +bool RDKShell::keyCodeFromWayland(uint32_t waylandKeyCode, uint32_t waylandFlags, uint32_t &mappedKeyCode, uint32_t &mappedFlags) +{ + EXPECT_NE(impl, nullptr); + return impl->keyCodeFromWayland(waylandKeyCode, waylandFlags, mappedKeyCode, mappedFlags); +} + +bool (*keyCodeFromWayland)(uint32_t waylandKeyCode, uint32_t waylandFlags, uint32_t &mappedKeyCode, uint32_t &mappedFlags)= &RDKShell::keyCodeFromWayland; + +namespace RdkShell +{ + + RdkShellEvent* RdkShellEventListener::impl = nullptr; + RdkShellEventListener::RdkShellEventListener() {} + +void RdkShellEventListener::setImpl(RdkShellEvent* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + + void RdkShellEventListener::onApplicationLaunched(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onApplicationLaunched(client); + } + void RdkShellEventListener::onApplicationConnected(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onApplicationConnected(client); + } + void RdkShellEventListener::onApplicationDisconnected(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onApplicationDisconnected(client); + } + void RdkShellEventListener::onApplicationTerminated(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onApplicationTerminated(client); + } + void RdkShellEventListener::onApplicationFirstFrame(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onApplicationFirstFrame(client); + } + void RdkShellEventListener::onApplicationSuspended(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onApplicationSuspended(client); + } + void RdkShellEventListener::onApplicationResumed(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onApplicationResumed(client); + } + void RdkShellEventListener::onApplicationActivated(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onApplicationActivated(client); + } + void RdkShellEventListener::onUserInactive(const double minutes) + { + EXPECT_NE(impl, nullptr); + impl->onUserInactive(minutes); + } + void RdkShellEventListener::onDeviceLowRamWarning(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) + { + EXPECT_NE(impl, nullptr); + impl->onDeviceLowRamWarning(freeKb, availableKb, usedSwapKb); + } + void RdkShellEventListener::onDeviceCriticallyLowRamWarning(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) + { + EXPECT_NE(impl, nullptr); + impl->onDeviceCriticallyLowRamWarning(freeKb, availableKb, usedSwapKb); + } + void RdkShellEventListener::onDeviceLowRamWarningCleared(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) + { + EXPECT_NE(impl, nullptr); + impl->onDeviceLowRamWarningCleared(freeKb, availableKb, usedSwapKb); + } + void RdkShellEventListener::onDeviceCriticallyLowRamWarningCleared(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) + { + EXPECT_NE(impl, nullptr); + impl->onDeviceCriticallyLowRamWarningCleared(freeKb, availableKb, usedSwapKb); + } + void RdkShellEventListener::onEasterEgg(const std::string& name, const std::string& actionJson) + { + EXPECT_NE(impl, nullptr); + impl->onEasterEgg(name, actionJson); + } + void RdkShellEventListener::onPowerKey() + { + EXPECT_NE(impl, nullptr); + impl->onPowerKey(); + } + void RdkShellEventListener::onSizeChangeComplete(const std::string& client) + { + EXPECT_NE(impl, nullptr); + impl->onSizeChangeComplete(client); + } + +LoggerImpl* Logger::impl = nullptr; +Logger::Logger() {} + +void Logger::setImpl(LoggerImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +void Logger::enableFlushing(bool enable) +{ + EXPECT_NE(impl, nullptr); + impl->enableFlushing(enable); +} +bool Logger::isFlushingEnabled() +{ + EXPECT_NE(impl, nullptr); + return impl->isFlushingEnabled(); +} + +RdkShellApiImpl* RdkShellApi::impl = nullptr; + +RdkShellApi::RdkShellApi() {} + +void RdkShellApi::setImpl(RdkShellApiImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + + +void RdkShellApi::addEasterEgg(std::vector& details, std::string name, uint32_t timeout, std::string actionJson) +{ + EXPECT_NE(impl, nullptr); + impl->addEasterEgg(details, name, timeout, actionJson); +} +void RdkShellApi::removeEasterEgg(std::string name) +{ + EXPECT_NE(impl, nullptr); + impl->removeEasterEgg(name); +} +void RdkShellApi::getEasterEggs(std::vector& easterEggs) +{ + EXPECT_NE(impl, nullptr); + impl->getEasterEggs(easterEggs); +} +void RdkShellApi::initialize() +{ + EXPECT_NE(impl, nullptr); + impl->initialize(); +} +void RdkShellApi::update() +{ + EXPECT_NE(impl, nullptr); + impl->update(); +} +void RdkShellApi::draw() +{ + EXPECT_NE(impl, nullptr); + impl->draw(); +} +void RdkShellApi::deinitialize() +{ + EXPECT_NE(impl, nullptr); + impl->deinitialize(); +} +double RdkShellApi::seconds() +{ + EXPECT_NE(impl, nullptr); + return impl->seconds(); +} +double RdkShellApi::milliseconds() +{ + EXPECT_NE(impl, nullptr); + return impl->milliseconds(); +} +double RdkShellApi::microseconds() +{ + EXPECT_NE(impl, nullptr); + return impl->microseconds(); +} +bool RdkShellApi::systemRam(uint32_t& freeKb, uint32_t& totalKb, uint32_t& availableKb, uint32_t& usedSwapKb) +{ + EXPECT_NE(impl, nullptr); + return impl->systemRam(freeKb, totalKb, availableKb, usedSwapKb); +} +void RdkShellApi::setMemoryMonitor(std::map &configuration) +{ + EXPECT_NE(impl, nullptr); + impl->setMemoryMonitor(configuration); +} + +void (*addEasterEgg)(std::vector&, std::string, uint32_t, std::string) = &RdkShellApi::addEasterEgg; +void (*removeEasterEgg)(std::string) = &RdkShellApi::removeEasterEgg; +void (*getEasterEggs)(std::vector&) = &RdkShellApi::getEasterEggs; +void (*initialize)() = &RdkShellApi::initialize; +void (*update)() = &RdkShellApi::update; +void (*draw)() = &RdkShellApi::draw; +void (*deinitialize)() = &RdkShellApi::deinitialize; +double (*seconds)() = &RdkShellApi::seconds; +double (*milliseconds)() = &RdkShellApi::milliseconds; +double (*microseconds)() = &RdkShellApi::microseconds; +bool (*systemRam)(uint32_t&, uint32_t&, uint32_t&, uint32_t&) = &RdkShellApi::systemRam; +void (*setMemoryMonitor)(std::map&) = &RdkShellApi::setMemoryMonitor; + + +CompositorControllerImpl* CompositorController::impl = nullptr; + +CompositorController::CompositorController() {} + +void CompositorController::setImpl(CompositorControllerImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +bool CompositorController::setVisibility(const std::string& client, const bool visible) +{ + return impl->setVisibility(client, visible); +} +bool CompositorController::moveToFront(const std::string& client) +{ + return impl->moveToFront(client); +} +bool CompositorController::moveToBack(const std::string& client) +{ + return impl->moveToBack(client); +} +bool CompositorController::moveBehind(const std::string& client, const std::string& target) +{ + return impl->moveBehind(client, target); +} +bool CompositorController::setFocus(const std::string& client) +{ + return impl->setFocus(client); +} +bool CompositorController::getFocused(std::string& client) +{ + return impl->getFocused(client); +} + bool CompositorController::kill(const std::string& client) +{ + return impl->kill(client); +} +bool CompositorController::addKeyIntercept(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) +{ + return impl->addKeyIntercept(client, keyCode, flags); +} +bool CompositorController::removeKeyIntercept(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) +{ + return impl->removeKeyIntercept(client, keyCode, flags); +} +bool CompositorController::addKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::map &listenerProperties) +{ + return impl->addKeyListener(client, keyCode, flags, listenerProperties); +} +bool CompositorController::addNativeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::map &listenerProperties) +{ + return impl->addNativeKeyListener(client, keyCode, flags, listenerProperties); +} +bool CompositorController::removeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) +{ + return impl->removeKeyListener(client, keyCode, flags); +} + bool CompositorController::removeNativeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) +{ + return impl->removeNativeKeyListener(client, keyCode, flags); +} +bool CompositorController::addKeyMetadataListener(const std::string& client) +{ + return impl->addKeyMetadataListener(client); +} +bool CompositorController::removeKeyMetadataListener(const std::string& client) +{ + return impl->removeKeyMetadataListener(client); +} +bool CompositorController::injectKey(const uint32_t& keyCode, const uint32_t& flags) +{ + return impl->injectKey(keyCode, flags); +} +bool CompositorController::generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey) +{ + return impl->generateKey(client, keyCode, flags, virtualKey); +} +bool CompositorController::generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey, double duration) +{ + return impl->generateKey(client, keyCode, flags, virtualKey, duration); +} + +bool CompositorController::getScreenResolution(uint32_t &width, uint32_t &height) +{ + return impl->getScreenResolution(width,height); +} +bool CompositorController::setScreenResolution(const uint32_t width, const uint32_t height) +{ + return impl->setScreenResolution(width,height); +} +bool CompositorController::getClients(std::vector& clients) +{ + return impl->getClients(clients); +} +bool CompositorController::getZOrder(std::vector&clients) +{ + return impl->getZOrder(clients); +} +bool CompositorController::getBounds(const std::string& client, uint32_t &x, uint32_t &y, uint32_t &width, uint32_t &height) +{ + return impl->getBounds(client, x, y, width, height); +} +bool CompositorController::setBounds(const std::string& client, const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height ) +{ + return impl->setBounds(client, x, y, width, height); +} +bool CompositorController::getVisibility(const std::string& client, bool& visible) +{ + return impl->getVisibility(client, visible); +} +bool CompositorController::getOpacity(const std::string& client, unsigned int& opacity) +{ + return impl->getOpacity(client, opacity); +} +bool CompositorController::setOpacity(const std::string& client, const unsigned int opacity) +{ + return impl->setOpacity(client, opacity); +} +bool CompositorController::getScale(const std::string& client, double &scaleX, double &scaleY) +{ + return impl->getScale(client, scaleX, scaleY); +} +bool CompositorController::setScale(const std::string& client, double scaleX, double scaleY) +{ + return impl->setScale(client, scaleX, scaleY); +} +bool CompositorController::getHolePunch(const std::string& client, bool& holePunch) +{ + return impl->getHolePunch(client, holePunch); +} +bool CompositorController::setHolePunch(const std::string& client, const bool holePunch) +{ + return impl->setHolePunch(client, holePunch); +} +bool CompositorController::scaleToFit(const std::string& client, const int32_t x, const int32_t y, const uint32_t width, const uint32_t height) +{ + return impl->scaleToFit(client,x,y,width,height); +} +bool CompositorController::createDisplay(const std::string& client, const std::string& displayName, uint32_t displayWidth, uint32_t displayHeight, + bool virtualDisplayEnabled, uint32_t virtualWidth, uint32_t virtualHeight, bool topmost, bool focus , bool autodestroy) +{ + return impl->createDisplay(client, displayName, displayWidth, displayHeight, virtualDisplayEnabled, virtualWidth, virtualHeight, topmost, focus, autodestroy); +} +bool CompositorController::addAnimation(const std::string& client, double duration, std::map &animationProperties) +{ + return impl->addAnimation(client, duration, animationProperties); +} +bool CompositorController::removeAnimation(const std::string& client) +{ + return impl->removeAnimation(client); +} +bool CompositorController::addListener(const std::string& client, std::shared_ptr listener) +{ + return impl->addListener(client, listener); +} +bool CompositorController::removeListener(const std::string& client, std::shared_ptr listener) +{ + return impl->removeListener(client, listener); +} +void CompositorController::enableInactivityReporting(const bool enable) +{ + EXPECT_NE(impl, nullptr); + impl->enableInactivityReporting(enable); +} +void CompositorController::setInactivityInterval(const double minutes) +{ + EXPECT_NE(impl, nullptr); + impl->setInactivityInterval(minutes); +} +void CompositorController::resetInactivityTime() +{ + EXPECT_NE(impl, nullptr); + impl->resetInactivityTime(); +} +void CompositorController::setEventListener(std::shared_ptr listener) +{ + EXPECT_NE(impl, nullptr); + impl->setEventListener(listener); +} +bool CompositorController::launchApplication(const std::string& client, const std::string& uri, const std::string& mimeType, bool topmost, bool focus) +{ + EXPECT_NE(impl, nullptr); + return impl->launchApplication(client, uri, mimeType, topmost, focus); +} +bool CompositorController::suspendApplication(const std::string& client) +{ + EXPECT_NE(impl, nullptr); + return impl->suspendApplication(client); +} +bool CompositorController::resumeApplication(const std::string& client) +{ + EXPECT_NE(impl, nullptr); + return impl->resumeApplication(client); +} +bool CompositorController::getMimeType(const std::string& client, std::string& mimeType) +{ + EXPECT_NE(impl, nullptr); + return impl->getMimeType(client, mimeType); +} +bool CompositorController::setMimeType(const std::string& client, const std::string& mimeType) +{ + EXPECT_NE(impl, nullptr); + return impl->setMimeType(client, mimeType); +} +bool CompositorController::hideSplashScreen() +{ + EXPECT_NE(impl, nullptr); + return impl->hideSplashScreen(); +} +bool CompositorController::showSplashScreen(uint32_t displayTimeInSeconds) +{ + EXPECT_NE(impl, nullptr); + return impl->showSplashScreen(displayTimeInSeconds); +} +bool CompositorController::hideWatermark() +{ + EXPECT_NE(impl, nullptr); + return impl->hideWatermark(); +} +bool CompositorController::showWatermark() +{ + EXPECT_NE(impl, nullptr); + return impl->showWatermark(); +} +bool CompositorController::hideFullScreenImage() +{ + EXPECT_NE(impl, nullptr); + return impl->hideFullScreenImage(); +} +bool CompositorController::showFullScreenImage(std::string file) +{ + EXPECT_NE(impl, nullptr); + return impl->showFullScreenImage(file); +} +bool CompositorController::setLogLevel(const std::string level) +{ + EXPECT_NE(impl, nullptr); + return impl->setLogLevel(level); +} +bool CompositorController::getLogLevel(std::string& level) +{ + EXPECT_NE(impl, nullptr); + return impl->getLogLevel(level); +} +bool CompositorController::setTopmost(const std::string& client, bool topmost, bool focus) +{ + EXPECT_NE(impl, nullptr); + return impl->setTopmost(client, topmost, focus); +} +bool CompositorController::getTopmost(std::string& client) +{ + EXPECT_NE(impl, nullptr); + return impl->getTopmost(client); +} +bool CompositorController::isSurfaceModeEnabled() +{ + EXPECT_NE(impl, nullptr); + return impl->isSurfaceModeEnabled(); +} +bool CompositorController::enableKeyRepeats(bool enable) +{ + EXPECT_NE(impl, nullptr); + return impl->enableKeyRepeats(enable); +} +bool CompositorController::getKeyRepeatsEnabled(bool& enable) +{ + EXPECT_NE(impl, nullptr); + return impl->getKeyRepeatsEnabled(enable); +} +bool CompositorController::getVirtualResolution(const std::string& client, uint32_t &virtualWidth, uint32_t &virtualHeight) +{ + EXPECT_NE(impl, nullptr); + return impl->getVirtualResolution(client, virtualWidth, virtualHeight); +} +bool CompositorController::setVirtualResolution(const std::string& client, const uint32_t virtualWidth, const uint32_t virtualHeight) +{ + EXPECT_NE(impl, nullptr); + return impl->setVirtualResolution(client, virtualWidth, virtualHeight); +} +bool CompositorController::enableVirtualDisplay(const std::string& client, const bool enable) +{ + EXPECT_NE(impl, nullptr); + return impl->enableVirtualDisplay(client, enable); +} +bool CompositorController::getVirtualDisplayEnabled(const std::string& client, bool &enabled) +{ + EXPECT_NE(impl, nullptr); + return impl->getVirtualDisplayEnabled(client, enabled); +} +bool CompositorController::getLastKeyPress(uint32_t &keyCode, uint32_t &modifiers, uint64_t ×tampInSeconds) +{ + EXPECT_NE(impl, nullptr); + return impl->getLastKeyPress(keyCode, modifiers, timestampInSeconds); +} +bool CompositorController::ignoreKeyInputs(bool ignore) +{ + EXPECT_NE(impl, nullptr); + return impl->ignoreKeyInputs(ignore); +} +bool CompositorController::screenShot(uint8_t* &data, uint32_t &size) +{ + EXPECT_NE(impl, nullptr); + return impl->screenShot(data, size); +} +bool CompositorController::enableInputEvents(const std::string& client, bool enable) +{ + EXPECT_NE(impl, nullptr); + return impl->enableInputEvents(client, enable); +} +bool CompositorController::showCursor() +{ + EXPECT_NE(impl, nullptr); + return impl->showCursor(); +} +bool CompositorController::hideCursor() +{ + EXPECT_NE(impl, nullptr); + return impl->hideCursor(); +} +bool CompositorController::setCursorSize(uint32_t width, uint32_t height) +{ + EXPECT_NE(impl, nullptr); + return impl->setCursorSize(width, height); +} +bool CompositorController::getCursorSize(uint32_t& width, uint32_t& height) +{ + EXPECT_NE(impl, nullptr); + return impl->getCursorSize(width, height); +} +void CompositorController::setKeyRepeatConfig(bool enabled, int32_t initialDelay, int32_t repeatInterval) +{ + EXPECT_NE(impl, nullptr); + impl->setKeyRepeatConfig(enabled, initialDelay, repeatInterval); +} +bool CompositorController::setAVBlocked(std::string callsign, bool blockAV) +{ + EXPECT_NE(impl, nullptr); + return impl->setAVBlocked(callsign, blockAV); +} +bool CompositorController::getBlockedAVApplications(std::vector& apps) +{ + EXPECT_NE(impl, nullptr); + return impl->getBlockedAVApplications(apps); +} +bool CompositorController::isErmEnabled() +{ + EXPECT_NE(impl, nullptr); + return impl->isErmEnabled(); +} +} + + diff --git a/Tests/mocks/rdkshell.h b/Tests/mocks/rdkshell.h index 6f4d731e01..f335c744e6 100644 --- a/Tests/mocks/rdkshell.h +++ b/Tests/mocks/rdkshell.h @@ -18,23 +18,17 @@ class RDKShellImpl { }; class RDKShell { +protected: + static RDKShellImpl* impl; public: - static RDKShell& getInstance() - { - static RDKShell instance; - return instance; - } - - RDKShellImpl* impl; - - static bool keyCodeFromWayland(uint32_t waylandKeyCode, uint32_t waylandFlags, uint32_t &mappedKeyCode, uint32_t &mappedFlags) - { - return getInstance().impl->keyCodeFromWayland(waylandKeyCode, waylandFlags, mappedKeyCode, mappedFlags); - } - + RDKShell(); + RDKShell(const RDKShell &obj) = delete; // deleted copy constructor so that copy of the instance cannot be created. + static void setImpl(RDKShellImpl* newImpl); + static bool keyCodeFromWayland(uint32_t waylandKeyCode, uint32_t waylandFlags, uint32_t &mappedKeyCode, uint32_t &mappedFlags); }; -constexpr auto keyCodeFromWayland = &RDKShell::keyCodeFromWayland; +extern bool (*keyCodeFromWayland)(uint32_t waylandKeyCode, uint32_t waylandFlags, uint32_t &mappedKeyCode, uint32_t &mappedFlags); + namespace RdkShell { class RdkShellEvent @@ -55,7 +49,7 @@ namespace RdkShell virtual void onDeviceCriticallyLowRamWarningCleared(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) = 0; virtual void onPowerKey() = 0; virtual void onSizeChangeComplete(const std::string& client) = 0; - virtual void onEasterEgg(const std::string& name, const std::string& actionJson) = 0; + virtual void onEasterEgg(const std::string& name, const std::string& actionJson) = 0; }; @@ -69,79 +63,29 @@ namespace RdkShell class RdkShellEventListener { + protected: + static RdkShellEvent* impl; public: - static RdkShellEventListener& getInstance() - { - static RdkShellEventListener instance; - return instance; - } - - RdkShellEvent* impl; - virtual void onApplicationLaunched(const std::string& client) - { - getInstance().impl->onApplicationLaunched(client); - } - virtual void onApplicationConnected(const std::string& client) - { - getInstance().impl->onApplicationConnected(client); - } - virtual void onApplicationDisconnected(const std::string& client) - { - getInstance().impl->onApplicationDisconnected(client); - } - virtual void onApplicationTerminated(const std::string& client) - { - getInstance().impl->onApplicationTerminated(client); - } - virtual void onApplicationFirstFrame(const std::string& client) - { - getInstance().impl->onApplicationFirstFrame(client); - } - virtual void onApplicationSuspended(const std::string& client) - { - getInstance().impl->onApplicationSuspended(client); - } - virtual void onApplicationResumed(const std::string& client) - { - getInstance().impl->onApplicationResumed(client); - } - virtual void onApplicationActivated(const std::string& client) - { - getInstance().impl->onApplicationActivated(client); - } - virtual void onUserInactive(const double minutes) - { - getInstance().impl->onUserInactive(minutes); - } - virtual void onDeviceLowRamWarning(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) - { - getInstance().impl->onDeviceLowRamWarning(freeKb, availableKb, usedSwapKb); - } - virtual void onDeviceCriticallyLowRamWarning(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) - { - getInstance().impl->onDeviceCriticallyLowRamWarning(freeKb, availableKb, usedSwapKb); - } - virtual void onDeviceLowRamWarningCleared(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) - { - getInstance().impl->onDeviceLowRamWarningCleared(freeKb, availableKb, usedSwapKb); - } - virtual void onDeviceCriticallyLowRamWarningCleared(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb) - { - getInstance().impl->onDeviceCriticallyLowRamWarningCleared(freeKb, availableKb, usedSwapKb); - } - virtual void onEasterEgg(const std::string& name, const std::string& actionJson) - { - getInstance().impl->onEasterEgg(name, actionJson); - } - virtual void onPowerKey() - { - getInstance().impl->onPowerKey(); - } - virtual void onSizeChangeComplete(const std::string& client) - { - getInstance().impl->onSizeChangeComplete(client); - } - const std::string RDKSHELL_EVENT_SIZE_CHANGE_COMPLETE = "onSizeChangeComplete"; + RdkShellEventListener(); + RdkShellEventListener(const RdkShellEventListener &obj) = delete; // deleted copy constructor so that copy of the instance cannot be created. + static void setImpl(RdkShellEvent* newImpl); + virtual void onApplicationLaunched(const std::string& client); + virtual void onApplicationConnected(const std::string& client); + virtual void onApplicationDisconnected(const std::string& client); + virtual void onApplicationTerminated(const std::string& client); + virtual void onApplicationFirstFrame(const std::string& client); + virtual void onApplicationSuspended(const std::string& client); + virtual void onApplicationResumed(const std::string& client); + virtual void onApplicationActivated(const std::string& client); + virtual void onUserInactive(const double minutes); + virtual void onDeviceLowRamWarning(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb); + virtual void onDeviceCriticallyLowRamWarning(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb); + virtual void onDeviceLowRamWarningCleared(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb); + virtual void onDeviceCriticallyLowRamWarningCleared(const int32_t freeKb, const int32_t availableKb, const int32_t usedSwapKb); + virtual void onEasterEgg(const std::string& name, const std::string& actionJson); + virtual void onPowerKey(); + virtual void onSizeChangeComplete(const std::string& client); + const std::string RDKSHELL_EVENT_SIZE_CHANGE_COMPLETE = "onSizeChangeComplete"; }; @@ -181,103 +125,60 @@ namespace RdkShell class LoggerImpl { - public: - virtual void enableFlushing(bool enable) = 0; + public: + virtual void enableFlushing(bool enable) = 0; virtual bool isFlushingEnabled() = 0; }; class Logger { + protected: + static LoggerImpl* impl; public: - static Logger& getInstance() - { - static Logger instance; - return instance; - } - - LoggerImpl* impl; - static void enableFlushing(bool enable) - { - getInstance().impl->enableFlushing(enable); - } - static bool isFlushingEnabled() - { - return getInstance().impl->isFlushingEnabled(); - } + Logger(); + Logger(const Logger &obj) = delete; // deleted copy constructor so that copy of the instance cannot be created. + static void setImpl(LoggerImpl* newImpl); + static void enableFlushing(bool enable); + static bool isFlushingEnabled(); }; class RdkShellApi { + protected: + static RdkShellApiImpl* impl; + public: - static RdkShellApi& getInstance() - { - static RdkShellApi instance; - return instance; - } + RdkShellApi(); + RdkShellApi(const RdkShellApi& obj) = delete; - RdkShellApiImpl* impl; + static void setImpl(RdkShellApiImpl* newImpl); - static void addEasterEgg(std::vector& details, std::string name, uint32_t timeout, std::string actionJson) - { - getInstance().impl->addEasterEgg(details, name, timeout, actionJson); - } - static void removeEasterEgg(std::string name) - { - getInstance().impl->removeEasterEgg(name); - } - static void getEasterEggs(std::vector& easterEggs) - { - getInstance().impl->getEasterEggs(easterEggs); - } - static void initialize() - { - getInstance().impl->initialize(); - } - static void update() - { - getInstance().impl->update(); - } - static void draw() - { - getInstance().impl->draw(); - } - static void deinitialize() - { - getInstance().impl->deinitialize(); - } - static double seconds() - { - return getInstance().impl->seconds(); - } - static double milliseconds() - { - return getInstance().impl->milliseconds(); - } - static double microseconds() - { - return getInstance().impl->microseconds(); - } - static bool systemRam(uint32_t& freeKb, uint32_t& totalKb, uint32_t& availableKb, uint32_t& usedSwapKb) - { - return getInstance().impl->systemRam(freeKb, totalKb, availableKb, usedSwapKb); - } - static void setMemoryMonitor(std::map &configuration) - { - getInstance().impl->setMemoryMonitor(configuration); - } + static void addEasterEgg(std::vector& details, std::string name, uint32_t timeout, std::string actionJson); + static void removeEasterEgg(std::string name); + static void getEasterEggs(std::vector& easterEggs); + static void initialize(); + static void update(); + static void draw(); + static void deinitialize(); + static double seconds(); + static double milliseconds(); + static double microseconds(); + static bool systemRam(uint32_t& freeKb, uint32_t& totalKb, uint32_t& availableKb, uint32_t& usedSwapKb); + static void setMemoryMonitor(std::map &configuration); }; - constexpr auto addEasterEgg = &RdkShellApi::addEasterEgg; - constexpr auto removeEasterEgg = &RdkShellApi::removeEasterEgg; - constexpr auto getEasterEggs = &RdkShellApi::getEasterEggs; - constexpr auto initialize = &RdkShellApi::initialize; - constexpr auto deinitialize = &RdkShellApi::deinitialize; - constexpr auto update = &RdkShellApi::update; - constexpr auto draw = &RdkShellApi::draw; - constexpr auto seconds = &RdkShellApi::seconds; - constexpr auto milliseconds = &RdkShellApi::milliseconds; - constexpr auto microseconds = &RdkShellApi::microseconds; - constexpr auto systemRam = &RdkShellApi::systemRam; - constexpr auto setMemoryMonitor = &RdkShellApi::setMemoryMonitor; + + extern void (*addEasterEgg)(std::vector&, std::string, uint32_t, std::string); + extern void (*removeEasterEgg)(std::string); + extern void (*getEasterEggs)(std::vector&); + extern void (*initialize)(); + extern void (*update)(); + extern void (*draw)(); + extern void (*deinitialize)(); + extern double (*seconds)(); + extern double (*milliseconds)(); + extern double (*microseconds)(); + extern bool (*systemRam)(uint32_t&, uint32_t&, uint32_t&, uint32_t&); + extern void (*setMemoryMonitor)(std::map&); #define RDKSHELL_APPLICATION_MIME_TYPE_NATIVE "application/native" #define RDKSHELL_APPLICATION_MIME_TYPE_DAC_NATIVE "application/dac.native" @@ -355,7 +256,7 @@ namespace RdkShell virtual bool createDisplay(const std::string& client, const std::string& displayName, uint32_t displayWidth=0, uint32_t displayHeight=0, bool virtualDisplayEnabled=false, uint32_t virtualWidth=0, uint32_t virtualHeight=0, bool topmost = false, bool focus = false , bool autodestroy = true) = 0; virtual bool generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey="") = 0; - virtual bool generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey, double duration) = 0; + virtual bool generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey, double duration) = 0; virtual bool addKeyMetadataListener(const std::string& client) = 0; virtual bool removeNativeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) = 0; virtual bool addNativeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::map &listenerProperties) = 0; @@ -368,317 +269,89 @@ namespace RdkShell class CompositorController { - public: - - static CompositorController& getInstance() - { - static CompositorController instance; - return instance; - } + protected: + static CompositorControllerImpl* impl; + public: - CompositorControllerImpl* impl; - - static bool setVisibility(const std::string& client, const bool visible) - { - return getInstance().impl->setVisibility(client, visible); - } - static bool moveToFront(const std::string& client) - { - return getInstance().impl->moveToFront(client); - } - static bool moveToBack(const std::string& client) - { - return getInstance().impl->moveToBack(client); - } - static bool moveBehind(const std::string& client, const std::string& target) - { - return getInstance().impl->moveBehind(client, target); - } - static bool setFocus(const std::string& client) - { - return getInstance().impl->setFocus(client); - } - static bool getFocused(std::string& client) - { - return getInstance().impl->getFocused(client); - } - static bool kill(const std::string& client) - { - return getInstance().impl->kill(client); - } - static bool addKeyIntercept(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) - { - return getInstance().impl->addKeyIntercept(client, keyCode, flags); - } - static bool removeKeyIntercept(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) - { - return getInstance().impl->removeKeyIntercept(client, keyCode, flags); - } - static bool addKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::map &listenerProperties) - { - return getInstance().impl->addKeyListener(client, keyCode, flags, listenerProperties); - } - static bool addNativeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::map &listenerProperties) - { - return getInstance().impl->addNativeKeyListener(client, keyCode, flags, listenerProperties); - } - static bool removeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) - { - return getInstance().impl->removeKeyListener(client, keyCode, flags); - } - static bool removeNativeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags) - { - return getInstance().impl->removeNativeKeyListener(client, keyCode, flags); - } - static bool addKeyMetadataListener(const std::string& client) - { - return getInstance().impl->addKeyMetadataListener(client); - } - static bool removeKeyMetadataListener(const std::string& client) - { - return getInstance().impl->removeKeyMetadataListener(client); - } - static bool injectKey(const uint32_t& keyCode, const uint32_t& flags) - { - return getInstance().impl->injectKey(keyCode, flags); - } - static bool generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey="") - { - return getInstance().impl->generateKey(client, keyCode, flags, virtualKey); - } - static bool generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey, double duration) - { - return getInstance().impl->generateKey(client, keyCode, flags, virtualKey, duration); - } - static bool getScreenResolution(uint32_t &width, uint32_t &height) - { - return getInstance().impl->getScreenResolution(width,height); - } - static bool setScreenResolution(const uint32_t width, const uint32_t height) - { - return getInstance().impl->setScreenResolution(width,height); - } - static bool getClients(std::vector& clients) - { - return getInstance().impl->getClients(clients); - } - static bool getZOrder(std::vector&clients) - { - return getInstance().impl->getZOrder(clients); - } - static bool getBounds(const std::string& client, uint32_t &x, uint32_t &y, uint32_t &width, uint32_t &height) - { - return getInstance().impl->getBounds(client, x, y, width, height); - } - static bool setBounds(const std::string& client, const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height ) - { - return getInstance().impl->setBounds(client, x, y, width, height); - } - static bool getVisibility(const std::string& client, bool& visible) - { - return getInstance().impl->getVisibility(client, visible); - } - static bool getOpacity(const std::string& client, unsigned int& opacity) - { - return getInstance().impl->getOpacity(client, opacity); - } - static bool setOpacity(const std::string& client, const unsigned int opacity) - { - return getInstance().impl->setOpacity(client, opacity); - } - static bool getScale(const std::string& client, double &scaleX, double &scaleY) - { - return getInstance().impl->getScale(client, scaleX, scaleY); - } - static bool setScale(const std::string& client, double scaleX, double scaleY) - { - return getInstance().impl->setScale(client, scaleX, scaleY); - } - static bool getHolePunch(const std::string& client, bool& holePunch) - { - return getInstance().impl->getHolePunch(client, holePunch); - } - static bool setHolePunch(const std::string& client, const bool holePunch) - { - return getInstance().impl->setHolePunch(client, holePunch); - } - static bool scaleToFit(const std::string& client, const int32_t x, const int32_t y, const uint32_t width, const uint32_t height) - { - return getInstance().impl->scaleToFit(client,x,y,width,height); - } - static bool createDisplay(const std::string& client, const std::string& displayName, uint32_t displayWidth=0, uint32_t displayHeight=0, - bool virtualDisplayEnabled=false, uint32_t virtualWidth=0, uint32_t virtualHeight=0, bool topmost = false, bool focus = false , bool autodestroy = true) - { - return getInstance().impl->createDisplay(client, displayName, displayWidth, displayHeight, virtualDisplayEnabled, virtualWidth, virtualHeight, topmost, focus, autodestroy); - } - static bool addAnimation(const std::string& client, double duration, std::map &animationProperties) - { - return getInstance().impl->addAnimation(client, duration, animationProperties); - } - static bool removeAnimation(const std::string& client) - { - return getInstance().impl->removeAnimation(client); - } - static bool addListener(const std::string& client, std::shared_ptr listener) - { - return getInstance().impl->addListener(client, listener); - } - static bool removeListener(const std::string& client, std::shared_ptr listener) - { - return getInstance().impl->removeListener(client, listener); - } - static void enableInactivityReporting(const bool enable) - { - getInstance().impl->enableInactivityReporting(enable); - } - static void setInactivityInterval(const double minutes) - { - getInstance().impl->setInactivityInterval(minutes); - } - static void resetInactivityTime() - { - getInstance().impl->resetInactivityTime(); - } - static void setEventListener(std::shared_ptr listener) - { - getInstance().impl->setEventListener(listener); - } - static bool launchApplication(const std::string& client, const std::string& uri, const std::string& mimeType, bool topmost = false, bool focus = false) - { - return getInstance().impl->launchApplication(client, uri, mimeType, topmost, focus); - } - static bool suspendApplication(const std::string& client) - { - return getInstance().impl->suspendApplication(client); - } - static bool resumeApplication(const std::string& client) - { - return getInstance().impl->resumeApplication(client); - } - static bool getMimeType(const std::string& client, std::string& mimeType) - { - return getInstance().impl->getMimeType(client, mimeType); - } - static bool setMimeType(const std::string& client, const std::string& mimeType) - { - return getInstance().impl->setMimeType(client, mimeType); - } - static bool hideSplashScreen() - { - return getInstance().impl->hideSplashScreen(); - } - static bool showSplashScreen(uint32_t displayTimeInSeconds) - { - return getInstance().impl->showSplashScreen(displayTimeInSeconds); - } - static bool hideWatermark() - { - return getInstance().impl->hideWatermark(); - } - static bool showWatermark() - { - return getInstance().impl->showWatermark(); - } - static bool hideFullScreenImage() - { - return getInstance().impl->hideFullScreenImage(); - } - static bool showFullScreenImage(std::string file) - { - return getInstance().impl->showFullScreenImage(file); - } - static bool setLogLevel(const std::string level) - { - return getInstance().impl->setLogLevel(level); - } - static bool getLogLevel(std::string& level) - { - return getInstance().impl->getLogLevel(level); - } - static bool setTopmost(const std::string& client, bool topmost, bool focus = false) - { - return getInstance().impl->setTopmost(client, topmost, focus); - } - static bool getTopmost(std::string& client) - { - return getInstance().impl->getTopmost(client); - } - static bool isSurfaceModeEnabled() - { - return getInstance().impl->isSurfaceModeEnabled(); - } - static bool enableKeyRepeats(bool enable) - { - return getInstance().impl->enableKeyRepeats(enable); - } - static bool getKeyRepeatsEnabled(bool& enable) - { - return getInstance().impl->getKeyRepeatsEnabled(enable); - } - static bool getVirtualResolution(const std::string& client, uint32_t &virtualWidth, uint32_t &virtualHeight) - { - return getInstance().impl->getVirtualResolution(client, virtualWidth, virtualHeight); - } - static bool setVirtualResolution(const std::string& client, const uint32_t virtualWidth, const uint32_t virtualHeight) - { - return getInstance().impl->setVirtualResolution(client, virtualWidth, virtualHeight); - } - static bool enableVirtualDisplay(const std::string& client, const bool enable) - { - return getInstance().impl->enableVirtualDisplay(client, enable); - } - static bool getVirtualDisplayEnabled(const std::string& client, bool &enabled) - { - return getInstance().impl->getVirtualDisplayEnabled(client, enabled); - } - static bool getLastKeyPress(uint32_t &keyCode, uint32_t &modifiers, uint64_t ×tampInSeconds) - { - return getInstance().impl->getLastKeyPress(keyCode, modifiers, timestampInSeconds); - } - static bool ignoreKeyInputs(bool ignore) - { - return getInstance().impl->ignoreKeyInputs(ignore); - } - static bool screenShot(uint8_t* &data, uint32_t &size) - { - return getInstance().impl->screenShot(data, size); - } - static bool enableInputEvents(const std::string& client, bool enable) - { - return getInstance().impl->enableInputEvents(client, enable); - } - static bool showCursor() - { - return getInstance().impl->showCursor(); - } - static bool hideCursor() - { - return getInstance().impl->hideCursor(); - } - static bool setCursorSize(uint32_t width, uint32_t height) - { - return getInstance().impl->setCursorSize(width, height); - } - static bool getCursorSize(uint32_t& width, uint32_t& height) - { - return getInstance().impl->getCursorSize(width, height); - } - static void setKeyRepeatConfig(bool enabled, int32_t initialDelay, int32_t repeatInterval) - { - getInstance().impl->setKeyRepeatConfig(enabled, initialDelay, repeatInterval); - } - static bool setAVBlocked(std::string callsign, bool blockAV) - { - return getInstance().impl->setAVBlocked(callsign, blockAV); - } - static bool getBlockedAVApplications(std::vector& apps) - { - return getInstance().impl->getBlockedAVApplications(apps); - } - static bool isErmEnabled() - { - return getInstance().impl->isErmEnabled(); - } + CompositorController(); + CompositorController(const CompositorController &obj) = delete; // deleted copy constructor so that copy of the instance cannot be created. + static void setImpl(CompositorControllerImpl* newImpl); + static bool setVisibility(const std::string& client, const bool visible); + static bool moveToFront(const std::string& client); + static bool moveToBack(const std::string& client); + static bool moveBehind(const std::string& client, const std::string& target); + static bool setFocus(const std::string& client); + static bool getFocused(std::string& client); + static bool kill(const std::string& client); + static bool addKeyIntercept(const std::string& client, const uint32_t& keyCode, const uint32_t& flags); + static bool removeKeyIntercept(const std::string& client, const uint32_t& keyCode, const uint32_t& flags); + static bool addKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::map &listenerProperties); + static bool addNativeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::map &listenerProperties); + static bool removeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags); + static bool removeNativeKeyListener(const std::string& client, const uint32_t& keyCode, const uint32_t& flags); + static bool addKeyMetadataListener(const std::string& client); + static bool removeKeyMetadataListener(const std::string& client); + static bool injectKey(const uint32_t& keyCode, const uint32_t& flags); + static bool generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey=""); + static bool generateKey(const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey, double duration); + static bool getScreenResolution(uint32_t &width, uint32_t &height); + static bool setScreenResolution(const uint32_t width, const uint32_t height); + static bool getClients(std::vector& clients); + static bool getZOrder(std::vector&clients); + static bool getBounds(const std::string& client, uint32_t &x, uint32_t &y, uint32_t &width, uint32_t &height); + static bool setBounds(const std::string& client, const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height ); + static bool getVisibility(const std::string& client, bool& visible); + static bool getOpacity(const std::string& client, unsigned int& opacity); + static bool setOpacity(const std::string& client, const unsigned int opacity); + static bool getScale(const std::string& client, double &scaleX, double &scaleY); + static bool setScale(const std::string& client, double scaleX, double scaleY); + static bool getHolePunch(const std::string& client, bool& holePunch); + static bool setHolePunch(const std::string& client, const bool holePunch); + static bool scaleToFit(const std::string& client, const int32_t x, const int32_t y, const uint32_t width, const uint32_t height); + static bool createDisplay(const std::string& client, const std::string& displayName, uint32_t displayWidth = 0, uint32_t displayHeight = 0, + bool virtualDisplayEnabled = false, uint32_t virtualWidth = 0, uint32_t virtualHeight = 0, bool topmost = false, bool focus = false, bool autodestroy = true); + static bool addAnimation(const std::string& client, double duration, std::map& animationProperties); + static bool removeAnimation(const std::string& client); + static bool addListener(const std::string& client, std::shared_ptr listener); + static bool removeListener(const std::string& client, std::shared_ptr listener); + static void enableInactivityReporting(const bool enable); + static void setInactivityInterval(const double minutes); + static void resetInactivityTime(); + static void setEventListener(std::shared_ptr listener); + static bool launchApplication(const std::string& client, const std::string& uri, const std::string& mimeType, bool topmost = false, bool focus = false); + static bool suspendApplication(const std::string& client); + static bool resumeApplication(const std::string& client); + static bool getMimeType(const std::string& client, std::string& mimeType); + static bool setMimeType(const std::string& client, const std::string& mimeType); + static bool hideSplashScreen(); + static bool showSplashScreen(uint32_t displayTimeInSeconds); + static bool hideWatermark(); + static bool showWatermark(); + static bool hideFullScreenImage(); + static bool showFullScreenImage(std::string file); + static bool setLogLevel(const std::string level); + static bool getLogLevel(std::string& level); + static bool setTopmost(const std::string& client, bool topmost, bool focus = false); + static bool getTopmost(std::string& client); + static bool isSurfaceModeEnabled(); + static bool enableKeyRepeats(bool enable); + static bool getKeyRepeatsEnabled(bool& enable); + static bool getVirtualResolution(const std::string& client, uint32_t& virtualWidth, uint32_t& virtualHeight); + static bool setVirtualResolution(const std::string& client, const uint32_t virtualWidth, const uint32_t virtualHeight); + static bool enableVirtualDisplay(const std::string& client, const bool enable); + static bool getVirtualDisplayEnabled(const std::string& client, bool& enabled); + static bool getLastKeyPress(uint32_t& keyCode, uint32_t& modifiers, uint64_t& timestampInSeconds); + static bool ignoreKeyInputs(bool ignore); + static bool screenShot(uint8_t*& data, uint32_t& size); + static bool enableInputEvents(const std::string& client, bool enable); + static bool showCursor(); + static bool hideCursor(); + static bool setCursorSize(uint32_t width, uint32_t height); + static bool getCursorSize(uint32_t& width, uint32_t& height); + static void setKeyRepeatConfig(bool enabled, int32_t initialDelay, int32_t repeatInterval); + static bool setAVBlocked(std::string callsign, bool blockAV); + static bool getBlockedAVApplications(std::vector& apps); + static bool isErmEnabled(); }; diff --git a/Tests/mocks/rdkshellmock.h b/Tests/mocks/rdkshellmock.h index a00de3e0cc..9a5463c53a 100644 --- a/Tests/mocks/rdkshellmock.h +++ b/Tests/mocks/rdkshellmock.h @@ -152,6 +152,7 @@ class CompositorImplMock : public RdkShell::CompositorControllerImpl { bool virtualDisplayEnabled, uint32_t virtualWidth, uint32_t virtualHeight, bool topmost, bool focus, bool autodestroy), (override)); MOCK_METHOD(bool, generateKey, (const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey), (override)); MOCK_METHOD(bool, generateKey, (const std::string& client, const uint32_t& keyCode, const uint32_t& flags, std::string virtualKey, double duration), (override)); + MOCK_METHOD(bool, addKeyMetadataListener, (const std::string& client), (override)); MOCK_METHOD(bool, removeNativeKeyListener, (const std::string& client, const uint32_t& keyCode, const uint32_t& flags), (override)); MOCK_METHOD(bool, addNativeKeyListener, (const std::string& client, const uint32_t& keyCode, const uint32_t& flags, (std::map &listenerProperties)), (override)); diff --git a/Tests/mocks/thunder/Module.h b/Tests/mocks/thunder/Module.h index 3b25ea1db5..289d820778 100644 --- a/Tests/mocks/thunder/Module.h +++ b/Tests/mocks/thunder/Module.h @@ -1,7 +1,7 @@ #pragma once #ifndef MODULE_NAME -#define MODULE_NAME RdkServicesTest +#define MODULE_NAME RdkServicesL1Test #endif #include diff --git a/Warehouse/CMakeLists.txt b/Warehouse/CMakeLists.txt index f1ba7b7043..218ebf5fd6 100644 --- a/Warehouse/CMakeLists.txt +++ b/Warehouse/CMakeLists.txt @@ -55,7 +55,7 @@ endif(DS_FOUND) #target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS} ../helpers) #target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES}) -if (NOT RDK_SERVICES_TEST) +if (NOT RDK_SERVICES_L1_TEST) target_compile_options(${MODULE_NAME} PRIVATE -Wno-error) endif () diff --git a/XCast/CMakeLists.txt b/XCast/CMakeLists.txt index 43418eec25..0290690041 100644 --- a/XCast/CMakeLists.txt +++ b/XCast/CMakeLists.txt @@ -41,9 +41,9 @@ target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS} ../hel target_include_directories(${MODULE_NAME} PRIVATE ${RFC_INCLUDE_DIRS} ../helpers) target_include_directories(${MODULE_NAME} PRIVATE $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/pxcore) -if(NOT RDK_SERVICES_TEST) +if(NOT RDK_SERVICES_L1_TEST) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins rtRemote rtCore ${RFC_LIBRARIES} ${IARMBUS_LIBRARIES}) -else(RDK_SERVICES_TEST) +else(RDK_SERVICES_L1_TEST) target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${RFC_LIBRARIES} ${IARMBUS_LIBRARIES}) endif() diff --git a/tests.cmake b/l1tests.cmake old mode 100644 new mode 100755 similarity index 100% rename from tests.cmake rename to l1tests.cmake diff --git a/l2tests.cmake b/l2tests.cmake new file mode 100755 index 0000000000..3b453d3d10 --- /dev/null +++ b/l2tests.cmake @@ -0,0 +1,100 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +message("Building for L2 tests...") + +message("Generating empty headers to suppress compiler errors") + +file(GLOB BASEDIR Tests) +set(BASEDIR ${BASEDIR}/headers) +set(EMPTY_HEADERS_DIRS + ${BASEDIR} + ${BASEDIR}/rdk/ds + ${BASEDIR}/rdk/iarmbus + ${BASEDIR}/rdk/iarmmgrs-hal + ${BASEDIR}/systemservices + ${BASEDIR}/systemservices/proc + ) + +set(EMPTY_HEADERS + ${BASEDIR}/rdk/ds/host.hpp + ${BASEDIR}/rdk/ds/videoOutputPort.hpp + ${BASEDIR}/rdk/ds/audioOutputPort.hpp + ${BASEDIR}/rdk/iarmbus/libIARM.h + ${BASEDIR}/rdk/iarmbus/libIBus.h + ${BASEDIR}/rdk/iarmbus/libIBusDaemon.h + ${BASEDIR}/rdk/iarmmgrs-hal/pwrMgr.h + ${BASEDIR}/rdk/iarmmgrs-hal/mfrMgr.h + ${BASEDIR}/rdk/iarmmgrs-hal/sysMgr.h + ${BASEDIR}/rdk/ds/sleepMode.hpp + ${BASEDIR}/rfcapi.h + ${BASEDIR}/systemservices/proc/readproc.h + ) + +file(MAKE_DIRECTORY ${EMPTY_HEADERS_DIRS}) + +file(GLOB_RECURSE EMPTY_HEADERS_AVAILABLE "${BASEDIR}/*") +if (EMPTY_HEADERS_AVAILABLE) + message("Skip already generated headers to avoid rebuild") + list(REMOVE_ITEM EMPTY_HEADERS ${EMPTY_HEADERS_AVAILABLE}) +endif () +if (EMPTY_HEADERS) + file(TOUCH ${EMPTY_HEADERS}) +endif () + +include_directories(${EMPTY_HEADERS_DIRS}) + +message("Adding compiler and linker options for all targets") + +file(GLOB BASEDIR Tests/mocks) +set(FAKE_HEADERS + ${BASEDIR}/devicesettings.h + ${BASEDIR}/Iarm.h + ${BASEDIR}/Rfc.h + ) + +foreach (file ${FAKE_HEADERS}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}") +endforeach () + +add_compile_options(-Wall -Werror) + + +add_definitions( + -DUSE_IARMBUS + -DRFC_ENABLED + -DUSE_DS + -DENABLE_THERMAL_PROTECTION + -DHAS_API_SYSTEM + -DHAS_API_POWERSTATE +) + + +message("Setting build options") +set(CMAKE_DISABLE_FIND_PACKAGE_DS ON) +set(CMAKE_DISABLE_FIND_PACKAGE_IARMBus ON) +set(CMAKE_DISABLE_FIND_PACKAGE_Udev ON) +set(CMAKE_DISABLE_FIND_PACKAGE_RFC ON) +set(CMAKE_DISABLE_FIND_PACKAGE_RBus ON) +set(CMAKE_DISABLE_FIND_PACKAGE_CEC ON) +set(CMAKE_DISABLE_FIND_PACKAGE_Dobby ON) +set(CMAKE_DISABLE_FIND_PACKAGE_CEC ON) +set(PLUGIN_SYSTEMSERVICES ON) +set(PLUGIN_L2Tests ON) +set(BUILD_SHARED_LIBS ON) +set(DS_FOUND ON)