|
| 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 | +} |
0 commit comments