Skip to content

Commit

Permalink
CPPSDK: test case added for core
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Nov 9, 2023
1 parent abb7565 commit 9a1e3bb
Show file tree
Hide file tree
Showing 16 changed files with 745 additions and 984 deletions.
3 changes: 2 additions & 1 deletion src/sdks/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"validate": "npx firebolt-openrpc validate --input ./dist/firebolt-core-open-rpc.json",
"sdk": "npx firebolt-openrpc sdk --input ./dist/firebolt-core-open-rpc.json --template ./src/js --output ./build/javascript/src --static-module Platform",
"native": "npx firebolt-openrpc sdk --input ./dist/firebolt-core-open-rpc.json --template ./src/cpp --output ./build/c/src --static-module Platform --language ../../../node_modules/@firebolt-js/openrpc/languages/c",
"cpp": "npx firebolt-openrpc sdk --input ./dist/firebolt-core-open-rpc.json --template ./src/cpp --output ./build/cpp/src --static-module Platform --language ../../../node_modules/@firebolt-js/openrpc/languages/cpp",
"compile": "cd ../../.. && npm run compile",
"slice": "npx firebolt-openrpc slice -i ../../../dist/firebolt-open-rpc.json --sdk ./sdk.config.json -o ./dist/firebolt-core-open-rpc.json",
"docs": "npx firebolt-openrpc docs --input ./dist/firebolt-core-open-rpc.json --output build/docs/markdown --as-path",
Expand Down Expand Up @@ -48,4 +49,4 @@
"sdk"
],
"license": "Apache-2.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Comcast Cable Communications Management, LLC
# Copyright 2023 Comcast Cable Communications Corement, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,7 +46,7 @@ set(TESTAPP TestFireboltCore)

message("Setup ${TESTAPP}")

add_executable(${TESTAPP} main.c)
add_executable(${TESTAPP} CoreSDKTest.cpp Main.cpp)

