Skip to content

Commit

Permalink
feat: Add native discovery test app (#324)
Browse files Browse the repository at this point in the history
Co-authored-by: kschrief <kschriefer91@gmail.com>
  • Loading branch information
ksentak and kschrief authored Sep 25, 2024
1 parent e9acde0 commit 93bc083
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
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

0 comments on commit 93bc083

Please sign in to comment.