From 21bb70ce62b3f67aa94925f34a3a1bce8a604af9 Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Thu, 3 Oct 2024 14:46:54 -0400 Subject: [PATCH] test(core): SecondScreen unit tests --- .../cpp/sdk/cpptest/unit/secondscreenTest.cpp | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/sdks/core/src/cpp/sdk/cpptest/unit/secondscreenTest.cpp 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); +}