diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt b/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt index c542cf6cc..4b1b6a8f6 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt +++ b/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt @@ -39,8 +39,6 @@ endif () find_package(WPEFramework CONFIG REQUIRED) find_package(${NAMESPACE}Core CONFIG REQUIRED) -find_package(Firebolt CONFIG REQUIRED) -find_package(${FIREBOLT_NAMESPACE}SDK CONFIG REQUIRED) set(TESTAPP TestFireboltCore) @@ -52,13 +50,13 @@ target_link_libraries(${TESTAPP} PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core ${FIREBOLT_NAMESPACE}SDK::${FIREBOLT_NAMESPACE}SDK + nlohmann_json_schema_validator + gtest_main ) target_include_directories(${TESTAPP} PRIVATE - $ - $ - $ + $ ) if (POLYMORPHICS_REDUCER_METHODS) @@ -79,3 +77,34 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/bin COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${TESTAPP} ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/bin ) + +if(ENABLE_UNIT_TESTS) + set(UNIT_TESTS_APP FireboltCoreUnitTests) + + message("Setup ${UNIT_TESTS_APP}") + + file(GLOB UNIT_TESTS "unit/*") + + add_executable(${UNIT_TESTS_APP} + CoreSDKTest.cpp + Unit.cpp + ${UNIT_TESTS} + ) + + link_directories(${CMAKE_SOURCE_DIR}/../../Thunder/install/usr/lib/) + target_link_libraries(${UNIT_TESTS_APP} + PRIVATE + ${NAMESPACE}Core::${NAMESPACE}Core + ${FIREBOLT_NAMESPACE}SDK::${FIREBOLT_NAMESPACE}SDK + nlohmann_json_schema_validator + gtest_main + ) + + target_include_directories(${UNIT_TESTS_APP} + PRIVATE + $ + ) + + include(GoogleTest) + gtest_discover_tests(${UNIT_TESTS_APP}) +endif() diff --git a/src/sdks/core/src/cpp/sdk/cpptest/Unit.cpp b/src/sdks/core/src/cpp/sdk/cpptest/Unit.cpp new file mode 100644 index 000000000..acf72128c --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/Unit.cpp @@ -0,0 +1,10 @@ +#include "gtest/gtest.h" +#include "CoreSDKTest.h" + +int main(int argc, char **argv) +{ + std::string url = "ws://localhost:9998"; + CoreSDKTest::CreateFireboltInstance(url); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp new file mode 100644 index 000000000..09a6efc58 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp @@ -0,0 +1,314 @@ +#include "unit.h" + +class AccessibilityTest : public ::testing::Test +{ +protected: + JsonEngine *jsonEngine; + Firebolt::Error error = Firebolt::Error::None; + + void SetUp() override + { + jsonEngine = new JsonEngine(); + } + + void TearDown() override + { + delete jsonEngine; + } + + std::string fontFamilyToString(Firebolt::Accessibility::FontFamily fontFamily) + { + std::string str = ""; + switch (fontFamily) + { + case Firebolt::Accessibility::FontFamily::MONOSPACED_SERIF: + str = "monospaced_serif"; + break; + case Firebolt::Accessibility::FontFamily::PROPORTIONAL_SERIF: + str = "proportional_serif"; + break; + case Firebolt::Accessibility::FontFamily::MONOSPACED_SANSERIF: + str = "monospaced_sanserif"; + break; + case Firebolt::Accessibility::FontFamily::PROPORTIONAL_SANSERIF: + str = "proportional_sanserif"; + break; + case Firebolt::Accessibility::FontFamily::SMALLCAPS: + str = "smallcaps"; + break; + case Firebolt::Accessibility::FontFamily::CURSIVE: + str = "cursive"; + break; + case Firebolt::Accessibility::FontFamily::CASUAL: + str = "casual"; + break; + default: + str = "unknown"; + } + return str; + } + + std::string fontEdgeToString(Firebolt::Accessibility::FontEdge fontEdge) + { + std::string str = ""; + switch (fontEdge) + { + case Firebolt::Accessibility::FontEdge::NONE: + str = "none"; + break; + case Firebolt::Accessibility::FontEdge::RAISED: + str = "raised"; + break; + case Firebolt::Accessibility::FontEdge::DEPRESSED: + str = "depressed"; + break; + case Firebolt::Accessibility::FontEdge::UNIFORM: + str = "uniform"; + break; + case Firebolt::Accessibility::FontEdge::DROP_SHADOW_LEFT: + str = "drop_shadow_left"; + break; + case Firebolt::Accessibility::FontEdge::DROP_SHADOW_RIGHT: + str = "drop_shadow_right"; + break; + default: + str = "unknown"; + } + return str; + } +}; + +TEST_F(AccessibilityTest, ClosedCaptions) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Accessibility.closedCaptions")); + + Firebolt::Accessibility::ClosedCaptionsSettings closedCaptions = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().closedCaptions(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve closedCaptions from Accessibility.closedCaptions() method"; + EXPECT_EQ(closedCaptions.enabled, expectedValues["enabled"]); + + if (closedCaptions.styles.has_value()) { + const auto& styles = closedCaptions.styles.value(); + + if (styles.backgroundColor.has_value()) + EXPECT_EQ(styles.backgroundColor.value(), expectedValues["styles"]["backgroundColor"]); + + if (styles.backgroundOpacity.has_value()) + EXPECT_EQ(styles.backgroundOpacity.value(), expectedValues["styles"]["backgroundOpacity"]); + + if (styles.fontColor.has_value()) + EXPECT_EQ(styles.fontColor.value(), expectedValues["styles"]["fontColor"]); + + if (styles.fontEdge.has_value()) + EXPECT_EQ(fontEdgeToString(styles.fontEdge.value()), expectedValues["styles"]["fontEdge"]); + + if (styles.fontEdgeColor.has_value()) + EXPECT_EQ(styles.fontEdgeColor.value(), expectedValues["styles"]["fontEdgeColor"]); + + if (styles.fontFamily.has_value()) + EXPECT_EQ(fontFamilyToString(styles.fontFamily.value()), expectedValues["styles"]["fontFamily"]); + + if (styles.fontOpacity.has_value()) + EXPECT_EQ(styles.fontOpacity.value(), expectedValues["styles"]["fontOpacity"]); + + if (styles.fontSize.has_value()) + EXPECT_EQ(styles.fontSize.value(), expectedValues["styles"]["fontSize"]); + + if (styles.textAlign.has_value()) + EXPECT_EQ(styles.textAlign.value(), expectedValues["styles"]["textAlign"]); + + if (styles.textAlignVertical.has_value()) + EXPECT_EQ(styles.textAlignVertical.value(), expectedValues["styles"]["textAlignVertical"]); + + if (styles.windowColor.has_value()) + EXPECT_EQ(styles.windowColor.value(), expectedValues["styles"]["windowColor"]); + + if (styles.windowOpacity.has_value()) + EXPECT_EQ(styles.windowOpacity.value(), expectedValues["styles"]["windowOpacity"]); + } + + EXPECT_EQ(closedCaptions.preferredLanguages.value()[0], expectedValues["preferredLanguages"][0]); + EXPECT_EQ(closedCaptions.preferredLanguages.value()[1], expectedValues["preferredLanguages"][1]); +} + +TEST_F(AccessibilityTest, ClosedCaptionsSettings) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Accessibility.closedCaptionsSettings")); + + Firebolt::Accessibility::ClosedCaptionsSettings closedCaptionSettings = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().closedCaptionsSettings(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve closedCaptionSettings from Accessibility.closedCaptionSettings() method"; + EXPECT_EQ(closedCaptionSettings.enabled, expectedValues["enabled"]); + + if (closedCaptionSettings.styles.has_value()) { + const auto& styles = closedCaptionSettings.styles.value(); + + if (styles.backgroundColor.has_value()) + EXPECT_EQ(styles.backgroundColor.value(), expectedValues["styles"]["backgroundColor"]); + + if (styles.backgroundOpacity.has_value()) + EXPECT_EQ(styles.backgroundOpacity.value(), expectedValues["styles"]["backgroundOpacity"]); + + if (styles.fontColor.has_value()) + EXPECT_EQ(styles.fontColor.value(), expectedValues["styles"]["fontColor"]); + + if (styles.fontEdge.has_value()) + EXPECT_EQ(fontEdgeToString(styles.fontEdge.value()), expectedValues["styles"]["fontEdge"]); + + if (styles.fontEdgeColor.has_value()) + EXPECT_EQ(styles.fontEdgeColor.value(), expectedValues["styles"]["fontEdgeColor"]); + + if (styles.fontFamily.has_value()) + EXPECT_EQ(fontFamilyToString(styles.fontFamily.value()), expectedValues["styles"]["fontFamily"]); + + if (styles.fontOpacity.has_value()) + EXPECT_EQ(styles.fontOpacity.value(), expectedValues["styles"]["fontOpacity"]); + + if (styles.fontSize.has_value()) + EXPECT_EQ(styles.fontSize.value(), expectedValues["styles"]["fontSize"]); + + if (styles.textAlign.has_value()) + EXPECT_EQ(styles.textAlign.value(), expectedValues["styles"]["textAlign"]); + + if (styles.textAlignVertical.has_value()) + EXPECT_EQ(styles.textAlignVertical.value(), expectedValues["styles"]["textAlignVertical"]); + + if (styles.windowColor.has_value()) + EXPECT_EQ(styles.windowColor.value(), expectedValues["styles"]["windowColor"]); + + if (styles.windowOpacity.has_value()) + EXPECT_EQ(styles.windowOpacity.value(), expectedValues["styles"]["windowOpacity"]); + } + + EXPECT_EQ(closedCaptionSettings.preferredLanguages.value()[0], expectedValues["preferredLanguages"][0]); + EXPECT_EQ(closedCaptionSettings.preferredLanguages.value()[1], expectedValues["preferredLanguages"][1]); +} + +TEST_F(AccessibilityTest, VoiceGuidance) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Accessibility.voiceGuidance")); + + auto voiceGuidance = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().voiceGuidance(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve voiceGuidance from Accessibility.voiceGuidance() method"; + + EXPECT_EQ(voiceGuidance.enabled, expectedValues["enabled"]); + EXPECT_EQ(voiceGuidance.speed, expectedValues["speed"]); +} + +TEST_F(AccessibilityTest, VoiceGuidanceSettings) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Accessibility.voiceGuidanceSettings")); + + auto voiceGuidanceSettings = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().voiceGuidanceSettings(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve voiceGuidanceSettings from Accessibility.voiceGuidanceSettings() method"; + + EXPECT_EQ(voiceGuidanceSettings.enabled, expectedValues["enabled"]); + EXPECT_EQ(voiceGuidanceSettings.speed, expectedValues["speed"]); +} + +TEST_F(AccessibilityTest, AudioDescriptionSettings) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Accessibility.audioDescriptionSettings")); + + auto audioDescriptionSettings = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().audioDescriptionSettings(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve audioDescriptionSettings from Accessibility.audioDescriptionSettings() method"; + + EXPECT_EQ(audioDescriptionSettings.enabled, expectedValues["enabled"]); +} + +struct ClosedCaptionsChange : public Firebolt::Accessibility::IAccessibility::IOnClosedCaptionsSettingsChangedNotification { + void onClosedCaptionsSettingsChanged(const Firebolt::Accessibility::ClosedCaptionsSettings&) override; +}; + +// Below function is for when the event trigger via setter is done +Firebolt::Accessibility::ClosedCaptionsSettings newSettings; +void ClosedCaptionsChange::onClosedCaptionsSettingsChanged(const Firebolt::Accessibility::ClosedCaptionsSettings& closedCaptionsSettings) +{ + std::cout << "ClosedCaptionsSettingsChanged event fired" << std::endl; + newSettings = closedCaptionsSettings; +} + +TEST_F(AccessibilityTest, subscribeOnClosedCaptionsSettingsChanged) +{ + Firebolt::Error error = Firebolt::Error::None; + ClosedCaptionsChange closedCaptionsChange; + Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().subscribe(closedCaptionsChange, &error); + std::cout << " error: " << static_cast(error) << std::endl; + EXPECT_EQ(error, Firebolt::Error::None); + /* Since there is no return value for event subscription, error would be the only validation for now. + Returning a mock event response from open rpc and validating it against expected values from open rpc might not be of value. + This comment is applicable to all event unit tests. + */ +} + +TEST_F(AccessibilityTest, unsubscribeOnClosedCaptionsSettingsChanged) +{ + Firebolt::Error error = Firebolt::Error::None; + ClosedCaptionsChange closedCaptionsChange; + Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().unsubscribe(closedCaptionsChange, &error); + std::cout << " error: " << static_cast(error) << std::endl; + EXPECT_EQ(error, Firebolt::Error::None); +} + +struct VoiceGuidanceSettings : public Firebolt::Accessibility::IAccessibility::IOnVoiceGuidanceSettingsChangedNotification { + void onVoiceGuidanceSettingsChanged(const Firebolt::Accessibility::VoiceGuidanceSettings&) override; +}; + +// Below function is for when the event trigger via setter is done +Firebolt::Accessibility::VoiceGuidanceSettings newVoiceGuidanceSettings; +void VoiceGuidanceSettings::onVoiceGuidanceSettingsChanged(const Firebolt::Accessibility::VoiceGuidanceSettings& voiceGuidanceSettings) +{ + std::cout << "VoiceGuidanceSettingsChanged event fired" << std::endl; + newVoiceGuidanceSettings = voiceGuidanceSettings; +} + +TEST_F(AccessibilityTest, subscribeOnVoiceGuidanceSettingsChanged) +{ + Firebolt::Error error = Firebolt::Error::None; + VoiceGuidanceSettings voiceGuidanceSettings; + Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().subscribe(voiceGuidanceSettings, &error); + std::cout << " error: " << static_cast(error) << std::endl; + EXPECT_EQ(error, Firebolt::Error::None); +} + +TEST_F(AccessibilityTest, unsubscribeOnVoiceGuidanceSettingsChanged) +{ + Firebolt::Error error = Firebolt::Error::None; + VoiceGuidanceSettings voiceGuidanceSettings; + Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().unsubscribe(voiceGuidanceSettings, &error); + std::cout << " error: " << static_cast(error) << std::endl; + EXPECT_EQ(error, Firebolt::Error::None); +} + +struct AudioDescriptionSettings : public Firebolt::Accessibility::IAccessibility::IOnAudioDescriptionSettingsChangedNotification { + void onAudioDescriptionSettingsChanged(const Firebolt::Accessibility::AudioDescriptionSettings&) override; +}; + +// Below function is for when the event trigger via setter is done +Firebolt::Accessibility::AudioDescriptionSettings newAudioDescriptionSettings; +void AudioDescriptionSettings::onAudioDescriptionSettingsChanged(const Firebolt::Accessibility::AudioDescriptionSettings& audioDescriptionSettings) +{ + std::cout << "AudioDescriptionSettingsChanged event fired" << std::endl; + newAudioDescriptionSettings = audioDescriptionSettings; +} + +TEST_F(AccessibilityTest, subscribeOnAudioDescriptionSettingsChanged) +{ + Firebolt::Error error = Firebolt::Error::None; + AudioDescriptionSettings audioDescriptionSettings; + Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().subscribe(audioDescriptionSettings, &error); + std::cout << " error: " << static_cast(error) << std::endl; + EXPECT_EQ(error, Firebolt::Error::None); +} + +TEST_F(AccessibilityTest, unsubscribeOnAudioDescriptionSettingsChanged) +{ + Firebolt::Error error = Firebolt::Error::None; + AudioDescriptionSettings audioDescriptionSettings; + Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().unsubscribe(audioDescriptionSettings, &error); + std::cout << " error: " << static_cast(error) << std::endl; + EXPECT_EQ(error, Firebolt::Error::None); +} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/accountTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/accountTest.cpp new file mode 100644 index 000000000..000c80bfa --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/accountTest.cpp @@ -0,0 +1,38 @@ +#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, Id) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Account.id")); + + std::string account_id = Firebolt::IFireboltAccessor::Instance().AccountInterface().id(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve account_id from Account.id() method"; + EXPECT_EQ(account_id, expectedValues); +} + +TEST_F(AccountTest, Uid) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Account.uid")); + + std::string account_uid = Firebolt::IFireboltAccessor::Instance().AccountInterface().uid(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve account_uid from Account.uid() method"; + EXPECT_EQ(account_uid, expectedValues); +} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/advertisingTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/advertisingTest.cpp new file mode 100644 index 000000000..4b4ab631b --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/advertisingTest.cpp @@ -0,0 +1,107 @@ +#include "unit.h" + +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; + } + + std::string skipRestrictionToString(Firebolt::Advertising::SkipRestriction skipRestriction) + { + std::string str = ""; + switch (skipRestriction) + { + case Firebolt::Advertising::SkipRestriction::NONE: + str = "none"; + break; + case Firebolt::Advertising::SkipRestriction::ADS_UNWATCHED: + str = "adsUnwatched"; + break; + case Firebolt::Advertising::SkipRestriction::ADS_ALL: + str = "adsAll"; + break; + case Firebolt::Advertising::SkipRestriction::ALL: + str = "all"; + break; + default: + str = "unknown"; + } + return str; + } +}; + +TEST_F(AdvertisingTest, Config) +{ + std::string expectedValues = jsonEngine->get_value("Advertising.config"); + + Firebolt::Advertising::AdConfigurationOptions options; + std::string adFrameworkConfig = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().config(options, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve adFrameworkConfig from Advertising.config() method"; + EXPECT_EQ((nlohmann::json::parse(adFrameworkConfig)).dump(), expectedValues); +} + +TEST_F(AdvertisingTest, Policy) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Advertising.policy")); + + Firebolt::Advertising::AdPolicy adPolicy = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().policy(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve adPolicy from Advertising.policy() method"; + + if (adPolicy.limitAdTracking.has_value()) + EXPECT_EQ(adPolicy.limitAdTracking, expectedValues["limitAdTracking"]); + + if (adPolicy.skipRestriction.has_value()) + EXPECT_EQ(skipRestrictionToString(adPolicy.skipRestriction.value()), expectedValues["skipRestriction"]); +} + +// Helper function to convert JSON value to AdvertisingIdResultLmt enum +std::string lmtToString(Firebolt::Advertising::AdvertisingIdResultLmt lmt) { + return std::to_string(static_cast(lmt)); +} + +TEST_F(AdvertisingTest, Id) +{ + nlohmann::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Advertising.advertisingId")); + + std::optional options = std::nullopt; // Assuming options are not provided + + Firebolt::Advertising::AdvertisingIdResult actualValues = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().advertisingId(options, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve AdvertisingId from Advertising.advertisingId() method"; + + EXPECT_EQ(actualValues.ifa, expectedValues["ifa"]); + EXPECT_EQ(actualValues.ifa_type, expectedValues["ifa_type"]); + EXPECT_EQ(lmtToString(actualValues.lmt), expectedValues["lmt"]); +} + +TEST_F(AdvertisingTest, DeviceAttributes) +{ + std::string expectedValues = jsonEngine->get_value("Advertising.deviceAttributes"); + + std::string deviceAttributes = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().deviceAttributes(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve deviceAttributes from Advertising.deviceAttributes() method"; + EXPECT_EQ(deviceAttributes, expectedValues); +} + +TEST_F(AdvertisingTest, AppBundleId) +{ + auto actual_value = jsonEngine->get_value("Advertising.appBundleId"); + + auto appBundleId = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().appBundleId(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve appBundleId from Advertising.appBundleId() method"; + EXPECT_EQ(appBundleId, REMOVE_QUOTES(actual_value)); +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/authenticationTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/authenticationTest.cpp new file mode 100644 index 000000000..cc16a5163 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/authenticationTest.cpp @@ -0,0 +1,61 @@ +#include "unit.h" + +class AuthenticationTest : 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(AuthenticationTest, Token) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Authentication.token")); + + Firebolt::Authentication::TokenType type = Firebolt::Authentication::TokenType::DEVICE; + std::optional options; + + auto token = Firebolt::IFireboltAccessor::Instance().AuthenticationInterface().token(type, options, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve token from Authentication.token() method"; + EXPECT_EQ(token.value, expectedValues["value"]); +} + +TEST_F(AuthenticationTest, Device) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Authentication.device")); + + std::string device = Firebolt::IFireboltAccessor::Instance().AuthenticationInterface().device(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve device from Authentication.device() method"; + EXPECT_EQ(device, expectedValues); +} + +TEST_F(AuthenticationTest, Session) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Authentication.session")); + + std::string session = Firebolt::IFireboltAccessor::Instance().AuthenticationInterface().session(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve session from Authentication.session() method"; + EXPECT_EQ(session, expectedValues); +} + +TEST_F(AuthenticationTest, Root) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Authentication.root")); + + std::string root = Firebolt::IFireboltAccessor::Instance().AuthenticationInterface().root(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve root from Authentication.root() method"; + EXPECT_EQ(root, expectedValues); +} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/capabilitiesTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/capabilitiesTest.cpp new file mode 100644 index 000000000..f29179771 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/capabilitiesTest.cpp @@ -0,0 +1,149 @@ +#include "unit.h" + +class CapabilitiesTest : 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(CapabilitiesTest, Supported) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Capabilities.supported")); + + std::string capability = "xrn:firebolt:capability:wifi:scan"; + + bool supported = Firebolt::IFireboltAccessor::Instance().CapabilitiesInterface().supported(capability, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve supported from Capabilities.supported() method"; + EXPECT_EQ(supported, expectedValues); +} + +TEST_F(CapabilitiesTest, Available) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Capabilities.available")); + + std::string capability = "xrn:firebolt:capability:token:device"; + + bool available = Firebolt::IFireboltAccessor::Instance().CapabilitiesInterface().available(capability, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve available from Capabilities.available() method"; + EXPECT_EQ(available, expectedValues); +} + +TEST_F(CapabilitiesTest, Permitted) +{ + nlohmann::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Capabilities.permitted")); + + std::string capability = "xrn:firebolt:capability:input:keyboard"; + + // Initialize options with a role + std::optional options; + options.emplace(); // Initialize the optional + options->role = Firebolt::Capabilities::Role::MANAGE; + + // Call the permitted function + bool permitted = Firebolt::IFireboltAccessor::Instance().CapabilitiesInterface().permitted(capability, options, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve permitted from Capabilities.permitted() method"; + EXPECT_EQ(permitted, expectedValues); +} + +TEST_F(CapabilitiesTest, Granted) +{ + nlohmann::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Capabilities.granted")); + std::string capability = "xrn:firebolt:capability:localization:postal-code"; + + std::optional options; + bool granted = Firebolt::IFireboltAccessor::Instance().CapabilitiesInterface().granted(capability, options, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve granted from Capabilities.granted() method"; + EXPECT_EQ(granted, expectedValues); +} + +TEST_F(CapabilitiesTest, Info) +{ + // Parse the expected values from the JSON + nlohmann::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Capabilities.info")); + + // Extract the expected result for the specific capability + nlohmann::json expectedValue; + for (const auto &item : expectedValues) + { + if (item["capability"] == "xrn:firebolt:capability:device:model") + { + expectedValue = item; + break; + } + } + // Define the capabilities to query + std::vector capabilities = { + "xrn:firebolt:capability:device:model"}; + + std::vector info = Firebolt::IFireboltAccessor::Instance().CapabilitiesInterface().info(capabilities, &error); + + // Ensure there's at least one result + ASSERT_FALSE(info.empty()); + + // Compare the first actual value with the expected value + Firebolt::Capabilities::CapabilityInfo actualValue = info[0]; + + // Compare each field + EXPECT_EQ(actualValue.capability, expectedValue["capability"].get()); + EXPECT_EQ(actualValue.supported, expectedValue["supported"].get()); + EXPECT_EQ(actualValue.available, expectedValue["available"].get()); + + if (expectedValue.contains("use")) + { + if (expectedValue["use"].contains("permitted")) + { + auto expectedPermitted = expectedValue["use"]["permitted"].is_null() ? std::optional{} : std::make_optional(expectedValue["use"]["permitted"].get()); + EXPECT_EQ(actualValue.use.permitted, expectedPermitted); + } + if (expectedValue["use"].contains("granted")) + { + auto expectedGranted = expectedValue["use"]["granted"].is_null() ? std::optional{} : std::make_optional(expectedValue["use"]["granted"].get()); + EXPECT_EQ(actualValue.use.granted, expectedGranted); + } + } + + if (expectedValue.contains("manage")) + { + if (expectedValue["manage"].contains("permitted")) + { + auto expectedPermitted = expectedValue["manage"]["permitted"].is_null() ? std::optional{} : std::make_optional(expectedValue["manage"]["permitted"].get()); + EXPECT_EQ(actualValue.manage.permitted, expectedPermitted); + } + if (expectedValue["manage"].contains("granted")) + { + auto expectedGranted = expectedValue["manage"]["granted"].is_null() ? std::optional{} : std::make_optional(expectedValue["manage"]["granted"].get()); + EXPECT_EQ(actualValue.manage.granted, expectedGranted); + } + } + + if (expectedValue.contains("provide")) + { + if (expectedValue["provide"].contains("permitted")) + { + auto expectedPermitted = expectedValue["provide"]["permitted"].is_null() ? std::optional{} : std::make_optional(expectedValue["provide"]["permitted"].get()); + EXPECT_EQ(actualValue.provide.permitted, expectedPermitted); + } + if (expectedValue["provide"].contains("granted")) + { + auto expectedGranted = expectedValue["provide"]["granted"].is_null() ? std::optional{} : std::make_optional(expectedValue["provide"]["granted"].get()); + EXPECT_EQ(actualValue.provide.granted, expectedGranted); + } + } + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve info from Capabilities.info() method"; +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/deviceTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/deviceTest.cpp new file mode 100644 index 000000000..85107fd33 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/deviceTest.cpp @@ -0,0 +1,268 @@ +#include "unit.h" + +class DeviceTest : 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(DeviceTest, Id) +{ + + auto actual_value = jsonEngine->get_value("Device.id"); + + auto id = Firebolt::IFireboltAccessor::Instance().DeviceInterface().id(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve id from Device.id() method"; + EXPECT_EQ(id, REMOVE_QUOTES(actual_value)); +} + +TEST_F(DeviceTest, Distributor) +{ + + auto actual_value = jsonEngine->get_value("Device.distributor"); + + auto distributor = Firebolt::IFireboltAccessor::Instance().DeviceInterface().distributor(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve distributor from Device.distributor() method"; + EXPECT_EQ(distributor, REMOVE_QUOTES(actual_value)); +} + +TEST_F(DeviceTest, Platform) +{ + + auto actual_value = jsonEngine->get_value("Device.platform"); + + auto platform = Firebolt::IFireboltAccessor::Instance().DeviceInterface().platform(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve platform from Device.platform() method"; + EXPECT_EQ(platform, REMOVE_QUOTES(actual_value)); +} + +TEST_F(DeviceTest, Uid) +{ + + auto actual_value = jsonEngine->get_value("Device.uid"); + + auto uid = Firebolt::IFireboltAccessor::Instance().DeviceInterface().uid(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve uid from Device.uid() method"; + EXPECT_EQ(uid, REMOVE_QUOTES(actual_value)); +} + +TEST_F(DeviceTest, Type) +{ + + auto actual_value = jsonEngine->get_value("Device.type"); + + auto type = Firebolt::IFireboltAccessor::Instance().DeviceInterface().type(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve type from Device.type() method"; + EXPECT_EQ(type, REMOVE_QUOTES(actual_value)); +} + +TEST_F(DeviceTest, Model) +{ + + auto actual_value = jsonEngine->get_value("Device.model"); + + auto model = Firebolt::IFireboltAccessor::Instance().DeviceInterface().model(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve model from Device.model() method"; + EXPECT_EQ(model, REMOVE_QUOTES(actual_value)); +} + +TEST_F(DeviceTest, Sku) +{ + + auto actual_value = jsonEngine->get_value("Device.sku"); + + auto sku = Firebolt::IFireboltAccessor::Instance().DeviceInterface().sku(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve sku from Device.sku() method"; + EXPECT_EQ(sku, REMOVE_QUOTES(actual_value)); +} + +TEST_F(DeviceTest, TestDeviceMake) +{ + + auto actual_value = jsonEngine->get_value("Device.make"); + + auto make = Firebolt::IFireboltAccessor::Instance().DeviceInterface().make(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve make from Device.make() method"; + EXPECT_EQ(make, REMOVE_QUOTES(actual_value)); +} + +TEST_F(DeviceTest, Hdcp) +{ + Firebolt::Error error = Firebolt::Error::None; + + // Parsing expected JSON values into a BooleanMap + nlohmann::json expectedJson = nlohmann::json::parse(jsonEngine->get_value("Device.hdcp")); + Firebolt::Types::BooleanMap expectedValues; + + for (auto it = expectedJson.begin(); it != expectedJson.end(); ++it) + { + expectedValues[it.key()] = it.value().get(); + } + + // Getting the actual value from the DeviceInterface + Firebolt::Device::HDCPVersionMap hdcpMap = Firebolt::IFireboltAccessor::Instance().DeviceInterface().hdcp(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve hdcp from Device.hdcp() method"; + + // Convert HDCPVersionMap to BooleanMap for comparison + Firebolt::Types::BooleanMap actualValues; + actualValues["hdcp1.4"] = hdcpMap.hdcp1_4; + actualValues["hdcp2.2"] = hdcpMap.hdcp2_2; + + EXPECT_EQ(actualValues, expectedValues); +} + +TEST_F(DeviceTest, Hdr) +{ + Firebolt::Error error = Firebolt::Error::None; + + // Parsing expected JSON values into a BooleanMap + nlohmann::json expectedJson = nlohmann::json::parse(jsonEngine->get_value("Device.hdr")); + Firebolt::Types::BooleanMap expectedValues; + + for (auto it = expectedJson.begin(); it != expectedJson.end(); ++it) + { + expectedValues[it.key()] = it.value().get(); + } + + // Getting the actual value from the DeviceInterface + Firebolt::Device::HDRFormatMap hdrMap = Firebolt::IFireboltAccessor::Instance().DeviceInterface().hdr(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve hdr from Device.hdr() method"; + + // Convert HDRFormatMap to BooleanMap for comparison + Firebolt::Types::BooleanMap actualValues; + actualValues["hdr10"] = hdrMap.hdr10; + actualValues["hdr10Plus"] = hdrMap.hdr10Plus; + actualValues["dolbyVision"] = hdrMap.dolbyVision; + actualValues["hlg"] = hdrMap.hlg; + + EXPECT_EQ(actualValues, expectedValues); +} + +TEST_F(DeviceTest, Audio) +{ + // Hardcoded expected values + Firebolt::Device::AudioProfiles expectedValues; + expectedValues.stereo = true; + expectedValues.dolbyDigital5_1 = true; + expectedValues.dolbyDigital5_1_plus = true; + expectedValues.dolbyAtmos = true; + + // Getting the actual value from the DeviceInterface + const Firebolt::Device::AudioProfiles audio = Firebolt::IFireboltAccessor::Instance().DeviceInterface().audio(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve audio from Device.audio() method"; + EXPECT_EQ(audio.stereo, expectedValues.stereo); + EXPECT_EQ(audio.dolbyDigital5_1, expectedValues.dolbyDigital5_1); + EXPECT_EQ(audio.dolbyDigital5_1_plus, expectedValues.dolbyDigital5_1_plus); + EXPECT_EQ(audio.dolbyAtmos, expectedValues.dolbyAtmos); +} + +TEST_F(DeviceTest, Network) +{ + + // Hardcoded expected values + Firebolt::Device::NetworkInfoResult expectedValues; + expectedValues.state = Firebolt::Device::NetworkState::CONNECTED; + expectedValues.type = Firebolt::Device::NetworkType::WIFI; + + // Getting the actual value from the DeviceInterface + Firebolt::Device::NetworkInfoResult network = Firebolt::IFireboltAccessor::Instance().DeviceInterface().network(&error); + + // Perform the assertions + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve network from Device.network() method"; + EXPECT_EQ(network.state, expectedValues.state); + EXPECT_EQ(network.type, expectedValues.type); +} + +TEST_F(DeviceTest, ScreenResolution) +{ + + // Parse expected JSON values + nlohmann::json expectedJson; + try + { + std::string jsonString = jsonEngine->get_value("Device.screenResolution"); + expectedJson = nlohmann::json::parse(jsonString); + } + catch (const nlohmann::json::exception &e) + { + FAIL() << "Failed to parse JSON: " << e.what(); + } + + // Validate that expectedJson is an array and has the required number of elements + if (!expectedJson.is_array()) + { + FAIL() << "Expected JSON is not an array: " << expectedJson.dump(4); + } + + // Getting the actual value from the DeviceInterface + Firebolt::Error error = Firebolt::Error::None; + std::string screenResolution = Firebolt::IFireboltAccessor::Instance().DeviceInterface().screenResolution(&error); + + // Perform the assertions + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve screenResolution from Device.screenResolution() method"; + EXPECT_EQ(screenResolution, expectedJson.get()); +} + +TEST_F(DeviceTest, VideoResolution) +{ + + // Parse expected JSON values + nlohmann::json expectedJson; + try + { + std::string jsonString = jsonEngine->get_value("Device.videoResolution"); + expectedJson = nlohmann::json::parse(jsonString); + } + catch (const nlohmann::json::exception &e) + { + FAIL() << "Failed to parse JSON: " << e.what(); + } + + // Validate that expectedJson is an array and has the required number of elements + if (!expectedJson.is_array()) + { + FAIL() << "Expected JSON is not an array: " << expectedJson.dump(4); + } + + + // Getting the actual value from the DeviceInterface + Firebolt::Error error = Firebolt::Error::None; + std::string videoResolution = Firebolt::IFireboltAccessor::Instance().DeviceInterface().videoResolution(&error); + + // Perform the assertions + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve videoResolution from Device.videoResolution() method"; + EXPECT_EQ(videoResolution, expectedJson.get()); +} + +TEST_F(DeviceTest, Name) +{ + + auto actual_value = jsonEngine->get_value("Device.name"); + + auto name = Firebolt::IFireboltAccessor::Instance().DeviceInterface().name(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve name from Device.name() method"; + EXPECT_EQ(name, REMOVE_QUOTES(actual_value)); +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/discoveryTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/discoveryTest.cpp new file mode 100644 index 000000000..6a1a55a94 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/discoveryTest.cpp @@ -0,0 +1,204 @@ +#include "unit.h" + +class DiscoveryTest : public ::testing::Test +{ +protected: + JsonEngine* jsonEngine; + Firebolt::Error error = Firebolt::Error::None; + + void SetUp() override + { + jsonEngine = new JsonEngine(); + } + + void TearDown() override + { + delete jsonEngine; + } + + // Helper function to mock EntityInfo + Firebolt::Entertainment::EntityInfo mockEntityInfo() + { + Firebolt::Entertainment::EntityInfo entityInfo; + entityInfo.identifiers.entityId = "345"; + entityInfo.title = "Cool Runnings"; + entityInfo.entityType = Firebolt::Entertainment::EntityInfoEntityType::PROGRAM; + entityInfo.programType = Firebolt::Entertainment::ProgramType::MOVIE; + entityInfo.synopsis = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc."; + entityInfo.releaseDate = "1993-01-01T00:00:00.000Z"; + + // Mock content ratings + Firebolt::Entertainment::ContentRating usRating; + usRating.scheme = Firebolt::Entertainment::ContentRatingScheme::US_MOVIE; + usRating.rating = "PG"; + + Firebolt::Entertainment::ContentRating caRating; + caRating.scheme = Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE; + caRating.rating = "G"; + + entityInfo.contentRatings = std::vector{usRating, caRating}; + + // Mock ways to watch + Firebolt::Entertainment::WayToWatch wayToWatch; + wayToWatch.identifiers.assetId = "123"; + wayToWatch.expires = "2025-01-01T00:00:00.000Z"; + wayToWatch.entitled = true; + wayToWatch.entitledExpires = "2025-01-01T00:00:00.000Z"; + wayToWatch.offeringType = Firebolt::Entertainment::OfferingType::BUY; + wayToWatch.price = 2.99f; + + wayToWatch.videoQuality = std::vector{Firebolt::Entertainment::WayToWatchVideoQuality::UHD}; + wayToWatch.audioProfile = std::vector{Firebolt::Types::AudioProfile::DOLBY_ATMOS}; + wayToWatch.audioLanguages = std::vector{"en"}; + wayToWatch.closedCaptions = std::vector{"en"}; + wayToWatch.subtitles = std::vector{"es"}; + wayToWatch.audioDescriptions = std::vector{"en"}; + + entityInfo.waysToWatch = std::vector{wayToWatch}; + + return entityInfo; + } +}; + + +TEST_F(DiscoveryTest, Policy) +{ + Firebolt::Error error = Firebolt::Error::None; + + // Parsing expected JSON values into a BooleanMap + nlohmann::json_abi_v3_11_3::json expectedJson = nlohmann::json::parse(jsonEngine->get_value("Discovery.policy")); + Firebolt::Types::BooleanMap expectedValues; + + for (auto it = expectedJson.begin(); it != expectedJson.end(); ++it) + { + expectedValues[it.key()] = it.value().get(); + } + + // Getting the actual value + Firebolt::Discovery::DiscoveryPolicy policy = Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().policy(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve policy from Discovery.policy() method"; + + // Convert DiscoveryPolicy to BooleanMap for comparison + Firebolt::Types::BooleanMap actualValues; + actualValues["enableRecommendations"] = policy.enableRecommendations; + actualValues["shareWatchHistory"] = policy.shareWatchHistory; + actualValues["rememberWatchedPrograms"] = policy.rememberWatchedPrograms; + + EXPECT_EQ(actualValues, expectedValues); +} + +TEST_F(DiscoveryTest, EntityInfo) +{ + Firebolt::Error error = Firebolt::Error::None; + nlohmann::json_abi_v3_11_3::json expectedValue = nlohmann::json::parse(jsonEngine->get_value("Discovery.entityInfo")); + + // Mock EntityInfoResult + Firebolt::Discovery::EntityInfoResult entityInfoResult; + entityInfoResult.expires = "2025-01-01T00:00:00.000Z"; + entityInfoResult.entity = mockEntityInfo(); + entityInfoResult.related = std::nullopt; + + bool actualValue = Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().entityInfo(entityInfoResult, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Discovery.entityInfo() method"; + EXPECT_EQ(actualValue, expectedValue); +} + +TEST_F(DiscoveryTest, PurchasedContent) +{ + Firebolt::Error error = Firebolt::Error::None; + nlohmann::json_abi_v3_11_3::json expectedValue = nlohmann::json::parse(jsonEngine->get_value("Discovery.purchasedContent")); + + // Mock purchasedContentResult + Firebolt::Discovery::PurchasedContentResult purchasedContentResult; + purchasedContentResult.expires = "2025-01-01T00:00:00.000Z"; + purchasedContentResult.totalCount = 10; + purchasedContentResult.entries.push_back(mockEntityInfo()); + + bool actualValue = Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().purchasedContent(purchasedContentResult, &error); + + EXPECT_EQ(actualValue, expectedValue); +} + +TEST_F(DiscoveryTest, WatchNext) +{ + Firebolt::Error error = Firebolt::Error::None; + nlohmann::json_abi_v3_11_3::json expectedJson = nlohmann::json::parse(jsonEngine->get_value("Discovery.watchNext")); + + std::string title = "A Fantastic Show"; + Firebolt::Entertainment::ContentIdentifiers contentIdentifiers; + contentIdentifiers.entityId = "partner.com/entity/456"; + + bool result = Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().watchNext(title, contentIdentifiers, std::nullopt, std::nullopt, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve policy from Discovery.watchNext() method"; + EXPECT_EQ(result, expectedJson); +} + + +TEST_F(DiscoveryTest, Entitlements) +{ + Firebolt::Error error = Firebolt::Error::None; + nlohmann::json_abi_v3_11_3::json expectedJson = nlohmann::json::parse(jsonEngine->get_value("Discovery.entitlements")); + + std::vector mockEntitlements = { + {"entitlement1", "2023-01-01T00:00:00Z", "2023-12-31T23:59:59Z"}, + {"entitlement2", std::nullopt, "2023-12-31T23:59:59Z"}, + {"entitlement3", "2023-01-01T00:00:00Z", std::nullopt} + }; + bool success = Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().entitlements(mockEntitlements, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve policy from Discovery.entitlements() method"; + EXPECT_EQ(success, expectedJson); +} + + +TEST_F(DiscoveryTest, ContentAccess) +{ + auto expectedValue = jsonEngine->get_value("Discovery.contentAccess"); + + std::vector mockAvailabilities = { + {Firebolt::Discovery::AvailabilityType::CHANNEL_LINEUP, "availability1", "catalog1", "2023-01-01T00:00:00Z", "2023-12-31T23:59:59Z"}, + {Firebolt::Discovery::AvailabilityType::PROGRAM_LINEUP, "availability2", std::nullopt, "2023-01-01T00:00:00Z", std::nullopt} + }; + + std::vector mockEntitlements = { + {"entitlement1", "2023-01-01T00:00:00Z", "2023-12-31T23:59:59Z"}, + {"entitlement2", std::nullopt, "2023-12-31T23:59:59Z"}, + {"entitlement3", "2023-01-01T00:00:00Z", std::nullopt} + }; + + Firebolt::Discovery::ContentAccessIdentifiers mockContentAccessIdentifiers = { + mockAvailabilities, + mockEntitlements + }; + + Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().contentAccess(mockContentAccessIdentifiers, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to call Discovery.contentAccess() method"; +} + +TEST_F(DiscoveryTest, ClearContentAccess) +{ + auto expectedValue = jsonEngine->get_value("Discovery.clearContentAccess"); + + Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().clearContentAccess(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to call Discovery.clearContentAccess() method"; +} + +TEST_F(DiscoveryTest, Launch) +{ + nlohmann::json_abi_v3_11_3::json expectedValue = nlohmann::json::parse(jsonEngine->get_value("Discovery.launch")); + + std::string appId = "123"; + Firebolt::Intents::LaunchIntent launchIntent; + launchIntent.action = "launch"; + launchIntent.context.source = "source"; + + bool actualValue = Firebolt::IFireboltAccessor::Instance().DiscoveryInterface().launch("appId", launchIntent, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to call Discovery.launch() method"; + EXPECT_EQ(actualValue, expectedValue); +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/keyboardTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/keyboardTest.cpp new file mode 100644 index 000000000..fad495cae --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/keyboardTest.cpp @@ -0,0 +1,62 @@ +#include "unit.h" + +class KeyboardTest : public ::testing::Test +{ +protected: + JsonEngine *jsonEngine; + Firebolt::Error error = Firebolt::Error::None; + + void SetUp() override + { + jsonEngine = new JsonEngine(); + } + + void TearDown() override + { + delete jsonEngine; + } + + struct KeyboardAsyncResponse : public Firebolt::Keyboard::IKeyboardAsyncResponse { + void response(const std::string& result, Firebolt::Error *err) override { + // Handle the response here + std::cout << "Response received: " << result << std::endl; + } + }; +}; + +TEST_F(KeyboardTest, Email) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Keyboard.email")); + + Firebolt::Keyboard::EmailUsage type = Firebolt::Keyboard::EmailUsage::SIGN_IN; + std::string message = "abc@123.com"; + KeyboardAsyncResponse responseHandler; + + Firebolt::IFireboltAccessor::Instance().KeyboardInterface().requestEmail(type, message, responseHandler, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to call keyboard.email() method"; +} + +TEST_F(KeyboardTest, Password) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Keyboard.password")); + + std::string message = "abc123"; + KeyboardAsyncResponse responseHandler; + + Firebolt::IFireboltAccessor::Instance().KeyboardInterface().requestPassword(message, responseHandler, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to call keyboard.password() method"; +} + +TEST_F(KeyboardTest, Standard) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Keyboard.standard")); + + std::string message = "hello world"; + KeyboardAsyncResponse responseHandler; + + Firebolt::IFireboltAccessor::Instance().KeyboardInterface().requestStandard(message, responseHandler, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to call keyboard.standard() method"; +} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/lifecycleTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/lifecycleTest.cpp new file mode 100644 index 000000000..7eb35c6d6 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/lifecycleTest.cpp @@ -0,0 +1,39 @@ +#include "unit.h" + +class LifecycleTest : 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(LifecycleTest, Close) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Lifecycle.close")); + + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().close(Firebolt::Lifecycle::CloseReason::USER_EXIT, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Error on calling Lifecycle.close() method"; +} + +// Lifecycle.ready method needs events to be supported in mock transport to work + +TEST_F(LifecycleTest, Finished) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Lifecycle.finished")); + + Firebolt::IFireboltAccessor::Instance().LifecycleInterface().finished(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Error on calling Lifecycle.background() method"; +} + diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/localizationTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/localizationTest.cpp new file mode 100644 index 000000000..523d070b4 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/localizationTest.cpp @@ -0,0 +1,133 @@ +#include "unit.h" +#include + +class LocalizationTest : 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(LocalizationTest, Locality) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Localization.locality")); + + std::string locality = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().locality(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve locality from Localization.locality() method"; + EXPECT_EQ(locality, expectedValues); +} + +TEST_F(LocalizationTest, PostalCode) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Localization.postalCode")); + + std::string postalCode = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().postalCode(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve postal_code from Localization.postalCode() method"; + EXPECT_EQ(postalCode, expectedValues); +} + +TEST_F(LocalizationTest, CountryCode) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Localization.countryCode")); + + std::string countryCode = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().countryCode(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve country_code from Localization.countryCode() method"; + EXPECT_EQ(countryCode, expectedValues); +} + +TEST_F(LocalizationTest, Language) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Localization.language")); + + std::string language = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().language(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve language from Localization.language() method"; + EXPECT_EQ(language, expectedValues); +} + +TEST_F(LocalizationTest, Locale) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Localization.locale")); + + std::string locale = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().locale(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve locale from Localization.language() method"; + EXPECT_EQ(locale, expectedValues); +} + +TEST_F(LocalizationTest, PreferredAudioLanguages) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Localization.preferredAudioLanguages")); + + std::vector preferredAudioLanguages = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().preferredAudioLanguages(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve preferred_audio_languages from Localization.preferredAudioLanguages() method"; + EXPECT_EQ(preferredAudioLanguages, expectedValues); +} + +TEST_F(LocalizationTest, AdditionalInfo) +{ + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Localization.additionalInfo")); + + Firebolt::Localization::Info additionalInfo = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().additionalInfo(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve additional_info from Localization.additionalInfo() method"; + EXPECT_EQ(additionalInfo, expectedValues); +} + +// Helper function to round a double to 4 decimal places +double roundTo4Decimals(double value) { + return std::round(value * 10000.0) / 10000.0; +} + +TEST_F(LocalizationTest, LatLon) +{ + nlohmann::json expectedJson; + try + { + std::string jsonString = jsonEngine->get_value("Localization.latlon"); + expectedJson = nlohmann::json::parse(jsonString); + } + catch (const nlohmann::json::exception &e) + { + FAIL() << "Failed to parse JSON: " << e.what(); + } + + // Validate that expectedJson is an array and has the required number of elements + if (!expectedJson.is_array()) + { + FAIL() << "Expected JSON is not an array: " << expectedJson.dump(4); + } + + if (expectedJson.size() != 2) + { + FAIL() << "Expected JSON array does not have 2 elements: " << expectedJson.dump(4); + } + + // Getting the actual value from the LocalizationInterface + Firebolt::Localization::LatLon latlon = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().latlon(&error); + + // Round the actual values to 4 decimal places + double roundedLat = roundTo4Decimals(latlon.first); + double roundedLon = roundTo4Decimals(latlon.second); + + // Convert actual value to JSON + nlohmann::json actualJson = {roundedLat, roundedLon}; + + // Perform the assertions + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve latlon from Localization.latlon() method"; + EXPECT_EQ(actualJson, expectedJson); +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/metricsTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/metricsTest.cpp new file mode 100644 index 000000000..0f588a44c --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/metricsTest.cpp @@ -0,0 +1,204 @@ +#include "unit.h" + +class MetricsTest : 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(MetricsTest, StartContent) +{ + + auto actual_value = jsonEngine->get_value("Metrics.startContent"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().startContent("example", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.startContent() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, StopContent) +{ + + auto actual_value = jsonEngine->get_value("Metrics.stopContent"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().stopContent("example", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.stopContent() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, Page) +{ + // Parse the expected values from the JSON + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Metrics.page")); + + std::string pageId = "xyz"; + + bool status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().page(pageId, &error); + + // Compare the expected and actual results + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.page() method"; + EXPECT_EQ(status, expectedValues); +} + +TEST_F(MetricsTest, Action) +{ + // Parse the expected values from the JSON + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Metrics.action")); + std::cout << "Expected value for capability " << expectedValues << std::endl; + + Firebolt::Metrics::Category category = Firebolt::Metrics::Category::USER; + auto type = "The user did foo"; + std::optional parameters = std::nullopt; + + bool status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().action(category, type, parameters, &error); + std::cout << "Status value for capability " << status << std::endl; + + // Compare the expected and actual results + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.action() method"; + EXPECT_EQ(status, expectedValues); +} + +TEST_F(MetricsTest, Error) +{ + // Parse the expected values from the JSON + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Metrics.error")); + std::cout << "Expected value for capability " << expectedValues << std::endl; + + Firebolt::Metrics::ErrorType type = Firebolt::Metrics::ErrorType::MEDIA; + std::string code = "MEDIA-STALLED"; + std::string description = "playback stalled"; + std::optional parameters = std::nullopt; + bool visible = true; + + bool status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().error(type, code, description, visible, parameters, &error); + std::cout << "Status value for capability " << status << std::endl; + + // Compare the expected and actual results + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.error() method"; + EXPECT_EQ(status, expectedValues); +} + +TEST_F(MetricsTest, MediaLoadStart) +{ + auto actual_value = jsonEngine->get_value("Metrics.mediaLoadStart"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaLoadStart("345", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaLoadStart() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaPlay) +{ + auto actual_value = jsonEngine->get_value("Metrics.mediaPlay"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaPlay("345", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaPlay() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaPlaying) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaPlaying"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaPlaying("345", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaPlaying() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaPause) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaPause"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaPause("345", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaPause() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaWaiting) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaWaiting"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaWaiting("345", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaWaiting() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaProgress) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaProgress"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaProgress("345", "0.75", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaProgress() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaSeeking) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaSeeking"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaSeeking("345", "0.25", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaSeeking() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaSeeked) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaSeeked"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaSeeked("345", "0.51", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaSeeked() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaRateChange) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaRateChange"); + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaRateChange("345", 2, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaRateChange() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaRenditionChange) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaRenditionChange"); + std::optional profile = std::nullopt; + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaRenditionChange("345", 1080, 950, 1020, profile, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Metrics.mediaRenditionChange() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} + +TEST_F(MetricsTest, MediaEnded) +{ + std::string actual_value = jsonEngine->get_value("Metrics.mediaEnded"); + std::optional profile = std::nullopt; + + auto status = Firebolt::IFireboltAccessor::Instance().MetricsInterface().mediaEnded("345", &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve account_uid from Metrics.mediaEnded() method"; + EXPECT_EQ(status, STRING_TO_BOOL(actual_value)); +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/parametersTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/parametersTest.cpp new file mode 100644 index 000000000..2a29e5d91 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/parametersTest.cpp @@ -0,0 +1,41 @@ +#include "unit.h" + +class ParametersTest : 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(ParametersTest, Initialization) +{ + nlohmann::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Parameters.initialization")); + + Firebolt::Parameters::AppInitialization appInitialization = Firebolt::IFireboltAccessor::Instance().ParametersInterface().initialization(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve appInitialization from Parameters.initialization() method"; + EXPECT_EQ(appInitialization.us_privacy, expectedValues["us_privacy"]); + EXPECT_EQ(appInitialization.lmt, expectedValues["lmt"]); + + ASSERT_TRUE(appInitialization.discovery.has_value()); + ASSERT_TRUE(appInitialization.discovery.value().navigateTo.has_value()); + + // Deserialize the actual navigateTo value (double-deserialization to handle extra escaping) + std::string actualNavigateToStr = appInitialization.discovery.value().navigateTo.value(); + nlohmann::json actualNavigateToJson = nlohmann::json::parse(nlohmann::json::parse(actualNavigateToStr).get()); + + // Convert expectedValues["discovery"]["navigateTo"] to a serialized JSON string + nlohmann::json expectedNavigateTo = expectedValues["discovery"]["navigateTo"]; + + EXPECT_EQ(actualNavigateToJson, expectedNavigateTo); +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/profileTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/profileTest.cpp new file mode 100644 index 000000000..7e5815612 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/profileTest.cpp @@ -0,0 +1,52 @@ +#include "unit.h" +#include "common/types.h" + +class ProfileTest : 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(ProfileTest, ApproveContentRating) +{ + + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Profile.approveContentRating")); + + bool status = Firebolt::IFireboltAccessor::Instance().ProfileInterface().approveContentRating(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Profile.approveContentRating() method"; + EXPECT_EQ(status, expectedValues); +} + +TEST_F(ProfileTest, ApprovePurchase) +{ + + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Profile.approvePurchase")); + + bool status = Firebolt::IFireboltAccessor::Instance().ProfileInterface().approvePurchase(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve status from Profile.approvePurchase() method"; + EXPECT_EQ(status, expectedValues); +} + +TEST_F(ProfileTest, Flags) +{ + + nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Profile.flags")); + + Firebolt::Types::FlatMap flag = Firebolt::IFireboltAccessor::Instance().ProfileInterface().flags(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve flag from Profile.flags() method"; + EXPECT_EQ(flag["userExperience"], expectedValues["userExperience"]); +} \ No newline at end of file diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/secondscreenTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/secondscreenTest.cpp new file mode 100644 index 000000000..43c9377f2 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/secondscreenTest.cpp @@ -0,0 +1,58 @@ +#include "unit.h" + +class SecondScreenTest : 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(SecondScreenTest, FriendlyName) +{ + nlohmann::json_abi_v3_11_3::json expectedValue = nlohmann::json::parse(jsonEngine->get_value("SecondScreen.friendlyName")); + + auto actualValue = Firebolt::IFireboltAccessor::Instance().SecondScreenInterface().friendlyName(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve friendlyName from Secondscreen.friendlyName() method"; + EXPECT_EQ(actualValue, expectedValue); +} + +TEST_F(SecondScreenTest, Device) +{ + nlohmann::json_abi_v3_11_3::json expectedValue = nlohmann::json::parse(jsonEngine->get_value("SecondScreen.device")); + + auto actualValue = Firebolt::IFireboltAccessor::Instance().SecondScreenInterface().device(std::nullopt, &error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve device from Secondscreen.device() method"; + EXPECT_EQ(actualValue, expectedValue); +} + +TEST_F(SecondScreenTest, Protocols) +{ + std::string jsonString = jsonEngine->get_value("SecondScreen.protocols"); + + // Check if the JSON string is empty + ASSERT_FALSE(jsonString.empty()) << "JSON string for Secondscreen.protocols is empty"; + + nlohmann::json expectedValues; + try { + expectedValues = nlohmann::json::parse(jsonString); + } catch (const nlohmann::json::parse_error& e) { + FAIL() << "Failed to parse JSON string: " << e.what(); + } + + Firebolt::Types::BooleanMap actualValues = Firebolt::IFireboltAccessor::Instance().SecondScreenInterface().protocols(&error); + + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve protocols from Secondscreen.protocols() method"; + EXPECT_EQ(actualValues, expectedValues); +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/securestorageTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/securestorageTest.cpp new file mode 100644 index 000000000..8fdc05518 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/securestorageTest.cpp @@ -0,0 +1,61 @@ +#include "unit.h" + +class SecureStorageTest : public ::testing::Test +{ +protected: + JsonEngine *jsonEngine; + Firebolt::Error error = Firebolt::Error::None; + + void SetUp() override + { + jsonEngine = new JsonEngine(); + } + + void TearDown() override + { + delete jsonEngine; + } +}; + +// Check enum issue with test app verse actual transport +TEST_F(SecureStorageTest, Get) +{ + auto expectedValue = jsonEngine->get_value("SecureStorage.get"); + + Firebolt::SecureStorage::StorageScope scope = Firebolt::SecureStorage::StorageScope::DEVICE; + + std::string actualValue = Firebolt::IFireboltAccessor::Instance().SecureStorageInterface().get(scope, "authRefreshToken", &error); + + EXPECT_EQ(expectedValue, actualValue); +} + +TEST_F(SecureStorageTest, Set) +{ + // Call setter to set the value + Firebolt::SecureStorage::StorageScope scope = Firebolt::SecureStorage::StorageScope::DEVICE; + std::string expectedValue = "123456"; + Firebolt::SecureStorage::StorageOptions options; + options.ttl = 6.0; + Firebolt::IFireboltAccessor::Instance().SecureStorageInterface().set(scope, "authRefreshToken", expectedValue, options, &error); + + // Check if there was an error during the set operation + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to set value in SecureStorage.set() method"; +} + +TEST_F(SecureStorageTest, Remove) +{ + Firebolt::SecureStorage::StorageScope scope = Firebolt::SecureStorage::StorageScope::DEVICE; + Firebolt::IFireboltAccessor::Instance().SecureStorageInterface().remove(scope, "authRefreshToken", &error); + + // Check if there was an error during the remove operation + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to remove value in SecureStorage.remove() method"; +} + +TEST_F(SecureStorageTest, Clear) +{ + Firebolt::SecureStorage::StorageScope scope = Firebolt::SecureStorage::StorageScope::DEVICE; + Firebolt::IFireboltAccessor::Instance().SecureStorageInterface().clear(scope, &error); + + // Check if there was an error during the clear operation + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to clear value in SecureStorage.clear() method"; +} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/unit.h b/src/sdks/core/src/cpp/sdk/cpptest/unit/unit.h new file mode 100644 index 000000000..281096f15 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/unit.h @@ -0,0 +1,5 @@ +#pragma once + +#include "gtest/gtest.h" +#include "../CoreSDKTest.h" +#include "json_engine.h" \ No newline at end of file