Skip to content

Commit c1a655e

Browse files
[RDKEMW-2711] RDKEMW-4232: Moving the L2 Test files to entservices-inputoutput (#107)
* input and output L2 changes set 1 * branch name change * removing identifiers * refer to develop * Update L2-tests.yml * Update L2-tests.yml * Update CMakeLists.txt * Update CMakeLists.txt * Update L2-tests.yml
1 parent d86f5d3 commit c1a655e

File tree

7 files changed

+292
-4
lines changed

7 files changed

+292
-4
lines changed

.github/workflows/L2-tests.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
name: L2-tests
22

3+
#enable the workflow incase of any plugin/testcase changes
34
on:
4-
push:
5-
branches: [ main, develop, 'sprint/**', 'release/**' ]
6-
pull_request:
7-
branches: [ main, develop, 'sprint/**', 'release/**' ]
5+
workflow_dispatch:
86

97
env:
108
BUILD_TYPE: Debug

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ string(TOLOWER ${NAMESPACE} STORAGE_DIRECTORY)
3636
# for writing pc and config files
3737
include(CmakeHelperFunctions)
3838

39+
if(RDK_SERVICE_L2_TEST)
40+
add_subdirectory(Tests/L2Tests)
41+
endif()
42+
3943
if(RDK_SERVICES_L1_TEST)
4044
add_subdirectory(Tests/L1Tests)
4145
endif()

Tests/.clang-format

100644100755
File mode changed.

Tests/L2Tests/CMakeLists.txt

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# If not stated otherwise in this file or this component's LICENSE file the
2+
# following copyright and licenses apply:
3+
#
4+
# Copyright 2023 RDK Management
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
19+
set(PLUGIN_NAME L2TestsIO)
20+
set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME})
21+
set(THUNDER_PORT 9998)
22+
#set(CMAKE_CXX_STANDARD 11)
23+
find_package(${NAMESPACE}Plugins REQUIRED)
24+
25+
include(FetchContent)
26+
FetchContent_Declare(
27+
googletest
28+
URL https://github.com/google/googletest/archive/e39786088138f2749d64e9e90e0f9902daa77c40.zip
29+
)
30+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
31+
FetchContent_MakeAvailable(googletest)
32+
33+
if(PLUGIN_AVOUTPUT)
34+
set(SRC_FILES ${SRC_FILES} tests/AVOutputTV_L2Test.cpp)
35+
endif()
36+
37+
add_library(${MODULE_NAME} SHARED ${SRC_FILES})
38+
39+
set_target_properties(${MODULE_NAME} PROPERTIES
40+
CXX_STANDARD 11
41+
CXX_STANDARD_REQUIRED YES)
42+
43+
target_compile_definitions(${MODULE_NAME}
44+
PRIVATE
45+
MODULE_NAME=Plugin_${PLUGIN_NAME}
46+
THUNDER_PORT="${THUNDER_PORT}")
47+
48+
target_compile_options(${MODULE_NAME} PRIVATE -Wno-error)
49+
target_link_libraries(${MODULE_NAME} PRIVATE gmock_main ${NAMESPACE}Plugins::${NAMESPACE}Plugins)
50+
51+
if (NOT L2_TEST_OOP_RPC)
52+
find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib)
53+
if (TESTMOCKLIB_LIBRARIES)
54+
message ("Found mock library - ${TESTMOCKLIB_LIBRARIES}")
55+
target_link_libraries(${MODULE_NAME} PRIVATE ${TESTMOCKLIB_LIBRARIES})
56+
else (TESTMOCKLIB_LIBRARIES)
57+
message ("Require ${TESTMOCKLIB_LIBRARIES} library")
58+
endif (TESTMOCKLIB_LIBRARIES)
59+
endif (NOT L2_TEST_OOP_RPC)
60+
61+
find_library(MOCKACCESSOR_LIBRARIES NAMES MockAccessor)
62+
if (MOCKACCESSOR_LIBRARIES)
63+
message ("Found MockAccessor library - ${MOCKACCESSOR_LIBRARIES}")
64+
target_link_libraries(${MODULE_NAME} PRIVATE ${MOCKACCESSOR_LIBRARIES})
65+
else (MOCKACCESSOR_LIBRARIES)
66+
message ("Require ${MOCKACCESSOR_LIBRARIES} library")
67+
endif (MOCKACCESSOR_LIBRARIES)
68+
69+
target_include_directories(
70+
${MODULE_NAME} PRIVATE ./
71+
../../helpers
72+
../../../entservices-testframework/Tests/mocks
73+
../../../entservices-testframework/Tests/mocks/thunder
74+
../../../entservices-testframework/Tests/mocks/devicesettings
75+
../../../entservices-testframework/Tests/mocks/MockPlugin
76+
../../../entservices-testframework/Tests/L2Tests/L2TestsPlugin
77+
${CMAKE_INSTALL_PREFIX}/include
78+
)
79+
80+
install(TARGETS ${MODULE_NAME} DESTINATION lib)
81+
82+
write_config(${PLUGIN_NAME})
83+
84+
85+
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
/**
2+
* If not stated otherwise in this file or this component's LICENSE
3+
* file the following copyright and licenses apply:
4+
*
5+
* Copyright 2024 RDK Management
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
**/
19+
20+
#include <gtest/gtest.h>
21+
#include <gmock/gmock.h>
22+
#include "L2Tests.h"
23+
#include "L2TestsMock.h"
24+
#include <mutex>
25+
#include <condition_variable>
26+
#include <fstream>
27+
28+
#define JSON_TIMEOUT (1000)
29+
#define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)<PID:%d><TID:%d>" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr);
30+
#define AVOUTPUT_CALLSIGN _T("org.rdk.AVOutput.1")
31+
#define AVOUTPUT_CALLSIGNL2TEST_CALLSIGN _T("L2tests.1")
32+
33+
using ::testing::NiceMock;
34+
using namespace WPEFramework;
35+
using testing::StrictMock;
36+
37+
/**
38+
* @brief Internal test mock class
39+
*
40+
* Note that this is for internal test use only and doesn't mock any actual
41+
* concrete interface.
42+
*/
43+
44+
/* AVOutput L2 test class declaration */
45+
class AVOutput_L2test : public L2TestMocks {
46+
protected:
47+
Core::JSONRPC::Message message;
48+
string response;
49+
IARM_EventHandler_t dsHdmiStatusEventHandler;
50+
IARM_EventHandler_t dsHdmiVideoModeEventHandler;
51+
52+
virtual ~AVOutput_L2test() override;
53+
54+
public:
55+
AVOutput_L2test();
56+
};
57+
58+
/**
59+
* @brief Constructor for AVOutput L2 test class
60+
*/
61+
AVOutput_L2test::AVOutput_L2test()
62+
: L2TestMocks()
63+
{
64+
printf("AVOutput Constructor\n");
65+
uint32_t status = Core::ERROR_GENERAL;
66+
67+
std::ofstream devicePropFileStream("/etc/device.properties");
68+
devicePropFileStream << "RDK_PROFILE=TV";
69+
devicePropFileStream << "\n";
70+
devicePropFileStream.close();
71+
72+
EXPECT_CALL(*p_rfcApiImplMock, getRFCParameter(::testing::_, ::testing::_, ::testing::_))
73+
.Times(1)
74+
.WillOnce(::testing::Invoke(
75+
[](char* pcCallerID, const char* pcParameterName, RFC_ParamData_t* pstParamData) {
76+
EXPECT_EQ(string(pcCallerID), string("AVOutput"));
77+
EXPECT_EQ(string(pcParameterName), string("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AVOutput.DynamicAutoLatency"));
78+
strncpy(pstParamData->value, "true", sizeof(pstParamData->value));
79+
return WDMP_SUCCESS;
80+
}));
81+
82+
ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_))
83+
.WillByDefault(::testing::Invoke(
84+
[&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) {
85+
if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS)) {
86+
EXPECT_TRUE(handler != nullptr);
87+
dsHdmiStatusEventHandler = handler;
88+
}
89+
if ((string(IARM_BUS_DSMGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE)) {
90+
EXPECT_TRUE(handler != nullptr);
91+
dsHdmiVideoModeEventHandler = handler;
92+
}
93+
return IARM_RESULT_SUCCESS;
94+
}));
95+
96+
ON_CALL(*p_hdmiInputImplMock, getCurrentVideoModeObj(::testing::_))
97+
.WillByDefault(::testing::Invoke(
98+
[&](dsVideoPortResolution_t& resolution) {
99+
resolution.pixelResolution = dsVIDEO_PIXELRES_1920x1080;
100+
return tvERROR_NONE;
101+
}));
102+
103+
ON_CALL(*p_tvSettingsImplMock, TvInit())
104+
.WillByDefault(::testing::Return(tvERROR_NONE));
105+
106+
ON_CALL(*p_tvSettingsImplMock, RegisterVideoFormatChangeCB(testing::_))
107+
.WillByDefault(testing::Return(tvERROR_NONE));
108+
ON_CALL(*p_tvSettingsImplMock, RegisterVideoContentChangeCB(testing::_))
109+
.WillByDefault(testing::Return(tvERROR_NONE));
110+
ON_CALL(*p_tvSettingsImplMock, RegisterVideoResolutionChangeCB(testing::_))
111+
.WillByDefault(testing::Return(tvERROR_NONE));
112+
ON_CALL(*p_tvSettingsImplMock, RegisterVideoFrameRateChangeCB(testing::_))
113+
.WillByDefault(testing::Return(tvERROR_NONE));
114+
115+
EXPECT_CALL(*p_tr181ApiImplMock, getLocalParam(::testing::_, ::testing::_, ::testing::_))
116+
.Times(2)
117+
.WillOnce(::testing::Invoke(
118+
[&](char *pcCallerID, const char* pcParameterName, TR181_ParamData_t *pstParamData) {
119+
EXPECT_EQ(string(pcCallerID), string("AVOutput"));
120+
strncpy(pstParamData->value, "Normal", sizeof(pstParamData->value));
121+
122+
return tr181Success;
123+
}))
124+
.WillOnce(::testing::Invoke(
125+
[&](char *pcCallerID, const char* pcParameterName, TR181_ParamData_t *pstParamData) {
126+
EXPECT_EQ(string(pcCallerID), string("AVOutput"));
127+
strncpy(pstParamData->value, "Normal", sizeof(pstParamData->value));
128+
129+
return tr181Success;
130+
}));
131+
132+
ON_CALL(*p_tvSettingsImplMock, SetAspectRatio(testing::_))
133+
.WillByDefault(testing::Invoke(
134+
[&](tvDisplayMode_t dispMode) {
135+
EXPECT_EQ(dispMode, tvDisplayMode_NORMAL);
136+
return tvERROR_NONE;
137+
}));
138+
139+
ON_CALL(*p_tvSettingsImplMock, GetCurrentSource(testing::_))
140+
.WillByDefault(testing::Invoke(
141+
[&](tvVideoSrcType_t *currentSource) {
142+
EXPECT_EQ(*currentSource, VIDEO_SOURCE_IP);
143+
return tvERROR_NONE;
144+
}));
145+
146+
ON_CALL(*p_tvSettingsImplMock, GetCurrentVideoFormat(testing::_))
147+
.WillByDefault(testing::Invoke(
148+
[&](tvVideoFormatType_t* videoFormat) {
149+
EXPECT_EQ(*videoFormat, VIDEO_FORMAT_NONE);
150+
return tvERROR_NONE; // Return an appropriate error code
151+
}));
152+
153+
ON_CALL(*p_tvSettingsImplMock, SetTVPictureMode(testing::_))
154+
.WillByDefault(testing::Invoke(
155+
[&](const char * pictureMode) {
156+
EXPECT_EQ(string(pictureMode), string("normal"));
157+
return tvERROR_NONE;
158+
}));
159+
160+
/* Activate plugin in constructor */
161+
status = ActivateService("org.rdk.AVOutput");
162+
EXPECT_EQ(Core::ERROR_NONE, status);
163+
}
164+
165+
/**
166+
* @brief Destructor for AVInput L2 test class
167+
*/
168+
AVOutput_L2test::~AVOutput_L2test()
169+
{
170+
printf("AVOutput Destructor\n");
171+
uint32_t status = Core::ERROR_GENERAL;
172+
173+
ON_CALL(*p_tvSettingsImplMock, TvTerm())
174+
.WillByDefault(::testing::Return(tvERROR_NONE));
175+
176+
status = DeactivateService("org.rdk.AVOutput");
177+
EXPECT_EQ(Core::ERROR_NONE, status);
178+
}
179+
180+
TEST_F(AVOutput_L2test, AVOUTPUT_GETINPUTDEVICE_Test)
181+
{
182+
JSONRPC::LinkType<Core::JSON::IElement> jsonrpc(AVOUTPUT_CALLSIGN, AVOUTPUT_CALLSIGNL2TEST_CALLSIGN);
183+
uint32_t status = Core::ERROR_GENERAL;
184+
JsonObject result, params;
185+
186+
ON_CALL(*p_tvSettingsImplMock, ReadCapablitiesFromConfODM(testing::_, testing::_, testing::_, testing::_, testing::_, testing::_, testing::_))
187+
.WillByDefault([](std::string& rangeInfo, std::string& pqmodeInfo, std::string& formatInfo, std::string& sourceInfo, std::string param, std::string& platformsupport, std::string& index) {
188+
printf("ReadCapablitiesFromConfODM\n");
189+
rangeInfo = "\"Standard\",\"Vivid\",\"EnergySaving\",\"Custom\",\"Theater\",\"Game\"";
190+
pqmodeInfo = "";
191+
formatInfo = "\"SDR\"";
192+
sourceInfo = "\"HDMI\",\"HDMI2\"";
193+
platformsupport = "";
194+
index = "0";
195+
196+
return tvERROR_NONE;
197+
});
198+
199+
status = InvokeServiceMethod("org.rdk.AVOutput.1", "getPictureModeCaps", params, result);
200+
201+
}

Tests/clang.cmake

100644100755
File mode changed.

Tests/gcc-with-coverage.cmake

100644100755
File mode changed.

0 commit comments

Comments
 (0)