From a3a40bc992936087ca822ae5ec02e3c42877f7a3 Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Mon, 30 Sep 2024 13:04:34 -0400 Subject: [PATCH] Correct unit tests that were not compiling correctly --- .../core/src/cpp/sdk/cpptest/CMakeLists.txt | 2 - .../sdk/cpptest/unit/accessibilityTest.cpp | 102 ++++++++++++------ .../cpp/sdk/cpptest/unit/advertisingTest.cpp | 11 +- .../src/cpp/sdk/cpptest/unit/deviceTest.cpp | 94 +++++++--------- 4 files changed, 120 insertions(+), 89 deletions(-) diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt b/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt index 611c07443..4b1b6a8f6 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt +++ b/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt @@ -83,8 +83,6 @@ if(ENABLE_UNIT_TESTS) message("Setup ${UNIT_TESTS_APP}") - add_definitions(-DUNIT_TEST) - file(GLOB UNIT_TESTS "unit/*") add_executable(${UNIT_TESTS_APP} diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp index 04f010ea7..f1cfa519c 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp @@ -82,29 +82,50 @@ TEST_F(AccessibilityTest, ClosedCaptions) { nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Accessibility.closedCaptions")); - auto closedCaptions = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().closedCaptions(&error); + 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"]); - EXPECT_EQ(closedCaptions.styles.backgroundColor.value(), expectedValues["styles"]["backgroundColor"]); - EXPECT_EQ(closedCaptions.styles.backgroundOpacity.value(), expectedValues["styles"]["backgroundOpacity"]); - EXPECT_EQ(closedCaptions.styles.fontColor.value(), expectedValues["styles"]["fontColor"]); + if (closedCaptions.styles.has_value()) { + const auto& styles = closedCaptions.styles.value(); - if (closedCaptions.styles.fontEdge.has_value()) - EXPECT_EQ(fontEdgeToString(closedCaptions.styles.fontEdge.value()), expectedValues["styles"]["fontEdge"]); + if (styles.backgroundColor.has_value()) + EXPECT_EQ(styles.backgroundColor.value(), expectedValues["styles"]["backgroundColor"]); - EXPECT_EQ(closedCaptions.styles.fontEdgeColor.value(), expectedValues["styles"]["fontEdgeColor"]); + if (styles.backgroundOpacity.has_value()) + EXPECT_EQ(styles.backgroundOpacity.value(), expectedValues["styles"]["backgroundOpacity"]); - if (closedCaptions.styles.fontFamily.has_value()) - EXPECT_EQ(fontFamilyToString(closedCaptions.styles.fontFamily.value()), expectedValues["styles"]["fontFamily"]); + if (styles.fontColor.has_value()) + EXPECT_EQ(styles.fontColor.value(), expectedValues["styles"]["fontColor"]); - EXPECT_EQ(closedCaptions.styles.fontOpacity.value(), expectedValues["styles"]["fontOpacity"]); - EXPECT_EQ(closedCaptions.styles.fontSize.value(), expectedValues["styles"]["fontSize"]); - EXPECT_EQ(closedCaptions.styles.textAlign.value(), expectedValues["styles"]["textAlign"]); - EXPECT_EQ(closedCaptions.styles.textAlignVertical.value(), expectedValues["styles"]["textAlignVertical"]); - EXPECT_EQ(closedCaptions.styles.windowColor.value(), expectedValues["styles"]["windowColor"]); - EXPECT_EQ(closedCaptions.styles.windowOpacity.value(), expectedValues["styles"]["windowOpacity"]); + 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]); @@ -114,30 +135,51 @@ TEST_F(AccessibilityTest, ClosedCaptionsSettings) { nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Accessibility.closedCaptionsSettings")); - auto closedCaptionSettings = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().closedCaptionsSettings(&error); + 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"]); - EXPECT_EQ(closedCaptionSettings.styles.backgroundColor.value(), expectedValues["styles"]["backgroundColor"]); - EXPECT_EQ(closedCaptionSettings.styles.backgroundOpacity.value(), expectedValues["styles"]["backgroundOpacity"]); - EXPECT_EQ(closedCaptionSettings.styles.fontColor.value(), expectedValues["styles"]["fontColor"]); + if (closedCaptionSettings.styles.has_value()) { + const auto& styles = closedCaptionSettings.styles.value(); - if (closedCaptionSettings.styles.fontEdge.has_value()) - EXPECT_EQ(fontEdgeToString(closedCaptionSettings.styles.fontEdge.value()), expectedValues["styles"]["fontEdge"]); + if (styles.backgroundColor.has_value()) + EXPECT_EQ(styles.backgroundColor.value(), expectedValues["styles"]["backgroundColor"]); - EXPECT_EQ(closedCaptionSettings.styles.fontEdgeColor.value(), expectedValues["styles"]["fontEdgeColor"]); + if (styles.backgroundOpacity.has_value()) + EXPECT_EQ(styles.backgroundOpacity.value(), expectedValues["styles"]["backgroundOpacity"]); - if (closedCaptionSettings.styles.fontFamily.has_value()) - EXPECT_EQ(fontFamilyToString(closedCaptionSettings.styles.fontFamily.value()), expectedValues["styles"]["fontFamily"]); + if (styles.fontColor.has_value()) + EXPECT_EQ(styles.fontColor.value(), expectedValues["styles"]["fontColor"]); - EXPECT_EQ(closedCaptionSettings.styles.fontOpacity.value(), expectedValues["styles"]["fontOpacity"]); - EXPECT_EQ(closedCaptionSettings.styles.fontSize.value(), expectedValues["styles"]["fontSize"]); - EXPECT_EQ(closedCaptionSettings.styles.textAlign.value(), expectedValues["styles"]["textAlign"]); - EXPECT_EQ(closedCaptionSettings.styles.textAlignVertical.value(), expectedValues["styles"]["textAlignVertical"]); - EXPECT_EQ(closedCaptionSettings.styles.windowColor.value(), expectedValues["styles"]["windowColor"]); - EXPECT_EQ(closedCaptionSettings.styles.windowOpacity.value(), expectedValues["styles"]["windowOpacity"]); + 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]); } diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/advertisingTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/advertisingTest.cpp index f58ac3c07..4b4ab631b 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/unit/advertisingTest.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/advertisingTest.cpp @@ -66,19 +66,24 @@ TEST_F(AdvertisingTest, Policy) 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::AdvertisingId actualValues = Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().advertisingId(options, &error); - + 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(actualValues.lmt, expectedValues["lmt"]); + EXPECT_EQ(lmtToString(actualValues.lmt), expectedValues["lmt"]); } TEST_F(AdvertisingTest, DeviceAttributes) diff --git a/src/sdks/core/src/cpp/sdk/cpptest/unit/deviceTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/unit/deviceTest.cpp index ec5b39225..85107fd33 100644 --- a/src/sdks/core/src/cpp/sdk/cpptest/unit/deviceTest.cpp +++ b/src/sdks/core/src/cpp/sdk/cpptest/unit/deviceTest.cpp @@ -107,6 +107,7 @@ TEST_F(DeviceTest, TestDeviceMake) 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")); @@ -118,14 +119,21 @@ TEST_F(DeviceTest, Hdcp) } // Getting the actual value from the DeviceInterface - Firebolt::Types::BooleanMap hdcp = Firebolt::IFireboltAccessor::Instance().DeviceInterface().hdcp(&error); + Firebolt::Device::HDCPVersionMap hdcpMap = Firebolt::IFireboltAccessor::Instance().DeviceInterface().hdcp(&error); EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve hdcp from Device.hdcp() method"; - EXPECT_EQ(hdcp, expectedValues); + + // 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")); @@ -137,58 +145,49 @@ TEST_F(DeviceTest, Hdr) } // Getting the actual value from the DeviceInterface - Firebolt::Types::BooleanMap hdr = Firebolt::IFireboltAccessor::Instance().DeviceInterface().hdr(&error); + Firebolt::Device::HDRFormatMap hdrMap = Firebolt::IFireboltAccessor::Instance().DeviceInterface().hdr(&error); EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve hdr from Device.hdr() method"; - EXPECT_EQ(hdr, expectedValues); -} -std::string AudioProfileToString(Firebolt::Types::AudioProfile profile) -{ - switch (profile) - { - case Firebolt::Types::AudioProfile::STEREO: - return "stereo"; - case Firebolt::Types::AudioProfile::DOLBY_DIGITAL_5_1: - return "dolbyDigital5.1+"; - case Firebolt::Types::AudioProfile::DOLBY_ATMOS: - return "dolbyAtmos"; - default: - return "dolbyDigital5.1"; - } + // 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) -{ - - // Parse expected JSON values - nlohmann::json expectedJson = nlohmann::json::parse(jsonEngine->get_value("Device.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"; - // Convert actualValue (AudioProfiles map) to JSON - nlohmann::json actualJson; - for (const auto &item : audio) - { - std::string profileKey = AudioProfileToString(item.first); // Replace this with the correct conversion function - actualJson[profileKey] = item.second; - } - - EXPECT_EQ(actualJson, expectedJson); + 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::NetworkInfo expectedValues; + 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::NetworkInfo network = Firebolt::IFireboltAccessor::Instance().DeviceInterface().network(&error); + 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"; @@ -217,20 +216,13 @@ TEST_F(DeviceTest, ScreenResolution) 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 DeviceInterface - Firebolt::Device::Resolution screenResolution = Firebolt::IFireboltAccessor::Instance().DeviceInterface().screenResolution(&error); - - // Convert actual value to JSON - nlohmann::json actualJson = {screenResolution.first, screenResolution.second}; + 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 actualResolution from Device.screenResolution() method"; - EXPECT_EQ(actualJson, expectedJson); + EXPECT_EQ(error, Firebolt::Error::None) << "Failed to retrieve screenResolution from Device.screenResolution() method"; + EXPECT_EQ(screenResolution, expectedJson.get()); } TEST_F(DeviceTest, VideoResolution) @@ -254,20 +246,14 @@ TEST_F(DeviceTest, VideoResolution) 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 DeviceInterface - Firebolt::Device::Resolution videoResolution = Firebolt::IFireboltAccessor::Instance().DeviceInterface().videoResolution(&error); - - // Convert actual value to JSON - nlohmann::json actualJson = {videoResolution.first, videoResolution.second}; + 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(actualJson, expectedJson); + EXPECT_EQ(videoResolution, expectedJson.get()); } TEST_F(DeviceTest, Name)