Skip to content

Commit

Permalink
CPPSDK: test event sample test added (rdkcentral#192)
Browse files Browse the repository at this point in the history
* CPPSDK: test event sample test added

* CPPSDK: more event test added
  • Loading branch information
HaseenaSainul authored Oct 11, 2023
1 parent 7b88a18 commit ae1cd80
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 13 deletions.
60 changes: 58 additions & 2 deletions src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,52 @@ void ShowMenu()
printf("Enter\n"
"\tN : Get Device Name\n"
"\tS : Set Device Name\n"
"\tC : Subscribe/Unsubscribe for Device Name Change\n"
"\tB : Get ClosedCaption Background Opacity\n"
"\tO : Set ClosedCaption Background Opacity\n"
"\tY : Subscribe/Unsubscribe for ClosedCaption Background Opacity Change\n"
"\tF : Get ClosedCaption Font Family\n"
"\tM : Set ClosedCaption Font Family\n"
"\tI : Subscribe/Unsubscribe for ClosedCaption Font Family Change\n"
"\tL : Get Localization Preferred AudioLanguages\n"
"\tP : Set Localization Preferred AudioLanguages\n"
"\tA : Set Localization Preferred AudioLanguages\n"
"\tR : Subscribe/Unsubscribe for Localization Preferred AudioLanguages Change\n"
"\tP : Subscribe/Unsubscribe for PinChallenge RequestChallenge\n"
"\tQ : Quit\n\n"
);
}

void ShowEventMenu()
{
printf("Enter\n"
"\tS: Subscribe Event\n"
"\tU: Unsubscribe Event\n"
"\tQ : Quit\n");
}

#define HandleEventListener(Module, eventFuncName) \
{ \
int opt; \
do { \
getchar(); \
ShowEventMenu(); \
printf("Enter option : "); \
opt = toupper(getchar()); \
switch (opt) { \
case 'S': { \
ManageSDKTest::Subscribe##Module##eventFuncName(); \
break; \
} \
case 'U': { \
ManageSDKTest::Unsubscribe##Module##eventFuncName(); \
break; \
} \
default: \
break; \
} \
} while (opt != 'Q'); \
}

int main (int argc, char* argv[])
{
char* config = "{\
Expand Down Expand Up @@ -47,6 +83,10 @@ int main (int argc, char* argv[])
ManageSDKTest::SetDeviceName();
break;
}
case 'C': {
HandleEventListener(Device, NameChanged)
break;
}
case 'B': {
ManageSDKTest::GetClosedCaptionBackgroundOpacity();
break;
Expand All @@ -55,6 +95,10 @@ int main (int argc, char* argv[])
ManageSDKTest::SetClosedCaptionBackgroundOpacity();
break;
}
case 'Y': {
HandleEventListener(ClosedCaptions, BackgroundOpacityChanged)
break;
}
case 'F': {
ManageSDKTest::GetClosedCaptionFontFamily();
break;
Expand All @@ -63,14 +107,26 @@ int main (int argc, char* argv[])
ManageSDKTest::SetClosedCaptionFontFamily();
break;
}
case 'I': {
HandleEventListener(ClosedCaptions, FontFamilyChanged)
break;
}
case 'L': {
ManageSDKTest::GetLocalizationPreferredAudioLanguages();
break;
}
case 'P': {
case 'A': {
ManageSDKTest::SetLocalizationPreferredAudioLanguages();
break;
}
case 'R': {
HandleEventListener(Localization, PreferredAudioLanguagesChanged)
break;
}
case 'P': {
HandleEventListener(PinChallenge, RequestChallenge)
break;
}

default:
break;
Expand Down
190 changes: 180 additions & 10 deletions src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@
*/

#include <unistd.h>
#include "firebolt.h"
#include "ManageSDKTest.h"

using namespace std;
bool ManageSDKTest::_connected;
ManageSDKTest::OnDeviceNameChangedNotification ManageSDKTest::_deviceNameChangedNotification;
ManageSDKTest::OnFontFamilyChangedNotification ManageSDKTest::_fontFamilyChangedNotification;
ManageSDKTest::OnBackgroundOpacityChangedNotification ManageSDKTest::_backgroundOpacityChangedNotification;
ManageSDKTest::OnPreferredAudioLanguagesChangedNotification ManageSDKTest::_preferredAudioLanguagesChangedNotification;
ManageSDKTest::OnRequestChallengeNotification ManageSDKTest::_requestChallengeNotification;

void ManageSDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error)
{
cout << "Change in connection: connected: " << connected << " error: " << static_cast<int>(error) << endl;
_connected = connected;
cout << "Change in connection: connected: " << connected << " error: " << static_cast<int>(error) << endl;
_connected = connected;
}

