Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Native SDK unit tests part 1 #325

Open
wants to merge 11 commits into
base: next
Choose a base branch
from
41 changes: 36 additions & 5 deletions src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
$<BUILD_INTERFACE:${FIREBOLT_PATH}/usr/include/${FIREBOLT_NAMESPACE}SDK>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/../>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/>
)

if (POLYMORPHICS_REDUCER_METHODS)
Expand All @@ -79,3 +77,36 @@ 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}")

add_definitions(-DUNIT_TEST)

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
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/>
)

include(GoogleTest)
gtest_discover_tests(${UNIT_TESTS_APP})
endif()
10 changes: 10 additions & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/Unit.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
178 changes: 178 additions & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/unit/accessibilityTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#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)
kschrief marked this conversation as resolved.
Show resolved Hide resolved
{
nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Accessibility.closedCaptions"));

auto 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.fontEdge.has_value())
EXPECT_EQ(fontEdgeToString(closedCaptions.styles.fontEdge.value()), expectedValues["styles"]["fontEdge"]);

EXPECT_EQ(closedCaptions.styles.fontEdgeColor.value(), expectedValues["styles"]["fontEdgeColor"]);

if (closedCaptions.styles.fontFamily.has_value())
EXPECT_EQ(fontFamilyToString(closedCaptions.styles.fontFamily.value()), expectedValues["styles"]["fontFamily"]);

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"]);

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"));

auto 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.fontEdge.has_value())
EXPECT_EQ(fontEdgeToString(closedCaptionSettings.styles.fontEdge.value()), expectedValues["styles"]["fontEdge"]);

EXPECT_EQ(closedCaptionSettings.styles.fontEdgeColor.value(), expectedValues["styles"]["fontEdgeColor"]);

if (closedCaptionSettings.styles.fontFamily.has_value())
EXPECT_EQ(fontFamilyToString(closedCaptionSettings.styles.fontFamily.value()), expectedValues["styles"]["fontFamily"]);

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"]);

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"]);
}
38 changes: 38 additions & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/unit/accountTest.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
102 changes: 102 additions & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/unit/advertisingTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#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"]);
}

TEST_F(AdvertisingTest, Id)
{
nlohmann::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Advertising.advertisingId"));

std::optional<Firebolt::Advertising::AdvertisingIdOptions> options = std::nullopt; // Assuming options are not provided

Firebolt::Advertising::AdvertisingId 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"]);
}

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));
}
Loading
Loading