Skip to content

Commit

Permalink
CPPSDK: Core & Manage test updates with more test: lifecycle test cas…
Browse files Browse the repository at this point in the history
…es are added
  • Loading branch information
HaseenaSainul committed Dec 7, 2023
1 parent 72e453c commit a65919e
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 3 deletions.
88 changes: 88 additions & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(error) << endl;
Expand Down Expand Up @@ -532,3 +535,88 @@ void CoreSDKTest::GetProfileFlags()
cout << "Get Profile flags status : " << static_cast<int>(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<Firebolt::Lifecycle::CloseReason>(reason), &error);
if (error == Firebolt::Error::None) {
cout << "Lifecycle close is success" << endl;
} else {
cout << "Lifecycle close status = " << static_cast<int>(error) << endl;
}
}
EnumMap<Firebolt::Lifecycle::LifecycleState> 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<Firebolt::Lifecycle::LifecycleEventSource> 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<Firebolt::Lifecycle::LifecycleState>(lifecycleStateMap, lifecycleEvent.state) << endl;
cout <<"\tprevious: " << ConvertFromEnum<Firebolt::Lifecycle::LifecycleState>(lifecycleStateMap, lifecycleEvent.previous) << endl;
if (lifecycleEvent.source.has_value()) {
cout <<"\tsource: " << ConvertFromEnum<Firebolt::Lifecycle::LifecycleEventSource>(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<int>(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<int>(error) << endl;
}
}
void CoreSDKTest::OnForegroundNotification::onForeground( const Firebolt::Lifecycle::LifecycleEvent& lifecycleEvent)
{
cout <<"onForeground event is triggered" << endl;
cout <<"\tstate: " << ConvertFromEnum<Firebolt::Lifecycle::LifecycleState>(lifecycleStateMap, lifecycleEvent.state) << endl;
cout <<"\tprevious: " << ConvertFromEnum<Firebolt::Lifecycle::LifecycleState>(lifecycleStateMap, lifecycleEvent.previous) << endl;
if (lifecycleEvent.source.has_value()) {
cout <<"\tsource: " << ConvertFromEnum<Firebolt::Lifecycle::LifecycleEventSource>(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<int>(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<int>(error) << endl;
}
}

24 changes: 23 additions & 1 deletion src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,24 @@ 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;

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();
Expand All @@ -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:
Expand All @@ -95,5 +115,7 @@ class CoreSDKTest {
static OnScreenResolutionChangedNotification _screenResolutionChangedNotification;
static OnPreferredAudioLanguagesChangedNotification _preferredAudioLanguagesChangedNotification;
static OnClosedCaptionsSettingsChangedNotification _closedCaptionsSettingsChangedNotification;
static OnBackgroundNotification _backgroundNotification;
static OnForegroundNotification _foregroundNotification;
};

41 changes: 41 additions & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -272,6 +309,10 @@ int main (int argc, char* argv[])
HandleProfileMethod();
break;
}
case 'F': {
HandleLifecycleMethod();
break;
}
default:
break;
}
Expand Down
2 changes: 0 additions & 2 deletions src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -697,7 +696,6 @@ void ManageSDKTest::PinChallengeProvider::SendMessage(bool response)
if (_challengeInput) {
cout << " Invoking _session->focus " << endl;
_session->focus();
getchar();
cout << " pinSpace : " << static_cast<int>(_parameters.pinSpace) << endl;
if (_parameters.capability.has_value()) {
cout << " capability : " << _parameters.capability.value() << endl;
Expand Down

0 comments on commit a65919e

Please sign in to comment.