From 6e00ace671251d8a0676b6990b887732e38b79f3 Mon Sep 17 00:00:00 2001 From: HaseenaSainul Date: Fri, 1 Dec 2023 04:22:52 -0500 Subject: [PATCH] Core/Manage: update in test app --- .../core/src/cpp/sdk/cpptest/CoreSDKTest.cpp | 2 +- .../core/src/cpp/sdk/cpptest/CoreSDKTest.h | 2 +- src/sdks/core/src/cpp/sdk/cpptest/Main.cpp | 142 ++++++++++-------- src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp | 70 +++++++-- .../src/cpp/sdk/cpptest/ManageSDKTest.cpp | 97 +++++++++++- .../src/cpp/sdk/cpptest/ManageSDKTest.h | 5 + 6 files changed, 234 insertions(+), 84 deletions(-) diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp index d6eeca4cc..443618035 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp @@ -123,7 +123,7 @@ void CoreSDKTest::GetDeviceModel() } } -void CoreSDKTest::GetDeviceSKU() +void CoreSDKTest::GetDeviceSku() { Firebolt::Error error = Firebolt::Error::None; const std::string sku = Firebolt::IFireboltAccessor::Instance().DeviceInterface().sku(&error); diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h index 61ff8eb36..d5ee900d4 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h @@ -54,7 +54,7 @@ class CoreSDKTest { static void SubscribeDeviceNameChanged(); static void UnsubscribeDeviceNameChanged(); static void GetDeviceModel(); - static void GetDeviceSKU(); + static void GetDeviceSku(); static void GetDeviceAudio(); static void SubscribeDeviceAudioChanged(); static void UnsubscribeDeviceAudioChanged(); diff --git a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp index a21407d97..444bd7fb4 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp @@ -4,23 +4,26 @@ void ShowMenu() { printf("Enter\n" - "\tD : Get Device Name\n" - "\tN : Subscribe/Unsubscribe for Device Name Change\n" - "\tA : Get Device Audio Profiles\n" - "\tS : Subscribe/Unsubscribe for Device Audio Profiles Change\n" - "\tR : Get Device Screen Resolution\n" - "\tU : Subscribe/Unsubscribe for Device Screen Resolution\n" - "\tL : Get Localization Preferred AudioLanguages\n" - "\tP : Subscribe/Unsubscribe for Localization Preferred AudioLanguages Change\n" - "\tC : Get Closed Caption Settings\n" - "\tB : Subscribe/Unsubscribe for Closed Caption Settings\n" - "\tK : Invoke keyboard methods email/password/standard\n" "\tM : Get Device Model\n" - "\tE : Get Device sku\n" + "\tS : Get Device Sku\n" + "\tN : Get/Subscribe/Unsubscribe Device Name\n" + "\tA : Get/Subscribe/Unsubscribe Device Audio Profiles\n" + "\tR : Get/Subscribe/Unsubscribe Device Screen Resolution\n" + "\tL : Get/Subscribe/Unsubscribe Localization Preferred AudioLanguages\n" + "\tC : Get/Subscribe/Unsubscribe Closed Caption Settings\n" + "\tK : Invoke keyboard methods email/password/standard\n" "\tQ : Quit\n\n" ); } +void ShowPropertyMenu(std::string& module, std::string& property) +{ + printf("%s:%s property options \n" + "\tG : Get value\n" + "\tR : Show subscribe/unscribe event menu\n" + "\tQ : Quit\n", module.c_str(), property.c_str()); +} + void ShowKeyboardMenu() { printf("Enter\n" @@ -38,6 +41,57 @@ void ShowEventMenu() "\tQ : Quit\n"); } +#define VALUE(string) #string +#define TO_STRING(string) VALUE(string) + +#define HandleEventListener(Module, eventFuncName) \ +{ \ + int opt; \ + do { \ + getchar(); \ + ShowEventMenu(); \ + printf("Enter option : "); \ + opt = toupper(getchar()); \ + switch (opt) { \ + case 'S': { \ + CoreSDKTest::Subscribe##Module##eventFuncName(); \ + break; \ + } \ + case 'U': { \ + CoreSDKTest::Unsubscribe##Module##eventFuncName(); \ + break; \ + } \ + default: \ + break; \ + } \ + } while (opt != 'Q'); \ +} + +#define HandleProperty(Module, Property) \ +{ \ + int opt; \ + do { \ + getchar(); \ + std::string module = TO_STRING(Module); \ + std::string property = TO_STRING(Property); \ + ShowPropertyMenu(module, property); \ + printf("Enter option : "); \ + opt = toupper(getchar()); \ + switch (opt) { \ + case 'G': { \ + CoreSDKTest::Get##Module##Property(); \ + break; \ + } \ + case 'R': { \ + HandleEventListener(Module, Property##Changed) \ + break; \ + } \ + default: \ + break; \ + } \ + } while (opt != 'Q'); \ +} + void HandleKeyboardMethodsInvokation() { int opt; @@ -65,29 +119,6 @@ void HandleKeyboardMethodsInvokation() } while (opt != 'Q'); } -#define HandleEventListener(Module, eventFuncName) \ -{ \ - int opt; \ - do { \ - getchar(); \ - ShowEventMenu(); \ - printf("Enter option : "); \ - opt = toupper(getchar()); \ - switch (opt) { \ - case 'S': { \ - CoreSDKTest::Subscribe##Module##eventFuncName(); \ - break; \ - } \ - case 'U': { \ - CoreSDKTest::Unsubscribe##Module##eventFuncName(); \ - break; \ - } \ - default: \ - break; \ - } \ - } while (opt != 'Q'); \ -} - #define options ":hu:" int main (int argc, char* argv[]) { @@ -116,59 +147,38 @@ int main (int argc, char* argv[]) printf("Enter option : "); option = toupper(getchar()); switch (option) { - case 'D': { - CoreSDKTest::GetDeviceName(); - break; - } case 'N': { - HandleEventListener(Device, NameChanged) + HandleProperty(Device, Name) break; } - case 'A': { - CoreSDKTest::GetDeviceAudio(); + case 'M': { + CoreSDKTest::GetDeviceModel(); break; } case 'S': { - HandleEventListener(Device, AudioChanged) + CoreSDKTest::GetDeviceSku(); break; } - case 'R': { - CoreSDKTest::GetDeviceScreenResolution(); + case 'A': { + HandleProperty(Device, Audio) break; } - case 'U': { - HandleEventListener(Device, ScreenResolutionChanged) + case 'R': { + HandleProperty(Device, ScreenResolution) break; } case 'L': { - CoreSDKTest::GetLocalizationPreferredAudioLanguages(); - break; - } - case 'P': { - HandleEventListener(Localization, PreferredAudioLanguagesChanged) + HandleProperty(Localization, PreferredAudioLanguages) break; } case 'C': { - CoreSDKTest::GetAccessibilityClosedCaptionsSettings(); - break; - } - case 'B': { - HandleEventListener(Accessibility, ClosedCaptionsSettingsChanged) + HandleProperty(Accessibility, ClosedCaptionsSettings) break; } case 'K': { HandleKeyboardMethodsInvokation(); break; } - case 'M': { - CoreSDKTest::GetDeviceModel(); - break; - } - case 'E': { - CoreSDKTest::GetDeviceSKU(); - break; - } - default: break; } diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp index 59f597322..fbde8a98e 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp @@ -12,44 +12,88 @@ void ShowMenu() "\tA : Register for Acknowledge Challenge Provider and check sequence\n" "\tP : Register for Pin Challenge Provider and check sequence\n" "\tI : Operate on Localization Additional Info\n" + "\tU : Grant/Deny/Clear permission on App\n" "\tQ : Quit\n\n" ); } +void ShowUserGrantsMenu() +{ + printf("Invoke lifecyclesession management sequence from postman \n" + "Once the permission granted/denies/cleared, please use provider + api test to validate it \n" + "Here capabilty used for the testing is hardcoded as device:model\n" + "\tG : Get Permission\n" + "\tR : Grant Permission\n" + "\tD : Deny Permission\n" + "\tC : Clear Permission\n" + "\tQ : Quit\n"); +} + void ShowAdditionalInfoMenu() { printf("Options \n" - "\tG: Get Additional Info\n" - "\tA: Add Additional Info\n" - "\tR: Remove Additional Info\n" + "\tG : Get Additional Info\n" + "\tA : Add Additional Info\n" + "\tR : Remove Additional Info\n" "\tQ : Quit\n"); } void ShowPropertyMenu(std::string& module, std::string& property) { printf("%s:%s property options \n" - "\tG: Get value\n" - "\tS: Set value\n" - "\tR: Show subscribe/unscribe event menu\n" + "\tG : Get value\n" + "\tS : Set value\n" + "\tR : Show subscribe/unscribe event menu\n" "\tQ : Quit\n", module.c_str(), property.c_str()); } void ShowProviderMenu(std::string& module) { - printf("Invoke %s onRequest sequence from other entity and press\n" - "\tR: To Send Response\n" - "\tE: To Send Error\n" + printf("Invoke lifecyclesession management from postman and api sequence from other entity for %s and press\n" + "\tR : To Send Response\n" + "\tE : To Send Error\n" "\tQ : Quit\n", module.c_str()); } void ShowEventMenu() { printf("Options \n" - "\tS: Subscribe Event\n" - "\tU: Unsubscribe Event\n" + "\tS : Subscribe Event\n" + "\tU : Unsubscribe Event\n" "\tQ : Quit\n"); } +void HandleUserGrants() +{ + int opt; + do { + getchar(); + ShowUserGrantsMenu(); + printf("Enter option : "); + opt = toupper(getchar()); + switch (opt) { + case 'G': { + ManageSDKTest::GetUserGrantsPermission(); + break; + } + case 'R': { + ManageSDKTest::GrantUserGrantsPermission(); + break; + } + case 'D': { + ManageSDKTest::DenyUserGrantsPermission(); + break; + } + case 'C': { + ManageSDKTest::ClearUserGrantsPermission(); + break; + } + default: + break; + } + } while (opt != 'Q'); +} + void HandleAdditionalInfo() { int opt; @@ -219,6 +263,10 @@ int main (int argc, char* argv[]) HandleAdditionalInfo(); break; } + case 'U': { + HandleUserGrants(); + break; + } default: break; } diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp index f7387b8ab..fed158c43 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp @@ -305,12 +305,12 @@ void ManageSDKTest::SetLocalizationPreferredAudioLanguages() getline(cin, language); std::vector newLanguages; - char* delimeter = " "; - char* token = strtok(const_cast(language.c_str()), delimeter); + string delimeter = " "; + char* token = strtok(const_cast(language.c_str()), delimeter.c_str()); while (token != nullptr) { newLanguages.push_back(string(token)); - token = strtok(nullptr, delimeter); + token = strtok(nullptr, delimeter.c_str()); } Firebolt::IFireboltAccessor::Instance().LocalizationInterface().setPreferredAudioLanguages(newLanguages, &error); @@ -513,7 +513,7 @@ void ManageSDKTest::AcknowledgeChallengeProvider::SendMessage(bool response) void ManageSDKTest::AcknowledgeChallengeProvider::challenge(const Firebolt::AcknowledgeChallenge::Challenge& parameters, std::unique_ptr session) { - cout << "KeyboardProvider Standard is invoked" << endl; + cout << "AcknowledgeChallengeProvider challenge is invoked" << endl; startAcknowledgeChallengeSession(parameters, std::move(session)); } @@ -584,7 +584,7 @@ void ManageSDKTest::PinChallengeProvider::SendMessage(bool response) void ManageSDKTest::PinChallengeProvider::challenge(const Firebolt::PinChallenge::PinChallenge& parameters, std::unique_ptr session) { - cout << "KeyboardProvider Standard is invoked" << endl; + cout << "PinChallengeProvider challenge is invoked" << endl; startPinChallengeSession(parameters, std::move(session)); } @@ -664,3 +664,90 @@ void ManageSDKTest::RemoveLocalizationAdditionalInfo() } +void ManageSDKTest::GetUserGrantsPermission() +{ + Firebolt::Error error = Firebolt::Error::None; + cout << "Enter appId :"; + getchar(); + std::string appId; + getline(cin, appId); + + std::vector grantInfo = Firebolt::IFireboltAccessor::Instance().UserGrantsInterface().app(appId, &error); + if (error == Firebolt::Error::None) { + cout << "Get UserGrants Permission is success" << endl; + if (grantInfo.size() > 0) { + cout << "Grant Permission list : " << endl; + for (auto info : grantInfo) { + cout << "GrantState : " << static_cast(info.state) << endl; + cout << "Capability : " << info.capability << endl; + cout << "Role : " << static_cast(info.role) << endl; + cout << "Lifespan : " << static_cast(info.lifespan) << endl; + } + } + } else { + cout << "Get UserGrants Permission status = " << static_cast(error) << endl; + } + + cin.putback('\n'); +} + +void ManageSDKTest::GrantUserGrantsPermission() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::UserGrants::GrantModificationOptions grantModificationOptions; + cout << "Enter appId :"; + getchar(); + std::string appId; + getline(cin, appId); + grantModificationOptions.appId = std::make_optional(appId); + + Firebolt::IFireboltAccessor::Instance().UserGrantsInterface().grant(Firebolt::Capabilities::Role::USE, "xrn:firebolt:capability:device:model", grantModificationOptions, &error); + if (error == Firebolt::Error::None) { + cout << "Grant UserGrants Permission is success" << endl; + } else { + cout << "Grant UserGrants Permission status = " << static_cast(error) << endl; + } + + cin.putback('\n'); +} + +void ManageSDKTest::DenyUserGrantsPermission() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::UserGrants::GrantModificationOptions grantModificationOptions; + cout << "Enter appId :"; + getchar(); + std::string appId; + getline(cin, appId); + grantModificationOptions.appId = std::make_optional(appId); + + Firebolt::IFireboltAccessor::Instance().UserGrantsInterface().deny(Firebolt::Capabilities::Role::USE, "xrn:firebolt:capability:device:model", grantModificationOptions, &error); + if (error == Firebolt::Error::None) { + cout << "Deny UserGrants Permission is success" << endl; + } else { + cout << "Deny UserGrants Permission status = " << static_cast(error) << endl; + } + + cin.putback('\n'); +} + +void ManageSDKTest::ClearUserGrantsPermission() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::UserGrants::GrantModificationOptions grantModificationOptions; + cout << "Enter appId :"; + getchar(); + std::string appId; + getline(cin, appId); + grantModificationOptions.appId = std::make_optional(appId); + + Firebolt::IFireboltAccessor::Instance().UserGrantsInterface().clear(Firebolt::Capabilities::Role::USE, "xrn:firebolt:capability:device:model", grantModificationOptions, &error); + if (error == Firebolt::Error::None) { + cout << "Clear UserGrants Permission is success" << endl; + } else { + cout << "Clear UserGrants Permission status = " << static_cast(error) << endl; + } + + cin.putback('\n'); +} + diff --git a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h index 41a7ef85d..3d3752eda 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.h @@ -137,6 +137,11 @@ class ManageSDKTest { static void AddLocalizationAdditionalInfo(); static void RemoveLocalizationAdditionalInfo(); + static void GetUserGrantsPermission(); + static void GrantUserGrantsPermission(); + static void DenyUserGrantsPermission(); + static void ClearUserGrantsPermission(); + static bool WaitOnConnectionReady(); private: