Skip to content

Commit

Permalink
Manage Test update based on provider integration
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Nov 28, 2023
1 parent ffd7d0d commit a4b1b53
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 44 deletions.
83 changes: 64 additions & 19 deletions src/sdks/manage/src/cpp/sdk/cpptest/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#include <getopt.h>
#include "ManageSDKTest.h"

void ShowMenu()
Expand All @@ -16,15 +16,21 @@ void ShowMenu()
"\tL : Get Localization Preferred AudioLanguages\n"
"\tA : Set Localization Preferred AudioLanguages\n"
"\tR : Subscribe/Unsubscribe for Localization Preferred AudioLanguages Change\n"
#ifdef RPC_ONLY
"\tP : Subscribe/Unsubscribe for PinChallenge RequestChallenge\n"
#endif
"\tD : Register for Keyboard Provider\n"
"\tE : Send Keyboard Result to Provider\n"
"\tD : Register for Keyboard Provider and check sequence\n"
"\tK : Register for Acknowledge Challenge Provider and check sequence\n"
"\tP : Register for Pin Challenge Provider and check sequence\n"
"\tQ : Quit\n\n"
);
}

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"
"\tQ : Quit\n", module.c_str());
}

void ShowEventMenu()
{
printf("Enter\n"
Expand Down Expand Up @@ -56,21 +62,52 @@ void ShowEventMenu()
} while (opt != 'Q'); \
}

#define VALUE(string) #string
#define TO_STRING(string) VALUE(string)
#define HandleProviderSequence(Module) \
{ \
int opt; \
do { \
getchar(); \
std::string module = TO_STRING(Module); \
ShowProviderMenu(module); \
printf("Enter option : "); \
opt = toupper(getchar()); \
switch (opt) { \
case 'R': { \
ManageSDKTest::SendResponseMessageTo##Module##Provider(); \
break; \
} \
case 'E': { \
ManageSDKTest::SendErrorMessageTo##Module##Provider(); \
break; \
} \
default: \
break; \
} \
} while (opt != 'Q'); \
}

