From d3dec0751c4d6434e0d155d388fe6f6a31751beb Mon Sep 17 00:00:00 2001 From: RAFI <103924677+cmuhammedrafi@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:16:24 +0530 Subject: [PATCH] Workflow intial commit --- .github/workflows/L1-tests.yml | 204 +++ CMakeLists.txt | 5 +- Tests/.clang-format | 108 ++ Tests/L1Tests/.lcovrc_l1 | 181 +++ Tests/L1Tests/CMakeLists.txt | 68 + Tests/L1Tests/README.md | 66 + Tests/L1Tests/tests/test_Network.cpp | 1411 +++++++++++++++++ Tests/L1Tests/tests/test_WifiManager.cpp | 591 +++++++ Tests/clang.cmake | 12 + Tests/gcc-with-coverage.cmake | 1 + Tests/mocks/CMakeLists.txt | 48 + Tests/mocks/Iarm.cpp | 104 ++ Tests/mocks/Iarm.h | 754 +++++++++ Tests/mocks/IarmBusMock.h | 48 + Tests/mocks/Udev.cpp | 124 ++ Tests/mocks/Udev.h | 73 + Tests/mocks/UdevMock.h | 24 + Tests/mocks/Wraps.cpp | 151 ++ Tests/mocks/Wraps.h | 52 + Tests/mocks/WrapsMock.h | 35 + Tests/mocks/thunder/COMLinkMock.h | 18 + Tests/mocks/thunder/DispatcherMock.h | 37 + Tests/mocks/thunder/FactoriesImplementation.h | 47 + Tests/mocks/thunder/Module.cpp | 3 + Tests/mocks/thunder/Module.h | 8 + Tests/mocks/thunder/ServiceMock.h | 77 + Tests/mocks/thunder/SystemInfo.h | 63 + .../mocks/thunder/WorkerPoolImplementation.h | 44 + unit_test.cmake | 50 + 29 files changed, 4406 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/L1-tests.yml create mode 100644 Tests/.clang-format create mode 100644 Tests/L1Tests/.lcovrc_l1 create mode 100755 Tests/L1Tests/CMakeLists.txt create mode 100755 Tests/L1Tests/README.md create mode 100755 Tests/L1Tests/tests/test_Network.cpp create mode 100755 Tests/L1Tests/tests/test_WifiManager.cpp create mode 100644 Tests/clang.cmake create mode 100644 Tests/gcc-with-coverage.cmake create mode 100755 Tests/mocks/CMakeLists.txt create mode 100755 Tests/mocks/Iarm.cpp create mode 100644 Tests/mocks/Iarm.h create mode 100644 Tests/mocks/IarmBusMock.h create mode 100755 Tests/mocks/Udev.cpp create mode 100644 Tests/mocks/Udev.h create mode 100644 Tests/mocks/UdevMock.h create mode 100644 Tests/mocks/Wraps.cpp create mode 100644 Tests/mocks/Wraps.h create mode 100644 Tests/mocks/WrapsMock.h create mode 100644 Tests/mocks/thunder/COMLinkMock.h create mode 100644 Tests/mocks/thunder/DispatcherMock.h create mode 100644 Tests/mocks/thunder/FactoriesImplementation.h create mode 100644 Tests/mocks/thunder/Module.cpp create mode 100644 Tests/mocks/thunder/Module.h create mode 100644 Tests/mocks/thunder/ServiceMock.h create mode 100644 Tests/mocks/thunder/SystemInfo.h create mode 100644 Tests/mocks/thunder/WorkerPoolImplementation.h create mode 100644 unit_test.cmake diff --git a/.github/workflows/L1-tests.yml b/.github/workflows/L1-tests.yml new file mode 100644 index 00000000..9e94c6fa --- /dev/null +++ b/.github/workflows/L1-tests.yml @@ -0,0 +1,204 @@ +name: l1-test + +on: + push: + branches: [ main, develop, 'topic/**'] + pull_request: + branches: [ main, develop] + +env: + BUILD_TYPE: Debug + THUNDER_REF: "R4.4.1" + THUNDER_TOOLS_REF: "R4.4.1" + INTERFACES_REF: "R4.4.1" + +jobs: + l1-tests: + name: Build and run unit 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 cache + # Cache Thunder/ThunderInterfaces. + # https://github.com/actions/cache + # https://docs.github.com/en/rest/actions/cache + # Modify the key if changing the list. + if: ${{ !env.ACT }} + id: cache + uses: actions/cache@v3 + with: + path: | + build/Thunder + build/ThunderInterfaces + build/ThunderTools + install + !install/etc/WPEFramework/plugins + !install/usr/bin/RdkServicesL1Test + !install/usr/include/gmock + !install/usr/include/gtest + !install/usr/lib/libgmockd.a + !install/usr/lib/libgmock_maind.a + !install/usr/lib/libgtestd.a + !install/usr/lib/libgtest_maind.a + !install/usr/lib/cmake/GTest + !install/usr/lib/pkgconfig/gmock.pc + !install/usr/lib/pkgconfig/gmock_main.pc + !install/usr/lib/pkgconfig/gtest.pc + !install/usr/lib/pkgconfig/gtest_main.pc + !install/usr/lib/wpeframework/plugins + key: ${{ runner.os }}-${{ env.THUNDER_REF }}-${{ env.INTERFACES_REF }}-3 + + - 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 libnm0 git pkg-config ninja-build libssl-dev libglib2.0-dev libnm-dev libcurl4-openssl-dev valgrind lcov clang + + - name: Checkout ThunderTools + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderTools + path: ThunderTools + ref: ${{env.THUNDER_TOOLS_REF}} + - name: Build ThunderTools + if: steps.cache.outputs.cache-hit != 'true' + run: > + cmake + -S "${{github.workspace}}/ThunderTools" + -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 + + - name: Checkout Thunder + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v3 + with: + repository: rdkcentral/Thunder + path: Thunder + ref: ${{env.THUNDER_REF}} + + - name: Build Thunder + if: steps.cache.outputs.cache-hit != 'true' + run: > + 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=55555 + -DEXCEPTIONS_ENABLE=ON + && + cmake --build build/Thunder -j8 + && + cmake --install build/Thunder + + - name: Checkout ThunderInterfaces + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderInterfaces + path: ThunderInterfaces + ref: ${{env.INTERFACES_REF}} + + - name: Build ThunderInterfaces + if: steps.cache.outputs.cache-hit != 'true' + 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: Checkout networkmanager + uses: actions/checkout@v3 + with: + path: networkmanager + + - name: Generate external headers + # Empty headers to mute errors + run: > + cd "${{github.workspace}}/networkmanager/Tests/" + && + mkdir -p + headers + headers/rdk/iarmbus + headers/network + && + cd headers + && + touch + rdk/iarmbus/libIARM.h + rdk/iarmbus/libIBus.h + rdk/iarmbus/libIBusDaemon.h + network/wifiSrvMgrIarmIf.h + network/netsrvmgrIarm.h + + - name: Set clang toolchain + if: ${{ matrix.compiler == 'clang' }} + run: echo "TOOLCHAIN_FILE=${{github.workspace}}/networkmanager/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}}/networkmanager/Tests/gcc-with-coverage.cmake" >> $GITHUB_ENV + + - name: Build NetworkManager + run: > + cmake + -S "${{github.workspace}}/networkmanager" + -B build/networkmanager + -DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}" + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + -DCMAKE_CXX_FLAGS=" + -fprofile-arcs + -ftest-coverage + -DEXCEPTIONS_ENABLE=ON + -I ${{github.workspace}}/networkmanagerTests/headers + -I ${{github.workspace}}/networkmanager/Tests/headers/rdk/iarmbus + -I ${{github.workspace}}/networkmanager/Tests/headers/network + -Wall -Werror -Wno-error=format= + -Wl,-wrap,system -Wl,-wrap,popen -Wl,-wrap,syslog" + -DCMAKE_DISABLE_FIND_PACKAGE_IARMBus=ON + -DENABLE_GNOME_NETWORKMANAGER=OFF + -DENABLE_NETWORKMANAGER_UNIT_TEST=ON + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + && + cmake --build build/networkmanager -j16 + && + cmake --install build/networkmanager diff --git a/CMakeLists.txt b/CMakeLists.txt index 911b2f12..2bc5ea04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,9 +32,12 @@ if(ENABLE_GNOME_NETWORKMANAGER) pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(LIBNM REQUIRED libnm) else() -find_package(IARMBus REQUIRED) +find_package(IARMBus) endif () +if(ENABLE_NETWORKMANAGER_UNIT_TEST) + include(unit_test.cmake) +endif() message("Setup ProxyStub for INetworkManager.h") find_package(CompileSettingsDebug CONFIG REQUIRED) diff --git a/Tests/.clang-format b/Tests/.clang-format new file mode 100644 index 00000000..423360be --- /dev/null +++ b/Tests/.clang-format @@ -0,0 +1,108 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: WebKit +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeCategories: + - Regex: '^"config\.h"' + Priority: -1 + # The main header for a source file automatically gets category 0 + - Regex: '.*' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... diff --git a/Tests/L1Tests/.lcovrc_l1 b/Tests/L1Tests/.lcovrc_l1 new file mode 100644 index 00000000..879fe2ce --- /dev/null +++ b/Tests/L1Tests/.lcovrc_l1 @@ -0,0 +1,181 @@ +# +# /etc/lcovrc - system-wide defaults for LCOV +# +# To change settings for a single user, place a customized copy of this file +# at location ~/.lcovrc +# + +# Specify an external style sheet file (same as --css-file option of genhtml) +#genhtml_css_file = gcov.css + +# Specify coverage rate limits (in %) for classifying file entries +# HI: hi_limit <= rate <= 100 graph color: green +# MED: med_limit <= rate < hi_limit graph color: orange +# LO: 0 <= rate < med_limit graph color: red +genhtml_hi_limit = 75 +genhtml_med_limit = 50 + +# Width of line coverage field in source code view +genhtml_line_field_width = 12 + +# Width of branch coverage field in source code view +genhtml_branch_field_width = 16 + +# Width of overview image (used by --frames option of genhtml) +genhtml_overview_width = 80 + +# Resolution of overview navigation: this number specifies the maximum +# difference in lines between the position a user selected from the overview +# and the position the source code window is scrolled to (used by --frames +# option of genhtml) +genhtml_nav_resolution = 4 + +# Clicking a line in the overview image should show the source code view at +# a position a bit further up so that the requested line is not the first +# line in the window. This number specifies that offset in lines (used by +# --frames option of genhtml) +genhtml_nav_offset = 10 + +# Do not remove unused test descriptions if non-zero (same as +# --keep-descriptions option of genhtml) +genhtml_keep_descriptions = 0 + +# Do not remove prefix from directory names if non-zero (same as --no-prefix +# option of genhtml) +genhtml_no_prefix = 0 + +# Do not create source code view if non-zero (same as --no-source option of +# genhtml) +genhtml_no_source = 0 + +# Replace tabs with number of spaces in source view (same as --num-spaces +# option of genhtml) +genhtml_num_spaces = 8 + +# Highlight lines with converted-only data if non-zero (same as --highlight +# option of genhtml) +genhtml_highlight = 0 + +# Include color legend in HTML output if non-zero (same as --legend option of +# genhtml) +genhtml_legend = 0 + +# Use FILE as HTML prolog for generated pages (same as --html-prolog option of +# genhtml) +#genhtml_html_prolog = FILE + +# Use FILE as HTML epilog for generated pages (same as --html-epilog option of +# genhtml) +#genhtml_html_epilog = FILE + +# Use custom filename extension for pages (same as --html-extension option of +# genhtml) +#genhtml_html_extension = html + +# Compress all generated html files with gzip. +#genhtml_html_gzip = 1 + +# Include sorted overview pages (can be disabled by the --no-sort option of +# genhtml) +genhtml_sort = 1 + +# Include function coverage data display (can be disabled by the +# --no-func-coverage option of genhtml) +#genhtml_function_coverage = 1 + +# Include branch coverage data display (can be disabled by the +# --no-branch-coverage option of genhtml) +#genhtml_branch_coverage = 1 + +# Specify the character set of all generated HTML pages +genhtml_charset=UTF-8 + +# Allow HTML markup in test case description text if non-zero +genhtml_desc_html=0 + +# Specify the precision for coverage rates +#genhtml_precision=1 + +# Show missed counts instead of hit counts +#genhtml_missed=1 + +# Demangle C++ symbols +#genhtml_demangle_cpp=1 + +# Name of the tool used for demangling C++ function names +#genhtml_demangle_cpp_tool = c++filt + +# Specify extra parameters to be passed to the demangling tool +#genhtml_demangle_cpp_params = "" + +# Location of the gcov tool (same as --gcov-info option of geninfo) +#geninfo_gcov_tool = gcov + +# Adjust test names to include operating system information if non-zero +#geninfo_adjust_testname = 0 + +# Calculate checksum for each source code line if non-zero (same as --checksum +# option of geninfo if non-zero, same as --no-checksum if zero) +#geninfo_checksum = 1 + +# Specify whether to capture coverage data for external source files (can +# be overridden by the --external and --no-external options of geninfo/lcov) +#geninfo_external = 1 + +# Enable libtool compatibility mode if non-zero (same as --compat-libtool option +# of geninfo if non-zero, same as --no-compat-libtool if zero) +#geninfo_compat_libtool = 0 + +# Use gcov's --all-blocks option if non-zero +#geninfo_gcov_all_blocks = 1 + +# Specify compatiblity modes (same as --compat option of geninfo). +#geninfo_compat = libtool=on, hammer=auto, split_crc=auto + +# Adjust path to source files by removing or changing path components that +# match the specified pattern (Perl regular expression format) +#geninfo_adjust_src_path = /tmp/build => /usr/src + +# Specify if geninfo should try to automatically determine the base-directory +# when collecting coverage data. +geninfo_auto_base = 1 + +# Use gcov intermediate format? Valid values are 0, 1, auto +geninfo_intermediate = auto + +# Specify if exception branches should be excluded from branch coverage. +geninfo_no_exception_branch = 0 + +# Directory containing gcov kernel files +# lcov_gcov_dir = /proc/gcov + +# Location of the insmod tool +lcov_insmod_tool = /sbin/insmod + +# Location of the modprobe tool +lcov_modprobe_tool = /sbin/modprobe + +# Location of the rmmod tool +lcov_rmmod_tool = /sbin/rmmod + +# Location for temporary directories +lcov_tmp_dir = /tmp + +# Show full paths during list operation if non-zero (same as --list-full-path +# option of lcov) +lcov_list_full_path = 0 + +# Specify the maximum width for list output. This value is ignored when +# lcov_list_full_path is non-zero. +lcov_list_width = 80 + +# Specify the maximum percentage of file names which may be truncated when +# choosing a directory prefix in list output. This value is ignored when +# lcov_list_full_path is non-zero. +lcov_list_truncate_max = 20 + +# Specify if function coverage data should be collected and processed. +lcov_function_coverage = 1 + +# Specify if branch coverage data should be collected and processed. +lcov_branch_coverage = 0 diff --git a/Tests/L1Tests/CMakeLists.txt b/Tests/L1Tests/CMakeLists.txt new file mode 100755 index 00000000..453d624d --- /dev/null +++ b/Tests/L1Tests/CMakeLists.txt @@ -0,0 +1,68 @@ +# 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. + +cmake_minimum_required(VERSION 3.8) +project(RdkServicesL1Test) + +set(CMAKE_CXX_STANDARD 11) + +find_package(${NAMESPACE}Plugins REQUIRED) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip +) +FetchContent_MakeAvailable(googletest) +file(GLOB TESTS tests/*.cpp) +add_executable(${PROJECT_NAME} + ${TESTS} + ../mocks/Iarm.cpp + ../mocks/Udev.cpp + ../mocks/thunder/Module.cpp + ../mocks/Wraps.cpp + ) + +set_source_files_properties( + tests/test_Network.cpp + PROPERTIES COMPILE_FLAGS "-fexceptions") + +include_directories( + ../../Network + ../../WifiManager + ) +link_directories( + ../../Network + ../../WifiManager + ) + +target_link_libraries(${PROJECT_NAME} + gmock_main + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ${NAMESPACE}Network + ${NAMESPACE}WifiManager + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + ../mocks + ../mocks/thunder + ) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/Tests/L1Tests/README.md b/Tests/L1Tests/README.md new file mode 100755 index 00000000..551d0484 --- /dev/null +++ b/Tests/L1Tests/README.md @@ -0,0 +1,66 @@ +# Unit 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/l1-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 [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 [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). + +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 smallest piece of logic you can test, isolate it from other parts. + - Use One-Assert-per-Test and Arrange-Act-Assert patterns. + If two or more tests operate on similar data, use a test fixture. + - Having more constraints than necessary is bad. + If a test over-specifies, it doesn’t leave enough freedom to the implementation. + Use `ON_CALL` by default, and only use `EXPECT_CALL` when intend to verify that the call is made. + +4. Before review: + - Enable [ClangFormat](./.clang-format) and make sure the tests code is formatted. + - Make sure the code builds without warnings. + - At the bottom of the workflow summary page on GitHub, there is a section with artifacts. + Artifacts include coverage report and valgrind log. + They help to understand how much code is covered by tests and whether there are memory leaks. + Make sure you check both. \ No newline at end of file diff --git a/Tests/L1Tests/tests/test_Network.cpp b/Tests/L1Tests/tests/test_Network.cpp new file mode 100755 index 00000000..9db8a1fc --- /dev/null +++ b/Tests/L1Tests/tests/test_Network.cpp @@ -0,0 +1,1411 @@ +#include +#include +#include +#include "Network.h" +#include "NetworkConnectivity.h" + +#include "FactoriesImplementation.h" +#include "ServiceMock.h" +#include "IarmBusMock.h" +#include "WrapsMock.h" + +using namespace std; +using namespace WPEFramework; + +using ::testing::NiceMock; + +extern "C" FILE* __real_popen(const char* command, const char* type); + +class NetworkTestBase : public ::testing::Test { +public: + + WrapsImplMock *p_wrapsImplMock = nullptr ; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + + NetworkTestBase() + { + 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"; + file << "WIFI_SUPPORT=true\n"; + file << "MOCA_INTERFACE=true\n"; + file <<"WIFI_INTERFACE==wlan0\n"; + file <<"MOCA_INTERFACE=eth0\n"; + file <<"ETHERNET_INTERFACE=eth0\n"; + file.close(); + + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* command, const char* type) -> FILE* { + return __real_popen(command, type); + })); + } +}; + +class NetworkTest : public NetworkTestBase { +protected: + + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + Core::JSONRPC::Connection connection; + string response; + + Core::JSONRPC::Message message; + ServiceMock service; + + NetworkTest() : plugin(Core::ProxyType::Create()), + handler(*plugin), + connection(1, 0) + { + IARM_EventHandler_t interfaceEnabled; + IARM_EventHandler_t interfaceConnection; + IARM_EventHandler_t interfaceIpaddress; + IARM_EventHandler_t defaultInterface; + + 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) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isAvailable))); + return IARM_RESULT_SUCCESS; + }); + + 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)) { + interfaceEnabled = handler; + } + if ((string(IARM_BUS_NM_SRV_MGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS)) { + interfaceConnection = handler; + } + if ((string(IARM_BUS_NM_SRV_MGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS)) { + interfaceIpaddress = handler; + } + if ((string(IARM_BUS_NM_SRV_MGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE)) { + defaultInterface = handler; + } + return IARM_RESULT_SUCCESS; + })); + + EXPECT_EQ(string(""), plugin->Initialize(&service)); + } + + virtual ~NetworkTest() override + { + 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; + } + } +}; + +class NetworkInitializedEventTest : public NetworkTest { +protected: + FactoriesImplementation factoriesImplementation; + PluginHost::IDispatcher* dispatcher; + + + NetworkInitializedEventTest() + : NetworkTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PluginHost::IDispatcher::ID)); + dispatcher->Activate(&service); + } + + virtual ~NetworkInitializedEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + PluginHost::IFactories::Assign(nullptr); + + } +}; + +TEST_F(NetworkTest, RegisteredMethods) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getStbIp"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getInterfaces"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isInterfaceEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setInterfaceEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getDefaultInterface"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getIPSettings"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isConnectedToInternet"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getInternetConnectionState"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getPublicIP"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getSTBIPFamily"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setConnectivityTestEndpoints"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getCaptivePortalURI"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("startConnectivityMonitoring"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("stopConnectivityMonitoring"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setDefaultInterface"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setIPSettings"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("trace"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("traceNamedEndpoint"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getNamedEndpoints"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("pingNamedEndpoint"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("ping"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getQuirks"))); +} + +TEST_F(NetworkTest, getStbIp) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getSTBip))); + + auto param = static_cast(arg); + memcpy(¶m->activeIfaceIpaddr, "192.168.1.101", sizeof("192.168.1.101")); + EXPECT_EQ(string(param->activeIfaceIpaddr), string(_T("192.168.1.101"))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ip\":\"192.168.1.101\",\"success\":true}")); +} + +TEST_F(NetworkTest, getStbIp_cache) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getSTBip))); + + auto param = static_cast(arg); + memcpy(¶m->activeIfaceIpaddr, "192.168.1.101", sizeof("192.168.1.101")); + EXPECT_EQ(string(param->activeIfaceIpaddr), string(_T("192.168.1.101"))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ip\":\"192.168.1.101\",\"success\":true}")); + +} + +TEST_F(NetworkTest, getNullStbIp) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getSTBip))); + + auto param = static_cast(arg); + EXPECT_EQ(string(param->activeIfaceIpaddr), string(_T(""))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ip\":\"\",\"success\":true}")); +} + +TEST_F(NetworkTest, getFailedStbIp) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getSTBip))); + + auto param = static_cast(arg); + EXPECT_EQ(string(param->activeIfaceIpaddr), string(_T(""))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + +} + +TEST_F(NetworkTest, getInterfaces) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getInterfaceList))); + auto param = static_cast(arg); + + 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; + + 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"))); +} + +TEST_F(NetworkTest, getInterfacesFailed) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getInterfaceList))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getInterfaces"), _T("{}"), response)); +} + +TEST_F(NetworkTest, isInterfaceEnabled) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isInterfaceEnabled))); + auto param = static_cast(arg); + + memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); + param->isInterfaceEnabled = true; + + EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); + EXPECT_EQ(param->isInterfaceEnabled, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isInterfaceEnabled"), _T("{\"interface\": \"ETHERNET\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"enabled\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, isInterfaceEnabled_failed) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isInterfaceEnabled))); + auto param = static_cast(arg); + + memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); + param->isInterfaceEnabled = true; + + EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); + EXPECT_EQ(param->isInterfaceEnabled, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("isInterfaceEnabled"), _T("{\"interface\": \"ETHERNET\"}"), response)); +} + +TEST_F(NetworkTest, getDefaultInterface) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getDefaultInterface_cache) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, isInterfaceEnabled_WrongIface) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isInterfaceEnabled))); + auto param = static_cast(arg); + + memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); + param->isInterfaceEnabled = true; + + EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); + EXPECT_EQ(param->isInterfaceEnabled, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("isInterfaceEnabled"), _T("{\"interface\": \"TEST\"}"), response)); +} + +TEST_F(NetworkTest, isInterfaceEnabled_Fail) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isInterfaceEnabled))); + auto param = static_cast(arg); + + memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); + param->isInterfaceEnabled = true; + + EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); + EXPECT_EQ(param->isInterfaceEnabled, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("isInterfaceEnabled"), _T("{\"interface\": \"TEST\"}"), response)); +} + +TEST_F(NetworkTest, getIPSettings) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipversion\":\"IPV4\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"autoconfig\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipaddr\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"netmask\":\"255.255.255.0\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"gateway\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"primarydns\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"secondarydns\":\"192.168.1.2\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getIP6Settings) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->ipversion, "IPV6", sizeof("IPV6")); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV6"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV6\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipversion\":\"IPV6\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"autoconfig\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipaddr\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"netmask\":\"255.255.255.0\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"gateway\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"primarydns\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"secondarydns\":\"192.168.1.2\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getIPSettings_wifi) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "WIFI", sizeof("WIFI")); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("WIFI"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"WIFI\",\"ipversion\": \"IPV4\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"WIFI\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipversion\":\"IPV4\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"autoconfig\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipaddr\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"netmask\":\"255.255.255.0\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"gateway\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"primarydns\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"secondarydns\":\"192.168.1.2\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + +} + +TEST_F(NetworkTest, getIP6Settings_wifi) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "WIFI", sizeof("WIFI")); + memcpy(¶m->ipversion, "IPV6", sizeof("IPV6")); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("WIFI"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV6"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"WIFI\",\"ipversion\": \"IPV6\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"WIFI\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipversion\":\"IPV6\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"autoconfig\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipaddr\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"netmask\":\"255.255.255.0\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"gateway\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"primarydns\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"secondarydns\":\"192.168.1.2\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + +} + +TEST_F(NetworkTest, getIPSettings_Failed) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); +} + +TEST_F(NetworkTest, getIPSettings_WrongIface) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"TEST\",\"ipversion\": \"IPV4\"}"), response)); +} + +TEST_F(NetworkTest, getPublicIP) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getPublicIP))); + auto param = static_cast(arg); + memcpy(¶m->public_ip, "69.136.49.95", sizeof("69.136.49.95")); + + EXPECT_EQ(string(param->public_ip), string(_T("69.136.49.95"))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPublicIP"), _T("{\"iface\": \"WIFI\", \"ipv6\": false}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"public_ip\":\"69.136.49.95\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, setInterfaceEnabled) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setInterfaceEnabled))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setInterfaceEnabled"), _T("{\"interface\": \"WIFI\", \"enabled\": true, \"persist\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkTest, setInterfaceEnabled_Failed) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setInterfaceEnabled))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setInterfaceEnabled"), _T("{\"interface\": \"WIFI\", \"enabled\": true, \"persist\": true}"), response)); +} + +TEST_F(NetworkTest, setInterfaceEnabled_WrongIface) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setInterfaceEnabled))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setInterfaceEnabled"), _T("{\"interface\": \"TEST\", \"enabled\": true, \"persist\": true}"), response)); +} + +TEST_F(NetworkTest, getSTBIPFamily) +{ + + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSTBIPFamily"), _T("{\"family\": \"AF_INET\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ip\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getSTBIPFamily_Error) +{ + + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getSTBIPFamily"), _T("{\"test\": \"AF_INET\"}"), response)); +} + +TEST_F(NetworkTest, getSTBIPFamily_Failed) +{ + + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + 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->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); +} + +TEST_F(NetworkTest, setDefaultInterface) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setDefaultInterface))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setDefaultInterface"), _T("{\"interface\": \"WIFI\", \"persist\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkTest, setDefaultInterface_WrongIface) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setDefaultInterface))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setDefaultInterface"), _T("{\"interface\": \"TEST\", \"persist\": true}"), response)); +} + +TEST_F(NetworkTest, setDefaultInterface_failed) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setDefaultInterface))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setDefaultInterface"), _T("{\"interface\": \"TEST\", \"persist\": true}"), response)); +} + +TEST_F(NetworkTest, setIPSettings) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setIPSettings))); + + auto param = static_cast(arg); + param->isSupported = true; + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setIPSettings"), _T("{\"interface\": \"WIFI\", \"ipversion\": \"IPV4\",\"autoconfig\": true,\"ipaddr\": \"192.168.1.101\",\"netmask\": \"255.255.255.0\",\"gateway\": \"192.168.1.1\",\"primarydns\": \"192.168.1.1\",\"secondarydns\": \"192.168.1.2\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"supported\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + + + +//TEST_F(NetworkTest, trace) +//{ +// EXPECT_CALL(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_NM_SRV_MGR_NAME))); +// EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); +// +// auto param = static_cast(arg); +// memcpy(¶m->interface, "eth0", sizeof("eth0")); +// memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); +// +// return IARM_RESULT_SUCCESS; +// }); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("trace"), _T("{\"endpoint\":\"45.57.221.20\", \"packets\":5}"), response)); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +//} +// +TEST_F(NetworkTest, trace_fail) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("trace"), _T("{\"endpoint\":\"45.57.221.20\", \"packets\":5}"), response)); +} + +TEST_F(NetworkTest, trace_noiface) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("trace"), _T("{\"test\":\"45.57.221.20\", \"packets\":5}"), response)); +} + +//TEST_F(NetworkTest, traceNamedEndpoint) +//{ +// EXPECT_CALL(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_NM_SRV_MGR_NAME))); +// EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); +// +// auto param = static_cast(arg); +// memcpy(¶m->interface, "eth0", sizeof("eth0")); +// memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); +// +// return IARM_RESULT_SUCCESS; +// }); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("traceNamedEndpoint"), _T("{\"endpointName\": \"CMTS\", \"packets\": 5}"), response)); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +//} + +TEST_F(NetworkTest, traceNamedEndpoint_noendoint) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("traceNamedEndpoint"), _T("{\"test\": \"CMTS\", \"packets\": 5}"), response)); +} + +TEST_F(NetworkTest, traceNamedEndpoint_fail) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("traceNamedEndpoint"), _T("{\"endpointName\": \"CMTS\", \"packets\": 5}"), response)); +} + +TEST_F(NetworkTest, getNamedEndpoints) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getNamedEndpoints"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"endpoints\":[\"CMTS\"],\"success\":true}")); +} + +//TEST_F(NetworkTest, pingNamedEndpoint) +//{ +// EXPECT_CALL(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_NM_SRV_MGR_NAME))); +// EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); +// +// auto param = static_cast(arg); +// memcpy(¶m->interface, "eth0", sizeof("eth0")); +// memcpy(¶m->gateway, "127.0.0.1", sizeof("127.0.0.1")); +// +// return IARM_RESULT_SUCCESS; +// }); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("pingNamedEndpoint"), _T("{\"endpointName\": \"CMTS\", \"packets\": 5, \"guid\": \"...\"}"), response)); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"target\":\"127.0.0.1\""))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetsTransmitted\":5"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetsReceived\":5"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetLoss\":\" 0\""))); +//} + +TEST_F(NetworkTest, pingNamedEndpoint_noarg) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "127.0.0.1", sizeof("127.0.0.1")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("pingNamedEndpoint"), _T("{\"test\": \"CMTS\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +TEST_F(NetworkTest, pingNamedEndpoint_fail) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "127.0.0.1", sizeof("127.0.0.1")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("pingNamedEndpoint"), _T("{\"endpointName\": \"CMTS\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +//TEST_F(NetworkTest, ping) +//{ +// EXPECT_CALL(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_NM_SRV_MGR_NAME))); +// EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); +// +// auto param = static_cast(arg); +// memcpy(¶m->interface, "eth0", sizeof("eth0")); +// memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); +// +// return IARM_RESULT_SUCCESS; +// }); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("ping"), _T("{\"endpoint\": \"127.0.0.1\", \"packets\": 5, \"guid\": \"...\"}"), response)); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"target\":\"127.0.0.1\""))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetsTransmitted\":5"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetsReceived\":5"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetLoss\":\" 0\""))); +//} + +TEST_F(NetworkTest, ping_noendpoint) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("ping"), _T("{\"test\": \"127.0.0.1\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +TEST_F(NetworkTest, ping_fail) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("ping"), _T("{\"endpoint\": \"127.0.0.1\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +TEST_F(NetworkTest, ping_fail1) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("ping"), _T("{\"test\": \"127.0.0.1\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +TEST_F(NetworkTest, getQuirks) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getQuirks"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"quirks\":[\"RDK-20093\"],\"success\":true}")); +} + +TEST_F(NetworkTest, getInternetConnectionState) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{\"ipversion\": \"IPV6\"}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"ipversion\":\"IPV6\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"success\":true}")); +} + +TEST_F(NetworkTest, getInternetConnectionState_cache) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"ipversion\":\"IPV4\",\"success\":true}")); +} + + +TEST_F(NetworkTest, isConnectedToInternet) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV6\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV6\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"success\":true}")); +} + +TEST_F(NetworkTest, isConnectedToInternet_cache) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV6\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV6\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV6\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV6\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"success\":true}")); +} + +TEST_F(NetworkTest, getCaptivePortalURI) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getCaptivePortalURI"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"URI\":\"\",\"success\":true}")); +} + +TEST_F(NetworkInitializedEventTest, ConnectivityMonitoring) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + Core::Event onInternetStatusChange(false, true); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onInternetStatusChange\",\"params\":{\"state\":0,\"status\":\"NO_INTERNET\"}}"))); + onInternetStatusChange.SetEvent(); + return Core::ERROR_NONE; + })); + + handler.Subscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startConnectivityMonitoring"), _T("{\"interval\":6}"), response)); + EXPECT_EQ(Core::ERROR_NONE, onInternetStatusChange.Lock()); + handler.Unsubscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + EXPECT_NE(Core::ERROR_GENERAL, handler.Invoke(connection, _T("stopConnectivityMonitoring"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkTest, setConnectivityTestEndpoints) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://clients3.google.com/generate_204\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkTest, setStunEndPoint) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setStunEndPoint"), _T("{}"), response)); + //EXPECT_EQ(response, string("{\"quirks\":[\"RDK-20093\"],\"success\":true}")); +} + +TEST_F(NetworkTest, configurePNI) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_configurePNI))); + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("configurePNI"), _T("{}"), response)); +} + +TEST_F(NetworkTest, configurePNI_fail) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_configurePNI))); + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("configurePNI"), _T("{}"), response)); +} + +TEST_F(NetworkInitializedEventTest, onInterfaceStatusChanged) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getInterfaceList))); + auto param = static_cast(arg); + + 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; + + 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_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onInterfaceStatusChanged\",\"params\":{\"interface\":\"ETHERNET\",\"enabled\":true}}"))); + return Core::ERROR_NONE; + })); + IARM_BUS_NetSrvMgr_Iface_EventInterfaceEnabledStatus_t intData; + intData.status = 1; + strcpy(intData.interface,"eth0"); + handler.Subscribe(0, _T("onInterfaceStatusChanged"), _T("org.rdk.Network"), message); + plugin->eventHandler("NET_SRV_MGR", IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS, static_cast(&intData), sizeof(intData)); + handler.Unsubscribe(0, _T("onInterfaceStatusChanged"), _T("org.rdk.Network"), message); +} + +TEST_F(NetworkInitializedEventTest, onConnectionStatusChanged) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + Core::Event onInternetStatusChange(false, true); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(2) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onConnectionStatusChanged\",\"params\":{\"interface\":\"ETHERNET\",\"status\":\"CONNECTED\"}}"))); + return Core::ERROR_NONE; + })) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onInternetStatusChange\",\"params\":{\"state\":0,\"status\":\"NO_INTERNET\"}}"))); + onInternetStatusChange.SetEvent(); + return Core::ERROR_NONE; + })); + + IARM_BUS_NetSrvMgr_Iface_EventInterfaceConnectionStatus_t intData; + intData.status = 1; + strcpy(intData.interface,"eth0"); + handler.Subscribe(0, _T("onConnectionStatusChanged"), _T("org.rdk.Network"), message); + handler.Subscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + plugin->eventHandler("NET_SRV_MGR", IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS, static_cast(&intData), sizeof(intData)); + handler.Unsubscribe(0, _T("onConnectionStatusChanged"), _T("org.rdk.Network"), message); + EXPECT_EQ(Core::ERROR_NONE, onInternetStatusChange.Lock()); + handler.Unsubscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + EXPECT_NE(Core::ERROR_GENERAL, handler.Invoke(connection, _T("stopConnectivityMonitoring"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkInitializedEventTest, onIPAddressStatusChanged) +{ + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onIPAddressStatusChanged\",\"params\":{\"interface\":\"ETHERNET\",\"ip4Address\":\"192.168.1.10\",\"status\":\"ACQUIRED\"}}"))); + return Core::ERROR_NONE; + })); + IARM_BUS_NetSrvMgr_Iface_EventInterfaceIPAddress_t intData; + intData.is_ipv6 = 0; + strcpy(intData.interface,"eth0"); + intData.acquired = 1; + strcpy(intData.ip_address,"192.168.1.10"); + handler.Subscribe(0, _T("onIPAddressStatusChanged"), _T("org.rdk.Network"), message); + plugin->eventHandler("NET_SRV_MGR", IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS, static_cast(&intData), sizeof(intData)); + handler.Unsubscribe(0, _T("onIPAddressStatusChanged"), _T("org.rdk.Network"), message); +} + +TEST_F(NetworkInitializedEventTest, onDefaultInterfaceChanged) +{ +/* + 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"))); +*/ + Core::Event onDefaultInterfaceChanged(false, true); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onDefaultInterfaceChanged\",\"params\":{\"oldInterfaceName\":\"\",\"newInterfaceName\":\"ETHERNET\"}}"))); + onDefaultInterfaceChanged.SetEvent(); + return Core::ERROR_NONE; + })); + IARM_BUS_NetSrvMgr_Iface_EventDefaultInterface_t intData; + strcpy(intData.newInterface,"eth0"); + handler.Subscribe(0, _T("onDefaultInterfaceChanged"), _T("org.rdk.Network"), message); + plugin->eventHandler("NET_SRV_MGR", IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE, static_cast(&intData), sizeof(intData)); + EXPECT_EQ(Core::ERROR_NONE, onDefaultInterfaceChanged.Lock()); + handler.Unsubscribe(0, _T("onDefaultInterfaceChanged"), _T("org.rdk.Network"), message); +} + +TEST_F(NetworkInitializedEventTest, onInternetStatusChange) +{ + Core::Event onInternetStatusChange(false, true); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onInternetStatusChange\",\"params\":{\"state\":0,\"status\":\"NO_INTERNET\"}}"))); + onInternetStatusChange.SetEvent(); + return Core::ERROR_NONE; + })); + nsm_internetState intData = NO_INTERNET; + handler.Subscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + plugin->notifyInternetStatusChange(intData); + EXPECT_EQ(Core::ERROR_NONE, onInternetStatusChange.Lock()); + handler.Unsubscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); +} diff --git a/Tests/L1Tests/tests/test_WifiManager.cpp b/Tests/L1Tests/tests/test_WifiManager.cpp new file mode 100755 index 00000000..99b8e546 --- /dev/null +++ b/Tests/L1Tests/tests/test_WifiManager.cpp @@ -0,0 +1,591 @@ +#include +#include +#include "WifiManager.h" + +#include "ServiceMock.h" +#include "IarmBusMock.h" +#include "WrapsMock.h" +#include "FactoriesImplementation.h" +#include "WifiManagerDefines.h" + +using namespace WPEFramework; + +using ::testing::NiceMock; + +class WifiManagerTest : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + Core::JSONRPC::Connection connection; + string response; + Core::JSONRPC::Message message; + WrapsImplMock *p_wrapsImplMock = nullptr ; + NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ServiceMock services; + + WifiManagerTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , connection(1, 0) + { + p_wrapsImplMock = new NiceMock ; + Wraps::setImpl(p_wrapsImplMock); + + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + } + virtual ~WifiManagerTest() override + { + 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; + } + } +}; + +class WifiInitializedEventTest : public WifiManagerTest { +protected: + FactoriesImplementation factoriesImplementation; + PluginHost::IDispatcher* dispatcher; + + + WifiInitializedEventTest() + : WifiManagerTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PluginHost::IDispatcher::ID)); + dispatcher->Activate(&services); + } + + virtual ~WifiInitializedEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + PluginHost::IFactories::Assign(nullptr); + + } +}; + + +TEST_F(WifiManagerTest, TestedAPIsShouldExist) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("startScan"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("stopScan"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("connect"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("disconnect"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("cancelWPSPairing"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("saveSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("clearSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setSignalThresholdChangeEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getPairedSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getPairedSSIDInfo"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isPaired"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getCurrentState"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getConnectedSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getQuirks"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isSignalThresholdChangeEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getSupportedSecurityModes"))); +} + + +TEST_F(WifiManagerTest, setEnabled) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setInterfaceEnabled))); + auto param = static_cast(arg); + EXPECT_EQ(param->isInterfaceEnabled, true); + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enable\":true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(WifiManagerTest, getCurrentState) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getCurrentState))); + auto param = static_cast(arg); + param->data.wifiStatus = WIFI_DISCONNECTED; + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getCurrentState"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"state\":2,\"success\":true}")); // WIFI_PAIRING enum 3 +} + +TEST_F(WifiManagerTest, getPairedSSID) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSID, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ssid\":\"rdk.test.wifi.network\",\"success\":true}")); +} + +TEST_F(WifiManagerTest, getPairedSSIDi_cache) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSID, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ssid\":\"rdk.test.wifi.network\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ssid\":\"rdk.test.wifi.network\",\"success\":true}")); +} + +TEST_F(WifiManagerTest, getPairedSSID_failed) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSID, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + return IARM_RESULT_IPCCORE_FAIL; + }); + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); +} + +TEST_F(WifiManagerTest, getPairedSSIDInfo) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + memcpy(¶m->data.getPairedSSIDInfo.bssid, "ff:ff:ff:ff:ff:ff", sizeof("ff:ff:ff:ff:ff:ff")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ssid\":\"rdk.test.wifi.network\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"bssid\":\"ff:ff:ff:ff:ff:ff\""))); +} + +TEST_F(WifiManagerTest, getPairedSSIDInfo_cache) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + memcpy(¶m->data.getPairedSSIDInfo.bssid, "ff:ff:ff:ff:ff:ff", sizeof("ff:ff:ff:ff:ff:ff")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ssid\":\"rdk.test.wifi.network\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"bssid\":\"ff:ff:ff:ff:ff:ff\""))); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ssid\":\"rdk.test.wifi.network\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"bssid\":\"ff:ff:ff:ff:ff:ff\""))); +} + +TEST_F(WifiManagerTest, getPairedSSIDInfo_fail) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + memcpy(¶m->data.getPairedSSIDInfo.bssid, "ff:ff:ff:ff:ff:ff", sizeof("ff:ff:ff:ff:ff:ff")); + return IARM_RESULT_IPCCORE_FAIL; + }); + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); +} + + +TEST_F(WifiManagerTest, getConnectedSSID) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getConnectedSSID))); + auto param = static_cast(arg); + memcpy(¶m->data.getConnectedSSID.ssid, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + memcpy(¶m->data.getConnectedSSID.bssid, "ff:ff:ff:ff:ff:ff", sizeof("ff:ff:ff:ff:ff:ff")); + param->data.getConnectedSSID.rate = 130.000; + param->data.getConnectedSSID.noise = -88.000; + param->data.getConnectedSSID.securityMode = NET_WIFI_SECURITY_WPA2_PSK_AES; + param->data.getConnectedSSID.signalStrength = -33.00; + param->data.getConnectedSSID.frequency = 2437.00; + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getConnectedSSID"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ssid\":\"rdk.test.wifi.network\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"bssid\":\"ff:ff:ff:ff:ff:ff\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"rate\":\"130.000000\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"noise\":\"-88.000000\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"frequency\":\"2.437000\""))); +} + +TEST_F(WifiManagerTest, connect) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_connect))); + auto param = static_cast(arg); + param->status = true; + EXPECT_EQ(string(param->data.connect.ssid), string(_T("123412341234"))); + EXPECT_EQ(string(param->data.connect.passphrase), string(_T("password"))); + EXPECT_EQ(param->data.connect.security_mode, NET_WIFI_SECURITY_WEP_128); //securityMode: 2 (NET_WIFI_SECURITY_WEP_128) + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("connect"), _T("{\"ssid\": \"123412341234\",\"passphrase\": \"password\",\"securityMode\": 2}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(WifiManagerTest, disconnect) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_disconnectSSID))); + auto param = static_cast(arg); + param->status = true; + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("disconnect"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, saveSSID) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_saveSSID))); + auto param = static_cast(arg); + param->status = true; + EXPECT_EQ(string(param->data.connect.ssid), string(_T("123412341234"))); + EXPECT_EQ(string(param->data.connect.passphrase), string(_T("password"))); + EXPECT_EQ(param->data.connect.security_mode, NET_WIFI_SECURITY_WEP_128); //securityMode: 2 (NET_WIFI_SECURITY_WEP_128) + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("saveSSID"), _T("{\"ssid\": \"123412341234\",\"passphrase\": \"password\",\"securityMode\": 2}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, clearSSID) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_clearSSID))); + auto param = static_cast(arg); + param->status = true; + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("clearSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, isPaired) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "123412341234", sizeof("123412341234")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isPaired"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, isPaired_cache) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "123412341234", sizeof("123412341234")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isPaired"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isPaired"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, startScan) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsync))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startScan"), _T("{\"incremental\": false,\"ssid\": \"...\",\"frequency\": \"...\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsyncIncr))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startScan"), _T("{\"incremental\": true,\"ssid\": \"...\",\"frequency\": \"...\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(WifiManagerTest, stopScan) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_stopProgressiveWifiScanning))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("stopScan"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(WifiManagerTest, cancelWPSPairing) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_cancelWPSPairing))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("cancelWPSPairing"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":\"\",\"success\":true}")); +} + +TEST_F(WifiManagerTest, initiateWPSPairing) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_initiateWPSPairing))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("initiateWPSPairing"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":\"\",\"success\":true}")); +} + +TEST_F(WifiManagerTest, initiateWPSPairing2) +{ + 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_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_initiateWPSPairing2))); + return IARM_RESULT_SUCCESS; + }); + + + JsonObject jsonObj; + JsonObject res; + jsonObj["method"] = "PIN"; + jsonObj["wps_pin"] = "88888888"; + uint32_t result = plugin->initiateWPSPairing2(jsonObj,res); + EXPECT_EQ(result, 0); +} + + +TEST_F(WifiManagerTest, SignalThresholdChangeEnabled) +{ + ServiceMock service; + EXPECT_EQ(string(""), plugin->Initialize(&service)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isSignalThresholdChangeEnabled"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":1,\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setSignalThresholdChangeEnabled"), _T("{\"enabled\": true, \"interval\":2000}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isSignalThresholdChangeEnabled"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); + plugin->Deinitialize(&service); +} + +TEST_F(WifiManagerTest, getSupportedSecurityModes) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSupportedSecurityModes"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(WifiManagerTest, getQuirks) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getQuirks"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(WifiInitializedEventTest, onWIFIStateChanged) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onWIFIStateChanged\",\"params\":{\"state\":1,\"isLNF\":false}}"))); + return Core::ERROR_NONE; + })); + WPEFramework::Plugin::WifiState intData = WPEFramework::Plugin::WifiState::DISABLED; + handler.Subscribe(0, _T("onWIFIStateChanged"), _T("org.rdk.WifiManager"), message); + plugin->onWIFIStateChanged(intData,false); + handler.Unsubscribe(0, _T("onWIFIStateChanged"), _T("org.rdk.WifiManager"), message); +} + +TEST_F(WifiInitializedEventTest, onSSIDsChanged) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onSSIDsChanged\",\"params\":{}}"))); + return Core::ERROR_NONE; + })); + handler.Subscribe(0, _T("onSSIDsChanged"), _T("org.rdk.WifiManager"), message); + plugin->onSSIDsChanged(); + handler.Unsubscribe(0, _T("onSSIDsChanged"), _T("org.rdk.WifiManager"), message); +} +TEST_F(WifiInitializedEventTest, onWifiSignalThresholdChanged) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onWifiSignalThresholdChanged\",\"params\":{\"signalStrength\":\"-27.000000\",\"strength\":\"Excellent\"}}"))); + return Core::ERROR_NONE; + })); + handler.Subscribe(0, _T("onWifiSignalThresholdChanged"), _T("org.rdk.WifiManager"), message); + plugin->onWifiSignalThresholdChanged(-27.000000,"Excellent"); + handler.Unsubscribe(0, _T("onWifiSignalThresholdChanged"), _T("org.rdk.WifiManager"), message); +} + +TEST_F(WifiInitializedEventTest, onError) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onError\",\"params\":{\"code\":2}}"))); + return Core::ERROR_NONE; + })); + WPEFramework::Plugin::ErrorCode intData = WPEFramework::Plugin::ErrorCode::CONNECTION_FAILED; + handler.Subscribe(0, _T("onError"), _T("org.rdk.WifiManager"), message); + plugin->onError(intData); + handler.Unsubscribe(0, _T("onError"), _T("org.rdk.WifiManager"), message); +} + + +TEST_F(WifiInitializedEventTest, onAvailableSSIDs) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onAvailableSSIDs\",\"params\":{\"ssid\":\"123412341234\",\"security\":2,\"signalStrength\":\"-27.000000\",\"frequency\":\"2.442000\"}}"))); + return Core::ERROR_NONE; + })); + JsonObject jsonObj; + jsonObj["ssid"] = "123412341234"; + jsonObj["security"] = 2; + jsonObj["signalStrength"] = "-27.000000"; + jsonObj["frequency"] = "2.442000"; + handler.Subscribe(0, _T("onAvailableSSIDs"), _T("org.rdk.WifiManager"), message); + plugin->onAvailableSSIDs(jsonObj); + handler.Unsubscribe(0, _T("onAvailableSSIDs"), _T("org.rdk.WifiManager"), message); +} + diff --git a/Tests/clang.cmake b/Tests/clang.cmake new file mode 100644 index 00000000..f5a97f56 --- /dev/null +++ b/Tests/clang.cmake @@ -0,0 +1,12 @@ +set(CMAKE_C_COMPILER "/usr/bin/clang") +set(CMAKE_CXX_COMPILER "/usr/bin/clang++") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-command-line-argument") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=missing-braces") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=dangling-gsl") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-const-variable") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=inconsistent-missing-override") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-parameter") + +# clang Valgrind: debuginfo reader: ensure_valid failed +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gdwarf-4") diff --git a/Tests/gcc-with-coverage.cmake b/Tests/gcc-with-coverage.cmake new file mode 100644 index 00000000..cb8d689e --- /dev/null +++ b/Tests/gcc-with-coverage.cmake @@ -0,0 +1 @@ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") diff --git a/Tests/mocks/CMakeLists.txt b/Tests/mocks/CMakeLists.txt new file mode 100755 index 00000000..5029fabe --- /dev/null +++ b/Tests/mocks/CMakeLists.txt @@ -0,0 +1,48 @@ +#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/e39786088138f2749d64e9e90e0f9902daa77c40.zip +) +FetchContent_MakeAvailable(googletest) + + +add_library(${MODULE_NAME} SHARED + Rfc.cpp + Iarm.cpp + Wraps.cpp + RBus.cpp + Telemetry.cpp + devicesettings.cpp + Udev.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/Iarm.cpp b/Tests/mocks/Iarm.cpp new file mode 100755 index 00000000..63afa6f6 --- /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 new file mode 100644 index 00000000..417a2bb4 --- /dev/null +++ b/Tests/mocks/Iarm.h @@ -0,0 +1,754 @@ +#pragma once + +#include + +typedef int IARM_EventId_t; + +typedef enum _IARM_Result_t { + IARM_RESULT_SUCCESS, + IARM_RESULT_INVALID_PARAM, + IARM_RESULT_INVALID_STATE, + IARM_RESULT_IPCCORE_FAIL, + IARM_RESULT_OOM, +} IARM_Result_t; + +#define IARM_BUS_DAEMON_NAME "Daemon" + +typedef IARM_Result_t (*IARM_BusCall_t)(void* arg); +typedef void (*IARM_EventHandler_t)(const char* owner, IARM_EventId_t eventId, void* data, size_t len); + +class IarmBusImpl { +public: + virtual ~IarmBusImpl() = default; + + virtual IARM_Result_t IARM_Bus_Init(const char* name) = 0; + virtual IARM_Result_t IARM_Bus_Connect() = 0; + virtual IARM_Result_t IARM_Bus_IsConnected(const char* memberName, int* isRegistered) = 0; + virtual IARM_Result_t IARM_Bus_RegisterEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) = 0; + 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_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: + 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); +}; + +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" + +typedef enum _IARM_Bus_Daemon_PowerState_t { + IARM_BUS_PWRMGR_POWERSTATE_OFF, + IARM_BUS_PWRMGR_POWERSTATE_STANDBY, + IARM_BUS_PWRMGR_POWERSTATE_ON, + IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP, + IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP +} IARM_Bus_PowerState_t; + +typedef IARM_Bus_PowerState_t IARM_Bus_PWRMgr_PowerState_t; + +typedef enum _IARM_Bus_Daemon_SysMode_t { + IARM_BUS_SYS_MODE_NORMAL, + IARM_BUS_SYS_MODE_EAS, + IARM_BUS_SYS_MODE_WAREHOUSE +} IARM_Bus_Daemon_SysMode_t; + +#define IARMBUS_AUDIOCAPTUREMGR_NAME "audiocapturemgr" +#define IARMBUS_AUDIOCAPTUREMGR_REQUEST_SAMPLE "requestSample" + +#define IARMBUS_AUDIOCAPTUREMGR_OPEN "open" +#define IARMBUS_AUDIOCAPTUREMGR_CLOSE "close" +#define IARMBUS_AUDIOCAPTUREMGR_START "start" +#define IARMBUS_AUDIOCAPTUREMGR_STOP "stop" +#define IARMBUS_AUDIOCAPTUREMGR_GET_DEFAULT_AUDIO_PROPS "getDefaultAudioProperties" +#define IARMBUS_AUDIOCAPTUREMGR_GET_AUDIO_PROPS "getAudioProperties" +#define IARMBUS_AUDIOCAPTUREMGR_GET_OUTPUT_PROPS "getOutputProperties" +#define IARMBUS_AUDIOCAPTUREMGR_SET_AUDIO_PROPERTIES "setAudioProperties" +#define IARMBUS_AUDIOCAPTUREMGR_SET_OUTPUT_PROPERTIES "setOutputProperties" + +#define AUDIOCAPTUREMGR_FILENAME_PREFIX "audio_sample" +#define AUDIOCAPTUREMGR_FILE_PATH "/opt/" + +#define DATA_CAPTURE_IARM_EVENT_AUDIO_CLIP_READY 100 + +#define ACM_RESULT_GENERAL_FAILURE 0 +#define ACM_RESULT_PRECAPTURE_NOT_SUPPORTED 1 +#define ACM_RESULT_STREAM_UNAVAILABLE 2 +#define ACM_RESULT_DURATION_OUT_OF_BOUNDS 3 +#define BUFFERED_FILE_OUTPUT "" + +enum Format { + acmFormate16BitStereo, + acmFormate16BitMonoLeft, + acmFormate16BitMonoRight, + acmFormate16BitMono, + acmFormate24BitStereo, + acmFormate24Bit5_1 +}; + +enum Sampling_frequency { + acmFreqe48000, + acmFreqe44100, + acmFreqe32000, + acmFreqe24000, + acmFreqe16000 +}; + +namespace audiocapturemgr { +using session_id_t = int; + +struct audio_properties_ifce_t { + Format format; + Sampling_frequency sampling_frequency; +}; +} + +struct iarmbus_notification_payload_t { + char dataLocator[64]; +}; + +struct iarmbus_acm_arg_t { + struct iarmbus_open_args { + int source; + std::string output_type; + }; + + struct iarmbus_request_payload_t { + float duration; + bool is_precapture; + }; + + struct output_t { + unsigned int buffer_duration; + unsigned int max_buffer_duration; + }; + + struct arg_output_props_t { + output_t output; + }; + + struct Details { + iarmbus_open_args arg_open; + audiocapturemgr::audio_properties_ifce_t arg_audio_properties; + iarmbus_request_payload_t arg_sample_request; + arg_output_props_t arg_output_props; + }; + + int session_id; + int result; + Details details; +}; + +#define IARM_BUS_CECMGR_NAME "CECMgr" +#define IARM_BUS_CECMGR_MAX_DATA_LENGTH 62 +#define IARM_BUS_CECMGR_API_Send "Send" + +typedef struct _IARM_Bus_CECMgr_Send_Param_t { + uint8_t length; + uint8_t data[IARM_BUS_CECMGR_MAX_DATA_LENGTH + 1]; + uint8_t retVal; +} IARM_Bus_CECMgr_Send_Param_t; + +#define IARM_BUS_DEEPSLEEPMGR_NAME "DEEPSLEEPMgr" + +#define IARM_BUS_DEEPSLEEPMGR_API_GetLastWakeupReason "GetLastWakeupReason" +#define IARM_BUS_DEEPSLEEPMGR_API_GetLastWakeupKeyCode "GetLastWakeupKeycode" + +typedef enum _DeepSleep_WakeupReason_t { + DEEPSLEEP_WAKEUPREASON_IR = 0, + DEEPSLEEP_WAKEUPREASON_RCU_BT, + DEEPSLEEP_WAKEUPREASON_RCU_RF4CE, + DEEPSLEEP_WAKEUPREASON_GPIO, + DEEPSLEEP_WAKEUPREASON_LAN, + DEEPSLEEP_WAKEUPREASON_WLAN, + DEEPSLEEP_WAKEUPREASON_TIMER, + DEEPSLEEP_WAKEUPREASON_FRONT_PANEL, + DEEPSLEEP_WAKEUPREASON_WATCHDOG, + DEEPSLEEP_WAKEUPREASON_SOFTWARE_RESET, + DEEPSLEEP_WAKEUPREASON_THERMAL_RESET, + DEEPSLEEP_WAKEUPREASON_WARM_RESET, + DEEPSLEEP_WAKEUPREASON_COLDBOOT, + DEEPSLEEP_WAKEUPREASON_STR_AUTH_FAILURE, + DEEPSLEEP_WAKEUPREASON_CEC, + DEEPSLEEP_WAKEUPREASON_PRESENCE, + DEEPSLEEP_WAKEUPREASON_VOICE, + DEEPSLEEP_WAKEUPREASON_UNKNOWN +} DeepSleep_WakeupReason_t; + +typedef struct _DeepSleepMgr_WakeupKeyCode_Param_t { + unsigned int keyCode; +} DeepSleepMgr_WakeupKeyCode_Param_t; + +#define IARM_BUS_MFRLIB_NAME "MFRLib" +#define IARM_BUS_MFRLIB_API_SetBootLoaderPattern "mfrSetBootloaderPattern" +#define IARM_BUS_MFRLIB_API_SetBlSplashScreen "mfrSetBlSplashScreen" +#define IARM_BUS_MFRLIB_API_GetSerializedData "mfrGetManufacturerData" + +typedef enum _mfrSerializedType_t { + mfrSERIALIZED_TYPE_MANUFACTURER = 0, + mfrSERIALIZED_TYPE_MANUFACTUREROUI, + mfrSERIALIZED_TYPE_MODELNAME, + mfrSERIALIZED_TYPE_DESCRIPTION, + mfrSERIALIZED_TYPE_PRODUCTCLASS, + mfrSERIALIZED_TYPE_SERIALNUMBER, + mfrSERIALIZED_TYPE_HARDWAREVERSION, + mfrSERIALIZED_TYPE_SOFTWAREVERSION, + mfrSERIALIZED_TYPE_PROVISIONINGCODE, + mfrSERIALIZED_TYPE_FIRSTUSEDATE, + mfrSERIALIZED_TYPE_DEVICEMAC, + mfrSERIALIZED_TYPE_MOCAMAC, + mfrSERIALIZED_TYPE_HDMIHDCP, + mfrSERIALIZED_TYPE_PDRIVERSION, + mfrSERIALIZED_TYPE_WIFIMAC, + mfrSERIALIZED_TYPE_BLUETOOTHMAC, + mfrSERIALIZED_TYPE_WPSPIN, + mfrSERIALIZED_TYPE_MANUFACTURING_SERIALNUMBER, + mfrSERIALIZED_TYPE_ETHERNETMAC, + mfrSERIALIZED_TYPE_ESTBMAC, + mfrSERIALIZED_TYPE_RF4CEMAC, + mfrSERIALIZED_TYPE_PROVISIONED_MODELNAME, + mfrSERIALIZED_TYPE_PMI, + mfrSERIALIZED_TYPE_HWID, + mfrSERIALIZED_TYPE_MODELNUMBER, + /* boot data */ + mfrSERIALIZED_TYPE_SOC_ID, + mfrSERIALIZED_TYPE_IMAGENAME, + mfrSERIALIZED_TYPE_IMAGETYPE, + mfrSERIALIZED_TYPE_BLVERSION, + /* provisional data */ + mfrSERIALIZED_TYPE_REGION, + /* other data */ + mfrSERIALIZED_TYPE_BDRIVERSION, + /* led data */ + mfrSERIALIZED_TYPE_LED_WHITE_LEVEL, + mfrSERIALIZED_TYPE_LED_PATTERN, + mfrSERIALIZED_TYPE_MAX, +#ifdef PANEL_SERIALIZATION_TYPES + mfrSERIALIZED_TYPE_COREBOARD_SERIALNUMBER=0x51, + mfrSERIALIZED_TYPE_FACTORYBOOT, + mfrSERIALIZED_TYPE_COUNTRYCODE, + mfrSERIALIZED_TYPE_LANGUAGECODE, + mfrSERIALIZED_TYPE_MANUFACTURERDATA, + mfrSERIALIZED_TYPE_CPD_SIZE, + mfrSERIALIZED_TYPE_PANEL_ID, + mfrSERIALIZED_TYPE_PANEL_TYPE, + mfrSERIALIZED_TYPE_PANEL_HDMI_WB_DATA_NORMAL, + mfrSERIALIZED_TYPE_PANEL_HDMI_WB_DATA_COLD, + mfrSERIALIZED_TYPE_PANEL_HDMI_WB_DATA_WARM, + mfrSERIALIZED_TYPE_PANEL_HDMI_WB_DATA_USER, + mfrSERIALIZED_TYPE_PANEL_TV_WB_DATA_NORMAL, + mfrSERIALIZED_TYPE_PANEL_TV_WB_DATA_COLD, + mfrSERIALIZED_TYPE_PANEL_TV_WB_DATA_WARM, + mfrSERIALIZED_TYPE_PANEL_TV_WB_DATA_USER, + mfrSERIALIZED_TYPE_PANEL_AV_WB_DATA_NORMAL, + mfrSERIALIZED_TYPE_PANEL_AV_WB_DATA_COLD, + mfrSERIALIZED_TYPE_PANEL_AV_WB_DATA_WARM, + mfrSERIALIZED_TYPE_PANEL_AV_WB_DATA_USER, + mfrSERIALIZED_TYPE_PANEL_DTB_VERSION, + mfrSERIALIZED_TYPE_PANEL_DTB_DATA_SIZE, + mfrSERIALIZED_TYPE_PANEL_DTB_DATA, + /* panel data*/ + mfrSERIALIZED_TYPE_PANEL_DATA_FUNCTION_STATUS, + mfrSERIALIZED_TYPE_PANEL_DATA_AGEING_TIME, + mfrSERIALIZED_TYPE_PANEL_DATA_POWER_ON_TIME, + mfrSERIALIZED_TYPE_PANEL_DATA_BACKLIGHT_TIME, + mfrSERIALIZED_TYPE_PANEL_DATA_VALID, + mfrSERIALIZED_TYPE_PANEL_DATA_TPV_APP_VERSION, + mfrSERIALIZED_TYPE_PANEL_ALS_CALIBRATION_INDEX0, + mfrSERIALIZED_TYPE_PANEL_ALS_CALIBRATION_INDEX1, + mfrSERIALIZED_TYPE_MAX_PANEL, +#endif +} mfrSerializedType_t; + +typedef enum _mfrBlPattern_t { + mfrBL_PATTERN_NORMAL = 0, + mfrBL_PATTERN_SILENT, + mfrBL_PATTERN_SILENT_LED_ON +} mfrBlPattern_t; + +typedef struct _IARM_Bus_MFRLib_SetBLPattern_Param_t { + mfrBlPattern_t pattern; +} IARM_Bus_MFRLib_SetBLPattern_Param_t; + +typedef struct _IARM_Bus_MFRLib_GetSerializedData_Param_t { + mfrSerializedType_t type; + char buffer[1280]; + int bufLen; +} IARM_Bus_MFRLib_GetSerializedData_Param_t; + +#define PWRMGR_MAX_REBOOT_REASON_LENGTH 100 + +#define MAX_PWR_STATE_BEF_REBOOR_STR_LEN (32) +#define IARM_BUS_PWRMGR_API_GetPowerStateBeforeReboot "GetPowerStateBeforeReboot" +#define IARM_BUS_PWRMGR_API_SetStandbyVideoState "SetStandbyVideoState" +#define IARM_BUS_PWRMGR_API_GetStandbyVideoState "GetStandbyVideoState" +#define IARM_BUS_PWRMGR_API_SetNetworkStandbyMode "SetNetworkStandbyMode" +#define IARM_BUS_PWRMGR_API_GetNetworkStandbyMode "GetNetworkStandbyMode" +#define IARM_BUS_PWRMGR_API_Reboot "performReboot" +#define IARM_BUS_PWRMGR_API_WareHouseClear "WarehouseClear" /*!< */ +#define IARM_BUS_PWRMGR_API_ColdFactoryReset "ColdFactoryReset" /*!< Reset the box to cold factory state*/ +#define IARM_BUS_PWRMGR_API_FactoryReset "FactoryReset" /*!< Reset the box to factory state*/ +#define IARM_BUS_PWRMGR_API_UserFactoryReset "UserFactoryReset" /*!< Reset the box to user factory state*/ +#define IARM_BUS_PWRMGR_API_WareHouseReset "WareHouseReset" /*!< Reset the box to warehouse state*/ + +typedef struct _IARM_Bus_PWRMgr_NetworkStandbyMode_Param_t { + bool bStandbyMode; +} IARM_Bus_PWRMgr_NetworkStandbyMode_Param_t; + +typedef struct _IARM_Bus_PWRMgr_GetPowerStateBeforeReboot_Param_t { + char powerStateBeforeReboot[MAX_PWR_STATE_BEF_REBOOR_STR_LEN]; +} IARM_Bus_PWRMgr_GetPowerStateBeforeReboot_Param_t; + +typedef struct _IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t { + unsigned int timeout; +} IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t; + +typedef enum _IARM_Bus_PWRMgr_ThermalState_t { + IARM_BUS_PWRMGR_TEMPERATURE_NORMAL = 0, + IARM_BUS_PWRMGR_TEMPERATURE_HIGH, + IARM_BUS_PWRMGR_TEMPERATURE_CRITICAL +} IARM_Bus_PWRMgr_ThermalState_t; + +typedef enum _WakeupSrcType_t { + WAKEUPSRC_VOICE = 0, + WAKEUPSRC_PRESENCE_DETECTION, + WAKEUPSRC_BLUETOOTH, + WAKEUPSRC_WIFI, + WAKEUPSRC_IR, + WAKEUPSRC_POWER_KEY, + WAKEUPSRC_TIMER, + WAKEUPSRC_CEC, + WAKEUPSRC_LAN, + WAKEUPSRC_MAX +} WakeupSrcType_t; + +typedef struct _PWRMgr_EventData_t { + union { + struct _MODE_DATA { + IARM_Bus_PWRMgr_PowerState_t curState; + IARM_Bus_PWRMgr_PowerState_t newState; + uint32_t deep_sleep_timeout; + bool nwStandbyMode; + } state; + struct _THERM_DATA { + IARM_Bus_PWRMgr_ThermalState_t curLevel; + IARM_Bus_PWRMgr_ThermalState_t newLevel; + float curTemperature; + } therm; + bool bNetworkStandbyMode; + int32_t reset_sequence_progress; + } data; +} IARM_Bus_PWRMgr_EventData_t; + +typedef struct _IARM_Bus_PWRMgr_GetThermalState_Param_t { + IARM_Bus_PWRMgr_ThermalState_t curLevel; + float curTemperature; +} IARM_Bus_PWRMgr_GetThermalState_Param_t; + +typedef struct _IARM_Bus_PWRMgr_GetTempThresholds_Param_t { + float tempHigh; + float tempCritical; +} IARM_Bus_PWRMgr_GetTempThresholds_Param_t; + +typedef struct _IARM_Bus_PWRMgr_SetTempThresholds_Param_t { + float tempHigh; + float tempCritical; +} IARM_Bus_PWRMgr_SetTempThresholds_Param_t; + +typedef struct _IARM_Bus_PWRMgr_GetOvertempGraceInterval_Param_t { + int graceInterval; +} IARM_Bus_PWRMgr_GetOvertempGraceInterval_Param_t; + +typedef struct _IARM_Bus_PWRMgr_SetOvertempGraceInterval_Param_t { + int graceInterval; +} IARM_Bus_PWRMgr_SetOvertempGraceInterval_Param_t; + +typedef struct _IARM_Bus_CommonAPI_SysModeChange_Param_t { + IARM_Bus_Daemon_SysMode_t oldMode; + IARM_Bus_Daemon_SysMode_t newMode; +} IARM_Bus_CommonAPI_SysModeChange_Param_t; + +typedef enum _PWRMgr_EventId_t { + IARM_BUS_PWRMGR_EVENT_MODECHANGED = 0, + IARM_BUS_PWRMGR_EVENT_DEEPSLEEP_TIMEOUT, + IARM_BUS_PWRMGR_EVENT_RESET_SEQUENCE, + IARM_BUS_PWRMGR_EVENT_REBOOTING, + IARM_BUS_PWRMGR_EVENT_THERMAL_MODECHANGED, + IARM_BUS_PWRMGR_EVENT_WAREHOUSEOPS_STATUSCHANGED, + IARM_BUS_PWRMGR_EVENT_NETWORK_STANDBYMODECHANGED, + IARM_BUS_PWRMGR_EVENT_MAX, +} IARM_Bus_PWRMgr_EventId_t; + +typedef struct _IARM_Bus_PWRMgr_RebootParam_t { + char reboot_reason_custom[PWRMGR_MAX_REBOOT_REASON_LENGTH]; + char reboot_reason_other[PWRMGR_MAX_REBOOT_REASON_LENGTH]; + char requestor[PWRMGR_MAX_REBOOT_REASON_LENGTH]; +} IARM_Bus_PWRMgr_RebootParam_t; + +#define IARM_BUS_PWRMGR_NAME "PWRMgr" +#define IARM_BUS_PWRMGR_API_SetPowerState "SetPowerState" +#define IARM_BUS_PWRMGR_API_GetPowerState "GetPowerState" + +typedef struct _IARM_Bus_PWRMgr_SetPowerState_Param_t { + IARM_Bus_PWRMgr_PowerState_t newState; + int keyCode; +} IARM_Bus_PWRMgr_SetPowerState_Param_t; + +typedef struct _IARM_Bus_PWRMgr_GetPowerState_Param_t { + IARM_Bus_PWRMgr_PowerState_t curState; +} IARM_Bus_PWRMgr_GetPowerState_Param_t; + +#define IARM_BUS_PWRMGR_API_GetThermalState "GetThermalState" +#define IARM_BUS_PWRMGR_API_GetTemperatureThresholds "GetTemperatureThresholds" +#define IARM_BUS_PWRMGR_API_SetTemperatureThresholds "SetTemperatureThresholds" +#define IARM_BUS_PWRMGR_API_GetOvertempGraceInterval "GetOvertempGraceInterval" +#define IARM_BUS_PWRMGR_API_SetOvertempGraceInterval "SetOvertempGraceInterval" + +/** + * @brief Structure which holds the wakeup source type and the value to be set and the power state. + */ +typedef struct _IARM_Bus_PWRMgr_WakeupSrcConfig_Param_t{ + uint32_t pwrMode; + uint32_t srcType; + uint32_t config; +} IARM_Bus_PWRMgr_WakeupSrcConfig_Param_t; +/** + * @brief Structure which holds the ware house reset time. + */ +typedef struct _IARM_Bus_PWRMgr_WareHouseReset_Param_t { + bool suppressReboot; /*!< STB should not be rebooted */ +} IARM_Bus_PWRMgr_WareHouseReset_Param_t; + +/** + * @brief Enumerator which represents the possible warehouse ops + */ +typedef enum _IARM_Bus_PWRMgr_WareHouseOpsStatus_t{ + IARM_BUS_PWRMGR_WAREHOUSE_COMPLETED = 0, /* warehouse operation completed sucessfully */ + IARM_BUS_PWRMGR_WAREHOUSE_INPROGRESS, /* warehouse operation in progress*/ + IARM_BUS_PWRMGR_WAREHOUSE_FAILED, /* warehouse operation failed.*/ +} IARM_Bus_PWRMgr_WareHouseOpsStatus_t; + +/** + * @brief Enumerator which represents the possible warehouse ops + */ +typedef enum _IARM_Bus_PWRMgr_WareHouseOps_t{ + IARM_BUS_PWRMGR_WAREHOUSE_RESET = 0, /* warehouse reset */ + IARM_BUS_PWRMGR_WAREHOUSE_CLEAR, /* warehouse clear*/ +} IARM_Bus_PWRMgr_WareHouseOps_t; + +/** + * @brief Structure which holds warehouse opn status value. + */ +typedef struct _IARM_BUS_PWRMgr_WareHouseOpn_EventData_t { + IARM_Bus_PWRMgr_WareHouseOps_t wareHouseOpn; /*!< WareHouse operation*/ + IARM_Bus_PWRMgr_WareHouseOpsStatus_t status; /*!< WareHouse operation status*/ +} IARM_BUS_PWRMgr_WareHouseOpn_EventData_t; + +#define IARM_BUS_PWRMGR_API_SetWakeupSrcConfig "setWakeupSrcConfig" +#define IARM_BUS_PWRMGR_API_GetWakeupSrcConfig "getWakeupSrcConfig" /*!< gets wakup configuration*/ + +#define IARM_BUS_SYSMGR_NAME "SYSMgr" +#define IARM_BUS_SYSMGR_API_GetSystemStates "GetSystemStates" + +/** + * @brief Structure which holds RFC device management update information. + */ +typedef struct _IARM_BUS_SYSMGR_DeviceMgtUpdateInfo_Param_t +{ + char source[10]; /*!< Device Management Update source. Ex: rfc */ + char type[10]; /*!< Device Management Update type. Ex: initial */ + bool status; /*!< Device Management Update status. true/false */ +} IARM_BUS_SYSMGR_DeviceMgtUpdateInfo_Param_t; + +typedef enum _SYSMgr_EventId_t { + IARM_BUS_SYSMGR_EVENT_SYSTEMSTATE, + IARM_BUS_SYSMGR_EVENT_XUPNP_DATA_REQUEST, /*!< Xupnp data request frm Receiver to UPNP*/ + IARM_BUS_SYSMGR_EVENT_XUPNP_DATA_UPDATE, /*!< Xupnp data frm UPNP to Receiver*/ + IARM_BUS_SYSMGR_EVENT_IMAGE_DNLD, /*Image download status to Receiver */ + IARM_BUS_SYSMGR_EVENT_CARD_FWDNLD, /*!< CARD FW download event to Receiver - Valid on Cisco CA*/ + IARM_BUS_SYSMGR_EVENT_HDCP_PROFILE_UPDATE, /*!< HDCP Profile Update */ + IARM_BUS_SYSMGR_EVENT_INTRUSION, /*!< Intrusion Detection */ + IARM_BUS_SYSMGR_EVENT_EISS_FILTER_STATUS, /*!< EISS Filter status event */ + IARM_BUS_SYSMGR_EVENT_EISS_APP_ID_UPDATE, /*!< EISS App ID update */ + IARM_BUS_SYSMGR_EVENT_KEYCODE_LOGGING_CHANGED, /*!< Key Code logging status update */ + IARM_BUS_SYSMGR_EVENT_USB_MOUNT_CHANGED, /*!< Fires when USB mounts change */ + IARM_BUS_SYSMGR_EVENT_APP_RELEASE_FOCUS, /*!< Application fires event to release focus*/ + IARM_BUS_SYSMGR_EVENT_DEVICE_UPDATE_RECEIVED, /*!< Received Device Management update information */ + IARM_BUS_SYSMGR_EVENT_MAX /*!< Max Event Id */ +} IARM_Bus_SYSMgr_EventId_t; + +typedef struct _IARM_BUS_SYSMGR_KEYCodeLoggingInfo_Param_t { + int logStatus; /*!< HDCP Profile Data */ +} IARM_BUS_SYSMGR_KEYCodeLoggingInfo_Param_t; + +#define IARM_BUS_SYSMGR_API_GetKeyCodeLoggingPref "GetKeyCodeLoggingPref" +#define IARM_BUS_SYSMGR_API_SetKeyCodeLoggingPref "SetKeyCodeLoggingPref" + +typedef enum _SYSMgr_SystemState_t { + IARM_BUS_SYSMGR_SYSSTATE_CHANNELMAP, //0 + IARM_BUS_SYSMGR_SYSSTATE_DISCONNECTMGR, //1 + IARM_BUS_SYSMGR_SYSSTATE_TUNEREADY, //2 + IARM_BUS_SYSMGR_SYSSTATE_EXIT_OK, //3 + IARM_BUS_SYSMGR_SYSSTATE_CMAC, //4 + IARM_BUS_SYSMGR_SYSSTATE_MOTO_ENTITLEMENT, //5 + IARM_BUS_SYSMGR_SYSSTATE_MOTO_HRV_RX, //6 + IARM_BUS_SYSMGR_SYSSTATE_CARD_CISCO_STATUS, //7 + IARM_BUS_SYSMGR_SYSSTATE_VIDEO_PRESENTING, //8 + IARM_BUS_SYSMGR_SYSSTATE_HDMI_OUT, //9 + IARM_BUS_SYSMGR_SYSSTATE_HDCP_ENABLED, //10 + IARM_BUS_SYSMGR_SYSSTATE_HDMI_EDID_READ, //11 + IARM_BUS_SYSMGR_SYSSTATE_FIRMWARE_DWNLD, //12 + IARM_BUS_SYSMGR_SYSSTATE_TIME_SOURCE, //13 + IARM_BUS_SYSMGR_SYSSTATE_TIME_ZONE, //14 + IARM_BUS_SYSMGR_SYSSTATE_CA_SYSTEM, //15 + IARM_BUS_SYSMGR_SYSSTATE_ESTB_IP, //16 + IARM_BUS_SYSMGR_SYSSTATE_ECM_IP, //17 + IARM_BUS_SYSMGR_SYSSTATE_LAN_IP, //18 + IARM_BUS_SYSMGR_SYSSTATE_MOCA, //19 + IARM_BUS_SYSMGR_SYSSTATE_DOCSIS, //20 + IARM_BUS_SYSMGR_SYSSTATE_DSG_BROADCAST_CHANNEL, //21 + IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL, //22 + IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD, //23 + IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_DWNLD, //24 + IARM_BUS_SYSMGR_SYSSTATE_CVR_SUBSYSTEM, //25 + IARM_BUS_SYSMGR_SYSSTATE_DOWNLOAD, //26 + IARM_BUS_SYSMGR_SYSSTATE_VOD_AD, //27 + IARM_BUS_SYSMGR_SYSSTATE_DAC_INIT_TIMESTAMP, //28 + IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_SERIAL_NO, //29 + IARM_BUS_SYSMGR_SYSSTATE_ECM_MAC, //30 + IARM_BUS_SYSMGR_SYSSTATE_DAC_ID, //31 + IARM_BUS_SYSMGR_SYSSTATE_PLANT_ID, //32 + IARM_BUS_SYSMGR_SYSSTATE_STB_SERIAL_NO, //33 + IARM_BUS_SYSMGR_SYSSTATE_BOOTUP, //34 + IARM_BUS_SYSMGR_SYSSTATE_GATEWAY_CONNECTION, //35 + IARM_BUS_SYSMGR_SYSSTATE_DST_OFFSET, //36 + IARM_BUS_SYSMGR_SYSSTATE_RF_CONNECTED, //37 + IARM_BUS_SYSMGR_SYSSTATE_PARTNERID_CHANGE, //38 + IARM_BUS_SYSMGR_SYSSTATE_IP_MODE, //39 + IARM_BUS_SYSMGR_SYSSTATE_LP_CONNECTION_RESET, //40 + IARM_BUS_SYSMGR_SYSSTATE_RWS_CONNECTION_RESET, //41 + IARM_BUS_SYSMGR_SYSSTATE_QAM_READY, //42 + IARM_BUS_SYSMGR_SYSSTATE_FIRMWARE_UPDATE_STATE, //43, Added as part of RDK-19978, As the IARM + IARM_BUS_SYSMGR_SYSSTATE_USB_DETECTED, //44 + IARM_BUS_SYSMGR_SYSSTATE_LOG_UPLOAD, //45 + IARM_BUS_SYSMGR_SYSSTATE_RED_RECOV_UPDATE_STATE, //46 +} IARM_Bus_SYSMgr_SystemState_t; + +typedef enum _SYSMgr_FirmwareUpdateState_t { + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_UNINITIALIZED = 0, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_REQUESTING = 1, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_DOWNLOADING = 2, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_FAILED = 3, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_DOWNLOAD_COMPLETE = 4, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_VALIDATION_COMPLETE = 5, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_PREPARING_TO_REBOOT = 6, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_ONHOLD_FOR_OPTOUT = 7, /* On Hold for opt-out */ + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_CRITICAL_REBOOT = 8, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_NO_UPGRADE_REQUIRED = 9 +} IARM_Bus_SYSMGR_FirmwareUpdateState_t; + +typedef enum _SYSMgr_RecoveryState_t { + IARM_BUS_SYSMGR_RECOVERY_STATE_COMPLETED = 0, + IARM_BUS_SYSMGR_RECOVERY_STATE_STARTED = 1, + IARM_BUS_SYSMGR_RECOVERY_STATE_DOWNLOADED = 2, + IARM_BUS_SYSMGR_RECOVERY_STATE_PROGRAMMED = 3, +} IARM_Bus_SYSMGR_RecoveryState_t; + +typedef enum _SYSMgr_LogUpload_t +{ + IARM_BUS_SYSMGR_LOG_UPLOAD_SUCCESS = 0, + IARM_BUS_SYSMGR_LOG_UPLOAD_FAILED = 1, + IARM_BUS_SYSMGR_LOG_UPLOAD_ABORTED = 2, +} IARM_Bus_SYSMGR_SYSMgr_LogUpload_t; + +typedef struct _IARM_BUS_SYSMgr_EventData_t { + union { + struct _CARD_FWDNLD_DATA { + char eventType; + char status; + } cardFWDNLD; + struct _IMAGE_FWDNLD_DATA { + char status; + } imageFWDNLD; + struct _XUPNP_DATA { + unsigned long deviceInfoLength; + } xupnpData; + struct _HDCP_PROFILE { + unsigned int hdcpProfile; + } hdcpProfileData; + struct _SystemStates { + IARM_Bus_SYSMgr_SystemState_t stateId; + int state; + int error; + char payload[128]; + } systemStates; + struct _EISS_STATUS { + int filterStatus; + } eissEventData; + struct _EISS_APP_ID { + unsigned char idList[4][6]; + int count; + } eissAppIDList; + struct _KEY_CODE_LOG { + int logStatus; + } keyCodeLogData; + struct _USB_MOUNT { + int mounted; + char device[128]; + char dir[256]; + } usbMountData; + + } data; +} IARM_Bus_SYSMgr_EventData_t; + +typedef struct _propertyValue { + int state; + int error; + char payload[128]; +} state_property; + +typedef struct _IARM_Bus_SYSMgr_GetSystemStates_Param_t { + state_property channel_map; + state_property disconnect_mgr_state; + state_property TuneReadyStatus; + state_property exit_ok_key_sequence; + state_property cmac; + state_property card_moto_entitlements; + state_property card_moto_hrv_rx; + state_property dac_init_timestamp; + state_property card_cisco_status; + state_property video_presenting; + state_property hdmi_out; + state_property hdcp_enabled; + state_property hdmi_edid_read; + state_property firmware_download; + state_property time_source; + state_property time_zone_available; + state_property ca_system; + state_property estb_ip; + state_property ecm_ip; + state_property lan_ip; + state_property moca; + state_property docsis; + state_property dsg_broadcast_tunnel; + state_property dsg_ca_tunnel; + state_property cable_card; + state_property cable_card_download; + state_property cvr_subsystem; + state_property download; + state_property vod_ad; + state_property card_serial_no; + state_property ecm_mac; + state_property dac_id; + state_property plant_id; + state_property stb_serial_no; + state_property bootup; + state_property dst_offset; + state_property rf_connected; + state_property ip_mode; + state_property qam_ready_status; + state_property firmware_update_state; + state_property red_recov_state; +} IARM_Bus_SYSMgr_GetSystemStates_Param_t; + +#define IARM_BUS_DSMGR_NAME "DSMgr" + +/*! Events published from DS Mananger */ +typedef enum _DSMgr_EventId_t { + IARM_BUS_DSMGR_EVENT_RES_PRECHANGE = 0, /*!< Resolution Pre Change Event */ + IARM_BUS_DSMGR_EVENT_RES_POSTCHANGE, /*!< Resolution Post Change Event */ + IARM_BUS_DSMGR_EVENT_ZOOM_SETTINGS, /*!< Zoom Settings Events */ + IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG, /*!< HDMI HPD DETECT Change Event */ + IARM_BUS_DSMGR_EVENT_AUDIO_MODE, /*!< HDMI HPD DETECT Change Event */ + IARM_BUS_DSMGR_EVENT_HDCP_STATUS, /*!< HDMI HDCP status */ + IARM_BUS_DSMGR_EVENT_RX_SENSE, /*!< HDMI Rx Sense status */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG, /*!< HDMI IN HPD change event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, /*!< HDMI IN signal status change event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS, /*!< HDMI IN status change event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_AV_LATENCY, /*!< HDMI IN AV Latency Event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, /*!< HDMI IN video mode update event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_ALLM_STATUS, /*!< HDMI IN ALLM mode update event */ + IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG, /*!< COMPOSITE IN HPD change event */ + IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_SIGNAL_STATUS, /*!< COMPOSITE IN signal status change event */ + IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_STATUS, /*!< COMPOSITE IN status change event */ + IARM_BUS_DSMGR_EVENT_TIME_FORMAT_CHANGE, /*!< Clock Time Format Change Event*/ + IARM_BUS_DSMGR_EVENT_AUDIO_LEVEL_CHANGED, /*!< Audio Level Change Event*/ + IARM_BUS_DSMGR_EVENT_AUDIO_OUT_HOTPLUG, /*!< AUDIO OUT HPD change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_FORMAT_UPDATE, /*!< Audio Format change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_PRIMARY_LANGUAGE_CHANGED, /*!< Audio Primary Language change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_SECONDARY_LANGUAGE_CHANGED, /*!< Audio Secondary Language change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_FADER_CONTROL_CHANGED, /*!< Audio Fader Control change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_ASSOCIATED_AUDIO_MIXING_CHANGED, /*!< Audio Associated Audio Mixing change event */ + IARM_BUS_DSMGR_EVENT_VIDEO_FORMAT_UPDATE, /*!< Video Format change event */ + IARM_BUS_DSMGR_EVENT_DISPLAY_FRAMRATE_PRECHANGE, /*!< Frame rate pre change */ + IARM_BUS_DSMGR_EVENT_DISPLAY_FRAMRATE_POSTCHANGE, /*!< Frame rate post change */ + IARM_BUS_DSMGR_EVENT_AUDIO_PORT_STATE, /*!< Audio Port Init State */ + IARM_BUS_DSMGR_EVENT_SLEEP_MODE_CHANGED, /*!< Sleep Mode Change Event*/ + IARM_BUS_DSMGR_EVENT_HDMI_IN_AVI_CONTENT_TYPE, /*Register(__VA_ARGS__) + + + +#define IARM_BUS_SYSMGR_API_RunScript "RunScript" +/*! Parameter for RunScript call*/ +typedef struct _IARM_Bus_SYSMgr_RunScript_t{ + char script_path [256]; //[in] Null terminated path name of the script. + int return_value; //[out] Returns the ret value of system. +} IARM_Bus_SYSMgr_RunScript_t; + +typedef enum _CECMgr_EventId_t { + IARM_BUS_CECMGR_EVENT_SEND, + IARM_BUS_CECMGR_EVENT_RECV, + IARM_BUS_CECMGR_EVENT_ENABLE, + IARM_BUS_CECMGR_EVENT_DAEMON_INITIALIZED, + IARM_BUS_CECMGR_EVENT_MAX, + IARM_BUS_CECMGR_EVENT_STATUS_UPDATED +} IARM_Bus_CECMgr_EventId_t; + +typedef struct _IARM_Bus_CECMgr_Status_Updated_Param_t +{ + int logicalAddress; +}IARM_Bus_CECMgr_Status_Updated_Param_t; + +typedef struct _IARM_Bus_MFRLib_SetBLSplashScreen_Param{ + char path[255]; +} IARM_Bus_MFRLib_SetBLSplashScreen_Param_t; + +#define IARM_BUS_CECMGR_API_isAvailable "isAvailable" +#define IARM_BUS_DSMGR_API_dsHdmiInGetNumberOfInputs "dsHdmiInGetNumberOfInputs" +#define IARM_BUS_DSMGR_API_dsHdmiInGetStatus "dsHdmiInGetStatus" +#define IARM_BUS_DSMGR_API_dsGetHDMIARCPortId "dsGetHDMIARCPortId" diff --git a/Tests/mocks/IarmBusMock.h b/Tests/mocks/IarmBusMock.h new file mode 100644 index 00000000..61d1c513 --- /dev/null +++ b/Tests/mocks/IarmBusMock.h @@ -0,0 +1,48 @@ +#pragma once + +#include + +#include "libIBus.h" + +class IarmBusImplMock : public IarmBusImpl { +public: + IarmBusImplMock() + : IarmBusImpl() + { + // Defaults: + ON_CALL(*this, IARM_Bus_IsConnected(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [](const char*, int* isRegistered) { + *isRegistered = 1; + return IARM_RESULT_SUCCESS; + })); + ON_CALL(*this, IARM_Bus_Init(::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_Connect()) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_UnRegisterEventHandler(::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_Call(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_BroadcastEvent(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_RegisterCall(::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_Call_with_IPCTimeout(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + } + virtual ~IarmBusImplMock() = default; + + MOCK_METHOD(IARM_Result_t, IARM_Bus_Init, (const char* name), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_Connect, (), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_IsConnected, (const char* memberName, int* isRegistered), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_RegisterEventHandler, (const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_UnRegisterEventHandler, (const char* ownerName, IARM_EventId_t eventId), (override)); + 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_Call_with_IPCTimeout, (const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout), (override)); +}; diff --git a/Tests/mocks/Udev.cpp b/Tests/mocks/Udev.cpp new file mode 100755 index 00000000..a6b8638b --- /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 new file mode 100644 index 00000000..a9681734 --- /dev/null +++ b/Tests/mocks/Udev.h @@ -0,0 +1,73 @@ +#pragma once + +struct udev { +}; + +struct udev_enumerate { +}; + +struct udev_list_entry { +}; + +struct udev_device { +}; + +class UdevImpl { +public: + virtual ~UdevImpl() = default; + + virtual struct udev* udev_new() = 0; + virtual struct udev_enumerate* udev_enumerate_new(struct udev* udev) = 0; + virtual void udev_enumerate_add_match_subsystem(struct udev_enumerate* enumerate, const char* subsystem) = 0; + virtual void udev_enumerate_scan_devices(struct udev_enumerate* enumerate) = 0; + virtual struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate* enumerate) = 0; + virtual void udev_enumerate_unref(struct udev_enumerate* enumerate) = 0; + virtual void udev_unref(struct udev* udev) = 0; + virtual const char* udev_list_entry_get_name(struct udev_list_entry* entry) = 0; + virtual struct udev_device* udev_device_new_from_syspath(struct udev* udev, const char* path) = 0; + virtual void udev_device_unref(struct udev_device* dev) = 0; + virtual struct udev_device* udev_device_get_parent_with_subsystem_devtype(struct udev_device* dev, const char* subsystem, const char* devtype) = 0; + virtual const char* udev_device_get_devtype(struct udev_device* dev) = 0; + virtual const char* udev_device_get_devnode(struct udev_device* dev) = 0; +}; + +class Udev { +protected: + static UdevImpl* impl; +public: + 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); +}; + +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; \ + list_entry; \ + list_entry = nullptr) diff --git a/Tests/mocks/UdevMock.h b/Tests/mocks/UdevMock.h new file mode 100644 index 00000000..8f34275e --- /dev/null +++ b/Tests/mocks/UdevMock.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "Udev.h" + +class UdevImplMock : public UdevImpl { +public: + virtual ~UdevImplMock() = default; + + MOCK_METHOD(struct udev*, udev_new, (), (override)); + MOCK_METHOD(struct udev_enumerate*, udev_enumerate_new, (struct udev * udev), (override)); + MOCK_METHOD(void, udev_enumerate_add_match_subsystem, (struct udev_enumerate * enumerate, const char* subsystem), (override)); + MOCK_METHOD(void, udev_enumerate_scan_devices, (struct udev_enumerate * enumerate), (override)); + MOCK_METHOD(struct udev_list_entry*, udev_enumerate_get_list_entry, (struct udev_enumerate * enumerate), (override)); + MOCK_METHOD(void, udev_enumerate_unref, (struct udev_enumerate * enumerate), (override)); + MOCK_METHOD(void, udev_unref, (struct udev * udev), (override)); + MOCK_METHOD(const char*, udev_list_entry_get_name, (struct udev_list_entry * entry), (override)); + MOCK_METHOD(struct udev_device*, udev_device_new_from_syspath, (struct udev * udev, const char* path), (override)); + MOCK_METHOD(void, udev_device_unref, (struct udev_device * dev), (override)); + MOCK_METHOD(struct udev_device*, udev_device_get_parent_with_subsystem_devtype, (struct udev_device * dev, const char* subsystem, const char* devtype), (override)); + MOCK_METHOD(const char*, udev_device_get_devtype, (struct udev_device * dev), (override)); + MOCK_METHOD(const char*, udev_device_get_devnode, (struct udev_device * dev), (override)); +}; diff --git a/Tests/mocks/Wraps.cpp b/Tests/mocks/Wraps.cpp new file mode 100644 index 00000000..8a61086a --- /dev/null +++ b/Tests/mocks/Wraps.cpp @@ -0,0 +1,151 @@ +#include +#include +#include "Wraps.h" +#include +#include + +extern "C" int __wrap_system(const char* command) +{ + return Wraps::getInstance().system(command); +} + +extern "C" FILE* __wrap_popen(const char* command, const char* type) +{ + return Wraps::getInstance().popen(command, type); +} + +extern "C" int __wrap_pclose(FILE* pipe) +{ + return Wraps::getInstance().pclose(pipe); +} + +//This function will be called for syslog() in the code (added -Wl,-wrap,syslog) +extern "C" void __wrap_syslog(int pri, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + Wraps::getInstance().syslog(pri, fmt, args); + vsyslog(pri, fmt, args); + va_end(args); +} + +extern "C" FILE* __wrap_setmntent(const char* command, const char* type) +{ + return Wraps::getInstance().setmntent(command, type); +} + +extern "C" struct mntent* __wrap_getmntent(FILE* pipe) +{ + return Wraps::getInstance().getmntent(pipe); +} + +extern "C" FILE * __wrap_v_secure_popen(const char *direction, const char *command, ...) +{ + va_list args; + FILE *retFp = nullptr; + va_start(args, command); + retFp = Wraps::getInstance().v_secure_popen(direction, command, args); + va_end(args); + return retFp; +} + + +extern "C" int __wrap_v_secure_pclose(FILE *file) +{ + return Wraps::getInstance().v_secure_pclose(file); +} + + +extern "C" int __wrap_v_secure_system(const char *command, ...) +{ + int ret; + va_list args; + va_start(args,command); + ret = Wraps::getInstance().v_secure_system(command, args); + va_end(args); + return ret; +} + +extern "C" ssize_t __wrap_readlink(const char *pathname, char *buf, size_t bufsiz) +{ + return Wraps::getInstance().readlink(pathname, buf, bufsiz); +} + +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); +} + + +ssize_t Wraps::readlink(const char *pathname, char *buf, size_t bufsiz) +{ + EXPECT_NE(impl, nullptr); + return impl->readlink(pathname,buf,bufsiz); +} + diff --git a/Tests/mocks/Wraps.h b/Tests/mocks/Wraps.h new file mode 100644 index 00000000..8dd7da37 --- /dev/null +++ b/Tests/mocks/Wraps.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include "secure_wrappermock.h" + +class WrapsImpl { +public: + virtual ~WrapsImpl() = default; + + virtual int system(const char* command) = 0; + virtual FILE* popen(const char* command, const char* type) = 0; + virtual int pclose(FILE *pipe) = 0; + virtual void syslog(int pri, const char* fmt, va_list args) = 0; + virtual FILE* setmntent(const char* command, const char* type) = 0; + virtual struct mntent* getmntent(FILE *pipe) = 0; + virtual FILE *v_secure_popen(const char *direction, const char *command, va_list args) = 0; + virtual int v_secure_pclose(FILE *) = 0; + virtual int v_secure_system(const char *command, va_list args) =0; + virtual ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) = 0; +}; + +class Wraps { +protected: + static WrapsImpl* impl; + +public: + Wraps(); + Wraps(const Wraps &obj) = delete; + static void setImpl(WrapsImpl* newImpl); + static Wraps& getInstance(); + + static int system(const char* command); + + static FILE* popen(const char* command, const char* type); + + static int pclose(FILE* pipe); + + static void syslog(int pri, const char* fmt, va_list args); + + static FILE* setmntent(const char* command, const char* type); + + static struct mntent* getmntent(FILE* pipe); + + static FILE *v_secure_popen(const char *direction, const char *command, va_list args); + + static int v_secure_pclose(FILE *file); + + static int v_secure_system(const char *command, va_list args); + + ssize_t readlink(const char *pathname, char *buf, size_t bufsiz); +}; diff --git a/Tests/mocks/WrapsMock.h b/Tests/mocks/WrapsMock.h new file mode 100644 index 00000000..2041eab9 --- /dev/null +++ b/Tests/mocks/WrapsMock.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include "Wraps.h" + +extern "C" FILE* __real_setmntent(const char* command, const char* type); + +class WrapsImplMock : public WrapsImpl { +public: + WrapsImplMock():WrapsImpl() + { + /*Setting up Default behavior for setmntent: + * We are mocking setmntent in this file below with __wrap_setmntent, + * and the actual setmntent will be called via this interface */ + ON_CALL(*this, setmntent(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* command, const char* type) -> FILE* { + return __real_setmntent(command, type); + })); + } + virtual ~WrapsImplMock() = default; + + MOCK_METHOD(int, system, (const char* command), (override)); + MOCK_METHOD(FILE*, popen, (const char* command, const char* type), (override)); + MOCK_METHOD(int, pclose, (FILE* pipe), (override)); + MOCK_METHOD(void, syslog, (int pri, const char* fmt, va_list args), (override)); + MOCK_METHOD(FILE*, setmntent, (const char* command, const char* type), (override)); + MOCK_METHOD(struct mntent*, getmntent, (FILE* pipe), (override)); + MOCK_METHOD(FILE*, v_secure_popen, (const char *direction, const char *command, va_list args), (override)); + MOCK_METHOD(int, v_secure_pclose, (FILE *file), (override)); + MOCK_METHOD(int, v_secure_system,(const char *command, va_list args), (override)); + MOCK_METHOD(ssize_t, readlink, (const char *pathname, char *buf, size_t bufsiz), (override)); +}; \ No newline at end of file diff --git a/Tests/mocks/thunder/COMLinkMock.h b/Tests/mocks/thunder/COMLinkMock.h new file mode 100644 index 00000000..a16d8701 --- /dev/null +++ b/Tests/mocks/thunder/COMLinkMock.h @@ -0,0 +1,18 @@ +#ifndef RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ +#define RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ + +#include + +#include "Module.h" + +class COMLinkMock : public WPEFramework::PluginHost::IShell::ICOMLink { +public: + virtual ~COMLinkMock() = default; + + MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override)); + MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&, const string&, const string&), (override)); +}; + +#endif //RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ diff --git a/Tests/mocks/thunder/DispatcherMock.h b/Tests/mocks/thunder/DispatcherMock.h new file mode 100644 index 00000000..df31c8a2 --- /dev/null +++ b/Tests/mocks/thunder/DispatcherMock.h @@ -0,0 +1,37 @@ +/* + * 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 DISPATCHERMOCK_H +#define DISPATCHERMOCK_H + +#include + +#include "Module.h" + + class DispatcherMock: public WPEFramework::PluginHost::IDispatcher{ + public: + virtual ~DispatcherMock() = default; + MOCK_METHOD(void, AddRef, (), (const, override)); + MOCK_METHOD(uint32_t, Release, (), (const, override)); + MOCK_METHOD(void*, QueryInterface, (const uint32_t interfaceNummer), (override)); + MOCK_METHOD(void, Activate, (WPEFramework::PluginHost::IShell* service)); + MOCK_METHOD(void, Deactivate, ()); + MOCK_METHOD(WPEFramework::Core::ProxyType, Invoke, (const string&, uint32_t, const WPEFramework::Core::JSONRPC::Message&), (override)); +}; +#endif //DISPATCHERMOCK_H diff --git a/Tests/mocks/thunder/FactoriesImplementation.h b/Tests/mocks/thunder/FactoriesImplementation.h new file mode 100644 index 00000000..e571fbb7 --- /dev/null +++ b/Tests/mocks/thunder/FactoriesImplementation.h @@ -0,0 +1,47 @@ +#pragma once + +#include + +#include "Module.h" + +class FactoriesImplementation : public WPEFramework::PluginHost::IFactories { +public: + FactoriesImplementation(const FactoriesImplementation&) = delete; + FactoriesImplementation& operator=(const FactoriesImplementation&) = delete; + + FactoriesImplementation() + : _requestFactory(5) + , _responseFactory(5) + , _fileBodyFactory(5) + , _jsonRPCFactory(5) + { + // Defaults: + ON_CALL(*this, Request()) + .WillByDefault(::testing::Invoke( + [&]() { return (_requestFactory.Element()); })); + ON_CALL(*this, Response()) + .WillByDefault(::testing::Invoke( + [&]() { return (_responseFactory.Element()); })); + ON_CALL(*this, FileBody()) + .WillByDefault(::testing::Invoke( + [&]() { return (_fileBodyFactory.Element()); })); + ON_CALL(*this, JSONRPC()) + .WillByDefault(::testing::Invoke( + [&]() { + return (WPEFramework::Core::ProxyType>(_jsonRPCFactory.Element())); + })); + } + + virtual ~FactoriesImplementation() = default; + + MOCK_METHOD(WPEFramework::Core::ProxyType, Request, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType, Response, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType, FileBody, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType>, JSONRPC, (), (override)); + +private: + WPEFramework::Core::ProxyPoolType _requestFactory; + WPEFramework::Core::ProxyPoolType _responseFactory; + WPEFramework::Core::ProxyPoolType _fileBodyFactory; + WPEFramework::Core::ProxyPoolType _jsonRPCFactory; +}; diff --git a/Tests/mocks/thunder/Module.cpp b/Tests/mocks/thunder/Module.cpp new file mode 100644 index 00000000..2d85ed90 --- /dev/null +++ b/Tests/mocks/thunder/Module.cpp @@ -0,0 +1,3 @@ +#include "Module.h" + +MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/Tests/mocks/thunder/Module.h b/Tests/mocks/thunder/Module.h new file mode 100644 index 00000000..289d8207 --- /dev/null +++ b/Tests/mocks/thunder/Module.h @@ -0,0 +1,8 @@ +#pragma once + +#ifndef MODULE_NAME +#define MODULE_NAME RdkServicesL1Test +#endif + +#include +#include diff --git a/Tests/mocks/thunder/ServiceMock.h b/Tests/mocks/thunder/ServiceMock.h new file mode 100644 index 00000000..47b9c285 --- /dev/null +++ b/Tests/mocks/thunder/ServiceMock.h @@ -0,0 +1,77 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2022 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 SERVICEMOCK_H +#define SERVICEMOCK_H + +#include + +#include "Module.h" + +class ServiceMock : public WPEFramework::PluginHost::IShell { +public: + virtual ~ServiceMock() = default; + + MOCK_METHOD(void, AddRef, (), (const, override)); + MOCK_METHOD(uint32_t, Release, (), (const, override)); + MOCK_METHOD(string, Versions, (), (const, override)); + MOCK_METHOD(string, Locator, (), (const, override)); + MOCK_METHOD(string, ClassName, (), (const, override)); + MOCK_METHOD(string, Callsign, (), (const, override)); + MOCK_METHOD(string, WebPrefix, (), (const, override)); + MOCK_METHOD(string, ConfigLine, (), (const, override)); + MOCK_METHOD(string, PersistentPath, (), (const, override)); + MOCK_METHOD(string, VolatilePath, (), (const, override)); + MOCK_METHOD(string, DataPath, (), (const, override)); + MOCK_METHOD(state, State, (), (const, override)); + MOCK_METHOD(bool, AutoStart, (), (const, override)); + MOCK_METHOD(bool, Resumed, (), (const, override)); + MOCK_METHOD(bool, IsSupported, (const uint8_t), (const, override)); + MOCK_METHOD(void, EnableWebServer, (const string&, const string&), (override)); + MOCK_METHOD(void, DisableWebServer, (), (override)); + MOCK_METHOD(WPEFramework::PluginHost::ISubSystem*, SubSystems, (), (override)); + MOCK_METHOD(uint32_t, Submit, (const uint32_t, const WPEFramework::Core::ProxyType&), (override)); + MOCK_METHOD(void, Notify, (const string&), (override)); + MOCK_METHOD(void*, QueryInterface, (const uint32_t), (override)); + MOCK_METHOD(void*, QueryInterfaceByCallsign, (const uint32_t, const string&), (override)); + MOCK_METHOD(void, Register, (WPEFramework::PluginHost::IPlugin::INotification*), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::PluginHost::IPlugin::INotification*), (override)); + MOCK_METHOD(string, Version, (), (const, override)); + MOCK_METHOD(string, Model, (), (const, override)); + MOCK_METHOD(bool, Background, (), (const, override)); + MOCK_METHOD(string, Accessor, (), (const, override)); + MOCK_METHOD(string, ProxyStubPath, (), (const, override)); + MOCK_METHOD(string, HashKey, (), (const, override)); + MOCK_METHOD(string, Substitute, (const string&), (const, override)); + MOCK_METHOD(WPEFramework::PluginHost::IShell::ICOMLink*, COMLink, (), (override)); + MOCK_METHOD(uint32_t, Activate, (const reason), (override)); + MOCK_METHOD(uint32_t, Deactivate, (const reason), (override)); + MOCK_METHOD(uint32_t, Unavailable, (const reason), (override)); + MOCK_METHOD(reason, Reason, (), (const, override)); + MOCK_METHOD(uint8_t, Major, (), (const, override)); + MOCK_METHOD(uint8_t, Minor, (), (const, override)); + MOCK_METHOD(uint8_t, Patch, (), (const, override)); + MOCK_METHOD(uint32_t, ConfigLine, (const string& config), (override)); + MOCK_METHOD(string, SystemRootPath, (), (const, override)); + MOCK_METHOD(uint32_t, SystemRootPath, (const string& systemRootPath), (override)); + MOCK_METHOD(uint32_t, Hibernate, (const string &processSequence, const uint32_t timeout), (override)); + MOCK_METHOD(uint32_t, Wakeup, (const string &processSequence, const uint32_t timeout), (override)); +}; + +#endif //SERVICEMOCK_H diff --git a/Tests/mocks/thunder/SystemInfo.h b/Tests/mocks/thunder/SystemInfo.h new file mode 100644 index 00000000..db48b294 --- /dev/null +++ b/Tests/mocks/thunder/SystemInfo.h @@ -0,0 +1,63 @@ +#pragma once + +#include + +#include "Module.h" + +class SystemInfo : public WPEFramework::PluginHost::ISubSystem { +private: + SystemInfo(const SystemInfo&) = delete; + SystemInfo& operator=(const SystemInfo&) = delete; + +public: + SystemInfo() + : _flags(0) + { + // Defaults: + ON_CALL(*this, Set(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type, WPEFramework::Core::IUnknown* information) { + _subsystems.emplace(type, information); + + if (type >= NEGATIVE_START) { + _flags &= ~(1 << (type - NEGATIVE_START)); + } else { + _flags |= (1 << type); + } + })); + ON_CALL(*this, Get(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type) -> const WPEFramework::Core::IUnknown* { + const WPEFramework::Core::IUnknown* result(nullptr); + + auto it = _subsystems.find(type); + if (it != _subsystems.end()) { + result = it->second; + } + + return result; + })); + ON_CALL(*this, IsActive(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type) -> bool { + return ((type < END_LIST) && ((_flags & (1 << type)) != 0)); + })); + } + virtual ~SystemInfo() = default; + +public: + MOCK_METHOD(void, Register, (WPEFramework::PluginHost::ISubSystem::INotification * notification), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::PluginHost::ISubSystem::INotification * notification), (override)); + MOCK_METHOD(string, BuildTreeHash, (), (const, override)); + MOCK_METHOD(void, Set, (const subsystem type, WPEFramework::Core::IUnknown* information), (override)); + MOCK_METHOD(const WPEFramework::Core::IUnknown*, Get, (const subsystem type), (const, override)); + MOCK_METHOD(bool, IsActive, (const subsystem type), (const, override)); + + BEGIN_INTERFACE_MAP(SystemInfo) + INTERFACE_ENTRY(WPEFramework::PluginHost::ISubSystem) + END_INTERFACE_MAP + +private: + std::map _subsystems; + uint32_t _flags; +}; diff --git a/Tests/mocks/thunder/WorkerPoolImplementation.h b/Tests/mocks/thunder/WorkerPoolImplementation.h new file mode 100644 index 00000000..dbc5b9e5 --- /dev/null +++ b/Tests/mocks/thunder/WorkerPoolImplementation.h @@ -0,0 +1,44 @@ +#pragma once + +#include + +#include "Module.h" + +class WorkerPoolImplementation : public WPEFramework::Core::WorkerPool { +private: + class Dispatcher : public WPEFramework::Core::ThreadPool::IDispatcher { + public: + Dispatcher(const Dispatcher&) = delete; + Dispatcher& operator=(const Dispatcher&) = delete; + + Dispatcher() = default; + ~Dispatcher() override = default; + + private: + void Initialize() override {} + void Deinitialize() override {} + void Dispatch(WPEFramework::Core::IDispatch* job) override + { + job->Dispatch(); + } + }; + +public: + WorkerPoolImplementation() = delete; + WorkerPoolImplementation(const WorkerPoolImplementation&) = delete; + WorkerPoolImplementation& operator=(const WorkerPoolImplementation&) = delete; + + WorkerPoolImplementation(const uint8_t threads, const uint32_t stackSize, const uint32_t queueSize) + : WPEFramework::Core::WorkerPool(threads - 1, stackSize, queueSize, &_dispatcher) + , _dispatcher() + { + } + + virtual ~WorkerPoolImplementation() + { + WPEFramework::Core::WorkerPool::Stop(); + } + +private: + Dispatcher _dispatcher; +}; diff --git a/unit_test.cmake b/unit_test.cmake new file mode 100644 index 00000000..4466647a --- /dev/null +++ b/unit_test.cmake @@ -0,0 +1,50 @@ +message("Building for unit tests...") + +message("Generating empty headers to suppress compiler errors") + +file(GLOB BASEDIR Tests) +set(BASEDIR ${BASEDIR}/headers) +set(EMPTY_HEADERS_DIRS + ${BASEDIR} + ${BASEDIR}/rdk/iarmbus + ${BASEDIR}/network + ) + +set(EMPTY_HEADERS + ${BASEDIR}/rdk/iarmbus/libIARM.h + ${BASEDIR}/rdk/iarmbus/libIBus.h + ${BASEDIR}/rdk/iarmbus/libIBusDaemon.h + ${BASEDIR}/network/wifiSrvMgrIarmIf.h + ${BASEDIR}/network/netsrvmgrIarm.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}/Iarm.h + ) + +foreach (file ${FAKE_HEADERS}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}") +endforeach () + +add_compile_options(-Wall -Werror) + +add_link_options(-Wl,-wrap,system -Wl,-wrap,popen -Wl,-wrap,syslog -Wl,-wrap,pclose -Wl,-wrap,getmntent -Wl,-wrap,setmntent -Wl,-wrap,v_secure_popen -Wl,-wrap,v_secure_pclose -Wl,-wrap,v_secure_system) + +message("Setting build options") +set(CMAKE_DISABLE_FIND_PACKAGE_IARMBus ON)