From a65919ef6358b8fca06d56cd3ef10f871b723f99 Mon Sep 17 00:00:00 2001 From: HaseenaSainul Date: Thu, 7 Dec 2023 03:04:30 -0500 Subject: [PATCH] CPPSDK: Core & Manage test updates with more test: lifecycle test cases are added --- .../core/src/cpp/sdk/cpptest/CoreSDKTest.cpp | 88 +++++++++++++++++++ .../core/src/cpp/sdk/cpptest/CoreSDKTest.h | 24 ++++- src/sdks/core/src/cpp/sdk/cpptest/Main.cpp | 41 +++++++++ .../src/cpp/sdk/cpptest/ManageSDKTest.cpp | 2 - 4 files changed, 152 insertions(+), 3 deletions(-) diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp index 946490508..379bf5430 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp @@ -28,6 +28,9 @@ CoreSDKTest::OnAudioChangedNotification CoreSDKTest::_audioChangedNotification; CoreSDKTest::OnScreenResolutionChangedNotification CoreSDKTest::_screenResolutionChangedNotification; CoreSDKTest::OnClosedCaptionsSettingsChangedNotification CoreSDKTest::_closedCaptionsSettingsChangedNotification; CoreSDKTest::OnPreferredAudioLanguagesChangedNotification CoreSDKTest::_preferredAudioLanguagesChangedNotification; +CoreSDKTest::OnBackgroundNotification CoreSDKTest::_backgroundNotification; +CoreSDKTest::OnForegroundNotification CoreSDKTest::_foregroundNotification; + void CoreSDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error) { cout << "Change in connection: connected: " << connected << " error: " << static_cast(error) << endl; @@ -532,3 +535,88 @@ void CoreSDKTest::GetProfileFlags() cout << "Get Profile flags status : " << static_cast(error) << endl; } } + +void CoreSDKTest::LifecycleClose() +{ + Firebolt::Error error = Firebolt::Error::None; + cout << "Enter close reason remote button(0), user exit(1), done(2) or error(3)" << endl; + int32_t reason; + cin >> reason; + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().close(static_cast(reason), &error); + if (error == Firebolt::Error::None) { + cout << "Lifecycle close is success" << endl; + } else { + cout << "Lifecycle close status = " << static_cast(error) << endl; + } +} +EnumMap lifecycleStateMap = { + { Firebolt::Lifecycle::LifecycleState::INITIALIZING, "initializing" }, + { Firebolt::Lifecycle::LifecycleState::INACTIVE, "inactive" }, + { Firebolt::Lifecycle::LifecycleState::FOREGROUND, "foreground" }, + { Firebolt::Lifecycle::LifecycleState::BACKGROUND, "background" }, + { Firebolt::Lifecycle::LifecycleState::UNLOADING, "unloading" }, + { Firebolt::Lifecycle::LifecycleState::SUSPENDED, "suspended" } +}; +EnumMap lifecycleEventSourceMap = { + { Firebolt::Lifecycle::LifecycleEventSource::VOICE, "voice" }, + { Firebolt::Lifecycle::LifecycleEventSource::REMOTE, "remote" } +}; +void CoreSDKTest::OnBackgroundNotification::onBackground( const Firebolt::Lifecycle::LifecycleEvent& lifecycleEvent) +{ + cout <<"onBackground event is triggered" << endl; + cout <<"\tstate: " << ConvertFromEnum(lifecycleStateMap, lifecycleEvent.state) << endl; + cout <<"\tprevious: " << ConvertFromEnum(lifecycleStateMap, lifecycleEvent.previous) << endl; + if (lifecycleEvent.source.has_value()) { + cout <<"\tsource: " << ConvertFromEnum(lifecycleEventSourceMap, lifecycleEvent.source.value()) << endl; + } +} +void CoreSDKTest::SubscribeLifecycleBackgroundNotification() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().subscribe(_backgroundNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Subscribe Lifecycle BackgroundNotification is success" << endl; + } else { + cout << "Subscribe Lifecycle BackgroundNotification status = " << static_cast(error) << endl; + } +} +void CoreSDKTest::UnsubscribeLifecycleBackgroundNotification() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().unsubscribe(_backgroundNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Unsubscribe Lifecycle BackgroundNotification is success" << endl; + } else { + cout << "Unsubscribe Lifecycle BackgroundNotification status = " << static_cast(error) << endl; + } +} +void CoreSDKTest::OnForegroundNotification::onForeground( const Firebolt::Lifecycle::LifecycleEvent& lifecycleEvent) +{ + cout <<"onForeground event is triggered" << endl; + cout <<"\tstate: " << ConvertFromEnum(lifecycleStateMap, lifecycleEvent.state) << endl; + cout <<"\tprevious: " << ConvertFromEnum(lifecycleStateMap, lifecycleEvent.previous) << endl; + if (lifecycleEvent.source.has_value()) { + cout <<"\tsource: " << ConvertFromEnum(lifecycleEventSourceMap, lifecycleEvent.source.value()) << endl; + } +} +void CoreSDKTest::SubscribeLifecycleForegroundNotification() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().subscribe(_foregroundNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Subscribe Lifecycle ForegroundNotification is success" << endl; + } else { + cout << "Subscribe Lifecycle ForegroundNotification status = " << static_cast(error) << endl; + } +} +void CoreSDKTest::UnsubscribeLifecycleForegroundNotification() +{ + Firebolt::Error error = Firebolt::Error::None; + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().unsubscribe(_foregroundNotification, &error); + if (error == Firebolt::Error::None) { + cout << "Unsubscribe Lifecycle ForegroundNotification is success" << endl; + } else { + cout << "Unsubscribe Lifecycle ForegroundNotification status = " << static_cast(error) << endl; + } +} + diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h index 9c0196999..fa19c5d22 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h @@ -46,6 +46,13 @@ class CoreSDKTest { void onClosedCaptionsSettingsChanged( const Firebolt::Accessibility::ClosedCaptionsSettings& ) override; }; + struct OnBackgroundNotification : public Firebolt::Lifecycle::ILifecycle::IOnBackgroundNotification { + void onBackground( const Firebolt::Lifecycle::LifecycleEvent& ) override; + }; + struct OnForegroundNotification : public Firebolt::Lifecycle::ILifecycle::IOnForegroundNotification { + void onForeground( const Firebolt::Lifecycle::LifecycleEvent& ) override; + }; + public: CoreSDKTest() = default; virtual ~CoreSDKTest() = default; @@ -53,8 +60,10 @@ class CoreSDKTest { static void CreateFireboltInstance(const std::string& url); static void DestroyFireboltInstance(); static void TestCoreStaticSDK(); + static void GetAccountId(); static void GetAccountUid(); + static void GetDeviceName(); static void SubscribeDeviceNameChanged(); static void UnsubscribeDeviceNameChanged(); @@ -66,24 +75,35 @@ class CoreSDKTest { static void GetDeviceScreenResolution(); static void SubscribeDeviceScreenResolutionChanged(); static void UnsubscribeDeviceScreenResolutionChanged(); + static void GetLocalizationPreferredAudioLanguages(); - static void SetLocalizationPreferredAudioLanguages(); static void SubscribeLocalizationPreferredAudioLanguagesChanged(); static void UnsubscribeLocalizationPreferredAudioLanguagesChanged(); + static void GetAccessibilityClosedCaptionsSettings(); static void SubscribeAccessibilityClosedCaptionsSettingsChanged(); static void UnsubscribeAccessibilityClosedCaptionsSettingsChanged(); + static void GetAdvertisingPolicy(); static void SubscribeAdvertisingPolicyChanged(); static void UnsubscribeAdvertisingPolicyChanged(); static void BuildAdvertisingConfiguration(); static void GetAdvertisingDeviceAttributes(); + static void InvokeKeyboardStandard(); static void InvokeKeyboardPassword(); static void InvokeKeyboardEmail(); + static void VerifyProfileApproveContentRating(); static void VerifyProfileApprovePurchase(); static void GetProfileFlags(); + + static void LifecycleClose(); + static void SubscribeLifecycleBackgroundNotification(); + static void UnsubscribeLifecycleBackgroundNotification(); + static void SubscribeLifecycleForegroundNotification(); + static void UnsubscribeLifecycleForegroundNotification(); + static bool WaitOnConnectionReady(); private: @@ -95,5 +115,7 @@ class CoreSDKTest { static OnScreenResolutionChangedNotification _screenResolutionChangedNotification; static OnPreferredAudioLanguagesChangedNotification _preferredAudioLanguagesChangedNotification; static OnClosedCaptionsSettingsChangedNotification _closedCaptionsSettingsChangedNotification; + static OnBackgroundNotification _backgroundNotification; + static OnForegroundNotification _foregroundNotification; }; diff --git a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp index 306d90f19..68f53af06 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp @@ -16,6 +16,7 @@ void ShowMenu() "\tC : Get/Subscribe/Unsubscribe Closed Caption Settings\n" "\tK : Invoke keyboard methods email/password/standard\n" "\tV : Handle Profile methods\n" + "\tF : Handle Lifecycle methods\n" "\tQ : Quit\n\n" ); } @@ -46,6 +47,15 @@ void ShowAdvertisingMenu() "\tQ : Quit\n"); } +void ShowLifecycleMenu() +{ + printf("Options: \n" + "\tC : Close lifecycle of the app\n" + "\tB : Subscribe/Unsubscribe Background notification\n" + "\tF : Subscribe/Unsubscribe Foreground notification\n" + "\tQ : Quit\n"); +} + void ShowKeyboardMenu() { printf("Enter\n" @@ -169,6 +179,33 @@ void HandleAdvertisingMethod() } while (opt != 'Q'); } +void HandleLifecycleMethod() +{ + int opt; + do { + getchar(); + ShowLifecycleMenu(); + printf("Enter option : "); + opt = toupper(getchar()); + switch (opt) { + case 'C': { + CoreSDKTest::LifecycleClose(); + break; + } + case 'B': { + HandleEventListener(Lifecycle, BackgroundNotification) + break; + } + case 'F': { + HandleEventListener(Lifecycle, ForegroundNotification) + break; + } + default: + break; + } + } while (opt != 'Q'); +} + void HandleKeyboardMethodsInvokation() { int opt; @@ -272,6 +309,10 @@ int main (int argc, char* argv[]) HandleProfileMethod(); break; } + case 'F': { + HandleLifecycleMethod(); + 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 728a30842..ae9c868a3 100644 --- a/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp +++ b/src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp @@ -637,7 +637,6 @@ void ManageSDKTest::AcknowledgeChallengeProvider::SendMessage(bool response) if (_challengeInput) { cout << " Invoking _session->focus " << endl; _session->focus(); - getchar(); cout << " capability : " << _parameters.capability << endl; cout << " id : " << _parameters.requestor.id << endl; cout << " name : " << _parameters.requestor.name << endl; @@ -697,7 +696,6 @@ void ManageSDKTest::PinChallengeProvider::SendMessage(bool response) if (_challengeInput) { cout << " Invoking _session->focus " << endl; _session->focus(); - getchar(); cout << " pinSpace : " << static_cast(_parameters.pinSpace) << endl; if (_parameters.capability.has_value()) { cout << " capability : " << _parameters.capability.value() << endl;