void ManageSDKTest::CreateFireboltInstance()
Expand Down Expand Up @@ -75,9 +79,9 @@ void ManageSDKTest::GetDeviceName()
const std::string name = Firebolt::IFireboltAccessor::Instance().DeviceInterface().Name(&error);

if (error == Firebolt::Error::None) {
cout << "Get DeviceName = " << name.c_str() << endl;
cout << "Get Device Name = " << name.c_str() << endl;
} else {
cout << "Get DeviceName status = " << static_cast<int>(error) << endl;
cout << "Get Device Name status = " << static_cast<int>(error) << endl;
}
}

Expand All @@ -87,9 +91,36 @@ void ManageSDKTest::SetDeviceName()
Firebolt::IFireboltAccessor::Instance().DeviceInterface().SetName("Hello", &error);

if (error == Firebolt::Error::None) {
cout << "Set DeviceName is success" << endl;
cout << "Set Device Name is success" << endl;
} else {
cout << "Set DeviceName status = " << static_cast<int>(error) << endl;
cout << "Set Device Name status = " << static_cast<int>(error) << endl;
}
}

void ManageSDKTest::OnDeviceNameChangedNotification::OnDeviceNameChanged( const std::string& name)
{
cout << "Name changed, new name --> " << name << endl;
}

void ManageSDKTest::SubscribeDeviceNameChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().DeviceInterface().Subscribe(_deviceNameChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe Device NameChange is success" << endl;
} else {
cout << "Subscribe Device NameChange status = " << static_cast<int>(error) << endl;
}
}

void ManageSDKTest::UnsubscribeDeviceNameChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().DeviceInterface().Unsubscribe(_deviceNameChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe Device NameChange is success" << endl;
} else {
cout << "Unsubscribe Device NameChange status = " << static_cast<int>(error) << endl;
}
}

Expand Down Expand Up @@ -117,13 +148,54 @@ void ManageSDKTest::SetClosedCaptionBackgroundOpacity()
}
}

void ManageSDKTest::OnBackgroundOpacityChangedNotification::OnBackgroundOpacityChanged( const float opacity )
{
cout << "BackgroundOpacity changed, new value --> " << opacity << endl;
}

void ManageSDKTest::SubscribeClosedCaptionsBackgroundOpacityChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().Subscribe(_backgroundOpacityChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe ClosedCaptions BackgroundOpacityChange is success" << endl;
} else {
cout << "Subscribe ClosedCaptions BackgroundOpacityChange status = " << static_cast<int>(error) << endl;
}
}

void ManageSDKTest::UnsubscribeClosedCaptionsBackgroundOpacityChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().Unsubscribe(_backgroundOpacityChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe ClosedCaptions BackgroundOpacityChange is success" << endl;
} else {
cout << "Unsubscribe ClosedCaptions BackgroundOpacityChange status = " << static_cast<int>(error) << endl;
}
}

using FontFamilyMap = std::unordered_map<Firebolt::Accessibility::FontFamily, string>;
FontFamilyMap fontFamilyMap = {
{ Firebolt::Accessibility::FontFamily::MONOSPACED_SERIF, "MonospacedSerif" },
{ Firebolt::Accessibility::FontFamily::PROPORTIONAL_SERIF, "ProportionalSerif" },
{ Firebolt::Accessibility::FontFamily::MONOSPACED_SANSERIF, "MonospacedSanserif" },
{ Firebolt::Accessibility::FontFamily::PROPORTIONAL_SANSERIF, "ProportionalSanserif" },
{ Firebolt::Accessibility::FontFamily::SMALLCAPS, "SmallCaps" },
{ Firebolt::Accessibility::FontFamily::CURSIVE, "Cursive" },
{ Firebolt::Accessibility::FontFamily::CASUAL, "Casual" }};
inline const string& ConvertToFontFamilyStr(Firebolt::Accessibility::FontFamily family)
{
return fontFamilyMap[family];
}

void ManageSDKTest::GetClosedCaptionFontFamily()
{
Firebolt::Error error = Firebolt::Error::None;
const Firebolt::Accessibility::FontFamily value = Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().FontFamily(&error);

if (error == Firebolt::Error::None) {
cout << "Get ClosedCaption FontFamily = " << static_cast<int>(value) << endl;
cout << "Get ClosedCaption FontFamily value = " << ConvertToFontFamilyStr(value) << endl;
} else {
cout << "Get ClosedCaption FontFamily status = " << static_cast<int>(error) << endl;
}
Expand All @@ -141,6 +213,33 @@ void ManageSDKTest::SetClosedCaptionFontFamily()
}
}

