diff --git a/rfcMgr/gtest/gtest_main.cpp b/rfcMgr/gtest/gtest_main.cpp index 11cbf3ae..bcab16ba 100644 --- a/rfcMgr/gtest/gtest_main.cpp +++ b/rfcMgr/gtest/gtest_main.cpp @@ -1335,6 +1335,129 @@ TEST(rfcMgrTest, EmptyFeatures) { } } +// RDKEMW-11615: AccountID Validation Tests +class AccountIDValidationTest : public ::testing::Test { +protected: + std::string currentAccountID; + std::string unknownStr; + + void SetUp() override { + currentAccountID = "3064488088886635972"; + unknownStr = "Unknown"; + } +}; + +// Test case: Empty AccountID should be rejected +TEST_F(AccountIDValidationTest, EmptyAccountIDRejected) +{ + std::string emptyValue = ""; + EXPECT_TRUE(emptyValue.empty()); +} + +// Test case: Unknown AccountID should be replaced with current value +TEST_F(AccountIDValidationTest, UnknownAccountIDReplaced) +{ + std::string receivedAccountID = "Unknown"; + std::string replacementAccountID = currentAccountID; + + // Check if received value is "Unknown" + bool isUnknown = StringCaseCompare(receivedAccountID, unknownStr); + EXPECT_TRUE(isUnknown); + + // When unknown, should use current value + if (isUnknown) { + receivedAccountID = replacementAccountID; + } + + EXPECT_EQ(receivedAccountID, "3064488088886635972"); +} + +// Test case: Valid AccountID should be accepted +TEST_F(AccountIDValidationTest, ValidAccountIDAccepted) +{ + std::string validAccountID = "3064488088886635972"; + std::string currentValue = "OldAccountID"; + + // Check if it's not empty and not "Unknown" + bool isValid = (!validAccountID.empty() && !StringCaseCompare(validAccountID, unknownStr)); + EXPECT_TRUE(isValid); +} + +// Test case: AccountID comparison should be case-insensitive +TEST_F(AccountIDValidationTest, UnknownCaseInsensitiveComparison) +{ + std::string unknownUpper = "UNKNOWN"; + std::string unknownMixed = "UnKnOwN"; + + EXPECT_TRUE(StringCaseCompare(unknownUpper, unknownStr)); + EXPECT_TRUE(StringCaseCompare(unknownMixed, unknownStr)); +} + +// Test case: Config value change detection +TEST_F(AccountIDValidationTest, ConfigValueChangeDetection) +{ + std::string currentValue = "OldAccountID"; + std::string newValue = "3064488088886635972"; + + bool valueChanged = (currentValue != newValue); + EXPECT_TRUE(valueChanged); +} + +// Test case: No change when current and new values are same +TEST_F(AccountIDValidationTest, NoConfigValueChangeWhenSame) +{ + std::string currentValue = "3064488088886635972"; + std::string newValue = "3064488088886635972"; + + bool valueChanged = (currentValue != newValue); + EXPECT_FALSE(valueChanged); +} + +TEST(rfcMgrTest, GetAccountID_ValidValue) { + writeToTr181storeFile("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID", "3064488088886635972", "/opt/secure/RFC/tr181store.ini", Quoted); + RuntimeFeatureControlProcessor *rfcObj = new RuntimeFeatureControlProcessor(); + rfcObj->GetAccountID(); + EXPECT_EQ(rfcObj->_accountId, "3064488088886635972"); + EXPECT_FALSE(StringCaseCompare(rfcObj->_accountId, "Unknown")); + delete rfcObj; +} + +TEST(rfcMgrTest, GetAccountID_UnknownValue) { + writeToTr181storeFile("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID", "Unknown", "/opt/secure/RFC/tr181store.ini", Quoted); + RuntimeFeatureControlProcessor *rfcObj = new RuntimeFeatureControlProcessor(); + rfcObj->GetAccountID(); + EXPECT_TRUE(StringCaseCompare(rfcObj->_accountId, "Unknown")); + delete rfcObj; +} + +TEST(rfcMgrTest, GetAccountID_EmptyValue) { + writeToTr181storeFile("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID", "", "/opt/secure/RFC/tr181store.ini", Quoted); + RuntimeFeatureControlProcessor *rfcObj = new RuntimeFeatureControlProcessor(); + rfcObj->GetAccountID(); + EXPECT_TRUE(rfcObj->_accountId.empty()); + delete rfcObj; +} + +TEST(rfcMgrTest, GetValidAccountId_ReplacesUnknown) { + RuntimeFeatureControlProcessor *rfcObj = new RuntimeFeatureControlProcessor(); + rfcObj->_accountId = "4123705941507160513"; + rfcObj->_RFCKeyAndValueMap[RFC_ACCOUNT_ID_KEY_STR] = "Unknown"; + rfcObj->GetValidAccountId(); + // Should use the stored valid account ID instead of "Unknown" + EXPECT_EQ(rfcObj->_valid_accountId, "4123705941507160513"); + delete rfcObj; +} + +TEST(rfcMgrTest, GetValidAccountId_RejectsEmpty) { + RuntimeFeatureControlProcessor *rfcObj = new RuntimeFeatureControlProcessor(); + rfcObj->_accountId = "4123705941507160513"; + rfcObj->_RFCKeyAndValueMap[RFC_ACCOUNT_ID_KEY_STR] = ""; + rfcObj->GetValidAccountId(); + // Should use the stored valid account ID instead of empty string + EXPECT_EQ(rfcObj->_valid_accountId, "4123705941507160513"); + delete rfcObj; +} + GTEST_API_ int main(int argc, char *argv[]){ ::testing::InitGoogleTest(&argc, argv); diff --git a/rfcMgr/rfc_xconf_handler.h b/rfcMgr/rfc_xconf_handler.h index b2fa4aa0..4f568a8c 100644 --- a/rfcMgr/rfc_xconf_handler.h +++ b/rfcMgr/rfc_xconf_handler.h @@ -291,6 +291,11 @@ class RuntimeFeatureControlProcessor : public xconf::XconfHandler FRIEND_TEST(rfcMgrTest, ValidPartnerId); FRIEND_TEST(rfcMgrTest, Removed_PERSISTENCE_FILE); FRIEND_TEST(rfcMgrTest, EmptyFeatures); + FRIEND_TEST(rfcMgrTest, GetAccountID_ValidValue); + FRIEND_TEST(rfcMgrTest, GetAccountID_UnknownValue); + FRIEND_TEST(rfcMgrTest, GetAccountID_EmptyValue); + FRIEND_TEST(rfcMgrTest, GetValidAccountId_ReplacesUnknown); + FRIEND_TEST(rfcMgrTest, GetValidAccountId_RejectsEmpty); #endif }; diff --git a/rfcMgr/xconf_handler.h b/rfcMgr/xconf_handler.h index f7e52ac2..7589c0da 100644 --- a/rfcMgr/xconf_handler.h +++ b/rfcMgr/xconf_handler.h @@ -36,7 +36,7 @@ extern "C" { namespace xconf { class XconfHandler { public : - XconfHandler(){ } + XconfHandler() : _ebuild_type(eUNKNOWN) { } int initializeXconfHandler(void); // We do not allow this class to be copied !! diff --git a/test/rfcTest.cpp b/test/rfcTest.cpp index 24add97e..6e3048c3 100644 --- a/test/rfcTest.cpp +++ b/test/rfcTest.cpp @@ -19,14 +19,21 @@ #include "gtest/gtest.h" + + int add(int num1,int num2) { return (num1+num2); } + + TEST(Add, PositiveCase) { EXPECT_EQ(30,add(10,20)); EXPECT_EQ(50,add(30,20)); } + + +