From cf364a827c740937b6c26da5040fa8748e45affc Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Mon, 23 Sep 2024 12:46:42 -0400 Subject: [PATCH] feat: Add native discovery test app --- .../src/cpp/sdk/cpptest/DiscoverySDKTest.cpp | 40 +++++++++++++++++-- .../src/cpp/sdk/cpptest/DiscoverySDKTest.h | 10 ++++- .../discovery/src/cpp/sdk/cpptest/Main.cpp | 5 ++- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp index 27fe67244..62d3f0282 100644 --- a/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.cpp @@ -23,6 +23,7 @@ using namespace std; bool DiscoverySDKTest::_connected; +DiscoverySDKTest::OnUserInterestNotification DiscoverySDKTest::_userInterestNotification; void DiscoverySDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error) { @@ -89,14 +90,47 @@ inline const T ConvertToEnum(EnumMap 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(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(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(error)); - throw std::runtime_error("SampleTest failed. " + errorMessage); + throw std::runtime_error("Content.requestUserInterest failed." + errorMessage); } } diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h index 2fcd2bcc0..cdb70ca65 100644 --- a/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/DiscoverySDKTest.h @@ -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; @@ -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; + }; \ No newline at end of file diff --git a/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp index 26e2b5dc6..aee23e31f 100644 --- a/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp +++ b/src/sdks/discovery/src/cpp/sdk/cpptest/Main.cpp @@ -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;