void ManageSDKTest::OnFontFamilyChangedNotification::OnFontFamilyChanged( const Firebolt::Accessibility::FontFamily& family )
{
cout << "FontFamily changed, new code --> " << ConvertToFontFamilyStr(family) << endl;
}

void ManageSDKTest::SubscribeClosedCaptionsFontFamilyChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().Subscribe(_fontFamilyChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe ClosedCaptions FontFamilyChange is success" << endl;
} else {
cout << "Subscribe ClosedCaptions FontFamilyChange status = " << static_cast<int>(error) << endl;
}
}

void ManageSDKTest::UnsubscribeClosedCaptionsFontFamilyChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().ClosedCaptionsInterface().Unsubscribe(_fontFamilyChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe ClosedCaptions FontFamilyChange is success" << endl;
} else {
cout << "Unsubscribe ClosedCaptions FontFamilyChange status = " << static_cast<int>(error) << endl;
}
}

void ManageSDKTest::GetLocalizationPreferredAudioLanguages()
{
Firebolt::Error error = Firebolt::Error::None;
Expand All @@ -149,8 +248,8 @@ void ManageSDKTest::GetLocalizationPreferredAudioLanguages()
if (error == Firebolt::Error::None) {
cout << "Get Localization PreferredAudioLanguages : " << endl;
for (auto language: languages) {
cout << "----- > " <<language << endl;
}
cout << "----- > " <<language << endl;
}
} else {
cout << "Get Localization PreferredAudioLanguages status = " << static_cast<int>(error) << endl;
}
Expand All @@ -169,3 +268,74 @@ void ManageSDKTest::SetLocalizationPreferredAudioLanguages()
}
}

void ManageSDKTest::OnPreferredAudioLanguagesChangedNotification::OnPreferredAudioLanguagesChanged( const std::vector<std::string>& languages)
{
cout << "PreferredAudioLanguages Changed, new languages --> " << endl;
for (auto language : languages) {
cout << " -> " << language << endl;
}
}

void ManageSDKTest::SubscribeLocalizationPreferredAudioLanguagesChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().LocalizationInterface().Subscribe(_preferredAudioLanguagesChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe Localization PreferredAudioLanguagesChange is success" << endl;
} else {
cout << "Subscribe Localization PreferredAudioLanguagesChange status = " << static_cast<int>(error) << endl;
}
}

void ManageSDKTest::UnsubscribeLocalizationPreferredAudioLanguagesChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().LocalizationInterface().Unsubscribe(_preferredAudioLanguagesChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe Localization PreferredAudioLanguagesChange is success" << endl;
} else {
cout << "Unsubscribe Localization PreferredAudioLanguagesChange status = " << static_cast<int>(error) << endl;
}
}

using PinSpaceMap = std::unordered_map<Firebolt::PinChallenge::PinChallengePinSpace, string>;
PinSpaceMap pinSpaceMap = {
{ Firebolt::PinChallenge::PinChallengePinSpace::PURCHASE, "Purchase" },
{ Firebolt::PinChallenge::PinChallengePinSpace::CONTENT, "Content" }};
inline const string& ConvertToPinSpaceStr(Firebolt::PinChallenge::PinChallengePinSpace pinSpace)
{
return pinSpaceMap[pinSpace];
}


void ManageSDKTest::OnRequestChallengeNotification::OnRequestChallenge( const Firebolt::PinChallenge::PinChallengeProviderRequest& pinChallenge )
{
cout << "RequestChallenge, new challenge --> " << endl;
cout << "CorrelationId : " << pinChallenge.correlationId << endl;
cout << "PinChallenge.ChallengeRequestor.Id : " << pinChallenge.parameters.requestor.id << endl;
cout << "PinChallenge.ChallengeRequestor.Name : " << pinChallenge.parameters.requestor.name << endl;
cout << "PinChallenge.PinChallengePinSpace : " << ConvertToPinSpaceStr(pinChallenge.parameters.pinSpace) << endl;
cout << "PinChallenge.Capability : " << *(pinChallenge.parameters.capability) << endl;
}

void ManageSDKTest::SubscribePinChallengeRequestChallenge()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().PinChallengeInterface().Subscribe(_requestChallengeNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe PinChallenge RequestChallenge is success" << endl;
} else {
cout << "Subscribe PinChallenge RequestChallenge status = " << static_cast<int>(error) << endl;
}
}

void ManageSDKTest::UnsubscribePinChallengeRequestChallenge()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().PinChallengeInterface().Unsubscribe(_requestChallengeNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe PinChallenge RequestChallenge is success" << endl;
} else {
cout << "Unsubscribe PinChallenge RequestChallenge status = " << static_cast<int>(error) << endl;
}
}
Loading

0 comments on commit ae1cd80

Please sign in to comment.