From 732bcb2f747b78121a278eee13eec6b5eb5b66ab Mon Sep 17 00:00:00 2001 From: HaseenaSainul Date: Tue, 7 Nov 2023 11:40:47 -0500 Subject: [PATCH] CPPSDK: test case added for core --- src/sdks/core/package.json | 3 +- .../cpp/sdk/{ctest => cpptest}/CMakeLists.txt | 7 +- .../core/src/cpp/sdk/cpptest/CoreSDKTest.cpp | 338 +++++++++++++ .../core/src/cpp/sdk/cpptest/CoreSDKTest.h | 80 +++ src/sdks/core/src/cpp/sdk/cpptest/Main.cpp | 127 +++++ .../src/cpp/sdk/{ctest => cpptest}/build.sh | 0 src/sdks/core/src/cpp/sdk/ctest/main.c | 470 ------------------ src/sdks/core/src/cpp/sdk/test/CMakeLists.txt | 8 +- .../cpp/sdk/test/CoreSDKTestGeneratedCode.c | 330 ------------ .../cpp/sdk/test/CoreSDKTestGeneratedCode.cpp | 91 ++++ .../cpp/sdk/test/CoreSDKTestGeneratedCode.h | 35 +- .../cpp/sdk/test/CoreSDKTestStaticCode.cpp | 46 ++ ...CoreSDKTests.h => CoreSDKTestStaticCode.h} | 9 +- .../core/src/cpp/sdk/test/CoreSDKTests.cpp | 86 ---- src/sdks/core/src/cpp/sdk/test/Main.c | 57 --- .../sdk/test/{CoreSDKCTests.h => Main.cpp} | 25 +- 16 files changed, 729 insertions(+), 983 deletions(-) rename src/sdks/core/src/cpp/sdk/{ctest => cpptest}/CMakeLists.txt (94%) create mode 100644 src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp create mode 100644 src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h create mode 100644 src/sdks/core/src/cpp/sdk/cpptest/Main.cpp rename src/sdks/core/src/cpp/sdk/{ctest => cpptest}/build.sh (100%) delete mode 100644 src/sdks/core/src/cpp/sdk/ctest/main.c delete mode 100644 src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.c create mode 100644 src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.cpp create mode 100644 src/sdks/core/src/cpp/sdk/test/CoreSDKTestStaticCode.cpp rename src/sdks/core/src/cpp/sdk/test/{CoreSDKTests.h => CoreSDKTestStaticCode.h} (91%) delete mode 100644 src/sdks/core/src/cpp/sdk/test/CoreSDKTests.cpp delete mode 100644 src/sdks/core/src/cpp/sdk/test/Main.c rename src/sdks/core/src/cpp/sdk/test/{CoreSDKCTests.h => Main.cpp} (57%) diff --git a/src/sdks/core/package.json b/src/sdks/core/package.json index b5c39baab..12fcca321 100644 --- a/src/sdks/core/package.json +++ b/src/sdks/core/package.json @@ -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", @@ -48,4 +49,4 @@ "sdk" ], "license": "Apache-2.0" -} \ No newline at end of file +} diff --git a/src/sdks/core/src/cpp/sdk/ctest/CMakeLists.txt b/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt similarity index 94% rename from src/sdks/core/src/cpp/sdk/ctest/CMakeLists.txt rename to src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt index c87f15662..e1ea1425a 100644 --- a/src/sdks/core/src/cpp/sdk/ctest/CMakeLists.txt +++ b/src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt @@ -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 @@ -61,6 +61,11 @@ target_include_directories(${TESTAPP} $ ) +set_target_properties(${TESTAPP} PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED YES +) + add_custom_command( TARGET ${TESTAPP} POST_BUILD diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp new file mode 100644 index 000000000..b0b9834a1 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.cpp @@ -0,0 +1,338 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, 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 +#include +#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(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(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(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(error) << endl; + } +} + +void PrintDeviceAudioProfiles( const Firebolt::Device::AudioProfiles& audioProfiles ) +{ + cout << "Get Device AudioProfiles :-> " << endl; + for (auto& item : audioProfiles) { + cout << "Profile: " << static_cast(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(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(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(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(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(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(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(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(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(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(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(error) << endl; + } +} + +void CoreSDKTest::GetLocalizationPreferredAudioLanguages() +{ + Firebolt::Error error = Firebolt::Error::None; + const std::vector languages = Firebolt::IFireboltAccessor::Instance().LocalizationInterface().preferredAudioLanguages(&error); + + if (error == Firebolt::Error::None) { + cout << "Get Localization PreferredAudioLanguages : " << endl; + for (auto language: languages) { + cout << "----- > " < " << 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(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(error) << endl; + } +} + diff --git a/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h new file mode 100644 index 000000000..93f3f207a --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/CoreSDKTest.h @@ -0,0 +1,80 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, 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 + */ + +#pragma once + +#include +#include "firebolt.h" + +class CoreSDKTest { + + class OnDeviceNameChangedNotification : public Firebolt::Device::IDevice::IOnDeviceNameChangedNotification { + public: + void onDeviceNameChanged( const std::string& ) override; + }; + class OnAudioChangedNotification : public Firebolt::Device::IDevice::IOnAudioChangedNotification { + public: + void onAudioChanged( const Firebolt::Device::AudioProfiles& ) override; + }; + class OnScreenResolutionChangedNotification : public Firebolt::Device::IDevice::IOnScreenResolutionChangedNotification { + public: + void onScreenResolutionChanged( const Firebolt::Device::Resolution& ) override; + }; + class OnPreferredAudioLanguagesChangedNotification : public Firebolt::Localization::ILocalization::IOnPreferredAudioLanguagesChangedNotification { + public: + void onPreferredAudioLanguagesChanged( const std::vector& ) override; + }; + struct OnClosedCaptionsSettingsChangedNotification : public Firebolt::Accessibility::IAccessibility::IOnClosedCaptionsSettingsChangedNotification { + void onClosedCaptionsSettingsChanged( const Firebolt::Accessibility::ClosedCaptionsSettings& ) override; + }; + +public: + CoreSDKTest() = default; + virtual ~CoreSDKTest() = default; + + static void CreateFireboltInstance(); + static void DestroyFireboltInstance(); + static void TestCoreStaticSDK(); + static void GetDeviceName(); + static void SubscribeDeviceNameChanged(); + static void UnsubscribeDeviceNameChanged(); + static void GetDeviceAudio(); + static void SubscribeDeviceAudioChanged(); + static void UnsubscribeDeviceAudioChanged(); + static void GetDeviceScreenResolution(); + static void SubscribeDeviceScreenResolutionChanged(); + static void UnsubscribeDeviceScreenResolutionChanged(); + static void GetLocalizationPreferredAudioLanguages(); + static void SetLocalizationPreferredAudioLanguages(); + static void SubscribeLocalizationPreferredAudioLanguagesChanged(); + static void UnsubscribeLocalizationPreferredAudioLanguagesChanged(); + static void GetAccessibilityClosedCaptionsSettings(); + static void SubscribeAccessibilityClosedCaptionsSettingsChanged(); + static void UnsubscribeAccessibilityClosedCaptionsSettingsChanged(); + static bool WaitOnConnectionReady(); + +private: + static void ConnectionChanged(const bool, const Firebolt::Error); + static bool _connected; + static OnDeviceNameChangedNotification _deviceNameChangedNotification; + static OnAudioChangedNotification _audioChangedNotification; + static OnScreenResolutionChangedNotification _screenResolutionChangedNotification; + static OnPreferredAudioLanguagesChangedNotification _preferredAudioLanguagesChangedNotification; + static OnClosedCaptionsSettingsChangedNotification _closedCaptionsSettingsChangedNotification; +}; + diff --git a/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp new file mode 100644 index 000000000..a76ace55e --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/cpptest/Main.cpp @@ -0,0 +1,127 @@ + +#include "CoreSDKTest.h" + +void ShowMenu() +{ + printf("Enter\n" + "\tD : Get Device Name\n" + "\tN : Subscribe/Unsubscribe for Device Name Change\n" + "\tA : Get Device Audio Profiles\n" + "\tS : Subscribe/Unsubscribe for Device Audio Profiles Change\n" + "\tR : Get Device Screen Resolution\n" + "\tU : Subscribe/Unsubscribe for Device Screen Resolution\n" + "\tL : Get Localization Preferred AudioLanguages\n" + "\tP : Subscribe/Unsubscribe for Localization Preferred AudioLanguages Change\n" + "\tC : Get Closed Caption Settings\n" + "\tB : Subscribe/Unsubscribe for Closed Caption Settings\n" + "\tQ : Quit\n\n" + ); +} + +void ShowEventMenu() +{ + printf("Enter\n" + "\tS: Subscribe Event\n" + "\tU: Unsubscribe Event\n" + "\tQ : Quit\n"); +} + +#define HandleEventListener(Module, eventFuncName) \ +{ \ + int opt; \ + do { \ + getchar(); \ + ShowEventMenu(); \ + printf("Enter option : "); \ + opt = toupper(getchar()); \ + switch (opt) { \ + case 'S': { \ + CoreSDKTest::Subscribe##Module##eventFuncName(); \ + break; \ + } \ + case 'U': { \ + CoreSDKTest::Unsubscribe##Module##eventFuncName(); \ + break; \ + } \ + default: \ + break; \ + } \ + } while (opt != 'Q'); \ +} + +int main (int argc, char* argv[]) +{ + char* config = "{\ + \"waitTime\": 1000,\ + \"logLevel\": \"Info\",\ + \"workerPool\":{\ + \"queueSize\": 8,\ + \"threadCount\": 3\ + },\ + \"wsUrl\": \"ws://127.0.0.1:9998\"\ +}"; + + printf("Firebolt Core SDK Test\n"); + + CoreSDKTest::CreateFireboltInstance(); + int option; + if (CoreSDKTest::WaitOnConnectionReady() == true) { + do { + ShowMenu(); + printf("Enter option : "); + option = toupper(getchar()); + switch (option) { + case 'D': { + CoreSDKTest::GetDeviceName(); + break; + } + case 'N': { + HandleEventListener(Device, NameChanged) + break; + } + case 'A': { + CoreSDKTest::GetDeviceAudio(); + break; + } + case 'S': { + HandleEventListener(Device, AudioChanged) + break; + } + case 'R': { + CoreSDKTest::GetDeviceScreenResolution(); + break; + } + case 'U': { + HandleEventListener(Device, ScreenResolutionChanged) + break; + } + case 'L': { + CoreSDKTest::GetLocalizationPreferredAudioLanguages(); + break; + } + case 'P': { + HandleEventListener(Localization, PreferredAudioLanguagesChanged) + break; + } + case 'C': { + CoreSDKTest::GetAccessibilityClosedCaptionsSettings(); + break; + } + case 'B': { + HandleEventListener(Accessibility, ClosedCaptionsSettingsChanged) + break; + } + default: + break; + } + getchar(); // Skip white space + } while (option != 'Q'); + + } else { + printf("Core Test not able to connect with server.... \n"); + } + + CoreSDKTest::DestroyFireboltInstance(); + + return 0; +} diff --git a/src/sdks/core/src/cpp/sdk/ctest/build.sh b/src/sdks/core/src/cpp/sdk/cpptest/build.sh similarity index 100% rename from src/sdks/core/src/cpp/sdk/ctest/build.sh rename to src/sdks/core/src/cpp/sdk/cpptest/build.sh diff --git a/src/sdks/core/src/cpp/sdk/ctest/main.c b/src/sdks/core/src/cpp/sdk/ctest/main.c deleted file mode 100644 index 6e6dbf020..000000000 --- a/src/sdks/core/src/cpp/sdk/ctest/main.c +++ /dev/null @@ -1,470 +0,0 @@ -#include -#include -#include - -#include "firebolt.h" -#include "accessibility.h" -#include "account.h" -#include "advertising.h" -#include "device.h" -#include "discovery.h" -#include "common/entertainment.h" - -void ShowMenu() -{ - printf("Enter\n" - "\tI : Get Device ID\n" - "\tC : Get Closed Caption Settings\n" - "\tG : Get Voice Guidance Settings\n" - "\tP : Get Advertising Policy\n" - "\tU : Get Account UID\n" - "\tE : Push EntityInfo\n" - "\tN : Register/Unregister for Device Name change\n" - "\tR : Register/Unregister for Screen Resolution change\n" - "\tA : Register/Unregister for Accessibilty Voice Guidance change\n" - "\tH : Register/Unregister for OnNavigateTo:HomeIntent\n" - "\tS : Register/Unregister for OnNavigateTo:SearchIntent\n" - "\tQ : Quit\n\n" - ); -} - -void ShowEventMenu() -{ - printf("Enter\n" - "\tR: Register Event\n" - "\tU: Unregister Event\n" - "\tQ : Quit\n"); -} - -#define HandleEventListener(Module, eventFuncName, Callback, eventTestStr, eventName) \ -{ \ - int opt; \ - do { \ - getchar(); \ - ShowEventMenu(); \ - printf("Enter option : "); \ - opt = toupper(getchar()); \ - switch (opt) { \ - case 'R': { \ - int32_t result = Module##_Register_On##eventFuncName((const void*)Callback, eventTestStr); \ - if (result != FireboltSDKErrorNone) { \ - printf("Register event %s is failed, status = %d \n", eventName, result); \ - } else { \ - printf("Event %s is registered successfully\n", eventName); \ - } \ - break; \ - } \ - case 'U': { \ - int32_t result = Module##_Unregister_On##eventFuncName((const void*)Callback); \ - if (result != FireboltSDKErrorNone) { \ - printf("Unregister event %s is failed, status = %d \n", eventName, result); \ - } else { \ - printf("Event %s is unregistered successfully\n", eventName); \ - } \ - break; \ - } \ - default: \ - break; \ - } \ - } while (opt != 'Q'); \ -} - -const char* get_skiprestriction_enum_string(Advertising_SkipRestriction skipRestriction) -{ - char* strSkipRestriction; - switch(skipRestriction) { - case ADVERTISING_SKIPRESTRICTION_NONE: - strSkipRestriction = "None"; - break; - case ADVERTISING_SKIPRESTRICTION_ADS_UNWATCHED: - strSkipRestriction = "AdsUnwatched"; - break; - case ADVERTISING_SKIPRESTRICTION_ADS_ALL: - strSkipRestriction = "AdsAll"; - break; - case ADVERTISING_SKIPRESTRICTION_ALL: - strSkipRestriction = "All"; - break; - default: - strSkipRestriction = "None"; - break; - } - return strSkipRestriction; -} - -static const char deviceNameTestStr[] = "DeviceNameTestStr"; -static void NotifyDeviceNameChange(const void* userData, Firebolt_String_t handle) -{ - if (handle) { - printf("Got new device.name :%s\n", Firebolt_String(handle)); - Firebolt_String_Release(handle); - } else { - printf("device.name event handle is not valid\n"); - } -} - -static const char deviceScreenResolutionTestStr[] = "deviceScreenResolutionTestStr"; -static void NotifyDeviceScreenResolutionChange(const void* userData, Device_ResolutionArray_t handle) -{ - if (Device_ResolutionArray_IsValid(handle) == true) { - uint32_t size = Device_ResolutionArray_Size(handle); - printf("Device ScreenResolutions changed for %d numbers\n", size); - for (uint32_t i = 0; i < size; ++i) { - printf("New reslution[%d] = %d\n", i, Device_ResolutionArray_Get(handle, i)); - } - Device_ResolutionArray_Release(handle); - } else { - printf("device.screenresolution event handle is not valid\n"); - } -} - -static const char accessibilityVoiceGuidanceTestStr[] = "AccessibilityVoiceGuidanceTestStr"; -static void NotifyAccessibilityVoiceGuidanceChange(const void* userData, Accessibility_VoiceGuidanceSettings_t handle) -{ - if (Accessibility_VoiceGuidanceSettings_IsValid(handle) == true) { - bool enabled = Accessibility_VoiceGuidanceSettings_Get_Enabled(handle); - uint32_t speed = Accessibility_VoiceGuidanceSettings_Get_Speed(handle); - printf("VoiceGuidanceSettings: Enabled : %d, Speed : %d\n", enabled, speed); - Accessibility_VoiceGuidanceSettings_Release(handle); - } else { - printf("accessibility.voiceguidance event handle is not valid\n"); - } -} - -static const char discoveryHomeIntentTestStr[] = "DiscoveryHomeIntentTestStr"; -static void NotifyOnNavigateToHomeIntent(const void* userData, Intents_HomeIntent_t handle) -{ - if (Intents_HomeIntent_IsValid(handle) == true) { - char* action = Intents_HomeIntent_Get_Action(handle); - printf("NavigateToHomeIntent: Action: %s\n", action); - Intents_HomeIntent_Release(handle); - } else { - printf("discovery.onNavigateToChanged HomeIntent event handle is not valid\n"); - } -} - -static const char discoverySearchIntentTestStr[] = "DiscoverySearchIntentTestStr"; -static void NotifyOnNavigateToSearchIntent(const void* userData, Intents_SearchIntent_t handle) -{ - if (Intents_SearchIntent_IsValid(handle) == true) { - char* action = Intents_SearchIntent_Get_Action(handle); - printf("NavigateToSearchIntent: Action: %s\n", action); - Intents_SearchIntent_Release(handle); - } else { - printf("discovery.onNavigateTo LauncIntent event handle is not valid\n"); - } -} - -int main (int argc, char* argv[]) -{ - char* config = "{\ - \"waitTime\": 1000,\ - \"logLevel\": \"Info\",\ - \"workerPool\":{\ - \"queueSize\": 8,\ - \"threadCount\": 3\ - },\ - \"wsUrl\": \"ws://127.0.0.1:9998\"\ -}"; - - printf("Firebolt Core SDK Test\n"); - - //Intitialize the SDK - FireboltSDK_Initialize(config); - int option; - - do { - ShowMenu(); - printf("Enter option : "); - option = toupper(getchar()); - switch (option) { - case 'I': { - //Lets get the Device ID - Firebolt_String_t handle; - int32_t result = Device_GetId(&handle); - if (result == FireboltSDKErrorNone) { - printf("Device: Id:%s\n\n", Firebolt_String(handle)); - Firebolt_String_Release(handle); - handle = NULL; - } else { - printf("Failed to get Device ID\n\n"); - } - break; - } - case 'C': { - Accessibility_ClosedCaptionsSettings_t handle; - int32_t result = Accessibility_GetClosedCaptionsSettings(&handle); - - if (result == FireboltSDKErrorNone) { - if (Accessibility_ClosedCaptionsSettings_IsValid(handle) == true) { - printf("ClosedCaption Settings ------------------\n"); - Accessibility_ClosedCaptionsStyles_t styleHandle = Accessibility_ClosedCaptionsSettings_Get_Styles(handle); - if (Accessibility_ClosedCaptionsStyles_IsValid(styleHandle)) { - printf("ClosedCaptionStyles:\n"); - char* fontFamily = Accessibility_ClosedCaptionsStyles_Get_FontFamily(styleHandle); - printf("\tFontFamily : %s\n", fontFamily); - uint32_t fontSize = Accessibility_ClosedCaptionsStyles_Get_FontSize(styleHandle); - printf("\tFontSize : %d\n", fontSize); - char* fontColor = Accessibility_ClosedCaptionsStyles_Get_FontColor(styleHandle); - printf("\tFontColor : %s\n", fontColor); - char* fontEdge = Accessibility_ClosedCaptionsStyles_Get_FontEdge(styleHandle); - printf("\tFontEdge : %s\n", fontEdge); - char* fontEdgeColor = Accessibility_ClosedCaptionsStyles_Get_FontEdgeColor(styleHandle); - printf("\tFontEdgeColor : %s\n", fontEdgeColor); - uint32_t fontOpacity = Accessibility_ClosedCaptionsStyles_Get_FontOpacity(styleHandle); - printf("\tFontOpacity : %d\n", fontOpacity); - char* bgColor = Accessibility_ClosedCaptionsStyles_Get_BackgroundColor(styleHandle); - printf("\tBackgroundColor : %s\n", bgColor); - uint32_t bgOpacity = Accessibility_ClosedCaptionsStyles_Get_BackgroundOpacity(styleHandle); - printf("\tBackgroundOpacity : %d\n", bgOpacity); - char* txAlign = Accessibility_ClosedCaptionsStyles_Get_TextAlign(styleHandle); - printf("\tTextAlign : %s\n", txAlign); - char* txAlignVertical = Accessibility_ClosedCaptionsStyles_Get_TextAlignVertical(styleHandle); - printf("\tTextAlignVertical : %s\n", txAlignVertical); - Accessibility_ClosedCaptionsStyles_Release(styleHandle); - } - bool enabled = Accessibility_ClosedCaptionsSettings_Get_Enabled(handle); - printf("Enabled: %d\n\n", enabled); - Accessibility_ClosedCaptionsSettings_Release(handle); - } else { - printf("Invalid ClosedCaptionsSettings_t\n\n"); - } - } else { - printf("Failed to get Closed Caption Settings\n\n"); - } - break; - } - case 'G': { - Accessibility_VoiceGuidanceSettings_t handle; - int32_t result = Accessibility_GetVoiceGuidanceSettings(&handle); - - if (result == FireboltSDKErrorNone) { - if (Accessibility_VoiceGuidanceSettings_IsValid(handle) == true) { - bool enabled = Accessibility_VoiceGuidanceSettings_Get_Enabled(handle); - uint32_t speed = Accessibility_VoiceGuidanceSettings_Get_Speed(handle); - printf("VoiceGuidanceSettings: Enabled : %d, Speed : %d\n", enabled, speed); - Accessibility_VoiceGuidanceSettings_Release(handle); - } else { - printf("Invalid VoiceGuidanceSettings_t\n\n"); - } - } else { - printf("Failed to get Voice Guidance Settings\n\n"); - } - break; - } - case 'P': { - Advertising_AdPolicy_t handle; - int32_t result = Advertising_GetPolicy(&handle); - if (result == FireboltSDKErrorNone) { - if (Advertising_AdPolicy_IsValid(handle) == true) { - printf("AdPolicy: "); - Advertising_SkipRestriction skipRestriction = Advertising_AdPolicy_Get_SkipRestriction(handle); - printf("SkipRestriction = %s ", get_skiprestriction_enum_string(skipRestriction)); - bool limitAdTracking = Advertising_AdPolicy_Get_LimitAdTracking(handle); - printf("LimitAdTracking = %s \n", limitAdTracking? "true" : "false"); - Advertising_AdPolicy_Release(handle); - } else { - printf("Invalid Advertising_AdPolicy_t\n\n"); - } - } else { - printf("Failed to get Advertising Policy\n\n"); - } - break; - } - case 'U': { - Firebolt_String_t handle; - int32_t result = Account_GetUid(&handle); - if (result == FireboltSDKErrorNone) { - printf("Account: Uid:%s\n\n", Firebolt_String(handle)); - Firebolt_String_Release(handle); - handle = NULL; - } else { - printf("Failed to get Advertising Policy\n\n"); - } - break; - } - case 'E': { - { - Discovery_EntityInfoResult_t entityInfoResult = Discovery_EntityInfoResult_Acquire(); - Entertainment_EntityInfo_t entityInfo = Entertainment_EntityInfo_Acquire(); - - //Populate the ContentIdentifiers Object - Entertainment_ContentIdentifiers_t ci = Entertainment_ContentIdentifiers_Acquire(); - Entertainment_ContentIdentifiers_Set_AssetId(ci, "12345678"); - Entertainment_ContentIdentifiers_Set_EntityId(ci, "ABCDEFGH"); - Entertainment_ContentIdentifiers_Set_SeasonId(ci, "1"); - Entertainment_ContentIdentifiers_Set_SeriesId(ci, "9ER34FR"); - Entertainment_ContentIdentifiers_Set_AppContentData(ci, "Sample App Content Data"); - - //Populate EntityInfo Object - //Set the ContentIdentifiers Object to EntityInfo Object - Entertainment_EntityInfo_Set_Identifiers(entityInfo, ci); - Entertainment_ContentIdentifiers_Release(ci); - Entertainment_EntityInfo_Set_Title(entityInfo, "Game Of Thrones"); - Entertainment_EntityInfo_Set_EntityType(entityInfo, "program"); - Entertainment_EntityInfo_Set_ProgramType(entityInfo, ENTERTAINMENT_PROGRAMTYPE_SEASON); - Entertainment_EntityInfo_Set_Synopsis(entityInfo, "The imaginary continent of Westeros was once inhabited by a magical people, the Children of the Forest. For centuries, other people came across the Narrow Sea from the eastern continent of Essos: up North, the First Men; in the Center, the Andals; down South, the Dornish."); - Entertainment_EntityInfo_Set_SeasonNumber(entityInfo, 1); - Entertainment_EntityInfo_Set_EpisodeNumber(entityInfo, 1); - Entertainment_EntityInfo_Set_ReleaseDate(entityInfo, "2012-04-23T18:25:43.511Z"); - - { - Entertainment_ContentRatingArray_t crArray = Entertainment_ContentRatingArray_Acquire(); - { - //Populate the ContentRatings Handle for US TV scheme - Entertainment_ContentRating_t cr = Entertainment_ContentRating_Acquire(); - Entertainment_ContentRating_Set_Scheme(cr, ENTERTAINMENT_CONTENTRATING_SCHEME_US_TV); - Entertainment_ContentRating_Set_Rating(cr, "TVMA"); - Entertainment_ContentRating_AdvisoriesArray_t crAdvisories = Entertainment_ContentRating_AdvisoriesArray_Acquire(); - Entertainment_ContentRating_AdvisoriesArray_Add(crAdvisories, "V"); - Entertainment_ContentRating_AdvisoriesArray_Add(crAdvisories, "S"); - Entertainment_ContentRating_AdvisoriesArray_Add(crAdvisories, "L"); - Entertainment_ContentRating_Set_Advisories(cr, crAdvisories); - Entertainment_ContentRating_AdvisoriesArray_Release(crAdvisories); - Entertainment_ContentRatingArray_Add(crArray, cr); - } - { - //Populate the ContentRatings Handle for US TV scheme - Entertainment_ContentRating_t cr = Entertainment_ContentRating_Acquire(); - Entertainment_ContentRating_Set_Scheme(cr, ENTERTAINMENT_CONTENTRATING_SCHEME_CA_TV); - Entertainment_ContentRating_Set_Rating(cr, "18+"); - Entertainment_ContentRating_AdvisoriesArray_t crAdvisories = Entertainment_ContentRating_AdvisoriesArray_Acquire(); - Entertainment_ContentRating_AdvisoriesArray_Add(crAdvisories, "18+"); - Entertainment_ContentRating_Set_Advisories(cr, crAdvisories); - Entertainment_ContentRating_AdvisoriesArray_Release(crAdvisories); - Entertainment_ContentRatingArray_Add(crArray, cr); - } - Entertainment_EntityInfo_Set_ContentRatings(entityInfo, crArray); - Entertainment_ContentRatingArray_Release(crArray); - } - - //Populate WayToWatch Array in EntityInfo - { - //Populate the WayToWatch Object - Entertainment_WayToWatch_t w2w = Entertainment_WayToWatch_Acquire(); - { - //Add the ContentIdentifiers Object in WayToWatch - Entertainment_ContentIdentifiers_t ciI = Entertainment_ContentIdentifiers_Acquire(); - Entertainment_ContentIdentifiers_Set_AssetId(ciI, "12345678"); - Entertainment_ContentIdentifiers_Set_EntityId(ciI, "ABCDEFGH"); - Entertainment_ContentIdentifiers_Set_SeasonId(ciI, "1"); - Entertainment_ContentIdentifiers_Set_SeriesId(ciI, "9ER34FR"); - Entertainment_ContentIdentifiers_Set_AppContentData(ciI, "Sample App Content Data"); - Entertainment_WayToWatch_Set_Identifiers(w2w, ciI); - Entertainment_ContentIdentifiers_Release(ciI); - } - Entertainment_WayToWatch_Set_Expires(w2w, "2014-04-23T18:25:43.511Z"); - Entertainment_WayToWatch_Set_Entitled(w2w, true); - Entertainment_WayToWatch_Set_EntitledExpires(w2w, "2014-04-23T18:25:43.511Z"); - Entertainment_WayToWatch_Set_OfferingType(w2w, ENTERTAINMENT_OFFERINGTYPE_FREE); - Entertainment_WayToWatch_Set_HasAds(w2w, true); - - //Populate VideoQuality Array - Entertainment_WayToWatch_VideoQualityArray_t vqArray = - Entertainment_WayToWatch_VideoQualityArray_Acquire(); - Entertainment_WayToWatch_VideoQualityArray_Add( - vqArray, ENTERTAINMENT_WAYTOWATCH_VIDEOQUALITY_HD); - Entertainment_WayToWatch_VideoQualityArray_Add( - vqArray, ENTERTAINMENT_WAYTOWATCH_VIDEOQUALITY_UHD); - Entertainment_WayToWatch_Set_VideoQuality(w2w, vqArray); - Entertainment_WayToWatch_VideoQualityArray_Release(vqArray); - - //Populate AudioProfile Array - Entertainment_AudioProfileArray_t apArray = - Entertainment_AudioProfileArray_Acquire(); - Entertainment_AudioProfileArray_Add( - apArray, TYPES_AUDIOPROFILE_STEREO); - Entertainment_AudioProfileArray_Add( - apArray, TYPES_AUDIOPROFILE_DOLBY_DIGITAL_5_1); - Entertainment_AudioProfileArray_Add( - apArray, TYPES_AUDIOPROFILE_DOLBY_DIGITAL_5_1_PLUS); - Entertainment_WayToWatch_Set_AudioProfile(w2w, apArray); - Entertainment_AudioProfileArray_Release(apArray); - - //Populate AudioLanguages Array - Entertainment_WayToWatch_AudioLanguagesArray_t alArray = - Entertainment_WayToWatch_AudioLanguagesArray_Acquire(); - Entertainment_WayToWatch_AudioLanguagesArray_Add(alArray, "en"); - Entertainment_WayToWatch_AudioLanguagesArray_Add(alArray, "fr"); - Entertainment_WayToWatch_Set_AudioLanguages(w2w, alArray); - Entertainment_WayToWatch_AudioLanguagesArray_Release(alArray); - - //Populate ClosedCaptions Array - Entertainment_WayToWatch_ClosedCaptionsArray_t ccArray = - Entertainment_WayToWatch_ClosedCaptionsArray_Acquire(); - Entertainment_WayToWatch_ClosedCaptionsArray_Add(ccArray, "en"); - Entertainment_WayToWatch_ClosedCaptionsArray_Add(ccArray, "fr"); - Entertainment_WayToWatch_Set_ClosedCaptions(w2w, ccArray); - Entertainment_WayToWatch_ClosedCaptionsArray_Release(ccArray); - - //Populate Subtitles Array - Entertainment_WayToWatch_SubtitlesArray_t sbArray = - Entertainment_WayToWatch_SubtitlesArray_Acquire(); - Entertainment_WayToWatch_SubtitlesArray_Add(sbArray, "en"); - Entertainment_WayToWatch_SubtitlesArray_Add(sbArray, "fr"); - Entertainment_WayToWatch_Set_Subtitles(w2w, sbArray); - Entertainment_WayToWatch_SubtitlesArray_Release(sbArray); - - //Populate AudioDescriptions Array - Entertainment_WayToWatch_AudioDescriptionsArray_t adArray = - Entertainment_WayToWatch_AudioDescriptionsArray_Acquire(); - Entertainment_WayToWatch_AudioDescriptionsArray_Add(adArray, "en"); - Entertainment_WayToWatch_Set_AudioDescriptions(w2w, adArray); - Entertainment_WayToWatch_AudioDescriptionsArray_Release(adArray); - - //Populate WayToWatch Array - Entertainment_WayToWatchArray_t w2wArray = - Entertainment_WayToWatchArray_Acquire(); - Entertainment_WayToWatchArray_Add(w2wArray, w2w); - Entertainment_EntityInfo_Set_WaysToWatch(entityInfo, w2wArray); - Entertainment_WayToWatchArray_Release(w2wArray); - Entertainment_WayToWatch_Release(w2w); - } - - //Populate EntityInfoResult Object - Discovery_EntityInfoResult_Set_Expires(entityInfoResult, "2012-06-23T18:25:43.511Z"); - Discovery_EntityInfoResult_Set_Entity(entityInfoResult, entityInfo); - Entertainment_EntityInfo_Release(entityInfo); - - //All Set, Call the Push - int32_t result = Discovery_PushEntityInfo(entityInfoResult); - if (result == FireboltSDKErrorNone) { - printf("\nSuccessfully Pushed entityInfo\n"); - - } else { - printf("\nFailed to Push entityInfo\n"); - } - Discovery_EntityInfoResult_Release(entityInfoResult); - break; - } - } - case 'R': { - HandleEventListener(Device, ScreenResolutionChanged, (const void*)NotifyDeviceScreenResolutionChange, deviceScreenResolutionTestStr, "device.screenresolution") - break; - } - case 'N': { - HandleEventListener(Device, NameChanged, (const void*)NotifyDeviceNameChange, deviceNameTestStr, "device.name") - break; - } - case 'A': { - HandleEventListener(Accessibility, VoiceGuidanceSettingsChanged, (const void*)NotifyAccessibilityVoiceGuidanceChange, accessibilityVoiceGuidanceTestStr, "accessibility.voiceguidance") - break; - } - case 'H': { - HandleEventListener(Discovery, NavigateToHomeIntent, (const void*)NotifyOnNavigateToHomeIntent, discoveryHomeIntentTestStr, "discovery.onNavigateTo") - break; - } - case 'S': { - HandleEventListener(Discovery, NavigateToSearchIntent, (const void*)NotifyOnNavigateToSearchIntent, discoverySearchIntentTestStr, "discovery.onNavigateTo") - break; - } - default: - break; - } - getchar(); // Skip white space - } while (option != 'Q'); - - FireboltSDK_Deinitialize(); - - return 0; -} diff --git a/src/sdks/core/src/cpp/sdk/test/CMakeLists.txt b/src/sdks/core/src/cpp/sdk/test/CMakeLists.txt index 9242ea10e..b196ac143 100644 --- a/src/sdks/core/src/cpp/sdk/test/CMakeLists.txt +++ b/src/sdks/core/src/cpp/sdk/test/CMakeLists.txt @@ -27,7 +27,9 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) find_package(${NAMESPACE}Core CONFIG REQUIRED) file(GLOB CPP_SOURCES *.cpp) -add_library(${TESTLIB} STATIC ${CPP_SOURCES} CoreSDKTestGeneratedCode.c) +list(REMOVE_ITEM CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Main.cpp) +message("After CPP_SOURCES " ${CPP_SOURCES}) +add_library(${TESTLIB} STATIC ${CPP_SOURCES}) target_link_libraries(${TESTLIB} PRIVATE @@ -44,7 +46,7 @@ target_include_directories(${TESTLIB} ) set_target_properties(${TESTLIB} PROPERTIES - CXX_STANDARD 11 + CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES LINK_WHAT_YOU_USE TRUE FRAMEWORK FALSE @@ -54,7 +56,7 @@ set(TESTAPP FireboltCoreSDKTestApp) message("Setup ${TESTAPP} v${PROJECT_VERSION}") -add_executable(${TESTAPP} Main.c) +add_executable(${TESTAPP} Main.cpp) target_link_libraries(${TESTAPP} PRIVATE diff --git a/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.c b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.c deleted file mode 100644 index cbb0fa76c..000000000 --- a/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright 2023 Comcast Cable Communications Management, 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 - -#include "CoreSDKCTests.h" -#include "CoreSDKTestGeneratedCode.h" - -#include "accessibility.h" -#include "advertising.h" -#include "common/types.h" -#include "device.h" -#include "lifecycle.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t test_generated_properties_get_device_id() -{ - Firebolt_String_t handle; - int32_t result = Device_GetId(&handle); - - if (result == FireboltSDKErrorNone) { - printf("\nDevice: Id:%s\n", Firebolt_String(handle)); - Firebolt_String_Release(handle); - } - - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} -#if 0 -int32_t test_generated_properties_get_device_version() -{ - Device_Versions_t handle; - int32_t result = Device_GetVersion(&handle); - - if (result == FireboltSDKErrorNone) { - if (Device_Versions_IsValid(handle)) { - Types_SemanticVersion_t sdkHandle = Device_Versions_Get_Sdk(handle); - if (Types_SemanticVersion_IsValid(sdkHandle)) { - uint32_t major = Types_SemanticVersion_Get_Major(sdkHandle); - uint32_t minor = Types_SemanticVersion_Get_Minor(sdkHandle); - uint32_t patch = Types_SemanticVersion_Get_Patch(sdkHandle); - char* readable = Types_SemanticVersion_Get_Readable(sdkHandle); - printf("\nDevice:SDK Version major:%d minor:%d patch:%d readable:%s\n", - major, minor, patch, readable); - Types_SemanticVersion_Release(sdkHandle); - result = FireboltSDKErrorNone; - } - Types_SemanticVersion_t osHandle = Device_Versions_Get_Os(handle); - if (Types_SemanticVersion_IsValid(osHandle)) { - uint32_t major = Types_SemanticVersion_Get_Major(osHandle); - uint32_t minor = Types_SemanticVersion_Get_Minor(osHandle); - uint32_t patch = Types_SemanticVersion_Get_Patch(osHandle); - const char* readable = Types_SemanticVersion_Get_Readable(osHandle); - printf("\nDevice:OS Version major:%d minor:%d patch:%d readable:%s\n", - major, minor, patch, readable); - Types_SemanticVersion_Release(osHandle); - result = FireboltSDKErrorNone; - } - Device_Versions_Release(handle); - } else { - result = FireboltSDKErrorUnavailable; - } - } - - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} -#endif -int32_t test_generated_properties_get_accessibility_closedcaption() -{ - Accessibility_ClosedCaptionsSettings_t handle; - int32_t result = Accessibility_GetClosedCaptionsSettings(&handle); - - if (result == FireboltSDKErrorNone) { - if (Accessibility_ClosedCaptionsSettings_IsValid(handle) == true) { - printf("ClosedCaption Settings ------------------\n"); - Accessibility_ClosedCaptionsStyles_t styleHandle = Accessibility_ClosedCaptionsSettings_Get_Styles(handle); - if (Accessibility_ClosedCaptionsStyles_IsValid(styleHandle)) { - printf("ClosedCaptionStyles:\n"); - char* fontFamily = Accessibility_ClosedCaptionsStyles_Get_FontFamily(styleHandle); - printf("\tFontFamily : %s\n", fontFamily); - uint32_t fontSize = Accessibility_ClosedCaptionsStyles_Get_FontSize(styleHandle); - printf("\tFontSize : %d\n", fontSize); - char* fontColor = Accessibility_ClosedCaptionsStyles_Get_FontColor(styleHandle); - printf("\tFontColor : %s\n", fontColor); - char* fontEdge = Accessibility_ClosedCaptionsStyles_Get_FontEdge(styleHandle); - printf("\tFontEdge : %s\n", fontEdge); - char* fontEdgeColor = Accessibility_ClosedCaptionsStyles_Get_FontEdgeColor(styleHandle); - printf("\tFontEdgeColor : %s\n", fontEdgeColor); - uint32_t fontOpacity = Accessibility_ClosedCaptionsStyles_Get_FontOpacity(styleHandle); - printf("\tFontOpacity : %d\n", fontOpacity); - char* bgColor = Accessibility_ClosedCaptionsStyles_Get_BackgroundColor(styleHandle); - printf("\tBackgroundColor : %s\n", bgColor); - uint32_t bgOpacity = Accessibility_ClosedCaptionsStyles_Get_BackgroundOpacity(styleHandle); - printf("\tBackgroundOpacity : %d\n", bgOpacity); - char* txAlign = Accessibility_ClosedCaptionsStyles_Get_TextAlign(styleHandle); - printf("\tTextAlign : %s\n", txAlign); - char* txAlignVertical = Accessibility_ClosedCaptionsStyles_Get_TextAlignVertical(styleHandle); - printf("\tTextAlignVertical : %s\n", txAlignVertical); - Accessibility_ClosedCaptionsStyles_Release(styleHandle); - } - bool enabled = Accessibility_ClosedCaptionsSettings_Get_Enabled(handle); - printf("Enabled: %d\n", enabled); - Accessibility_ClosedCaptionsSettings_Release(handle); - } else { - result = FireboltSDKErrorUnavailable; - } - } - - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} -int32_t test_generated_properties_get_accessibility_voiceguidancesettings() -{ - Accessibility_VoiceGuidanceSettings_t handle; - int32_t result = Accessibility_GetVoiceGuidanceSettings(&handle); - - if (result == FireboltSDKErrorNone) { - if (Accessibility_VoiceGuidanceSettings_IsValid(handle) == true) { - bool enabled = Accessibility_VoiceGuidanceSettings_Get_Enabled(handle); - uint32_t speed = Accessibility_VoiceGuidanceSettings_Get_Speed(handle); - printf("VoiceGuidanceSettings: Enabled : %d, Speed : %d\n", enabled, speed); - Accessibility_VoiceGuidanceSettings_Release(handle); - } else { - result = FireboltSDKErrorUnavailable; - } - } - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} -const char* get_skiprestriction_enum_string(Advertising_SkipRestriction skipRestriction) -{ - const char* strSkipRestriction; - switch(skipRestriction) { - case ADVERTISING_SKIPRESTRICTION_NONE: - strSkipRestriction = "None"; - break; - case ADVERTISING_SKIPRESTRICTION_ADS_UNWATCHED: - strSkipRestriction = "AdsUnwatched"; - break; - case ADVERTISING_SKIPRESTRICTION_ADS_ALL: - strSkipRestriction = "AdsAll"; - break; - case ADVERTISING_SKIPRESTRICTION_ALL: - strSkipRestriction = "All"; - break; - default: - strSkipRestriction = "None"; - break; - } - return strSkipRestriction; -} - -int32_t test_generated_properties_get_advertising_policy() -{ - Advertising_AdPolicy_t handle; - int32_t result = Advertising_GetPolicy(&handle); - if (result == FireboltSDKErrorNone) { - if (Advertising_AdPolicy_IsValid(handle) == true) { - printf("AdPolicy: "); - Advertising_SkipRestriction skipRestriction = Advertising_AdPolicy_Get_SkipRestriction(handle); - printf("SkipRestriction = %s ", get_skiprestriction_enum_string(skipRestriction)); - bool limitAdTracking = Advertising_AdPolicy_Get_LimitAdTracking(handle); - printf("LimitAdTracking = %s \n", limitAdTracking? "true" : "false"); - Advertising_AdPolicy_Release(handle); - } else { - result = FireboltSDKErrorUnavailable; - } - } - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} - -#include -#include -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; - -static const char deviceNameTestStr[] = "DeviceNameTestStr"; -static void NotifyDeviceNameChange(const void* userData, Firebolt_String_t handle) -{ - EXPECT_NE(handle, NULL); - if (handle) { - printf("\nGot new device.name :%s\n", Firebolt_String(handle)); - Firebolt_String_Release(handle); - } - EXPECT_EQ(strncmp((const char*)userData, deviceNameTestStr, strlen(deviceNameTestStr)), 0); - pthread_cond_signal(&cond); -} -int32_t test_generated_event_device_name() -{ - int32_t result = Device_Register_OnNameChanged((const void*)&NotifyDeviceNameChange, deviceNameTestStr); - EXPECT_EQ(result, FireboltSDKErrorNone); - if (result != FireboltSDKErrorNone) { - printf("Set event device.name status = %d \n", result); - } else { - printf("Set event device.name registered successfully\n"); - - pthread_mutex_lock(&lock); - printf("Waiting for device.name event\n"); - pthread_cond_wait(&cond, &lock); - pthread_mutex_unlock(&lock); - } - - result = Device_Unregister_OnNameChanged((const void*)NotifyDeviceNameChange); - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} - -int32_t test_generated_event_device_name_with_register_same_callback() -{ - int32_t result = Device_Register_OnNameChanged((const void*)NotifyDeviceNameChange, deviceNameTestStr); - EXPECT_EQ(result, FireboltSDKErrorNone); - if (result != FireboltSDKErrorNone) { - printf("Set event device.name status = %d \n", result); - } else { - printf("Set event device.name registered successfully\n"); - result = Device_Register_OnNameChanged((const void*)NotifyDeviceNameChange, deviceNameTestStr); - EXPECT_EQ(result, FireboltSDKErrorInUse); - if (result == FireboltSDKErrorInUse) { - printf("%s Yes this device.name event is already registered with same callback\n", __func__); - } - } - - result = Device_Unregister_OnNameChanged((const void*)NotifyDeviceNameChange); - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} -static const char deviceScreenResolutionTestStr[] = "deviceScreenResolutionTestStr"; -static void NotifyDeviceScreenResolutionChange(const void* userData, Device_ResolutionArray_t handle) -{ - EXPECT_EQ(Device_ResolutionArray_IsValid(handle), true); - if (Device_ResolutionArray_IsValid(handle) == true) { - uint32_t size = Device_ResolutionArray_Size(handle); - printf("Device ScreenResolutions changed for %d numbers\n", size); - for (uint32_t i = 0; i < size; ++i) { - printf("New reslution[%d] = %d\n", i, Device_ResolutionArray_Get(handle, i)); - } - Device_ResolutionArray_Release(handle); - } - EXPECT_EQ(strncmp((const char*)userData, deviceScreenResolutionTestStr, strlen(deviceScreenResolutionTestStr)), 0); - pthread_cond_signal(&cond); -} -int32_t test_generated_event_device_screenresolution() -{ - int32_t result = Device_Register_OnScreenResolutionChanged((const void*)NotifyDeviceScreenResolutionChange, deviceScreenResolutionTestStr); - EXPECT_EQ(result, FireboltSDKErrorNone); - if (result != FireboltSDKErrorNone) { - printf("Set event device.screenresolution status = %d \n", result); - } else { - printf("Set event device.screenresolution registered successfully\n"); - - pthread_mutex_lock(&lock); - printf("Waiting for device.screenresolution event\n"); - pthread_cond_wait(&cond, &lock); - pthread_mutex_unlock(&lock); - } - - result = Device_Unregister_OnScreenResolutionChanged((const void*)NotifyDeviceScreenResolutionChange); - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} - -static const char accessibilityVoiceGuidanceTestStr[] = "AccessibilityVoiceGuidanceTestStr"; -static void NotifyAccessibilityVoiceGuidanceChange(const void* userData, Accessibility_VoiceGuidanceSettings_t handle) -{ - EXPECT_EQ(Accessibility_VoiceGuidanceSettings_IsValid(handle), true); - if (Accessibility_VoiceGuidanceSettings_IsValid(handle) == true) { - bool enabled = Accessibility_VoiceGuidanceSettings_Get_Enabled(handle); - uint32_t speed = Accessibility_VoiceGuidanceSettings_Get_Speed(handle); - printf("VoiceGuidanceSettings: Enabled : %d, Speed : %d\n", enabled, speed); - Accessibility_VoiceGuidanceSettings_Release(handle); - } - EXPECT_EQ(strncmp((const char*)userData, accessibilityVoiceGuidanceTestStr, strlen(accessibilityVoiceGuidanceTestStr)), 0); - pthread_cond_signal(&cond); -} -int32_t test_generated_event_accessibility_voice_guidance_settings() -{ - int32_t result = Accessibility_Register_OnVoiceGuidanceSettingsChanged((const void*)NotifyAccessibilityVoiceGuidanceChange, accessibilityVoiceGuidanceTestStr); - EXPECT_EQ(result, FireboltSDKErrorNone); - if (result != FireboltSDKErrorNone) { - printf("Set event device.name status = %d \n", result); - } else { - printf("Set event accessibility.voiceguidance registered successfully\n"); - - pthread_mutex_lock(&lock); - printf("Waiting for accessibility.voiceguidance event\n"); - pthread_cond_wait(&cond, &lock); - pthread_mutex_unlock(&lock); - } - - result = Accessibility_Unregister_OnVoiceGuidanceSettingsChanged((const void*)NotifyAccessibilityVoiceGuidanceChange); - EXPECT_EQ(result, FireboltSDKErrorNone); - return result; -} -#if 0 -int32_t test_generated_calls_metrics_lifecycle_ready() -{ - int32_t result = Lifecycle_Ready(); - if (result != FireboltSDKErrorNone) { - printf("Lifecycle.ready call status = %d \n", result); - } else { - printf("Lifecycle.ready is called successfully\n"); - } - // Just add sleep() to keep the test process in active for a while, since the test process should be in-active to invoke worker pool dispatcher (for calls-metrics mehods). This sleep is not required for actual apps case. - sleep(1); - return result; -} -#endif -#ifdef __cplusplus -} -#endif diff --git a/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.cpp b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.cpp new file mode 100644 index 000000000..3265daf68 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.cpp @@ -0,0 +1,91 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, 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 + +#include "Module.h" +#include "firebolt.h" +#include "CoreSDKTestStaticCode.h" +#include "CoreSDKTestGeneratedCode.h" + +using namespace std; +bool CoreSDKTestGeneratedCode::_connected; + +void CoreSDKTestGeneratedCode::ConnectionChanged(const bool connected, const Firebolt::Error error) +{ + cout << "Change in connection: connected: " << connected << " error: " << static_cast(error) << endl; + _connected = connected; +} + +void CoreSDKTestGeneratedCode::CreateFireboltInstance() +{ + const std::string config = _T("{\ + \"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 CoreSDKTestGeneratedCode::DestroyFireboltInstance() +{ + Firebolt::IFireboltAccessor::Instance().Disconnect(); + Firebolt::IFireboltAccessor::Instance().Deinitialize(); + Firebolt::IFireboltAccessor::Instance().Dispose(); +} + +bool CoreSDKTestGeneratedCode::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 + SleepMs(sleepSlot); + waiting -= sleepSlot; + } + return _connected; +} + +void CoreSDKTestGeneratedCode::TestCoreStaticSDK() +{ + FireboltSDK::Tests::Main(); +} + +void CoreSDKTestGeneratedCode::GetDeviceName() +{ + Firebolt::Error error = Firebolt::Error::None; + const std::string name = Firebolt::IFireboltAccessor::Instance().DeviceInterface().Name(&error); + + if (error == Firebolt::Error::None) { + cout << "Get DeviceName = " << name.c_str() << endl; + } else { + cout << "Get DeviceName status = " << static_cast(error) << endl; + } +} + diff --git a/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.h b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.h index 4b9d12441..cfa3c86ae 100644 --- a/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.h +++ b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestGeneratedCode.h @@ -16,27 +16,24 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef CORESDK_TEST_GENERATED_CODE_H -#define CORESDK_TEST_GENERATED_CODE_H +#pragma once +#include "error.h" -#ifdef __cplusplus -extern "C" { -#endif +class CoreSDKTestGeneratedCode { -//int32_t test_generated_properties_get_device_version(); -int32_t test_generated_properties_get_device_id(); -int32_t test_generated_properties_get_accessibility_closedcaption(); -int32_t test_generated_properties_get_accessibility_voiceguidancesettings(); -int32_t test_generated_properties_get_advertising_policy(); -int32_t test_generated_event_device_name(); -int32_t test_generated_event_device_name_with_register_same_callback(); -int32_t test_generated_event_device_screenresolution(); -int32_t test_generated_event_accessibility_voice_guidance_settings(); -//int32_t test_generated_calls_metrics_lifecycle_ready(); +public: + CoreSDKTestGeneratedCode() = default; + virtual ~CoreSDKTestGeneratedCode() = default; -#ifdef __cplusplus -} -#endif + static void CreateFireboltInstance(); + static void DestroyFireboltInstance(); + static void TestCoreStaticSDK(); + static void GetDeviceName(); + static bool WaitOnConnectionReady(); + +private: + static void ConnectionChanged(const bool, const Firebolt::Error); + static bool _connected; +}; -#endif // CORESDK_TEST_GENERATED_CODE_H diff --git a/src/sdks/core/src/cpp/sdk/test/CoreSDKTestStaticCode.cpp b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestStaticCode.cpp new file mode 100644 index 000000000..8ac533e31 --- /dev/null +++ b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestStaticCode.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2023 Comcast Cable Communications Management, 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 "Module.h" +#include "CoreSDKTestStaticCode.h" + +namespace FireboltSDK { + CoreTestStaticCode::CoreTestStaticCode() + : Tests() + { + _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Get Country Code"), + std::forward_as_tuple(&GetCountryCode)); + } + + /* static */ Firebolt::Error CoreTestStaticCode::GetCountryCode() + { + const string method = _T("localization.countryCode"); + WPEFramework::Core::ProxyType response; + Firebolt::Error status = FireboltSDK::Properties::Get(method, response); + + EXPECT_EQ(status, Firebolt::Error::None); + if (status == Firebolt::Error::None) { + FIREBOLT_LOG_INFO(Logger::Category::Core, Logger::Module(), "CountryCode : %s", response->Value().c_str()); + } else { + FIREBOLT_LOG_ERROR(Logger::Category::Core, Logger::Module(), "Get %s status = %d\n", method.c_str(), status); + } + + return status; + } +} + diff --git a/src/sdks/core/src/cpp/sdk/test/CoreSDKTests.h b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestStaticCode.h similarity index 91% rename from src/sdks/core/src/cpp/sdk/test/CoreSDKTests.h rename to src/sdks/core/src/cpp/sdk/test/CoreSDKTestStaticCode.h index 480129e6d..8966112f9 100644 --- a/src/sdks/core/src/cpp/sdk/test/CoreSDKTests.h +++ b/src/sdks/core/src/cpp/sdk/test/CoreSDKTestStaticCode.h @@ -17,7 +17,6 @@ */ #pragma once - #include namespace FireboltSDK { @@ -51,12 +50,12 @@ namespace FireboltSDK { WPEFramework::Core::JSON::Boolean RememberWatchedPrograms; }; - class CoreTests : public Tests { + class CoreTestStaticCode : public Tests { public: - CoreTests(); - ~CoreTests() override = default; + CoreTestStaticCode(); + ~CoreTestStaticCode() override = default; - static int32_t GetDiscoveryPolicy(); + static Firebolt::Error GetCountryCode(); }; } diff --git a/src/sdks/core/src/cpp/sdk/test/CoreSDKTests.cpp b/src/sdks/core/src/cpp/sdk/test/CoreSDKTests.cpp deleted file mode 100644 index cfcca0686..000000000 --- a/src/sdks/core/src/cpp/sdk/test/CoreSDKTests.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2023 Comcast Cable Communications Management, 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 "Module.h" -#include "CoreSDKTests.h" - -namespace FireboltSDK { - CoreTests::CoreTests() - : Tests() - { - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Get Discovery Policy"), - std::forward_as_tuple(&GetDiscoveryPolicy)); - } - - /* static */ int32_t CoreTests::GetDiscoveryPolicy() - { - const string method = _T("discovery.policy"); - WPEFramework::Core::ProxyType response; - int32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::Core, Logger::Module(), - "EnableRecommendations : %d", response->EnableRecommendations.Value()); - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::Core, Logger::Module(), - "ShareWatchHistory : %d", response->ShareWatchHistory.Value()); - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::Core, Logger::Module(), - "RememberWatchedPrograms : %d", response->RememberWatchedPrograms.Value()); - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::Core, Logger::Module(), - "Get %s status = %d", method.c_str(), status); - } - - return status; - } -} - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t test_firebolt_core_main() -{ - return FireboltSDK::Tests::Main(); -} - -int32_t test_properties_get_policy() -{ - const string method = _T("discovery.policy"); - WPEFramework::Core::ProxyType response; - int32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::Core, "ctest", - "EnableRecommendations : %d", response->EnableRecommendations.Value()); - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::Core, "ctest", - "ShareWatchHistory : %d", response->ShareWatchHistory.Value()); - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::Core, "ctest", - "RememberWatchedPrograms : %d", response->RememberWatchedPrograms.Value()); - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::Core, "ctest", - "Get %s status = %d", method.c_str(), status); - } - - return status; -} - -#ifdef __cplusplus -} -#endif diff --git a/src/sdks/core/src/cpp/sdk/test/Main.c b/src/sdks/core/src/cpp/sdk/test/Main.c deleted file mode 100644 index 2490dbb95..000000000 --- a/src/sdks/core/src/cpp/sdk/test/Main.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2023 Comcast Cable Communications Management, 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 -#include "CoreSDKCTests.h" -#include "CoreSDKTestGeneratedCode.h" - -int __cnt = 0; -int __pass = 0; - -int TotalTests = 0; -int TotalTestsPassed = 0; - -int main() -{ - test_firebolt_create_instance(); - test_firebolt_core_main(); - - // Calling C function sequences - printf("%s:%s:%d Calling C function tests\n", __FILE__, __func__, __LINE__); - EXECUTE("test_properties_get_device_id", test_properties_get_device_id); - EXECUTE("test_properties_get_policy", test_properties_get_policy); - EXECUTE("test_properties_set", test_properties_set); - EXECUTE("test_eventregister_by_providing_callback", test_eventregister_by_providing_callback); - EXECUTE("test_eventregister", test_eventregister); - EXECUTE("test_string_set_get_value", test_string_set_get_value); - EXECUTE("test_generated_properties_get_device_id", test_generated_properties_get_device_id); - //EXECUTE("test_generated_properties_get_device_version", test_generated_properties_get_device_version); - EXECUTE("test_generated_properties_get_accessibility_closedcaption", test_generated_properties_get_accessibility_closedcaption); - EXECUTE("test_generated_properties_get_accessibility_voiceguidancesettings", test_generated_properties_get_accessibility_voiceguidancesettings); - EXECUTE("test_generated_properties_get_advertising_policy", test_generated_properties_get_advertising_policy); - EXECUTE("test_generated_event_device_name", test_generated_event_device_name); - EXECUTE("test_generated_event_device_name_with_register_same_callback", test_generated_event_device_name_with_register_same_callback); - EXECUTE("test_generated_event_device_screenresolution", test_generated_event_device_screenresolution); - EXECUTE("test_generated_event_accessibility_voice_guidance_settings", test_generated_event_accessibility_voice_guidance_settings); - //EXECUTE("test_generated_calls_metrics_lifecycle_ready", test_generated_calls_metrics_lifecycle_ready); - - test_firebolt_dispose_instance(); - - printf("TOTAL: %i tests; %i PASSED, %i FAILED\n", TotalTests, TotalTestsPassed, (TotalTests - TotalTestsPassed)); -} - diff --git a/src/sdks/core/src/cpp/sdk/test/CoreSDKCTests.h b/src/sdks/core/src/cpp/sdk/test/Main.cpp similarity index 57% rename from src/sdks/core/src/cpp/sdk/test/CoreSDKCTests.h rename to src/sdks/core/src/cpp/sdk/test/Main.cpp index a6592156c..bd4329d42 100644 --- a/src/sdks/core/src/cpp/sdk/test/CoreSDKCTests.h +++ b/src/sdks/core/src/cpp/sdk/test/Main.cpp @@ -16,20 +16,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef CORESDK_C_TESTS_H -#define CORESDK_C_TESTS_H +#include +#include "CoreSDKTestGeneratedCode.h" -#include +int __cnt = 0; +int __pass = 0; -#ifdef __cplusplus -extern "C" { -#endif +int TotalTests = 0; +int TotalTestsPassed = 0; -int32_t test_firebolt_core_main(); -int32_t test_properties_get_policy(); +int main() +{ + CoreSDKTestGeneratedCode::CreateFireboltInstance(); -#ifdef __cplusplus + if (CoreSDKTestGeneratedCode::WaitOnConnectionReady() == true) { + CoreSDKTestGeneratedCode::GetDeviceName(); + } + CoreSDKTestGeneratedCode::DestroyFireboltInstance(); + printf("TOTAL: %i tests; %i PASSED, %i FAILED\n", TotalTests, TotalTestsPassed, (TotalTests - TotalTestsPassed)); } -#endif -#endif //CORESDK_C_TESTS_H