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..f1cfa519c --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp @@ -0,0 +1,220 @@ +#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"]); +} 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/lifecycleTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/lifecycleTest.cpp new file mode 100644 index 000000000..228220f02 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/lifecycleTest.cpp @@ -0,0 +1,27 @@ +#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"; +} 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..24458f282 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/parametersTest.cpp @@ -0,0 +1,42 @@ +#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_abi_v3_11_3::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"]); + + nlohmann::json_abi_v3_11_3::json navigateTo = nlohmann::json::parse(appInitialization.discovery.value().navigateTo.value()); + + EXPECT_EQ(navigateTo["action"], + expectedValues["discovery"]["navigateTo"]["action"]); + EXPECT_EQ(navigateTo["context"]["source"], + expectedValues["discovery"]["navigateTo"]["context"]["source"]); + EXPECT_EQ(navigateTo["data"]["entityId"], + expectedValues["discovery"]["navigateTo"]["data"]["entityId"]); + EXPECT_EQ(navigateTo["data"]["entityType"], + expectedValues["discovery"]["navigateTo"]["data"]["entityType"]); + EXPECT_EQ(navigateTo["data"]["programType"], + expectedValues["discovery"]["navigateTo"]["data"]["programType"]); +} \ No newline at end of file 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/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