Skip to content
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
84d8578
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 5, 2025
2eb3b77
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 5, 2025
b744a75
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 5, 2025
4c5ca10
Update MaintenanceManager.h
Abhinavpv28 Jun 5, 2025
54105db
Update CMakeLists.txt
Abhinavpv28 Jun 5, 2025
9e1c9d8
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 5, 2025
39ea8c4
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 6, 2025
0372ded
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
366eef4
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
b86c8f7
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
7b8ae51
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
0cc2585
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
1be3618
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
d5b3fe7
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
6932b7d
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
2366993
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
55ce4a7
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
c3d6ba2
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
a9459b5
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
f72da60
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
f78a028
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
21ce16a
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
213b1df
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
af9b5f9
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
080f15b
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
d5b8440
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
82d1288
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
a9b0cd3
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
eb1bcd8
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
337b569
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
5c85f67
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
19aa53a
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
d6ef9d0
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
f92cf04
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 7, 2025
e9df04f
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
d7971a9
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
4bebb19
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
ccf4b2c
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
a8c3b92
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
decc125
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
b5d1323
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
c280adc
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
30f36fc
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
4195c78
Update test_MaintenanceManager.cpp
Abhinavpv28 Jun 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MaintenanceManager/MaintenanceManager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**

Check failure on line 1 in MaintenanceManager/MaintenanceManager.h

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'MaintenanceManager/MaintenanceManager.h' (Match: rdkcentral/rdkservices/1, 319 lines, url: https://github.com/rdkcentral/rdkservices/archive/GRT_v1.tar.gz, file: MaintenanceManager/MaintenanceManager.h)
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
Expand Down Expand Up @@ -170,7 +170,11 @@

class MaintenanceManager : public PluginHost::IPlugin, public PluginHost::JSONRPC
{
#if defined(GTEST_ENABLE)
public:
#else
private:
#endif
typedef Core::JSON::String JString;
typedef Core::JSON::ArrayType<JString> JStringArray;
typedef Core::JSON::Boolean JBool;
Expand Down
2 changes: 2 additions & 0 deletions Tests/L1Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ target_link_directories(${MODULE_NAME} PUBLIC ${CMAKE_INSTALL_PREFIX}/lib/wpefra

target_link_libraries(${MODULE_NAME} ${TEST_LIB})

target_compile_definitions(${MODULE_NAME} PRIVATE GTEST_ENABLE)

target_include_directories(${MODULE_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down
214 changes: 214 additions & 0 deletions Tests/L1Tests/tests/test_MaintenanceManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/**

Check failure on line 2 in Tests/L1Tests/tests/test_MaintenanceManager.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'Tests/L1Tests/tests/test_MaintenanceManager.cpp' (Match: rdkcentral/rdkservices/1, 538 lines, url: https://github.com/rdkcentral/rdkservices/archive/GRT_v1.tar.gz, file: Tests/tests/test_MaintenanceManager.cpp)
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
Expand Down Expand Up @@ -40,10 +40,119 @@
using ::testing::AssertionResult;
using ::testing::AssertionSuccess;
using ::testing::AssertionFailure;
using ::testing::DoAll;
using ::testing::Return;

extern "C" FILE* __real_popen(const char* command, const char* type);
extern "C" int __real_pclose(FILE* pipe);

class MockShell : public WPEFramework::PluginHost::IShell {
public:
MOCK_METHOD(void, EnableWebServer, (const string&, const string&), (override));
MOCK_METHOD(void, DisableWebServer, (), (override));
MOCK_METHOD(string, Model, (), (const, override));
MOCK_METHOD(bool, Background, (), (const, override));
MOCK_METHOD(string, Accessor, (), (const, override));
MOCK_METHOD(string, WebPrefix, (), (const, override));
MOCK_METHOD(string, Locator, (), (const, override));
MOCK_METHOD(string, ClassName, (), (const, override));
MOCK_METHOD(string, Versions, (), (const, override));
MOCK_METHOD(string, Callsign, (), (const, override));
MOCK_METHOD(string, PersistentPath, (), (const, override));
MOCK_METHOD(string, VolatilePath, (), (const, override));
MOCK_METHOD(string, DataPath, (), (const, override));
MOCK_METHOD(string, ProxyStubPath, (), (const, override));
MOCK_METHOD(string, SystemPath, (), (const, override));
MOCK_METHOD(string, SystemRootPath, (), (const, override));
MOCK_METHOD(WPEFramework::Core::hresult, SystemRootPath, (const string&), (override));
MOCK_METHOD(PluginHost::IShell::startup, Startup, (), (const, override));
MOCK_METHOD(WPEFramework::Core::hresult, Startup, (const PluginHost::IShell::startup), (override));
MOCK_METHOD(string, Substitute, (const string&), (const, override));
MOCK_METHOD(bool, Resumed, (), (const, override));
MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool), (override));
MOCK_METHOD(string, HashKey, (), (const, override));
MOCK_METHOD(string, ConfigLine, (), (const, override));
MOCK_METHOD(WPEFramework::Core::hresult, ConfigLine, (const string&), (override));
MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string&), (const, override));
MOCK_METHOD(bool, IsSupported, (const uint8_t), (const, override));
MOCK_METHOD(WPEFramework::PluginHost::ISubSystem*, SubSystems, (), (override));
MOCK_METHOD(void, Notify, (const string&), (override));
MOCK_METHOD(void, Register, (PluginHost::IPlugin::INotification*), (override));
MOCK_METHOD(void, Unregister, (PluginHost::IPlugin::INotification*), (override));
MOCK_METHOD(PluginHost::IShell::state, State, (), (const, override));
MOCK_METHOD(void*, QueryInterfaceByCallsign, (const uint32_t, const string&), (override));
MOCK_METHOD(void*, QueryInterface, (const uint32_t), (override));
MOCK_METHOD(void, AddRef, (), (const, override));
MOCK_METHOD(uint32_t, Release, (), (const, override));
MOCK_METHOD(std::string, PluginPath, (), (const, override));
MOCK_METHOD(WPEFramework::Core::hresult, Activate, (const reason), (override));
MOCK_METHOD(WPEFramework::Core::hresult, Deactivate, (const reason), (override));
MOCK_METHOD(WPEFramework::Core::hresult, Unavailable, (const reason), (override));
MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t), (override));
MOCK_METHOD(reason, Reason, (), (const, override));
MOCK_METHOD(uint32_t, Submit, (const uint32_t, const Core::ProxyType<Core::JSON::IElement>&), (override));
MOCK_METHOD(ICOMLink*, COMLink, (), (override));
//MOCK_METHOD(Core::hresult, getServiceState, (const std::string&, const std::string&, PluginHost::IShell::state&), (override));
MOCK_METHOD(uint32_t, getServiceState, (PluginHost::IShell* shell, const string& callsign, PluginHost::IShell::state& state));
//MOCK_METHOD(Core::hresult, getServiceState, (const string&, const string&, PluginHost::IShell::state&), (const, override));
MOCK_METHOD(bool, queryIAuthService, (), ());
// Add any additional methods required by your build here.
};

class MockAuthService : public WPEFramework::Exchange::IAuthService {
public:
MOCK_METHOD(uint32_t, GetActivationStatus, (ActivationStatusResult&), (override));
MOCK_METHOD(uint32_t, SetActivationStatus, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, ClearAuthToken, (SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, ClearSessionToken, (SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, ClearServiceAccessToken, (SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, ClearLostAndFoundAccessToken, (SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, ClearServiceAccountId, (SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, ClearCustomProperties, (SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, GetCustomProperties, (std::string&, bool&), (override));
MOCK_METHOD(uint32_t, SetCustomProperties, (const std::string&, bool&), (override));
MOCK_METHOD(uint32_t, GetAlternateIds, (std::string&, std::string&, bool&), (override));
MOCK_METHOD(uint32_t, SetAlternateIds, (const std::string&, std::string&, bool&), (override));
MOCK_METHOD(uint32_t, GetTransitionData, (std::string&, std::string&, bool&), (override));
MOCK_METHOD(void, AddRef, (), (const, override));
MOCK_METHOD(uint32_t, Release, (), (const, override));
MOCK_METHOD(void*, QueryInterface, (uint32_t), (override));
MOCK_METHOD(uint32_t, Register, (IAuthService::INotification*), (override));
MOCK_METHOD(uint32_t, Unregister, (IAuthService::INotification*), (override));
MOCK_METHOD(uint32_t, Configure, (), (override));
MOCK_METHOD(uint32_t, GetInfo, (GetInfoResult&), (override));
MOCK_METHOD(uint32_t, GetDeviceInfo, (GetDeviceInfoResult&), (override));
MOCK_METHOD(uint32_t, GetDeviceId, (GetDeviceIdResult&), (override));


MOCK_METHOD(uint32_t, SetDeviceId, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, SetPartnerId, (const std::string&, SetPartnerIdResult&), (override));
MOCK_METHOD(uint32_t, GetAuthToken, (const bool, const bool, GetAuthTokenResult&), (override));
MOCK_METHOD(uint32_t, GetSessionToken, (GetSessionTokenResult&), (override));
MOCK_METHOD(uint32_t, SetSessionToken, (const int32_t&, const std::string&, uint32_t, const std::string&, const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, GetServiceAccessToken, (GetServiceAccessTokenResult&), (override));
MOCK_METHOD(uint32_t, SetServiceAccessToken, (const int32_t&, const std::string&, uint32_t, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, GetServiceAccountId, (GetServiceAccountIdResult&), (override));
MOCK_METHOD(uint32_t, SetServiceAccountId, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, SetAuthIdToken, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, Ready, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, GetBootstrapProperty, (const std::string&, GetBootstrapPropResult&), (override));
MOCK_METHOD(uint32_t, ActivationStarted, (SuccessResult&), (override));
MOCK_METHOD(uint32_t, ActivationComplete, (SuccessResult&), (override));
MOCK_METHOD(uint32_t, GetLostAndFoundAccessToken, (std::string&, std::string&, bool&), (override));
MOCK_METHOD(uint32_t, SetLostAndFoundAccessToken, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, GetXDeviceId, (GetXDeviceIdResult&), (override));
MOCK_METHOD(uint32_t, SetXDeviceId, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, GetExperience, (GetExpResult&), (override));
MOCK_METHOD(uint32_t, SetExperience, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, GetXifaId, (GetxifaIdResult&), (override));
MOCK_METHOD(uint32_t, SetXifaId, (const std::string&, SuccessMsgResult&), (override));
MOCK_METHOD(uint32_t, GetAdvtOptOut, (AdvtOptOutResult&), (override));
MOCK_METHOD(uint32_t, SetAdvtOptOut, (const bool&, SuccessMsgResult&), (override));
// ... and so on, for all pure virtuals
// Add any additional pure virtuals from base interfaces if compiler asks for them.
};

class MaintenanceManagerTest : public Test {
protected:
Core::ProxyType<Plugin::MaintenanceManager> plugin_;
Expand Down Expand Up @@ -95,6 +204,49 @@
}
};


class MaintenanceManagerCheckActivatedStatusTest : public MaintenanceManagerTest {
protected:
NiceMock<MockShell> mockService_;
NiceMock<MockAuthService> mockAuthServicePlugin_;

MaintenanceManagerCheckActivatedStatusTest() {
// Assign mock plugins
plugin_->m_service = &mockService_;
Copy link
Contributor

@rdkcmf-jenkins rdkcmf-jenkins Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverity issue no longer present as of: undefined

Show issue

Coverity Issue - Explicit null dereferenced

Attempting to access the managed object of an empty smart pointer "this->plugin_".

Medium Impact, CWE-476
FORWARD_NULL

plugin_->m_authservicePlugin = &mockAuthServicePlugin_;
}
class TestableMaintenanceManager : public Plugin::MaintenanceManager {
public:
std::string statusToReturn;
void setMockActivationStatus(const std::string& status) { statusToReturn = status; }

std::string checkActivatedStatus() {
return statusToReturn;
}
void AddRef() const override {
// No-op for test
}

uint32_t Release() const override {
return 0; // Dummy return
}
};

std::unique_ptr<TestableMaintenanceManager> plugin_;

void SetUp() override {
MaintenanceManagerTest::SetUp();
plugin_ = std::make_unique<TestableMaintenanceManager>();
}

void TearDown() override {
plugin_.reset();
}

virtual ~MaintenanceManagerCheckActivatedStatusTest() override {}
};


static AssertionResult isValidCtrlmRcuIarmEvent(IARM_EventId_t ctrlmRcuIarmEventId)
{
switch (ctrlmRcuIarmEventId) {
Expand Down Expand Up @@ -806,3 +958,65 @@
}
}
#endif
TEST_F(MaintenanceManagerCheckActivatedStatusTest, ServiceNotActivated) {
PluginHost::IShell::state state = PluginHost::IShell::state::UNAVAILABLE;

// Mock getServiceState to simulate UNAVAILABLE state
EXPECT_CALL(mockService_, getServiceState(_, _, _))
.WillRepeatedly(DoAll(::testing::SetArgReferee<2>(state), Return(Core::ERROR_NONE)));

// Mock queryIAuthService to return false (no interface)
//EXPECT_CALL(mockService_, queryIAuthService())
// .WillOnce(Return(false));

// Test: Plugin is not activated after retries, expect "invalid"
std::string result = plugin_->checkActivatedStatus();
EXPECT_EQ(result, "invalid");
}
// Test: Service Activated, No Interface
TEST_F(MaintenanceManagerCheckActivatedStatusTest, ServiceActivatedNoInterface) {
PluginHost::IShell::state state = PluginHost::IShell::state::ACTIVATED;

// Mock getServiceState to simulate ACTIVATED state
EXPECT_CALL(mockService_, getServiceState(_, _, _))
.WillRepeatedly(DoAll(::testing::SetArgReferee<2>(state), Return(Core::ERROR_NONE)));

// Mock queryIAuthService to return false (no interface)
EXPECT_CALL(mockService_, queryIAuthService())
.WillOnce(Return(false));

// Test: No interface available, expect "invalid"
std::string result = plugin_->checkActivatedStatus();
EXPECT_EQ(result, "invalid");
}

// Test: Successful Activation Status Retrieval
TEST_F(MaintenanceManagerCheckActivatedStatusTest, SuccessfulActivationStatus) {
PluginHost::IShell::state state = PluginHost::IShell::state::ACTIVATED;

// Mock getServiceState to simulate ACTIVATED state
EXPECT_CALL(mockService_, getServiceState(_, _, _))
.WillRepeatedly(DoAll(::testing::SetArgReferee<2>(state), Return(Core::ERROR_NONE)));

// Mock queryIAuthService to return true (interface available)
EXPECT_CALL(mockService_, queryIAuthService())
.WillOnce(Return(true));

// Mock GetActivationStatus to return a successful status
WPEFramework::Exchange::IAuthService::ActivationStatusResult asRes;
asRes.status = "activated"; // Simulating the status being "activated"
EXPECT_CALL(mockAuthServicePlugin_, GetActivationStatus(_))
.WillOnce(DoAll(::testing::SetArgReferee<0>(asRes), Return(Core::ERROR_NONE)));

// Test: Successfully retrieve the activation status, expect "activated"
std::string result = plugin_->checkActivatedStatus();
EXPECT_EQ(result, "activated");
}
TEST_F(MaintenanceManagerCheckActivatedStatusTest, ActivatedStatusReturnsTrueNoSkip) {
plugin_->setMockActivationStatus("activated");
bool skip = false;

EXPECT_TRUE(plugin_->getActivatedStatus(skip));
EXPECT_FALSE(skip);
}

Loading