diff --git a/docs/openrpc/the-spec/firebolt-open-rpc.json b/docs/openrpc/the-spec/firebolt-open-rpc.json index a7a5052..2a988db 100644 --- a/docs/openrpc/the-spec/firebolt-open-rpc.json +++ b/docs/openrpc/the-spec/firebolt-open-rpc.json @@ -580,7 +580,7 @@ ], "params": [ { - "name": "osName", + "name": "value", "summary": "The operating system name", "required": true, "schema": { @@ -599,7 +599,7 @@ "name": "Setting the operating system name", "params": [ { - "name": "osName", + "name": "value", "value": "Linux" } ], @@ -653,7 +653,7 @@ ], "params": [ { - "name": "osVersion", + "name": "value", "summary": "The operating system version", "required": true, "schema": { @@ -672,7 +672,7 @@ "name": "Setting the operating system version", "params": [ { - "name": "osVersion", + "name": "value", "value": "5.15.0" } ], @@ -4112,6 +4112,340 @@ } } }, + { + "name": "VideoOutput.resolution", + "summary": "Returns the resolution for the active video output", + "params": [], + "result": { + "name": "resolution", + "schema": { + "type": "object", + "required": ["height", "width"], + "properties": { + "height": {"type": "integer", "minimum": 0}, + "width": {"type": "integer", "minimum": 0} + } + } + }, + "examples": [{ + "name": "Getting resolution", + "params": [], + "result": {"name": "Default Result", "value": {"height": 1080, "width": 1920}} + }] + }, + { + "name": "VideoOutput.hdcp", + "summary": "Returns HDCP state for the active video output", + "params": [], + "tags": [ + { + "name": "property:readonly" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:cpp-client-only" + ] + } + ], + "result": { + "name": "hdcp", + "schema": { + "type": "string", + "enum": [ + "direct", + "hdcp1.4", + "hdcp2.2", + "none" + ] + } + }, + "examples": [ + { + "name": "Getting HDCP state", + "params": [], + "result": { + "name": "Default Result", + "value": "hdcp1.4" + } + } + ] + }, + { + "name": "VideoOutput.cecState", + "summary": "Returns CEC state for the active video output", + "params": [], + "tags": [ + { + "name": "property:readonly" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:cpp-client-only" + ] + } + ], + "result": { + "name": "cecState", + "schema": { + "type": "string", + "enum": [ + "active", + "inactive", + "unsupported" + ] + } + }, + "examples": [ + { + "name": "Getting CEC state", + "params": [], + "result": { + "name": "Default Result", + "value": "inactive" + } + } + ] + }, + { + "name": "VideoOutput.refreshRate", + "summary": "Returns refresh rate for the active video output", + "params": [], + "tags": [ + { + "name": "property:readonly" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:cpp-client-only" + ] + } + ], + "result": { + "name": "refreshRate", + "schema": { + "type": "number", + "enum": [ + 0, + 23.976, + 24, + 25, + 29.97, + 30, + 50, + 59.94, + 60 + ] + } + }, + "examples": [ + { + "name": "Getting refresh rate", + "params": [], + "result": { + "name": "Default Result", + "value": 59.94 + } + } + ] + }, + { + "name": "VideoOutput.colorDepth", + "summary": "Returns color depth for the active video output", + "params": [], + "result": {"name": "colorDepth", "schema": {"type": "integer", "enum": [0, 8, 10, 12]}}, + "examples": [{"name": "Getting color depth", "params": [], "result": {"name": "Default Result", "value": 8}}] + }, + { + "name": "VideoOutput.colorFormat", + "summary": "Returns color format for the active video output", + "params": [], + "result": {"name": "colorFormat", "schema": {"type": "string", "enum": ["ycbcr420", "ycbcr422", "ycbcr444", "rgb444", "none"]}}, + "examples": [{"name": "Getting color format", "params": [], "result": {"name": "Default Result", "value": "ycbcr422"}}] + }, + { + "name": "VideoOutput.colorimetry", + "summary": "Returns colorimetry for the active video output", + "params": [], + "result": {"name": "colorimetry", "schema": {"type": "string", "enum": ["bt2020rgb", "bt2020ycc", "bt709", "oprgb", "none"]}}, + "examples": [{"name": "Getting colorimetry", "params": [], "result": {"name": "Default Result", "value": "bt709"}}] + }, + { + "name": "VideoOutput.dynamicRange", + "summary": "Returns dynamic range for the active video output", + "params": [], + "result": {"name": "dynamicRange", "schema": {"type": "string", "enum": ["hdr10", "hdr10plus", "dolbyVision", "hlg", "sdr", "none"]}}, + "examples": [{"name": "Getting dynamic range", "params": [], "result": {"name": "Default Result", "value": "sdr"}}] + }, + { + "name": "VideoOutput.quantizationRange", + "summary": "Returns quantization range for the active video output", + "params": [], + "result": {"name": "quantizationRange", "schema": {"type": "string", "enum": ["limited", "full", "none"]}}, + "examples": [{"name": "Getting quantization range", "params": [], "result": {"name": "Default Result", "value": "limited"}}] + }, + { + "name": "VideoOutput.onHdcpChanged", + "summary": "Returns HDCP state changes for the active video output", + "params": [ + { + "name": "listen", + "schema": { + "type": "boolean" + } + } + ], + "tags": [ + { + "name": "event", + "x-notifier": "VideoOutput.onHdcpChanged", + "x-subscriber-for": "VideoOutput.hdcp" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:cpp-client-only" + ] + } + ], + "examples": [ + { + "name": "Getting HDCP state change notifications", + "params": [ + { + "name": "listen", + "value": true + } + ], + "result": { + "name": "result", + "value": null + } + } + ], + "result": { + "name": "result", + "schema": { + "type": "string", + "enum": [ + "hdcp1.4", + "hdcp2.2", + "none", + "direct" + ] + } + } + }, + { + "name": "VideoOutput.onCecStateChanged", + "summary": "Returns CEC state changes for the active video output", + "params": [ + { + "name": "listen", + "schema": { + "type": "boolean" + } + } + ], + "tags": [ + { + "name": "event", + "x-notifier": "VideoOutput.onCecStateChanged", + "x-subscriber-for": "VideoOutput.cecState" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:cpp-client-only" + ] + } + ], + "examples": [ + { + "name": "Getting CEC state change notifications", + "params": [ + { + "name": "listen", + "value": true + } + ], + "result": { + "name": "result", + "value": null + } + } + ], + "result": { + "name": "result", + "schema": { + "type": "string", + "enum": [ + "active", + "inactive", + "unsupported" + ] + } + } + }, + { + "name": "VideoOutput.onRefreshRateChanged", + "summary": "Returns refresh rate changes for the active video output", + "params": [ + { + "name": "listen", + "schema": { + "type": "boolean" + } + } + ], + "tags": [ + { + "name": "event", + "x-notifier": "VideoOutput.onRefreshRateChanged", + "x-subscriber-for": "VideoOutput.refreshRate" + }, + { + "name": "capabilities", + "x-uses": [ + "xrn:firebolt:capability:cpp-client-only" + ] + } + ], + "examples": [ + { + "name": "Getting refresh rate change notifications", + "params": [ + { + "name": "listen", + "value": true + } + ], + "result": { + "name": "result", + "value": null + } + } + ], + "result": { + "name": "result", + "schema": { + "type": "string", + "enum": [ + "0", + "23.976", + "24", + "25", + "29.97", + "30", + "50", + "59.94", + "60" + ] + } + } + }, { "name": "Localization.onCountryChanged", "tags": [ diff --git a/include/firebolt/videooutput.h b/include/firebolt/videooutput.h index 4833e74..24b6538 100644 --- a/include/firebolt/videooutput.h +++ b/include/firebolt/videooutput.h @@ -16,9 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 */ // -// ============================================================================ -// AUTO-GENERATED by firebolt-sdk-gen v0.1.0 — DO NOT EDIT -// ============================================================================ #ifndef FIREBOLT_VIDEOOUTPUT_H #define FIREBOLT_VIDEOOUTPUT_H diff --git a/src/device_impl.cpp b/src/device_impl.cpp index 9d899c7..adee10b 100644 --- a/src/device_impl.cpp +++ b/src/device_impl.cpp @@ -44,7 +44,9 @@ Result DeviceImpl::osName() const Result DeviceImpl::setOsName(const std::string& osName) { - return helper_.invoke("Device.setOsName", nlohmann::json(osName)); + nlohmann::json params; + params["value"] = osName; + return helper_.invoke("Device.setOsName", params); } Result DeviceImpl::osVersion() const @@ -54,7 +56,9 @@ Result DeviceImpl::osVersion() const Result DeviceImpl::setOsVersion(const std::string& osVersion) { - return helper_.invoke("Device.setOsVersion", nlohmann::json(osVersion)); + nlohmann::json params; + params["value"] = osVersion; + return helper_.invoke("Device.setOsVersion", params); } Result DeviceImpl::firmware() const diff --git a/src/json_types/videooutput.h b/src/json_types/videooutput.h index 9cc1398..99c2176 100644 --- a/src/json_types/videooutput.h +++ b/src/json_types/videooutput.h @@ -16,13 +16,11 @@ * SPDX-License-Identifier: Apache-2.0 */ // -// ============================================================================ -// AUTO-GENERATED by firebolt-sdk-gen v0.1.0 — DO NOT EDIT -// ============================================================================ #ifndef FIREBOLT_VIDEOOUTPUT_JSON_H #define FIREBOLT_VIDEOOUTPUT_JSON_H #include "firebolt/videooutput.h" +#include #include #include @@ -155,6 +153,193 @@ inline const Firebolt::JSON::EnumType<::Firebolt::VideoOutput::RefreshRateValue> {"60", ::Firebolt::VideoOutput::RefreshRateValue::R60}, }); +class CecStateValueJson : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::CecStateValue> +{ +public: + void fromJson(const nlohmann::json& json) override + { + cecStateValue_ = CecStateValueEnum.at(json.get()); + } + [[nodiscard]] ::Firebolt::VideoOutput::CecStateValue value() const override { return cecStateValue_; } + +private: + ::Firebolt::VideoOutput::CecStateValue cecStateValue_; +}; + +class ColorDepthValueJson : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::ColorDepthValue> +{ +public: + void fromJson(const nlohmann::json& json) override + { + if (json.is_string()) + { + colorDepthValue_ = ColorDepthValueEnum.at(json.get()); + return; + } + + if (json.is_number_integer() || json.is_number_unsigned()) + { + const auto value = json.get(); + switch (value) + { + case 0: + colorDepthValue_ = ::Firebolt::VideoOutput::ColorDepthValue::D0; + return; + case 8: + colorDepthValue_ = ::Firebolt::VideoOutput::ColorDepthValue::D8; + return; + case 10: + colorDepthValue_ = ::Firebolt::VideoOutput::ColorDepthValue::D10; + return; + case 12: + colorDepthValue_ = ::Firebolt::VideoOutput::ColorDepthValue::D12; + return; + default: + throw std::out_of_range("Unsupported color depth value"); + } + } + + throw std::invalid_argument("ColorDepthValue must be a string or integer"); + } + [[nodiscard]] ::Firebolt::VideoOutput::ColorDepthValue value() const override { return colorDepthValue_; } + +private: + ::Firebolt::VideoOutput::ColorDepthValue colorDepthValue_; +}; + +class ColorFormatValueJson : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::ColorFormatValue> +{ +public: + void fromJson(const nlohmann::json& json) override + { + colorFormatValue_ = ColorFormatValueEnum.at(json.get()); + } + [[nodiscard]] ::Firebolt::VideoOutput::ColorFormatValue value() const override { return colorFormatValue_; } + +private: + ::Firebolt::VideoOutput::ColorFormatValue colorFormatValue_; +}; + +class DynamicRangeValueJson : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::DynamicRangeValue> +{ +public: + void fromJson(const nlohmann::json& json) override + { + dynamicRangeValue_ = DynamicRangeValueEnum.at(json.get()); + } + [[nodiscard]] ::Firebolt::VideoOutput::DynamicRangeValue value() const override { return dynamicRangeValue_; } + +private: + ::Firebolt::VideoOutput::DynamicRangeValue dynamicRangeValue_; +}; + +class HdcpStateJson : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::HdcpState> +{ +public: + void fromJson(const nlohmann::json& json) override { hdcpState_ = HdcpStateEnum.at(json.get()); } + [[nodiscard]] ::Firebolt::VideoOutput::HdcpState value() const override { return hdcpState_; } + +private: + ::Firebolt::VideoOutput::HdcpState hdcpState_; +}; + +class OutputColorimetryJson : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::OutputColorimetry> +{ +public: + void fromJson(const nlohmann::json& json) override + { + outputColorimetry_ = OutputColorimetryEnum.at(json.get()); + } + [[nodiscard]] ::Firebolt::VideoOutput::OutputColorimetry value() const override { return outputColorimetry_; } + +private: + ::Firebolt::VideoOutput::OutputColorimetry outputColorimetry_; +}; + +class QuantizationRangeValueJson : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::QuantizationRangeValue> +{ +public: + void fromJson(const nlohmann::json& json) override + { + quantizationRangeValue_ = QuantizationRangeValueEnum.at(json.get()); + } + [[nodiscard]] ::Firebolt::VideoOutput::QuantizationRangeValue value() const override + { + return quantizationRangeValue_; + } + +private: + ::Firebolt::VideoOutput::QuantizationRangeValue quantizationRangeValue_; +}; + +class RefreshRateValueJson : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::RefreshRateValue> +{ +public: + void fromJson(const nlohmann::json& json) override + { + if (json.is_string()) + { + refreshRateValue_ = RefreshRateValueEnum.at(json.get()); + return; + } + + if (json.is_number_integer() || json.is_number_unsigned()) + { + const auto value = json.get(); + switch (value) + { + case 0: + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R0; + return; + case 24: + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R24; + return; + case 25: + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R25; + return; + case 30: + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R30; + return; + case 50: + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R50; + return; + case 60: + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R60; + return; + default: + throw std::out_of_range("Unsupported refresh rate value"); + } + } + + if (json.is_number_float()) + { + const auto value = json.get(); + if (std::fabs(value - 23.976) < 0.001) + { + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R23976; + return; + } + if (std::fabs(value - 29.97) < 0.001) + { + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R2997; + return; + } + if (std::fabs(value - 59.94) < 0.001) + { + refreshRateValue_ = ::Firebolt::VideoOutput::RefreshRateValue::R5994; + return; + } + throw std::out_of_range("Unsupported refresh rate value"); + } + + throw std::invalid_argument("RefreshRateValue must be a string or number"); + } + [[nodiscard]] ::Firebolt::VideoOutput::RefreshRateValue value() const override { return refreshRateValue_; } + +private: + ::Firebolt::VideoOutput::RefreshRateValue refreshRateValue_; +}; + class VideoOutputResolution : public Firebolt::JSON::NL_Json_Basic<::Firebolt::VideoOutput::VideoOutputResolution> { public: diff --git a/src/videooutput_impl.cpp b/src/videooutput_impl.cpp index 73242b3..90feb33 100644 --- a/src/videooutput_impl.cpp +++ b/src/videooutput_impl.cpp @@ -16,9 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 */ // -// ============================================================================ -// AUTO-GENERATED by firebolt-sdk-gen v0.1.0 — DO NOT EDIT -// ============================================================================ #include "videooutput_impl.h" #include "json_types/videooutput.h" #include @@ -44,60 +41,57 @@ VideoOutputImpl::subscribeOnResolutionChanged(std::function VideoOutputImpl::hdcp() const { - return helper_.get, HdcpState>("VideoOutput.hdcp"); + return helper_.get("VideoOutput.hdcp"); } Result VideoOutputImpl::subscribeOnHdcpChanged(std::function&& notification) { - return subscriptionManager_.subscribe>("VideoOutput.onHdcpChanged", - std::move(notification)); + return subscriptionManager_.subscribe("VideoOutput.onHdcpChanged", std::move(notification)); } Result VideoOutputImpl::cecState() const { - return helper_.get, CecStateValue>("VideoOutput.cecState"); + return helper_.get("VideoOutput.cecState"); } Result VideoOutputImpl::subscribeOnCecStateChanged(std::function&& notification) { - return subscriptionManager_.subscribe>("VideoOutput.onCecStateChanged", - std::move(notification)); + return subscriptionManager_.subscribe("VideoOutput.onCecStateChanged", + std::move(notification)); } Result VideoOutputImpl::refreshRate() const { - return helper_.get, RefreshRateValue>("VideoOutput.refreshRate"); + return helper_.get("VideoOutput.refreshRate"); } Result VideoOutputImpl::subscribeOnRefreshRateChanged(std::function&& notification) { - return subscriptionManager_ - .subscribe>("VideoOutput.onRefreshRateChanged", - std::move(notification)); + return subscriptionManager_.subscribe("VideoOutput.onRefreshRateChanged", + std::move(notification)); } Result VideoOutputImpl::colorDepth() const { - return helper_.get, ColorDepthValue>("VideoOutput.colorDepth"); + return helper_.get("VideoOutput.colorDepth"); } Result VideoOutputImpl::colorFormat() const { - return helper_.get, ColorFormatValue>("VideoOutput.colorFormat"); + return helper_.get("VideoOutput.colorFormat"); } Result VideoOutputImpl::colorimetry() const { - return helper_.get, OutputColorimetry>("VideoOutput.colorimetry"); + return helper_.get("VideoOutput.colorimetry"); } Result VideoOutputImpl::dynamicRange() const { - return helper_.get, DynamicRangeValue>("VideoOutput.dynamicRange"); + return helper_.get("VideoOutput.dynamicRange"); } Result VideoOutputImpl::quantizationRange() const { - return helper_.get, QuantizationRangeValue>( - "VideoOutput.quantizationRange"); + return helper_.get("VideoOutput.quantizationRange"); } Result VideoOutputImpl::unsubscribe(SubscriptionId id) diff --git a/test/component/videooutputGeneratedTest.cpp b/test/component/videooutputGeneratedTest.cpp index b2f9958..bea855b 100644 --- a/test/component/videooutputGeneratedTest.cpp +++ b/test/component/videooutputGeneratedTest.cpp @@ -16,21 +16,230 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "firebolt/firebolt.h" #include "firebolt/videooutput.h" +#include "json_engine.h" +#include "json_types/videooutput.h" +#include "utils.h" +#include #include +#include -TEST(VideooutputGeneratedCTest, InterfaceSurfaceHasresolution) +class VideooutputGeneratedRuntimeCTest : public ::testing::Test { - using Interface = Firebolt::VideoOutput::IVideoOutput; - auto ptr = &Interface::resolution; - (void)ptr; - SUCCEED(); +protected: + void SetUp() override { eventReceived = false; } + + void resetEventState() + { + std::lock_guard lock(mtx); + eventReceived = false; + } + + std::condition_variable cv; + std::mutex mtx; + bool eventReceived{false}; + JsonEngine jsonEngine; +}; + +TEST(VideooutputGeneratedCTest, HdcpMarshallerParsesWireString) +{ + Firebolt::VideoOutput::JsonData::HdcpStateJson jsonType; + jsonType.fromJson(nlohmann::json("hdcp1.4")); + + EXPECT_EQ(jsonType.value(), Firebolt::VideoOutput::HdcpState::Hdcp14); +} + +TEST(VideooutputGeneratedCTest, CecStateMarshallerParsesWireString) +{ + Firebolt::VideoOutput::JsonData::CecStateValueJson jsonType; + jsonType.fromJson(nlohmann::json("inactive")); + + EXPECT_EQ(jsonType.value(), Firebolt::VideoOutput::CecStateValue::Inactive); +} + +TEST(VideooutputGeneratedCTest, ColorFormatMarshallerParsesWireString) +{ + Firebolt::VideoOutput::JsonData::ColorFormatValueJson jsonType; + jsonType.fromJson(nlohmann::json("ycbcr422")); + + EXPECT_EQ(jsonType.value(), Firebolt::VideoOutput::ColorFormatValue::Ycbcr422); +} + +TEST(VideooutputGeneratedCTest, DynamicRangeMarshallerParsesWireString) +{ + Firebolt::VideoOutput::JsonData::DynamicRangeValueJson jsonType; + jsonType.fromJson(nlohmann::json("sdr")); + + EXPECT_EQ(jsonType.value(), Firebolt::VideoOutput::DynamicRangeValue::Sdr); +} + +TEST(VideooutputGeneratedCTest, QuantizationRangeMarshallerParsesWireString) +{ + Firebolt::VideoOutput::JsonData::QuantizationRangeValueJson jsonType; + jsonType.fromJson(nlohmann::json("limited")); + + EXPECT_EQ(jsonType.value(), Firebolt::VideoOutput::QuantizationRangeValue::Limited); +} + +TEST(VideooutputGeneratedCTest, RefreshRateMarshallerParsesWireString) +{ + Firebolt::VideoOutput::JsonData::RefreshRateValueJson jsonType; + jsonType.fromJson(nlohmann::json("59.94")); + + EXPECT_EQ(jsonType.value(), Firebolt::VideoOutput::RefreshRateValue::R5994); +} + +TEST(VideooutputGeneratedCTest, MarshallersRejectUnknownWireValues) +{ + Firebolt::VideoOutput::JsonData::HdcpStateJson hdcpJson; + Firebolt::VideoOutput::JsonData::CecStateValueJson cecStateJson; + Firebolt::VideoOutput::JsonData::ColorFormatValueJson colorFormatJson; + Firebolt::VideoOutput::JsonData::DynamicRangeValueJson dynamicRangeJson; + Firebolt::VideoOutput::JsonData::QuantizationRangeValueJson quantizationRangeJson; + Firebolt::VideoOutput::JsonData::RefreshRateValueJson refreshRateJson; + Firebolt::VideoOutput::JsonData::ColorDepthValueJson colorDepthJson; + + EXPECT_THROW(hdcpJson.fromJson(nlohmann::json("hdcp3.0")), std::out_of_range); + EXPECT_THROW(cecStateJson.fromJson(nlohmann::json("not-a-state")), std::out_of_range); + EXPECT_THROW(colorFormatJson.fromJson(nlohmann::json("xyz")), std::out_of_range); + EXPECT_THROW(dynamicRangeJson.fromJson(nlohmann::json("hdr11")), std::out_of_range); + EXPECT_THROW(quantizationRangeJson.fromJson(nlohmann::json("super")), std::out_of_range); + EXPECT_THROW(refreshRateJson.fromJson(nlohmann::json("61")), std::out_of_range); + EXPECT_THROW(refreshRateJson.fromJson(nlohmann::json(59)), std::out_of_range); + EXPECT_THROW(colorDepthJson.fromJson(nlohmann::json("11")), std::out_of_range); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, ResolutionReturnsParsedValue) +{ + const auto expected = jsonEngine.get_value("VideoOutput.resolution"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().resolution(); + + ASSERT_TRUE(result) << "VideoOutputImpl::resolution() returned an error"; + EXPECT_EQ(result->height, expected.at("height").get()); + EXPECT_EQ(result->width, expected.at("width").get()); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, HdcpReturnsParsedValue) +{ + const auto expected = jsonEngine.get_value("VideoOutput.hdcp"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().hdcp(); + + ASSERT_TRUE(result) << "VideoOutputImpl::hdcp() returned an error"; + EXPECT_EQ(*result, Firebolt::VideoOutput::JsonData::HdcpStateEnum.at(expected.get())); } -TEST(VideooutputGeneratedCTest, InterfaceSurfaceHascolorDepth) +TEST_F(VideooutputGeneratedRuntimeCTest, CecStateReturnsParsedValue) { - using Interface = Firebolt::VideoOutput::IVideoOutput; - auto ptr = &Interface::colorDepth; - (void)ptr; - SUCCEED(); + const auto expected = jsonEngine.get_value("VideoOutput.cecState"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().cecState(); + + ASSERT_TRUE(result) << "VideoOutputImpl::cecState() returned an error"; + EXPECT_EQ(*result, Firebolt::VideoOutput::JsonData::CecStateValueEnum.at(expected.get())); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, RefreshRateReturnsParsedNumericValue) +{ + const auto expected = jsonEngine.get_value("VideoOutput.refreshRate"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().refreshRate(); + + ASSERT_TRUE(result) << "VideoOutputImpl::refreshRate() returned an error"; + EXPECT_DOUBLE_EQ(expected.get(), 59.94); + EXPECT_EQ(*result, Firebolt::VideoOutput::RefreshRateValue::R5994); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, ColorDepthReturnsParsedNumericValue) +{ + const auto expected = jsonEngine.get_value("VideoOutput.colorDepth"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().colorDepth(); + + ASSERT_TRUE(result) << "VideoOutputImpl::colorDepth() returned an error"; + EXPECT_EQ(expected.get(), 8); + EXPECT_EQ(*result, Firebolt::VideoOutput::ColorDepthValue::D8); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, ColorFormatReturnsParsedValue) +{ + const auto expected = jsonEngine.get_value("VideoOutput.colorFormat"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().colorFormat(); + + ASSERT_TRUE(result) << "VideoOutputImpl::colorFormat() returned an error"; + EXPECT_EQ(*result, Firebolt::VideoOutput::JsonData::ColorFormatValueEnum.at(expected.get())); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, ColorimetryReturnsParsedValue) +{ + const auto expected = jsonEngine.get_value("VideoOutput.colorimetry"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().colorimetry(); + + ASSERT_TRUE(result) << "VideoOutputImpl::colorimetry() returned an error"; + EXPECT_EQ(*result, Firebolt::VideoOutput::JsonData::OutputColorimetryEnum.at(expected.get())); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, DynamicRangeReturnsParsedValue) +{ + const auto expected = jsonEngine.get_value("VideoOutput.dynamicRange"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().dynamicRange(); + + ASSERT_TRUE(result) << "VideoOutputImpl::dynamicRange() returned an error"; + EXPECT_EQ(*result, Firebolt::VideoOutput::JsonData::DynamicRangeValueEnum.at(expected.get())); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, QuantizationRangeReturnsParsedValue) +{ + const auto expected = jsonEngine.get_value("VideoOutput.quantizationRange"); + const auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().quantizationRange(); + + ASSERT_TRUE(result) << "VideoOutputImpl::quantizationRange() returned an error"; + EXPECT_EQ(*result, Firebolt::VideoOutput::JsonData::QuantizationRangeValueEnum.at(expected.get())); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, SubscribeOnHdcpChangedParsesWireStringPayload) +{ + auto id = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().subscribeOnHdcpChanged( + [&](const Firebolt::VideoOutput::HdcpState& value) + { + EXPECT_EQ(value, Firebolt::VideoOutput::HdcpState::Hdcp14); + { + std::lock_guard lock(mtx); + eventReceived = true; + } + cv.notify_one(); + }); + + verifyEventSubscription(id); + triggerEvent("VideoOutput.onHdcpChanged", R"("hdcp1.4")"); + verifyEventReceived(mtx, cv, eventReceived); + + resetEventState(); + triggerEvent("VideoOutput.onHdcpChanged", R"("invalid-hdcp")"); + verifyEventNotReceived(mtx, cv, eventReceived); + + auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().unsubscribe(id.value()); + verifyUnsubscribeResult(result); +} + +TEST_F(VideooutputGeneratedRuntimeCTest, SubscribeOnCecStateChangedParsesWireStringPayload) +{ + auto id = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().subscribeOnCecStateChanged( + [&](const Firebolt::VideoOutput::CecStateValue& value) + { + EXPECT_EQ(value, Firebolt::VideoOutput::CecStateValue::Inactive); + { + std::lock_guard lock(mtx); + eventReceived = true; + } + cv.notify_one(); + }); + + verifyEventSubscription(id); + triggerEvent("VideoOutput.onCecStateChanged", R"("inactive")"); + verifyEventReceived(mtx, cv, eventReceived); + + resetEventState(); + triggerEvent("VideoOutput.onCecStateChanged", R"("invalid-cec")"); + verifyEventNotReceived(mtx, cv, eventReceived); + + auto result = Firebolt::IFireboltAccessor::Instance().VideoOutputInterface().unsubscribe(id.value()); + verifyUnsubscribeResult(result); } diff --git a/test/unit/deviceTest.cpp b/test/unit/deviceTest.cpp index a90a1bc..c5f34cf 100644 --- a/test/unit/deviceTest.cpp +++ b/test/unit/deviceTest.cpp @@ -67,7 +67,9 @@ TEST_F(DeviceUTest, OsName) TEST_F(DeviceUTest, SetOsName) { - EXPECT_CALL(mockHelper, invoke("Device.setOsName", nlohmann::json("Linux"))) + nlohmann::json expectedParams; + expectedParams["value"] = "Linux"; + EXPECT_CALL(mockHelper, invoke("Device.setOsName", expectedParams)) .WillOnce(Invoke([](const std::string&, const nlohmann::json&) { return Firebolt::Result{Firebolt::Error::None}; })); @@ -88,7 +90,9 @@ TEST_F(DeviceUTest, OsVersion) TEST_F(DeviceUTest, SetOsVersion) { - EXPECT_CALL(mockHelper, invoke("Device.setOsVersion", nlohmann::json("5.15.0"))) + nlohmann::json expectedParams; + expectedParams["value"] = "5.15.0"; + EXPECT_CALL(mockHelper, invoke("Device.setOsVersion", expectedParams)) .WillOnce(Invoke([](const std::string&, const nlohmann::json&) { return Firebolt::Result{Firebolt::Error::None}; })); diff --git a/test/unit/videooutputGeneratedTest.cpp b/test/unit/videooutputGeneratedTest.cpp index 736ac6c..67b845a 100644 --- a/test/unit/videooutputGeneratedTest.cpp +++ b/test/unit/videooutputGeneratedTest.cpp @@ -59,7 +59,6 @@ TEST_F(VideooutputGeneratedUTest, Constructs) { SUCCEED(); } - TEST_F(VideooutputGeneratedUTest, UnsubscribeForwardsToHelper) { EXPECT_CALL(mockHelper, unsubscribe(7)).WillOnce(::testing::Return(Firebolt::Result{Firebolt::Error::None})); @@ -114,7 +113,7 @@ TEST_F(VideooutputGeneratedUTest, ResolutionReturnsInvalidParamsWhenPayloadIsMal TEST_F(VideooutputGeneratedUTest, HdcpReturnsParsedValue) { - expectGetterResponse("VideoOutput.hdcp", nlohmann::json(static_cast(Firebolt::VideoOutput::HdcpState::Hdcp22))); + expectGetterResponse("VideoOutput.hdcp", nlohmann::json("hdcp2.2")); auto result = impl.hdcp(); ASSERT_TRUE(result); @@ -130,10 +129,18 @@ TEST_F(VideooutputGeneratedUTest, HdcpForwardsTransportErrors) EXPECT_EQ(result.error(), Firebolt::Error::General); } +TEST_F(VideooutputGeneratedUTest, HdcpReturnsInvalidParamsWhenEnumValueIsUnknown) +{ + expectGetterResponse("VideoOutput.hdcp", nlohmann::json("hdcp3.0")); + + auto result = impl.hdcp(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + TEST_F(VideooutputGeneratedUTest, CecStateReturnsParsedValue) { - expectGetterResponse("VideoOutput.cecState", - nlohmann::json(static_cast(Firebolt::VideoOutput::CecStateValue::Inactive))); + expectGetterResponse("VideoOutput.cecState", nlohmann::json("inactive")); auto result = impl.cecState(); ASSERT_TRUE(result); @@ -149,16 +156,51 @@ TEST_F(VideooutputGeneratedUTest, CecStateForwardsTransportErrors) EXPECT_EQ(result.error(), Firebolt::Error::General); } +TEST_F(VideooutputGeneratedUTest, CecStateReturnsInvalidParamsWhenEnumValueIsUnknown) +{ + expectGetterResponse("VideoOutput.cecState", nlohmann::json("invalid-cec")); + + auto result = impl.cecState(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + TEST_F(VideooutputGeneratedUTest, RefreshRateReturnsParsedValue) { - expectGetterResponse("VideoOutput.refreshRate", - nlohmann::json(static_cast(Firebolt::VideoOutput::RefreshRateValue::R5994))); + expectGetterResponse("VideoOutput.refreshRate", nlohmann::json("59.94")); auto result = impl.refreshRate(); ASSERT_TRUE(result); EXPECT_EQ(*result, Firebolt::VideoOutput::RefreshRateValue::R5994); } +TEST_F(VideooutputGeneratedUTest, RefreshRateReturnsParsedValueWhenPayloadIsNumber) +{ + expectGetterResponse("VideoOutput.refreshRate", nlohmann::json(59.94)); + + auto result = impl.refreshRate(); + ASSERT_TRUE(result); + EXPECT_EQ(*result, Firebolt::VideoOutput::RefreshRateValue::R5994); +} + +TEST_F(VideooutputGeneratedUTest, RefreshRateReturnsInvalidParamsWhenPayloadIsUnsupportedInteger) +{ + expectGetterResponse("VideoOutput.refreshRate", nlohmann::json(59)); + + auto result = impl.refreshRate(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + +TEST_F(VideooutputGeneratedUTest, RefreshRateReturnsInvalidParamsWhenNumericValueIsUnknown) +{ + expectGetterResponse("VideoOutput.refreshRate", nlohmann::json(61)); + + auto result = impl.refreshRate(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + TEST_F(VideooutputGeneratedUTest, RefreshRateForwardsTransportErrors) { expectGetterTransportError("VideoOutput.refreshRate"); @@ -170,14 +212,31 @@ TEST_F(VideooutputGeneratedUTest, RefreshRateForwardsTransportErrors) TEST_F(VideooutputGeneratedUTest, ColorDepthReturnsParsedValue) { - expectGetterResponse("VideoOutput.colorDepth", - nlohmann::json(static_cast(Firebolt::VideoOutput::ColorDepthValue::D12))); + expectGetterResponse("VideoOutput.colorDepth", nlohmann::json("12")); auto result = impl.colorDepth(); ASSERT_TRUE(result); EXPECT_EQ(*result, Firebolt::VideoOutput::ColorDepthValue::D12); } +TEST_F(VideooutputGeneratedUTest, ColorDepthReturnsParsedValueWhenPayloadIsNumber) +{ + expectGetterResponse("VideoOutput.colorDepth", nlohmann::json(8)); + + auto result = impl.colorDepth(); + ASSERT_TRUE(result); + EXPECT_EQ(*result, Firebolt::VideoOutput::ColorDepthValue::D8); +} + +TEST_F(VideooutputGeneratedUTest, ColorDepthReturnsInvalidParamsWhenNumericValueIsUnknown) +{ + expectGetterResponse("VideoOutput.colorDepth", nlohmann::json(11)); + + auto result = impl.colorDepth(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + TEST_F(VideooutputGeneratedUTest, ColorDepthForwardsTransportErrors) { expectGetterTransportError("VideoOutput.colorDepth"); @@ -189,8 +248,7 @@ TEST_F(VideooutputGeneratedUTest, ColorDepthForwardsTransportErrors) TEST_F(VideooutputGeneratedUTest, ColorFormatReturnsParsedValue) { - expectGetterResponse("VideoOutput.colorFormat", - nlohmann::json(static_cast(Firebolt::VideoOutput::ColorFormatValue::Ycbcr444))); + expectGetterResponse("VideoOutput.colorFormat", nlohmann::json("ycbcr444")); auto result = impl.colorFormat(); ASSERT_TRUE(result); @@ -206,10 +264,18 @@ TEST_F(VideooutputGeneratedUTest, ColorFormatForwardsTransportErrors) EXPECT_EQ(result.error(), Firebolt::Error::General); } +TEST_F(VideooutputGeneratedUTest, ColorFormatReturnsInvalidParamsWhenEnumValueIsUnknown) +{ + expectGetterResponse("VideoOutput.colorFormat", nlohmann::json("invalid-format")); + + auto result = impl.colorFormat(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + TEST_F(VideooutputGeneratedUTest, ColorimetryReturnsParsedValue) { - expectGetterResponse("VideoOutput.colorimetry", - nlohmann::json(static_cast(Firebolt::VideoOutput::OutputColorimetry::Bt2020rgb))); + expectGetterResponse("VideoOutput.colorimetry", nlohmann::json("bt2020rgb")); auto result = impl.colorimetry(); ASSERT_TRUE(result); @@ -225,10 +291,18 @@ TEST_F(VideooutputGeneratedUTest, ColorimetryForwardsTransportErrors) EXPECT_EQ(result.error(), Firebolt::Error::General); } +TEST_F(VideooutputGeneratedUTest, ColorimetryReturnsInvalidParamsWhenEnumValueIsUnknown) +{ + expectGetterResponse("VideoOutput.colorimetry", nlohmann::json("invalid-colorimetry")); + + auto result = impl.colorimetry(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + TEST_F(VideooutputGeneratedUTest, DynamicRangeReturnsParsedValue) { - expectGetterResponse("VideoOutput.dynamicRange", - nlohmann::json(static_cast(Firebolt::VideoOutput::DynamicRangeValue::Hdr10plus))); + expectGetterResponse("VideoOutput.dynamicRange", nlohmann::json("hdr10plus")); auto result = impl.dynamicRange(); ASSERT_TRUE(result); @@ -244,10 +318,18 @@ TEST_F(VideooutputGeneratedUTest, DynamicRangeForwardsTransportErrors) EXPECT_EQ(result.error(), Firebolt::Error::General); } +TEST_F(VideooutputGeneratedUTest, DynamicRangeReturnsInvalidParamsWhenEnumValueIsUnknown) +{ + expectGetterResponse("VideoOutput.dynamicRange", nlohmann::json("invalid-range")); + + auto result = impl.dynamicRange(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + TEST_F(VideooutputGeneratedUTest, QuantizationRangeReturnsParsedValue) { - expectGetterResponse("VideoOutput.quantizationRange", - nlohmann::json(static_cast(Firebolt::VideoOutput::QuantizationRangeValue::Limited))); + expectGetterResponse("VideoOutput.quantizationRange", nlohmann::json("limited")); auto result = impl.quantizationRange(); ASSERT_TRUE(result); @@ -263,6 +345,15 @@ TEST_F(VideooutputGeneratedUTest, QuantizationRangeForwardsTransportErrors) EXPECT_EQ(result.error(), Firebolt::Error::General); } +TEST_F(VideooutputGeneratedUTest, QuantizationRangeReturnsInvalidParamsWhenEnumValueIsUnknown) +{ + expectGetterResponse("VideoOutput.quantizationRange", nlohmann::json("invalid-range")); + + auto result = impl.quantizationRange(); + ASSERT_FALSE(result); + EXPECT_EQ(result.error(), Firebolt::Error::InvalidParams); +} + TEST_F(VideooutputGeneratedUTest, SubscribeOnResolutionChangedForwardsAndDispatchesParsedPayload) { bool notified = false; @@ -336,7 +427,7 @@ TEST_F(VideooutputGeneratedUTest, SubscribeOnHdcpChangedForwardsAndDispatchesPar void (*callback)(void*, const nlohmann::json&)) { Firebolt::Helpers::SubscriptionData data{owner, eventName, std::move(notification)}; - callback(&data, nlohmann::json(static_cast(Firebolt::VideoOutput::HdcpState::Direct))); + callback(&data, nlohmann::json("direct")); return Firebolt::Result{11}; })); @@ -375,7 +466,7 @@ TEST_F(VideooutputGeneratedUTest, SubscribeOnCecStateChangedForwardsAndDispatche void (*callback)(void*, const nlohmann::json&)) { Firebolt::Helpers::SubscriptionData data{owner, eventName, std::move(notification)}; - callback(&data, nlohmann::json(static_cast(Firebolt::VideoOutput::CecStateValue::Active))); + callback(&data, nlohmann::json("active")); return Firebolt::Result{12}; })); @@ -414,7 +505,7 @@ TEST_F(VideooutputGeneratedUTest, SubscribeOnRefreshRateChangedForwardsAndDispat void (*callback)(void*, const nlohmann::json&)) { Firebolt::Helpers::SubscriptionData data{owner, eventName, std::move(notification)}; - callback(&data, nlohmann::json(static_cast(Firebolt::VideoOutput::RefreshRateValue::R24))); + callback(&data, nlohmann::json("24")); return Firebolt::Result{13}; }));