Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add native discovery test app #324

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using namespace std;
bool DiscoverySDKTest::_connected;
DiscoverySDKTest::OnUserInterestNotification DiscoverySDKTest::_userInterestNotification;

void DiscoverySDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error)
{
Expand Down Expand Up @@ -89,14 +90,47 @@ inline const T ConvertToEnum(EnumMap<T> enumMap, const string& str)
return value;
}

void DiscoverySDKTest::SampleTest()
void DiscoverySDKTest::OnUserInterestNotification::onUserInterest( const Firebolt::Content::InterestEvent& interest)
{
cout << "User Interest changed notification" << endl;
}

void DiscoverySDKTest::SubscribeUserInterest()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().ContentInterface().subscribe(_userInterestNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe Content.UserInterest is a success." << endl;
} else {
std::string errorMessage = "Error: " + std::to_string(static_cast<int>(error));
throw std::runtime_error("Subscribe Content.UserInterest failed. " + errorMessage);
}
}

void DiscoverySDKTest::UnsubscribeUserInterest()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().ContentInterface().unsubscribe(_userInterestNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe Content.UserInterest is a success." << endl;
} else {
std::string errorMessage = "Error: " + std::to_string(static_cast<int>(error));
throw std::runtime_error("Unsubscribe Content.UserInterest failed." + errorMessage);
}
}

void DiscoverySDKTest::RequestUserInterest()
{
Firebolt::Discovery::InterestType type = Firebolt::Discovery::InterestType::INTEREST;
Firebolt::Discovery::InterestReason reason = Firebolt::Discovery::InterestReason::REACTION;
Firebolt::Error error = Firebolt::Error::None;

Firebolt::IFireboltAccessor::Instance().ContentInterface().requestUserInterest(type, reason, &error);

if (error == Firebolt::Error::None) {
cout << "Sample Test Passed!" << endl;
cout << "Content.requestuserInterest call is a success." << endl;
} else {
std::string errorMessage = "Error: " + std::to_string(static_cast<int>(error));
throw std::runtime_error("SampleTest failed. " + errorMessage);
throw std::runtime_error("Content.requestUserInterest failed." + errorMessage);
}
}
10 changes: 9 additions & 1 deletion src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "firebolt.h"

class DiscoverySDKTest {
class OnUserInterestNotification : public Firebolt::Content::IContent::IOnUserInterestNotification {
public:
void onUserInterest( const Firebolt::Content::InterestEvent& ) override;
};

public:
DiscoverySDKTest() = default;
Expand All @@ -31,11 +35,15 @@ class DiscoverySDKTest {
static void DestroyFireboltInstance();
static void TestDiscoveryStaticSDK();

static void SampleTest();
static void SubscribeUserInterest();
static void UnsubscribeUserInterest();
static void RequestUserInterest();

static bool WaitOnConnectionReady();

private:
static void ConnectionChanged(const bool, const Firebolt::Error);
static bool _connected;
static OnUserInterestNotification _userInterestNotification;

};
5 changes: 3 additions & 2 deletions src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ void RunAllTests() {

// Ensure the connection is ready before running tests
if (DiscoverySDKTest::WaitOnConnectionReady()) {
// Add tests here

runTest(DiscoverySDKTest::SampleTest, "SampleTest");
runTest(DiscoverySDKTest::SubscribeUserInterest, "SubscribeUserInterest");
runTest(DiscoverySDKTest::UnsubscribeUserInterest, "UnsubscribeUserInterest");
runTest(DiscoverySDKTest::RequestUserInterest, "RequestUserInterest");

if (allTestsPassed) {
cout << "============================" << endl;
Expand Down
Loading