Skip to content

Commit

Permalink
fix: Manage sdk unit tests (non-events) (#341)
Browse files Browse the repository at this point in the history
* test(manage): Advertising unit tests

* test(manage): AudioDescription unit tests

* test(manage): ClosedCaptions unit tests

* test(manage): Device unit tests

* test(manage): HDMI-Input unit tests

* test(manage): Localization unit tests

* test(manage): Privacy unit tests

* test(manage): Voice guidance unit tests

* test(manage): Account unit tests

* test(manage): Secure Storage unit tests

* test(manage): User Grant unit tests

* test(manage): Wifi unit tests

* test(manage): Metrics unit tests

* test(manage): AcknowledgeChallenge unit tests

* test(manage): Keyboard unit tests

* test(manage): PinChallenge unit tests

---------

Co-authored-by: Keaton Sentak <[email protected]>
  • Loading branch information
AdityaKasar and ksentak authored Nov 18, 2024
1 parent 9ad3187 commit 85a0378
Show file tree
Hide file tree
Showing 18 changed files with 1,853 additions and 116 deletions.
26 changes: 26 additions & 0 deletions src/sdks/manage/src/cpp/sdk/cpptest/unit/accountTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "unit.h"

class AccountTest : public ::testing::Test
{
protected:
JsonEngine *jsonEngine;
Firebolt::Error error = Firebolt::Error::None;

void SetUp() override
{
jsonEngine = new JsonEngine();
}

void TearDown() override
{
delete jsonEngine;
}
};

TEST_F(AccountTest, session)
{
std::string token = "expiresIn";
int32_t expiresIn = 84000;
Firebolt::IFireboltAccessor::Instance().AccountInterface().session(token, expiresIn, &error);
EXPECT_EQ(error, Firebolt::Error::None) << "Error on calling AccountInterface.session() method";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "unit.h"

using namespace Firebolt::AcknowledgeChallenge;

struct AcknowledgeChallengeProvider : public IAcknowledgeChallengeProvider
{
AcknowledgeChallengeProvider();
~AcknowledgeChallengeProvider() override = default;
void SendMessage(bool response);
void challenge(const Challenge &parameters, std::unique_ptr<IAcknowledgeChallengeSession> session) override;

private:
void startAcknowledgeChallengeSession(const Challenge &parameters, std::unique_ptr<IAcknowledgeChallengeSession> session);

private:
std::unique_ptr<IAcknowledgeChallengeSession> _session;
Challenge _parameters;
bool _challengeInput;
};

class AcknowledgeChallengeTest : public ::testing::Test
{
protected:
JsonEngine *jsonEngine;
Firebolt::Error error = Firebolt::Error::None;
AcknowledgeChallengeProvider _acknowledgeChallengeProvider;

void SetUp() override
{
jsonEngine = new JsonEngine();
}

void TearDown() override
{
delete jsonEngine;
}
};

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

void AcknowledgeChallengeProvider::SendMessage(bool response)
{
}

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

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

TEST_F(AcknowledgeChallengeTest, registerAcknowledgeChallengeProvider)
{
Firebolt::IFireboltAccessor::Instance().AcknowledgeChallengeInterface().provide(_acknowledgeChallengeProvider);
}
57 changes: 54 additions & 3 deletions src/sdks/manage/src/cpp/sdk/cpptest/unit/advertisingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,73 @@
class AdvertisingTest : public ::testing::Test
{
protected:
JsonEngine *jsonEngine;
Firebolt::Error error = Firebolt::Error::None;

void SetUp() override
{
jsonEngine = new JsonEngine();
}

void TearDown() override
{
delete jsonEngine;
}
};

TEST_F(AdvertisingTest, resetIdentifier)
{
Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().resetIdentifier(&error);
EXPECT_EQ(error, Firebolt::Error::None) << "Error on calling AdvertisingInterface.resetIdentifier() method";
}

TEST_F(AdvertisingTest, skipRestriction)
{
std::string expectedValues = jsonEngine->get_value("Advertising.skipRestriction");
Firebolt::Advertising::SkipRestriction restriction = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().skipRestriction(&error);

std::string actual_skip_restriction;
switch (restriction)
{
case Firebolt::Advertising::SkipRestriction::NONE:
actual_skip_restriction = "none";
break;
case Firebolt::Advertising::SkipRestriction::ADS_UNWATCHED:
actual_skip_restriction = "ads_unwatched";
break;
case Firebolt::Advertising::SkipRestriction::ADS_ALL:
actual_skip_restriction = "ads_all";
break;
case Firebolt::Advertising::SkipRestriction::ALL:
actual_skip_restriction = "all";
break;
default:
actual_skip_restriction = "unknown";
}

EXPECT_EQ(error, Firebolt::Error::None) << "Error on calling AdvertisingInterface.skipRestriction() method";
EXPECT_EQ(REMOVE_QUOTES(expectedValues), actual_skip_restriction) << "Error: wrong skipRestriction returned by AdvertisingInterface.skipRestriction()";
}

TEST_F(AdvertisingTest, setSkipRestriction)
{
Firebolt::Advertising::SkipRestriction expected_value = Firebolt::Advertising::SkipRestriction::ADS_ALL; // Replace with the appropriate enum value
Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().setSkipRestriction(expected_value, &error);
EXPECT_EQ(error, Firebolt::Error::None) << "Error on calling AdvertisingInterface.setSkipRestriction() method";
}

// Events Tests
struct SkipRestrictionChanged : public Firebolt::Advertising::IAdvertising::IOnSkipRestrictionChangedNotification
{
void onSkipRestrictionChanged( const Firebolt::Advertising::SkipRestriction& ) override;
void onSkipRestrictionChanged(const Firebolt::Advertising::SkipRestriction &) override;
};

Firebolt::Advertising::SkipRestriction newSkipRestriction;
void SkipRestrictionChanged::onSkipRestrictionChanged(const Firebolt::Advertising::SkipRestriction& skipRestriction)
void SkipRestrictionChanged::onSkipRestrictionChanged(const Firebolt::Advertising::SkipRestriction &skipRestriction)
{
std::cout << "onSkipRestrictionChanged event fired";
}


TEST_F(AdvertisingTest, subscribeOnSkipRestrictionChanged)
{
SkipRestrictionChanged skipRestrictionChanged;
Expand Down
30 changes: 27 additions & 3 deletions src/sdks/manage/src/cpp/sdk/cpptest/unit/audioDescriptionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,46 @@
class AudioDescriptionsTest : public ::testing::Test
{
protected:
JsonEngine *jsonEngine;
Firebolt::Error error = Firebolt::Error::None;

void SetUp() override
{
jsonEngine = new JsonEngine();
}

void TearDown() override
{
delete jsonEngine;
}
};

TEST_F(AudioDescriptionsTest, enabled)
{
auto expectedValues = jsonEngine->get_value("AudioDescriptions.enabled");
bool enable = Firebolt::IFireboltAccessor::Instance().AudioDescriptionsInterface().enabled(&error);

EXPECT_EQ(error, Firebolt::Error::None) << "Error on calling AudioDescriptions.enabled() method";
EXPECT_EQ(expectedValues == "true", enable) << "Error: AudioDescriptions.enabled() dose not returns enabled";
}

TEST_F(AudioDescriptionsTest, setEnabled)
{
Firebolt::IFireboltAccessor::Instance().AudioDescriptionsInterface().setEnabled(true, &error);

EXPECT_EQ(error, Firebolt::Error::None) << "Error on calling AudioDescriptions.setEnabled() method";
}

struct EnabledChanged : public Firebolt::AudioDescriptions::IAudioDescriptions::IOnEnabledChangedNotification
{
void onEnabledChanged( const bool ) override;
void onEnabledChanged(const bool) override;
};


void EnabledChanged::onEnabledChanged(const bool)
{
std::cout << "onAudioDescriptionEnabledChanged event fired";
}


TEST_F(AudioDescriptionsTest, subscribeonEnabledChanged)
{
EnabledChanged enabledChanged;
Expand Down
Loading

0 comments on commit 85a0378

Please sign in to comment.