target_link_libraries(${TESTAPP}
PRIVATE
Expand All @@ -61,6 +61,11 @@ target_include_directories(${TESTAPP}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/../>
)

set_target_properties(${TESTAPP} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
)

add_custom_command(
TARGET ${TESTAPP}
POST_BUILD
Expand Down
338 changes: 338 additions & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
/*
* Copyright 2023 Comcast Cable Communications Corement, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <unistd.h>
#include <iomanip>
#include "CoreSDKTest.h"

using namespace std;
bool CoreSDKTest::_connected;
CoreSDKTest::OnDeviceNameChangedNotification CoreSDKTest::_deviceNameChangedNotification;
CoreSDKTest::OnAudioChangedNotification CoreSDKTest::_audioChangedNotification;
CoreSDKTest::OnScreenResolutionChangedNotification CoreSDKTest::_screenResolutionChangedNotification;
CoreSDKTest::OnClosedCaptionsSettingsChangedNotification CoreSDKTest::_closedCaptionsSettingsChangedNotification;
CoreSDKTest::OnPreferredAudioLanguagesChangedNotification CoreSDKTest::_preferredAudioLanguagesChangedNotification;
void CoreSDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error)
{
cout << "Change in connection: connected: " << connected << " error: " << static_cast<int>(error) << endl;
_connected = connected;
}

void CoreSDKTest::CreateFireboltInstance()
{
const std::string config = "{\
\"waitTime\": 1000,\
\"logLevel\": \"Info\",\
\"workerPool\":{\
\"queueSize\": 8,\
\"threadCount\": 3\
},\
\"wsUrl\": \"ws://127.0.0.1:9998\"\
}";

_connected = false;
Firebolt::IFireboltAccessor::Instance().Initialize(config);
Firebolt::IFireboltAccessor::Instance().Connect(ConnectionChanged);
}

void CoreSDKTest::DestroyFireboltInstance()
{
Firebolt::IFireboltAccessor::Instance().Disconnect();
Firebolt::IFireboltAccessor::Instance().Deinitialize();
Firebolt::IFireboltAccessor::Instance().Dispose();
}

bool CoreSDKTest::WaitOnConnectionReady()
{
uint32_t waiting = 10000;
static constexpr uint32_t SLEEPSLOT_TIME = 100;

// Right, a wait till connection is closed is requested..
while ((waiting > 0) && (_connected == false)) {

uint32_t sleepSlot = (waiting > SLEEPSLOT_TIME ? SLEEPSLOT_TIME : waiting);
// Right, lets sleep in slices of 100 ms
usleep(sleepSlot);
waiting -= sleepSlot;
}
return _connected;
}

void CoreSDKTest::GetDeviceName()
{
Firebolt::Error error = Firebolt::Error::None;
const std::string name = Firebolt::IFireboltAccessor::Instance().DeviceInterface().name(&error);

if (error == Firebolt::Error::None) {
cout << "Get Device Name = " << name.c_str() << endl;
} else {
cout << "Get Device Name status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::OnDeviceNameChangedNotification::onDeviceNameChanged( const std::string& name)
{
cout << "Name changed, new name --> " << name << endl;
}

void CoreSDKTest::SubscribeDeviceNameChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().DeviceInterface().subscribe(_deviceNameChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe Device NameChange is success" << endl;
} else {
cout << "Subscribe Device NameChange status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::UnsubscribeDeviceNameChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().DeviceInterface().unsubscribe(_deviceNameChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe Device NameChange is success" << endl;
} else {
cout << "Unsubscribe Device NameChange status = " << static_cast<int>(error) << endl;
}
}

void PrintDeviceAudioProfiles( const Firebolt::Device::AudioProfiles& audioProfiles )
{
cout << "Get Device AudioProfiles :-> " << endl;
for (auto& item : audioProfiles) {
cout << "Profile: " << static_cast<int>(item.first) << " status: " << item.second << endl;
}
}

void CoreSDKTest::GetDeviceAudio()
{
Firebolt::Error error = Firebolt::Error::None;
const Firebolt::Device::AudioProfiles audioProfiles = Firebolt::IFireboltAccessor::Instance().DeviceInterface().audio(&error);
if (error == Firebolt::Error::None) {
PrintDeviceAudioProfiles(audioProfiles);
} else {
cout << "Get Device AudioProfiles status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::OnAudioChangedNotification::onAudioChanged( const Firebolt::Device::AudioProfiles& audioProfiles )
{
cout << "onAudioChanged event " << endl;
PrintDeviceAudioProfiles(audioProfiles);
}

void CoreSDKTest::SubscribeDeviceAudioChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().DeviceInterface().subscribe(_audioChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe Device Audio Change is success" << endl;
} else {
cout << "Subscribe Device Audio Change status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::UnsubscribeDeviceAudioChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().DeviceInterface().unsubscribe(_audioChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe Device Audio Change is success" << endl;
} else {
cout << "Unsubscribe Device Audio Change status = " << static_cast<int>(error) << endl;
}
}

void PrintDeviceScreenResolution( const Firebolt::Device::Resolution& resolution )
{
cout << "Get Device ScreenResolution :-> " << endl;
cout << resolution.first << " X " << resolution.second << endl;
}

void CoreSDKTest::GetDeviceScreenResolution()
{
Firebolt::Error error = Firebolt::Error::None;
const Firebolt::Device::Resolution resolution = Firebolt::IFireboltAccessor::Instance().DeviceInterface().screenResolution(&error);
if (error == Firebolt::Error::None) {
PrintDeviceScreenResolution(resolution);
} else {
cout << "Get Device ScreenResolution status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::OnScreenResolutionChangedNotification::onScreenResolutionChanged( const Firebolt::Device::Resolution& resolution )
{
cout << "onScreenResolutionChanged event " << endl;
PrintDeviceScreenResolution(resolution);
}

void CoreSDKTest::SubscribeDeviceScreenResolutionChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().DeviceInterface().subscribe(_screenResolutionChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe Device ScreenResolution Change is success" << endl;
} else {
cout << "Subscribe Device ScreenResolution Change status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::UnsubscribeDeviceScreenResolutionChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().DeviceInterface().unsubscribe(_screenResolutionChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe Device ScreenResolution Change is success" << endl;
} else {
cout << "Unsubscribe Device ScreenResolution Change status = " << static_cast<int>(error) << endl;
}
}

void PrintClosedCaptionsSettings( const Firebolt::Accessibility::ClosedCaptionsSettings& closedCaptionsSettings)
{
cout << "Get Accessibility ClosedCaptionsSettings :-> " << endl;
cout << "ClosedCaptionsSettings::Enabled : " << closedCaptionsSettings.enabled << endl;
if (closedCaptionsSettings.styles.fontFamily.has_value()) {
cout << "ClosedCaptionsSettings::Styles::FontFamily : " << static_cast<int>(closedCaptionsSettings.styles.fontFamily.value()) << endl;
}
if (closedCaptionsSettings.styles.fontSize.has_value()) {
cout << "ClosedCaptionsSettings::Styles::FontSize : " << setprecision(3) << closedCaptionsSettings.styles.fontSize.value() << endl;
}
if (closedCaptionsSettings.styles.fontColor.has_value()) {
cout << "ClosedCaptionsSettings::Styles::FontColor : " << closedCaptionsSettings.styles.fontColor.value() << endl;
}
if (closedCaptionsSettings.styles.fontEdge.has_value()) {
cout << "ClosedCaptionsSettings::Styles::FontEdge : " << static_cast<int>(closedCaptionsSettings.styles.fontEdge.value()) << endl;
}
if (closedCaptionsSettings.styles.fontEdgeColor.has_value()) {
cout << "ClosedCaptionsSettings::Styles::FontEdgeColor : " << closedCaptionsSettings.styles.fontEdgeColor.value() << endl;
}
if (closedCaptionsSettings.styles.fontOpacity.has_value()) {
cout << "ClosedCaptionsSettings::Styles::FontOpacity : " << closedCaptionsSettings.styles.fontOpacity.value() << endl;
}
if (closedCaptionsSettings.styles.backgroundColor.has_value()) {
cout << "ClosedCaptionsSettings::Styles::BackgroundColor : " << closedCaptionsSettings.styles.backgroundColor.value() << endl;
}
if (closedCaptionsSettings.styles.backgroundOpacity.has_value()) {
cout << "ClosedCaptionsSettings::Styles::BackgroundOpacity : " << closedCaptionsSettings.styles.backgroundOpacity.value() << endl;
}
if (closedCaptionsSettings.styles.textAlign.has_value()) {
cout << "ClosedCaptionsSettings::Styles::TextAlign : " << closedCaptionsSettings.styles.textAlign.value() << endl;
}
if (closedCaptionsSettings.styles.textAlignVertical.has_value()) {
cout << "ClosedCaptionsSettings::Styles::TextAlignVertical : " << closedCaptionsSettings.styles.textAlignVertical.value() << endl;
}
if (closedCaptionsSettings.styles.windowColor.has_value()) {
cout << "ClosedCaptionsSettings::Styles::WindowColor : " << closedCaptionsSettings.styles.windowColor.value() << endl;
}
if (closedCaptionsSettings.styles.windowOpacity.has_value()) {
cout << "ClosedCaptionsSettings::Styles::WindowOpacity : " << closedCaptionsSettings.styles.windowOpacity.value() << endl;
}
cout << "ClosedCaptionsSettings::PreferredLanguages :";

for (auto index: closedCaptionsSettings.preferredLanguages.value()) {
cout << " " << index;
}
cout << endl;
}

void CoreSDKTest::GetAccessibilityClosedCaptionsSettings()
{
Firebolt::Error error = Firebolt::Error::None;
const Firebolt::Accessibility::ClosedCaptionsSettings closedCaptionsSettings = Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().closedCaptionsSettings(&error);
if (error == Firebolt::Error::None) {
PrintClosedCaptionsSettings(closedCaptionsSettings);
} else {
cout << "Get Accessibility ClosedCaptionsSettings status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::OnClosedCaptionsSettingsChangedNotification::onClosedCaptionsSettingsChanged( const Firebolt::Accessibility::ClosedCaptionsSettings& closedCaptionsSettings )
{
cout << "ClosedCaptionsSettingsChanged event " << endl;
PrintClosedCaptionsSettings(closedCaptionsSettings);
}

void CoreSDKTest::SubscribeAccessibilityClosedCaptionsSettingsChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().subscribe(_closedCaptionsSettingsChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe Accessibilty ClosedCaptionSettings Change is success" << endl;
} else {
cout << "Subscribe Accessibilty ClosedCaptionSettings Change status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::UnsubscribeAccessibilityClosedCaptionsSettingsChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().AccessibilityInterface().unsubscribe(_closedCaptionsSettingsChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe Accessibilty ClosedCaptionSettings Change is success" << endl;
} else {
cout << "Unsubscribe Accessibilty ClosedCaptionSettings Change status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::GetLocalizationPreferredAudioLanguages()
{
Firebolt::Error error = Firebolt::Error::None;
const std::vector<std::string> languages = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().preferredAudioLanguages(&error);

if (error == Firebolt::Error::None) {
cout << "Get Localization PreferredAudioLanguages : " << endl;
for (auto language: languages) {
cout << "----- > " <<language << endl;
}
} else {
cout << "Get Localization PreferredAudioLanguages status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::OnPreferredAudioLanguagesChangedNotification::onPreferredAudioLanguagesChanged( const std::vector<std::string>& languages)
{
cout << "PreferredAudioLanguages Changed, new languages --> " << endl;
for (auto language : languages) {
cout << " -> " << language << endl;
}
}

void CoreSDKTest::SubscribeLocalizationPreferredAudioLanguagesChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().LocalizationInterface().subscribe(_preferredAudioLanguagesChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Subscribe Localization PreferredAudioLanguagesChange is success" << endl;
} else {
cout << "Subscribe Localization PreferredAudioLanguagesChange status = " << static_cast<int>(error) << endl;
}
}

void CoreSDKTest::UnsubscribeLocalizationPreferredAudioLanguagesChanged()
{
Firebolt::Error error = Firebolt::Error::None;
Firebolt::IFireboltAccessor::Instance().LocalizationInterface().unsubscribe(_preferredAudioLanguagesChangedNotification, &error);
if (error == Firebolt::Error::None) {
cout << "Unsubscribe Localization PreferredAudioLanguagesChange is success" << endl;
} else {
cout << "Unsubscribe Localization PreferredAudioLanguagesChange status = " << static_cast<int>(error) << endl;
}
}

Loading

0 comments on commit 9a1e3bb

Please sign in to comment.