#define options ":hu:"
int main (int argc, char* argv[])
{
char* config = "{\
\"waitTime\": 1000,\
\"logLevel\": \"Info\",\
\"workerPool\":{\
\"queueSize\": 8,\
\"threadCount\": 3\
},\
\"wsUrl\": \"ws://127.0.0.1:9998\"\
}";
int c;
std::string url = "ws://127.0.0.1:9998";
while ((c = getopt (argc, argv, options)) != -1) {
switch (c)
{
case 'u':
url = optarg;
break;

case 'h':
printf("./TestFireboltManage -u ws://ip:port\n");
exit(1);
}
}

printf("Firebolt Manage SDK Test\n");

ManageSDKTest::CreateFireboltInstance();
ManageSDKTest::CreateFireboltInstance(url);
int option;

if (ManageSDKTest::WaitOnConnectionReady() == true) {
Expand Down Expand Up @@ -135,10 +172,18 @@ int main (int argc, char* argv[])
#endif
case 'D': {
ManageSDKTest::RegisterKeyboardProvider();
HandleProviderSequence(Keyboard)
break;
}
case 'E': {
ManageSDKTest::SendMessageToKeyboardProvider();
case 'K': {
ManageSDKTest::RegisterAcknowledgeChallengeProvider();
HandleProviderSequence(AcknowledgeChallenge)
break;
}
case 'P': {
ManageSDKTest::RegisterPinChallengeProvider();
HandleProviderSequence(PinChallenge)
break;
}
default:
break;
Expand Down
185 changes: 163 additions & 22 deletions src/sdks/manage/src/cpp/sdk/cpptest/ManageSDKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ ManageSDKTest::OnPreferredAudioLanguagesChangedNotification ManageSDKTest::_pref
ManageSDKTest::OnRequestChallengeNotification ManageSDKTest::_requestChallengeNotification;
#endif
ManageSDKTest::KeyboardProvider ManageSDKTest::_keyboardProvider;
ManageSDKTest::AcknowledgeChallengeProvider ManageSDKTest::_acknowledgeChallengeProvider;
ManageSDKTest::PinChallengeProvider ManageSDKTest::_pinChallengeProvider;

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

void ManageSDKTest::CreateFireboltInstance()
void ManageSDKTest::CreateFireboltInstance(const std::string& url)
{
const std::string config = "{\
\"waitTime\": 1000,\
Expand All @@ -45,8 +47,7 @@ void ManageSDKTest::CreateFireboltInstance()
\"queueSize\": 8,\
\"threadCount\": 3\
},\
\"wsUrl\": \"ws://127.0.0.1:9998\"\
}";
\"wsUrl\": " + url + "}";

_connected = false;
Firebolt::IFireboltAccessor::Instance().Initialize(config);
Expand Down Expand Up @@ -351,7 +352,7 @@ ManageSDKTest::KeyboardProvider::KeyboardProvider()
{
}

void ManageSDKTest::KeyboardProvider::keyboardLoop()
void ManageSDKTest::KeyboardProvider::SendMessage(bool response)
{
if (_keyInput) {
cout << " Invoking _session->focus " << endl;
Expand All @@ -361,22 +362,20 @@ void ManageSDKTest::KeyboardProvider::keyboardLoop()
string key;
cout << _parameters.message << " : ";
getline(cin, key);
cout<< " key --> " << key;
Firebolt::Keyboard::KeyboardResult keyboardResult;
keyboardResult.text = key;
keyboardResult.canceled = false;
cout << " Invoking _session->result " << endl;
_session->result(keyboardResult);

key = "";
cout<< "\n Enter error message too for testing --> " << key;
getline(cin, key);
Firebolt::Keyboard::KeyboardError keyboardError;
keyboardError.code = 123;
keyboardError.message = key;
cout << " Invoking _session->error " << endl;
_session->error(keyboardError);

if (response) {
Firebolt::Keyboard::KeyboardResult keyboardResult;
keyboardResult.text = key;
keyboardResult.canceled = false;
cout << " Invoking _session->result " << endl;
_session->result(keyboardResult);
} else {
Firebolt::Keyboard::KeyboardError keyboardError;
keyboardError.code = 123;
keyboardError.message = key;
keyboardError.data = "nothing to send";
cout << " Invoking _session->error " << endl;
_session->error(keyboardError);
}
_keyInput = false;
cin.putback('\n');
} else {
Expand Down Expand Up @@ -414,7 +413,149 @@ void ManageSDKTest::RegisterKeyboardProvider()
Firebolt::IFireboltAccessor::Instance().KeyboardInterface().provide(_keyboardProvider);
}

void ManageSDKTest::SendMessageToKeyboardProvider()
void ManageSDKTest::SendResponseMessageToKeyboardProvider()
{
_keyboardProvider.SendMessage(true);
}

void ManageSDKTest::SendErrorMessageToKeyboardProvider()
{
_keyboardProvider.SendMessage(false);
}

ManageSDKTest::AcknowledgeChallengeProvider::AcknowledgeChallengeProvider()
: _session(nullptr)
, _parameters()
, _challengeInput(false)
{
}

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;
if (response) {
Firebolt::AcknowledgeChallenge::GrantResult challengeResult;
challengeResult.granted = true;
cout << " Invoking _session->result " << endl;
_session->result(challengeResult);
} else {
string key;
getline(cin, key);

Firebolt::AcknowledgeChallenge::AcknowledgeChallengeError challengeError;
challengeError.code = 234;
challengeError.message = key;
cout << " Invoking _session->error " << endl;
_session->error(challengeError);
cin.putback('\n');
}
_challengeInput = false;
} else {
cout << " there is no active acknowledge challenge input session " << endl;
}
}

void ManageSDKTest::AcknowledgeChallengeProvider::challenge(const Firebolt::AcknowledgeChallenge::Challenge& parameters, std::unique_ptr<Firebolt::AcknowledgeChallenge::IAcknowledgeChallengeSession> session)
{
cout << "KeyboardProvider Standard is invoked" << endl;
startAcknowledgeChallengeSession(parameters, std::move(session));
}

void ManageSDKTest::AcknowledgeChallengeProvider::startAcknowledgeChallengeSession( const Firebolt::AcknowledgeChallenge::Challenge& parameters, std::unique_ptr<Firebolt::AcknowledgeChallenge::IAcknowledgeChallengeSession> session )
{
_session = std::move(session);
_parameters = parameters;
_challengeInput = true;
}

void ManageSDKTest::RegisterAcknowledgeChallengeProvider()
{
Firebolt::IFireboltAccessor::Instance().AcknowledgeChallengeInterface().provide(_acknowledgeChallengeProvider);
}

void ManageSDKTest::SendResponseMessageToAcknowledgeChallengeProvider()
{
_acknowledgeChallengeProvider.SendMessage(true);
}

void ManageSDKTest::SendErrorMessageToAcknowledgeChallengeProvider()
{
_acknowledgeChallengeProvider.SendMessage(false);
}

ManageSDKTest::PinChallengeProvider::PinChallengeProvider()
: _session(nullptr)
, _parameters()
, _challengeInput(false)
{
}

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;
}
cout << " id : " << _parameters.requestor.id << endl;
cout << " name : " << _parameters.requestor.name << endl;

if (response) {
Firebolt::PinChallenge::PinChallengeResult challengeResult;
challengeResult.granted = true;
challengeResult.reason = Firebolt::PinChallenge::ResultReason::CORRECT_PIN;
cout << " Invoking _session->result " << endl;
_session->result(challengeResult);
} else {
string key;
getline(cin, key);

Firebolt::PinChallenge::PinChallengeError challengeError;
challengeError.code = 234;
challengeError.message = key;
cout << " Invoking _session->error " << endl;
_session->error(challengeError);
cin.putback('\n');
}
_challengeInput = false;
} else {
cout << " there is no active pin challenge input session " << endl;
}
}

void ManageSDKTest::PinChallengeProvider::challenge(const Firebolt::PinChallenge::PinChallenge& parameters, std::unique_ptr<Firebolt::PinChallenge::IPinChallengeSession> session)
{
cout << "KeyboardProvider Standard is invoked" << endl;
startPinChallengeSession(parameters, std::move(session));
}

void ManageSDKTest::PinChallengeProvider::startPinChallengeSession( const Firebolt::PinChallenge::PinChallenge& parameters, std::unique_ptr<Firebolt::PinChallenge::IPinChallengeSession> session )
{
_session = std::move(session);
_parameters = parameters;
_challengeInput = true;
}

void ManageSDKTest::RegisterPinChallengeProvider()
{
Firebolt::IFireboltAccessor::Instance().PinChallengeInterface().provide(_pinChallengeProvider);
}

void ManageSDKTest::SendResponseMessageToPinChallengeProvider()
{
_pinChallengeProvider.SendMessage(true);
}

void ManageSDKTest::SendErrorMessageToPinChallengeProvider()
{
_keyboardProvider.keyboardLoop();
_pinChallengeProvider.SendMessage(false);
}
Loading

0 comments on commit a4b1b53

Please sign in to comment.