Skip to content

Commit

Permalink
fix: Events C++ Unit Tests (#336)
Browse files Browse the repository at this point in the history
* test(manage): Unit test setup

* test(manage): Advertising events unit tests

* test(manage): AudioDescription events unit tests

* test(manage): ClosedCaption events unit tests

* test(manage): Device events unit tests

* test(manage): Discovery events unit tests

* test(manage): HdmiInput events unit tests

* test(manage): Localization events unit tests

* test(manage): Privacy events unit tests

* test(manage): VoiceGuidance events unit tests

---------

Co-authored-by: kschrief <[email protected]>
  • Loading branch information
AdityaKasar and kschrief authored Oct 28, 2024
1 parent 09b756b commit eb10d13
Show file tree
Hide file tree
Showing 12 changed files with 1,162 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/sdks/manage/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 TestFireboltManage)

Expand All @@ -52,13 +50,16 @@ 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/>
)

set_target_properties(${TESTAPP} PROPERTIES
Expand All @@ -73,3 +74,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 FireboltManageUnitTests)

message("Setup ${UNIT_TESTS_APP}")

file(GLOB UNIT_TESTS "unit/*")

add_executable(${UNIT_TESTS_APP}
ManageSDKTest.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/manage/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 "ManageSDKTest.h"

int main(int argc, char **argv)
{
std::string url = "ws://localhost:9998";
ManageSDKTest::CreateFireboltInstance(url);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
34 changes: 34 additions & 0 deletions src/sdks/manage/src/cpp/sdk/cpptest/unit/advertisingTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "unit.h"

class AdvertisingTest : public ::testing::Test
{
protected:
Firebolt::Error error = Firebolt::Error::None;
};


struct SkipRestrictionChanged : public Firebolt::Advertising::IAdvertising::IOnSkipRestrictionChangedNotification
{
void onSkipRestrictionChanged( const Firebolt::Advertising::SkipRestriction& ) override;
};

Firebolt::Advertising::SkipRestriction newSkipRestriction;
void SkipRestrictionChanged::onSkipRestrictionChanged(const Firebolt::Advertising::SkipRestriction& skipRestriction)
{
std::cout << "onSkipRestrictionChanged event fired";
}


TEST_F(AdvertisingTest, subscribeOnSkipRestrictionChanged)
{
SkipRestrictionChanged skipRestrictionChanged;
Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().subscribe(skipRestrictionChanged, &error);
EXPECT_EQ(error, Firebolt::Error::None) << "Error in subscribing to SkipRestrictionChanged";
}

TEST_F(AdvertisingTest, unsubscribeOnSkipRestrictionChanged)
{
SkipRestrictionChanged skipRestrictionChanged;
Firebolt::IFireboltAccessor::Instance().AdvertisingInterface().unsubscribe(skipRestrictionChanged, &error);
EXPECT_EQ(error, Firebolt::Error::None) << "Error in unsubscribing to SkipRestrictionChanged";
}
34 changes: 34 additions & 0 deletions src/sdks/manage/src/cpp/sdk/cpptest/unit/audioDescriptionsTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "unit.h"

class AudioDescriptionsTest : public ::testing::Test
{
protected:
Firebolt::Error error = Firebolt::Error::None;
};


struct EnabledChanged : public Firebolt::AudioDescriptions::IAudioDescriptions::IOnEnabledChangedNotification
{
void onEnabledChanged( const bool ) override;
};


void EnabledChanged::onEnabledChanged(const bool)
{
std::cout << "onAudioDescriptionEnabledChanged event fired";
}


TEST_F(AudioDescriptionsTest, subscribeonEnabledChanged)
{
EnabledChanged enabledChanged;
Firebolt::IFireboltAccessor::Instance().AudioDescriptionsInterface().subscribe(enabledChanged, &error);
EXPECT_EQ(error, Firebolt::Error::None) << "Error in subscribing to EnabledChanged";
}

TEST_F(AudioDescriptionsTest, unsubscribeonEnabledChanged)
{
EnabledChanged enabledChanged;
Firebolt::IFireboltAccessor::Instance().AudioDescriptionsInterface().unsubscribe(enabledChanged, &error);
EXPECT_EQ(error, Firebolt::Error::None) << "Error in unsubscribing to EnabledChanged";
}
Loading

0 comments on commit eb10d13

Please sign in to comment.