From 36bd0eb247873430c1a0fbcd88fa3e6d04a75a3d Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Tue, 9 Jun 2026 19:21:29 -0400 Subject: [PATCH] refactor(sonar): fix cpp:S125, cpp:S3261, cpp:S995, cpp:S6009, cpp:S3574, and cpp:S1186 --- .../display_device/windows/settings_utils.h | 4 +- .../display_device/windows/win_api_layer.h | 5 +- .../windows/win_api_layer_interface.h | 5 +- .../display_device/windows/win_api_utils.h | 8 +--- src/windows/settings_manager_apply.cpp | 1 + src/windows/settings_manager_revert.cpp | 1 + src/windows/settings_utils.cpp | 4 +- src/windows/win_api_layer.cpp | 9 ++-- src/windows/win_api_utils.cpp | 6 +-- src/windows/win_display_device_modes.cpp | 15 +++--- tests/unit/general/test_comparison.cpp | 4 +- tests/unit/general/test_edid_parsing.cpp | 4 +- tests/unit/general/test_json_converter.cpp | 4 +- tests/unit/general/test_logging.cpp | 5 +- tests/unit/general/test_retry_scheduler.cpp | 48 +++++++++++-------- tests/unit/windows/test_comparison.cpp | 4 +- tests/unit/windows/test_json_converter.cpp | 4 +- tests/unit/windows/test_win_api_utils.cpp | 34 +++++-------- .../windows/test_win_display_device_hdr.cpp | 2 +- tests/unit/windows/test_win_playground.cpp | 9 ---- tests/unit/windows/utils/helpers.cpp | 2 +- tests/unit/windows/utils/helpers.h | 2 +- tests/unit/windows/utils/mock_win_api_layer.h | 2 +- 23 files changed, 82 insertions(+), 100 deletions(-) diff --git a/src/windows/include/display_device/windows/settings_utils.h b/src/windows/include/display_device/windows/settings_utils.h index d6be1898..36e63bb7 100644 --- a/src/windows/include/display_device/windows/settings_utils.h +++ b/src/windows/include/display_device/windows/settings_utils.h @@ -36,7 +36,7 @@ namespace display_device::win_utils { * const auto extended_topology { stripTopologyOfUnavailableDevices(*iface) }; * @examples_end */ - ActiveTopology createFullExtendedTopology(WinDisplayDeviceInterface &win_dd); + ActiveTopology createFullExtendedTopology(const WinDisplayDeviceInterface &win_dd); /** * @brief Get one primary device from the provided topology. @@ -49,7 +49,7 @@ namespace display_device::win_utils { * const auto primary_device_id { getPrimaryDevice(*iface, topology) }; * @examples_end */ - std::string getPrimaryDevice(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); + std::string getPrimaryDevice(const WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); /** * @brief Compute the new intial state from arbitrary data. diff --git a/src/windows/include/display_device/windows/win_api_layer.h b/src/windows/include/display_device/windows/win_api_layer.h index fe8bb33a..be7b74cf 100644 --- a/src/windows/include/display_device/windows/win_api_layer.h +++ b/src/windows/include/display_device/windows/win_api_layer.h @@ -4,6 +4,9 @@ */ #pragma once +// system includes +#include + // local includes #include "win_api_layer_interface.h" @@ -44,6 +47,6 @@ namespace display_device { [[nodiscard]] bool setHdrState(const DISPLAYCONFIG_PATH_INFO &path, HdrState state) override; /** For details @see WinApiLayerInterface::getDisplayScale */ - [[nodiscard]] std::optional getDisplayScale(const std::string &display_name, const DISPLAYCONFIG_SOURCE_MODE &source_mode) const override; + [[nodiscard]] std::optional getDisplayScale(std::string_view display_name, const DISPLAYCONFIG_SOURCE_MODE &source_mode) const override; }; } // namespace display_device diff --git a/src/windows/include/display_device/windows/win_api_layer_interface.h b/src/windows/include/display_device/windows/win_api_layer_interface.h index c9e43d23..a40862c7 100644 --- a/src/windows/include/display_device/windows/win_api_layer_interface.h +++ b/src/windows/include/display_device/windows/win_api_layer_interface.h @@ -4,6 +4,9 @@ */ #pragma once +// system includes +#include + // local includes #include "types.h" @@ -195,6 +198,6 @@ namespace display_device { * const auto scale = iface->getDisplayScale(iface->getDisplayName(path), source_mode); * @examples_end */ - [[nodiscard]] virtual std::optional getDisplayScale(const std::string &display_name, const DISPLAYCONFIG_SOURCE_MODE &source_mode) const = 0; + [[nodiscard]] virtual std::optional getDisplayScale(std::string_view display_name, const DISPLAYCONFIG_SOURCE_MODE &source_mode) const = 0; }; } // namespace display_device diff --git a/src/windows/include/display_device/windows/win_api_utils.h b/src/windows/include/display_device/windows/win_api_utils.h index 6273c3db..f82a6490 100644 --- a/src/windows/include/display_device/windows/win_api_utils.h +++ b/src/windows/include/display_device/windows/win_api_utils.h @@ -6,6 +6,7 @@ // system includes #include +#include // local includes #include "win_api_layer_interface.h" @@ -202,12 +203,7 @@ namespace display_device::win_utils { * const DISPLAYCONFIG_PATH_INFO* active_path = get_active_path(*iface, "MY_DEVICE_ID", paths); * @examples_end */ - [[nodiscard]] const DISPLAYCONFIG_PATH_INFO *getActivePath(const WinApiLayerInterface &w_api, const std::string &device_id, const std::vector &paths); - - /** - * @see getActivePath (const version) for the description. - */ - [[nodiscard]] DISPLAYCONFIG_PATH_INFO *getActivePath(const WinApiLayerInterface &w_api, const std::string &device_id, std::vector &paths); + [[nodiscard]] const DISPLAYCONFIG_PATH_INFO *getActivePath(const WinApiLayerInterface &w_api, std::string_view device_id, const std::vector &paths); /** * @brief Collect arbitrary source data from provided paths. diff --git a/src/windows/settings_manager_apply.cpp b/src/windows/settings_manager_apply.cpp index 51d56862..d8ef53d5 100644 --- a/src/windows/settings_manager_apply.cpp +++ b/src/windows/settings_manager_apply.cpp @@ -20,6 +20,7 @@ namespace display_device { * @brief Function that does nothing. */ void noopFn() { + // Intentionally empty guard callback. } } // namespace diff --git a/src/windows/settings_manager_revert.cpp b/src/windows/settings_manager_revert.cpp index 327568c0..0e7dffdd 100644 --- a/src/windows/settings_manager_revert.cpp +++ b/src/windows/settings_manager_revert.cpp @@ -19,6 +19,7 @@ namespace display_device { * @brief Function that does nothing. */ void noopFn() { + // Intentionally empty guard callback. } } // namespace diff --git a/src/windows/settings_utils.cpp b/src/windows/settings_utils.cpp index 682e5fc2..e3558759 100644 --- a/src/windows/settings_utils.cpp +++ b/src/windows/settings_utils.cpp @@ -137,7 +137,7 @@ namespace display_device::win_utils { return flattened_topology; } - ActiveTopology createFullExtendedTopology(WinDisplayDeviceInterface &win_dd) { + ActiveTopology createFullExtendedTopology(const WinDisplayDeviceInterface &win_dd) { const auto devices {win_dd.enumAvailableDevices()}; if (devices.empty()) { DD_LOG(error) << "Failed to enumerate available devices for full extended topology!"; @@ -152,7 +152,7 @@ namespace display_device::win_utils { return topology; } - std::string getPrimaryDevice(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { + std::string getPrimaryDevice(const WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { const auto flat_topology {flattenTopology(topology)}; for (const auto &device_id : flat_topology) { if (win_dd.isPrimary(device_id)) { diff --git a/src/windows/win_api_layer.cpp b/src/windows/win_api_layer.cpp index e803182b..83bf35f2 100644 --- a/src/windows/win_api_layer.cpp +++ b/src/windows/win_api_layer.cpp @@ -14,6 +14,7 @@ #include #include #include +#include // local includes #include "display_device/logging.h" @@ -310,7 +311,7 @@ namespace display_device { * @param value The UTF-16 wide string. * @return The converted UTF-8 string. */ - std::string toUtf8(const WinApiLayerInterface &w_api, const std::wstring &value) { + std::string toUtf8(const WinApiLayerInterface &w_api, const std::wstring_view value) { // No conversion needed if the string is empty if (value.empty()) { return {}; @@ -637,10 +638,10 @@ namespace display_device { return true; } - std::optional WinApiLayer::getDisplayScale(const std::string &display_name, const DISPLAYCONFIG_SOURCE_MODE &source_mode) const { + std::optional WinApiLayer::getDisplayScale(const std::string_view display_name, const DISPLAYCONFIG_SOURCE_MODE &source_mode) const { // Note: implementation based on https://stackoverflow.com/a/74046173 struct EnumData { - std::string m_display_name; + std::string_view m_display_name; std::optional m_width; }; @@ -648,7 +649,7 @@ namespace display_device { EnumDisplayMonitors( nullptr, nullptr, - [](HMONITOR monitor, HDC, LPRECT, LPARAM user_data) -> BOOL { + [](HMONITOR monitor, HDC, LPRECT, LPARAM user_data) { auto *data = reinterpret_cast(user_data); if (data == nullptr) { // Sanity check diff --git a/src/windows/win_api_utils.cpp b/src/windows/win_api_utils.cpp index 7711ae3f..a888db9b 100644 --- a/src/windows/win_api_utils.cpp +++ b/src/windows/win_api_utils.cpp @@ -204,7 +204,7 @@ namespace display_device::win_utils { return ValidatedDeviceInfo {device_path, device_id}; } - const DISPLAYCONFIG_PATH_INFO *getActivePath(const WinApiLayerInterface &w_api, const std::string &device_id, const std::vector &paths) { + const DISPLAYCONFIG_PATH_INFO *getActivePath(const WinApiLayerInterface &w_api, const std::string_view device_id, const std::vector &paths) { for (const auto &path : paths) { const auto device_info {getDeviceInfoForValidPath(w_api, path, ValidatedPathType::Active)}; if (!device_info) { @@ -219,10 +219,6 @@ namespace display_device::win_utils { return nullptr; } - DISPLAYCONFIG_PATH_INFO *getActivePath(const WinApiLayerInterface &w_api, const std::string &device_id, std::vector &paths) { - return const_cast(getActivePath(w_api, device_id, const_cast &>(paths))); - } - PathSourceIndexDataMap collectSourceDataForMatchingPaths(const WinApiLayerInterface &w_api, const std::vector &paths) { PathSourceIndexDataMap path_data; diff --git a/src/windows/win_display_device_modes.cpp b/src/windows/win_display_device_modes.cpp index 68ca0abc..9c71f583 100644 --- a/src/windows/win_display_device_modes.cpp +++ b/src/windows/win_display_device_modes.cpp @@ -41,7 +41,8 @@ namespace display_device { return false; } - const auto source_mode {win_utils::getSourceMode(win_utils::getSourceIndex(*path, display_data->m_modes), display_data->m_modes)}; + auto &mutable_path {display_data->m_paths[static_cast(path - display_data->m_paths.data())]}; + const auto source_mode {win_utils::getSourceMode(win_utils::getSourceIndex(mutable_path, display_data->m_modes), display_data->m_modes)}; if (!source_mode) { DD_LOG(error) << "Active device does not have a source mode: " << device_id << "!"; return false; @@ -52,11 +53,11 @@ namespace display_device { bool refresh_rate_changed; if (strategy == Strategy::Relaxed) { - refresh_rate_changed = !win_utils::fuzzyCompareRefreshRates(Rational {path->targetInfo.refreshRate.Numerator, path->targetInfo.refreshRate.Denominator}, mode.m_refresh_rate); + refresh_rate_changed = !win_utils::fuzzyCompareRefreshRates(Rational {mutable_path.targetInfo.refreshRate.Numerator, mutable_path.targetInfo.refreshRate.Denominator}, mode.m_refresh_rate); } else { // Since we are in strict mode, do not fuzzy compare it - refresh_rate_changed = path->targetInfo.refreshRate.Numerator != mode.m_refresh_rate.m_numerator || - path->targetInfo.refreshRate.Denominator != mode.m_refresh_rate.m_denominator; + refresh_rate_changed = mutable_path.targetInfo.refreshRate.Numerator != mode.m_refresh_rate.m_numerator || + mutable_path.targetInfo.refreshRate.Denominator != mode.m_refresh_rate.m_denominator; } if (resolution_changed) { @@ -66,14 +67,14 @@ namespace display_device { } if (refresh_rate_changed) { - path->targetInfo.refreshRate = {mode.m_refresh_rate.m_numerator, mode.m_refresh_rate.m_denominator}; + mutable_path.targetInfo.refreshRate = {mode.m_refresh_rate.m_numerator, mode.m_refresh_rate.m_denominator}; new_changes = true; } if (new_changes) { // Clear the target index so that Windows has to select/modify the target to best match the requirements. - win_utils::setTargetIndex(*path, std::nullopt); - win_utils::setDesktopIndex(*path, std::nullopt); // Part of struct containing target index and so it needs to be cleared + win_utils::setTargetIndex(mutable_path, std::nullopt); + win_utils::setDesktopIndex(mutable_path, std::nullopt); // Part of struct containing target index and so it needs to be cleared } changes_applied = changes_applied || new_changes; diff --git a/tests/unit/general/test_comparison.cpp b/tests/unit/general/test_comparison.cpp index 131aebb3..1ff0edfe 100644 --- a/tests/unit/general/test_comparison.cpp +++ b/tests/unit/general/test_comparison.cpp @@ -2,10 +2,8 @@ #include "display_device/types.h" #include "fixtures/fixtures.h" -namespace { - // Specialized TEST macro(s) for this test file +// Specialized TEST macro(s) for this test file #define TEST_S(...) DD_MAKE_TEST(TEST, TypeComparison, __VA_ARGS__) -} // namespace TEST_S(Point) { EXPECT_EQ(display_device::Point({1, 1}), display_device::Point({1, 1})); diff --git a/tests/unit/general/test_edid_parsing.cpp b/tests/unit/general/test_edid_parsing.cpp index 2a003dbb..65e013b0 100644 --- a/tests/unit/general/test_edid_parsing.cpp +++ b/tests/unit/general/test_edid_parsing.cpp @@ -2,10 +2,8 @@ #include "display_device/types.h" #include "fixtures/fixtures.h" -namespace { - // Specialized TEST macro(s) for this test file +// Specialized TEST macro(s) for this test file #define TEST_S(...) DD_MAKE_TEST(TEST, EdidParsing, __VA_ARGS__) -} // namespace TEST_S(NoData) { EXPECT_EQ(display_device::EdidData::parse({}), std::nullopt); diff --git a/tests/unit/general/test_json_converter.cpp b/tests/unit/general/test_json_converter.cpp index b07d419a..6bf3c2ac 100644 --- a/tests/unit/general/test_json_converter.cpp +++ b/tests/unit/general/test_json_converter.cpp @@ -1,10 +1,8 @@ // local includes #include "fixtures/json_converter_test.h" -namespace { - // Specialized TEST macro(s) for this test file +// Specialized TEST macro(s) for this test file #define TEST_F_S(...) DD_MAKE_TEST(TEST_F, JsonConverterTest, __VA_ARGS__) -} // namespace TEST_F_S(EdidData) { display_device::EdidData item { diff --git a/tests/unit/general/test_logging.cpp b/tests/unit/general/test_logging.cpp index 1984497e..e678cac9 100644 --- a/tests/unit/general/test_logging.cpp +++ b/tests/unit/general/test_logging.cpp @@ -1,6 +1,7 @@ // system includes #include #include +#include // local includes #include "display_device/logging.h" @@ -106,7 +107,7 @@ TEST_S(DefaultLogger) { using level = display_device::Logger::LogLevel; auto &logger {display_device::Logger::get()}; - const auto write_and_get_cout {[this, &logger](level level, std::string value) -> std::string { + const auto write_and_get_cout {[this, &logger](level level, std::string value) { m_cout_buffer.str(std::string {}); // reset the buffer logger.write(level, std::move(value)); return m_cout_buffer.str(); @@ -130,7 +131,7 @@ TEST_S(CustomCallback) { std::string output; logger.setLogLevel(level::verbose); - logger.setCustomCallback([&output](const level level, const std::string &value) { + logger.setCustomCallback([&output](const level level, const std::string_view value) { output = std::format("{} {}", static_cast(level), value); }); diff --git a/tests/unit/general/test_retry_scheduler.cpp b/tests/unit/general/test_retry_scheduler.cpp index 1c7702cc..3f65f5cf 100644 --- a/tests/unit/general/test_retry_scheduler.cpp +++ b/tests/unit/general/test_retry_scheduler.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include // local includes #include "display_device/retry_scheduler.h" @@ -106,7 +108,7 @@ TEST_F_S(Schedule, SchedulingDurations) { std::this_thread::sleep_for(1ms); } - return m_impl.execute([](TestIface &iface) { + return m_impl.execute([](const TestIface &iface) { int sum {0}; for (const auto timing : iface.m_durations) { sum += timing; @@ -299,8 +301,8 @@ TEST_F_S(Schedule, ExceptionThrown, DuringImmediateCall) { } std::string output; - logger.setCustomCallback([&output](auto, const std::string &value) { - output = value; + logger.setCustomCallback([&output](auto, const std::string_view value) { + output = std::string {value}; }); EXPECT_TRUE(m_impl.isScheduled()); @@ -329,8 +331,8 @@ TEST_F_S(Schedule, ExceptionThrown, DuringScheduledCall) { auto &logger {display_device::Logger::get()}; std::string output; - logger.setCustomCallback([&output](auto, const std::string &value) { - output = value; + logger.setCustomCallback([&output](auto, const std::string_view value) { + output = std::string {value}; }); bool first_call {true}; @@ -530,7 +532,9 @@ TEST_F_S(Execute, ConstVsNonConst, WithoutStopToken) { const auto const_callback_auto = [](const auto &iface) { iface.constMethod(); }; - const auto non_const_callback_auto = [](auto &iface) { + const auto non_const_callback_auto = [](Iface &iface) + requires(!std::is_const_v) + { iface.nonConstMethod(); }; @@ -541,12 +545,12 @@ TEST_F_S(Execute, ConstVsNonConst, WithoutStopToken) { non_const_impl.execute(const_callback_auto); non_const_impl.execute(non_const_callback_auto); - // Verify it compiles with const (commented out code will not compile) + // Verify it compiles with const const auto &const_impl {m_impl}; const_impl.execute(const_callback); - // const_impl.execute(non_const_callback); + static_assert(!std::is_invocable_v); const_impl.execute(const_callback_auto); - // const_impl.execute(non_const_callback_auto); + static_assert(!std::is_invocable_v); } TEST_F_S(Execute, ConstVsNonConst, WithStopToken) { @@ -570,15 +574,21 @@ TEST_F_S(Execute, ConstVsNonConst, WithStopToken) { iface.constMethod(); (void) token.stopRequested(); }; - const auto const_non_const_callback_auto = [](const auto &iface, auto &token) { + const auto const_non_const_callback_auto = [](const Iface &iface, Token &token) + requires(!std::is_const_v) + { iface.constMethod(); token.requestStop(); }; - const auto non_const_const_callback_auto = [](auto &iface, const auto &token) { + const auto non_const_const_callback_auto = [](Iface &iface, const Token &token) + requires(!std::is_const_v) + { iface.nonConstMethod(); (void) token.stopRequested(); }; - const auto non_const_non_const_callback_auto = [](auto &iface, auto &token) { + const auto non_const_non_const_callback_auto = [](Iface &iface, Token &token) + requires(!std::is_const_v && !std::is_const_v) + { iface.nonConstMethod(); token.requestStop(); }; @@ -594,16 +604,16 @@ TEST_F_S(Execute, ConstVsNonConst, WithStopToken) { non_const_impl.execute(non_const_const_callback_auto); non_const_impl.execute(non_const_non_const_callback_auto); - // Verify it compiles with const (commented out code will not compile) + // Verify it compiles with const const auto &const_impl {m_impl}; const_impl.execute(const_const_callback); - // const_impl.execute(const_non_const_callback); - // const_impl.execute(non_const_const_callback); - // const_impl.execute(non_const_non_const_callback); + static_assert(!std::is_invocable_v); + static_assert(!std::is_invocable_v); + static_assert(!std::is_invocable_v); const_impl.execute(const_const_callback_auto); - // const_impl.execute(const_non_const_callback_auto); - // const_impl.execute(non_const_const_callback_auto); - // const_impl.execute(non_const_non_const_callback_auto); + static_assert(!std::is_invocable_v); + static_assert(!std::is_invocable_v); + static_assert(!std::is_invocable_v); } TEST_F_S(Stop) { diff --git a/tests/unit/windows/test_comparison.cpp b/tests/unit/windows/test_comparison.cpp index ba2cbe7d..df9dc2a9 100644 --- a/tests/unit/windows/test_comparison.cpp +++ b/tests/unit/windows/test_comparison.cpp @@ -2,10 +2,8 @@ #include "display_device/windows/types.h" #include "fixtures/fixtures.h" -namespace { - // Specialized TEST macro(s) for this test file +// Specialized TEST macro(s) for this test file #define TEST_S(...) DD_MAKE_TEST(TEST, TypeComparison, __VA_ARGS__) -} // namespace TEST_S(DisplayMode) { EXPECT_EQ(display_device::DisplayMode({1, 1}, {1, 1}), display_device::DisplayMode({1, 1}, {1, 1})); diff --git a/tests/unit/windows/test_json_converter.cpp b/tests/unit/windows/test_json_converter.cpp index f239ac94..c9da3752 100644 --- a/tests/unit/windows/test_json_converter.cpp +++ b/tests/unit/windows/test_json_converter.cpp @@ -3,10 +3,8 @@ #include "fixtures/json_converter_test.h" #include "utils/comparison.h" -namespace { - // Specialized TEST macro(s) for this test file +// Specialized TEST macro(s) for this test file #define TEST_F_S(...) DD_MAKE_TEST(TEST_F, JsonConverterTest, __VA_ARGS__) -} // namespace TEST_F_S(ActiveTopology) { executeTestCase(display_device::ActiveTopology {}, R"([])"); diff --git a/tests/unit/windows/test_win_api_utils.cpp b/tests/unit/windows/test_win_api_utils.cpp index 1cdf5f98..735125e3 100644 --- a/tests/unit/windows/test_win_api_utils.cpp +++ b/tests/unit/windows/test_win_api_utils.cpp @@ -424,55 +424,45 @@ TEST_F_S_MOCKED(GetDeviceInfo, UnavailablePath, ActivePath) { TEST_F_S_MOCKED(GetActivePath, InstantMatch) { EXPECT_CALL(m_layer, getMonitorDevicePath(_)) - .Times(2) + .Times(1) .WillRepeatedly(Return("Path1")); EXPECT_CALL(m_layer, getDisplayName(_)) - .Times(2) + .Times(1) .WillRepeatedly(Return("DisplayNameX")); EXPECT_CALL(m_layer, getDeviceId(_)) - .Times(2) + .Times(1) .WillRepeatedly(Return("DeviceId1")); - auto *path {display_device::win_utils::getActivePath(m_layer, "DeviceId1", const_cast &>(PATHS_WITH_SOURCE_IDS))}; - auto *const_path {display_device::win_utils::getActivePath(m_layer, "DeviceId1", PATHS_WITH_SOURCE_IDS)}; + const auto *path {display_device::win_utils::getActivePath(m_layer, "DeviceId1", PATHS_WITH_SOURCE_IDS)}; - EXPECT_EQ(path, const_path); EXPECT_EQ(path, &PATHS_WITH_SOURCE_IDS.at(0)); } TEST_F_S_MOCKED(GetActivePath, SecondMatch) { EXPECT_CALL(m_layer, getMonitorDevicePath(_)) - .Times(4) - .WillOnce(Return("Path1")) - .WillOnce(Return("Path2")) + .Times(2) .WillOnce(Return("Path1")) .WillOnce(Return("Path2")); EXPECT_CALL(m_layer, getDisplayName(_)) - .Times(4) + .Times(2) .WillRepeatedly(Return("DisplayNameX")); EXPECT_CALL(m_layer, getDeviceId(_)) - .Times(4) - .WillOnce(Return("DeviceId1")) - .WillOnce(Return("DeviceId2")) + .Times(2) .WillOnce(Return("DeviceId1")) .WillOnce(Return("DeviceId2")); - auto *path {display_device::win_utils::getActivePath(m_layer, "DeviceId2", const_cast &>(PATHS_WITH_SOURCE_IDS))}; - auto *const_path {display_device::win_utils::getActivePath(m_layer, "DeviceId2", PATHS_WITH_SOURCE_IDS)}; + const auto *path {display_device::win_utils::getActivePath(m_layer, "DeviceId2", PATHS_WITH_SOURCE_IDS)}; - EXPECT_EQ(path, const_path); EXPECT_EQ(path, &PATHS_WITH_SOURCE_IDS.at(1)); } TEST_F_S_MOCKED(GetActivePath, NoMatch) { EXPECT_CALL(m_layer, getMonitorDevicePath(_)) - .Times(4) - .WillOnce(Return("")); + .Times(2) + .WillRepeatedly(Return("")); - auto *path {display_device::win_utils::getActivePath(m_layer, "DeviceId1", const_cast &>(PATHS_WITH_SOURCE_IDS))}; - auto *const_path {display_device::win_utils::getActivePath(m_layer, "DeviceId1", PATHS_WITH_SOURCE_IDS)}; + const auto *path {display_device::win_utils::getActivePath(m_layer, "DeviceId1", PATHS_WITH_SOURCE_IDS)}; - EXPECT_EQ(path, const_path); EXPECT_EQ(path, nullptr); } @@ -827,8 +817,6 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToQueryDevices) { } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, EmptyDeviceIdInProvidedList) { - // InSequence sequence; - // setupExpectCallFor4ActivePathsAndModes(display_device::QueryType::Active, sequence); EXPECT_CALL(m_layer, queryDisplayConfig(display_device::QueryType::Active)) .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)); diff --git a/tests/unit/windows/test_win_display_device_hdr.cpp b/tests/unit/windows/test_win_display_device_hdr.cpp index 7db2d874..4def3d5a 100644 --- a/tests/unit/windows/test_win_display_device_hdr.cpp +++ b/tests/unit/windows/test_win_display_device_hdr.cpp @@ -77,7 +77,7 @@ TEST_F_S(GetSetHdrStates) { ASSERT_TRUE(m_win_dd.setTopology(makeExtendedTopology(*available_devices))); const auto hdr_states {m_win_dd.getCurrentHdrStates(display_device::win_utils::flattenTopology(m_win_dd.getCurrentTopology()))}; - if (!std::ranges::any_of(hdr_states, [](auto entry) -> bool { + if (!std::ranges::any_of(hdr_states, [](auto entry) { return static_cast(entry.second); })) { GTEST_SKIP_("No HDR display is available in the system."); diff --git a/tests/unit/windows/test_win_playground.cpp b/tests/unit/windows/test_win_playground.cpp index f87bbb91..d70e1082 100644 --- a/tests/unit/windows/test_win_playground.cpp +++ b/tests/unit/windows/test_win_playground.cpp @@ -46,20 +46,11 @@ namespace { } // namespace TEST_F_S(EnumAvailableDevices) { - // Usage example: - // test_libdisplaydevice.exe --gtest_color=yes --gtest_also_run_disabled_tests --gtest_filter=*WinPlayground.EnumAvailableDevices - DD_LOG(info) << "enumerated devices:\n" << toJson(getImpl().enumAvailableDevices()); } TEST_F_S(ApplySettings) { - // Usage example: - // test_libdisplaydevice.exe --gtest_color=yes --gtest_also_run_disabled_tests --gtest_filter=*WinPlayground.ApplySettings config='{\"device_id\":\"{77f67f3e-754f-5d31-af64-ee037e18100a}\",\"device_prep\":\"EnsureActive\",\"hdr_state\":null,\"refresh_rate\":null,\"resolution\":null}' - // - // With workarounds (optional): - // test_libdisplaydevice.exe --gtest_color=yes --gtest_also_run_disabled_tests --gtest_filter=*WinPlayground.ApplySettings config='...' workarounds='{\"hdr_blank_delay\":500}' - const auto config_arg {getArgWithMatchingPattern(R"(^config=)", true)}; if (!config_arg) { GTEST_FAIL() << "\"config=\" argument not found!"; diff --git a/tests/unit/windows/utils/helpers.cpp b/tests/unit/windows/utils/helpers.cpp index 0e6e55c5..1f2cc53d 100644 --- a/tests/unit/windows/utils/helpers.cpp +++ b/tests/unit/windows/utils/helpers.cpp @@ -4,7 +4,7 @@ // local includes #include "display_device/windows/json.h" -std::optional> getAvailableDevices(display_device::WinApiLayer &layer, const bool only_valid_output) { +std::optional> getAvailableDevices(const display_device::WinApiLayer &layer, const bool only_valid_output) { const auto all_devices {layer.queryDisplayConfig(display_device::QueryType::All)}; if (!all_devices) { return std::nullopt; diff --git a/tests/unit/windows/utils/helpers.h b/tests/unit/windows/utils/helpers.h index 0a9aff5a..ae631287 100644 --- a/tests/unit/windows/utils/helpers.h +++ b/tests/unit/windows/utils/helpers.h @@ -8,6 +8,6 @@ #include "display_device/windows/win_api_layer.h" // Generic helper functions -std::optional> getAvailableDevices(display_device::WinApiLayer &layer, bool only_valid_output = true); +std::optional> getAvailableDevices(const display_device::WinApiLayer &layer, bool only_valid_output = true); std::optional> serializeState(const std::optional &state); diff --git a/tests/unit/windows/utils/mock_win_api_layer.h b/tests/unit/windows/utils/mock_win_api_layer.h index 1c5edbf7..871e742d 100644 --- a/tests/unit/windows/utils/mock_win_api_layer.h +++ b/tests/unit/windows/utils/mock_win_api_layer.h @@ -19,7 +19,7 @@ namespace display_device { MOCK_METHOD(LONG, setDisplayConfig, (std::vector, std::vector, UINT32), (override)); MOCK_METHOD(std::optional, getHdrState, (const DISPLAYCONFIG_PATH_INFO &), (const, override)); MOCK_METHOD(bool, setHdrState, (const DISPLAYCONFIG_PATH_INFO &, HdrState), (override)); - MOCK_METHOD(std::optional, getDisplayScale, (const std::string &, const DISPLAYCONFIG_SOURCE_MODE &), (const, override)); + MOCK_METHOD(std::optional, getDisplayScale, (std::string_view, const DISPLAYCONFIG_SOURCE_MODE &), (const, override)); }; } // namespace display_device