Skip to content

Commit

Permalink
Native sdk unit tests part 1 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
parag-pv committed Sep 16, 2024
1 parent beda574 commit 8ef0203
Show file tree
Hide file tree
Showing 20 changed files with 2,130 additions and 4 deletions.
47 changes: 45 additions & 2 deletions src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,64 @@ find_package(${NAMESPACE}Core CONFIG REQUIRED)
find_package(Firebolt CONFIG REQUIRED)
find_package(${FIREBOLT_NAMESPACE}SDK CONFIG REQUIRED)

# Manually add the library
add_library(nlohmann_json_schema_validator SHARED IMPORTED)
set_target_properties(nlohmann_json_schema_validator PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../build/build/_deps/nlohmann_json_schema_validator-src/libnlohmann_json_schema_validator.a
)
add_library(gmock_main SHARED IMPORTED)
set_target_properties(gmock_main PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../build/lib/libgmock.a
)
add_library(gtest SHARED IMPORTED)
set_target_properties(gtest PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../build/lib/libgtest.a
)

add_library(gtest_main SHARED IMPORTED)
set_target_properties(gtest_main PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../build/lib/libgtest_main.a
)

include_directories(${CMAKE_SOURCE_DIR}/build/_deps/json-src/include)

set(TESTAPP TestFireboltCore)

message("Setup ${TESTAPP}")

add_executable(${TESTAPP} CoreSDKTest.cpp Main.cpp)
if(UNIT_TEST STREQUAL "ON")
add_definitions(-DUNIT_TEST)

file(GLOB UNIT_TESTS "unit/advertisingTest.cpp")

add_executable(${TESTAPP}
CoreSDKTest.cpp
Unit.cpp
${UNIT_TESTS}
)
else()
add_executable(${TESTAPP}
CoreSDKTest.cpp
Main.cpp
)
endif()

target_link_libraries(${TESTAPP}
PRIVATE
${NAMESPACE}Core::${NAMESPACE}Core
${FIREBOLT_NAMESPACE}SDK::${FIREBOLT_NAMESPACE}SDK
nlohmann_json_schema_validator
gmock_main
gtest_main
gtest
)

target_include_directories(${TESTAPP}
PRIVATE
$<BUILD_INTERFACE:${FIREBOLT_PATH}/usr/include/${FIREBOLT_NAMESPACE}SDK>
$<BUILD_INTERFACE:${FIREBOLT_PATH}/usr/include/>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/../build/_deps/nlohmann_json-src/include/>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/../build/_deps/nlohmann_json_schema_validator-src/src/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/../>
)
Expand All @@ -78,4 +121,4 @@ add_custom_command(
COMMENT "=================== Installing TestApp ======================"
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
)
)
9 changes: 9 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,9 @@
#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();
}
5 changes: 3 additions & 2 deletions src/sdks/core/src/cpp/sdk/cpptest/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ TestPath="."
FireboltPath=${FIREBOLT_PATH}
SysrootPath=${SYSROOT_PATH}
ClearBuild="N"
while getopts t:s:f:ch flag
while getopts t:s:f:c:uh flag
do
case "${flag}" in
t) TestPath="${OPTARG}";;
s) SysrootPath="${OPTARG}";;
f) FireboltPath="${OPTARG}";;
c) ClearBuild="Y";;
u) UnitTest="ON";;
h) usage && exit 1;;
esac
done
Expand All @@ -36,6 +37,6 @@ echo "TestPath"
echo "${TestPath}"
echo "FireboltPath"
echo ${FireboltPath}
cmake -B${TestPath}/build -S${TestPath} -DSYSROOT_PATH=${SysrootPath} -DFIREBOLT_PATH=${FireboltPath}
cmake -B${TestPath}/build -S${TestPath} -DSYSROOT_PATH=${SysrootPath} -DFIREBOLT_PATH=${FireboltPath} -DUNIT_TEST=${UnitTest}
# -DPOLYMORPHICS_METHODS=ON // Enable this to test
cmake --build ${TestPath}/build
186 changes: 186 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,186 @@
#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"));

auto closedCaptionSettings = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().closedCaptions(&error);

EXPECT_EQ(error, Firebolt::Error::None);
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, 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);
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 voiceGuidanceSettings = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().voiceGuidance(&error);

EXPECT_EQ(error, Firebolt::Error::None);

EXPECT_EQ(voiceGuidanceSettings.enabled, expectedValues["enabled"]);
EXPECT_EQ(voiceGuidanceSettings.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);

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

EXPECT_EQ(audioDescriptionSettings.enabled, expectedValues["enabled"]);
}


// TEST_F(AccessibilityTest, onClosedCaptionsSettingsChanged)
// {
// Firebolt::Error error = Firebolt::Error::None;
// auto actual_value = jsonEngine->get_value("Accessibility.onClosedCaptionsSettingsChanged");
// actual_value = actual_value.substr(1, actual_value.length() - 2);
// auto value = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().onClosedCaptionsSettingsChanged(&error);
// EXPECT_EQ(error, Firebolt::Error::None);
// EXPECT_EQ(value, actual_value);
// }


// TEST_F(AccessibilityTest, onVoiceGuidanceSettingsChanged)
// {
// Firebolt::Error error = Firebolt::Error::None;
// auto actual_value = jsonEngine->get_value("Accessibility.onVoiceGuidanceSettingsChanged");
// actual_value = actual_value.substr(1, actual_value.length() - 2);
// auto value = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().onVoiceGuidanceSettingsChanged(&error);
// EXPECT_EQ(error, Firebolt::Error::None);
// EXPECT_EQ(value, actual_value);
// }


// TEST_F(AccessibilityTest, onAudioDescriptionSettingsChanged)
// {
// Firebolt::Error error = Firebolt::Error::None;
// auto actual_value = jsonEngine->get_value("Accessibility.onAudioDescriptionSettingsChanged");
// actual_value = actual_value.substr(1, actual_value.length() - 2);
// auto value = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().onAudioDescriptionSettingsChanged(&error);
// EXPECT_EQ(error, Firebolt::Error::None);
// EXPECT_EQ(value, actual_value);
// }
40 changes: 40 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,40 @@
#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 value = Firebolt::IFireboltAccessor::Instance().AccountInterface().id(&error);

EXPECT_EQ(error, Firebolt::Error::None);
EXPECT_EQ(value, expectedValues);
}


TEST_F(AccountTest, Uid)
{
nlohmann::json_abi_v3_11_3::json expectedValues = nlohmann::json::parse(jsonEngine->get_value("Account.uid"));

std::string value = Firebolt::IFireboltAccessor::Instance().AccountInterface().uid(&error);

EXPECT_EQ(error, Firebolt::Error::None);
EXPECT_EQ(value, expectedValues);
}
Loading

0 comments on commit 8ef0203

Please sign in to comment.