From a84dca32e3d1f3a02f2eb6470d449118537acf04 Mon Sep 17 00:00:00 2001 From: LizardByte-bot <108553330+LizardByte-bot@users.noreply.github.com> Date: Mon, 20 Jan 2025 03:41:45 +0000 Subject: [PATCH 1/2] chore: update global workflows --- .clang-format | 63 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/.clang-format b/.clang-format index e72a1e2..d6da5d9 100644 --- a/.clang-format +++ b/.clang-format @@ -6,27 +6,34 @@ # Generated from CLion C/C++ Code Style settings BasedOnStyle: LLVM AccessModifierOffset: -2 -AlignAfterOpenBracket: DontAlign -AlignConsecutiveAssignments: false +AlignAfterOpenBracket: BlockIndent +AlignConsecutiveAssignments: None +AlignEscapedNewlines: DontAlign AlignOperands: Align AllowAllArgumentsOnNextLine: false AllowAllConstructorInitializersOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: Always +AllowShortBlocksOnASingleLine: Empty AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLambdasOnASingleLine: All +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: None AllowShortLoopsOnASingleLine: true AlignTrailingComments: false -AlwaysBreakAfterReturnType: All +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: MultiLine -BreakBeforeBraces: Custom +BinPackArguments: false +BinPackParameters: false +BracedInitializerIndentWidth: 2 BraceWrapping: AfterCaseLabel: false AfterClass: false AfterControlStatement: Never AfterEnum: false + AfterExternBlock: true AfterFunction: false AfterNamespace: false AfterObjCDeclaration: false @@ -36,39 +43,75 @@ BraceWrapping: IndentBraces: false SplitEmptyFunction: false SplitEmptyRecord: true +BreakArrays: true BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach BreakBeforeTernaryOperators: false BreakConstructorInitializers: AfterColon BreakInheritanceList: AfterColon ColumnLimit: 0 CompactNamespaces: false ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +ExperimentalAutoDetectBinPacking: true +FixNamespaceComments: true +IncludeBlocks: Regroup +IndentAccessModifiers: false +IndentCaseBlocks: true IndentCaseLabels: true +IndentExternBlock: Indent +IndentGotoLabels: true IndentPPDirectives: BeforeHash IndentWidth: 2 +IndentWrappedFunctionNames: true +InsertBraces: true +InsertNewlineAtEOF: true KeepEmptyLinesAtTheStartOfBlocks: false +LineEnding: LF MaxEmptyLinesToKeep: 1 NamespaceIndentation: All +ObjCBinPackProtocolList: Never ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: Never +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 1 +PenaltyBreakString: 1 +PenaltyBreakFirstLessLess: 0 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 100000000 PointerAlignment: Right +ReferenceAlignment: Pointer ReflowComments: true +RemoveBracesLLVM: false +RemoveSemicolon: false +SeparateDefinitionBlocks: Always +SortIncludes: CaseInsensitive +SortUsingDeclarations: Lexicographic SpaceAfterCStyleCast: true SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true +SpaceAfterTemplateKeyword: false SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: true SpaceBeforeCtorInitializerColon: false SpaceBeforeInheritanceColon: false +SpaceBeforeJsonColon: false SpaceBeforeParens: ControlStatements SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 SpacesInAngles: Never SpacesInCStyleCastParentheses: false SpacesInContainerLiterals: false +SpacesInLineCommentPrefix: + Maximum: 3 + Minimum: 1 SpacesInParentheses: false SpacesInSquareBrackets: false TabWidth: 2 -Cpp11BracedListStyle: false UseTab: Never From f5199bcafb1f7550ee26abe9831a22f1ed127df4 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 20 Jan 2025 15:19:57 -0500 Subject: [PATCH 2/2] chore: update clang-format --- scripts/update_clang_format.py | 2 + src/common/file_settings_persistence.cpp | 28 +- .../display_device/audio_context_interface.h | 9 +- .../display_device/detail/json_converter.h | 26 +- .../detail/json_serializer_details.h | 112 +++-- .../file_settings_persistence.h | 9 +- src/common/include/display_device/json.h | 2 +- src/common/include/display_device/logging.h | 27 +- .../display_device/noop_audio_context.h | 9 +- .../noop_settings_persistence.h | 9 +- .../include/display_device/retry_scheduler.h | 139 +++--- .../settings_manager_interface.h | 15 +- .../settings_persistence_interface.h | 9 +- src/common/include/display_device/types.h | 18 +- src/common/json_serializer.cpp | 8 +- src/common/logging.cpp | 46 +- src/common/noop_audio_context.cpp | 9 +- src/common/noop_settings_persistence.cpp | 9 +- src/common/retry_scheduler.cpp | 8 +- src/common/types.cpp | 24 +- .../display_device/windows/persistent_state.h | 6 +- .../display_device/windows/settings_manager.h | 33 +- .../display_device/windows/settings_utils.h | 68 +-- .../include/display_device/windows/types.h | 20 +- .../display_device/windows/win_api_layer.h | 30 +- .../windows/win_api_layer_interface.h | 30 +- .../display_device/windows/win_api_utils.h | 57 +-- .../windows/win_display_device.h | 39 +- .../windows/win_display_device_interface.h | 39 +- src/windows/json.cpp | 2 +- src/windows/persistent_state.cpp | 23 +- src/windows/settings_manager_apply.cpp | 125 +++-- src/windows/settings_manager_general.cpp | 24 +- src/windows/settings_manager_revert.cpp | 61 ++- src/windows/settings_utils.cpp | 145 +++--- src/windows/types.cpp | 18 +- src/windows/win_api_layer.cpp | 183 ++++---- src/windows/win_api_utils.cpp | 150 +++--- src/windows/win_display_device_general.cpp | 72 ++- src/windows/win_display_device_hdr.cpp | 30 +- src/windows/win_display_device_modes.cpp | 58 ++- src/windows/win_display_device_primary.cpp | 28 +- src/windows/win_display_device_topology.cpp | 59 +-- tests/fixtures/fixtures.cpp | 38 +- tests/fixtures/include/fixtures/fixtures.h | 33 +- .../include/fixtures/json_converter_test.h | 9 +- tests/fixtures/include/fixtures/test_utils.h | 9 +- tests/fixtures/test_utils.cpp | 13 +- tests/unit/general/test_comparison.cpp | 93 ++-- .../test_file_settings_persistence.cpp | 47 +- tests/unit/general/test_json.cpp | 112 +++-- tests/unit/general/test_json_converter.cpp | 57 +-- tests/unit/general/test_logging.cpp | 36 +- .../test_noop_settings_persistence.cpp | 2 +- tests/unit/general/test_retry_scheduler.cpp | 330 ++++++++----- tests/unit/windows/test_comparison.cpp | 33 +- tests/unit/windows/test_json_converter.cpp | 26 +- tests/unit/windows/test_persistent_state.cpp | 28 +- .../windows/test_settings_manager_apply.cpp | 438 +++++++++--------- .../windows/test_settings_manager_general.cpp | 31 +- .../windows/test_settings_manager_revert.cpp | 132 +++--- tests/unit/windows/test_settings_utils.cpp | 239 +++++----- tests/unit/windows/test_win_api_layer.cpp | 68 ++- tests/unit/windows/test_win_api_utils.cpp | 176 ++++--- .../test_win_display_device_general.cpp | 126 ++--- .../windows/test_win_display_device_hdr.cpp | 87 ++-- .../windows/test_win_display_device_modes.cpp | 246 +++++----- .../test_win_display_device_primary.cpp | 83 ++-- .../test_win_display_device_topology.cpp | 140 +++--- tests/unit/windows/test_win_playground.cpp | 21 +- tests/unit/windows/utils/comparison.cpp | 52 +-- tests/unit/windows/utils/comparison.h | 42 +- tests/unit/windows/utils/guards.cpp | 12 +- tests/unit/windows/utils/guards.h | 12 +- tests/unit/windows/utils/helpers.cpp | 22 +- tests/unit/windows/utils/helpers.h | 6 +- .../unit/windows/utils/mock_win_api_layer.cpp | 43 +- .../windows/utils/mock_win_display_device.cpp | 45 +- 78 files changed, 2163 insertions(+), 2542 deletions(-) diff --git a/scripts/update_clang_format.py b/scripts/update_clang_format.py index d5a90ec..5e5f917 100644 --- a/scripts/update_clang_format.py +++ b/scripts/update_clang_format.py @@ -8,8 +8,10 @@ 'tests', ] file_types = [ + 'c', 'cpp', 'h', + 'h', 'm', 'mm' ] diff --git a/src/common/file_settings_persistence.cpp b/src/common/file_settings_persistence.cpp index df882bf..01f03e8 100644 --- a/src/common/file_settings_persistence.cpp +++ b/src/common/file_settings_persistence.cpp @@ -15,33 +15,30 @@ namespace display_device { FileSettingsPersistence::FileSettingsPersistence(std::filesystem::path filepath): - m_filepath { std::move(filepath) } { + m_filepath {std::move(filepath)} { if (m_filepath.empty()) { - throw std::runtime_error { "Empty filename provided for FileSettingsPersistence!" }; + throw std::runtime_error {"Empty filename provided for FileSettingsPersistence!"}; } } - bool - FileSettingsPersistence::store(const std::vector &data) { + bool FileSettingsPersistence::store(const std::vector &data) { try { - std::ofstream stream { m_filepath, std::ios::binary | std::ios::trunc }; + std::ofstream stream {m_filepath, std::ios::binary | std::ios::trunc}; if (!stream) { DD_LOG(error) << "Failed to open " << m_filepath << " for writing!"; return false; } - std::copy(std::begin(data), std::end(data), std::ostreambuf_iterator { stream }); + std::copy(std::begin(data), std::end(data), std::ostreambuf_iterator {stream}); return true; - } - catch (const std::exception &error) { + } catch (const std::exception &error) { DD_LOG(error) << "Failed to write to " << m_filepath << "! Error:\n" << error.what(); return false; } } - std::optional> - FileSettingsPersistence::load() const { + std::optional> FileSettingsPersistence::load() const { if (std::error_code error_code; !std::filesystem::exists(m_filepath, error_code)) { if (error_code) { DD_LOG(error) << "Failed to load " << m_filepath << "! Error:\n" @@ -53,24 +50,21 @@ namespace display_device { } try { - std::ifstream stream { m_filepath, std::ios::binary }; + std::ifstream stream {m_filepath, std::ios::binary}; if (!stream) { DD_LOG(error) << "Failed to open " << m_filepath << " for reading!"; return std::nullopt; } - return std::vector { std::istreambuf_iterator { stream }, - std::istreambuf_iterator {} }; - } - catch (const std::exception &error) { + return std::vector {std::istreambuf_iterator {stream}, std::istreambuf_iterator {}}; + } catch (const std::exception &error) { DD_LOG(error) << "Failed to read " << m_filepath << "! Error:\n" << error.what(); return std::nullopt; } } - bool - FileSettingsPersistence::clear() { + bool FileSettingsPersistence::clear() { // Return valud does not matter since we check the error code in case the file could NOT be removed. std::error_code error_code; std::filesystem::remove(m_filepath, error_code); diff --git a/src/common/include/display_device/audio_context_interface.h b/src/common/include/display_device/audio_context_interface.h index 26098d3..ab68175 100644 --- a/src/common/include/display_device/audio_context_interface.h +++ b/src/common/include/display_device/audio_context_interface.h @@ -27,8 +27,7 @@ namespace display_device { * const auto result { iface->capture() }; * @examples_end */ - [[nodiscard]] virtual bool - capture() = 0; + [[nodiscard]] virtual bool capture() = 0; /** * @brief Check if the context is already captured. @@ -38,8 +37,7 @@ namespace display_device { * const auto result { iface->isCaptured() }; * @examples_end */ - [[nodiscard]] virtual bool - isCaptured() const = 0; + [[nodiscard]] virtual bool isCaptured() const = 0; /** * @brief Release captured audio context for the devices (if any). @@ -48,7 +46,6 @@ namespace display_device { * const auto result { iface->release() }; * @examples_end */ - virtual void - release() = 0; + virtual void release() = 0; }; } // namespace display_device diff --git a/src/common/include/display_device/detail/json_converter.h b/src/common/include/display_device/detail/json_converter.h index 9510b97..fa41c53 100644 --- a/src/common/include/display_device/detail/json_converter.h +++ b/src/common/include/display_device/detail/json_converter.h @@ -10,9 +10,8 @@ namespace display_device { // A shared "toJson" implementation. Extracted here for UTs + coverage. - template - std::string - toJsonHelper(const Type &obj, const std::optional &indent, bool *success) { + template + std::string toJsonHelper(const Type &obj, const std::optional &indent, bool *success) { try { if (success) { *success = true; @@ -20,8 +19,7 @@ namespace display_device { nlohmann::json json_obj = obj; return json_obj.dump(static_cast(indent.value_or(-1))); - } - catch (const std::exception &err) { // GCOVR_EXCL_BR_LINE for fallthrough branch + } catch (const std::exception &err) { // GCOVR_EXCL_BR_LINE for fallthrough branch if (success) { *success = false; } @@ -31,9 +29,8 @@ namespace display_device { } // A shared "fromJson" implementation. Extracted here for UTs + coverage. - template - bool - fromJsonHelper(const std::string &string, Type &obj, std::string *error_message = nullptr) { + template + bool fromJsonHelper(const std::string &string, Type &obj, std::string *error_message = nullptr) { try { if (error_message) { error_message->clear(); @@ -42,8 +39,7 @@ namespace display_device { Type parsed_obj = nlohmann::json::parse(string); obj = std::move(parsed_obj); return true; - } - catch (const std::exception &err) { + } catch (const std::exception &err) { if (error_message) { *error_message = err.what(); } @@ -52,12 +48,12 @@ namespace display_device { } } - #define DD_JSON_DEFINE_CONVERTER(Type) \ + #define DD_JSON_DEFINE_CONVERTER(Type) \ std::string toJson(const Type &obj, const std::optional &indent, bool *success) { \ - return toJsonHelper(obj, indent, success); \ - } \ - bool fromJson(const std::string &string, Type &obj, std::string *error_message) { \ - return fromJsonHelper(string, obj, error_message); \ + return toJsonHelper(obj, indent, success); \ + } \ + bool fromJson(const std::string &string, Type &obj, std::string *error_message) { \ + return fromJsonHelper(string, obj, error_message); \ } } // namespace display_device #endif diff --git a/src/common/include/display_device/detail/json_serializer_details.h b/src/common/include/display_device/detail/json_serializer_details.h index cd41c8b..1fec98a 100644 --- a/src/common/include/display_device/detail/json_serializer_details.h +++ b/src/common/include/display_device/detail/json_serializer_details.h @@ -14,36 +14,40 @@ // Coverage has trouble with inlined functions when they are included in different units, // therefore the usual macro was split into declaration and definition - #define DD_JSON_DECLARE_SERIALIZE_TYPE(Type) \ + #define DD_JSON_DECLARE_SERIALIZE_TYPE(Type) \ void to_json(nlohmann::json &nlohmann_json_j, const Type &nlohmann_json_t); \ void from_json(const nlohmann::json &nlohmann_json_j, Type &nlohmann_json_t); - #define DD_JSON_DEFINE_SERIALIZE_STRUCT(Type, ...) \ - void to_json(nlohmann::json &nlohmann_json_j, const Type &nlohmann_json_t) { \ - NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DD_JSON_TO, __VA_ARGS__)) \ - } \ - \ + #define DD_JSON_DEFINE_SERIALIZE_STRUCT(Type, ...) \ + void to_json(nlohmann::json &nlohmann_json_j, const Type &nlohmann_json_t) { \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DD_JSON_TO, __VA_ARGS__)) \ + } \ +\ void from_json(const nlohmann::json &nlohmann_json_j, Type &nlohmann_json_t) { \ - NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DD_JSON_FROM, __VA_ARGS__)) \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(DD_JSON_FROM, __VA_ARGS__)) \ } // Coverage has trouble with getEnumMap() function since it has a lot of "fallthrough" // branches when creating a map, therefore the macro has baked in pattern to disable branch coverage // in GCOVR - #define DD_JSON_DEFINE_SERIALIZE_ENUM_GCOVR_EXCL_BR_LINE(Type, ...) \ - const std::map & \ - getEnumMap(const Type &) { \ - static_assert(std::is_enum::value, #Type " must be an enum!"); \ - static const std::map map = __VA_ARGS__; \ - return map; \ - } \ - \ - void to_json(nlohmann::json &nlohmann_json_j, const Type &nlohmann_json_t) { \ - nlohmann_json_j = findInEnumMap(#Type " is missing enum mapping!", [nlohmann_json_t](const auto &pair) { return pair.first == nlohmann_json_t; })->second; \ - } \ - \ - void from_json(const nlohmann::json &nlohmann_json_j, Type &nlohmann_json_t) { \ - nlohmann_json_t = findInEnumMap(#Type " is missing enum mapping!", [&nlohmann_json_j](const auto &pair) { return pair.second == nlohmann_json_j; })->first; \ + #define DD_JSON_DEFINE_SERIALIZE_ENUM_GCOVR_EXCL_BR_LINE(Type, ...) \ + const std::map & \ + getEnumMap(const Type &) { \ + static_assert(std::is_enum::value, #Type " must be an enum!"); \ + static const std::map map = __VA_ARGS__; \ + return map; \ + } \ +\ + void to_json(nlohmann::json &nlohmann_json_j, const Type &nlohmann_json_t) { \ + nlohmann_json_j = findInEnumMap(#Type " is missing enum mapping!", [nlohmann_json_t](const auto &pair) { \ + return pair.first == nlohmann_json_t; \ + })->second; \ + } \ +\ + void from_json(const nlohmann::json &nlohmann_json_j, Type &nlohmann_json_t) { \ + nlohmann_json_t = findInEnumMap(#Type " is missing enum mapping!", [&nlohmann_json_j](const auto &pair) { \ + return pair.second == nlohmann_json_j; \ + })->first; \ } namespace display_device { @@ -51,22 +55,21 @@ namespace display_device { * @brief Holds information for serializing variants. */ namespace detail { - template + template struct JsonTypeName; - template <> + template<> struct JsonTypeName { - static constexpr std::string_view m_name { "double" }; + static constexpr std::string_view m_name {"double"}; }; - template <> + template<> struct JsonTypeName { - static constexpr std::string_view m_name { "rational" }; + static constexpr std::string_view m_name {"rational"}; }; - template - bool - variantFromJson(const nlohmann::json &nlohmann_json_j, std::variant &value) { + template + bool variantFromJson(const nlohmann::json &nlohmann_json_j, std::variant &value) { if (nlohmann_json_j.at("type").get() != JsonTypeName::m_name) { return false; } @@ -77,11 +80,10 @@ namespace display_device { } // namespace detail // A shared function for enums to find values in the map. Extracted here for UTs + coverage - template - typename std::map::const_iterator - findInEnumMap(const char *error_msg, Predicate predicate) { - const auto &map { getEnumMap(T {}) }; - auto it { std::find_if(std::begin(map), std::end(map), predicate) }; + template + typename std::map::const_iterator findInEnumMap(const char *error_msg, Predicate predicate) { + const auto &map {getEnumMap(T {})}; + auto it {std::find_if(std::begin(map), std::end(map), predicate)}; if (it == std::end(map)) { // GCOVR_EXCL_BR_LINE for fallthrough branch throw std::runtime_error(error_msg); // GCOVR_EXCL_BR_LINE for fallthrough branch } @@ -91,24 +93,20 @@ namespace display_device { namespace nlohmann { // Specialization for optional types until they actually implement it. - template + template struct adl_serializer> { - static void - to_json(json &nlohmann_json_j, const std::optional &nlohmann_json_t) { + static void to_json(json &nlohmann_json_j, const std::optional &nlohmann_json_t) { if (nlohmann_json_t == std::nullopt) { nlohmann_json_j = nullptr; - } - else { + } else { nlohmann_json_j = *nlohmann_json_t; } } - static void - from_json(const json &nlohmann_json_j, std::optional &nlohmann_json_t) { + static void from_json(const json &nlohmann_json_j, std::optional &nlohmann_json_t) { if (nlohmann_json_j.is_null()) { nlohmann_json_t = std::nullopt; - } - else { + } else { nlohmann_json_t = nlohmann_json_j.get(); } } @@ -116,44 +114,40 @@ namespace nlohmann { // Specialization for variant type. // See https://github.com/nlohmann/json/issues/1261#issuecomment-2048770747 - template + template struct adl_serializer> { - static void - to_json(json &nlohmann_json_j, const std::variant &nlohmann_json_t) { + static void to_json(json &nlohmann_json_j, const std::variant &nlohmann_json_t) { std::visit( [&nlohmann_json_j](const T &value) { nlohmann_json_j["type"] = display_device::detail::JsonTypeName>::m_name; nlohmann_json_j["value"] = value; }, - nlohmann_json_t); + nlohmann_json_t + ); } - static void - from_json(const json &nlohmann_json_j, std::variant &nlohmann_json_t) { + static void from_json(const json &nlohmann_json_j, std::variant &nlohmann_json_t) { // Call variant_from_json for all types, only one will succeed - const bool found { (display_device::detail::variantFromJson(nlohmann_json_j, nlohmann_json_t) || ...) }; + const bool found {(display_device::detail::variantFromJson(nlohmann_json_j, nlohmann_json_t) || ...)}; if (!found) { - const std::string error { "Could not parse variant from type " + nlohmann_json_j.at("type").get() + "!" }; + const std::string error {"Could not parse variant from type " + nlohmann_json_j.at("type").get() + "!"}; throw std::runtime_error(error); } } }; // Specialization for chrono duration. - template + template struct adl_serializer> { using NanoRep = decltype(std::chrono::nanoseconds {}.count()); - static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), - "Duration support above nanoseconds have not been tested/verified yet!"); + static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), "Duration support above nanoseconds have not been tested/verified yet!"); - static void - to_json(json &nlohmann_json_j, const std::chrono::duration &nlohmann_json_t) { + static void to_json(json &nlohmann_json_j, const std::chrono::duration &nlohmann_json_t) { nlohmann_json_j = nlohmann_json_t.count(); } - static void - from_json(const json &nlohmann_json_j, std::chrono::duration &nlohmann_json_t) { - nlohmann_json_t = std::chrono::duration { nlohmann_json_j.get() }; + static void from_json(const json &nlohmann_json_j, std::chrono::duration &nlohmann_json_t) { + nlohmann_json_t = std::chrono::duration {nlohmann_json_j.get()}; } }; } // namespace nlohmann diff --git a/src/common/include/display_device/file_settings_persistence.h b/src/common/include/display_device/file_settings_persistence.h index 8dc37d0..5e63010 100644 --- a/src/common/include/display_device/file_settings_persistence.h +++ b/src/common/include/display_device/file_settings_persistence.h @@ -28,23 +28,20 @@ namespace display_device { * @warning The method does not create missing directories! * @see SettingsPersistenceInterface::store for more details. */ - [[nodiscard]] bool - store(const std::vector &data) override; + [[nodiscard]] bool store(const std::vector &data) override; /** * Read the data from the file specified in constructor. * @note If file does not exist, an empty data list will be returned instead of null optional. * @see SettingsPersistenceInterface::load for more details. */ - [[nodiscard]] std::optional> - load() const override; + [[nodiscard]] std::optional> load() const override; /** * Remove the file specified in constructor (if it exists). * @see SettingsPersistenceInterface::clear for more details. */ - [[nodiscard]] bool - clear() override; + [[nodiscard]] bool clear() override; private: std::filesystem::path m_filepath; diff --git a/src/common/include/display_device/json.h b/src/common/include/display_device/json.h index e22d9b7..68609ab 100644 --- a/src/common/include/display_device/json.h +++ b/src/common/include/display_device/json.h @@ -17,7 +17,7 @@ * DD_LOG(info) << "Got devices:\n" << toJson(devices); * @examples_end */ -#define DD_JSON_DECLARE_CONVERTER(Type) \ +#define DD_JSON_DECLARE_CONVERTER(Type) \ [[nodiscard]] std::string toJson(const Type &obj, const std::optional &indent = 2u, bool *success = nullptr); \ [[nodiscard]] bool fromJson(const std::string &string, Type &obj, std::string *error_message = nullptr); // NOLINT(*-macro-parentheses) diff --git a/src/common/include/display_device/logging.h b/src/common/include/display_device/logging.h index c650087..f22a043 100644 --- a/src/common/include/display_device/logging.h +++ b/src/common/include/display_device/logging.h @@ -46,8 +46,7 @@ namespace display_device { * Logger& logger { Logger::get() }; * @examples_end */ - static Logger & - get(); + static Logger &get(); /** * @brief Set the log level for the logger. @@ -56,8 +55,7 @@ namespace display_device { * Logger::get().setLogLevel(Logger::LogLevel::Info); * @examples_end */ - void - setLogLevel(LogLevel log_level); + void setLogLevel(LogLevel log_level); /** * @brief Check if log level is currently enabled. @@ -67,8 +65,7 @@ namespace display_device { * const bool is_enabled { Logger::get().isLogLevelEnabled(Logger::LogLevel::Info) }; * @examples_end */ - [[nodiscard]] bool - isLogLevelEnabled(LogLevel log_level) const; + [[nodiscard]] bool isLogLevelEnabled(LogLevel log_level) const; /** * @brief Set custom callback for writing the logs. @@ -79,8 +76,7 @@ namespace display_device { * }); * @examples_end */ - void - setCustomCallback(Callback callback); + void setCustomCallback(Callback callback); /** * @brief Write the string to the output (via callback) if the log level is enabled. @@ -90,8 +86,7 @@ namespace display_device { * Logger::get().write(Logger::LogLevel::Info, "Hello World!"); * @examples_end */ - void - write(LogLevel log_level, std::string value); + void write(LogLevel log_level, std::string value); /** * @brief A deleted copy constructor for singleton pattern. @@ -103,8 +98,7 @@ namespace display_device { * @brief A deleted assignment operator for singleton pattern. * @note Public to ensure better compiler error message. */ - void - operator=(Logger const &) = delete; + void operator=(Logger const &) = delete; private: /** @@ -137,9 +131,8 @@ namespace display_device { * @param value Arbitrary value to be written to the buffer. * @returns Reference to the writer utility for chaining the operators. */ - template - LogWriter & - operator<<(T &&value) { + template + LogWriter &operator<<(T &&value) { m_buffer << std::forward(value); return *this; } @@ -157,6 +150,6 @@ namespace display_device { * DD_LOG(error) << "OH MY GAWD!"; * @examples_end */ -#define DD_LOG(level) \ - for (bool is_enabled { display_device::Logger::get().isLogLevelEnabled(display_device::Logger::LogLevel::level) }; is_enabled; is_enabled = false) \ +#define DD_LOG(level) \ + for (bool is_enabled {display_device::Logger::get().isLogLevelEnabled(display_device::Logger::LogLevel::level)}; is_enabled; is_enabled = false) \ display_device::LogWriter(display_device::Logger::LogLevel::level) diff --git a/src/common/include/display_device/noop_audio_context.h b/src/common/include/display_device/noop_audio_context.h index 81a4160..a70fb79 100644 --- a/src/common/include/display_device/noop_audio_context.h +++ b/src/common/include/display_device/noop_audio_context.h @@ -14,16 +14,13 @@ namespace display_device { class NoopAudioContext: public AudioContextInterface { public: /** Always returns true and sets m_is_captured to true. */ - [[nodiscard]] bool - capture() override; + [[nodiscard]] bool capture() override; /** Returns the m_is_captured value. */ - [[nodiscard]] bool - isCaptured() const override; + [[nodiscard]] bool isCaptured() const override; /** Sets m_is_captured to false. */ - void - release() override; + void release() override; private: bool m_is_captured {}; diff --git a/src/common/include/display_device/noop_settings_persistence.h b/src/common/include/display_device/noop_settings_persistence.h index 28ec592..6031dad 100644 --- a/src/common/include/display_device/noop_settings_persistence.h +++ b/src/common/include/display_device/noop_settings_persistence.h @@ -14,15 +14,12 @@ namespace display_device { class NoopSettingsPersistence: public SettingsPersistenceInterface { public: /** Always returns true. */ - [[nodiscard]] bool - store(const std::vector &) override; + [[nodiscard]] bool store(const std::vector &) override; /** Always returns empty vector. */ - [[nodiscard]] std::optional> - load() const override; + [[nodiscard]] std::optional> load() const override; /** Always returns true. */ - [[nodiscard]] bool - clear() override; + [[nodiscard]] bool clear() override; }; } // namespace display_device diff --git a/src/common/include/display_device/retry_scheduler.h b/src/common/include/display_device/retry_scheduler.h index 106d991..6fae59f 100644 --- a/src/common/include/display_device/retry_scheduler.h +++ b/src/common/include/display_device/retry_scheduler.h @@ -38,8 +38,7 @@ namespace display_device { /** * @brief Deleted copy operator. */ - SchedulerStopToken & - operator=(const SchedulerStopToken &) = delete; + SchedulerStopToken &operator=(const SchedulerStopToken &) = delete; /** * @brief Executes cleanup logic if scheduler stop was requested. @@ -49,18 +48,16 @@ namespace display_device { /** * @brief Request the scheduler to be stopped. */ - void - requestStop(); + void requestStop(); /** * @brief Check if stop was requested. * @return True if stop was requested, false otherwise. */ - [[nodiscard]] bool - stopRequested() const; + [[nodiscard]] bool stopRequested() const; private: - bool m_stop_requested { false }; + bool m_stop_requested {false}; std::function m_cleanup; }; @@ -69,7 +66,7 @@ namespace display_device { * @brief Given that we know that we are dealing with a function, * check if it is an optional function (like std::function<...>) or other callable. */ - template + template concept OptionalFunction = requires(FunctionT exec_fn) { static_cast(exec_fn); }; @@ -77,15 +74,15 @@ namespace display_device { /** * @brief A convenience template struct helper for adding const to the type. */ - template + template struct AutoConst; - template + template struct AutoConst { using type = T; }; - template + template struct AutoConst { using type = std::add_const_t; }; @@ -93,21 +90,21 @@ namespace display_device { /** * @brief A convenience template helper for adding const to the type. */ - template + template using auto_const_t = typename AutoConst::type; /** * @brief Check if the function signature matches the acceptable signature for RetryScheduler::execute * without a stop token. */ - template + template concept ExecuteWithoutStopToken = requires(FunctionT exec_fn, T &value) { exec_fn(value); }; /** * @brief Check if the function signature matches the acceptable signature for RetryScheduler::execute * with a stop token. */ - template + template concept ExecuteWithStopToken = requires(FunctionT exec_fn, T &value, SchedulerStopToken &token) { exec_fn(value, token); }; @@ -115,7 +112,7 @@ namespace display_device { /** * @brief Check if the function signature matches the acceptable signature for RetryScheduler::execute. */ - template + template concept ExecuteCallbackLike = ExecuteWithoutStopToken || ExecuteWithStopToken; } // namespace detail @@ -133,7 +130,7 @@ namespace display_device { }; std::vector m_sleep_durations; ///< Specifies for long the scheduled thread sleeps before invoking executor. Last duration is reused indefinitely. - Execution m_execution { Execution::Immediate }; ///< Executor's execution logic. + Execution m_execution {Execution::Immediate}; ///< Executor's execution logic. }; /** @@ -142,7 +139,7 @@ namespace display_device { * @note The scheduler is designed to only schedule 1 callback at a time, until it is either * replaced or stopped. */ - template + template class RetryScheduler final { public: /** @@ -150,18 +147,21 @@ namespace display_device { * @param iface Interface to be passed around to the executor functions. */ explicit RetryScheduler(std::unique_ptr iface): - m_iface { iface ? std::move(iface) : throw std::logic_error { "Nullptr interface provided in RetryScheduler!" } }, - m_thread { [this]() { - std::unique_lock lock { m_mutex }; + m_iface {iface ? std::move(iface) : throw std::logic_error {"Nullptr interface provided in RetryScheduler!"}}, + m_thread {[this]() { + std::unique_lock lock {m_mutex}; while (m_keep_alive) { m_syncing_thread = false; - if (auto duration { takeNextDuration(m_sleep_durations) }; duration > std::chrono::milliseconds::zero()) { + if (auto duration {takeNextDuration(m_sleep_durations)}; duration > std::chrono::milliseconds::zero()) { // We're going to sleep until manually woken up or the time elapses. - m_sleep_cv.wait_for(lock, duration, [this]() { return m_syncing_thread; }); - } - else { + m_sleep_cv.wait_for(lock, duration, [this]() { + return m_syncing_thread; + }); + } else { // We're going to sleep until manually woken up. - m_sleep_cv.wait(lock, [this]() { return m_syncing_thread; }); + m_sleep_cv.wait(lock, [this]() { + return m_syncing_thread; + }); } if (m_syncing_thread) { @@ -170,18 +170,19 @@ namespace display_device { } try { - SchedulerStopToken scheduler_stop_token { [&]() { clearThreadLoopUnlocked(); } }; + SchedulerStopToken scheduler_stop_token {[&]() { + clearThreadLoopUnlocked(); + }}; m_retry_function(*m_iface, scheduler_stop_token); continue; - } - catch (const std::exception &error) { + } catch (const std::exception &error) { DD_LOG(error) << "Exception thrown in the RetryScheduler thread. Stopping scheduler. Error:\n" << error.what(); } clearThreadLoopUnlocked(); } - } } { + }} { } /** @@ -189,7 +190,7 @@ namespace display_device { */ ~RetryScheduler() { { - std::lock_guard lock { m_mutex }; + std::lock_guard lock {m_mutex}; m_keep_alive = false; syncThreadUnlocked(); } @@ -215,22 +216,25 @@ namespace display_device { * }, { .m_sleep_durations = { 50ms, 10ms }); * @examples_end */ - void - schedule(std::function exec_fn, const SchedulerOptions &options) { + void schedule(std::function exec_fn, const SchedulerOptions &options) { if (!exec_fn) { - throw std::logic_error { "Empty callback function provided in RetryScheduler::schedule!" }; + throw std::logic_error {"Empty callback function provided in RetryScheduler::schedule!"}; } if (options.m_sleep_durations.empty()) { - throw std::logic_error { "At least 1 sleep duration must be specified in RetryScheduler::schedule!" }; + throw std::logic_error {"At least 1 sleep duration must be specified in RetryScheduler::schedule!"}; } - if (std::ranges::any_of(options.m_sleep_durations, [&](const auto &duration) { return duration == std::chrono::milliseconds::zero(); })) { - throw std::logic_error { "All of the durations specified in RetryScheduler::schedule must be larger than a 0!" }; + if (std::ranges::any_of(options.m_sleep_durations, [&](const auto &duration) { + return duration == std::chrono::milliseconds::zero(); + })) { + throw std::logic_error {"All of the durations specified in RetryScheduler::schedule must be larger than a 0!"}; } - std::lock_guard lock { m_mutex }; - SchedulerStopToken stop_token { [&]() { stopUnlocked(); } }; + std::lock_guard lock {m_mutex}; + SchedulerStopToken stop_token {[&]() { + stopUnlocked(); + }}; // We are catching the exception here instead of propagating to have // similar try...catch login as in the scheduler thread. @@ -249,8 +253,7 @@ namespace display_device { m_sleep_durations = std::move(sleep_durations); syncThreadUnlocked(); } - } - catch (const std::exception &error) { + } catch (const std::exception &error) { stop_token.requestStop(); DD_LOG(error) << "Exception thrown in the RetryScheduler::schedule. Stopping scheduler. Error:\n" << error.what(); @@ -260,18 +263,16 @@ namespace display_device { /** * @brief A non-const variant of the `executeImpl` method. See it for details. */ - template - auto - execute(FunctionT &&exec_fn) { + template + auto execute(FunctionT &&exec_fn) { return executeImpl(*this, std::forward(exec_fn)); } /** * @brief A const variant of the `executeImpl` method. See it for details. */ - template - auto - execute(FunctionT &&exec_fn) const { + template + auto execute(FunctionT &&exec_fn) const { return executeImpl(*this, std::forward(exec_fn)); } @@ -279,26 +280,23 @@ namespace display_device { * @brief Check whether anything is scheduled for execution. * @return True if something is scheduled, false otherwise. */ - [[nodiscard]] bool - isScheduled() const { + [[nodiscard]] bool isScheduled() const { return static_cast(m_retry_function); } /** * @brief Stop the scheduled function - will no longer be execute once THIS method returns. */ - void - stop() { - std::lock_guard lock { m_mutex }; + void stop() { + std::lock_guard lock {m_mutex}; stopUnlocked(); } private: - static std::chrono::milliseconds - takeNextDuration(std::vector &durations) { + static std::chrono::milliseconds takeNextDuration(std::vector &durations) { if (durations.size() > 1) { - const auto front_it { std::begin(durations) }; - const auto front_value { *front_it }; + const auto front_it {std::begin(durations)}; + const auto front_value {*front_it}; durations.erase(front_it); return front_value; } @@ -342,8 +340,7 @@ namespace display_device { * }); * @examples_end */ - static auto - executeImpl(auto &self, auto &&exec_fn) + static auto executeImpl(auto &self, auto &&exec_fn) requires detail::ExecuteCallbackLike { using FunctionT = decltype(exec_fn); @@ -351,21 +348,20 @@ namespace display_device { if constexpr (detail::OptionalFunction) { if (!exec_fn) { - throw std::logic_error { "Empty callback function provided in RetryScheduler::execute!" }; + throw std::logic_error {"Empty callback function provided in RetryScheduler::execute!"}; } } - std::lock_guard lock { self.m_mutex }; - detail::auto_const_t, IsConst> &iface_ref { *self.m_iface }; + std::lock_guard lock {self.m_mutex}; + detail::auto_const_t, IsConst> &iface_ref {*self.m_iface}; if constexpr (detail::ExecuteWithStopToken) { - detail::auto_const_t stop_token { [&self]() { + detail::auto_const_t stop_token {[&self]() { if constexpr (!IsConst) { self.stopUnlocked(); } - } }; + }}; return std::forward(exec_fn)(iface_ref, stop_token); - } - else { + } else { return std::forward(exec_fn)(iface_ref); } } @@ -373,8 +369,7 @@ namespace display_device { /** * @brief Clear the necessary data so that the thread will go into a deep sleep. */ - void - clearThreadLoopUnlocked() { + void clearThreadLoopUnlocked() { m_sleep_durations = {}; m_retry_function = nullptr; } @@ -382,8 +377,7 @@ namespace display_device { /** * @brief Manually wake up the thread for synchronization. */ - void - syncThreadUnlocked() { + void syncThreadUnlocked() { m_syncing_thread = true; m_sleep_cv.notify_one(); } @@ -391,8 +385,7 @@ namespace display_device { /** * @brief Stop the scheduled function. */ - void - stopUnlocked() { + void stopUnlocked() { if (isScheduled()) { clearThreadLoopUnlocked(); syncThreadUnlocked(); @@ -401,12 +394,12 @@ namespace display_device { std::unique_ptr m_iface; /**< Interface to be passed around to the executor functions. */ std::vector m_sleep_durations; /**< Sleep times for the timer. */ - std::function m_retry_function { nullptr }; /**< Function to be executed until it succeeds. */ + std::function m_retry_function {nullptr}; /**< Function to be executed until it succeeds. */ mutable std::mutex m_mutex {}; /**< A mutex for synchronizing thread and "external" access. */ std::condition_variable m_sleep_cv {}; /**< Condition variable for waking up thread. */ - bool m_syncing_thread { false }; /**< Safeguard for the condition variable to prevent sporadic thread wake-ups. */ - bool m_keep_alive { true }; /**< When set to false, scheduler thread will exit. */ + bool m_syncing_thread {false}; /**< Safeguard for the condition variable to prevent sporadic thread wake-ups. */ + bool m_keep_alive {true}; /**< When set to false, scheduler thread will exit. */ // Always the last in the list so that all the members are already initialized! std::thread m_thread; /**< A scheduler thread. */ diff --git a/src/common/include/display_device/settings_manager_interface.h b/src/common/include/display_device/settings_manager_interface.h index 28305ae..c7cd885 100644 --- a/src/common/include/display_device/settings_manager_interface.h +++ b/src/common/include/display_device/settings_manager_interface.h @@ -54,8 +54,7 @@ namespace display_device { * const auto devices { iface->enumAvailableDevices() }; * @examples_end */ - [[nodiscard]] virtual EnumeratedDeviceList - enumAvailableDevices() const = 0; + [[nodiscard]] virtual EnumeratedDeviceList enumAvailableDevices() const = 0; /** * @brief Get display name associated with the device. @@ -68,8 +67,7 @@ namespace display_device { * const std::string display_name = iface->getDisplayName(device_id); * @examples_end */ - [[nodiscard]] virtual std::string - getDisplayName(const std::string &device_id) const = 0; + [[nodiscard]] virtual std::string getDisplayName(const std::string &device_id) const = 0; /** * @brief Apply the provided configuration to the system. @@ -82,8 +80,7 @@ namespace display_device { * const auto result = iface->applySettings(config); * @examples_end */ - [[nodiscard]] virtual ApplyResult - applySettings(const SingleDisplayConfiguration &config) = 0; + [[nodiscard]] virtual ApplyResult applySettings(const SingleDisplayConfiguration &config) = 0; /** * @brief Revert the applied configuration and restore the previous settings. @@ -93,8 +90,7 @@ namespace display_device { * const auto result = iface->revertSettings(); * @examples_end */ - [[nodiscard]] virtual RevertResult - revertSettings() = 0; + [[nodiscard]] virtual RevertResult revertSettings() = 0; /** * @brief Reset the persistence in case the settings cannot be reverted. @@ -118,7 +114,6 @@ namespace display_device { * } * @examples_end */ - [[nodiscard]] virtual bool - resetPersistence() = 0; + [[nodiscard]] virtual bool resetPersistence() = 0; }; } // namespace display_device diff --git a/src/common/include/display_device/settings_persistence_interface.h b/src/common/include/display_device/settings_persistence_interface.h index 65844f3..b57bf13 100644 --- a/src/common/include/display_device/settings_persistence_interface.h +++ b/src/common/include/display_device/settings_persistence_interface.h @@ -30,8 +30,7 @@ namespace display_device { * const auto result = iface->store(data); * @examples_end */ - [[nodiscard]] virtual bool - store(const std::vector &data) = 0; + [[nodiscard]] virtual bool store(const std::vector &data) = 0; /** * @brief Load saved settings data. @@ -43,8 +42,7 @@ namespace display_device { * const auto opt_data = iface->load(); * @examples_end */ - [[nodiscard]] virtual std::optional> - load() const = 0; + [[nodiscard]] virtual std::optional> load() const = 0; /** * @brief Clear the persistent settings data. @@ -54,7 +52,6 @@ namespace display_device { * const auto result = iface->clear(); * @examples_end */ - [[nodiscard]] virtual bool - clear() = 0; + [[nodiscard]] virtual bool clear() = 0; }; } // namespace display_device diff --git a/src/common/include/display_device/types.h b/src/common/include/display_device/types.h index cf4fb6e..456ee53 100644 --- a/src/common/include/display_device/types.h +++ b/src/common/include/display_device/types.h @@ -29,8 +29,7 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const Resolution &lhs, const Resolution &rhs); + friend bool operator==(const Resolution &lhs, const Resolution &rhs); }; /** @@ -43,8 +42,7 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const Point &lhs, const Point &rhs); + friend bool operator==(const Point &lhs, const Point &rhs); }; /** @@ -57,8 +55,7 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const Rational &lhs, const Rational &rhs); + friend bool operator==(const Rational &lhs, const Rational &rhs); }; /** @@ -84,8 +81,7 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const Info &lhs, const Info &rhs); + friend bool operator==(const Info &lhs, const Info &rhs); }; std::string m_device_id {}; /**< A unique device ID used by this API to identify the device. */ @@ -96,8 +92,7 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const EnumeratedDevice &lhs, const EnumeratedDevice &rhs); + friend bool operator==(const EnumeratedDevice &lhs, const EnumeratedDevice &rhs); }; /** @@ -131,7 +126,6 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const SingleDisplayConfiguration &lhs, const SingleDisplayConfiguration &rhs); + friend bool operator==(const SingleDisplayConfiguration &lhs, const SingleDisplayConfiguration &rhs); }; } // namespace display_device diff --git a/src/common/json_serializer.cpp b/src/common/json_serializer.cpp index 5c28b11..627c801 100644 --- a/src/common/json_serializer.cpp +++ b/src/common/json_serializer.cpp @@ -11,12 +11,8 @@ namespace display_device { // Enums - DD_JSON_DEFINE_SERIALIZE_ENUM_GCOVR_EXCL_BR_LINE(HdrState, { { HdrState::Disabled, "Disabled" }, - { HdrState::Enabled, "Enabled" } }) - DD_JSON_DEFINE_SERIALIZE_ENUM_GCOVR_EXCL_BR_LINE(SingleDisplayConfiguration::DevicePreparation, { { SingleDisplayConfiguration::DevicePreparation::VerifyOnly, "VerifyOnly" }, - { SingleDisplayConfiguration::DevicePreparation::EnsureActive, "EnsureActive" }, - { SingleDisplayConfiguration::DevicePreparation::EnsurePrimary, "EnsurePrimary" }, - { SingleDisplayConfiguration::DevicePreparation::EnsureOnlyDisplay, "EnsureOnlyDisplay" } }) + DD_JSON_DEFINE_SERIALIZE_ENUM_GCOVR_EXCL_BR_LINE(HdrState, {{HdrState::Disabled, "Disabled"}, {HdrState::Enabled, "Enabled"}}) + DD_JSON_DEFINE_SERIALIZE_ENUM_GCOVR_EXCL_BR_LINE(SingleDisplayConfiguration::DevicePreparation, {{SingleDisplayConfiguration::DevicePreparation::VerifyOnly, "VerifyOnly"}, {SingleDisplayConfiguration::DevicePreparation::EnsureActive, "EnsureActive"}, {SingleDisplayConfiguration::DevicePreparation::EnsurePrimary, "EnsurePrimary"}, {SingleDisplayConfiguration::DevicePreparation::EnsureOnlyDisplay, "EnsureOnlyDisplay"}}) // Structs DD_JSON_DEFINE_SERIALIZE_STRUCT(Resolution, width, height) diff --git a/src/common/logging.cpp b/src/common/logging.cpp index 7d3e037..a8c5591 100644 --- a/src/common/logging.cpp +++ b/src/common/logging.cpp @@ -17,13 +17,12 @@ namespace display_device { namespace { - std::tm - threadSafeLocaltime(const std::time_t &time) { + std::tm threadSafeLocaltime(const std::time_t &time) { #if defined(_MSC_VER) // MSVCRT (2005+): std::localtime is threadsafe - const auto tm_ptr { std::localtime(&time) }; + const auto tm_ptr {std::localtime(&time)}; #else // POSIX std::tm buffer; - const auto tm_ptr { localtime_r(&time, &buffer) }; + const auto tm_ptr {localtime_r(&time, &buffer)}; #endif // _MSC_VER if (tm_ptr) { return *tm_ptr; @@ -32,31 +31,26 @@ namespace display_device { } } // namespace - Logger & - Logger::get() { + Logger &Logger::get() { static Logger instance; // GCOVR_EXCL_BR_LINE for some reason... return instance; } - void - Logger::setLogLevel(const LogLevel log_level) { + void Logger::setLogLevel(const LogLevel log_level) { m_enabled_log_level = log_level; } - bool - Logger::isLogLevelEnabled(LogLevel log_level) const { - const auto log_level_v { static_cast>(log_level) }; - const auto enabled_log_level_v { static_cast>(m_enabled_log_level) }; + bool Logger::isLogLevelEnabled(LogLevel log_level) const { + const auto log_level_v {static_cast>(log_level)}; + const auto enabled_log_level_v {static_cast>(m_enabled_log_level)}; return log_level_v >= enabled_log_level_v; } - void - Logger::setCustomCallback(Callback callback) { + void Logger::setCustomCallback(Callback callback) { m_custom_callback = std::move(callback); } - void - Logger::write(const LogLevel log_level, std::string value) { + void Logger::write(const LogLevel log_level, std::string value) { if (!isLogLevelEnabled(log_level)) { return; } @@ -70,15 +64,15 @@ namespace display_device { { // Time (limited by GCC 10, so it's not pretty...) { - const auto now { std::chrono::system_clock::now() }; - const auto now_ms { std::chrono::duration_cast(now.time_since_epoch()) }; - const auto now_s { std::chrono::duration_cast(now_ms) }; + const auto now {std::chrono::system_clock::now()}; + const auto now_ms {std::chrono::duration_cast(now.time_since_epoch())}; + const auto now_s {std::chrono::duration_cast(now_ms)}; - const std::time_t time { std::chrono::system_clock::to_time_t(now) }; - const auto localtime { threadSafeLocaltime(time) }; - const auto now_decimal_part { now_ms - now_s }; + const std::time_t time {std::chrono::system_clock::to_time_t(now)}; + const auto localtime {threadSafeLocaltime(time)}; + const auto now_decimal_part {now_ms - now_s}; - const auto old_flags { stream.flags() }; // Save formatting flags so that they can be restored... + const auto old_flags {stream.flags()}; // Save formatting flags so that they can be restored... stream << std::put_time(&localtime, "[%Y-%m-%d %H:%M:%S.") << std::setfill('0') << std::setw(3) << now_decimal_part.count() << "] "; stream.flags(old_flags); } @@ -110,16 +104,16 @@ namespace display_device { } static std::mutex log_mutex; - std::lock_guard lock { log_mutex }; + std::lock_guard lock {log_mutex}; std::cout << stream.rdbuf() << std::endl; } Logger::Logger(): - m_enabled_log_level { LogLevel::info } { + m_enabled_log_level {LogLevel::info} { } LogWriter::LogWriter(const Logger::LogLevel log_level): - m_log_level { log_level } {} + m_log_level {log_level} {} LogWriter::~LogWriter() { Logger::get().write(m_log_level, m_buffer.str()); diff --git a/src/common/noop_audio_context.cpp b/src/common/noop_audio_context.cpp index 52037ad..d32b7e2 100644 --- a/src/common/noop_audio_context.cpp +++ b/src/common/noop_audio_context.cpp @@ -6,19 +6,16 @@ #include "display_device/noop_audio_context.h" namespace display_device { - bool - NoopAudioContext::capture() { + bool NoopAudioContext::capture() { m_is_captured = true; return true; } - bool - NoopAudioContext::isCaptured() const { + bool NoopAudioContext::isCaptured() const { return m_is_captured; } - void - NoopAudioContext::release() { + void NoopAudioContext::release() { m_is_captured = false; } } // namespace display_device diff --git a/src/common/noop_settings_persistence.cpp b/src/common/noop_settings_persistence.cpp index 9c0cf56..7de77a8 100644 --- a/src/common/noop_settings_persistence.cpp +++ b/src/common/noop_settings_persistence.cpp @@ -6,18 +6,15 @@ #include "display_device/noop_settings_persistence.h" namespace display_device { - bool - NoopSettingsPersistence::store(const std::vector &) { + bool NoopSettingsPersistence::store(const std::vector &) { return true; } - std::optional> - NoopSettingsPersistence::load() const { + std::optional> NoopSettingsPersistence::load() const { return std::vector {}; } - bool - NoopSettingsPersistence::clear() { + bool NoopSettingsPersistence::clear() { return true; } } // namespace display_device diff --git a/src/common/retry_scheduler.cpp b/src/common/retry_scheduler.cpp index a5f764c..f836898 100644 --- a/src/common/retry_scheduler.cpp +++ b/src/common/retry_scheduler.cpp @@ -7,7 +7,7 @@ namespace display_device { SchedulerStopToken::SchedulerStopToken(std::function cleanup): - m_cleanup { std::move(cleanup) } { + m_cleanup {std::move(cleanup)} { } SchedulerStopToken::~SchedulerStopToken() { @@ -16,13 +16,11 @@ namespace display_device { } } - void - SchedulerStopToken::requestStop() { + void SchedulerStopToken::requestStop() { m_stop_requested = true; } - bool - SchedulerStopToken::stopRequested() const { + bool SchedulerStopToken::stopRequested() const { return m_stop_requested; } } // namespace display_device diff --git a/src/common/types.cpp b/src/common/types.cpp index 17abd27..eb243b9 100644 --- a/src/common/types.cpp +++ b/src/common/types.cpp @@ -6,13 +6,11 @@ #include "display_device/types.h" namespace { - bool - fuzzyCompare(const double lhs, const double rhs) { + bool fuzzyCompare(const double lhs, const double rhs) { return std::abs(lhs - rhs) * 1000000000000. <= std::min(std::abs(lhs), std::abs(rhs)); } - bool - fuzzyCompare(const display_device::FloatingPoint &lhs, const display_device::FloatingPoint &rhs) { + bool fuzzyCompare(const display_device::FloatingPoint &lhs, const display_device::FloatingPoint &rhs) { if (lhs.index() == rhs.index()) { if (std::holds_alternative(lhs)) { return fuzzyCompare(std::get(lhs), std::get(rhs)); @@ -24,35 +22,29 @@ namespace { } // namespace namespace display_device { - bool - operator==(const Rational &lhs, const Rational &rhs) { + bool operator==(const Rational &lhs, const Rational &rhs) { return lhs.m_numerator == rhs.m_numerator && lhs.m_denominator == rhs.m_denominator; } - bool - operator==(const Point &lhs, const Point &rhs) { + bool operator==(const Point &lhs, const Point &rhs) { return lhs.m_x == rhs.m_x && lhs.m_y == rhs.m_y; } - bool - operator==(const Resolution &lhs, const Resolution &rhs) { + bool operator==(const Resolution &lhs, const Resolution &rhs) { return lhs.m_height == rhs.m_height && lhs.m_width == rhs.m_width; } - bool - operator==(const EnumeratedDevice::Info &lhs, const EnumeratedDevice::Info &rhs) { + bool operator==(const EnumeratedDevice::Info &lhs, const EnumeratedDevice::Info &rhs) { return lhs.m_resolution == rhs.m_resolution && fuzzyCompare(lhs.m_resolution_scale, rhs.m_resolution_scale) && fuzzyCompare(lhs.m_refresh_rate, rhs.m_refresh_rate) && lhs.m_primary == rhs.m_primary && lhs.m_origin_point == rhs.m_origin_point && lhs.m_hdr_state == rhs.m_hdr_state; } - bool - operator==(const EnumeratedDevice &lhs, const EnumeratedDevice &rhs) { + bool operator==(const EnumeratedDevice &lhs, const EnumeratedDevice &rhs) { return lhs.m_device_id == rhs.m_device_id && lhs.m_display_name == rhs.m_display_name && lhs.m_friendly_name == rhs.m_friendly_name && lhs.m_info == rhs.m_info; } - bool - operator==(const SingleDisplayConfiguration &lhs, const SingleDisplayConfiguration &rhs) { + bool operator==(const SingleDisplayConfiguration &lhs, const SingleDisplayConfiguration &rhs) { return lhs.m_device_id == rhs.m_device_id && lhs.m_device_prep == rhs.m_device_prep && lhs.m_resolution == rhs.m_resolution && lhs.m_refresh_rate == rhs.m_refresh_rate && lhs.m_hdr_state == rhs.m_hdr_state; } } // namespace display_device diff --git a/src/windows/include/display_device/windows/persistent_state.h b/src/windows/include/display_device/windows/persistent_state.h index e69373b..c2f738f 100644 --- a/src/windows/include/display_device/windows/persistent_state.h +++ b/src/windows/include/display_device/windows/persistent_state.h @@ -29,15 +29,13 @@ namespace display_device { * @param state New state to be set. * @return True if the state was succesfully updated, false otherwise. */ - [[nodiscard]] bool - persistState(const std::optional &state); + [[nodiscard]] bool persistState(const std::optional &state); /** * @brief Get cached state. * @return Cached state */ - [[nodiscard]] const std::optional & - getState() const; + [[nodiscard]] const std::optional &getState() const; protected: std::shared_ptr m_settings_persistence_api; diff --git a/src/windows/include/display_device/windows/settings_manager.h b/src/windows/include/display_device/windows/settings_manager.h index ad8088f..b80d965 100644 --- a/src/windows/include/display_device/windows/settings_manager.h +++ b/src/windows/include/display_device/windows/settings_manager.h @@ -30,27 +30,23 @@ namespace display_device { std::shared_ptr dd_api, std::shared_ptr audio_context_api, std::unique_ptr persistent_state, - WinWorkarounds workarounds); + WinWorkarounds workarounds + ); /** For details @see SettingsManagerInterface::enumAvailableDevices */ - [[nodiscard]] EnumeratedDeviceList - enumAvailableDevices() const override; + [[nodiscard]] EnumeratedDeviceList enumAvailableDevices() const override; /** For details @see SettingsManagerInterface::getDisplayName */ - [[nodiscard]] std::string - getDisplayName(const std::string &device_id) const override; + [[nodiscard]] std::string getDisplayName(const std::string &device_id) const override; /** For details @see SettingsManagerInterface::applySettings */ - [[nodiscard]] ApplyResult - applySettings(const SingleDisplayConfiguration &config) override; + [[nodiscard]] ApplyResult applySettings(const SingleDisplayConfiguration &config) override; /** For details @see SettingsManagerInterface::revertSettings */ - [[nodiscard]] RevertResult - revertSettings() override; + [[nodiscard]] RevertResult revertSettings() override; /** For details @see SettingsManagerInterface::resetPersistence */ - [[nodiscard]] bool - resetPersistence() override; + [[nodiscard]] bool resetPersistence() override; protected: /** @@ -61,8 +57,7 @@ namespace display_device { * @param system_settings_touched Inticates whether a "write" operation could have been performed on the OS. * @return A tuple of (new_state that is to be updated/persisted, device_to_configure, additional_devices_to_configure). */ - [[nodiscard]] std::optional>> - prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched); + [[nodiscard]] std::optional>> prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched); /** * @brief Changes or restores the primary device based on the cached state, new state and configuration. @@ -73,8 +68,7 @@ namespace display_device { * @param system_settings_touched Inticates whether a "write" operation could have been performed on the OS. * @return True if no errors have occured, false otherwise. */ - [[nodiscard]] bool - preparePrimaryDevice(const SingleDisplayConfiguration &config, const std::string &device_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); + [[nodiscard]] bool preparePrimaryDevice(const SingleDisplayConfiguration &config, const std::string &device_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); /** * @brief Changes or restores the display modes based on the cached state, new state and configuration. @@ -86,8 +80,7 @@ namespace display_device { * @param system_settings_touched Inticates whether a "write" operation could have been performed on the OS. * @return True if no errors have occured, false otherwise. */ - [[nodiscard]] bool - prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); + [[nodiscard]] bool prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); /** * @brief Changes or restores the HDR states based on the cached state, new state and configuration. @@ -99,8 +92,7 @@ namespace display_device { * @param system_settings_touched Inticates whether a "write" operation could have been performed on the OS. * @return True if no errors have occured, false otherwise. */ - [[nodiscard]] bool - prepareHdrStates(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); + [[nodiscard]] bool prepareHdrStates(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched); /** * @brief Try to revert the modified settings. @@ -111,8 +103,7 @@ namespace display_device { * @warning The method assumes that the caller will ensure restoring the topology * in case of a failure! */ - [[nodiscard]] RevertResult - revertModifiedSettings(const ActiveTopology ¤t_topology, bool &system_settings_touched, bool *switched_topology = nullptr); + [[nodiscard]] RevertResult revertModifiedSettings(const ActiveTopology ¤t_topology, bool &system_settings_touched, bool *switched_topology = nullptr); std::shared_ptr m_dd_api; std::shared_ptr m_audio_context_api; diff --git a/src/windows/include/display_device/windows/settings_utils.h b/src/windows/include/display_device/windows/settings_utils.h index fa1387b..66e1478 100644 --- a/src/windows/include/display_device/windows/settings_utils.h +++ b/src/windows/include/display_device/windows/settings_utils.h @@ -25,8 +25,7 @@ namespace display_device::win_utils { * const auto device_ids { flattenTopology(topology) }; * @examples_end */ - std::set - flattenTopology(const ActiveTopology &topology); + std::set flattenTopology(const ActiveTopology &topology); /** * @brief Create extended topology from all the available devices. @@ -37,8 +36,7 @@ namespace display_device::win_utils { * const auto extended_topology { stripTopologyOfUnavailableDevices(*iface) }; * @examples_end */ - ActiveTopology - createFullExtendedTopology(WinDisplayDeviceInterface &win_dd); + ActiveTopology createFullExtendedTopology(WinDisplayDeviceInterface &win_dd); /** * @brief Get one primary device from the provided topology. @@ -51,8 +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(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); /** * @brief Compute the new intial state from arbitrary data. @@ -68,10 +65,7 @@ namespace display_device::win_utils { * const auto new_initial_state { computeInitialState(prev_state, topology_before_changes, devices) }; * @examples_end */ - std::optional - computeInitialState(const std::optional &prev_state, - const ActiveTopology &topology_before_changes, - const EnumeratedDeviceList &devices); + std::optional computeInitialState(const std::optional &prev_state, const ActiveTopology &topology_before_changes, const EnumeratedDeviceList &devices); /** * @brief Strip the initial state of non-existing devices. @@ -79,8 +73,7 @@ namespace display_device::win_utils { * @param devices Currently available device list. * @return Stripped initial state. */ - std::optional - stripInitialState(const SingleDisplayConfigState::Initial &initial_state, const EnumeratedDeviceList &devices); + std::optional stripInitialState(const SingleDisplayConfigState::Initial &initial_state, const EnumeratedDeviceList &devices); /** * @brief Compute new topology from arbitrary data. @@ -91,12 +84,7 @@ namespace display_device::win_utils { * @param initial_topology The initial topology from `computeInitialState(...)`. * @return New topology that should be set. */ - ActiveTopology - computeNewTopology(SingleDisplayConfiguration::DevicePreparation device_prep, - bool configuring_primary_devices, - const std::string &device_to_configure, - const std::set &additional_devices_to_configure, - const ActiveTopology &initial_topology); + ActiveTopology computeNewTopology(SingleDisplayConfiguration::DevicePreparation device_prep, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const ActiveTopology &initial_topology); /** * @brief Compute new topology + metadata from config settings and initial state. @@ -105,10 +93,7 @@ namespace display_device::win_utils { * @param initial_state The initial topology from `computeInitialState(...)` or `stripInitialState(...)` (or both). * @return A tuple of (new_topology, device_to_configure, addotional_devices_to_configure). */ - std::tuple> - computeNewTopologyAndMetadata(SingleDisplayConfiguration::DevicePreparation device_prep, - const std::string &device_id, - const SingleDisplayConfigState::Initial &initial_state); + std::tuple> computeNewTopologyAndMetadata(SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state); /** * @brief Compute new display modes from arbitrary data. @@ -120,13 +105,7 @@ namespace display_device::win_utils { * @param original_modes Display modes to be used as a base onto which changes are made. * @return New display modes that should be set. */ - DeviceDisplayModeMap - computeNewDisplayModes(const std::optional &resolution, - const std::optional &refresh_rate, - bool configuring_primary_devices, - const std::string &device_to_configure, - const std::set &additional_devices_to_configure, - const DeviceDisplayModeMap &original_modes); + DeviceDisplayModeMap computeNewDisplayModes(const std::optional &resolution, const std::optional &refresh_rate, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const DeviceDisplayModeMap &original_modes); /** * @brief Compute new HDR states from arbitrary data. @@ -137,12 +116,7 @@ namespace display_device::win_utils { * @param original_states HDR states to be used as a base onto which changes are made. * @return New HDR states that should be set. */ - HdrStateMap - computeNewHdrStates(const std::optional &hdr_state, - bool configuring_primary_devices, - const std::string &device_to_configure, - const std::set &additional_devices_to_configure, - const HdrStateMap &original_states); + HdrStateMap computeNewHdrStates(const std::optional &hdr_state, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const HdrStateMap &original_states); /** * @brief Toggle enabled HDR states off and on again if quick succession. @@ -165,8 +139,7 @@ namespace display_device::win_utils { * @param delay Delay between OFF and ON states (ON -> OFF -> DELAY -> ON). * If null optional is provided, the function does nothing. */ - void - blankHdrStates(WinDisplayDeviceInterface &win_dd, const std::optional &delay); + void blankHdrStates(WinDisplayDeviceInterface &win_dd, const std::optional &delay); /** * @brief Make guard function for the topology. @@ -178,8 +151,7 @@ namespace display_device::win_utils { * boost::scope::scope_exit guard { topologyGuardFn(*iface, iface->getCurrentTopology()) }; * @examples_end */ - DdGuardFn - topologyGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); + DdGuardFn topologyGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); /** * @brief Make guard function for the display modes. @@ -191,8 +163,7 @@ namespace display_device::win_utils { * boost::scope::scope_exit guard { modeGuardFn(*iface, iface->getCurrentTopology()) }; * @examples_end */ - DdGuardFn - modeGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); + DdGuardFn modeGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); /** * @brief Make guard function for the display modes. @@ -206,8 +177,7 @@ namespace display_device::win_utils { * boost::scope::scope_exit guard { modeGuardFn(*iface, modes) }; * @examples_end */ - DdGuardFn - modeGuardFn(WinDisplayDeviceInterface &win_dd, const DeviceDisplayModeMap &modes); + DdGuardFn modeGuardFn(WinDisplayDeviceInterface &win_dd, const DeviceDisplayModeMap &modes); /** * @brief Make guard function for the primary display. @@ -219,8 +189,7 @@ namespace display_device::win_utils { * boost::scope::scope_exit guard { primaryGuardFn(*iface, iface->getCurrentTopology()) }; * @examples_end */ - DdGuardFn - primaryGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); + DdGuardFn primaryGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); /** * @brief Make guard function for the primary display. @@ -234,8 +203,7 @@ namespace display_device::win_utils { * boost::scope::scope_exit guard { primaryGuardFn(*iface, prev_primary_device) }; * @examples_end */ - DdGuardFn - primaryGuardFn(WinDisplayDeviceInterface &win_dd, const std::string &primary_device); + DdGuardFn primaryGuardFn(WinDisplayDeviceInterface &win_dd, const std::string &primary_device); /** * @brief Make guard function for the HDR states. @@ -247,8 +215,7 @@ namespace display_device::win_utils { * boost::scope::scope_exit guard { hdrStateGuardFn(*iface, iface->getCurrentTopology()) }; * @examples_end */ - DdGuardFn - hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); + DdGuardFn hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology); /** * @brief Make guard function for the HDR states. @@ -262,6 +229,5 @@ namespace display_device::win_utils { * boost::scope::scope_exit guard { hdrStateGuardFn(*iface, states) }; * @examples_end */ - DdGuardFn - hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const HdrStateMap &states); + DdGuardFn hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const HdrStateMap &states); } // namespace display_device::win_utils diff --git a/src/windows/include/display_device/windows/types.h b/src/windows/include/display_device/windows/types.h index 2fad0b4..dc049ec 100644 --- a/src/windows/include/display_device/windows/types.h +++ b/src/windows/include/display_device/windows/types.h @@ -95,8 +95,7 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const DisplayMode &lhs, const DisplayMode &rhs); + friend bool operator==(const DisplayMode &lhs, const DisplayMode &rhs); }; /** @@ -124,8 +123,7 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const Initial &lhs, const Initial &rhs); + friend bool operator==(const Initial &lhs, const Initial &rhs); }; /** @@ -148,14 +146,12 @@ namespace display_device { * const has_modifications = state.hasModifications(); * @examples_end */ - [[nodiscard]] bool - hasModifications() const; + [[nodiscard]] bool hasModifications() const; /** * @brief Comparator for strict equality. */ - friend bool - operator==(const Modified &lhs, const Modified &rhs); + friend bool operator==(const Modified &lhs, const Modified &rhs); }; Initial m_initial; @@ -164,8 +160,7 @@ namespace display_device { /** * @brief Comparator for strict equality. */ - friend bool - operator==(const SingleDisplayConfigState &lhs, const SingleDisplayConfigState &rhs); + friend bool operator==(const SingleDisplayConfigState &lhs, const SingleDisplayConfigState &rhs); }; /** @@ -177,12 +172,11 @@ namespace display_device { * @brief Settings for workarounds/hacks for Windows. */ struct WinWorkarounds { - std::optional m_hdr_blank_delay { std::nullopt }; ///< @seealso{win_utils::blankHdrStates for more details.} + std::optional m_hdr_blank_delay {std::nullopt}; ///< @seealso{win_utils::blankHdrStates for more details.} /** * @brief Comparator for strict equality. */ - friend bool - operator==(const WinWorkarounds &lhs, const WinWorkarounds &rhs); + friend bool operator==(const WinWorkarounds &lhs, const WinWorkarounds &rhs); }; } // namespace display_device 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 e4874cc..d328421 100644 --- a/src/windows/include/display_device/windows/win_api_layer.h +++ b/src/windows/include/display_device/windows/win_api_layer.h @@ -14,43 +14,33 @@ namespace display_device { class WinApiLayer: public WinApiLayerInterface { public: /** For details @see WinApiLayerInterface::getErrorString */ - [[nodiscard]] std::string - getErrorString(LONG error_code) const override; + [[nodiscard]] std::string getErrorString(LONG error_code) const override; /** For details @see WinApiLayerInterface::queryDisplayConfig */ - [[nodiscard]] std::optional - queryDisplayConfig(QueryType type) const override; + [[nodiscard]] std::optional queryDisplayConfig(QueryType type) const override; /** For details @see WinApiLayerInterface::getDeviceId */ - [[nodiscard]] std::string - getDeviceId(const DISPLAYCONFIG_PATH_INFO &path) const override; + [[nodiscard]] std::string getDeviceId(const DISPLAYCONFIG_PATH_INFO &path) const override; /** For details @see WinApiLayerInterface::getMonitorDevicePath */ - [[nodiscard]] std::string - getMonitorDevicePath(const DISPLAYCONFIG_PATH_INFO &path) const override; + [[nodiscard]] std::string getMonitorDevicePath(const DISPLAYCONFIG_PATH_INFO &path) const override; /** For details @see WinApiLayerInterface::getFriendlyName */ - [[nodiscard]] std::string - getFriendlyName(const DISPLAYCONFIG_PATH_INFO &path) const override; + [[nodiscard]] std::string getFriendlyName(const DISPLAYCONFIG_PATH_INFO &path) const override; /** For details @see WinApiLayerInterface::getDisplayName */ - [[nodiscard]] std::string - getDisplayName(const DISPLAYCONFIG_PATH_INFO &path) const override; + [[nodiscard]] std::string getDisplayName(const DISPLAYCONFIG_PATH_INFO &path) const override; /** For details @see WinApiLayerInterface::setDisplayConfig */ - [[nodiscard]] LONG - setDisplayConfig(std::vector paths, std::vector modes, UINT32 flags) override; + [[nodiscard]] LONG setDisplayConfig(std::vector paths, std::vector modes, UINT32 flags) override; /** For details @see WinApiLayerInterface::getHdrState */ - [[nodiscard]] std::optional - getHdrState(const DISPLAYCONFIG_PATH_INFO &path) const override; + [[nodiscard]] std::optional getHdrState(const DISPLAYCONFIG_PATH_INFO &path) const override; /** For details @see WinApiLayerInterface::setHdrState */ - [[nodiscard]] bool - setHdrState(const DISPLAYCONFIG_PATH_INFO &path, HdrState state) override; + [[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(const std::string &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 426ad2b..877997a 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 @@ -27,8 +27,7 @@ namespace display_device { * const std::string error_message = iface->getErrorString(ERROR_NOT_SUPPORTED); * @examples_end */ - [[nodiscard]] virtual std::string - getErrorString(LONG error_code) const = 0; + [[nodiscard]] virtual std::string getErrorString(LONG error_code) const = 0; /** * @brief Query Windows for the device paths and associated modes. @@ -39,8 +38,7 @@ namespace display_device { * const auto display_data = iface->queryDisplayConfig(QueryType::Active); * @examples_end */ - [[nodiscard]] virtual std::optional - queryDisplayConfig(QueryType type) const = 0; + [[nodiscard]] virtual std::optional queryDisplayConfig(QueryType type) const = 0; /** * @brief Get a stable and persistent device id for the path. @@ -84,8 +82,7 @@ namespace display_device { * const std::string device_path = iface->getDeviceId(path); * @examples_end */ - [[nodiscard]] virtual std::string - getDeviceId(const DISPLAYCONFIG_PATH_INFO &path) const = 0; + [[nodiscard]] virtual std::string getDeviceId(const DISPLAYCONFIG_PATH_INFO &path) const = 0; /** * @brief Get a string that represents a path from the adapter to the display target. @@ -101,8 +98,7 @@ namespace display_device { * const std::string device_path = iface->getMonitorDevicePath(path); * @examples_end */ - [[nodiscard]] virtual std::string - getMonitorDevicePath(const DISPLAYCONFIG_PATH_INFO &path) const = 0; + [[nodiscard]] virtual std::string getMonitorDevicePath(const DISPLAYCONFIG_PATH_INFO &path) const = 0; /** * @brief Get the user friendly name for the path. @@ -116,8 +112,7 @@ namespace display_device { * const std::string friendly_name = iface->getFriendlyName(path); * @examples_end */ - [[nodiscard]] virtual std::string - getFriendlyName(const DISPLAYCONFIG_PATH_INFO &path) const = 0; + [[nodiscard]] virtual std::string getFriendlyName(const DISPLAYCONFIG_PATH_INFO &path) const = 0; /** * @brief Get the logical display name for the path. @@ -136,8 +131,7 @@ namespace display_device { * const std::string display_name = iface->getDisplayName(path); * @examples_end */ - [[nodiscard]] virtual std::string - getDisplayName(const DISPLAYCONFIG_PATH_INFO &path) const = 0; + [[nodiscard]] virtual std::string getDisplayName(const DISPLAYCONFIG_PATH_INFO &path) const = 0; /** * @brief Direct wrapper around the SetDisplayConfig WinAPI. @@ -154,8 +148,7 @@ namespace display_device { * const auto result = iface->setDisplayConfig(paths, {}, 0); * @examples_end */ - [[nodiscard]] virtual LONG - setDisplayConfig(std::vector paths, std::vector modes, UINT32 flags) = 0; + [[nodiscard]] virtual LONG setDisplayConfig(std::vector paths, std::vector modes, UINT32 flags) = 0; /** * @brief Get the HDR state the path. @@ -167,8 +160,7 @@ namespace display_device { * const auto hdr_state = iface->getHdrState(path); * @examples_end */ - [[nodiscard]] virtual std::optional - getHdrState(const DISPLAYCONFIG_PATH_INFO &path) const = 0; + [[nodiscard]] virtual std::optional getHdrState(const DISPLAYCONFIG_PATH_INFO &path) const = 0; /** * @brief Set the HDR state for the path. @@ -181,8 +173,7 @@ namespace display_device { * const bool success = iface->setHdrState(path, HdrState::Enabled); * @examples_end */ - [[nodiscard]] virtual bool - setHdrState(const DISPLAYCONFIG_PATH_INFO &path, HdrState state) = 0; + [[nodiscard]] virtual bool setHdrState(const DISPLAYCONFIG_PATH_INFO &path, HdrState state) = 0; /** * @brief Get the scaling value for the display. @@ -197,7 +188,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(const std::string &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 a9ee88f..41c6171 100644 --- a/src/windows/include/display_device/windows/win_api_utils.h +++ b/src/windows/include/display_device/windows/win_api_utils.h @@ -29,8 +29,7 @@ namespace display_device::win_utils { * const bool available = isAvailable(path); * @examples_end */ - [[nodiscard]] bool - isAvailable(const DISPLAYCONFIG_PATH_INFO &path); + [[nodiscard]] bool isAvailable(const DISPLAYCONFIG_PATH_INFO &path); /** * @brief Check if the display device path is marked as active. @@ -42,8 +41,7 @@ namespace display_device::win_utils { * const bool active = isActive(path); * @examples_end */ - [[nodiscard]] bool - isActive(const DISPLAYCONFIG_PATH_INFO &path); + [[nodiscard]] bool isActive(const DISPLAYCONFIG_PATH_INFO &path); /** * @brief Mark the display device path as active. @@ -56,8 +54,7 @@ namespace display_device::win_utils { * } * @examples_end */ - void - setActive(DISPLAYCONFIG_PATH_INFO &path); + void setActive(DISPLAYCONFIG_PATH_INFO &path); /** * @brief Check if the display's source mode is primary - if the associated device is a primary display device. @@ -69,8 +66,7 @@ namespace display_device::win_utils { * const bool is_primary = isPrimary(mode); * @examples_end */ - bool - isPrimary(const DISPLAYCONFIG_SOURCE_MODE &mode); + bool isPrimary(const DISPLAYCONFIG_SOURCE_MODE &mode); /** * @brief Get the source mode index from the path. @@ -88,8 +84,7 @@ namespace display_device::win_utils { * const auto source_index = getSourceIndex(path, modes); * @examples_end */ - [[nodiscard]] std::optional - getSourceIndex(const DISPLAYCONFIG_PATH_INFO &path, const std::vector &modes); + [[nodiscard]] std::optional getSourceIndex(const DISPLAYCONFIG_PATH_INFO &path, const std::vector &modes); /** * @brief Set the source mode index in the path. @@ -102,8 +97,7 @@ namespace display_device::win_utils { * set_source_index(path, std::nullopt); * @examples_end */ - void - setSourceIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index); + void setSourceIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index); /** * @brief Set the target mode index in the path. @@ -116,8 +110,7 @@ namespace display_device::win_utils { * set_target_index(path, std::nullopt); * @examples_end */ - void - setTargetIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index); + void setTargetIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index); /** * @brief Set the desktop mode index in the path. @@ -130,8 +123,7 @@ namespace display_device::win_utils { * set_desktop_index(path, std::nullopt); * @examples_end */ - void - setDesktopIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index); + void setDesktopIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index); /** * @brief Set the clone group id in the path. @@ -144,8 +136,7 @@ namespace display_device::win_utils { * set_clone_group_id(path, std::nullopt); * @examples_end */ - void - setCloneGroupId(DISPLAYCONFIG_PATH_INFO &path, const std::optional &id); + void setCloneGroupId(DISPLAYCONFIG_PATH_INFO &path, const std::optional &id); /** * @brief Get the source mode from the list at the specified index. @@ -165,14 +156,12 @@ namespace display_device::win_utils { * const DISPLAYCONFIG_SOURCE_MODE* source_mode = getSourceMode(getSourceIndex(path, modes), modes); * @examples_end */ - [[nodiscard]] const DISPLAYCONFIG_SOURCE_MODE * - getSourceMode(const std::optional &index, const std::vector &modes); + [[nodiscard]] const DISPLAYCONFIG_SOURCE_MODE *getSourceMode(const std::optional &index, const std::vector &modes); /** * @see getSourceMode (const version) for the description. */ - [[nodiscard]] DISPLAYCONFIG_SOURCE_MODE * - getSourceMode(const std::optional &index, std::vector &modes); + [[nodiscard]] DISPLAYCONFIG_SOURCE_MODE *getSourceMode(const std::optional &index, std::vector &modes); /** * @brief Validate the path and get the commonly used information from it. @@ -198,8 +187,7 @@ namespace display_device::win_utils { * const auto device_info = getDeviceInfoForValidPath(*iface, path, ValidatedPathType::Active); * @examples_end */ - [[nodiscard]] std::optional - getDeviceInfoForValidPath(const WinApiLayerInterface &w_api, const DISPLAYCONFIG_PATH_INFO &path, ValidatedPathType type); + [[nodiscard]] std::optional getDeviceInfoForValidPath(const WinApiLayerInterface &w_api, const DISPLAYCONFIG_PATH_INFO &path, ValidatedPathType type); /** * @brief Get the active path matching the device id. @@ -214,14 +202,12 @@ 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); + [[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]] DISPLAYCONFIG_PATH_INFO *getActivePath(const WinApiLayerInterface &w_api, const std::string &device_id, std::vector &paths); /** * @brief Collect arbitrary source data from provided paths. @@ -239,8 +225,7 @@ namespace display_device::win_utils { * const auto path_data = collectSourceDataForMatchingPaths(*iface, paths); * @examples_end */ - [[nodiscard]] PathSourceIndexDataMap - collectSourceDataForMatchingPaths(const WinApiLayerInterface &w_api, const std::vector &paths); + [[nodiscard]] PathSourceIndexDataMap collectSourceDataForMatchingPaths(const WinApiLayerInterface &w_api, const std::vector &paths); /** * @brief Select the best possible paths to be used for the requested topology based on the data that is available to us. @@ -261,8 +246,7 @@ namespace display_device::win_utils { * @param paths Display paths that were used for collecting source data. * @return A list of path that will make up new topology, or an empty list if function fails. */ - [[nodiscard]] std::vector - makePathsForNewTopology(const ActiveTopology &new_topology, const PathSourceIndexDataMap &path_source_data, const std::vector &paths); + [[nodiscard]] std::vector makePathsForNewTopology(const ActiveTopology &new_topology, const PathSourceIndexDataMap &path_source_data, const std::vector &paths); /** * @brief Get all the missing duplicate device ids for the provided device ids. @@ -275,8 +259,7 @@ namespace display_device::win_utils { * const auto device_ids_with_duplicates = getAllDeviceIdsAndMatchingDuplicates(*iface, { "MY_ID1" }); * @examples_end */ - [[nodiscard]] std::set - getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const std::set &device_ids); + [[nodiscard]] std::set getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const std::set &device_ids); /** * @brief Check if the refresh rates are almost equal. @@ -288,8 +271,7 @@ namespace display_device::win_utils { * const bool not_equal = fuzzyCompareRefreshRates(Rational { 60, 1 }, Rational { 5585, 100 }); * @examples_end */ - [[nodiscard]] bool - fuzzyCompareRefreshRates(const Rational &lhs, const Rational &rhs); + [[nodiscard]] bool fuzzyCompareRefreshRates(const Rational &lhs, const Rational &rhs); /** * @brief Check if the display modes are almost equal. @@ -303,6 +285,5 @@ namespace display_device::win_utils { * DisplayMode { { 1920, 1080 }, { 5585, 100 } }); * @examples_end */ - [[nodiscard]] bool - fuzzyCompareModes(const DisplayMode &lhs, const DisplayMode &rhs); + [[nodiscard]] bool fuzzyCompareModes(const DisplayMode &lhs, const DisplayMode &rhs); } // namespace display_device::win_utils diff --git a/src/windows/include/display_device/windows/win_display_device.h b/src/windows/include/display_device/windows/win_display_device.h index d5b66f9..c2fdfd1 100644 --- a/src/windows/include/display_device/windows/win_display_device.h +++ b/src/windows/include/display_device/windows/win_display_device.h @@ -24,56 +24,43 @@ namespace display_device { explicit WinDisplayDevice(std::shared_ptr w_api); /** For details @see WinDisplayDeviceInterface::isApiAccessAvailable */ - [[nodiscard]] bool - isApiAccessAvailable() const override; + [[nodiscard]] bool isApiAccessAvailable() const override; /** For details @see WinDisplayDeviceInterface::enumAvailableDevices */ - [[nodiscard]] EnumeratedDeviceList - enumAvailableDevices() const override; + [[nodiscard]] EnumeratedDeviceList enumAvailableDevices() const override; /** For details @see WinDisplayDeviceInterface::getDisplayName */ - [[nodiscard]] std::string - getDisplayName(const std::string &device_id) const override; + [[nodiscard]] std::string getDisplayName(const std::string &device_id) const override; /** For details @see WinDisplayDeviceInterface::getCurrentTopology */ - [[nodiscard]] ActiveTopology - getCurrentTopology() const override; + [[nodiscard]] ActiveTopology getCurrentTopology() const override; /** For details @see WinDisplayDeviceInterface::isTopologyValid */ - [[nodiscard]] bool - isTopologyValid(const ActiveTopology &topology) const override; + [[nodiscard]] bool isTopologyValid(const ActiveTopology &topology) const override; /** For details @see WinDisplayDeviceInterface::getCurrentTopology */ - [[nodiscard]] bool - isTopologyTheSame(const ActiveTopology &lhs, const ActiveTopology &rhs) const override; + [[nodiscard]] bool isTopologyTheSame(const ActiveTopology &lhs, const ActiveTopology &rhs) const override; /** For details @see WinDisplayDeviceInterface::setTopology */ - [[nodiscard]] bool - setTopology(const ActiveTopology &new_topology) override; + [[nodiscard]] bool setTopology(const ActiveTopology &new_topology) override; /** For details @see WinDisplayDeviceInterface::getCurrentDisplayModes */ - [[nodiscard]] DeviceDisplayModeMap - getCurrentDisplayModes(const std::set &device_ids) const override; + [[nodiscard]] DeviceDisplayModeMap getCurrentDisplayModes(const std::set &device_ids) const override; /** For details @see WinDisplayDeviceInterface::setDisplayModes */ - [[nodiscard]] bool - setDisplayModes(const DeviceDisplayModeMap &modes) override; + [[nodiscard]] bool setDisplayModes(const DeviceDisplayModeMap &modes) override; /** For details @see WinDisplayDeviceInterface::isPrimary */ - [[nodiscard]] bool - isPrimary(const std::string &device_id) const override; + [[nodiscard]] bool isPrimary(const std::string &device_id) const override; /** For details @see WinDisplayDeviceInterface::setAsPrimary */ - [[nodiscard]] bool - setAsPrimary(const std::string &device_id) override; + [[nodiscard]] bool setAsPrimary(const std::string &device_id) override; /** For details @see WinDisplayDeviceInterface::getCurrentHdrStates */ - [[nodiscard]] HdrStateMap - getCurrentHdrStates(const std::set &device_ids) const override; + [[nodiscard]] HdrStateMap getCurrentHdrStates(const std::set &device_ids) const override; /** For details @see WinDisplayDeviceInterface::setHdrStates */ - [[nodiscard]] bool - setHdrStates(const HdrStateMap &states) override; + [[nodiscard]] bool setHdrStates(const HdrStateMap &states) override; private: std::shared_ptr m_w_api; diff --git a/src/windows/include/display_device/windows/win_display_device_interface.h b/src/windows/include/display_device/windows/win_display_device_interface.h index 60abfc2..a3f4d8c 100644 --- a/src/windows/include/display_device/windows/win_display_device_interface.h +++ b/src/windows/include/display_device/windows/win_display_device_interface.h @@ -29,8 +29,7 @@ namespace display_device { * const bool have_access { iface->isApiAccessAvailable() }; * @examples_end */ - [[nodiscard]] virtual bool - isApiAccessAvailable() const = 0; + [[nodiscard]] virtual bool isApiAccessAvailable() const = 0; /** * @brief Enumerate the available (active and inactive) devices. @@ -40,8 +39,7 @@ namespace display_device { * const auto devices { enumAvailableDevices() }; * @examples_end */ - [[nodiscard]] virtual EnumeratedDeviceList - enumAvailableDevices() const = 0; + [[nodiscard]] virtual EnumeratedDeviceList enumAvailableDevices() const = 0; /** * @brief Get display name associated with the device. @@ -54,8 +52,7 @@ namespace display_device { * const std::string display_name = iface->getDisplayName(device_id); * @examples_end */ - [[nodiscard]] virtual std::string - getDisplayName(const std::string &device_id) const = 0; + [[nodiscard]] virtual std::string getDisplayName(const std::string &device_id) const = 0; /** * @brief Get the active (current) topology. @@ -66,8 +63,7 @@ namespace display_device { * const auto current_topology { iface->getCurrentTopology() }; * @examples_end */ - [[nodiscard]] virtual ActiveTopology - getCurrentTopology() const = 0; + [[nodiscard]] virtual ActiveTopology getCurrentTopology() const = 0; /** * @brief Verify if the active topology is valid. @@ -84,8 +80,7 @@ namespace display_device { * const bool is_valid = iface->isTopologyValid(current_topology); * @examples_end */ - [[nodiscard]] virtual bool - isTopologyValid(const ActiveTopology &topology) const = 0; + [[nodiscard]] virtual bool isTopologyValid(const ActiveTopology &topology) const = 0; /** * @brief Check if the topologies are close enough to be considered the same by the OS. @@ -100,8 +95,7 @@ namespace display_device { * const bool is_the_same = iface->isTopologyTheSame(current_topology, new_topology); * @examples_end */ - [[nodiscard]] virtual bool - isTopologyTheSame(const ActiveTopology &lhs, const ActiveTopology &rhs) const = 0; + [[nodiscard]] virtual bool isTopologyTheSame(const ActiveTopology &lhs, const ActiveTopology &rhs) const = 0; /** * @brief Set a new active topology for the OS. @@ -114,8 +108,7 @@ namespace display_device { * const bool success = iface->setTopology(current_topology); * @examples_end */ - [[nodiscard]] virtual bool - setTopology(const ActiveTopology &new_topology) = 0; + [[nodiscard]] virtual bool setTopology(const ActiveTopology &new_topology) = 0; /** * @brief Get current display modes for the devices. @@ -128,8 +121,7 @@ namespace display_device { * const auto current_modes = iface->getCurrentDisplayModes(device_ids); * @examples_end */ - [[nodiscard]] virtual DeviceDisplayModeMap - getCurrentDisplayModes(const std::set &device_ids) const = 0; + [[nodiscard]] virtual DeviceDisplayModeMap getCurrentDisplayModes(const std::set &device_ids) const = 0; /** * @brief Set new display modes for the devices. @@ -145,8 +137,7 @@ namespace display_device { * { display_b, { { 1920, 1080 }, { 120, 1 } } } }); * @examples_end */ - [[nodiscard]] virtual bool - setDisplayModes(const DeviceDisplayModeMap &modes) = 0; + [[nodiscard]] virtual bool setDisplayModes(const DeviceDisplayModeMap &modes) = 0; /** * @brief Check whether the specified device is primary. @@ -158,8 +149,7 @@ namespace display_device { * const bool is_primary = iface->isPrimary(device_id); * @examples_end */ - [[nodiscard]] virtual bool - isPrimary(const std::string &device_id) const = 0; + [[nodiscard]] virtual bool isPrimary(const std::string &device_id) const = 0; /** * @brief Set the device as a primary display. @@ -172,8 +162,7 @@ namespace display_device { * const bool success = iface->set_as_primary_device(device_id); * @examples_end */ - [[nodiscard]] virtual bool - setAsPrimary(const std::string &device_id) = 0; + [[nodiscard]] virtual bool setAsPrimary(const std::string &device_id) = 0; /** * @brief Get HDR state for the devices. @@ -186,8 +175,7 @@ namespace display_device { * const auto current_hdr_states = iface->getCurrentHdrStates(device_ids); * @examples_end */ - [[nodiscard]] virtual HdrStateMap - getCurrentHdrStates(const std::set &device_ids) const = 0; + [[nodiscard]] virtual HdrStateMap getCurrentHdrStates(const std::set &device_ids) const = 0; /** * @brief Set HDR states for the devices. @@ -203,7 +191,6 @@ namespace display_device { * { display_b, HdrState::Disabled } }); * @examples_end */ - [[nodiscard]] virtual bool - setHdrStates(const HdrStateMap &states) = 0; + [[nodiscard]] virtual bool setHdrStates(const HdrStateMap &states) = 0; }; } // namespace display_device diff --git a/src/windows/json.cpp b/src/windows/json.cpp index 44b49d9..967c209 100644 --- a/src/windows/json.cpp +++ b/src/windows/json.cpp @@ -13,7 +13,7 @@ // clang-format on namespace display_device { - const std::optional JSON_COMPACT { std::nullopt }; + const std::optional JSON_COMPACT {std::nullopt}; DD_JSON_DEFINE_CONVERTER(ActiveTopology) DD_JSON_DEFINE_CONVERTER(DeviceDisplayModeMap) diff --git a/src/windows/persistent_state.cpp b/src/windows/persistent_state.cpp index 23fae78..2ff9d5e 100644 --- a/src/windows/persistent_state.cpp +++ b/src/windows/persistent_state.cpp @@ -12,27 +12,26 @@ namespace display_device { PersistentState::PersistentState(std::shared_ptr settings_persistence_api, const bool throw_on_load_error): - m_settings_persistence_api { std::move(settings_persistence_api) } { + m_settings_persistence_api {std::move(settings_persistence_api)} { if (!m_settings_persistence_api) { m_settings_persistence_api = std::make_shared(); } std::string error_message; - if (const auto persistent_settings { m_settings_persistence_api->load() }) { + if (const auto persistent_settings {m_settings_persistence_api->load()}) { if (!persistent_settings->empty()) { m_cached_state = SingleDisplayConfigState {}; - if (!fromJson({ std::begin(*persistent_settings), std::end(*persistent_settings) }, *m_cached_state, &error_message)) { + if (!fromJson({std::begin(*persistent_settings), std::end(*persistent_settings)}, *m_cached_state, &error_message)) { error_message = "Failed to parse persistent settings! Error:\n" + error_message; } } - } - else { + } else { error_message = "Failed to load persistent settings!"; } if (!error_message.empty()) { if (throw_on_load_error) { - throw std::runtime_error { error_message }; + throw std::runtime_error {error_message}; } DD_LOG(error) << error_message; @@ -40,8 +39,7 @@ namespace display_device { } } - bool - PersistentState::persistState(const std::optional &state) { + bool PersistentState::persistState(const std::optional &state) { if (m_cached_state == state) { return true; } @@ -55,15 +53,15 @@ namespace display_device { return true; } - bool success { false }; - const auto json_string { toJson(*state, 2, &success) }; + bool success {false}; + const auto json_string {toJson(*state, 2, &success)}; if (!success) { DD_LOG(error) << "Failed to serialize new persistent state! Error:\n" << json_string; return false; } - if (!m_settings_persistence_api->store({ std::begin(json_string), std::end(json_string) })) { + if (!m_settings_persistence_api->store({std::begin(json_string), std::end(json_string)})) { return false; } @@ -71,8 +69,7 @@ namespace display_device { return true; } - const std::optional & - PersistentState::getState() const { + const std::optional &PersistentState::getState() const { return m_cached_state; } } // namespace display_device diff --git a/src/windows/settings_manager_apply.cpp b/src/windows/settings_manager_apply.cpp index 7c98cba..1f6c505 100644 --- a/src/windows/settings_manager_apply.cpp +++ b/src/windows/settings_manager_apply.cpp @@ -19,14 +19,12 @@ namespace display_device { /** * @brief Function that does nothing. */ - void - noopFn() { + void noopFn() { } } // namespace - SettingsManager::ApplyResult - SettingsManager::applySettings(const SingleDisplayConfiguration &config) { - const auto api_access { m_dd_api->isApiAccessAvailable() }; + SettingsManager::ApplyResult SettingsManager::applySettings(const SingleDisplayConfiguration &config) { + const auto api_access {m_dd_api->isApiAccessAvailable()}; DD_LOG(info) << "Trying to apply display device settings. API is available: " << toJson(api_access); if (!api_access) { @@ -35,7 +33,7 @@ namespace display_device { DD_LOG(info) << "Using the following configuration:\n" << toJson(config); - const auto topology_before_changes { m_dd_api->getCurrentTopology() }; + const auto topology_before_changes {m_dd_api->getCurrentTopology()}; if (!m_dd_api->isTopologyValid(topology_before_changes)) { DD_LOG(error) << "Retrieved current topology is invalid:\n" << toJson(topology_before_changes); @@ -44,18 +42,18 @@ namespace display_device { DD_LOG(info) << "Active topology before any changes:\n" << toJson(topology_before_changes); - bool system_settings_touched { false }; - boost::scope::scope_exit hdr_blank_always_executed_guard { [this, &system_settings_touched]() { + bool system_settings_touched {false}; + boost::scope::scope_exit hdr_blank_always_executed_guard {[this, &system_settings_touched]() { if (system_settings_touched) { win_utils::blankHdrStates(*m_dd_api, m_workarounds.m_hdr_blank_delay); } - } }; + }}; - bool release_context { false }; - boost::scope::scope_exit topology_prep_guard { [this, topology = topology_before_changes, was_captured = m_audio_context_api->isCaptured(), &release_context]() { + bool release_context {false}; + boost::scope::scope_exit topology_prep_guard {[this, topology = topology_before_changes, was_captured = m_audio_context_api->isCaptured(), &release_context]() { // It is possible that during topology preparation, some settings will be reverted for the modified topology. // To keel it simple, these settings will not be restored! - const auto result { m_dd_api->setTopology(topology) }; + const auto result {m_dd_api->setTopology(topology)}; if (!result) { DD_LOG(error) << "Failed to revert back to topology in the topology guard!"; if (release_context) { @@ -70,31 +68,31 @@ namespace display_device { // We only want to release context that was not captured before. m_audio_context_api->release(); } - } }; + }}; - const auto &prepped_topology_data { prepareTopology(config, topology_before_changes, release_context, system_settings_touched) }; + const auto &prepped_topology_data {prepareTopology(config, topology_before_changes, release_context, system_settings_touched)}; if (!prepped_topology_data) { // Error already logged return ApplyResult::DevicePrepFailed; } auto [new_state, device_to_configure, additional_devices_to_configure] = *prepped_topology_data; - DdGuardFn primary_guard_fn { noopFn }; - boost::scope::scope_exit primary_guard { primary_guard_fn }; + DdGuardFn primary_guard_fn {noopFn}; + boost::scope::scope_exit primary_guard {primary_guard_fn}; if (!preparePrimaryDevice(config, device_to_configure, primary_guard_fn, new_state, system_settings_touched)) { // Error already logged return ApplyResult::PrimaryDevicePrepFailed; } - DdGuardFn mode_guard_fn { noopFn }; - boost::scope::scope_exit mode_guard { mode_guard_fn }; + DdGuardFn mode_guard_fn {noopFn}; + boost::scope::scope_exit mode_guard {mode_guard_fn}; if (!prepareDisplayModes(config, device_to_configure, additional_devices_to_configure, mode_guard_fn, new_state, system_settings_touched)) { // Error already logged return ApplyResult::DisplayModePrepFailed; } - DdGuardFn hdr_state_guard_fn { noopFn }; - boost::scope::scope_exit hdr_state_guard { hdr_state_guard_fn }; + DdGuardFn hdr_state_guard_fn {noopFn}; + boost::scope::scope_exit hdr_state_guard {hdr_state_guard_fn}; if (!prepareHdrStates(config, device_to_configure, additional_devices_to_configure, hdr_state_guard_fn, new_state, system_settings_touched)) { // Error already logged return ApplyResult::HdrStatePrepFailed; @@ -120,9 +118,8 @@ namespace display_device { return ApplyResult::Ok; } - std::optional>> - SettingsManager::prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched) { - const EnumeratedDeviceList devices { m_dd_api->enumAvailableDevices() }; + std::optional>> SettingsManager::prepareTopology(const SingleDisplayConfiguration &config, const ActiveTopology &topology_before_changes, bool &release_context, bool &system_settings_touched) { + const EnumeratedDeviceList devices {m_dd_api->enumAvailableDevices()}; if (devices.empty()) { DD_LOG(error) << "Failed to enumerate display devices!"; return std::nullopt; @@ -131,7 +128,9 @@ namespace display_device { << toJson(devices); if (!config.m_device_id.empty()) { - auto device_it { std::ranges::find_if(devices, [device_id = config.m_device_id](const auto &item) { return item.m_device_id == device_id; }) }; + auto device_it {std::ranges::find_if(devices, [device_id = config.m_device_id](const auto &item) { + return item.m_device_id == device_id; + })}; if (device_it == std::end(devices)) { // Do not use toJson in case the user entered some BS string... DD_LOG(error) << "Device \"" << config.m_device_id << "\" is not available in the system!"; @@ -139,24 +138,24 @@ namespace display_device { } } - const auto &cached_state { m_persistence_state->getState() }; - const auto new_initial_state { win_utils::computeInitialState(cached_state ? std::make_optional(cached_state->m_initial) : std::nullopt, topology_before_changes, devices) }; + const auto &cached_state {m_persistence_state->getState()}; + const auto new_initial_state {win_utils::computeInitialState(cached_state ? std::make_optional(cached_state->m_initial) : std::nullopt, topology_before_changes, devices)}; if (!new_initial_state) { // Error already logged return std::nullopt; } - SingleDisplayConfigState new_state { *new_initial_state }; + SingleDisplayConfigState new_state {*new_initial_state}; // In case some devices are no longer available in the system, we could try to strip them from the initial state // and hope that we are still "safe" to make further changes (to be determined by computeNewTopologyAndMetadata call below). - const auto stripped_initial_state { win_utils::stripInitialState(new_state.m_initial, devices) }; + const auto stripped_initial_state {win_utils::stripInitialState(new_state.m_initial, devices)}; if (!stripped_initial_state) { // Error already logged return std::nullopt; } const auto &[new_topology, device_to_configure, additional_devices_to_configure] = win_utils::computeNewTopologyAndMetadata(config.m_device_prep, config.m_device_id, *stripped_initial_state); - const auto change_is_needed { !m_dd_api->isTopologyTheSame(topology_before_changes, new_topology) }; + const auto change_is_needed {!m_dd_api->isTopologyTheSame(topology_before_changes, new_topology)}; DD_LOG(info) << "Newly computed display device topology data:\n" << " - topology: " << toJson(new_topology, JSON_COMPACT) << "\n" << " - change is needed: " << toJson(change_is_needed, JSON_COMPACT) << "\n" @@ -178,11 +177,11 @@ namespace display_device { } } - const bool audio_is_captured { m_audio_context_api->isCaptured() }; + const bool audio_is_captured {m_audio_context_api->isCaptured()}; if (!audio_is_captured) { // Non-stripped initial state MUST be checked here as the missing device could have its context captured! - const bool switching_from_initial { m_dd_api->isTopologyTheSame(new_state.m_initial.m_topology, topology_before_changes) }; - const bool new_topology_contains_all_current_topology_devices { std::ranges::includes(win_utils::flattenTopology(new_topology), win_utils::flattenTopology(topology_before_changes)) }; + const bool switching_from_initial {m_dd_api->isTopologyTheSame(new_state.m_initial.m_topology, topology_before_changes)}; + const bool new_topology_contains_all_current_topology_devices {std::ranges::includes(win_utils::flattenTopology(new_topology), win_utils::flattenTopology(topology_before_changes))}; if (switching_from_initial && !new_topology_contains_all_current_topology_devices) { // Only capture the context when switching from initial topology. All the other intermediate states, like non-existent // capture state after system restart are to be avoided. @@ -207,12 +206,11 @@ namespace display_device { return std::make_tuple(new_state, device_to_configure, additional_devices_to_configure); } - bool - SettingsManager::preparePrimaryDevice(const SingleDisplayConfiguration &config, const std::string &device_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { - const auto &cached_state { m_persistence_state->getState() }; - const auto cached_primary_device { cached_state ? cached_state->m_modified.m_original_primary_device : std::string {} }; - const bool ensure_primary { config.m_device_prep == SingleDisplayConfiguration::DevicePreparation::EnsurePrimary }; - const bool might_need_to_restore { !cached_primary_device.empty() }; + bool SettingsManager::preparePrimaryDevice(const SingleDisplayConfiguration &config, const std::string &device_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { + const auto &cached_state {m_persistence_state->getState()}; + const auto cached_primary_device {cached_state ? cached_state->m_modified.m_original_primary_device : std::string {}}; + const bool ensure_primary {config.m_device_prep == SingleDisplayConfiguration::DevicePreparation::EnsurePrimary}; + const bool might_need_to_restore {!cached_primary_device.empty()}; std::string current_primary_device; if (ensure_primary || might_need_to_restore) { @@ -224,7 +222,7 @@ namespace display_device { } } - const auto try_change { [&](const std::string &new_device, const auto info_preamble, const auto error_log) { + const auto try_change {[&](const std::string &new_device, const auto info_preamble, const auto error_log) { if (current_primary_device != new_device) { system_settings_touched = true; @@ -238,11 +236,11 @@ namespace display_device { } return true; - } }; + }}; if (ensure_primary) { - const auto original_primary_device { cached_primary_device.empty() ? current_primary_device : cached_primary_device }; - const auto &new_primary_device { device_to_configure }; + const auto original_primary_device {cached_primary_device.empty() ? current_primary_device : cached_primary_device}; + const auto &new_primary_device {device_to_configure}; if (!try_change(new_primary_device, "Changing primary display to:\n", "Failed to apply new configuration, because a new primary device could not be set!")) { // Error already logged @@ -264,12 +262,11 @@ namespace display_device { return true; } - bool - SettingsManager::prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { - const auto &cached_state { m_persistence_state->getState() }; - const auto cached_display_modes { cached_state ? cached_state->m_modified.m_original_modes : DeviceDisplayModeMap {} }; - const bool change_required { config.m_resolution || config.m_refresh_rate }; - const bool might_need_to_restore { !cached_display_modes.empty() }; + bool SettingsManager::prepareDisplayModes(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { + const auto &cached_state {m_persistence_state->getState()}; + const auto cached_display_modes {cached_state ? cached_state->m_modified.m_original_modes : DeviceDisplayModeMap {}}; + const bool change_required {config.m_resolution || config.m_refresh_rate}; + const bool might_need_to_restore {!cached_display_modes.empty()}; DeviceDisplayModeMap current_display_modes; if (change_required || might_need_to_restore) { @@ -280,7 +277,7 @@ namespace display_device { } } - const auto try_change { [&](const DeviceDisplayModeMap &new_modes, const auto info_preamble, const auto error_log) { + const auto try_change {[&](const DeviceDisplayModeMap &new_modes, const auto info_preamble, const auto error_log) { if (current_display_modes != new_modes) { DD_LOG(info) << info_preamble << toJson(new_modes); if (!m_dd_api->setDisplayModes(new_modes)) { @@ -299,13 +296,12 @@ namespace display_device { } return true; - } }; + }}; if (change_required) { - const bool configuring_primary_devices { config.m_device_id.empty() }; - const auto original_display_modes { cached_display_modes.empty() ? current_display_modes : cached_display_modes }; - const auto new_display_modes { win_utils::computeNewDisplayModes(config.m_resolution, - config.m_refresh_rate, configuring_primary_devices, device_to_configure, additional_devices_to_configure, original_display_modes) }; + const bool configuring_primary_devices {config.m_device_id.empty()}; + const auto original_display_modes {cached_display_modes.empty() ? current_display_modes : cached_display_modes}; + const auto new_display_modes {win_utils::computeNewDisplayModes(config.m_resolution, config.m_refresh_rate, configuring_primary_devices, device_to_configure, additional_devices_to_configure, original_display_modes)}; if (!try_change(new_display_modes, "Changing display modes to:\n", "Failed to apply new configuration, because new display modes could not be set!")) { // Error already logged @@ -327,12 +323,11 @@ namespace display_device { return true; } - [[nodiscard]] bool - SettingsManager::prepareHdrStates(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { - const auto &cached_state { m_persistence_state->getState() }; - const auto cached_hdr_states { cached_state ? cached_state->m_modified.m_original_hdr_states : HdrStateMap {} }; - const bool change_required { config.m_hdr_state }; - const bool might_need_to_restore { !cached_hdr_states.empty() }; + [[nodiscard]] bool SettingsManager::prepareHdrStates(const SingleDisplayConfiguration &config, const std::string &device_to_configure, const std::set &additional_devices_to_configure, DdGuardFn &guard_fn, SingleDisplayConfigState &new_state, bool &system_settings_touched) { + const auto &cached_state {m_persistence_state->getState()}; + const auto cached_hdr_states {cached_state ? cached_state->m_modified.m_original_hdr_states : HdrStateMap {}}; + const bool change_required {config.m_hdr_state}; + const bool might_need_to_restore {!cached_hdr_states.empty()}; HdrStateMap current_hdr_states; if (change_required || might_need_to_restore) { @@ -343,7 +338,7 @@ namespace display_device { } } - const auto try_change { [&](const HdrStateMap &new_states, const auto info_preamble, const auto error_log) { + const auto try_change {[&](const HdrStateMap &new_states, const auto info_preamble, const auto error_log) { if (current_hdr_states != new_states) { system_settings_touched = true; @@ -357,12 +352,12 @@ namespace display_device { } return true; - } }; + }}; if (change_required) { - const bool configuring_primary_devices { config.m_device_id.empty() }; - const auto original_hdr_states { cached_hdr_states.empty() ? current_hdr_states : cached_hdr_states }; - const auto new_hdr_states { win_utils::computeNewHdrStates(config.m_hdr_state, configuring_primary_devices, device_to_configure, additional_devices_to_configure, original_hdr_states) }; + const bool configuring_primary_devices {config.m_device_id.empty()}; + const auto original_hdr_states {cached_hdr_states.empty() ? current_hdr_states : cached_hdr_states}; + const auto new_hdr_states {win_utils::computeNewHdrStates(config.m_hdr_state, configuring_primary_devices, device_to_configure, additional_devices_to_configure, original_hdr_states)}; if (!try_change(new_hdr_states, "Changing HDR states to:\n", "Failed to apply new configuration, because new HDR states could not be set!")) { // Error already logged diff --git a/src/windows/settings_manager_general.cpp b/src/windows/settings_manager_general.cpp index 624ede2..758d8b4 100644 --- a/src/windows/settings_manager_general.cpp +++ b/src/windows/settings_manager_general.cpp @@ -15,13 +15,14 @@ namespace display_device { std::shared_ptr dd_api, std::shared_ptr audio_context_api, std::unique_ptr persistent_state, - WinWorkarounds workarounds): - m_dd_api { std::move(dd_api) }, - m_audio_context_api { std::move(audio_context_api) }, - m_persistence_state { std::move(persistent_state) }, - m_workarounds { std::move(workarounds) } { + WinWorkarounds workarounds + ): + m_dd_api {std::move(dd_api)}, + m_audio_context_api {std::move(audio_context_api)}, + m_persistence_state {std::move(persistent_state)}, + m_workarounds {std::move(workarounds)} { if (!m_dd_api) { - throw std::logic_error { "Nullptr provided for WinDisplayDeviceInterface in SettingsManager!" }; + throw std::logic_error {"Nullptr provided for WinDisplayDeviceInterface in SettingsManager!"}; } if (!m_audio_context_api) { @@ -29,25 +30,22 @@ namespace display_device { } if (!m_persistence_state) { - throw std::logic_error { "Nullptr provided for PersistentState in SettingsManager!" }; + throw std::logic_error {"Nullptr provided for PersistentState in SettingsManager!"}; } DD_LOG(info) << "Provided workaround settings for SettingsManager:\n" << toJson(m_workarounds); } - EnumeratedDeviceList - SettingsManager::enumAvailableDevices() const { + EnumeratedDeviceList SettingsManager::enumAvailableDevices() const { return m_dd_api->enumAvailableDevices(); } - std::string - SettingsManager::getDisplayName(const std::string &device_id) const { + std::string SettingsManager::getDisplayName(const std::string &device_id) const { return m_dd_api->getDisplayName(device_id); } - bool - SettingsManager::resetPersistence() { + bool SettingsManager::resetPersistence() { // Trying to revert one more time in case we succeed. if (revertSettings() == RevertResult::Ok) { return true; diff --git a/src/windows/settings_manager_revert.cpp b/src/windows/settings_manager_revert.cpp index b464507..327568c 100644 --- a/src/windows/settings_manager_revert.cpp +++ b/src/windows/settings_manager_revert.cpp @@ -18,54 +18,52 @@ namespace display_device { /** * @brief Function that does nothing. */ - void - noopFn() { + void noopFn() { } } // namespace - SettingsManager::RevertResult - SettingsManager::revertSettings() { - const auto &cached_state { m_persistence_state->getState() }; + SettingsManager::RevertResult SettingsManager::revertSettings() { + const auto &cached_state {m_persistence_state->getState()}; if (!cached_state) { return RevertResult::Ok; } - const auto api_access { m_dd_api->isApiAccessAvailable() }; + const auto api_access {m_dd_api->isApiAccessAvailable()}; DD_LOG(info) << "Trying to revert applied display device settings. API is available: " << toJson(api_access); if (!api_access) { return RevertResult::ApiTemporarilyUnavailable; } - const auto current_topology { m_dd_api->getCurrentTopology() }; + const auto current_topology {m_dd_api->getCurrentTopology()}; if (!m_dd_api->isTopologyValid(current_topology)) { DD_LOG(error) << "Retrieved current topology is invalid:\n" << toJson(current_topology); return RevertResult::TopologyIsInvalid; } - bool system_settings_touched { false }; - boost::scope::scope_exit hdr_blank_always_executed_guard { [this, &system_settings_touched]() { + bool system_settings_touched {false}; + boost::scope::scope_exit hdr_blank_always_executed_guard {[this, &system_settings_touched]() { if (system_settings_touched) { win_utils::blankHdrStates(*m_dd_api, m_workarounds.m_hdr_blank_delay); } - } }; - boost::scope::scope_exit topology_prep_guard { [this, ¤t_topology, &system_settings_touched]() { - auto topology_to_restore { win_utils::createFullExtendedTopology(*m_dd_api) }; + }}; + boost::scope::scope_exit topology_prep_guard {[this, ¤t_topology, &system_settings_touched]() { + auto topology_to_restore {win_utils::createFullExtendedTopology(*m_dd_api)}; if (!m_dd_api->isTopologyValid(topology_to_restore)) { topology_to_restore = current_topology; } - const bool is_topology_the_same { m_dd_api->isTopologyTheSame(current_topology, topology_to_restore) }; + const bool is_topology_the_same {m_dd_api->isTopologyTheSame(current_topology, topology_to_restore)}; system_settings_touched = system_settings_touched || !is_topology_the_same; if (!is_topology_the_same && !m_dd_api->setTopology(topology_to_restore)) { DD_LOG(error) << "failed to revert topology in revertSettings topology guard! Used the following topology:\n" << toJson(topology_to_restore); } - } }; + }}; // We can revert the modified setting independently before playing around with initial topology. - bool switched_to_modified_topology { false }; + bool switched_to_modified_topology {false}; if (const auto result = revertModifiedSettings(current_topology, system_settings_touched, &switched_to_modified_topology); result != RevertResult::Ok) { // Error already logged return result; @@ -77,8 +75,8 @@ namespace display_device { return RevertResult::TopologyIsInvalid; } - const bool is_topology_the_same { m_dd_api->isTopologyTheSame(current_topology, cached_state->m_initial.m_topology) }; - const bool need_to_switch_topology { !is_topology_the_same || switched_to_modified_topology }; + const bool is_topology_the_same {m_dd_api->isTopologyTheSame(current_topology, cached_state->m_initial.m_topology)}; + const bool need_to_switch_topology {!is_topology_the_same || switched_to_modified_topology}; system_settings_touched = system_settings_touched || !is_topology_the_same; if (need_to_switch_topology && !m_dd_api->setTopology(cached_state->m_initial.m_topology)) { DD_LOG(error) << "Failed to change topology to:\n" @@ -100,9 +98,8 @@ namespace display_device { return RevertResult::Ok; } - SettingsManager::RevertResult - SettingsManager::revertModifiedSettings(const ActiveTopology ¤t_topology, bool &system_settings_touched, bool *switched_topology) { - const auto &cached_state { m_persistence_state->getState() }; + SettingsManager::RevertResult SettingsManager::revertModifiedSettings(const ActiveTopology ¤t_topology, bool &system_settings_touched, bool *switched_topology) { + const auto &cached_state {m_persistence_state->getState()}; if (!cached_state || !cached_state->m_modified.hasModifications()) { return RevertResult::Ok; } @@ -113,7 +110,7 @@ namespace display_device { return RevertResult::TopologyIsInvalid; } - const bool is_topology_the_same { m_dd_api->isTopologyTheSame(current_topology, cached_state->m_modified.m_topology) }; + const bool is_topology_the_same {m_dd_api->isTopologyTheSame(current_topology, cached_state->m_modified.m_topology)}; system_settings_touched = !is_topology_the_same; if (!is_topology_the_same && !m_dd_api->setTopology(cached_state->m_modified.m_topology)) { DD_LOG(error) << "Failed to change topology to:\n" @@ -124,10 +121,10 @@ namespace display_device { *switched_topology = !is_topology_the_same; } - DdGuardFn hdr_guard_fn { noopFn }; - boost::scope::scope_exit hdr_guard { hdr_guard_fn }; + DdGuardFn hdr_guard_fn {noopFn}; + boost::scope::scope_exit hdr_guard {hdr_guard_fn}; if (!cached_state->m_modified.m_original_hdr_states.empty()) { - const auto current_states { m_dd_api->getCurrentHdrStates(win_utils::flattenTopology(cached_state->m_modified.m_topology)) }; + const auto current_states {m_dd_api->getCurrentHdrStates(win_utils::flattenTopology(cached_state->m_modified.m_topology))}; if (current_states != cached_state->m_modified.m_original_hdr_states) { system_settings_touched = true; @@ -142,10 +139,10 @@ namespace display_device { } } - DdGuardFn mode_guard_fn { noopFn }; - boost::scope::scope_exit mode_guard { mode_guard_fn }; + DdGuardFn mode_guard_fn {noopFn}; + boost::scope::scope_exit mode_guard {mode_guard_fn}; if (!cached_state->m_modified.m_original_modes.empty()) { - const auto current_modes { m_dd_api->getCurrentDisplayModes(win_utils::flattenTopology(cached_state->m_modified.m_topology)) }; + const auto current_modes {m_dd_api->getCurrentDisplayModes(win_utils::flattenTopology(cached_state->m_modified.m_topology))}; if (current_modes != cached_state->m_modified.m_original_modes) { DD_LOG(info) << "Trying to change back the display modes to:\n" << toJson(cached_state->m_modified.m_original_modes); @@ -165,10 +162,10 @@ namespace display_device { } } - DdGuardFn primary_guard_fn { noopFn }; - boost::scope::scope_exit primary_guard { primary_guard_fn }; + DdGuardFn primary_guard_fn {noopFn}; + boost::scope::scope_exit primary_guard {primary_guard_fn}; if (!cached_state->m_modified.m_original_primary_device.empty()) { - const auto current_primary_device { win_utils::getPrimaryDevice(*m_dd_api, cached_state->m_modified.m_topology) }; + const auto current_primary_device {win_utils::getPrimaryDevice(*m_dd_api, cached_state->m_modified.m_topology)}; if (current_primary_device != cached_state->m_modified.m_original_primary_device) { system_settings_touched = true; @@ -182,8 +179,8 @@ namespace display_device { } } - auto cleared_data { *cached_state }; - cleared_data.m_modified = { cleared_data.m_modified.m_topology }; + auto cleared_data {*cached_state}; + cleared_data.m_modified = {cleared_data.m_modified.m_topology}; if (!m_persistence_state->persistState(cleared_data)) { DD_LOG(error) << "Failed to save reverted settings! Undoing changes to modified topology..."; return RevertResult::PersistenceSaveFailed; diff --git a/src/windows/settings_utils.cpp b/src/windows/settings_utils.cpp index 9782a8e..d49d971 100644 --- a/src/windows/settings_utils.cpp +++ b/src/windows/settings_utils.cpp @@ -19,16 +19,14 @@ namespace display_device::win_utils { /** * @brief predicate for getDeviceIds. */ - bool - anyDevice(const EnumeratedDevice &) { + bool anyDevice(const EnumeratedDevice &) { return true; } /** * @brief predicate for getDeviceIds. */ - bool - primaryOnlyDevices(const EnumeratedDevice &device) { + bool primaryOnlyDevices(const EnumeratedDevice &device) { return device.m_info && device.m_info->m_primary; } @@ -44,8 +42,7 @@ namespace display_device::win_utils { * const auto primary_only_ids { getDeviceIds(devices, primaryOnlyDevices) }; * @examples_end */ - std::set - getDeviceIds(const EnumeratedDeviceList &devices, const std::add_lvalue_reference_t &predicate) { + std::set getDeviceIds(const EnumeratedDeviceList &devices, const std::add_lvalue_reference_t &predicate) { std::set device_ids; for (const auto &device : devices) { if (predicate(device)) { @@ -62,9 +59,8 @@ namespace display_device::win_utils { * @param devices List of devices. * @return Topology without missing device ids. */ - ActiveTopology - stripTopology(const ActiveTopology &topology, const EnumeratedDeviceList &devices) { - const std::set available_device_ids { getDeviceIds(devices, anyDevice) }; + ActiveTopology stripTopology(const ActiveTopology &topology, const EnumeratedDeviceList &devices) { + const std::set available_device_ids {getDeviceIds(devices, anyDevice)}; ActiveTopology stripped_topology; for (const auto &group : topology) { @@ -89,13 +85,11 @@ namespace display_device::win_utils { * @param devices List of devices. * @return List without missing device ids. */ - std::set - stripDevices(const std::set &device_ids, const EnumeratedDeviceList &devices) { - std::set available_device_ids { getDeviceIds(devices, anyDevice) }; + std::set stripDevices(const std::set &device_ids, const EnumeratedDeviceList &devices) { + std::set available_device_ids {getDeviceIds(devices, anyDevice)}; std::set available_devices; - std::ranges::set_intersection(device_ids, available_device_ids, - std::inserter(available_devices, std::begin(available_devices))); + std::ranges::set_intersection(device_ids, available_device_ids, std::inserter(available_devices, std::begin(available_devices))); return available_devices; } @@ -105,8 +99,7 @@ namespace display_device::win_utils { * @param target_device_id Device id whose group to search for. * @return Other ids in the group without (excluding the provided one). */ - std::set - tryGetOtherDevicesInTheSameGroup(const ActiveTopology &topology, const std::string &target_device_id) { + std::set tryGetOtherDevicesInTheSameGroup(const ActiveTopology &topology, const std::string &target_device_id) { std::set device_ids; for (const auto &group : topology) { @@ -126,16 +119,14 @@ namespace display_device::win_utils { /** * @brief Merge the configurable devices into a vector. */ - std::vector - joinConfigurableDevices(const std::string &device_to_configure, const std::set &additional_devices_to_configure) { - std::vector devices { device_to_configure }; + std::vector joinConfigurableDevices(const std::string &device_to_configure, const std::set &additional_devices_to_configure) { + std::vector devices {device_to_configure}; devices.insert(std::end(devices), std::begin(additional_devices_to_configure), std::end(additional_devices_to_configure)); return devices; } } // namespace - std::set - flattenTopology(const ActiveTopology &topology) { + std::set flattenTopology(const ActiveTopology &topology) { std::set flattened_topology; for (const auto &group : topology) { for (const auto &device_id : group) { @@ -146,9 +137,8 @@ namespace display_device::win_utils { return flattened_topology; } - ActiveTopology - createFullExtendedTopology(WinDisplayDeviceInterface &win_dd) { - const auto devices { win_dd.enumAvailableDevices() }; + ActiveTopology createFullExtendedTopology(WinDisplayDeviceInterface &win_dd) { + const auto devices {win_dd.enumAvailableDevices()}; if (devices.empty()) { DD_LOG(error) << "Failed to enumerate available devices for full extended topology!"; return {}; @@ -156,15 +146,14 @@ namespace display_device::win_utils { ActiveTopology topology; for (const auto &device : devices) { - topology.push_back({ device.m_device_id }); + topology.push_back({device.m_device_id}); } return topology; } - std::string - getPrimaryDevice(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { - const auto flat_topology { flattenTopology(topology) }; + std::string getPrimaryDevice(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)) { return device_id; @@ -174,8 +163,7 @@ namespace display_device::win_utils { return {}; } - std::optional - computeInitialState(const std::optional &prev_state, const ActiveTopology &topology_before_changes, const EnumeratedDeviceList &devices) { + std::optional computeInitialState(const std::optional &prev_state, const ActiveTopology &topology_before_changes, const EnumeratedDeviceList &devices) { // We first need to determine the "initial" state that will be used when reverting // the changes as the "go-to" final state we need to achieve. It will also be used // as the base for creating new topology based on the provided config settings. @@ -191,7 +179,7 @@ namespace display_device::win_utils { return *prev_state; } - const auto primary_devices { getDeviceIds(devices, primaryOnlyDevices) }; + const auto primary_devices {getDeviceIds(devices, primaryOnlyDevices)}; if (primary_devices.empty()) { DD_LOG(error) << "Enumerated device list does not contain primary devices!"; return std::nullopt; @@ -203,8 +191,7 @@ namespace display_device::win_utils { }; } - ActiveTopology - computeNewTopology(const SingleDisplayConfiguration::DevicePreparation device_prep, const bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const ActiveTopology &initial_topology) { + ActiveTopology computeNewTopology(const SingleDisplayConfiguration::DevicePreparation device_prep, const bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const ActiveTopology &initial_topology) { using DevicePrep = SingleDisplayConfiguration::DevicePreparation; if (device_prep != DevicePrep::VerifyOnly) { @@ -212,17 +199,17 @@ namespace display_device::win_utils { // Device needs to be the only one that's active OR if it's a PRIMARY device, // only the whole PRIMARY group needs to be active (in case they are duplicated) if (configuring_primary_devices) { - return ActiveTopology { joinConfigurableDevices(device_to_configure, additional_devices_to_configure) }; + return ActiveTopology {joinConfigurableDevices(device_to_configure, additional_devices_to_configure)}; } - return ActiveTopology { { device_to_configure } }; + return ActiveTopology {{device_to_configure}}; } // The device needs to be active at least for `DevicePrep::EnsureActive || DevicePrep::EnsurePrimary`. if (!flattenTopology(initial_topology).contains(device_to_configure)) { // Create an extended topology as it's probably what makes sense the most... - ActiveTopology new_topology { initial_topology }; - new_topology.push_back({ device_to_configure }); + ActiveTopology new_topology {initial_topology}; + new_topology.push_back({device_to_configure}); return new_topology; } } @@ -230,10 +217,9 @@ namespace display_device::win_utils { return initial_topology; } - std::optional - stripInitialState(const SingleDisplayConfigState::Initial &initial_state, const EnumeratedDeviceList &devices) { - const auto stripped_initial_topology { stripTopology(initial_state.m_topology, devices) }; - auto initial_primary_devices { stripDevices(initial_state.m_primary_devices, devices) }; + std::optional stripInitialState(const SingleDisplayConfigState::Initial &initial_state, const EnumeratedDeviceList &devices) { + const auto stripped_initial_topology {stripTopology(initial_state.m_topology, devices)}; + auto initial_primary_devices {stripDevices(initial_state.m_primary_devices, devices)}; if (stripped_initial_topology.empty()) { DD_LOG(error) << "Enumerated device list does not contain ANY of the devices from the initial state!"; @@ -263,13 +249,10 @@ namespace display_device::win_utils { }; } - std::tuple> - computeNewTopologyAndMetadata(const SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state) { - const bool configuring_unspecified_devices { device_id.empty() }; - const auto device_to_configure { configuring_unspecified_devices ? *std::begin(initial_state.m_primary_devices) : device_id }; - auto additional_devices_to_configure { configuring_unspecified_devices ? - std::set { std::next(std::begin(initial_state.m_primary_devices)), std::end(initial_state.m_primary_devices) } : - tryGetOtherDevicesInTheSameGroup(initial_state.m_topology, device_to_configure) }; + std::tuple> computeNewTopologyAndMetadata(const SingleDisplayConfiguration::DevicePreparation device_prep, const std::string &device_id, const SingleDisplayConfigState::Initial &initial_state) { + const bool configuring_unspecified_devices {device_id.empty()}; + const auto device_to_configure {configuring_unspecified_devices ? *std::begin(initial_state.m_primary_devices) : device_id}; + auto additional_devices_to_configure {configuring_unspecified_devices ? std::set {std::next(std::begin(initial_state.m_primary_devices)), std::end(initial_state.m_primary_devices)} : tryGetOtherDevicesInTheSameGroup(initial_state.m_topology, device_to_configure)}; DD_LOG(info) << "Will compute new display device topology from the following input:\n" << " - initial topology: " << toJson(initial_state.m_topology, JSON_COMPACT) << "\n" << " - initial primary devices: " << toJson(initial_state.m_primary_devices, JSON_COMPACT) << "\n" @@ -277,48 +260,46 @@ namespace display_device::win_utils { << " - device to configure: " << toJson(device_to_configure, JSON_COMPACT) << "\n" << " - additional devices to configure: " << toJson(additional_devices_to_configure, JSON_COMPACT); - const auto new_topology { computeNewTopology(device_prep, configuring_unspecified_devices, device_to_configure, additional_devices_to_configure, initial_state.m_topology) }; + const auto new_topology {computeNewTopology(device_prep, configuring_unspecified_devices, device_to_configure, additional_devices_to_configure, initial_state.m_topology)}; additional_devices_to_configure = tryGetOtherDevicesInTheSameGroup(new_topology, device_to_configure); return std::make_tuple(new_topology, device_to_configure, additional_devices_to_configure); } - DeviceDisplayModeMap - computeNewDisplayModes(const std::optional &resolution, const std::optional &refresh_rate, const bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const DeviceDisplayModeMap &original_modes) { - DeviceDisplayModeMap new_modes { original_modes }; + DeviceDisplayModeMap computeNewDisplayModes(const std::optional &resolution, const std::optional &refresh_rate, const bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const DeviceDisplayModeMap &original_modes) { + DeviceDisplayModeMap new_modes {original_modes}; if (resolution) { // For duplicate devices the resolution must match no matter what, otherwise // they cannot be duplicated, which breaks Windows' rules. Therefore // we change resolution for all devices. - const auto devices { joinConfigurableDevices(device_to_configure, additional_devices_to_configure) }; + const auto devices {joinConfigurableDevices(device_to_configure, additional_devices_to_configure)}; for (const auto &device_id : devices) { new_modes[device_id].m_resolution = *resolution; } } if (refresh_rate) { - const auto from_floating_point { [](const FloatingPoint &value) { - if (const auto *rational_value { std::get_if(&value) }; rational_value) { + const auto from_floating_point {[](const FloatingPoint &value) { + if (const auto *rational_value {std::get_if(&value)}; rational_value) { return *rational_value; } // It's hard to deal with floating values, so we just multiply it // to keep 4 decimal places (if any) and let Windows deal with it! // Genius idea if I'm being honest. - constexpr unsigned int multiplier { 10000 }; - const double transformed_value { std::round(std::get(value) * multiplier) }; - return Rational { static_cast(transformed_value), multiplier }; - } }; + constexpr unsigned int multiplier {10000}; + const double transformed_value {std::round(std::get(value) * multiplier)}; + return Rational {static_cast(transformed_value), multiplier}; + }}; if (configuring_primary_devices) { // No device has been specified, so if they're all are primary devices // we need to apply the refresh rate change to all duplicates. - const auto devices { joinConfigurableDevices(device_to_configure, additional_devices_to_configure) }; + const auto devices {joinConfigurableDevices(device_to_configure, additional_devices_to_configure)}; for (const auto &device_id : devices) { new_modes[device_id].m_refresh_rate = from_floating_point(*refresh_rate); } - } - else { + } else { // Even if we have duplicate devices, their refresh rate may differ // and since the device was specified, let's apply the refresh // rate only to the specified device. @@ -329,13 +310,12 @@ namespace display_device::win_utils { return new_modes; } - HdrStateMap - computeNewHdrStates(const std::optional &hdr_state, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const HdrStateMap &original_states) { - HdrStateMap new_states { original_states }; + HdrStateMap computeNewHdrStates(const std::optional &hdr_state, bool configuring_primary_devices, const std::string &device_to_configure, const std::set &additional_devices_to_configure, const HdrStateMap &original_states) { + HdrStateMap new_states {original_states}; if (hdr_state) { const auto try_update_new_state = [&new_states, &hdr_state](const std::string &device_id) { - const auto current_state { new_states[device_id] }; + const auto current_state {new_states[device_id]}; if (!current_state) { return; } @@ -346,12 +326,11 @@ namespace display_device::win_utils { if (configuring_primary_devices) { // No device has been specified, so if they're all are primary devices // we need to update state for all duplicates. - const auto devices { joinConfigurableDevices(device_to_configure, additional_devices_to_configure) }; + const auto devices {joinConfigurableDevices(device_to_configure, additional_devices_to_configure)}; for (const auto &device_id : devices) { try_update_new_state(device_id); } - } - else { + } else { // Even if we have duplicate devices, their HDR states may differ // and since the device was specified, let's apply the HDR state // only to the specified device. @@ -362,19 +341,18 @@ namespace display_device::win_utils { return new_states; } - void - blankHdrStates(WinDisplayDeviceInterface &win_dd, const std::optional &delay) { + void blankHdrStates(WinDisplayDeviceInterface &win_dd, const std::optional &delay) { if (!delay) { return; } - const auto topology { win_dd.getCurrentTopology() }; + const auto topology {win_dd.getCurrentTopology()}; if (!win_dd.isTopologyValid(topology)) { DD_LOG(error) << "Got an invalid topology while trying to blank HDR states!"; return; } - const auto current_states { win_dd.getCurrentHdrStates(flattenTopology(topology)) }; + const auto current_states {win_dd.getCurrentHdrStates(flattenTopology(topology))}; if (current_states.empty()) { DD_LOG(error) << "Failed to get current HDR states! Topology:\n" << toJson(topology); @@ -411,8 +389,7 @@ namespace display_device::win_utils { } } - DdGuardFn - topologyGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { + DdGuardFn topologyGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { DD_LOG(debug) << "Got topology in topologyGuardFn:\n" << toJson(topology); return [&win_dd, topology]() { @@ -423,13 +400,11 @@ namespace display_device::win_utils { }; } - DdGuardFn - modeGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { + DdGuardFn modeGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { return modeGuardFn(win_dd, win_dd.getCurrentDisplayModes(flattenTopology(topology))); } - DdGuardFn - modeGuardFn(WinDisplayDeviceInterface &win_dd, const DeviceDisplayModeMap &modes) { + DdGuardFn modeGuardFn(WinDisplayDeviceInterface &win_dd, const DeviceDisplayModeMap &modes) { DD_LOG(debug) << "Got modes in modeGuardFn:\n" << toJson(modes); return [&win_dd, modes]() { @@ -440,13 +415,11 @@ namespace display_device::win_utils { }; } - DdGuardFn - primaryGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { + DdGuardFn primaryGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { return primaryGuardFn(win_dd, getPrimaryDevice(win_dd, topology)); } - DdGuardFn - primaryGuardFn(WinDisplayDeviceInterface &win_dd, const std::string &primary_device) { + DdGuardFn primaryGuardFn(WinDisplayDeviceInterface &win_dd, const std::string &primary_device) { DD_LOG(debug) << "Got primary device in primaryGuardFn:\n" << toJson(primary_device); return [&win_dd, primary_device]() { @@ -457,13 +430,11 @@ namespace display_device::win_utils { }; } - DdGuardFn - hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { + DdGuardFn hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const ActiveTopology &topology) { return hdrStateGuardFn(win_dd, win_dd.getCurrentHdrStates(flattenTopology(topology))); } - DdGuardFn - hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const HdrStateMap &states) { + DdGuardFn hdrStateGuardFn(WinDisplayDeviceInterface &win_dd, const HdrStateMap &states) { DD_LOG(debug) << "Got states in hdrStateGuardFn:\n" << toJson(states); return [&win_dd, states]() { diff --git a/src/windows/types.cpp b/src/windows/types.cpp index 44d0708..3f80520 100644 --- a/src/windows/types.cpp +++ b/src/windows/types.cpp @@ -6,33 +6,27 @@ #include "display_device/windows/types.h" namespace display_device { - bool - operator==(const DisplayMode &lhs, const DisplayMode &rhs) { + bool operator==(const DisplayMode &lhs, const DisplayMode &rhs) { return lhs.m_refresh_rate == rhs.m_refresh_rate && lhs.m_resolution == rhs.m_resolution; } - bool - SingleDisplayConfigState::Modified::hasModifications() const { + bool SingleDisplayConfigState::Modified::hasModifications() const { return !m_original_modes.empty() || !m_original_hdr_states.empty() || !m_original_primary_device.empty(); } - bool - operator==(const SingleDisplayConfigState::Initial &lhs, const SingleDisplayConfigState::Initial &rhs) { + bool operator==(const SingleDisplayConfigState::Initial &lhs, const SingleDisplayConfigState::Initial &rhs) { return lhs.m_topology == rhs.m_topology && lhs.m_primary_devices == rhs.m_primary_devices; } - bool - operator==(const SingleDisplayConfigState::Modified &lhs, const SingleDisplayConfigState::Modified &rhs) { + bool operator==(const SingleDisplayConfigState::Modified &lhs, const SingleDisplayConfigState::Modified &rhs) { return lhs.m_topology == rhs.m_topology && lhs.m_original_modes == rhs.m_original_modes && lhs.m_original_hdr_states == rhs.m_original_hdr_states && lhs.m_original_primary_device == rhs.m_original_primary_device; } - bool - operator==(const SingleDisplayConfigState &lhs, const SingleDisplayConfigState &rhs) { + bool operator==(const SingleDisplayConfigState &lhs, const SingleDisplayConfigState &rhs) { return lhs.m_initial == rhs.m_initial && lhs.m_modified == rhs.m_modified; } - bool - operator==(const WinWorkarounds &lhs, const WinWorkarounds &rhs) { + bool operator==(const WinWorkarounds &lhs, const WinWorkarounds &rhs) { return lhs.m_hdr_blank_delay == rhs.m_hdr_blank_delay; } } // namespace display_device diff --git a/src/windows/win_api_layer.cpp b/src/windows/win_api_layer.cpp index 9364cd5..8f37ec1 100644 --- a/src/windows/win_api_layer.cpp +++ b/src/windows/win_api_layer.cpp @@ -24,8 +24,7 @@ namespace display_device { namespace { /** @brief Dumps the result of @see queryDisplayConfig into a string */ - std::string - dumpPath(const DISPLAYCONFIG_PATH_INFO &info) { + std::string dumpPath(const DISPLAYCONFIG_PATH_INFO &info) { std::ostringstream output; std::ios state(nullptr); state.copyfmt(output); @@ -60,8 +59,7 @@ namespace display_device { } /** @brief Dumps the result of @see queryDisplayConfig into a string */ - std::string - dumpMode(const DISPLAYCONFIG_MODE_INFO &info) { + std::string dumpMode(const DISPLAYCONFIG_MODE_INFO &info) { std::stringstream output; std::ios state(nullptr); state.copyfmt(output); @@ -73,8 +71,7 @@ namespace display_device { output << "pixelFormat: " << info.sourceMode.pixelFormat << std::endl; output << "position: [" << info.sourceMode.position.x << ", " << info.sourceMode.position.y << "]"; // clang-format on - } - else if (info.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET) { + } else if (info.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET) { // clang-format off output << "pixelRate: " << info.targetMode.targetVideoSignalInfo.pixelRate << std::endl; output << "hSyncFreq: " << info.targetMode.targetVideoSignalInfo.hSyncFreq.Numerator << "/" << info.targetMode.targetVideoSignalInfo.hSyncFreq.Denominator << std::endl; @@ -84,8 +81,7 @@ namespace display_device { output << "videoStandard: " << info.targetMode.targetVideoSignalInfo.videoStandard << std::endl; output << "scanLineOrdering: " << info.targetMode.targetVideoSignalInfo.scanLineOrdering; // clang-format on - } - else if (info.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE) { + } else if (info.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE) { // TODO: One day MinGW will add updated struct definition and the following code can be enabled // clang-format off // output << "PathSourceSize: [" << info.desktopImageInfo.PathSourceSize.x << ", " << info.desktopImageInfo.PathSourceSize.y << "]" << std::endl; @@ -93,8 +89,7 @@ namespace display_device { // output << "DesktopImageClip: [" << info.desktopImageInfo.DesktopImageClip.bottom << ", " << info.desktopImageInfo.DesktopImageClip.left << ", " << info.desktopImageInfo.DesktopImageClip.right << ", " << info.desktopImageInfo.DesktopImageClip.top << "]"; // clang-format on output << "NOT SUPPORTED BY COMPILER YET..."; - } - else { + } else { output << "NOT IMPLEMENTED YET..."; } @@ -102,15 +97,13 @@ namespace display_device { } /** @brief Dumps the result of @see queryDisplayConfig into a string */ - std::string - dumpPathsAndModes(const std::vector &paths, - const std::vector &modes) { + std::string dumpPathsAndModes(const std::vector &paths, const std::vector &modes) { std::ostringstream output; output << std::endl << "Got " << paths.size() << " path(s):"; - bool path_dumped { false }; - for (auto i { 0u }; i < paths.size(); ++i) { + bool path_dumped {false}; + for (auto i {0u}; i < paths.size(); ++i) { output << std::endl << "----------------------------------------[index: " << i << "]" << std::endl; @@ -124,7 +117,7 @@ namespace display_device { } output << "Got " << modes.size() << " mode(s):"; - for (auto i { 0u }; i < modes.size(); ++i) { + for (auto i {0u}; i < modes.size(); ++i) { output << std::endl << "----------------------------------------[index: " << i << "]" << std::endl; @@ -139,21 +132,20 @@ namespace display_device { * function is identical except that it returns wide-string instead * of a normal one. */ - std::wstring - getMonitorDevicePathWstr(const WinApiLayerInterface &w_api, const DISPLAYCONFIG_PATH_INFO &path) { + std::wstring getMonitorDevicePathWstr(const WinApiLayerInterface &w_api, const DISPLAYCONFIG_PATH_INFO &path) { DISPLAYCONFIG_TARGET_DEVICE_NAME target_name = {}; target_name.header.adapterId = path.targetInfo.adapterId; target_name.header.id = path.targetInfo.id; target_name.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME; target_name.header.size = sizeof(target_name); - LONG result { DisplayConfigGetDeviceInfo(&target_name.header) }; + LONG result {DisplayConfigGetDeviceInfo(&target_name.header)}; if (result != ERROR_SUCCESS) { DD_LOG(error) << w_api.getErrorString(result) << " failed to get target device name!"; return {}; } - return std::wstring { target_name.monitorDevicePath }; + return std::wstring {target_name.monitorDevicePath}; } /** @@ -161,14 +153,12 @@ namespace display_device { * @returns True if device interface path was retrieved and is non-empty, false otherwise. * @see getDeviceId implementation for more context regarding this madness. */ - bool - getDeviceInterfaceDetail(const WinApiLayerInterface &w_api, HDEVINFO dev_info_handle, SP_DEVICE_INTERFACE_DATA &dev_interface_data, std::wstring &dev_interface_path, SP_DEVINFO_DATA &dev_info_data) { - DWORD required_size_in_bytes { 0 }; + bool getDeviceInterfaceDetail(const WinApiLayerInterface &w_api, HDEVINFO dev_info_handle, SP_DEVICE_INTERFACE_DATA &dev_interface_data, std::wstring &dev_interface_path, SP_DEVINFO_DATA &dev_info_data) { + DWORD required_size_in_bytes {0}; if (SetupDiGetDeviceInterfaceDetailW(dev_info_handle, &dev_interface_data, nullptr, 0, &required_size_in_bytes, nullptr)) { DD_LOG(error) << "\"SetupDiGetDeviceInterfaceDetailW\" did not fail, what?!"; return false; - } - else if (required_size_in_bytes <= 0) { + } else if (required_size_in_bytes <= 0) { DD_LOG(error) << w_api.getErrorString(static_cast(GetLastError())) << " \"SetupDiGetDeviceInterfaceDetailW\" failed while getting size."; return false; } @@ -177,7 +167,7 @@ namespace display_device { buffer.resize(required_size_in_bytes); // This part is just EVIL! - auto detail_data { reinterpret_cast(buffer.data()) }; + auto detail_data {reinterpret_cast(buffer.data())}; detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W); if (!SetupDiGetDeviceInterfaceDetailW(dev_info_handle, &dev_interface_data, detail_data, required_size_in_bytes, nullptr, &dev_info_data)) { @@ -185,7 +175,7 @@ namespace display_device { return false; } - dev_interface_path = std::wstring { detail_data->DevicePath }; + dev_interface_path = std::wstring {detail_data->DevicePath}; return !dev_interface_path.empty(); } @@ -194,14 +184,12 @@ namespace display_device { * @returns True if instance id was retrieved and is non-empty, false otherwise. * @see getDeviceId implementation for more context regarding this madness. */ - bool - getDeviceInstanceId(const WinApiLayerInterface &w_api, HDEVINFO dev_info_handle, SP_DEVINFO_DATA &dev_info_data, std::wstring &instance_id) { - DWORD required_size_in_characters { 0 }; + bool getDeviceInstanceId(const WinApiLayerInterface &w_api, HDEVINFO dev_info_handle, SP_DEVINFO_DATA &dev_info_data, std::wstring &instance_id) { + DWORD required_size_in_characters {0}; if (SetupDiGetDeviceInstanceIdW(dev_info_handle, &dev_info_data, nullptr, 0, &required_size_in_characters)) { DD_LOG(error) << "\"SetupDiGetDeviceInstanceIdW\" did not fail, what?!"; return false; - } - else if (required_size_in_characters <= 0) { + } else if (required_size_in_characters <= 0) { DD_LOG(error) << w_api.getErrorString(static_cast(GetLastError())) << " \"SetupDiGetDeviceInstanceIdW\" failed while getting size."; return false; } @@ -220,10 +208,9 @@ namespace display_device { * @returns True if EDID was retrieved and is non-empty, false otherwise. * @see getDeviceId implementation for more context regarding this madness. */ - bool - getDeviceEdid(const WinApiLayerInterface &w_api, HDEVINFO dev_info_handle, SP_DEVINFO_DATA &dev_info_data, std::vector &edid) { + bool getDeviceEdid(const WinApiLayerInterface &w_api, HDEVINFO dev_info_handle, SP_DEVINFO_DATA &dev_info_data, std::vector &edid) { // We could just directly open the registry key as the path is known, but we can also use the this - HKEY reg_key { SetupDiOpenDevRegKey(dev_info_handle, &dev_info_data, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ) }; + HKEY reg_key {SetupDiOpenDevRegKey(dev_info_handle, &dev_info_data, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ)}; if (reg_key == INVALID_HANDLE_VALUE) { DD_LOG(error) << w_api.getErrorString(static_cast(GetLastError())) << " \"SetupDiOpenDevRegKey\" failed."; return false; @@ -231,15 +218,15 @@ namespace display_device { const auto reg_key_cleanup { boost::scope::scope_exit([&w_api, ®_key]() { - const auto status { RegCloseKey(reg_key) }; + const auto status {RegCloseKey(reg_key)}; if (status != ERROR_SUCCESS) { DD_LOG(error) << w_api.getErrorString(status) << " \"RegCloseKey\" failed."; } }) }; - DWORD required_size_in_bytes { 0 }; - auto status { RegQueryValueExW(reg_key, L"EDID", nullptr, nullptr, nullptr, &required_size_in_bytes) }; + DWORD required_size_in_bytes {0}; + auto status {RegQueryValueExW(reg_key, L"EDID", nullptr, nullptr, nullptr, &required_size_in_bytes)}; if (status != ERROR_SUCCESS) { DD_LOG(error) << w_api.getErrorString(status) << " \"RegQueryValueExW\" failed when getting size."; return false; @@ -262,8 +249,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 &value) { // No conversion needed if the string is empty if (value.empty()) { return {}; @@ -288,8 +274,7 @@ namespace display_device { } } // namespace - std::string - WinApiLayer::getErrorString(LONG error_code) const { + std::string WinApiLayer::getErrorString(LONG error_code) const { std::ostringstream error; error << "[code: "; switch (error_code) { @@ -319,8 +304,7 @@ namespace display_device { return error.str(); } - std::optional - WinApiLayer::queryDisplayConfig(QueryType type) const { + std::optional WinApiLayer::queryDisplayConfig(QueryType type) const { std::vector paths; std::vector modes; LONG result = ERROR_SUCCESS; @@ -331,8 +315,8 @@ namespace display_device { flags |= QDC_VIRTUAL_MODE_AWARE; // supported from W10 onwards do { - UINT32 path_count { 0 }; - UINT32 mode_count { 0 }; + UINT32 path_count {0}; + UINT32 mode_count {0}; result = GetDisplayConfigBufferSizes(flags, &path_count, &mode_count); if (result != ERROR_SUCCESS) { @@ -359,21 +343,20 @@ namespace display_device { DD_LOG(verbose) << "Result of " << (type == QueryType::Active ? "ACTIVE" : "ALL") << " display config query:\n" << dumpPathsAndModes(paths, modes) << "\n"; - return PathAndModeData { paths, modes }; + return PathAndModeData {paths, modes}; } - std::string - WinApiLayer::getDeviceId(const DISPLAYCONFIG_PATH_INFO &path) const { - const auto device_path { getMonitorDevicePathWstr(*this, path) }; + std::string WinApiLayer::getDeviceId(const DISPLAYCONFIG_PATH_INFO &path) const { + const auto device_path {getMonitorDevicePathWstr(*this, path)}; if (device_path.empty()) { // Error already logged return {}; } - static const GUID monitor_guid { 0xe6f07b5f, 0xee97, 0x4a90, { 0xb0, 0x76, 0x33, 0xf5, 0x7b, 0xf4, 0xea, 0xa7 } }; + static const GUID monitor_guid {0xe6f07b5f, 0xee97, 0x4a90, {0xb0, 0x76, 0x33, 0xf5, 0x7b, 0xf4, 0xea, 0xa7}}; std::vector device_id_data; - HDEVINFO dev_info_handle { SetupDiGetClassDevsW(&monitor_guid, nullptr, nullptr, DIGCF_DEVICEINTERFACE) }; + HDEVINFO dev_info_handle {SetupDiGetClassDevsW(&monitor_guid, nullptr, nullptr, DIGCF_DEVICEINTERFACE)}; if (dev_info_handle) { const auto dev_info_handle_cleanup { boost::scope::scope_exit([this, &dev_info_handle]() { @@ -387,7 +370,7 @@ namespace display_device { dev_interface_data.cbSize = sizeof(dev_interface_data); for (DWORD monitor_index = 0;; ++monitor_index) { if (!SetupDiEnumDeviceInterfaces(dev_info_handle, nullptr, &monitor_guid, monitor_index, &dev_interface_data)) { - const DWORD error_code { GetLastError() }; + const DWORD error_code {GetLastError()}; if (error_code == ERROR_NO_MORE_ITEMS) { break; } @@ -450,14 +433,10 @@ namespace display_device { break; } - device_id_data.insert(std::end(device_id_data), - reinterpret_cast(instance_id.data()), - reinterpret_cast(instance_id.data() + unstable_part_index)); - device_id_data.insert(std::end(device_id_data), - reinterpret_cast(instance_id.data() + semi_stable_part_index), - reinterpret_cast(instance_id.data() + instance_id.size())); + device_id_data.insert(std::end(device_id_data), reinterpret_cast(instance_id.data()), reinterpret_cast(instance_id.data() + unstable_part_index)); + device_id_data.insert(std::end(device_id_data), reinterpret_cast(instance_id.data() + semi_stable_part_index), reinterpret_cast(instance_id.data() + instance_id.size())); - static const auto dump_device_id_data { [](const auto &data) -> std::string { + static const auto dump_device_id_data {[](const auto &data) -> std::string { if (data.empty()) { return {}; } @@ -473,7 +452,7 @@ namespace display_device { output << "]"; return output.str(); - } }; + }}; DD_LOG(verbose) << "Creating device id from EDID + instance ID: " << dump_device_id_data(device_id_data); break; } @@ -482,33 +461,29 @@ namespace display_device { if (device_id_data.empty()) { // Using the device path as a fallback, which is always unique, but not as stable as the preferred one DD_LOG(verbose) << "Creating device id from path " << toUtf8(*this, device_path); - device_id_data.insert(std::end(device_id_data), - reinterpret_cast(device_path.data()), - reinterpret_cast(device_path.data() + device_path.size())); + device_id_data.insert(std::end(device_id_data), reinterpret_cast(device_path.data()), reinterpret_cast(device_path.data() + device_path.size())); } static constexpr boost::uuids::uuid ns_id {}; // null namespace = no salt - const auto boost_uuid { boost::uuids::name_generator_sha1 { ns_id }(device_id_data.data(), device_id_data.size()) }; - const std::string device_id { "{" + boost::uuids::to_string(boost_uuid) + "}" }; + const auto boost_uuid {boost::uuids::name_generator_sha1 {ns_id}(device_id_data.data(), device_id_data.size())}; + const std::string device_id {"{" + boost::uuids::to_string(boost_uuid) + "}"}; DD_LOG(verbose) << "Created device id: " << toUtf8(*this, device_path) << " -> " << device_id; return device_id; } - std::string - WinApiLayer::getMonitorDevicePath(const DISPLAYCONFIG_PATH_INFO &path) const { + std::string WinApiLayer::getMonitorDevicePath(const DISPLAYCONFIG_PATH_INFO &path) const { return toUtf8(*this, getMonitorDevicePathWstr(*this, path)); } - std::string - WinApiLayer::getFriendlyName(const DISPLAYCONFIG_PATH_INFO &path) const { + std::string WinApiLayer::getFriendlyName(const DISPLAYCONFIG_PATH_INFO &path) const { DISPLAYCONFIG_TARGET_DEVICE_NAME target_name = {}; target_name.header.adapterId = path.targetInfo.adapterId; target_name.header.id = path.targetInfo.id; target_name.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME; target_name.header.size = sizeof(target_name); - LONG result { DisplayConfigGetDeviceInfo(&target_name.header) }; + LONG result {DisplayConfigGetDeviceInfo(&target_name.header)}; if (result != ERROR_SUCCESS) { DD_LOG(error) << getErrorString(result) << " failed to get target device name!"; return {}; @@ -517,15 +492,14 @@ namespace display_device { return target_name.flags.friendlyNameFromEdid ? toUtf8(*this, target_name.monitorFriendlyDeviceName) : std::string {}; } - std::string - WinApiLayer::getDisplayName(const DISPLAYCONFIG_PATH_INFO &path) const { + std::string WinApiLayer::getDisplayName(const DISPLAYCONFIG_PATH_INFO &path) const { DISPLAYCONFIG_SOURCE_DEVICE_NAME source_name = {}; source_name.header.id = path.sourceInfo.id; source_name.header.adapterId = path.sourceInfo.adapterId; source_name.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME; source_name.header.size = sizeof(source_name); - LONG result { DisplayConfigGetDeviceInfo(&source_name.header) }; + LONG result {DisplayConfigGetDeviceInfo(&source_name.header)}; if (result != ERROR_SUCCESS) { DD_LOG(error) << getErrorString(result) << " failed to get display name!"; return {}; @@ -534,26 +508,25 @@ namespace display_device { return toUtf8(*this, source_name.viewGdiDeviceName); } - LONG - WinApiLayer::setDisplayConfig(std::vector paths, std::vector modes, UINT32 flags) { + LONG WinApiLayer::setDisplayConfig(std::vector paths, std::vector modes, UINT32 flags) { // std::vector::data() "may or may not return a null pointer, if size() is 0", therefore we want to enforce nullptr... return ::SetDisplayConfig( paths.size(), paths.empty() ? nullptr : paths.data(), modes.size(), modes.empty() ? nullptr : modes.data(), - flags); + flags + ); } - std::optional - WinApiLayer::getHdrState(const DISPLAYCONFIG_PATH_INFO &path) const { + std::optional WinApiLayer::getHdrState(const DISPLAYCONFIG_PATH_INFO &path) const { DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO color_info = {}; color_info.header.adapterId = path.targetInfo.adapterId; color_info.header.id = path.targetInfo.id; color_info.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO; color_info.header.size = sizeof(color_info); - LONG result { DisplayConfigGetDeviceInfo(&color_info.header) }; + LONG result {DisplayConfigGetDeviceInfo(&color_info.header)}; if (result != ERROR_SUCCESS) { DD_LOG(error) << getErrorString(result) << " failed to get advanced color info!"; return std::nullopt; @@ -562,8 +535,7 @@ namespace display_device { return color_info.advancedColorSupported ? std::make_optional(color_info.advancedColorEnabled ? HdrState::Enabled : HdrState::Disabled) : std::nullopt; } - bool - WinApiLayer::setHdrState(const DISPLAYCONFIG_PATH_INFO &path, HdrState state) { + bool WinApiLayer::setHdrState(const DISPLAYCONFIG_PATH_INFO &path, HdrState state) { DISPLAYCONFIG_SET_ADVANCED_COLOR_STATE color_state = {}; color_state.header.adapterId = path.targetInfo.adapterId; color_state.header.id = path.targetInfo.id; @@ -571,7 +543,7 @@ namespace display_device { color_state.header.size = sizeof(color_state); color_state.enableAdvancedColor = state == HdrState::Enabled ? 1 : 0; - LONG result { DisplayConfigSetDeviceInfo(&color_state.header) }; + LONG result {DisplayConfigSetDeviceInfo(&color_state.header)}; if (result != ERROR_SUCCESS) { DD_LOG(error) << getErrorString(result) << " failed to set advanced color info!"; return false; @@ -580,36 +552,37 @@ 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 &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::optional m_width; }; - EnumData enum_data { display_name, std::nullopt }; + EnumData enum_data {display_name, std::nullopt}; EnumDisplayMonitors( - nullptr, nullptr, [](HMONITOR monitor, HDC, LPRECT, LPARAM user_data) -> BOOL { - auto *data = reinterpret_cast(user_data); - if (data == nullptr) - { - // Sanity check - DD_LOG(error) << "EnumData is a nullptr!"; - return FALSE; - } - - MONITORINFOEXA monitor_info{ sizeof(MONITORINFOEXA ) }; - if (GetMonitorInfoA(monitor, &monitor_info)) - { - if (data->m_display_name == monitor_info.szDevice) - { - data->m_width = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left; + nullptr, + nullptr, + [](HMONITOR monitor, HDC, LPRECT, LPARAM user_data) -> BOOL { + auto *data = reinterpret_cast(user_data); + if (data == nullptr) { + // Sanity check + DD_LOG(error) << "EnumData is a nullptr!"; return FALSE; } - } - return TRUE; }, reinterpret_cast(&enum_data)); + MONITORINFOEXA monitor_info {sizeof(MONITORINFOEXA)}; + if (GetMonitorInfoA(monitor, &monitor_info)) { + if (data->m_display_name == monitor_info.szDevice) { + data->m_width = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left; + return FALSE; + } + } + + return TRUE; + }, + reinterpret_cast(&enum_data) + ); if (!enum_data.m_width) { DD_LOG(debug) << "Failed to get monitor info for " << display_name << "!"; @@ -621,7 +594,7 @@ namespace display_device { return std::nullopt; } - const auto width { static_cast(*enum_data.m_width) / static_cast(source_mode.width) }; - return Rational { static_cast(std::round((static_cast(GetDpiForSystem()) / 96. / width) * 100)), 100 }; + const auto width {static_cast(*enum_data.m_width) / static_cast(source_mode.width)}; + return Rational {static_cast(std::round((static_cast(GetDpiForSystem()) / 96. / width) * 100)), 100}; } } // namespace display_device diff --git a/src/windows/win_api_utils.cpp b/src/windows/win_api_utils.cpp index 8d0ef71..e7fabe9 100644 --- a/src/windows/win_api_utils.cpp +++ b/src/windows/win_api_utils.cpp @@ -21,8 +21,7 @@ namespace { * const bool not_equal = (LUID{ 12, 34 }) != (LUID{ 12, 56 }); * @examples_end */ - bool - operator!=(const LUID &lhs, const LUID &rhs) { + bool operator!=(const LUID &lhs, const LUID &rhs) { return lhs.HighPart != rhs.HighPart || lhs.LowPart != rhs.LowPart; } @@ -34,8 +33,7 @@ namespace { * const bool id_string = to_string({ 12, 34 }); * @examples_end */ - std::string - toString(const LUID &id) { + std::string toString(const LUID &id) { return std::to_string(id.HighPart) + std::to_string(id.LowPart); } @@ -52,35 +50,29 @@ namespace { * const bool are_duplicated = are_modes_duplicated(mode_a, mode_b); * @examples_end */ - bool - are_modes_duplicated(const DISPLAYCONFIG_SOURCE_MODE &lhs, const DISPLAYCONFIG_SOURCE_MODE &rhs) { + bool are_modes_duplicated(const DISPLAYCONFIG_SOURCE_MODE &lhs, const DISPLAYCONFIG_SOURCE_MODE &rhs) { return lhs.position.x == rhs.position.x && lhs.position.y == rhs.position.y; } } // namespace namespace display_device::win_utils { - bool - isAvailable(const DISPLAYCONFIG_PATH_INFO &path) { + bool isAvailable(const DISPLAYCONFIG_PATH_INFO &path) { return path.targetInfo.targetAvailable == TRUE; } - bool - isActive(const DISPLAYCONFIG_PATH_INFO &path) { + bool isActive(const DISPLAYCONFIG_PATH_INFO &path) { return static_cast(path.flags & DISPLAYCONFIG_PATH_ACTIVE); } - void - setActive(DISPLAYCONFIG_PATH_INFO &path) { + void setActive(DISPLAYCONFIG_PATH_INFO &path) { path.flags |= DISPLAYCONFIG_PATH_ACTIVE; } - bool - isPrimary(const DISPLAYCONFIG_SOURCE_MODE &mode) { + bool isPrimary(const DISPLAYCONFIG_SOURCE_MODE &mode) { return mode.position.x == 0 && mode.position.y == 0; } - std::optional - getSourceIndex(const DISPLAYCONFIG_PATH_INFO &path, const std::vector &modes) { + std::optional getSourceIndex(const DISPLAYCONFIG_PATH_INFO &path, const std::vector &modes) { // The MS docs is not clear when to access the index union struct or not. It appears that union struct is available, // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying (always in our case). // @@ -88,7 +80,7 @@ namespace display_device::win_utils { // that is just BS (maybe copy-pasta mistake), because some cases were found where the flag is not set and the union // is still being used. - const UINT32 index { path.sourceInfo.sourceModeInfoIdx }; + const UINT32 index {path.sourceInfo.sourceModeInfoIdx}; if (index == DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID) { return std::nullopt; } @@ -101,8 +93,7 @@ namespace display_device::win_utils { return index; } - void - setSourceIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index) { + void setSourceIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index) { // The MS docs is not clear when to access the index union struct or not. It appears that union struct is available, // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying (always in our case). // @@ -112,13 +103,12 @@ namespace display_device::win_utils { if (index) { path.sourceInfo.sourceModeInfoIdx = *index; - } - else { + } else { path.sourceInfo.sourceModeInfoIdx = DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID; } } - void - setTargetIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index) { + + void setTargetIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index) { // The MS docs is not clear when to access the index union struct or not. It appears that union struct is available, // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying (always in our case). // @@ -128,13 +118,12 @@ namespace display_device::win_utils { if (index) { path.targetInfo.targetModeInfoIdx = *index; - } - else { + } else { path.targetInfo.targetModeInfoIdx = DISPLAYCONFIG_PATH_TARGET_MODE_IDX_INVALID; } } - void - setDesktopIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index) { + + void setDesktopIndex(DISPLAYCONFIG_PATH_INFO &path, const std::optional &index) { // The MS docs is not clear when to access the index union struct or not. It appears that union struct is available, // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying (always in our case). // @@ -144,13 +133,12 @@ namespace display_device::win_utils { if (index) { path.targetInfo.desktopModeInfoIdx = *index; - } - else { + } else { path.targetInfo.desktopModeInfoIdx = DISPLAYCONFIG_PATH_DESKTOP_IMAGE_IDX_INVALID; } } - void - setCloneGroupId(DISPLAYCONFIG_PATH_INFO &path, const std::optional &id) { + + void setCloneGroupId(DISPLAYCONFIG_PATH_INFO &path, const std::optional &id) { // The MS docs is not clear when to access the index union struct or not. It appears that union struct is available, // whenever QDC_VIRTUAL_MODE_AWARE is specified when querying (always in our case). // @@ -160,14 +148,12 @@ namespace display_device::win_utils { if (id) { path.sourceInfo.cloneGroupId = *id; - } - else { + } else { path.sourceInfo.cloneGroupId = DISPLAYCONFIG_PATH_CLONE_GROUP_INVALID; } } - const DISPLAYCONFIG_SOURCE_MODE * - getSourceMode(const std::optional &index, const std::vector &modes) { + const DISPLAYCONFIG_SOURCE_MODE *getSourceMode(const std::optional &index, const std::vector &modes) { if (!index) { return nullptr; } @@ -177,7 +163,7 @@ namespace display_device::win_utils { return nullptr; } - const auto &mode { modes[*index] }; + const auto &mode {modes[*index]}; if (mode.infoType != DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE) { DD_LOG(error) << "Mode at index " << *index << " is not source mode!"; return nullptr; @@ -186,13 +172,11 @@ namespace display_device::win_utils { return &mode.sourceMode; } - DISPLAYCONFIG_SOURCE_MODE * - getSourceMode(const std::optional &index, std::vector &modes) { + DISPLAYCONFIG_SOURCE_MODE *getSourceMode(const std::optional &index, std::vector &modes) { return const_cast(getSourceMode(index, const_cast &>(modes))); } - std::optional - getDeviceInfoForValidPath(const WinApiLayerInterface &w_api, const DISPLAYCONFIG_PATH_INFO &path, const ValidatedPathType type) { + std::optional getDeviceInfoForValidPath(const WinApiLayerInterface &w_api, const DISPLAYCONFIG_PATH_INFO &path, const ValidatedPathType type) { if (!isAvailable(path)) { // Could be transient issue according to MSDOCS (no longer available, but still "active") return std::nullopt; @@ -204,28 +188,27 @@ namespace display_device::win_utils { } } - const auto device_path { w_api.getMonitorDevicePath(path) }; + const auto device_path {w_api.getMonitorDevicePath(path)}; if (device_path.empty()) { return std::nullopt; } - const auto device_id { w_api.getDeviceId(path) }; + const auto device_id {w_api.getDeviceId(path)}; if (device_id.empty()) { return std::nullopt; } - const auto display_name { w_api.getDisplayName(path) }; + const auto display_name {w_api.getDisplayName(path)}; if (display_name.empty()) { return std::nullopt; } - return ValidatedDeviceInfo { device_path, device_id }; + 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 &device_id, const std::vector &paths) { for (const auto &path : paths) { - const auto device_info { getDeviceInfoForValidPath(w_api, path, ValidatedPathType::Active) }; + const auto device_info {getDeviceInfoForValidPath(w_api, path, ValidatedPathType::Active)}; if (!device_info) { continue; } @@ -238,33 +221,30 @@ namespace display_device::win_utils { return nullptr; } - DISPLAYCONFIG_PATH_INFO * - getActivePath(const WinApiLayerInterface &w_api, const std::string &device_id, std::vector &paths) { + 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 collectSourceDataForMatchingPaths(const WinApiLayerInterface &w_api, const std::vector &paths) { PathSourceIndexDataMap path_data; std::unordered_map paths_to_ids; for (std::size_t index = 0; index < paths.size(); ++index) { - const auto &path { paths[index] }; + const auto &path {paths[index]}; - const auto device_info { getDeviceInfoForValidPath(w_api, path, ValidatedPathType::Any) }; + const auto device_info {getDeviceInfoForValidPath(w_api, path, ValidatedPathType::Any)}; if (!device_info) { // Path is not valid continue; } - const auto prev_device_id_for_path_it { paths_to_ids.find(device_info->m_device_path) }; + const auto prev_device_id_for_path_it {paths_to_ids.find(device_info->m_device_path)}; if (prev_device_id_for_path_it != std::end(paths_to_ids)) { if (prev_device_id_for_path_it->second != device_info->m_device_id) { DD_LOG(error) << "Duplicate display device id found: " << device_info->m_device_id << " (device path: " << device_info->m_device_path << ")"; return {}; } - } - else { + } else { for (const auto &[device_path, device_id] : paths_to_ids) { if (device_id == device_info->m_device_id) { DD_LOG(error) << "Device id " << device_info->m_device_id << " is shared between 2 different paths: " << device_path << " and " << device_info->m_device_path; @@ -275,29 +255,26 @@ namespace display_device::win_utils { paths_to_ids[device_info->m_device_path] = device_info->m_device_id; } - auto path_data_it { path_data.find(device_info->m_device_id) }; + auto path_data_it {path_data.find(device_info->m_device_id)}; if (path_data_it != std::end(path_data)) { if (path_data_it->second.m_adapter_id != path.sourceInfo.adapterId) { // Sanity check, should not be possible since adapter in embedded in the device path DD_LOG(error) << "Device path " << device_info->m_device_path << " has different adapters!"; return {}; - } - else if (isActive(path)) { + } else if (isActive(path)) { // Sanity check, should not be possible as all active paths are in the front DD_LOG(error) << "Device path " << device_info->m_device_path << " is active, but not the first entry in the list!"; return {}; - } - else if (path_data_it->second.m_source_id_to_path_index.contains(path.sourceInfo.id)) { + } else if (path_data_it->second.m_source_id_to_path_index.contains(path.sourceInfo.id)) { // Sanity check, should not be possible unless Windows goes bonkers DD_LOG(error) << "Device path " << device_info->m_device_path << " has duplicate source ids!"; return {}; } path_data_it->second.m_source_id_to_path_index[path.sourceInfo.id] = index; - } - else { + } else { path_data[device_info->m_device_id] = { - { { path.sourceInfo.id, index } }, + {{path.sourceInfo.id, index}}, path.sourceInfo.adapterId, // Since active paths are always in the front, this is the only time we set it isActive(path) ? std::make_optional(path.sourceInfo.id) : std::nullopt @@ -313,14 +290,13 @@ namespace display_device::win_utils { return path_data; } - std::vector - makePathsForNewTopology(const ActiveTopology &new_topology, const PathSourceIndexDataMap &path_source_data, const std::vector &paths) { + std::vector makePathsForNewTopology(const ActiveTopology &new_topology, const PathSourceIndexDataMap &path_source_data, const std::vector &paths) { std::vector new_paths; - UINT32 group_id { 0 }; + UINT32 group_id {0}; std::unordered_map> used_source_ids_per_adapter; const auto is_source_id_already_used = [&used_source_ids_per_adapter](const LUID &adapter_id, UINT32 source_id) { - auto entry_it { used_source_ids_per_adapter.find(toString(adapter_id)) }; + auto entry_it {used_source_ids_per_adapter.find(toString(adapter_id))}; if (entry_it != std::end(used_source_ids_per_adapter)) { return entry_it->second.contains(source_id); } @@ -331,7 +307,7 @@ namespace display_device::win_utils { for (const auto &group : new_topology) { std::unordered_map used_source_ids_per_adapter_per_group; const auto get_already_used_source_id_in_group = [&used_source_ids_per_adapter_per_group](const LUID &adapter_id) -> std::optional { - auto entry_it { used_source_ids_per_adapter_per_group.find(toString(adapter_id)) }; + auto entry_it {used_source_ids_per_adapter_per_group.find(toString(adapter_id))}; if (entry_it != std::end(used_source_ids_per_adapter_per_group)) { return entry_it->second; } @@ -340,28 +316,27 @@ namespace display_device::win_utils { }; for (const std::string &device_id : group) { - auto path_source_data_it { path_source_data.find(device_id) }; + auto path_source_data_it {path_source_data.find(device_id)}; if (path_source_data_it == std::end(path_source_data)) { DD_LOG(error) << "Device " << device_id << " does not exist in the available path source data!"; return {}; } std::size_t selected_path_index {}; - const auto &source_data { path_source_data_it->second }; + const auto &source_data {path_source_data_it->second}; - const auto already_used_source_id { get_already_used_source_id_in_group(source_data.m_adapter_id) }; + const auto already_used_source_id {get_already_used_source_id_in_group(source_data.m_adapter_id)}; if (already_used_source_id) { // Some device in the group is already using the source id, and we belong to the same adapter. // This means we must also use the path with matching source id. - auto path_index_it { source_data.m_source_id_to_path_index.find(*already_used_source_id) }; + auto path_index_it {source_data.m_source_id_to_path_index.find(*already_used_source_id)}; if (path_index_it == std::end(source_data.m_source_id_to_path_index)) { DD_LOG(error) << "Device " << device_id << " does not have a path with a source id " << *already_used_source_id << "!"; return {}; } selected_path_index = path_index_it->second; - } - else { + } else { // Here we want to select a path index that has the lowest index (the "best" of paths), but only // if the source id is still free. Technically we should not need to find the lowest index, but that's // what will match the Windows' behaviour the closest if we need to create new topology in the end. @@ -400,7 +375,7 @@ namespace display_device::win_utils { return {}; } - auto selected_path { paths[selected_path_index] }; + auto selected_path {paths[selected_path_index]}; // All the indexes must be cleared and only the group id specified win_utils::setSourceIndex(selected_path, std::nullopt); @@ -421,9 +396,8 @@ namespace display_device::win_utils { return new_paths; } - std::set - getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const std::set &device_ids) { - const auto display_data { w_api.queryDisplayConfig(QueryType::Active) }; + std::set getAllDeviceIdsAndMatchingDuplicates(const WinApiLayerInterface &w_api, const std::set &device_ids) { + const auto display_data {w_api.queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return {}; @@ -436,13 +410,13 @@ namespace display_device::win_utils { return {}; } - const auto provided_path { getActivePath(w_api, device_id, display_data->m_paths) }; + const auto provided_path {getActivePath(w_api, device_id, display_data->m_paths)}; if (!provided_path) { DD_LOG(warning) << "Failed to find device for " << device_id << "!"; return {}; } - const auto provided_path_source_mode { getSourceMode(getSourceIndex(*provided_path, display_data->m_modes), display_data->m_modes) }; + const auto provided_path_source_mode {getSourceMode(getSourceIndex(*provided_path, display_data->m_modes), display_data->m_modes)}; if (!provided_path_source_mode) { DD_LOG(error) << "Active device does not have a source mode: " << device_id << "!"; return {}; @@ -451,7 +425,7 @@ namespace display_device::win_utils { // We will now iterate over all the active paths (provided path included) and check if // any of them are duplicated. for (const auto &path : display_data->m_paths) { - const auto device_info { getDeviceInfoForValidPath(w_api, path, ValidatedPathType::Active) }; + const auto device_info {getDeviceInfoForValidPath(w_api, path, ValidatedPathType::Active)}; if (!device_info) { continue; } @@ -461,7 +435,7 @@ namespace display_device::win_utils { continue; } - const auto source_mode { getSourceMode(getSourceIndex(path, display_data->m_modes), display_data->m_modes) }; + const auto source_mode {getSourceMode(getSourceIndex(path, display_data->m_modes), display_data->m_modes)}; if (!source_mode) { DD_LOG(error) << "Active device does not have a source mode: " << device_info->m_device_id << "!"; return {}; @@ -478,19 +452,17 @@ namespace display_device::win_utils { return all_device_ids; } - bool - fuzzyCompareRefreshRates(const Rational &lhs, const Rational &rhs) { + bool fuzzyCompareRefreshRates(const Rational &lhs, const Rational &rhs) { if (lhs.m_denominator > 0 && rhs.m_denominator > 0) { - const double lhs_f { static_cast(lhs.m_numerator) / static_cast(lhs.m_denominator) }; - const double rhs_f { static_cast(rhs.m_numerator) / static_cast(rhs.m_denominator) }; + const double lhs_f {static_cast(lhs.m_numerator) / static_cast(lhs.m_denominator)}; + const double rhs_f {static_cast(rhs.m_numerator) / static_cast(rhs.m_denominator)}; return (std::abs(lhs_f - rhs_f) <= 0.9); } return false; } - bool - fuzzyCompareModes(const DisplayMode &lhs, const DisplayMode &rhs) { + bool fuzzyCompareModes(const DisplayMode &lhs, const DisplayMode &rhs) { return lhs.m_resolution.m_width == rhs.m_resolution.m_width && lhs.m_resolution.m_height == rhs.m_resolution.m_height && fuzzyCompareRefreshRates(lhs.m_refresh_rate, rhs.m_refresh_rate); diff --git a/src/windows/win_display_device_general.cpp b/src/windows/win_display_device_general.cpp index bce9224..4c5e86a 100644 --- a/src/windows/win_display_device_general.cpp +++ b/src/windows/win_display_device_general.cpp @@ -11,15 +11,14 @@ namespace display_device { WinDisplayDevice::WinDisplayDevice(std::shared_ptr w_api): - m_w_api { std::move(w_api) } { + m_w_api {std::move(w_api)} { if (!m_w_api) { - throw std::logic_error { "Nullptr provided for WinApiLayerInterface in WinDisplayDevice!" }; + throw std::logic_error {"Nullptr provided for WinApiLayerInterface in WinDisplayDevice!"}; } } - bool - WinDisplayDevice::isApiAccessAvailable() const { - const auto display_data { m_w_api->queryDisplayConfig(QueryType::All) }; + bool WinDisplayDevice::isApiAccessAvailable() const { + const auto display_data {m_w_api->queryDisplayConfig(QueryType::All)}; if (!display_data) { DD_LOG(debug) << "WinDisplayDevice::isApiAccessAvailable failed while querying display data."; return false; @@ -28,92 +27,89 @@ namespace display_device { // Here we are supplying the retrieved display data back to SetDisplayConfig (with VALIDATE flag only, so that we make no actual changes). // Unless something is really broken on Windows, this call should never fail under normal circumstances - the configuration is 100% correct, since it was // provided by Windows. - const UINT32 flags { SDC_VALIDATE | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_VIRTUAL_MODE_AWARE }; - const LONG result { m_w_api->setDisplayConfig(display_data->m_paths, display_data->m_modes, flags) }; + const UINT32 flags {SDC_VALIDATE | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_VIRTUAL_MODE_AWARE}; + const LONG result {m_w_api->setDisplayConfig(display_data->m_paths, display_data->m_modes, flags)}; DD_LOG(debug) << "WinDisplayDevice::isApiAccessAvailable result: " << m_w_api->getErrorString(result); return result == ERROR_SUCCESS; } - EnumeratedDeviceList - WinDisplayDevice::enumAvailableDevices() const { - const auto display_data { m_w_api->queryDisplayConfig(QueryType::All) }; + EnumeratedDeviceList WinDisplayDevice::enumAvailableDevices() const { + const auto display_data {m_w_api->queryDisplayConfig(QueryType::All)}; if (!display_data) { // Error already logged return {}; } EnumeratedDeviceList available_devices; - const auto source_data { win_utils::collectSourceDataForMatchingPaths(*m_w_api, display_data->m_paths) }; + const auto source_data {win_utils::collectSourceDataForMatchingPaths(*m_w_api, display_data->m_paths)}; if (source_data.empty()) { // Error already logged return {}; } for (const auto &[device_id, data] : source_data) { - const auto source_id_index { data.m_active_source.value_or(0) }; - const auto &best_path { display_data->m_paths.at(data.m_source_id_to_path_index.at(source_id_index)) }; - const auto friendly_name { m_w_api->getFriendlyName(best_path) }; - const bool is_active { win_utils::isActive(best_path) }; - const auto source_mode { is_active ? win_utils::getSourceMode(win_utils::getSourceIndex(best_path, display_data->m_modes), display_data->m_modes) : nullptr }; - const auto display_name { is_active ? m_w_api->getDisplayName(best_path) : std::string {} }; // Inactive devices can have multiple display names, so it's just meaningless use any + const auto source_id_index {data.m_active_source.value_or(0)}; + const auto &best_path {display_data->m_paths.at(data.m_source_id_to_path_index.at(source_id_index))}; + const auto friendly_name {m_w_api->getFriendlyName(best_path)}; + const bool is_active {win_utils::isActive(best_path)}; + const auto source_mode {is_active ? win_utils::getSourceMode(win_utils::getSourceIndex(best_path, display_data->m_modes), display_data->m_modes) : nullptr}; + const auto display_name {is_active ? m_w_api->getDisplayName(best_path) : std::string {}}; // Inactive devices can have multiple display names, so it's just meaningless use any if (is_active && !source_mode) { DD_LOG(warning) << "Device " << device_id << " is missing source mode!"; } if (source_mode) { - const Rational refresh_rate { best_path.targetInfo.refreshRate.Denominator > 0 ? - Rational { best_path.targetInfo.refreshRate.Numerator, best_path.targetInfo.refreshRate.Denominator } : - Rational { 0, 1 } }; + const Rational refresh_rate {best_path.targetInfo.refreshRate.Denominator > 0 ? Rational {best_path.targetInfo.refreshRate.Numerator, best_path.targetInfo.refreshRate.Denominator} : Rational {0, 1}}; const EnumeratedDevice::Info info { - { source_mode->width, source_mode->height }, - m_w_api->getDisplayScale(display_name, *source_mode).value_or(Rational { 0, 1 }), + {source_mode->width, source_mode->height}, + m_w_api->getDisplayScale(display_name, *source_mode).value_or(Rational {0, 1}), refresh_rate, win_utils::isPrimary(*source_mode), - { static_cast(source_mode->position.x), static_cast(source_mode->position.y) }, + {static_cast(source_mode->position.x), static_cast(source_mode->position.y)}, m_w_api->getHdrState(best_path) }; available_devices.push_back( - { device_id, - display_name, - friendly_name, - info }); - } - else { + {device_id, + display_name, + friendly_name, + info} + ); + } else { available_devices.push_back( - { device_id, - display_name, - friendly_name, - std::nullopt }); + {device_id, + display_name, + friendly_name, + std::nullopt} + ); } } return available_devices; } - std::string - WinDisplayDevice::getDisplayName(const std::string &device_id) const { + std::string WinDisplayDevice::getDisplayName(const std::string &device_id) const { if (device_id.empty()) { // Valid return, no error return {}; } - const auto display_data { m_w_api->queryDisplayConfig(QueryType::Active) }; + const auto display_data {m_w_api->queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return {}; } - const auto path { win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths) }; + const auto path {win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths)}; if (!path) { // Debug level, because inactive device is valid case for this function DD_LOG(debug) << "Failed to find device for " << device_id << "!"; return {}; } - const auto display_name { m_w_api->getDisplayName(*path) }; + const auto display_name {m_w_api->getDisplayName(*path)}; if (display_name.empty()) { // Theoretically possible due to some race condition in the OS... DD_LOG(error) << "Device " << device_id << " has no display name assigned."; diff --git a/src/windows/win_display_device_hdr.cpp b/src/windows/win_display_device_hdr.cpp index 81eddaf..8be4dce 100644 --- a/src/windows/win_display_device_hdr.cpp +++ b/src/windows/win_display_device_hdr.cpp @@ -20,17 +20,16 @@ namespace display_device { /** * @see setHdrStates for a description as this was split off to reduce cognitive complexity. */ - bool - doSetHdrStates(WinApiLayerInterface &w_api, const PathAndModeData &display_data, const HdrStateMapNoOpt &states, HdrStateMapNoOpt *changed_states) { + bool doSetHdrStates(WinApiLayerInterface &w_api, const PathAndModeData &display_data, const HdrStateMapNoOpt &states, HdrStateMapNoOpt *changed_states) { const auto try_set_state { [&w_api, &display_data](const auto &device_id, const auto &state, auto ¤t_state) { - const auto path { win_utils::getActivePath(w_api, device_id, display_data.m_paths) }; + const auto path {win_utils::getActivePath(w_api, device_id, display_data.m_paths)}; if (!path) { DD_LOG(error) << "Failed to find device for " << device_id << "!"; return false; } - const auto current_state_int { w_api.getHdrState(*path) }; + const auto current_state_int {w_api.getHdrState(*path)}; if (!current_state_int) { DD_LOG(error) << "HDR state cannot be changed for " << device_id << "!"; return false; @@ -67,14 +66,13 @@ namespace display_device { } // namespace - HdrStateMap - WinDisplayDevice::getCurrentHdrStates(const std::set &device_ids) const { + HdrStateMap WinDisplayDevice::getCurrentHdrStates(const std::set &device_ids) const { if (device_ids.empty()) { DD_LOG(error) << "Device id set is empty!"; return {}; } - const auto display_data { m_w_api->queryDisplayConfig(QueryType::Active) }; + const auto display_data {m_w_api->queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return {}; @@ -82,7 +80,7 @@ namespace display_device { HdrStateMap states; for (const auto &device_id : device_ids) { - const auto path { win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths) }; + const auto path {win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths)}; if (!path) { DD_LOG(error) << "Failed to find device for " << device_id << "!"; return {}; @@ -94,25 +92,27 @@ namespace display_device { return states; } - bool - WinDisplayDevice::setHdrStates(const HdrStateMap &states) { + bool WinDisplayDevice::setHdrStates(const HdrStateMap &states) { if (states.empty()) { DD_LOG(error) << "States map is empty!"; return false; } HdrStateMapNoOpt states_without_opt; - std::ranges::copy(states | - std::ranges::views::filter([](const auto &entry) { return static_cast(entry.second); }) | - std::views::transform([](const auto &entry) { return std::make_pair(entry.first, *entry.second); }), - std::inserter(states_without_opt, std::begin(states_without_opt))); + std::ranges::copy(states | std::ranges::views::filter([](const auto &entry) { + return static_cast(entry.second); + }) | + std::views::transform([](const auto &entry) { + return std::make_pair(entry.first, *entry.second); + }), + std::inserter(states_without_opt, std::begin(states_without_opt))); if (states_without_opt.empty()) { // Return early as there is nothing to do... return true; } - const auto display_data { m_w_api->queryDisplayConfig(QueryType::Active) }; + const auto display_data {m_w_api->queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return {}; diff --git a/src/windows/win_display_device_modes.cpp b/src/windows/win_display_device_modes.cpp index 018bfcc..c89b8f2 100644 --- a/src/windows/win_display_device_modes.cpp +++ b/src/windows/win_display_device_modes.cpp @@ -26,36 +26,34 @@ namespace display_device { /** * @see set_display_modes for a description as this was split off to reduce cognitive complexity. */ - bool - doSetModes(WinApiLayerInterface &w_api, const DeviceDisplayModeMap &modes, const Strategy strategy) { - auto display_data { w_api.queryDisplayConfig(QueryType::Active) }; + bool doSetModes(WinApiLayerInterface &w_api, const DeviceDisplayModeMap &modes, const Strategy strategy) { + auto display_data {w_api.queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return false; } - bool changes_applied { false }; + bool changes_applied {false}; for (const auto &[device_id, mode] : modes) { - const auto path { win_utils::getActivePath(w_api, device_id, display_data->m_paths) }; + const auto path {win_utils::getActivePath(w_api, device_id, display_data->m_paths)}; if (!path) { DD_LOG(error) << "Failed to find device for " << device_id << "!"; return false; } - const auto source_mode { win_utils::getSourceMode(win_utils::getSourceIndex(*path, display_data->m_modes), display_data->m_modes) }; + const auto source_mode {win_utils::getSourceMode(win_utils::getSourceIndex(*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; } - bool new_changes { false }; - const bool resolution_changed { source_mode->width != mode.m_resolution.m_width || source_mode->height != mode.m_resolution.m_height }; + bool new_changes {false}; + const bool resolution_changed {source_mode->width != mode.m_resolution.m_width || source_mode->height != mode.m_resolution.m_height}; 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); - } - else { + refresh_rate_changed = !win_utils::fuzzyCompareRefreshRates(Rational {path->targetInfo.refreshRate.Numerator, 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; @@ -68,7 +66,7 @@ namespace display_device { } if (refresh_rate_changed) { - path->targetInfo.refreshRate = { mode.m_refresh_rate.m_numerator, mode.m_refresh_rate.m_denominator }; + path->targetInfo.refreshRate = {mode.m_refresh_rate.m_numerator, mode.m_refresh_rate.m_denominator}; new_changes = true; } @@ -86,7 +84,7 @@ namespace display_device { return true; } - UINT32 flags { SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE }; + UINT32 flags {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE}; if (strategy == Strategy::Relaxed) { // It's probably best for Windows to select the "best" display settings for us. However, in case we // have custom resolution set in nvidia control panel for example, this flag will prevent successfully applying @@ -94,7 +92,7 @@ namespace display_device { flags |= SDC_ALLOW_CHANGES; } - const LONG result { w_api.setDisplayConfig(display_data->m_paths, display_data->m_modes, flags) }; + const LONG result {w_api.setDisplayConfig(display_data->m_paths, display_data->m_modes, flags)}; if (result != ERROR_SUCCESS) { DD_LOG(error) << w_api.getErrorString(result) << " failed to set display mode!"; return false; @@ -104,14 +102,13 @@ namespace display_device { } } // namespace - DeviceDisplayModeMap - WinDisplayDevice::getCurrentDisplayModes(const std::set &device_ids) const { + DeviceDisplayModeMap WinDisplayDevice::getCurrentDisplayModes(const std::set &device_ids) const { if (device_ids.empty()) { DD_LOG(error) << "Device id set is empty!"; return {}; } - const auto display_data { m_w_api->queryDisplayConfig(QueryType::Active) }; + const auto display_data {m_w_api->queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return {}; @@ -124,31 +121,30 @@ namespace display_device { return {}; } - const auto path { win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths) }; + const auto path {win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths)}; if (!path) { DD_LOG(error) << "Failed to find device for " << device_id << "!"; return {}; } - const auto source_mode { win_utils::getSourceMode(win_utils::getSourceIndex(*path, display_data->m_modes), display_data->m_modes) }; + const auto source_mode {win_utils::getSourceMode(win_utils::getSourceIndex(*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 {}; } // For whatever reason they put refresh rate into path, but not the resolution. - const auto target_refresh_rate { path->targetInfo.refreshRate }; + const auto target_refresh_rate {path->targetInfo.refreshRate}; current_modes[device_id] = DisplayMode { - { source_mode->width, source_mode->height }, - { target_refresh_rate.Numerator, target_refresh_rate.Denominator } + {source_mode->width, source_mode->height}, + {target_refresh_rate.Numerator, target_refresh_rate.Denominator} }; } return current_modes; } - bool - WinDisplayDevice::setDisplayModes(const DeviceDisplayModeMap &modes) { + bool WinDisplayDevice::setDisplayModes(const DeviceDisplayModeMap &modes) { if (modes.empty()) { DD_LOG(error) << "Modes map is empty!"; return false; @@ -167,9 +163,9 @@ namespace display_device { // To avoid surprising end-user with unexpected source mode change, we validate that all duplicate // devices were provided instead of guessing modes automatically. This also resolve the problem of // having to choose refresh rate for duplicate display - leave it to the end-user of this function... - const auto keys_view { std::ranges::views::keys(modes) }; - const std::set device_ids { std::begin(keys_view), std::end(keys_view) }; - const auto all_device_ids { win_utils::getAllDeviceIdsAndMatchingDuplicates(*m_w_api, device_ids) }; + const auto keys_view {std::ranges::views::keys(modes)}; + const std::set device_ids {std::begin(keys_view), std::end(keys_view)}; + const auto all_device_ids {win_utils::getAllDeviceIdsAndMatchingDuplicates(*m_w_api, device_ids)}; if (all_device_ids.empty()) { DD_LOG(error) << "Failed to get all duplicated devices!"; return false; @@ -180,7 +176,7 @@ namespace display_device { return false; } - const auto &original_data { m_w_api->queryDisplayConfig(QueryType::All) }; + const auto &original_data {m_w_api->queryDisplayConfig(QueryType::All)}; if (!original_data) { // Error already logged return false; @@ -193,7 +189,7 @@ namespace display_device { const auto all_modes_match = [&modes](const DeviceDisplayModeMap ¤t_modes) { for (const auto &[device_id, requested_mode] : modes) { - auto mode_it { current_modes.find(device_id) }; + auto mode_it {current_modes.find(device_id)}; if (mode_it == std::end(current_modes)) { // This is a sanity check as `getCurrentDisplayModes` implicitly verifies this already. return false; @@ -207,7 +203,7 @@ namespace display_device { return true; }; - auto current_modes { getCurrentDisplayModes(device_ids) }; + auto current_modes {getCurrentDisplayModes(device_ids)}; if (!current_modes.empty()) { if (all_modes_match(current_modes)) { return true; @@ -232,7 +228,7 @@ namespace display_device { } } - const UINT32 flags { SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE }; + const UINT32 flags {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE}; static_cast(m_w_api->setDisplayConfig(original_data->m_paths, original_data->m_modes, flags)); // Return value does not matter as we are trying out best to undo DD_LOG(error) << "Failed to set display mode(-s) completely!"; return false; diff --git a/src/windows/win_display_device_primary.cpp b/src/windows/win_display_device_primary.cpp index 03b7f01..ed2f52d 100644 --- a/src/windows/win_display_device_primary.cpp +++ b/src/windows/win_display_device_primary.cpp @@ -10,26 +10,25 @@ #include "display_device/windows/win_api_utils.h" namespace display_device { - bool - WinDisplayDevice::isPrimary(const std::string &device_id) const { + bool WinDisplayDevice::isPrimary(const std::string &device_id) const { if (device_id.empty()) { DD_LOG(error) << "Device id is empty!"; return false; } - const auto display_data { m_w_api->queryDisplayConfig(QueryType::Active) }; + const auto display_data {m_w_api->queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return false; } - const auto path { win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths) }; + const auto path {win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths)}; if (!path) { DD_LOG(error) << "Failed to find active device for " << device_id << "!"; return false; } - const auto source_mode { win_utils::getSourceMode(win_utils::getSourceIndex(*path, display_data->m_modes), display_data->m_modes) }; + const auto source_mode {win_utils::getSourceMode(win_utils::getSourceIndex(*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; @@ -38,14 +37,13 @@ namespace display_device { return win_utils::isPrimary(*source_mode); } - bool - WinDisplayDevice::setAsPrimary(const std::string &device_id) { + bool WinDisplayDevice::setAsPrimary(const std::string &device_id) { if (device_id.empty()) { DD_LOG(error) << "Device id is empty!"; return false; } - auto display_data { m_w_api->queryDisplayConfig(QueryType::Active) }; + auto display_data {m_w_api->queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return false; @@ -54,13 +52,13 @@ namespace display_device { // Get the current origin point of the device (the one that we want to make primary) POINTL origin; { - const auto path { win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths) }; + const auto path {win_utils::getActivePath(*m_w_api, device_id, display_data->m_paths)}; if (!path) { DD_LOG(error) << "Failed to find device for " << device_id << "!"; return false; } - const auto source_mode { win_utils::getSourceMode(win_utils::getSourceIndex(*path, display_data->m_modes), display_data->m_modes) }; + const auto source_mode {win_utils::getSourceMode(win_utils::getSourceIndex(*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; @@ -78,9 +76,9 @@ namespace display_device { // device moves to (0, 0) position and others to their new positions. std::set modified_modes; for (auto &path : display_data->m_paths) { - const auto current_id { m_w_api->getDeviceId(path) }; - const auto source_index { win_utils::getSourceIndex(path, display_data->m_modes) }; - auto source_mode { win_utils::getSourceMode(source_index, display_data->m_modes) }; + const auto current_id {m_w_api->getDeviceId(path)}; + const auto source_index {win_utils::getSourceIndex(path, display_data->m_modes)}; + auto source_mode {win_utils::getSourceMode(source_index, display_data->m_modes)}; if (!source_index || !source_mode) { DD_LOG(error) << "Active device does not have a source mode: " << current_id << "!"; @@ -99,8 +97,8 @@ namespace display_device { modified_modes.insert(*source_index); } - const UINT32 flags { SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE }; - const LONG result { m_w_api->setDisplayConfig(display_data->m_paths, display_data->m_modes, flags) }; + const UINT32 flags {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE}; + const LONG result {m_w_api->setDisplayConfig(display_data->m_paths, display_data->m_modes, flags)}; if (result != ERROR_SUCCESS) { DD_LOG(error) << m_w_api->getErrorString(result) << " failed to set primary mode for " << device_id << "!"; return false; diff --git a/src/windows/win_display_device_topology.cpp b/src/windows/win_display_device_topology.cpp index a0623d2..6e1f21c 100644 --- a/src/windows/win_display_device_topology.cpp +++ b/src/windows/win_display_device_topology.cpp @@ -18,22 +18,21 @@ namespace display_device { /** * @see set_topology for a description as this was split off to reduce cognitive complexity. */ - bool - doSetTopology(WinApiLayerInterface &w_api, const ActiveTopology &new_topology, const PathAndModeData &display_data) { - const auto path_data { win_utils::collectSourceDataForMatchingPaths(w_api, display_data.m_paths) }; + bool doSetTopology(WinApiLayerInterface &w_api, const ActiveTopology &new_topology, const PathAndModeData &display_data) { + const auto path_data {win_utils::collectSourceDataForMatchingPaths(w_api, display_data.m_paths)}; if (path_data.empty()) { // Error already logged return false; } - auto paths { win_utils::makePathsForNewTopology(new_topology, path_data, display_data.m_paths) }; + auto paths {win_utils::makePathsForNewTopology(new_topology, path_data, display_data.m_paths)}; if (paths.empty()) { // Error already logged return false; } - UINT32 flags { SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE }; - LONG result { w_api.setDisplayConfig(paths, {}, flags) }; + UINT32 flags {SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE}; + LONG result {w_api.setDisplayConfig(paths, {}, flags)}; if (result == ERROR_GEN_FAILURE) { DD_LOG(warning) << w_api.getErrorString(result) << " failed to change topology using the topology from Windows DB! Asking Windows to create the topology."; @@ -43,8 +42,7 @@ namespace display_device { DD_LOG(error) << w_api.getErrorString(result) << " failed to create new topology configuration!"; return false; } - } - else if (result != ERROR_SUCCESS) { + } else if (result != ERROR_SUCCESS) { DD_LOG(error) << w_api.getErrorString(result) << " failed to change topology configuration!"; return false; } @@ -53,9 +51,8 @@ namespace display_device { } } // namespace - ActiveTopology - WinDisplayDevice::getCurrentTopology() const { - const auto display_data { m_w_api->queryDisplayConfig(QueryType::Active) }; + ActiveTopology WinDisplayDevice::getCurrentTopology() const { + const auto display_data {m_w_api->queryDisplayConfig(QueryType::Active)}; if (!display_data) { // Error already logged return {}; @@ -67,25 +64,24 @@ namespace display_device { std::unordered_map position_to_topology_index; ActiveTopology topology; for (const auto &path : display_data->m_paths) { - const auto device_info { win_utils::getDeviceInfoForValidPath(*m_w_api, path, display_device::ValidatedPathType::Active) }; + const auto device_info {win_utils::getDeviceInfoForValidPath(*m_w_api, path, display_device::ValidatedPathType::Active)}; if (!device_info) { continue; } - const auto source_mode { win_utils::getSourceMode(win_utils::getSourceIndex(path, display_data->m_modes), display_data->m_modes) }; + const auto source_mode {win_utils::getSourceMode(win_utils::getSourceIndex(path, display_data->m_modes), display_data->m_modes)}; if (!source_mode) { DD_LOG(error) << "Active device does not have a source mode: " << device_info->m_device_id << "!"; return {}; } - const std::string lazy_lookup { std::to_string(source_mode->position.x) + std::to_string(source_mode->position.y) }; - auto index_it { position_to_topology_index.find(lazy_lookup) }; + const std::string lazy_lookup {std::to_string(source_mode->position.x) + std::to_string(source_mode->position.y)}; + auto index_it {position_to_topology_index.find(lazy_lookup)}; if (index_it == std::end(position_to_topology_index)) { position_to_topology_index[lazy_lookup] = topology.size(); - topology.push_back({ device_info->m_device_id }); - } - else { + topology.push_back({device_info->m_device_id}); + } else { topology.at(index_it->second).push_back(device_info->m_device_id); } } @@ -93,8 +89,7 @@ namespace display_device { return topology; } - bool - WinDisplayDevice::isTopologyValid(const ActiveTopology &topology) const { + bool WinDisplayDevice::isTopologyValid(const ActiveTopology &topology) const { if (topology.empty()) { DD_LOG(warning) << "Topology input is empty!"; return false; @@ -121,8 +116,7 @@ namespace display_device { return true; } - bool - WinDisplayDevice::isTopologyTheSame(const ActiveTopology &lhs, const ActiveTopology &rhs) const { + bool WinDisplayDevice::isTopologyTheSame(const ActiveTopology &lhs, const ActiveTopology &rhs) const { const auto sort_topology = [](ActiveTopology &topology) { for (auto &group : topology) { std::sort(std::begin(group), std::end(group)); @@ -131,8 +125,8 @@ namespace display_device { std::sort(std::begin(topology), std::end(topology)); }; - auto lhs_copy { lhs }; - auto rhs_copy { rhs }; + auto lhs_copy {lhs}; + auto rhs_copy {rhs}; // On Windows order does not matter. sort_topology(lhs_copy); @@ -141,14 +135,13 @@ namespace display_device { return lhs_copy == rhs_copy; } - bool - WinDisplayDevice::setTopology(const ActiveTopology &new_topology) { + bool WinDisplayDevice::setTopology(const ActiveTopology &new_topology) { if (!isTopologyValid(new_topology)) { DD_LOG(error) << "Topology input is invalid!"; return false; } - const auto current_topology { getCurrentTopology() }; + const auto current_topology {getCurrentTopology()}; if (!isTopologyValid(current_topology)) { DD_LOG(error) << "Failed to get current topology!"; return false; @@ -159,19 +152,18 @@ namespace display_device { return true; } - const auto &original_data { m_w_api->queryDisplayConfig(QueryType::All) }; + const auto &original_data {m_w_api->queryDisplayConfig(QueryType::All)}; if (!original_data) { // Error already logged return false; } if (doSetTopology(*m_w_api, new_topology, *original_data)) { - const auto updated_topology { getCurrentTopology() }; + const auto updated_topology {getCurrentTopology()}; if (isTopologyValid(updated_topology)) { if (isTopologyTheSame(new_topology, updated_topology)) { return true; - } - else { + } else { // There is an interesting bug in Windows when you have nearly // identical devices, drivers or something. For example, imagine you have: // AM - Actual Monitor @@ -198,13 +190,12 @@ namespace display_device { // regardless of what Windows report back to us. DD_LOG(error) << "Failed to change topology due to Windows bug or because the display is in deep sleep!"; } - } - else { + } else { DD_LOG(error) << "Failed to get updated topology!"; } // Revert back to the original topology - const UINT32 flags { SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE }; + const UINT32 flags {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE}; static_cast(m_w_api->setDisplayConfig(original_data->m_paths, original_data->m_modes, flags)); // Return value does not matter as we are trying out best to undo } diff --git a/tests/fixtures/fixtures.cpp b/tests/fixtures/fixtures.cpp index ee73358..44020c0 100644 --- a/tests/fixtures/fixtures.cpp +++ b/tests/fixtures/fixtures.cpp @@ -4,9 +4,8 @@ // system includes #include -void -BaseTest::SetUp() { - if (const auto skip_reason { skipTest() }; !skip_reason.empty()) { +void BaseTest::SetUp() { + if (const auto skip_reason {skipTest()}; !skip_reason.empty()) { m_test_skipped_at_setup = true; GTEST_SKIP() << skip_reason; } @@ -21,8 +20,7 @@ BaseTest::SetUp() { display_device::Logger::get().setLogLevel(getDefaultLogLevel().value_or(display_device::Logger::LogLevel::verbose)); } -void -BaseTest::TearDown() { +void BaseTest::TearDown() { if (m_test_skipped_at_setup) { // We are not using the IsSkipped() state here. Here we are skipping // teardown, because we have skipped the setup entirely, but during normal @@ -49,20 +47,18 @@ BaseTest::TearDown() { } } -const std::vector & -BaseTest::getArgs() const { - static const auto args { ::testing::internal::GetArgvs() }; +const std::vector &BaseTest::getArgs() const { + static const auto args {::testing::internal::GetArgvs()}; return args; } -std::optional -BaseTest::getArgWithMatchingPattern(const std::string &pattern, bool remove_match) const { - const auto &args { getArgs() }; +std::optional BaseTest::getArgWithMatchingPattern(const std::string &pattern, bool remove_match) const { + const auto &args {getArgs()}; if (!args.empty()) { - const std::regex re_pattern { pattern }; + const std::regex re_pattern {pattern}; // We are skipping the first arg which is always binary name/path. - for (auto it { std::next(std::begin(args)) }; it != std::end(args); ++it) { + for (auto it {std::next(std::begin(args))}; it != std::end(args); ++it) { if (std::smatch match; std::regex_search(*it, match, re_pattern)) { return remove_match ? std::regex_replace(*it, re_pattern, "") : *it; } @@ -72,22 +68,19 @@ BaseTest::getArgWithMatchingPattern(const std::string &pattern, bool remove_matc return std::nullopt; } -bool -BaseTest::isOutputSuppressed() const { +bool BaseTest::isOutputSuppressed() const { return true; } -bool -BaseTest::isSystemTest() const { +bool BaseTest::isSystemTest() const { return false; } -std::string -BaseTest::skipTest() const { +std::string BaseTest::skipTest() const { if (isSystemTest()) { const static bool is_system_test_skippable { []() { - const auto value { getEnv("SKIP_SYSTEM_TESTS") }; + const auto value {getEnv("SKIP_SYSTEM_TESTS")}; return value == "1"; }() }; @@ -99,11 +92,10 @@ BaseTest::skipTest() const { return {}; } -std::optional -BaseTest::getDefaultLogLevel() const { +std::optional BaseTest::getDefaultLogLevel() const { const static auto default_log_level { []() -> std::optional { - const auto value { getEnv("LOG_LEVEL") }; + const auto value {getEnv("LOG_LEVEL")}; if (value == "verbose") { return display_device::Logger::LogLevel::verbose; } diff --git a/tests/fixtures/include/fixtures/fixtures.h b/tests/fixtures/include/fixtures/fixtures.h index 8992a9c..ae4b4e1 100644 --- a/tests/fixtures/include/fixtures/fixtures.h +++ b/tests/fixtures/include/fixtures/fixtures.h @@ -16,9 +16,8 @@ #undef TEST // Redefine TEST to use our BaseTest class, to automatically use our BaseTest fixture -#define TEST(test_case_name, test_name) \ - GTEST_TEST_(test_case_name, test_name, ::BaseTest, \ - ::testing::internal::GetTypeId<::BaseTest>()) +#define TEST(test_case_name, test_name) \ + GTEST_TEST_(test_case_name, test_name, ::BaseTest, ::testing::internal::GetTypeId<::BaseTest>()) // Helper macros for concatenating macro variables with an underscore separator (https://stackoverflow.com/questions/74505380/how-to-concatenate-join-va-args-with-delimiters-separators) #define DD_CAT_OP_(index, state, elem) BOOST_PP_CAT(state, BOOST_PP_CAT(_, elem)) @@ -44,18 +43,15 @@ class BaseTest: public ::testing::Test { protected: ~BaseTest() override = default; - void - SetUp() override; + void SetUp() override; - void - TearDown() override; + void TearDown() override; /** * @brief Get available command line arguments. * @return Command line args from GTest. */ - [[nodiscard]] virtual const std::vector & - getArgs() const; + [[nodiscard]] virtual const std::vector &getArgs() const; /** * @brief Get the command line argument that matches the pattern. @@ -63,43 +59,38 @@ class BaseTest: public ::testing::Test { * @param remove_match Specify if the matched pattern should be removed before returning argument. * @return Matching command line argument or null optional if nothing matched. */ - [[nodiscard]] virtual std::optional - getArgWithMatchingPattern(const std::string &pattern, bool remove_match) const; + [[nodiscard]] virtual std::optional getArgWithMatchingPattern(const std::string &pattern, bool remove_match) const; /** * @brief Check if the test output is to be redirected and printed out only if test fails. * @return True if output is to be suppressed, false otherwise. * @note It is useful for suppressing noise in automatic tests, but not so much in manual ones. */ - [[nodiscard]] virtual bool - isOutputSuppressed() const; + [[nodiscard]] virtual bool isOutputSuppressed() const; /** * @brief Check if the test interacts/modifies with the system settings. * @returns True if it does, false otherwise. * @note By setting SKIP_SYSTEM_TESTS=1 env, these tests will be skipped (useful during development). */ - [[nodiscard]] virtual bool - isSystemTest() const; + [[nodiscard]] virtual bool isSystemTest() const; /** * @brief Skip the test by specifying the reason. * @returns A non-empty string (reason) if test needs to be skipped, empty string otherwise. */ - [[nodiscard]] virtual std::string - skipTest() const; + [[nodiscard]] virtual std::string skipTest() const; /** * @brief Get the default log level for the test base. * @returns A log level set in the env OR null optional if fallback should be used (verbose). * @note By setting LOG_LEVEL= env you can change the level (e.g. LOG_LEVEL=error). */ - [[nodiscard]] virtual std::optional - getDefaultLogLevel() const; + [[nodiscard]] virtual std::optional getDefaultLogLevel() const; std::stringstream m_cout_buffer; /**< Stores the cout in case the output is suppressed. */ private: - std::streambuf *m_sbuf { nullptr }; /**< Stores the handle to the original cout stream. */ - bool m_test_skipped_at_setup { false }; /**< Indicates whether the SetUp method was skipped. */ + std::streambuf *m_sbuf {nullptr}; /**< Stores the handle to the original cout stream. */ + bool m_test_skipped_at_setup {false}; /**< Indicates whether the SetUp method was skipped. */ }; diff --git a/tests/fixtures/include/fixtures/json_converter_test.h b/tests/fixtures/include/fixtures/json_converter_test.h index 683df88..5b85bd3 100644 --- a/tests/fixtures/include/fixtures/json_converter_test.h +++ b/tests/fixtures/include/fixtures/json_converter_test.h @@ -6,11 +6,10 @@ class JsonConverterTest: public BaseTest { public: - template - void - executeTestCase(const T &input, const std::string &expected_string) { - bool success { false }; - const auto json_string { display_device::toJson(input, std::nullopt, &success) }; + template + void executeTestCase(const T &input, const std::string &expected_string) { + bool success {false}; + const auto json_string {display_device::toJson(input, std::nullopt, &success)}; EXPECT_TRUE(success); EXPECT_EQ(json_string, expected_string); diff --git a/tests/fixtures/include/fixtures/test_utils.h b/tests/fixtures/include/fixtures/test_utils.h index a73de6a..1376e7d 100644 --- a/tests/fixtures/include/fixtures/test_utils.h +++ b/tests/fixtures/include/fixtures/test_utils.h @@ -8,8 +8,7 @@ * @brief Test regular expression against string. * @return True if string matches the regex, false otherwise. */ -bool -testRegex(const std::string &test_pattern, const std::string ®ex_pattern); +bool testRegex(const std::string &test_pattern, const std::string ®ex_pattern); /** * @brief Set an environment variable. @@ -17,13 +16,11 @@ testRegex(const std::string &test_pattern, const std::string ®ex_pattern); * @param value Value of the environment variable. * @return 0 on success, non-zero error code on failure. */ -int -setEnv(const std::string &name, const std::string &value); +int setEnv(const std::string &name, const std::string &value); /** * @brief Get an environment variable. * @param name Name of the environment variable. * @return String value of the variable or an empty optional otherwise. */ -std::optional -getEnv(const std::string &name); +std::optional getEnv(const std::string &name); diff --git a/tests/fixtures/test_utils.cpp b/tests/fixtures/test_utils.cpp index c3b3f2b..b82ed70 100644 --- a/tests/fixtures/test_utils.cpp +++ b/tests/fixtures/test_utils.cpp @@ -8,8 +8,7 @@ #include #include -bool -testRegex(const std::string &input, const std::string &pattern) { +bool testRegex(const std::string &input, const std::string &pattern) { std::regex regex(pattern); std::smatch match; if (!std::regex_match(input, match, regex)) { @@ -21,8 +20,7 @@ testRegex(const std::string &input, const std::string &pattern) { return true; } -int -setEnv(const std::string &name, const std::string &value) { +int setEnv(const std::string &name, const std::string &value) { #ifdef _WIN32 return _putenv_s(name.c_str(), value.c_str()); #else @@ -30,10 +28,9 @@ setEnv(const std::string &name, const std::string &value) { #endif } -std::optional -getEnv(const std::string &name) { - if (const auto value { std::getenv(name.c_str()) }; value) { - return std::string { value }; +std::optional getEnv(const std::string &name) { + if (const auto value {std::getenv(name.c_str())}; value) { + return std::string {value}; } return std::nullopt; } diff --git a/tests/unit/general/test_comparison.cpp b/tests/unit/general/test_comparison.cpp index 68fcce4..0295ce0 100644 --- a/tests/unit/general/test_comparison.cpp +++ b/tests/unit/general/test_comparison.cpp @@ -8,81 +8,56 @@ namespace { } // namespace TEST_S(Point) { - EXPECT_EQ(display_device::Point({ 1, 1 }), display_device::Point({ 1, 1 })); - EXPECT_NE(display_device::Point({ 1, 1 }), display_device::Point({ 0, 1 })); - EXPECT_NE(display_device::Point({ 1, 1 }), display_device::Point({ 1, 0 })); + EXPECT_EQ(display_device::Point({1, 1}), display_device::Point({1, 1})); + EXPECT_NE(display_device::Point({1, 1}), display_device::Point({0, 1})); + EXPECT_NE(display_device::Point({1, 1}), display_device::Point({1, 0})); } TEST_S(Rational) { - EXPECT_EQ(display_device::Rational({ 1, 1 }), display_device::Rational({ 1, 1 })); - EXPECT_NE(display_device::Rational({ 1, 1 }), display_device::Rational({ 0, 1 })); - EXPECT_NE(display_device::Rational({ 1, 1 }), display_device::Rational({ 1, 0 })); + EXPECT_EQ(display_device::Rational({1, 1}), display_device::Rational({1, 1})); + EXPECT_NE(display_device::Rational({1, 1}), display_device::Rational({0, 1})); + EXPECT_NE(display_device::Rational({1, 1}), display_device::Rational({1, 0})); } TEST_S(Resolution) { - EXPECT_EQ(display_device::Resolution({ 1, 1 }), display_device::Resolution({ 1, 1 })); - EXPECT_NE(display_device::Resolution({ 1, 1 }), display_device::Resolution({ 0, 1 })); - EXPECT_NE(display_device::Resolution({ 1, 1 }), display_device::Resolution({ 1, 0 })); + EXPECT_EQ(display_device::Resolution({1, 1}), display_device::Resolution({1, 1})); + EXPECT_NE(display_device::Resolution({1, 1}), display_device::Resolution({0, 1})); + EXPECT_NE(display_device::Resolution({1, 1}), display_device::Resolution({1, 0})); } TEST_S(EnumeratedDevice, Info) { using Rat = display_device::Rational; - EXPECT_EQ(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, std::nullopt })); - EXPECT_EQ(display_device::EnumeratedDevice::Info({ { 1, 1 }, Rat { 1, 1 }, Rat { 1, 1 }, true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, Rat { 1, 1 }, Rat { 1, 1 }, true, { 1, 1 }, std::nullopt })); - EXPECT_EQ(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., Rat { 1, 1 }, true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., Rat { 1, 1 }, true, { 1, 1 }, std::nullopt })); - EXPECT_EQ(display_device::EnumeratedDevice::Info({ { 1, 1 }, Rat { 1, 1 }, 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, Rat { 1, 1 }, 1., true, { 1, 1 }, std::nullopt })); - EXPECT_NE(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., Rat { 1, 1 }, true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, Rat { 1, 1 }, Rat { 1, 1 }, true, { 1, 1 }, std::nullopt })); - EXPECT_NE(display_device::EnumeratedDevice::Info({ { 1, 1 }, Rat { 1, 1 }, 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, Rat { 1, 1 }, Rat { 1, 1 }, true, { 1, 1 }, std::nullopt })); - EXPECT_NE(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 0 }, 1., 1., true, { 1, 1 }, std::nullopt })); - EXPECT_NE(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, 1.1, 1., true, { 1, 1 }, std::nullopt })); - EXPECT_NE(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1.1, true, { 1, 1 }, std::nullopt })); - EXPECT_NE(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., false, { 1, 1 }, std::nullopt })); - EXPECT_NE(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 0 }, std::nullopt })); - EXPECT_NE(display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, std::nullopt }), - display_device::EnumeratedDevice::Info({ { 1, 1 }, 1., 1., true, { 1, 1 }, display_device::HdrState::Disabled })); + EXPECT_EQ(display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, std::nullopt})); + EXPECT_EQ(display_device::EnumeratedDevice::Info({{1, 1}, Rat {1, 1}, Rat {1, 1}, true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, Rat {1, 1}, Rat {1, 1}, true, {1, 1}, std::nullopt})); + EXPECT_EQ(display_device::EnumeratedDevice::Info({{1, 1}, 1., Rat {1, 1}, true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, 1., Rat {1, 1}, true, {1, 1}, std::nullopt})); + EXPECT_EQ(display_device::EnumeratedDevice::Info({{1, 1}, Rat {1, 1}, 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, Rat {1, 1}, 1., true, {1, 1}, std::nullopt})); + EXPECT_NE(display_device::EnumeratedDevice::Info({{1, 1}, 1., Rat {1, 1}, true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, Rat {1, 1}, Rat {1, 1}, true, {1, 1}, std::nullopt})); + EXPECT_NE(display_device::EnumeratedDevice::Info({{1, 1}, Rat {1, 1}, 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, Rat {1, 1}, Rat {1, 1}, true, {1, 1}, std::nullopt})); + EXPECT_NE(display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 0}, 1., 1., true, {1, 1}, std::nullopt})); + EXPECT_NE(display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, 1.1, 1., true, {1, 1}, std::nullopt})); + EXPECT_NE(display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, 1., 1.1, true, {1, 1}, std::nullopt})); + EXPECT_NE(display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., false, {1, 1}, std::nullopt})); + EXPECT_NE(display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 0}, std::nullopt})); + EXPECT_NE(display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, std::nullopt}), display_device::EnumeratedDevice::Info({{1, 1}, 1., 1., true, {1, 1}, display_device::HdrState::Disabled})); } TEST_S(EnumeratedDevice) { - EXPECT_EQ(display_device::EnumeratedDevice({ "1", "1", "1", display_device::EnumeratedDevice::Info {} }), - display_device::EnumeratedDevice({ "1", "1", "1", display_device::EnumeratedDevice::Info {} })); - EXPECT_NE(display_device::EnumeratedDevice({ "1", "1", "1", display_device::EnumeratedDevice::Info {} }), - display_device::EnumeratedDevice({ "0", "1", "1", display_device::EnumeratedDevice::Info {} })); - EXPECT_NE(display_device::EnumeratedDevice({ "1", "1", "1", display_device::EnumeratedDevice::Info {} }), - display_device::EnumeratedDevice({ "1", "0", "1", display_device::EnumeratedDevice::Info {} })); - EXPECT_NE(display_device::EnumeratedDevice({ "1", "1", "1", display_device::EnumeratedDevice::Info {} }), - display_device::EnumeratedDevice({ "1", "1", "0", display_device::EnumeratedDevice::Info {} })); - EXPECT_NE(display_device::EnumeratedDevice({ "1", "1", "1", display_device::EnumeratedDevice::Info {} }), - display_device::EnumeratedDevice({ "1", "1", "1", std::nullopt })); + EXPECT_EQ(display_device::EnumeratedDevice({"1", "1", "1", display_device::EnumeratedDevice::Info {}}), display_device::EnumeratedDevice({"1", "1", "1", display_device::EnumeratedDevice::Info {}})); + EXPECT_NE(display_device::EnumeratedDevice({"1", "1", "1", display_device::EnumeratedDevice::Info {}}), display_device::EnumeratedDevice({"0", "1", "1", display_device::EnumeratedDevice::Info {}})); + EXPECT_NE(display_device::EnumeratedDevice({"1", "1", "1", display_device::EnumeratedDevice::Info {}}), display_device::EnumeratedDevice({"1", "0", "1", display_device::EnumeratedDevice::Info {}})); + EXPECT_NE(display_device::EnumeratedDevice({"1", "1", "1", display_device::EnumeratedDevice::Info {}}), display_device::EnumeratedDevice({"1", "1", "0", display_device::EnumeratedDevice::Info {}})); + EXPECT_NE(display_device::EnumeratedDevice({"1", "1", "1", display_device::EnumeratedDevice::Info {}}), display_device::EnumeratedDevice({"1", "1", "1", std::nullopt})); } TEST_S(SingleDisplayConfiguration) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; using Rat = display_device::Rational; - EXPECT_EQ(display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled }), - display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled })); - EXPECT_EQ(display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, Rat { 1, 1 }, display_device::HdrState::Disabled }), - display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, Rat { 1, 1 }, display_device::HdrState::Disabled })); - EXPECT_NE(display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled }), - display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, Rat { 1, 1 }, display_device::HdrState::Disabled })); - EXPECT_NE(display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled }), - display_device::SingleDisplayConfiguration({ "0", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled })); - EXPECT_NE(display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled }), - display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsurePrimary, { { 1, 1 } }, 1., display_device::HdrState::Disabled })); - EXPECT_NE(display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled }), - display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 0 } }, 1., display_device::HdrState::Disabled })); - EXPECT_NE(display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled }), - display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1.1, display_device::HdrState::Disabled })); - EXPECT_NE(display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Disabled }), - display_device::SingleDisplayConfiguration({ "1", DevicePrep::EnsureActive, { { 1, 1 } }, 1., display_device::HdrState::Enabled })); + EXPECT_EQ(display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled}), display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled})); + EXPECT_EQ(display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, Rat {1, 1}, display_device::HdrState::Disabled}), display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, Rat {1, 1}, display_device::HdrState::Disabled})); + EXPECT_NE(display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled}), display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, Rat {1, 1}, display_device::HdrState::Disabled})); + EXPECT_NE(display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled}), display_device::SingleDisplayConfiguration({"0", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled})); + EXPECT_NE(display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled}), display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsurePrimary, {{1, 1}}, 1., display_device::HdrState::Disabled})); + EXPECT_NE(display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled}), display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 0}}, 1., display_device::HdrState::Disabled})); + EXPECT_NE(display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled}), display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1.1, display_device::HdrState::Disabled})); + EXPECT_NE(display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Disabled}), display_device::SingleDisplayConfiguration({"1", DevicePrep::EnsureActive, {{1, 1}}, 1., display_device::HdrState::Enabled})); } diff --git a/tests/unit/general/test_file_settings_persistence.cpp b/tests/unit/general/test_file_settings_persistence.cpp index 9780e29..92fd12c 100644 --- a/tests/unit/general/test_file_settings_persistence.cpp +++ b/tests/unit/general/test_file_settings_persistence.cpp @@ -17,8 +17,7 @@ namespace { std::filesystem::remove(m_filepath); } - display_device::FileSettingsPersistence & - getImpl(const std::filesystem::path &filepath = "testfile.ext") { + display_device::FileSettingsPersistence &getImpl(const std::filesystem::path &filepath = "testfile.ext") { if (!m_impl) { m_filepath = filepath; m_impl = std::make_unique(m_filepath); @@ -37,45 +36,47 @@ namespace { } // namespace TEST_F_S(EmptyFilenameProvided) { - EXPECT_THAT([]() { const display_device::FileSettingsPersistence persistence { {} }; }, - ThrowsMessage(HasSubstr("Empty filename provided for FileSettingsPersistence!"))); + EXPECT_THAT([]() { + const display_device::FileSettingsPersistence persistence {{}}; + }, + ThrowsMessage(HasSubstr("Empty filename provided for FileSettingsPersistence!"))); } TEST_F_S(Store, NewFileCreated) { - const std::filesystem::path filepath { "myfile.ext" }; - const std::vector data { 0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A' }; + const std::filesystem::path filepath {"myfile.ext"}; + const std::vector data {0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A'}; EXPECT_FALSE(std::filesystem::exists(filepath)); EXPECT_TRUE(getImpl(filepath).store(data)); EXPECT_TRUE(std::filesystem::exists(filepath)); - std::ifstream stream { filepath, std::ios::binary }; - std::vector file_data { std::istreambuf_iterator { stream }, std::istreambuf_iterator {} }; + std::ifstream stream {filepath, std::ios::binary}; + std::vector file_data {std::istreambuf_iterator {stream}, std::istreambuf_iterator {}}; EXPECT_EQ(file_data, data); } TEST_F_S(Store, FileOverwritten) { - const std::filesystem::path filepath { "myfile.ext" }; - const std::vector data1 { 0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A', ' ', '1' }; - const std::vector data2 { 0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A', ' ', '2' }; + const std::filesystem::path filepath {"myfile.ext"}; + const std::vector data1 {0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A', ' ', '1'}; + const std::vector data2 {0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A', ' ', '2'}; { - std::ofstream file { filepath, std::ios_base::binary }; - std::copy(std::begin(data1), std::end(data1), std::ostreambuf_iterator { file }); + std::ofstream file {filepath, std::ios_base::binary}; + std::copy(std::begin(data1), std::end(data1), std::ostreambuf_iterator {file}); } EXPECT_TRUE(std::filesystem::exists(filepath)); EXPECT_TRUE(getImpl(filepath).store(data2)); EXPECT_TRUE(std::filesystem::exists(filepath)); - std::ifstream stream { filepath, std::ios::binary }; - std::vector file_data { std::istreambuf_iterator { stream }, std::istreambuf_iterator {} }; + std::ifstream stream {filepath, std::ios::binary}; + std::vector file_data {std::istreambuf_iterator {stream}, std::istreambuf_iterator {}}; EXPECT_EQ(file_data, data2); } TEST_F_S(Store, FilepathWithDirectory) { - const std::filesystem::path filepath { "somedir/myfile.ext" }; - const std::vector data { 0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A' }; + const std::filesystem::path filepath {"somedir/myfile.ext"}; + const std::vector data {0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A'}; EXPECT_FALSE(std::filesystem::exists(filepath)); EXPECT_FALSE(getImpl(filepath).store(data)); @@ -87,12 +88,12 @@ TEST_F_S(Load, NoFileAvailable) { } TEST_F_S(Load, FileRead) { - const std::filesystem::path filepath { "myfile.ext" }; - const std::vector data { 0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A' }; + const std::filesystem::path filepath {"myfile.ext"}; + const std::vector data {0x00, 0x01, 0x02, 0x04, 'S', 'O', 'M', 'E', ' ', 'D', 'A', 'T', 'A'}; { - std::ofstream file { filepath, std::ios_base::binary }; - std::copy(std::begin(data), std::end(data), std::ostreambuf_iterator { file }); + std::ofstream file {filepath, std::ios_base::binary}; + std::copy(std::begin(data), std::end(data), std::ostreambuf_iterator {file}); } EXPECT_EQ(getImpl(filepath).load(), data); @@ -103,9 +104,9 @@ TEST_F_S(Clear, NoFileAvailable) { } TEST_F_S(Clear, FileRemoved) { - const std::filesystem::path filepath { "myfile.ext" }; + const std::filesystem::path filepath {"myfile.ext"}; { - std::ofstream file { filepath }; + std::ofstream file {filepath}; file << "some data"; } diff --git a/tests/unit/general/test_json.cpp b/tests/unit/general/test_json.cpp index 8764e98..9162a62 100644 --- a/tests/unit/general/test_json.cpp +++ b/tests/unit/general/test_json.cpp @@ -27,17 +27,15 @@ namespace display_device { using TestVariant = std::variant; - bool - operator==(const TestStruct::Nested &lhs, const TestStruct::Nested &rhs) { + bool operator==(const TestStruct::Nested &lhs, const TestStruct::Nested &rhs) { return lhs.m_c == rhs.m_c; } - bool - operator==(const TestStruct &lhs, const TestStruct &rhs) { + bool operator==(const TestStruct &lhs, const TestStruct &rhs) { return lhs.m_a == rhs.m_a && lhs.m_b == rhs.m_b; } - DD_JSON_DEFINE_SERIALIZE_ENUM_GCOVR_EXCL_BR_LINE(TestEnum, { { TestEnum::Value1, "Value1" }, { TestEnum::Value2, "ValueMaybe2" } }) + DD_JSON_DEFINE_SERIALIZE_ENUM_GCOVR_EXCL_BR_LINE(TestEnum, {{TestEnum::Value1, "Value1"}, {TestEnum::Value2, "ValueMaybe2"}}) DD_JSON_DEFINE_SERIALIZE_STRUCT(TestStruct::Nested, c) DD_JSON_DEFINE_SERIALIZE_STRUCT(TestStruct, a, b) @@ -61,56 +59,56 @@ namespace { #define TEST_S(...) DD_MAKE_TEST(TEST, JsonTest, __VA_ARGS__) // Additional convenience global const(s) - constexpr auto MIN_NANO_VAL { std::numeric_limits::min() }; - constexpr auto MAX_NANO_VAL { std::numeric_limits::max() }; + constexpr auto MIN_NANO_VAL {std::numeric_limits::min()}; + constexpr auto MAX_NANO_VAL {std::numeric_limits::max()}; } // namespace TEST_S(ToJson, NoError, WithSuccessParam) { - bool success { false }; - const auto json_string { display_device::toJson(display_device::TestStruct {}, std::nullopt, &success) }; + bool success {false}; + const auto json_string {display_device::toJson(display_device::TestStruct {}, std::nullopt, &success)}; EXPECT_TRUE(success); EXPECT_EQ(json_string, R"({"a":"","b":{"c":0}})"); } TEST_S(ToJson, NoError, WithoutSuccessParam) { - const auto json_string { display_device::toJson(display_device::TestStruct {}, std::nullopt, nullptr) }; + const auto json_string {display_device::toJson(display_device::TestStruct {}, std::nullopt, nullptr)}; EXPECT_EQ(json_string, R"({"a":"","b":{"c":0}})"); } TEST_S(ToJson, Error, WithSuccessParam) { - bool success { true }; - const auto json_string { display_device::toJson(display_device::TestStruct { "123\xC2" }, std::nullopt, &success) }; + bool success {true}; + const auto json_string {display_device::toJson(display_device::TestStruct {"123\xC2"}, std::nullopt, &success)}; EXPECT_FALSE(success); EXPECT_EQ(json_string, "[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xC2"); } TEST_S(ToJson, Error, WithoutSuccessParam) { - const auto json_string { display_device::toJson(display_device::TestStruct { "123\xC2" }, std::nullopt, nullptr) }; + const auto json_string {display_device::toJson(display_device::TestStruct {"123\xC2"}, std::nullopt, nullptr)}; EXPECT_EQ(json_string, "[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xC2"); } TEST_S(ToJson, Compact) { - const auto json_string { display_device::toJson(display_device::TestStruct {}, std::nullopt, nullptr) }; + const auto json_string {display_device::toJson(display_device::TestStruct {}, std::nullopt, nullptr)}; EXPECT_EQ(json_string, "{\"a\":\"\",\"b\":{\"c\":0}}"); } TEST_S(ToJson, NoIndent) { - const auto json_string { display_device::toJson(display_device::TestStruct {}, 0, nullptr) }; + const auto json_string {display_device::toJson(display_device::TestStruct {}, 0, nullptr)}; EXPECT_EQ(json_string, "{\n\"a\": \"\",\n\"b\": {\n\"c\": 0\n}\n}"); } TEST_S(ToJson, WithIndent) { - const auto json_string { display_device::toJson(display_device::TestStruct {}, 3, nullptr) }; + const auto json_string {display_device::toJson(display_device::TestStruct {}, 3, nullptr)}; EXPECT_EQ(json_string, "{\n \"a\": \"\",\n \"b\": {\n \"c\": 0\n }\n}"); } TEST_S(FromJson, NoError, WithErrorMessageParam) { - display_device::TestStruct original { "A", { 1 } }; - display_device::TestStruct expected { "B", { 2 } }; - display_device::TestStruct copy { original }; - std::string error_message { "some_string" }; + display_device::TestStruct original {"A", {1}}; + display_device::TestStruct expected {"B", {2}}; + display_device::TestStruct copy {original}; + std::string error_message {"some_string"}; EXPECT_EQ(original, copy); EXPECT_NE(copy, expected); @@ -122,9 +120,9 @@ TEST_S(FromJson, NoError, WithErrorMessageParam) { } TEST_S(FromJson, NoError, WithoutErrorMessageParam) { - display_device::TestStruct original { "A", { 1 } }; - display_device::TestStruct expected { "B", { 2 } }; - display_device::TestStruct copy { original }; + display_device::TestStruct original {"A", {1}}; + display_device::TestStruct expected {"B", {2}}; + display_device::TestStruct copy {original}; EXPECT_EQ(original, copy); EXPECT_NE(copy, expected); @@ -134,8 +132,8 @@ TEST_S(FromJson, NoError, WithoutErrorMessageParam) { } TEST_S(FromJson, Error, WithErrorMessageParam) { - display_device::TestStruct original { "A", { 1 } }; - display_device::TestStruct copy { original }; + display_device::TestStruct original {"A", {1}}; + display_device::TestStruct copy {original}; std::string error_message {}; EXPECT_EQ(original, copy); @@ -147,8 +145,8 @@ TEST_S(FromJson, Error, WithErrorMessageParam) { } TEST_S(FromJson, Error, WithoutErrorMessageParam) { - display_device::TestStruct original { "A", { 1 } }; - display_device::TestStruct copy { original }; + display_device::TestStruct original {"A", {1}}; + display_device::TestStruct copy {original}; EXPECT_EQ(original, copy); @@ -172,7 +170,7 @@ TEST_S(FromJson, Enum) { } TEST_S(ToJson, Enum, MissingMappingValue) { - const auto json_string { display_device::toJson(display_device::TestEnum::Value3, std::nullopt, nullptr) }; + const auto json_string {display_device::toJson(display_device::TestEnum::Value3, std::nullopt, nullptr)}; EXPECT_EQ(json_string, "TestEnum is missing enum mapping!"); } @@ -185,8 +183,8 @@ TEST_S(FromJson, Enum, MissingMappingValue) { } TEST_S(ToJson, TestVariant) { - EXPECT_EQ(toJson(display_device::TestVariant { 123. }, std::nullopt, nullptr), R"({"type":"double","value":123.0})"); - EXPECT_EQ(toJson(display_device::TestVariant { display_device::Rational { 1, 2 } }, std::nullopt, nullptr), R"({"type":"rational","value":{"denominator":2,"numerator":1}})"); + EXPECT_EQ(toJson(display_device::TestVariant {123.}, std::nullopt, nullptr), R"({"type":"double","value":123.0})"); + EXPECT_EQ(toJson(display_device::TestVariant {display_device::Rational {1, 2}}, std::nullopt, nullptr), R"({"type":"rational","value":{"denominator":2,"numerator":1}})"); } TEST_S(FromJson, TestVariant) { @@ -196,7 +194,7 @@ TEST_S(FromJson, TestVariant) { EXPECT_EQ(std::get(variant), 123.0); // Relying on GTest to properly compare floats EXPECT_TRUE(display_device::fromJson(R"({"type":"rational","value":{"denominator":2,"numerator":1}})", variant, nullptr)); - EXPECT_EQ(std::get(variant), display_device::Rational({ 1, 2 })); + EXPECT_EQ(std::get(variant), display_device::Rational({1, 2})); } TEST_S(FromJson, TestVariant, UnknownVariantType) { @@ -210,51 +208,51 @@ TEST_S(FromJson, TestVariant, UnknownVariantType) { TEST_S(ToJson, ChronoDuration) { using namespace std::chrono; - EXPECT_EQ(display_device::toJson(nanoseconds { 2000000000 }, std::nullopt, nullptr), R"(2000000000)"); - EXPECT_EQ(display_device::toJson(microseconds { 2000000 }, std::nullopt, nullptr), R"(2000000)"); - EXPECT_EQ(display_device::toJson(milliseconds { 2000 }, std::nullopt, nullptr), R"(2000)"); - EXPECT_EQ(display_device::toJson(seconds { 2 }, std::nullopt, nullptr), R"(2)"); - EXPECT_EQ(display_device::toJson(minutes { 20 }, std::nullopt, nullptr), R"(20)"); - EXPECT_EQ(display_device::toJson(hours { 20 }, std::nullopt, nullptr), R"(20)"); - EXPECT_EQ(display_device::toJson(days { 20 }, std::nullopt, nullptr), R"(20)"); - EXPECT_EQ(display_device::toJson(weeks { 20 }, std::nullopt, nullptr), R"(20)"); - EXPECT_EQ(display_device::toJson(months { 20 }, std::nullopt, nullptr), R"(20)"); - EXPECT_EQ(display_device::toJson(years { 20 }, std::nullopt, nullptr), R"(20)"); + EXPECT_EQ(display_device::toJson(nanoseconds {2000000000}, std::nullopt, nullptr), R"(2000000000)"); + EXPECT_EQ(display_device::toJson(microseconds {2000000}, std::nullopt, nullptr), R"(2000000)"); + EXPECT_EQ(display_device::toJson(milliseconds {2000}, std::nullopt, nullptr), R"(2000)"); + EXPECT_EQ(display_device::toJson(seconds {2}, std::nullopt, nullptr), R"(2)"); + EXPECT_EQ(display_device::toJson(minutes {20}, std::nullopt, nullptr), R"(20)"); + EXPECT_EQ(display_device::toJson(hours {20}, std::nullopt, nullptr), R"(20)"); + EXPECT_EQ(display_device::toJson(days {20}, std::nullopt, nullptr), R"(20)"); + EXPECT_EQ(display_device::toJson(weeks {20}, std::nullopt, nullptr), R"(20)"); + EXPECT_EQ(display_device::toJson(months {20}, std::nullopt, nullptr), R"(20)"); + EXPECT_EQ(display_device::toJson(years {20}, std::nullopt, nullptr), R"(20)"); } TEST_S(FromJson, ChronoDuration) { - const auto doTest { [](const std::string &string_input, T expected_value) { + const auto doTest {[](const std::string &string_input, T expected_value) { T value {}; EXPECT_TRUE(display_device::fromJson(string_input, value, nullptr)); EXPECT_EQ(value, expected_value); - } }; + }}; using namespace std::chrono; - doTest(R"(2000000000)", nanoseconds { 2000000000 }); - doTest(R"(2000000)", microseconds { 2000000 }); - doTest(R"(2000)", milliseconds { 2000 }); - doTest(R"(2)", seconds { 2 }); - doTest(R"(20)", minutes { 20 }); - doTest(R"(20)", hours { 20 }); - doTest(R"(20)", days { 20 }); - doTest(R"(20)", weeks { 20 }); - doTest(R"(20)", months { 20 }); - doTest(R"(20)", years { 20 }); + doTest(R"(2000000000)", nanoseconds {2000000000}); + doTest(R"(2000000)", microseconds {2000000}); + doTest(R"(2000)", milliseconds {2000}); + doTest(R"(2)", seconds {2}); + doTest(R"(20)", minutes {20}); + doTest(R"(20)", hours {20}); + doTest(R"(20)", days {20}); + doTest(R"(20)", weeks {20}); + doTest(R"(20)", months {20}); + doTest(R"(20)", years {20}); } TEST_S(ToJson, ChronoDuration, Ranges) { - EXPECT_EQ(display_device::toJson(std::chrono::nanoseconds { MIN_NANO_VAL }, std::nullopt, nullptr), std::to_string(MIN_NANO_VAL)); - EXPECT_EQ(display_device::toJson(std::chrono::nanoseconds { MAX_NANO_VAL }, std::nullopt, nullptr), std::to_string(MAX_NANO_VAL)); + EXPECT_EQ(display_device::toJson(std::chrono::nanoseconds {MIN_NANO_VAL}, std::nullopt, nullptr), std::to_string(MIN_NANO_VAL)); + EXPECT_EQ(display_device::toJson(std::chrono::nanoseconds {MAX_NANO_VAL}, std::nullopt, nullptr), std::to_string(MAX_NANO_VAL)); } TEST_S(FromJson, ChronoDuration, Ranges) { std::chrono::nanoseconds value {}; EXPECT_TRUE(display_device::fromJson(std::to_string(MIN_NANO_VAL), value, nullptr)); - EXPECT_EQ(value, std::chrono::nanoseconds { MIN_NANO_VAL }); + EXPECT_EQ(value, std::chrono::nanoseconds {MIN_NANO_VAL}); EXPECT_TRUE(display_device::fromJson(std::to_string(MAX_NANO_VAL), value, nullptr)); - EXPECT_EQ(value, std::chrono::nanoseconds { MAX_NANO_VAL }); + EXPECT_EQ(value, std::chrono::nanoseconds {MAX_NANO_VAL}); } diff --git a/tests/unit/general/test_json_converter.cpp b/tests/unit/general/test_json_converter.cpp index 22d642d..59c89b9 100644 --- a/tests/unit/general/test_json_converter.cpp +++ b/tests/unit/general/test_json_converter.cpp @@ -12,24 +12,26 @@ TEST_F_S(EnumeratedDevice) { "NAME_2", "FU_NAME_3", display_device::EnumeratedDevice::Info { - { 1920, 1080 }, - display_device::Rational { 175, 100 }, + {1920, 1080}, + display_device::Rational {175, 100}, 119.9554, false, - { 1, 2 }, - display_device::HdrState::Enabled } + {1, 2}, + display_device::HdrState::Enabled + } }; display_device::EnumeratedDevice item_2 { "ID_2", "NAME_2", "FU_NAME_2", display_device::EnumeratedDevice::Info { - { 1920, 1080 }, + {1920, 1080}, 1.75, - display_device::Rational { 1199554, 10000 }, + display_device::Rational {1199554, 10000}, true, - { 0, 0 }, - display_device::HdrState::Disabled } + {0, 0}, + display_device::HdrState::Disabled + } }; executeTestCase(display_device::EnumeratedDevice {}, R"({"device_id":"","display_name":"","friendly_name":"","info":null})"); @@ -43,39 +45,40 @@ TEST_F_S(EnumeratedDeviceList) { "NAME_2", "FU_NAME_3", display_device::EnumeratedDevice::Info { - { 1920, 1080 }, - display_device::Rational { 175, 100 }, + {1920, 1080}, + display_device::Rational {175, 100}, 119.9554, false, - { 1, 2 }, - display_device::HdrState::Enabled } + {1, 2}, + display_device::HdrState::Enabled + } }; display_device::EnumeratedDevice item_2 { "ID_2", "NAME_2", "FU_NAME_2", display_device::EnumeratedDevice::Info { - { 1920, 1080 }, + {1920, 1080}, 1.75, - display_device::Rational { 1199554, 10000 }, + display_device::Rational {1199554, 10000}, true, - { 0, 0 }, - display_device::HdrState::Disabled } + {0, 0}, + display_device::HdrState::Disabled + } }; display_device::EnumeratedDevice item_3 {}; executeTestCase(display_device::EnumeratedDeviceList {}, R"([])"); - executeTestCase(display_device::EnumeratedDeviceList { item_1, item_2, item_3 }, - R"([{"device_id":"ID_1","display_name":"NAME_2","friendly_name":"FU_NAME_3","info":{"hdr_state":"Enabled","origin_point":{"x":1,"y":2},"primary":false,"refresh_rate":{"type":"double","value":119.9554},"resolution":{"height":1080,"width":1920},"resolution_scale":{"type":"rational","value":{"denominator":100,"numerator":175}}}},)" - R"({"device_id":"ID_2","display_name":"NAME_2","friendly_name":"FU_NAME_2","info":{"hdr_state":"Disabled","origin_point":{"x":0,"y":0},"primary":true,"refresh_rate":{"type":"rational","value":{"denominator":10000,"numerator":1199554}},"resolution":{"height":1080,"width":1920},"resolution_scale":{"type":"double","value":1.75}}},)" - R"({"device_id":"","display_name":"","friendly_name":"","info":null}])"); + executeTestCase(display_device::EnumeratedDeviceList {item_1, item_2, item_3}, R"([{"device_id":"ID_1","display_name":"NAME_2","friendly_name":"FU_NAME_3","info":{"hdr_state":"Enabled","origin_point":{"x":1,"y":2},"primary":false,"refresh_rate":{"type":"double","value":119.9554},"resolution":{"height":1080,"width":1920},"resolution_scale":{"type":"rational","value":{"denominator":100,"numerator":175}}}},)" + R"({"device_id":"ID_2","display_name":"NAME_2","friendly_name":"FU_NAME_2","info":{"hdr_state":"Disabled","origin_point":{"x":0,"y":0},"primary":true,"refresh_rate":{"type":"rational","value":{"denominator":10000,"numerator":1199554}},"resolution":{"height":1080,"width":1920},"resolution_scale":{"type":"double","value":1.75}}},)" + R"({"device_id":"","display_name":"","friendly_name":"","info":null}])"); } TEST_F_S(SingleDisplayConfiguration) { - display_device::SingleDisplayConfiguration config_1 { "ID_1", display_device::SingleDisplayConfiguration::DevicePreparation::VerifyOnly, { { 156, 123 } }, 85., display_device::HdrState::Enabled }; - display_device::SingleDisplayConfiguration config_2 { "ID_2", display_device::SingleDisplayConfiguration::DevicePreparation::EnsureActive, std::nullopt, display_device::Rational { 85, 1 }, display_device::HdrState::Disabled }; - display_device::SingleDisplayConfiguration config_3 { "ID_3", display_device::SingleDisplayConfiguration::DevicePreparation::EnsureOnlyDisplay, { { 156, 123 } }, std::nullopt, std::nullopt }; - display_device::SingleDisplayConfiguration config_4 { "ID_4", display_device::SingleDisplayConfiguration::DevicePreparation::EnsurePrimary, std::nullopt, std::nullopt, std::nullopt }; + display_device::SingleDisplayConfiguration config_1 {"ID_1", display_device::SingleDisplayConfiguration::DevicePreparation::VerifyOnly, {{156, 123}}, 85., display_device::HdrState::Enabled}; + display_device::SingleDisplayConfiguration config_2 {"ID_2", display_device::SingleDisplayConfiguration::DevicePreparation::EnsureActive, std::nullopt, display_device::Rational {85, 1}, display_device::HdrState::Disabled}; + display_device::SingleDisplayConfiguration config_3 {"ID_3", display_device::SingleDisplayConfiguration::DevicePreparation::EnsureOnlyDisplay, {{156, 123}}, std::nullopt, std::nullopt}; + display_device::SingleDisplayConfiguration config_4 {"ID_4", display_device::SingleDisplayConfiguration::DevicePreparation::EnsurePrimary, std::nullopt, std::nullopt, std::nullopt}; executeTestCase(display_device::SingleDisplayConfiguration {}, R"({"device_id":"","device_prep":"VerifyOnly","hdr_state":null,"refresh_rate":null,"resolution":null})"); executeTestCase(config_1, R"({"device_id":"ID_1","device_prep":"VerifyOnly","hdr_state":"Enabled","refresh_rate":{"type":"double","value":85.0},"resolution":{"height":123,"width":156}})"); @@ -86,13 +89,13 @@ TEST_F_S(SingleDisplayConfiguration) { TEST_F_S(StringSet) { executeTestCase(std::set {}, R"([])"); - executeTestCase(std::set { "ABC", "DEF" }, R"(["ABC","DEF"])"); - executeTestCase(std::set { "DEF", "ABC" }, R"(["ABC","DEF"])"); + executeTestCase(std::set {"ABC", "DEF"}, R"(["ABC","DEF"])"); + executeTestCase(std::set {"DEF", "ABC"}, R"(["ABC","DEF"])"); } TEST_F_S(String) { executeTestCase(std::string {}, R"("")"); - executeTestCase(std::string { "ABC" }, R"("ABC")"); + executeTestCase(std::string {"ABC"}, R"("ABC")"); } TEST_F_S(Bool) { diff --git a/tests/unit/general/test_logging.cpp b/tests/unit/general/test_logging.cpp index 57c04f0..3664fa0 100644 --- a/tests/unit/general/test_logging.cpp +++ b/tests/unit/general/test_logging.cpp @@ -9,7 +9,7 @@ namespace { TEST_S(LogLevelVerbose) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; logger.setLogLevel(level::verbose); @@ -23,7 +23,7 @@ TEST_S(LogLevelVerbose) { TEST_S(LogLevelDebug) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; logger.setLogLevel(level::debug); @@ -37,7 +37,7 @@ TEST_S(LogLevelDebug) { TEST_S(LogLevelInfo) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; logger.setLogLevel(level::info); @@ -51,7 +51,7 @@ TEST_S(LogLevelInfo) { TEST_S(LogLevelWarning) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; logger.setLogLevel(level::warning); @@ -65,7 +65,7 @@ TEST_S(LogLevelWarning) { TEST_S(LogLevelError) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; logger.setLogLevel(level::error); @@ -79,7 +79,7 @@ TEST_S(LogLevelError) { TEST_S(LogLevelFatal) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; logger.setLogLevel(level::fatal); @@ -93,13 +93,13 @@ TEST_S(LogLevelFatal) { TEST_S(DefaultLogger) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + 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) -> std::string { m_cout_buffer.str(std::string {}); // reset the buffer logger.write(level, std::move(value)); return m_cout_buffer.str(); - } }; + }}; logger.setLogLevel(level::verbose); // clang-format off @@ -115,7 +115,7 @@ TEST_S(DefaultLogger) { TEST_S(CustomCallback) { using level = display_device::Logger::LogLevel; using level_t = std::underlying_type_t; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; std::string output; logger.setLogLevel(level::verbose); @@ -150,7 +150,7 @@ TEST_S(CustomCallback) { TEST_S(WriteMethodRespectsLogLevel, DefaultLogger) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; EXPECT_TRUE(m_cout_buffer.str().empty()); @@ -165,9 +165,9 @@ TEST_S(WriteMethodRespectsLogLevel, DefaultLogger) { TEST_S(WriteMethodRespectsLogLevel, CustomCallback) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; - bool callback_invoked { false }; + bool callback_invoked {false}; logger.setCustomCallback([&callback_invoked](auto, auto) { callback_invoked = true; }); @@ -183,18 +183,18 @@ TEST_S(WriteMethodRespectsLogLevel, CustomCallback) { TEST_S(LogMacroDisablesStreamChain) { using level = display_device::Logger::LogLevel; - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; - bool output_logged { false }; + bool output_logged {false}; logger.setCustomCallback([&output_logged](auto, auto) { output_logged = true; }); - bool some_function_invoked { false }; - const auto some_function { [&some_function_invoked]() { + bool some_function_invoked {false}; + const auto some_function {[&some_function_invoked]() { some_function_invoked = true; return "some string"; - } }; + }}; logger.setLogLevel(level::error); DD_LOG(info) << some_function(); diff --git a/tests/unit/general/test_noop_settings_persistence.cpp b/tests/unit/general/test_noop_settings_persistence.cpp index a33ba76..1e9bd8a 100644 --- a/tests/unit/general/test_noop_settings_persistence.cpp +++ b/tests/unit/general/test_noop_settings_persistence.cpp @@ -15,7 +15,7 @@ namespace { TEST_F_S(Store) { EXPECT_TRUE(m_impl.store({})); - EXPECT_TRUE(m_impl.store({ 0x01, 0x02, 0x03 })); + EXPECT_TRUE(m_impl.store({0x01, 0x02, 0x03})); } TEST_F_S(Load) { diff --git a/tests/unit/general/test_retry_scheduler.cpp b/tests/unit/general/test_retry_scheduler.cpp index efa6d3d..eb80fd7 100644 --- a/tests/unit/general/test_retry_scheduler.cpp +++ b/tests/unit/general/test_retry_scheduler.cpp @@ -15,23 +15,21 @@ namespace { struct TestIface { std::vector m_durations; - void - nonConstMethod() { /* noop */ } - void - constMethod() const { /* noop */ } + void nonConstMethod() { /* noop */ } + + void constMethod() const { /* noop */ } }; // Some threads wake up a little earlier than expected, so we round the lower bound to // 99% of the expected value to stabilize the tests - int - roundTo99(int value) { + int roundTo99(int value) { return static_cast(std::round(value * 0.99)); } // Test fixture(s) for this file class RetrySchedulerTest: public BaseTest { public: - display_device::RetryScheduler m_impl { std::make_unique() }; + display_device::RetryScheduler m_impl {std::make_unique()}; }; // Specialized TEST macro(s) for this test file @@ -39,31 +37,45 @@ namespace { } // namespace TEST_F_S(NullptrInterfaceProvided) { - EXPECT_THAT([]() { const display_device::RetryScheduler scheduler(nullptr); }, - ThrowsMessage(HasSubstr("Nullptr interface provided in RetryScheduler!"))); + EXPECT_THAT([]() { + const display_device::RetryScheduler scheduler(nullptr); + }, + ThrowsMessage(HasSubstr("Nullptr interface provided in RetryScheduler!"))); } TEST_F_S(Schedule, NullptrCallbackProvided) { - EXPECT_THAT([&]() { m_impl.schedule(nullptr, { .m_sleep_durations = { 0ms } }); }, - ThrowsMessage(HasSubstr("Empty callback function provided in RetryScheduler::schedule!"))); + EXPECT_THAT([&]() { + m_impl.schedule(nullptr, {.m_sleep_durations = {0ms}}); + }, + ThrowsMessage(HasSubstr("Empty callback function provided in RetryScheduler::schedule!"))); } TEST_F_S(Schedule, NoDurations) { - EXPECT_THAT([&]() { m_impl.schedule([](auto, auto &) {}, { .m_sleep_durations = {} }); }, - ThrowsMessage(HasSubstr("At least 1 sleep duration must be specified in RetryScheduler::schedule!"))); + EXPECT_THAT([&]() { + m_impl.schedule([](auto, auto &) { + }, + {.m_sleep_durations = {}}); + }, + ThrowsMessage(HasSubstr("At least 1 sleep duration must be specified in RetryScheduler::schedule!"))); } TEST_F_S(Schedule, ZeroDuration) { - EXPECT_THAT([&]() { m_impl.schedule([](auto, auto &) {}, { .m_sleep_durations = { 0ms } }); }, - ThrowsMessage(HasSubstr("All of the durations specified in RetryScheduler::schedule must be larger than a 0!"))); + EXPECT_THAT([&]() { + m_impl.schedule([](auto, auto &) { + }, + {.m_sleep_durations = {0ms}}); + }, + ThrowsMessage(HasSubstr("All of the durations specified in RetryScheduler::schedule must be larger than a 0!"))); } TEST_F_S(Schedule, SchedulingDurations) { // Note: in this test we care that the delay is not less than the requested one, but we // do not really have an upper ceiling... - const auto schedule_and_get_average_delays { [&](const std::vector &durations) { - m_impl.execute([](TestIface &iface) { iface.m_durations.clear(); }); + const auto schedule_and_get_average_delays {[&](const std::vector &durations) { + m_impl.execute([](TestIface &iface) { + iface.m_durations.clear(); + }); std::optional prev; m_impl.schedule([&durations, &prev](TestIface &iface, auto &stop_token) { @@ -77,42 +89,45 @@ TEST_F_S(Schedule, SchedulingDurations) { prev = now; }, - { .m_sleep_durations = durations }); + {.m_sleep_durations = durations}); while (m_impl.isScheduled()) { std::this_thread::sleep_for(1ms); } return m_impl.execute([](TestIface &iface) { - int sum { 0 }; + int sum {0}; for (const auto timing : iface.m_durations) { sum += timing; } return sum / iface.m_durations.size(); }); - } }; + }}; - EXPECT_GE(schedule_and_get_average_delays({ 10ms, 10ms, 10ms, 10ms, 10ms, 10ms, 10ms, 10ms, 10ms, 10ms }), 10); - EXPECT_GE(schedule_and_get_average_delays({ 50ms, 50ms, 50ms, 50ms, 50ms, 50ms, 50ms, 50ms, 50ms, 50ms }), 50); - EXPECT_GE(schedule_and_get_average_delays({ 10ms, 20ms, 30ms, 40ms, 50ms, 10ms, 50ms, 10ms, 50ms, 10ms }), 28); + EXPECT_GE(schedule_and_get_average_delays({10ms, 10ms, 10ms, 10ms, 10ms, 10ms, 10ms, 10ms, 10ms, 10ms}), 10); + EXPECT_GE(schedule_and_get_average_delays({50ms, 50ms, 50ms, 50ms, 50ms, 50ms, 50ms, 50ms, 50ms, 50ms}), 50); + EXPECT_GE(schedule_and_get_average_delays({10ms, 20ms, 30ms, 40ms, 50ms, 10ms, 50ms, 10ms, 50ms, 10ms}), 28); } TEST_F_S(Schedule, SchedulerInteruptAndReplacement) { - int counter_a { 0 }; - m_impl.schedule([&counter_a](auto, auto &) { counter_a++; }, { .m_sleep_durations = { 5ms } }); + int counter_a {0}; + m_impl.schedule([&counter_a](auto, auto &) { + counter_a++; + }, + {.m_sleep_durations = {5ms}}); while (counter_a < 3) { std::this_thread::sleep_for(1ms); } - int counter_a_last_value { 0 }; - int counter_b { 0 }; + int counter_a_last_value {0}; + int counter_b {0}; m_impl.schedule([&counter_a_last_value, &counter_a, &counter_b](auto, auto &) { std::this_thread::sleep_for(15ms); counter_a_last_value = counter_a; counter_b++; }, - { .m_sleep_durations = { 1ms } }); + {.m_sleep_durations = {1ms}}); while (counter_b < 3) { std::this_thread::sleep_for(1ms); @@ -129,19 +144,19 @@ TEST_F_S(Schedule, StoppedImmediately) { m_impl.schedule([&](auto, auto &stop_token) { stop_token.requestStop(); }, - { .m_sleep_durations = { 1000ms } }); + {.m_sleep_durations = {1000ms}}); EXPECT_FALSE(m_impl.isScheduled()); } TEST_F_S(Schedule, Execution, Immediate) { - const auto default_duration { 500ms }; - const auto calling_thread_id { std::this_thread::get_id() }; + const auto default_duration {500ms}; + const auto calling_thread_id {std::this_thread::get_id()}; std::optional first_call_scheduler_thread_id; std::optional second_call_scheduler_thread_id; - int first_call_delay { -1 }; - int second_call_delay { -1 }; + int first_call_delay {-1}; + int second_call_delay {-1}; auto prev = std::chrono::high_resolution_clock::now(); m_impl.schedule([&](auto, auto &stop_token) { const auto now = std::chrono::high_resolution_clock::now(); @@ -158,7 +173,7 @@ TEST_F_S(Schedule, Execution, Immediate) { second_call_scheduler_thread_id = std::this_thread::get_id(); stop_token.requestStop(); }, - { .m_sleep_durations = { default_duration * 2, default_duration }, .m_execution = display_device::SchedulerOptions::Execution::Immediate }); + {.m_sleep_durations = {default_duration * 2, default_duration}, .m_execution = display_device::SchedulerOptions::Execution::Immediate}); while (m_impl.isScheduled()) { std::this_thread::sleep_for(1ms); @@ -177,13 +192,13 @@ TEST_F_S(Schedule, Execution, Immediate) { } TEST_F_S(Schedule, Execution, ImmediateWithSleep) { - const auto default_duration { 500ms }; - const auto calling_thread_id { std::this_thread::get_id() }; + const auto default_duration {500ms}; + const auto calling_thread_id {std::this_thread::get_id()}; std::optional first_call_scheduler_thread_id; std::optional second_call_scheduler_thread_id; - int first_call_delay { -1 }; - int second_call_delay { -1 }; + int first_call_delay {-1}; + int second_call_delay {-1}; auto prev = std::chrono::high_resolution_clock::now(); m_impl.schedule([&](auto, auto &stop_token) { const auto now = std::chrono::high_resolution_clock::now(); @@ -200,7 +215,7 @@ TEST_F_S(Schedule, Execution, ImmediateWithSleep) { second_call_scheduler_thread_id = std::this_thread::get_id(); stop_token.requestStop(); }, - { .m_sleep_durations = { default_duration * 2, default_duration }, .m_execution = display_device::SchedulerOptions::Execution::ImmediateWithSleep }); + {.m_sleep_durations = {default_duration * 2, default_duration}, .m_execution = display_device::SchedulerOptions::Execution::ImmediateWithSleep}); while (m_impl.isScheduled()) { std::this_thread::sleep_for(1ms); @@ -219,13 +234,13 @@ TEST_F_S(Schedule, Execution, ImmediateWithSleep) { } TEST_F_S(Schedule, Execution, ScheduledOnly) { - const auto default_duration { 500ms }; - const auto calling_thread_id { std::this_thread::get_id() }; + const auto default_duration {500ms}; + const auto calling_thread_id {std::this_thread::get_id()}; std::optional first_call_scheduler_thread_id; std::optional second_call_scheduler_thread_id; - int first_call_delay { -1 }; - int second_call_delay { -1 }; + int first_call_delay {-1}; + int second_call_delay {-1}; auto prev = std::chrono::high_resolution_clock::now(); m_impl.schedule([&](auto, auto &stop_token) { const auto now = std::chrono::high_resolution_clock::now(); @@ -242,7 +257,7 @@ TEST_F_S(Schedule, Execution, ScheduledOnly) { second_call_scheduler_thread_id = std::this_thread::get_id(); stop_token.requestStop(); }, - { .m_sleep_durations = { default_duration * 2, default_duration }, .m_execution = display_device::SchedulerOptions::Execution::ScheduledOnly }); + {.m_sleep_durations = {default_duration * 2, default_duration}, .m_execution = display_device::SchedulerOptions::Execution::ScheduledOnly}); while (m_impl.isScheduled()) { std::this_thread::sleep_for(1ms); @@ -261,10 +276,13 @@ TEST_F_S(Schedule, Execution, ScheduledOnly) { } TEST_F_S(Schedule, ExceptionThrown, DuringImmediateCall) { - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; - int counter_a { 0 }; - m_impl.schedule([&](auto, auto &) { counter_a++; }, { .m_sleep_durations = { 1ms } }); + int counter_a {0}; + m_impl.schedule([&](auto, auto &) { + counter_a++; + }, + {.m_sleep_durations = {1ms}}); while (counter_a < 3) { std::this_thread::sleep_for(1ms); } @@ -278,13 +296,16 @@ TEST_F_S(Schedule, ExceptionThrown, DuringImmediateCall) { m_impl.schedule([&](auto, auto &) { throw std::runtime_error("Get rekt!"); }, - { .m_sleep_durations = { 1ms } }); + {.m_sleep_durations = {1ms}}); EXPECT_FALSE(m_impl.isScheduled()); EXPECT_EQ(output, "Exception thrown in the RetryScheduler::schedule. Stopping scheduler. Error:\nGet rekt!"); // Verify that scheduler still works - int counter_b { 0 }; - m_impl.schedule([&](auto, auto &) { counter_b++; }, { .m_sleep_durations = { 1ms } }); + int counter_b {0}; + m_impl.schedule([&](auto, auto &) { + counter_b++; + }, + {.m_sleep_durations = {1ms}}); while (counter_b < 3) { std::this_thread::sleep_for(1ms); } @@ -294,14 +315,14 @@ TEST_F_S(Schedule, ExceptionThrown, DuringImmediateCall) { } TEST_F_S(Schedule, ExceptionThrown, DuringScheduledCall) { - auto &logger { display_device::Logger::get() }; + auto &logger {display_device::Logger::get()}; std::string output; logger.setCustomCallback([&output](auto, const std::string &value) { output = value; }); - bool first_call { true }; + bool first_call {true}; EXPECT_EQ(output, ""); m_impl.schedule([&](auto, auto &) { if (!first_call) { @@ -309,7 +330,7 @@ TEST_F_S(Schedule, ExceptionThrown, DuringScheduledCall) { } first_call = false; }, - { .m_sleep_durations = { 1ms } }); + {.m_sleep_durations = {1ms}}); while (m_impl.isScheduled()) { std::this_thread::sleep_for(1ms); @@ -317,8 +338,11 @@ TEST_F_S(Schedule, ExceptionThrown, DuringScheduledCall) { EXPECT_EQ(output, "Exception thrown in the RetryScheduler thread. Stopping scheduler. Error:\nGet rekt!"); // Verify that scheduler still works - int counter { 0 }; - m_impl.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + int counter {0}; + m_impl.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } @@ -328,25 +352,34 @@ TEST_F_S(Schedule, ExceptionThrown, DuringScheduledCall) { } TEST_F_S(Execute, NonConst, NullptrCallbackProvided) { - EXPECT_THAT([this]() { auto &non_const_impl { m_impl }; non_const_impl.execute(std::function {}); }, - ThrowsMessage(HasSubstr("Empty callback function provided in RetryScheduler::execute!"))); + EXPECT_THAT([this]() { + auto &non_const_impl {m_impl}; + non_const_impl.execute(std::function {}); + }, + ThrowsMessage(HasSubstr("Empty callback function provided in RetryScheduler::execute!"))); } TEST_F_S(Execute, Const, NullptrCallbackProvided) { // Note: this test verifies that non-const method is invoked from const method. - EXPECT_THAT([this]() { auto &const_impl { m_impl }; const_impl.execute(std::function {}); }, - ThrowsMessage(HasSubstr("Empty callback function provided in RetryScheduler::execute!"))); + EXPECT_THAT([this]() { + auto &const_impl {m_impl}; + const_impl.execute(std::function {}); + }, + ThrowsMessage(HasSubstr("Empty callback function provided in RetryScheduler::execute!"))); } TEST_F_S(Execute, SchedulerNotStopped) { - int counter { 0 }; - m_impl.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + int counter {0}; + m_impl.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } - int counter_before_sleep { 0 }; - int counter_after_sleep { 0 }; + int counter_before_sleep {0}; + int counter_after_sleep {0}; m_impl.execute([&](auto, auto &) { counter_before_sleep = counter; std::this_thread::sleep_for(15ms); @@ -365,14 +398,17 @@ TEST_F_S(Execute, SchedulerNotStopped) { } TEST_F_S(Execute, SchedulerStopped) { - int counter { 0 }; - m_impl.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + int counter {0}; + m_impl.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } - int counter_before_sleep { 0 }; - int counter_after_sleep { 0 }; + int counter_before_sleep {0}; + int counter_after_sleep {0}; m_impl.execute([&](auto, auto &stop_token) { counter_before_sleep = counter; std::this_thread::sleep_for(15ms); @@ -387,11 +423,16 @@ TEST_F_S(Execute, SchedulerStopped) { TEST_F_S(Execute, SchedulerStopped, ExceptThatItWasNotRunning) { EXPECT_FALSE(m_impl.isScheduled()); - m_impl.execute([](auto, auto &stop_token) { stop_token.requestStop(); }); + m_impl.execute([](auto, auto &stop_token) { + stop_token.requestStop(); + }); EXPECT_FALSE(m_impl.isScheduled()); - int counter { 0 }; - m_impl.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + int counter {0}; + m_impl.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } @@ -401,16 +442,21 @@ TEST_F_S(Execute, SchedulerStopped, ExceptThatItWasNotRunning) { } TEST_F_S(Execute, ExceptionThrown) { - int counter { 0 }; - m_impl.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + int counter {0}; + m_impl.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } - EXPECT_THAT([&]() { m_impl.execute([](auto) { - throw std::runtime_error("Get rekt!"); - }); }, - ThrowsMessage(HasSubstr("Get rekt!"))); + EXPECT_THAT([&]() { + m_impl.execute([](auto) { + throw std::runtime_error("Get rekt!"); + }); + }, + ThrowsMessage(HasSubstr("Get rekt!"))); EXPECT_TRUE(m_impl.isScheduled()); @@ -419,17 +465,22 @@ TEST_F_S(Execute, ExceptionThrown) { } TEST_F_S(Execute, ExceptionThrown, BeforeStopToken) { - int counter { 0 }; - m_impl.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + int counter {0}; + m_impl.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } - EXPECT_THAT([&]() { m_impl.execute([](auto, auto &stop_token) { - throw std::runtime_error("Get rekt!"); - stop_token.requestStop(); - }); }, - ThrowsMessage(HasSubstr("Get rekt!"))); + EXPECT_THAT([&]() { + m_impl.execute([](auto, auto &stop_token) { + throw std::runtime_error("Get rekt!"); + stop_token.requestStop(); + }); + }, + ThrowsMessage(HasSubstr("Get rekt!"))); EXPECT_TRUE(m_impl.isScheduled()); @@ -438,36 +489,49 @@ TEST_F_S(Execute, ExceptionThrown, BeforeStopToken) { } TEST_F_S(Execute, ExceptionThrown, AfterStopToken) { - int counter { 0 }; - m_impl.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + int counter {0}; + m_impl.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } - EXPECT_THAT([&]() { m_impl.execute([](auto, auto &stop_token) { - stop_token.requestStop(); - throw std::runtime_error("Get rekt!"); - }); }, - ThrowsMessage(HasSubstr("Get rekt!"))); + EXPECT_THAT([&]() { + m_impl.execute([](auto, auto &stop_token) { + stop_token.requestStop(); + throw std::runtime_error("Get rekt!"); + }); + }, + ThrowsMessage(HasSubstr("Get rekt!"))); EXPECT_FALSE(m_impl.isScheduled()); } TEST_F_S(Execute, ConstVsNonConst, WithoutStopToken) { - const auto const_callback = [](const TestIface &iface) { iface.constMethod(); }; - const auto non_const_callback = [](TestIface &iface) { iface.nonConstMethod(); }; - const auto const_callback_auto = [](const auto &iface) { iface.constMethod(); }; - const auto non_const_callback_auto = [](auto &iface) { iface.nonConstMethod(); }; + const auto const_callback = [](const TestIface &iface) { + iface.constMethod(); + }; + const auto non_const_callback = [](TestIface &iface) { + iface.nonConstMethod(); + }; + const auto const_callback_auto = [](const auto &iface) { + iface.constMethod(); + }; + const auto non_const_callback_auto = [](auto &iface) { + iface.nonConstMethod(); + }; // Verify it compiles with non-const - auto &non_const_impl { m_impl }; + auto &non_const_impl {m_impl}; non_const_impl.execute(const_callback); non_const_impl.execute(non_const_callback); 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) - const auto &const_impl { m_impl }; + const auto &const_impl {m_impl}; const_impl.execute(const_callback); // const_impl.execute(non_const_callback); const_impl.execute(const_callback_auto); @@ -475,17 +539,41 @@ TEST_F_S(Execute, ConstVsNonConst, WithoutStopToken) { } TEST_F_S(Execute, ConstVsNonConst, WithStopToken) { - const auto const_const_callback = [](const TestIface &iface, const display_device::SchedulerStopToken &token) { iface.constMethod(); (void)token.stopRequested(); }; - const auto const_non_const_callback = [](const TestIface &iface, display_device::SchedulerStopToken &token) { iface.constMethod(); token.requestStop(); }; - const auto non_const_const_callback = [](TestIface &iface, const display_device::SchedulerStopToken &token) { iface.nonConstMethod(); (void)token.stopRequested(); }; - const auto non_const_non_const_callback = [](TestIface &iface, display_device::SchedulerStopToken &token) { iface.nonConstMethod(); token.requestStop(); }; - const auto const_const_callback_auto = [](const auto &iface, const auto &token) { iface.constMethod(); (void)token.stopRequested(); }; - const auto const_non_const_callback_auto = [](const auto &iface, auto &token) { iface.constMethod(); token.requestStop(); }; - const auto non_const_const_callback_auto = [](auto &iface, const auto &token) { iface.nonConstMethod(); (void)token.stopRequested(); }; - const auto non_const_non_const_callback_auto = [](auto &iface, auto &token) { iface.nonConstMethod(); token.requestStop(); }; + const auto const_const_callback = [](const TestIface &iface, const display_device::SchedulerStopToken &token) { + iface.constMethod(); + (void) token.stopRequested(); + }; + const auto const_non_const_callback = [](const TestIface &iface, display_device::SchedulerStopToken &token) { + iface.constMethod(); + token.requestStop(); + }; + const auto non_const_const_callback = [](TestIface &iface, const display_device::SchedulerStopToken &token) { + iface.nonConstMethod(); + (void) token.stopRequested(); + }; + const auto non_const_non_const_callback = [](TestIface &iface, display_device::SchedulerStopToken &token) { + iface.nonConstMethod(); + token.requestStop(); + }; + const auto const_const_callback_auto = [](const auto &iface, const auto &token) { + iface.constMethod(); + (void) token.stopRequested(); + }; + const auto const_non_const_callback_auto = [](const auto &iface, auto &token) { + iface.constMethod(); + token.requestStop(); + }; + const auto non_const_const_callback_auto = [](auto &iface, const auto &token) { + iface.nonConstMethod(); + (void) token.stopRequested(); + }; + const auto non_const_non_const_callback_auto = [](auto &iface, auto &token) { + iface.nonConstMethod(); + token.requestStop(); + }; // Verify it compiles with non-const - auto &non_const_impl { m_impl }; + auto &non_const_impl {m_impl}; non_const_impl.execute(const_const_callback); non_const_impl.execute(const_non_const_callback); non_const_impl.execute(non_const_const_callback); @@ -496,7 +584,7 @@ TEST_F_S(Execute, ConstVsNonConst, WithStopToken) { non_const_impl.execute(non_const_non_const_callback_auto); // Verify it compiles with const (commented out code will not compile) - const auto &const_impl { m_impl }; + 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); @@ -512,8 +600,11 @@ TEST_F_S(Stop) { m_impl.stop(); EXPECT_FALSE(m_impl.isScheduled()); - int counter { 0 }; - m_impl.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + int counter {0}; + m_impl.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } @@ -524,36 +615,41 @@ TEST_F_S(Stop) { } TEST_F_S(ThreadCleanupInDestructor) { - int counter { 0 }; + int counter {0}; { - display_device::RetryScheduler scheduler { std::make_unique() }; + display_device::RetryScheduler scheduler {std::make_unique()}; - scheduler.schedule([&](auto, auto &) { counter++; }, { .m_sleep_durations = { 1ms } }); + scheduler.schedule([&](auto, auto &) { + counter++; + }, + {.m_sleep_durations = {1ms}}); while (counter < 3) { std::this_thread::sleep_for(1ms); } } - const int counter_before_sleep { counter }; + const int counter_before_sleep {counter}; std::this_thread::sleep_for(100ms); - const int counter_after_sleep { counter }; + const int counter_after_sleep {counter}; EXPECT_EQ(counter_before_sleep, counter_after_sleep); } TEST_F_S(SchedulerStopToken, DestructorNoThrow) { EXPECT_NO_THROW({ - display_device::SchedulerStopToken token { []() {} }; + display_device::SchedulerStopToken token {[]() { + }}; token.requestStop(); }); EXPECT_NO_THROW({ - display_device::SchedulerStopToken token { []() {} }; + display_device::SchedulerStopToken token {[]() { + }}; }); EXPECT_NO_THROW({ - display_device::SchedulerStopToken token { {} }; + display_device::SchedulerStopToken token {{}}; token.requestStop(); }); EXPECT_NO_THROW({ - display_device::SchedulerStopToken token { {} }; + display_device::SchedulerStopToken token {{}}; }); } diff --git a/tests/unit/windows/test_comparison.cpp b/tests/unit/windows/test_comparison.cpp index 8e384e3..ba2cbe7 100644 --- a/tests/unit/windows/test_comparison.cpp +++ b/tests/unit/windows/test_comparison.cpp @@ -8,35 +8,30 @@ namespace { } // namespace TEST_S(DisplayMode) { - EXPECT_EQ(display_device::DisplayMode({ 1, 1 }, { 1, 1 }), display_device::DisplayMode({ 1, 1 }, { 1, 1 })); - EXPECT_NE(display_device::DisplayMode({ 1, 1 }, { 1, 1 }), display_device::DisplayMode({ 1, 0 }, { 1, 1 })); - EXPECT_NE(display_device::DisplayMode({ 1, 1 }, { 1, 1 }), display_device::DisplayMode({ 1, 1 }, { 1, 0 })); + EXPECT_EQ(display_device::DisplayMode({1, 1}, {1, 1}), display_device::DisplayMode({1, 1}, {1, 1})); + EXPECT_NE(display_device::DisplayMode({1, 1}, {1, 1}), display_device::DisplayMode({1, 0}, {1, 1})); + EXPECT_NE(display_device::DisplayMode({1, 1}, {1, 1}), display_device::DisplayMode({1, 1}, {1, 0})); } TEST_S(SingleDisplayConfigState, Initial) { using Initial = display_device::SingleDisplayConfigState::Initial; - EXPECT_EQ(Initial({ { { "1" } } }, { "1" }), Initial({ { { "1" } } }, { "1" })); - EXPECT_NE(Initial({ { { "1" } } }, { "1" }), Initial({ { { "0" } } }, { "1" })); - EXPECT_NE(Initial({ { { "1" } } }, { "1" }), Initial({ { { "1" } } }, { "0" })); + EXPECT_EQ(Initial({{{"1"}}}, {"1"}), Initial({{{"1"}}}, {"1"})); + EXPECT_NE(Initial({{{"1"}}}, {"1"}), Initial({{{"0"}}}, {"1"})); + EXPECT_NE(Initial({{{"1"}}}, {"1"}), Initial({{{"1"}}}, {"0"})); } TEST_S(SingleDisplayConfigState, Modified) { using Modified = display_device::SingleDisplayConfigState::Modified; - EXPECT_EQ(Modified({ { { "1" } } }, { { "1", {} } }, { { "1", {} } }, "1"), - Modified({ { { "1" } } }, { { "1", {} } }, { { "1", {} } }, "1")); - EXPECT_NE(Modified({ { { "1" } } }, { { "1", {} } }, { { "1", {} } }, "1"), - Modified({ { { "0" } } }, { { "1", {} } }, { { "1", {} } }, "1")); - EXPECT_NE(Modified({ { { "1" } } }, { { "1", {} } }, { { "1", {} } }, "1"), - Modified({ { { "1" } } }, { { "0", {} } }, { { "1", {} } }, "1")); - EXPECT_NE(Modified({ { { "1" } } }, { { "1", {} } }, { { "1", {} } }, "1"), - Modified({ { { "1" } } }, { { "1", {} } }, { { "0", {} } }, "1")); - EXPECT_NE(Modified({ { { "1" } } }, { { "1", {} } }, { { "1", {} } }, "1"), - Modified({ { { "1" } } }, { { "1", {} } }, { { "1", {} } }, "0")); + EXPECT_EQ(Modified({{{"1"}}}, {{"1", {}}}, {{"1", {}}}, "1"), Modified({{{"1"}}}, {{"1", {}}}, {{"1", {}}}, "1")); + EXPECT_NE(Modified({{{"1"}}}, {{"1", {}}}, {{"1", {}}}, "1"), Modified({{{"0"}}}, {{"1", {}}}, {{"1", {}}}, "1")); + EXPECT_NE(Modified({{{"1"}}}, {{"1", {}}}, {{"1", {}}}, "1"), Modified({{{"1"}}}, {{"0", {}}}, {{"1", {}}}, "1")); + EXPECT_NE(Modified({{{"1"}}}, {{"1", {}}}, {{"1", {}}}, "1"), Modified({{{"1"}}}, {{"1", {}}}, {{"0", {}}}, "1")); + EXPECT_NE(Modified({{{"1"}}}, {{"1", {}}}, {{"1", {}}}, "1"), Modified({{{"1"}}}, {{"1", {}}}, {{"1", {}}}, "0")); } TEST_S(SingleDisplayConfigState) { using SDSC = display_device::SingleDisplayConfigState; - EXPECT_EQ(SDSC({ { { "1" } } }, { { { "1" } } }), SDSC({ { { "1" } } }, { { { "1" } } })); - EXPECT_NE(SDSC({ { { "1" } } }, { { { "1" } } }), SDSC({ { { "0" } } }, { { { "1" } } })); - EXPECT_NE(SDSC({ { { "1" } } }, { { { "1" } } }), SDSC({ { { "1" } } }, { { { "0" } } })); + EXPECT_EQ(SDSC({{{"1"}}}, {{{"1"}}}), SDSC({{{"1"}}}, {{{"1"}}})); + EXPECT_NE(SDSC({{{"1"}}}, {{{"1"}}}), SDSC({{{"0"}}}, {{{"1"}}})); + EXPECT_NE(SDSC({{{"1"}}}, {{{"1"}}}), SDSC({{{"1"}}}, {{{"0"}}})); } diff --git a/tests/unit/windows/test_json_converter.cpp b/tests/unit/windows/test_json_converter.cpp index d0f5fcc..f239ac9 100644 --- a/tests/unit/windows/test_json_converter.cpp +++ b/tests/unit/windows/test_json_converter.cpp @@ -10,31 +10,29 @@ namespace { TEST_F_S(ActiveTopology) { executeTestCase(display_device::ActiveTopology {}, R"([])"); - executeTestCase(display_device::ActiveTopology { { "DeviceId1" }, { "DeviceId2", "DeviceId3" }, { "DeviceId4" } }, R"([["DeviceId1"],["DeviceId2","DeviceId3"],["DeviceId4"]])"); + executeTestCase(display_device::ActiveTopology {{"DeviceId1"}, {"DeviceId2", "DeviceId3"}, {"DeviceId4"}}, R"([["DeviceId1"],["DeviceId2","DeviceId3"],["DeviceId4"]])"); } TEST_F_S(DeviceDisplayModeMap) { executeTestCase(display_device::DeviceDisplayModeMap {}, R"({})"); - executeTestCase(display_device::DeviceDisplayModeMap { { "DeviceId1", {} }, { "DeviceId2", { { 1920, 1080 }, { 120, 1 } } } }, - R"({"DeviceId1":{"refresh_rate":{"denominator":0,"numerator":0},"resolution":{"height":0,"width":0}},"DeviceId2":{"refresh_rate":{"denominator":1,"numerator":120},"resolution":{"height":1080,"width":1920}}})"); + executeTestCase(display_device::DeviceDisplayModeMap {{"DeviceId1", {}}, {"DeviceId2", {{1920, 1080}, {120, 1}}}}, R"({"DeviceId1":{"refresh_rate":{"denominator":0,"numerator":0},"resolution":{"height":0,"width":0}},"DeviceId2":{"refresh_rate":{"denominator":1,"numerator":120},"resolution":{"height":1080,"width":1920}}})"); } TEST_F_S(HdrStateMap) { executeTestCase(display_device::HdrStateMap {}, R"({})"); - executeTestCase(display_device::HdrStateMap { { "DeviceId1", std::nullopt }, { "DeviceId2", display_device::HdrState::Enabled } }, - R"({"DeviceId1":null,"DeviceId2":"Enabled"})"); + executeTestCase(display_device::HdrStateMap {{"DeviceId1", std::nullopt}, {"DeviceId2", display_device::HdrState::Enabled}}, R"({"DeviceId1":null,"DeviceId2":"Enabled"})"); } TEST_F_S(SingleDisplayConfigState) { const display_device::SingleDisplayConfigState valid_input { - { { { "DeviceId1" } }, - { "DeviceId1" } }, - { display_device::SingleDisplayConfigState::Modified { - { { "DeviceId2" } }, - { { "DeviceId2", { { 1920, 1080 }, { 120, 1 } } } }, - { { "DeviceId2", { display_device::HdrState::Disabled } } }, - { "DeviceId2" }, - } } + {{{"DeviceId1"}}, + {"DeviceId1"}}, + {display_device::SingleDisplayConfigState::Modified { + {{"DeviceId2"}}, + {{"DeviceId2", {{1920, 1080}, {120, 1}}}}, + {{"DeviceId2", {display_device::HdrState::Disabled}}}, + {"DeviceId2"}, + }} }; executeTestCase(display_device::SingleDisplayConfigState {}, R"({"initial":{"primary_devices":[],"topology":[]},"modified":{"original_hdr_states":{},"original_modes":{},"original_primary_device":"","topology":[]}})"); @@ -43,7 +41,7 @@ TEST_F_S(SingleDisplayConfigState) { TEST_F_S(WinWorkarounds) { display_device::WinWorkarounds input { - std::chrono::milliseconds { 500 } + std::chrono::milliseconds {500} }; executeTestCase(display_device::WinWorkarounds {}, R"({"hdr_blank_delay":null})"); diff --git a/tests/unit/windows/test_persistent_state.cpp b/tests/unit/windows/test_persistent_state.cpp index 1d00665..0b0faed 100644 --- a/tests/unit/windows/test_persistent_state.cpp +++ b/tests/unit/windows/test_persistent_state.cpp @@ -16,8 +16,7 @@ namespace { // Test fixture(s) for this file class PersistentStateMocked: public BaseTest { public: - display_device::PersistentState & - getImpl(bool throw_on_load_error = false) { + display_device::PersistentState &getImpl(bool throw_on_load_error = false) { if (!m_impl) { m_impl = std::make_unique(m_settings_persistence_api, throw_on_load_error); } @@ -25,7 +24,7 @@ namespace { return *m_impl; } - std::shared_ptr> m_settings_persistence_api { std::make_shared>() }; + std::shared_ptr> m_settings_persistence_api {std::make_shared>()}; private: std::unique_ptr m_impl; @@ -42,7 +41,7 @@ TEST_F_S_MOCKED(NoopSettingsPersistence) { using PersistentState::PersistentState; }; - const NakedPersistentState persistent_state { nullptr }; + const NakedPersistentState persistent_state {nullptr}; EXPECT_TRUE(std::dynamic_pointer_cast(persistent_state.m_settings_persistence_api) != nullptr); } @@ -51,7 +50,10 @@ TEST_F_S_MOCKED(FailedToLoadPersitence) { .Times(1) .WillOnce(Return(serializeState(ut_consts::SDCS_NULL))); - EXPECT_THAT([this]() { getImpl(true); }, ThrowsMessage(HasSubstr("Failed to load persistent settings!"))); + EXPECT_THAT([this]() { + getImpl(true); + }, + ThrowsMessage(HasSubstr("Failed to load persistent settings!"))); } TEST_F_S_MOCKED(FailedToLoadPersitence, ThrowIsSuppressed) { @@ -63,21 +65,23 @@ TEST_F_S_MOCKED(FailedToLoadPersitence, ThrowIsSuppressed) { } TEST_F_S_MOCKED(InvalidPersitenceData) { - const std::string data_string { "SOMETHING" }; - const std::vector data { std::begin(data_string), std::end(data_string) }; + const std::string data_string {"SOMETHING"}; + const std::vector data {std::begin(data_string), std::end(data_string)}; EXPECT_CALL(*m_settings_persistence_api, load()) .Times(1) .WillOnce(Return(data)); - EXPECT_THAT([this]() { getImpl(true); }, - ThrowsMessage(HasSubstr("Failed to parse persistent settings! Error:\n" - "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'S'"))); + EXPECT_THAT([this]() { + getImpl(true); + }, + ThrowsMessage(HasSubstr("Failed to parse persistent settings! Error:\n" + "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'S'"))); } TEST_F_S_MOCKED(InvalidPersitenceData, ThrowIsSuppressed) { - const std::string data_string { "SOMETHING" }; - const std::vector data { std::begin(data_string), std::end(data_string) }; + const std::string data_string {"SOMETHING"}; + const std::vector data {std::begin(data_string), std::end(data_string)}; EXPECT_CALL(*m_settings_persistence_api, load()) .Times(1) diff --git a/tests/unit/windows/test_settings_manager_apply.cpp b/tests/unit/windows/test_settings_manager_apply.cpp index 982ffe1..554835d 100644 --- a/tests/unit/windows/test_settings_manager_apply.cpp +++ b/tests/unit/windows/test_settings_manager_apply.cpp @@ -16,48 +16,45 @@ namespace { using ::testing::StrictMock; // Additional convenience global const(s) - const display_device::ActiveTopology DEFAULT_CURRENT_TOPOLOGY { { "DeviceId1", "DeviceId2" }, { "DeviceId3" } }; + const display_device::ActiveTopology DEFAULT_CURRENT_TOPOLOGY {{"DeviceId1", "DeviceId2"}, {"DeviceId3"}}; const display_device::EnumeratedDeviceList DEFAULT_DEVICES { - { .m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } }, - { .m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } }, - { .m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info { .m_primary = false } }, - { .m_device_id = "DeviceId4" } + {.m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}, + {.m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}, + {.m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info {.m_primary = false}}, + {.m_device_id = "DeviceId4"} }; const display_device::EnumeratedDeviceList DEVICES_WITH_NO_PRIMARY { - { .m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info { .m_primary = false } }, - { .m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info { .m_primary = false } }, - { .m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info { .m_primary = false } }, - { .m_device_id = "DeviceId4" } + {.m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info {.m_primary = false}}, + {.m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info {.m_primary = false}}, + {.m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info {.m_primary = false}}, + {.m_device_id = "DeviceId4"} }; const display_device::DeviceDisplayModeMap DEFAULT_CURRENT_MODES { - { "DeviceId1", { { 1080, 720 }, { 120, 1 } } }, - { "DeviceId2", { { 1920, 1080 }, { 60, 1 } } }, - { "DeviceId3", { { 2560, 1440 }, { 30, 1 } } } + {"DeviceId1", {{1080, 720}, {120, 1}}}, + {"DeviceId2", {{1920, 1080}, {60, 1}}}, + {"DeviceId3", {{2560, 1440}, {30, 1}}} }; const display_device::HdrStateMap DEFAULT_CURRENT_HDR_STATES { - { "DeviceId1", display_device::HdrState::Disabled }, - { "DeviceId2", display_device::HdrState::Disabled }, - { "DeviceId3", std::nullopt } + {"DeviceId1", display_device::HdrState::Disabled}, + {"DeviceId2", display_device::HdrState::Disabled}, + {"DeviceId3", std::nullopt} }; - const display_device::SingleDisplayConfigState DEFAULT_PERSISTENCE_INPUT_BASE { { DEFAULT_CURRENT_TOPOLOGY, { "DeviceId1", "DeviceId2" } } }; + const display_device::SingleDisplayConfigState DEFAULT_PERSISTENCE_INPUT_BASE {{DEFAULT_CURRENT_TOPOLOGY, {"DeviceId1", "DeviceId2"}}}; // Test fixture(s) for this file class SettingsManagerApplyMocked: public BaseTest { public: - display_device::SettingsManager & - getImpl() { + display_device::SettingsManager &getImpl() { if (!m_impl) { - m_impl = std::make_unique(m_dd_api, m_audio_context_api, std::make_unique(m_settings_persistence_api), - display_device::WinWorkarounds { - .m_hdr_blank_delay = std::chrono::milliseconds { 123 } // Value is irrelevant for the tests - }); + m_impl = std::make_unique(m_dd_api, m_audio_context_api, std::make_unique(m_settings_persistence_api), display_device::WinWorkarounds { + .m_hdr_blank_delay = std::chrono::milliseconds {123} // Value is irrelevant for the tests + }); } return *m_impl; } - void - expectedDefaultCallsUntilTopologyPrep(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::ActiveTopology &topology = DEFAULT_CURRENT_TOPOLOGY, const std::optional &state = ut_consts::SDCS_EMPTY) { + void expectedDefaultCallsUntilTopologyPrep(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::ActiveTopology &topology = DEFAULT_CURRENT_TOPOLOGY, const std::optional &state = ut_consts::SDCS_EMPTY) { EXPECT_CALL(*m_settings_persistence_api, load()) .Times(1) .WillOnce(Return(serializeState(state))) @@ -76,71 +73,62 @@ namespace { .RetiresOnSaturation(); } - void - expectedIsCapturedCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const bool is_captured) { + void expectedIsCapturedCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const bool is_captured) { EXPECT_CALL(*m_audio_context_api, isCaptured()) .Times(1) .WillOnce(Return(is_captured)) .RetiresOnSaturation(); } - void - expectedCaptureCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const bool success = true) { + void expectedCaptureCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const bool success = true) { EXPECT_CALL(*m_audio_context_api, capture()) .Times(1) .WillOnce(Return(success)) .RetiresOnSaturation(); } - void - expectedReleaseCall(InSequence &sequence /* To ensure that sequence is created outside this scope */) { + void expectedReleaseCall(InSequence &sequence /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_audio_context_api, release()) .Times(1) .RetiresOnSaturation(); } - void - expectedTopologyGuardTopologyCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::ActiveTopology &topology = DEFAULT_CURRENT_TOPOLOGY, const bool success = true) { + void expectedTopologyGuardTopologyCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::ActiveTopology &topology = DEFAULT_CURRENT_TOPOLOGY, const bool success = true) { EXPECT_CALL(*m_dd_api, setTopology(topology)) .Times(1) .WillOnce(Return(success)) .RetiresOnSaturation(); } - void - expectedDeviceEnumCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::EnumeratedDeviceList &devices = DEFAULT_DEVICES) { + void expectedDeviceEnumCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::EnumeratedDeviceList &devices = DEFAULT_DEVICES) { EXPECT_CALL(*m_dd_api, enumAvailableDevices()) .Times(1) .WillOnce(Return(devices)) .RetiresOnSaturation(); } - void - expectedIsTopologyTheSameCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::ActiveTopology &lhs, const display_device::ActiveTopology &rhs) { + void expectedIsTopologyTheSameCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::ActiveTopology &lhs, const display_device::ActiveTopology &rhs) { EXPECT_CALL(*m_dd_api, isTopologyTheSame(lhs, rhs)) .Times(1) .WillOnce(Return(lhs == rhs)) .RetiresOnSaturation(); } - void - expectedSetTopologyCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::ActiveTopology &topology) { + void expectedSetTopologyCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::ActiveTopology &topology) { EXPECT_CALL(*m_dd_api, setTopology(topology)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedPersistenceCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &state, const bool success = true) { + void expectedPersistenceCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &state, const bool success = true) { EXPECT_CALL(*m_settings_persistence_api, store(*serializeState(state))) .Times(1) .WillOnce(Return(success)) .RetiresOnSaturation(); } - void - expectedTopologyGuardNewlyCapturedContextCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const bool is_captured) { + void expectedTopologyGuardNewlyCapturedContextCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const bool is_captured) { EXPECT_CALL(*m_audio_context_api, isCaptured()) .Times(1) .WillOnce(Return(is_captured)) @@ -153,80 +141,70 @@ namespace { } } - void - expectedIsPrimaryCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::string &device_id, const bool success = true) { + void expectedIsPrimaryCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::string &device_id, const bool success = true) { EXPECT_CALL(*m_dd_api, isPrimary(device_id)) .Times(1) .WillOnce(Return(success)) .RetiresOnSaturation(); } - void - expectedSetAsPrimaryCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::string &device_id, const bool success = true) { + void expectedSetAsPrimaryCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::string &device_id, const bool success = true) { EXPECT_CALL(*m_dd_api, setAsPrimary(device_id)) .Times(1) .WillOnce(Return(success)) .RetiresOnSaturation(); } - void - expectedPrimaryGuardCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::string &device_id) { + void expectedPrimaryGuardCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::string &device_id) { EXPECT_CALL(*m_dd_api, setAsPrimary(device_id)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedSetDisplayModesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::DeviceDisplayModeMap &modes, const bool success = true) { + void expectedSetDisplayModesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::DeviceDisplayModeMap &modes, const bool success = true) { EXPECT_CALL(*m_dd_api, setDisplayModes(modes)) .Times(1) .WillOnce(Return(success)) .RetiresOnSaturation(); } - void - expectedGetCurrentDisplayModesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::set &devices, const display_device::DeviceDisplayModeMap &modes) { + void expectedGetCurrentDisplayModesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::set &devices, const display_device::DeviceDisplayModeMap &modes) { EXPECT_CALL(*m_dd_api, getCurrentDisplayModes(devices)) .Times(1) .WillOnce(Return(modes)) .RetiresOnSaturation(); } - void - expectedSetDisplayModesGuardCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::DeviceDisplayModeMap &modes) { + void expectedSetDisplayModesGuardCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::DeviceDisplayModeMap &modes) { EXPECT_CALL(*m_dd_api, setDisplayModes(modes)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedSetHdrStatesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::HdrStateMap &states, const bool success = true) { + void expectedSetHdrStatesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::HdrStateMap &states, const bool success = true) { EXPECT_CALL(*m_dd_api, setHdrStates(states)) .Times(1) .WillOnce(Return(success)) .RetiresOnSaturation(); } - void - expectedGetCurrentHdrStatesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::set &devices, const display_device::HdrStateMap &states) { + void expectedGetCurrentHdrStatesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::set &devices, const display_device::HdrStateMap &states) { EXPECT_CALL(*m_dd_api, getCurrentHdrStates(devices)) .Times(1) .WillOnce(Return(states)) .RetiresOnSaturation(); } - void - expectedSetHdrStatesGuardCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::HdrStateMap &states) { + void expectedSetHdrStatesGuardCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const display_device::HdrStateMap &states) { EXPECT_CALL(*m_dd_api, setHdrStates(states)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedHdrWorkaroundCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */) { + void expectedHdrWorkaroundCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */) { // Using the "failure" path, to keep it simple EXPECT_CALL(*m_dd_api, getCurrentTopology()) .Times(1) @@ -238,9 +216,9 @@ namespace { .RetiresOnSaturation(); } - std::shared_ptr> m_dd_api { std::make_shared>() }; - std::shared_ptr> m_settings_persistence_api { std::make_shared>() }; - std::shared_ptr> m_audio_context_api { std::make_shared>() }; + std::shared_ptr> m_dd_api {std::make_shared>()}; + std::shared_ptr> m_settings_persistence_api {std::make_shared>()}; + std::shared_ptr> m_audio_context_api {std::make_shared>()}; private: std::unique_ptr m_impl; @@ -304,7 +282,7 @@ TEST_F_S_MOCKED(PrepareTopology, DeviceNotAvailable) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceIdX" }), display_device::SettingsManager::ApplyResult::DevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceIdX"}), display_device::SettingsManager::ApplyResult::DevicePrepFailed); } TEST_F_S_MOCKED(PrepareTopology, FailedToComputeInitialState) { @@ -316,19 +294,19 @@ TEST_F_S_MOCKED(PrepareTopology, FailedToComputeInitialState) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::DevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::DevicePrepFailed); } TEST_F_S_MOCKED(PrepareTopology, FailedToStripInitialState) { InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); expectedIsCapturedCall(sequence, false); - expectedDeviceEnumCall(sequence, { { .m_device_id = "DeviceId4", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } } }); + expectedDeviceEnumCall(sequence, {{.m_device_id = "DeviceId4", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}}); expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4" }), display_device::SettingsManager::ApplyResult::DevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4"}), display_device::SettingsManager::ApplyResult::DevicePrepFailed); } TEST_F_S_MOCKED(PrepareTopology, DeviceNotFoundInNewTopology) { @@ -341,12 +319,12 @@ TEST_F_S_MOCKED(PrepareTopology, DeviceNotFoundInNewTopology) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4" }), display_device::SettingsManager::ApplyResult::DevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4"}), display_device::SettingsManager::ApplyResult::DevicePrepFailed); } TEST_F_S_MOCKED(PrepareTopology, NoChangeIsNeeded) { - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified = { DEFAULT_CURRENT_TOPOLOGY }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified = {DEFAULT_CURRENT_TOPOLOGY}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); @@ -355,7 +333,7 @@ TEST_F_S_MOCKED(PrepareTopology, NoChangeIsNeeded) { expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, DEFAULT_CURRENT_TOPOLOGY); expectedPersistenceCall(sequence, persistence_input); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareTopology, RevertingSettingsFailed) { @@ -365,8 +343,8 @@ TEST_F_S_MOCKED(PrepareTopology, RevertingSettingsFailed) { expectedDefaultCallsUntilTopologyPrep(sequence, DEFAULT_CURRENT_TOPOLOGY, ut_consts::SDCS_FULL); expectedIsCapturedCall(sequence, false); expectedDeviceEnumCall(sequence); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, {{"DeviceId1"}}); EXPECT_CALL(*m_dd_api, isTopologyValid(ut_consts::SDCS_FULL->m_modified.m_topology)) .Times(1) .WillOnce(Return(false)) @@ -375,7 +353,7 @@ TEST_F_S_MOCKED(PrepareTopology, RevertingSettingsFailed) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay }), display_device::SettingsManager::ApplyResult::DevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay}), display_device::SettingsManager::ApplyResult::DevicePrepFailed); } TEST_F_S_MOCKED(PrepareTopology, AudioContextCaptureFailed) { @@ -385,7 +363,7 @@ TEST_F_S_MOCKED(PrepareTopology, AudioContextCaptureFailed) { expectedDefaultCallsUntilTopologyPrep(sequence); expectedIsCapturedCall(sequence, false); expectedDeviceEnumCall(sequence); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); expectedIsCapturedCall(sequence, false); expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, DEFAULT_CURRENT_TOPOLOGY); expectedCaptureCall(sequence, false); @@ -393,7 +371,7 @@ TEST_F_S_MOCKED(PrepareTopology, AudioContextCaptureFailed) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay }), display_device::SettingsManager::ApplyResult::DevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay}), display_device::SettingsManager::ApplyResult::DevicePrepFailed); } TEST_F_S_MOCKED(PrepareTopology, TopologyChangeFailed) { @@ -403,11 +381,11 @@ TEST_F_S_MOCKED(PrepareTopology, TopologyChangeFailed) { expectedDefaultCallsUntilTopologyPrep(sequence); expectedIsCapturedCall(sequence, false); expectedDeviceEnumCall(sequence); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); expectedIsCapturedCall(sequence, false); expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, DEFAULT_CURRENT_TOPOLOGY); expectedCaptureCall(sequence, true); - EXPECT_CALL(*m_dd_api, setTopology(display_device::ActiveTopology { { "DeviceId1" } })) + EXPECT_CALL(*m_dd_api, setTopology(display_device::ActiveTopology {{"DeviceId1"}})) .Times(1) .WillOnce(Return(false)) .RetiresOnSaturation(); @@ -416,56 +394,56 @@ TEST_F_S_MOCKED(PrepareTopology, TopologyChangeFailed) { expectedTopologyGuardNewlyCapturedContextCall(sequence, true); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay }), display_device::SettingsManager::ApplyResult::DevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay}), display_device::SettingsManager::ApplyResult::DevicePrepFailed); } TEST_F_S_MOCKED(PrepareTopology, AudioContextCaptured) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified = { { { "DeviceId1" } } }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified = {{{"DeviceId1"}}}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); expectedIsCapturedCall(sequence, false); expectedDeviceEnumCall(sequence); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); expectedIsCapturedCall(sequence, false); expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, DEFAULT_CURRENT_TOPOLOGY); expectedCaptureCall(sequence, true); - expectedSetTopologyCall(sequence, { { "DeviceId1" } }); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); + expectedSetTopologyCall(sequence, {{"DeviceId1"}}); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareTopology, AudioContextCaptureSkipped, NotInitialTopologySwitch) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { *ut_consts::SDCS_NO_MODIFICATIONS }; - persistence_input.m_modified = { { { "DeviceId1" } } }; + auto persistence_input {*ut_consts::SDCS_NO_MODIFICATIONS}; + persistence_input.m_modified = {{{"DeviceId1"}}}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence, DEFAULT_CURRENT_TOPOLOGY, ut_consts::SDCS_NO_MODIFICATIONS); expectedIsCapturedCall(sequence, false); expectedDeviceEnumCall(sequence); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, {{"DeviceId1"}}); expectedIsCapturedCall(sequence, false); expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, DEFAULT_CURRENT_TOPOLOGY); - expectedSetTopologyCall(sequence, { { "DeviceId1" } }); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, { { "DeviceId1" } }); + expectedSetTopologyCall(sequence, {{"DeviceId1"}}); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, {{"DeviceId1"}}); expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareTopology, AudioContextCaptureSkipped, NoDevicesAreGone) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified = { { { "DeviceId1", "DeviceId2" }, { "DeviceId3" }, { "DeviceId4" } } }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified = {{{"DeviceId1", "DeviceId2"}, {"DeviceId3"}, {"DeviceId4"}}}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); @@ -479,12 +457,12 @@ TEST_F_S_MOCKED(PrepareTopology, AudioContextCaptureSkipped, NoDevicesAreGone) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsureActive }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsureActive}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PreparePrimaryDevice, FailedToGetPrimaryDevice) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - const display_device::ActiveTopology topology { { "DeviceId1", "DeviceId2" }, { "DeviceId3" }, { "DeviceId4" } }; + const display_device::ActiveTopology topology {{"DeviceId1", "DeviceId2"}, {"DeviceId3"}, {"DeviceId4"}}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); @@ -505,12 +483,12 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, FailedToGetPrimaryDevice) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary }), display_device::SettingsManager::ApplyResult::PrimaryDevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary}), display_device::SettingsManager::ApplyResult::PrimaryDevicePrepFailed); } TEST_F_S_MOCKED(PreparePrimaryDevice, FailedToSetPrimaryDevice) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - const display_device::ActiveTopology topology { { "DeviceId1", "DeviceId2" }, { "DeviceId3" }, { "DeviceId4" } }; + const display_device::ActiveTopology topology {{"DeviceId1", "DeviceId2"}, {"DeviceId3"}, {"DeviceId4"}}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); @@ -529,13 +507,13 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, FailedToSetPrimaryDevice) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary }), display_device::SettingsManager::ApplyResult::PrimaryDevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary}), display_device::SettingsManager::ApplyResult::PrimaryDevicePrepFailed); } TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceSet) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified.m_topology = { { "DeviceId1", "DeviceId2" }, { "DeviceId3" }, { "DeviceId4" } }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified.m_topology = {{"DeviceId1", "DeviceId2"}, {"DeviceId3"}, {"DeviceId4"}}; persistence_input.m_modified.m_original_primary_device = "DeviceId1"; InSequence sequence; @@ -553,13 +531,13 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceSet) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceSet, CachedDeviceReused) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; - initial_state.m_modified.m_topology = { { "DeviceId1", "DeviceId2" }, { "DeviceId3" }, { "DeviceId4" } }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; + initial_state.m_modified.m_topology = {{"DeviceId1", "DeviceId2"}, {"DeviceId3"}, {"DeviceId4"}}; initial_state.m_modified.m_original_primary_device = "DeviceId1"; InSequence sequence; @@ -574,13 +552,13 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceSet, CachedDeviceReused) { expectedSetAsPrimaryCall(sequence, "DeviceId4"); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceSet, GuardInvoked) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified.m_topology = { { "DeviceId1", "DeviceId2" }, { "DeviceId3" }, { "DeviceId4" } }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified.m_topology = {{"DeviceId1", "DeviceId2"}, {"DeviceId3"}, {"DeviceId4"}}; persistence_input.m_modified.m_original_primary_device = "DeviceId1"; InSequence sequence; @@ -602,13 +580,13 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceSet, GuardInvoked) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceSetSkipped) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified.m_topology = { { "DeviceId1", "DeviceId2" }, { "DeviceId3" }, { "DeviceId4" } }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified.m_topology = {{"DeviceId1", "DeviceId2"}, {"DeviceId3"}, {"DeviceId4"}}; persistence_input.m_modified.m_original_primary_device = "DeviceId4"; InSequence sequence; @@ -631,12 +609,12 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceSetSkipped) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId4", .m_device_prep = DevicePrep::EnsurePrimary}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PreparePrimaryDevice, FailedToRestorePrimaryDevice) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto intial_state { ut_consts::SDCS_NO_MODIFICATIONS }; + auto intial_state {ut_consts::SDCS_NO_MODIFICATIONS}; intial_state->m_modified.m_original_primary_device = "DeviceId1"; InSequence sequence; @@ -653,15 +631,15 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, FailedToRestorePrimaryDevice) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId3", .m_device_prep = DevicePrep::EnsureActive }), display_device::SettingsManager::ApplyResult::PrimaryDevicePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId3", .m_device_prep = DevicePrep::EnsureActive}), display_device::SettingsManager::ApplyResult::PrimaryDevicePrepFailed); } TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceRestored) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto intial_state { ut_consts::SDCS_NO_MODIFICATIONS }; + auto intial_state {ut_consts::SDCS_NO_MODIFICATIONS}; intial_state->m_modified.m_original_primary_device = "DeviceId1"; - auto persistence_input { intial_state }; + auto persistence_input {intial_state}; persistence_input->m_modified.m_original_primary_device = ""; InSequence sequence; @@ -676,15 +654,15 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceRestored) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId3", .m_device_prep = DevicePrep::EnsureActive }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId3", .m_device_prep = DevicePrep::EnsureActive}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceRestored, PersistenceFailed) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto intial_state { ut_consts::SDCS_NO_MODIFICATIONS }; + auto intial_state {ut_consts::SDCS_NO_MODIFICATIONS}; intial_state->m_modified.m_original_primary_device = "DeviceId1"; - auto persistence_input { intial_state }; + auto persistence_input {intial_state}; persistence_input->m_modified.m_original_primary_device = ""; InSequence sequence; @@ -703,15 +681,15 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceRestored, PersistenceFailed) expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId3", .m_device_prep = DevicePrep::EnsureActive }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId3", .m_device_prep = DevicePrep::EnsureActive}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceRestoreSkipped, PersistenceFailed) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto intial_state { ut_consts::SDCS_NO_MODIFICATIONS }; + auto intial_state {ut_consts::SDCS_NO_MODIFICATIONS}; intial_state->m_modified.m_original_primary_device = "DeviceId1"; - auto persistence_input { intial_state }; + auto persistence_input {intial_state}; persistence_input->m_modified.m_original_primary_device = ""; InSequence sequence; @@ -726,7 +704,7 @@ TEST_F_S_MOCKED(PreparePrimaryDevice, PrimaryDeviceRestoreSkipped, PersistenceFa expectedTopologyGuardTopologyCall(sequence, intial_state->m_modified.m_topology); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId3", .m_device_prep = DevicePrep::EnsureActive }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId3", .m_device_prep = DevicePrep::EnsureActive}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PrepareDisplayModes, FailedToGetDisplayModes) { @@ -741,12 +719,12 @@ TEST_F_S_MOCKED(PrepareDisplayModes, FailedToGetDisplayModes) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_resolution = { { 1920, 1080 } } }), display_device::SettingsManager::ApplyResult::DisplayModePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_resolution = {{1920, 1080}}}), display_device::SettingsManager::ApplyResult::DisplayModePrepFailed); } TEST_F_S_MOCKED(PrepareDisplayModes, FailedToSetDisplayModes) { - auto new_modes { DEFAULT_CURRENT_MODES }; - new_modes["DeviceId1"].m_resolution = { 1920, 1080 }; + auto new_modes {DEFAULT_CURRENT_MODES}; + new_modes["DeviceId1"].m_resolution = {1920, 1080}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); @@ -761,14 +739,14 @@ TEST_F_S_MOCKED(PrepareDisplayModes, FailedToSetDisplayModes) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_resolution = { { 1920, 1080 } } }), display_device::SettingsManager::ApplyResult::DisplayModePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_resolution = {{1920, 1080}}}), display_device::SettingsManager::ApplyResult::DisplayModePrepFailed); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, ResolutionOnly) { - auto new_modes { DEFAULT_CURRENT_MODES }; - new_modes["DeviceId1"].m_resolution = { 1920, 1080 }; + auto new_modes {DEFAULT_CURRENT_MODES}; + new_modes["DeviceId1"].m_resolution = {1920, 1080}; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; @@ -784,14 +762,14 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, ResolutionOnly) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_resolution = { { 1920, 1080 } } }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_resolution = {{1920, 1080}}}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, RefreshRateOnly) { - auto new_modes { DEFAULT_CURRENT_MODES }; - new_modes["DeviceId1"].m_refresh_rate = { 308500, 10000 }; + auto new_modes {DEFAULT_CURRENT_MODES}; + new_modes["DeviceId1"].m_refresh_rate = {308500, 10000}; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; @@ -807,15 +785,15 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, RefreshRateOnly) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_refresh_rate = { { 30.85 } } }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_refresh_rate = {{30.85}}}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, ResolutionAndRefreshRate) { - auto new_modes { DEFAULT_CURRENT_MODES }; - new_modes["DeviceId1"].m_resolution = { 1920, 1080 }; - new_modes["DeviceId1"].m_refresh_rate = { 308500, 10000 }; + auto new_modes {DEFAULT_CURRENT_MODES}; + new_modes["DeviceId1"].m_resolution = {1920, 1080}; + new_modes["DeviceId1"].m_refresh_rate = {308500, 10000}; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; @@ -831,17 +809,17 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, ResolutionAndRefreshRate) expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_resolution = { { 1920, 1080 } }, .m_refresh_rate = { { 30.85 } } }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_resolution = {{1920, 1080}}, .m_refresh_rate = {{30.85}}}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, ResolutionAndRefreshRate, PrimaryDeviceSpecified) { - auto new_modes { DEFAULT_CURRENT_MODES }; - new_modes["DeviceId1"].m_resolution = { 1920, 1080 }; - new_modes["DeviceId1"].m_refresh_rate = { 308500, 10000 }; - new_modes["DeviceId2"].m_resolution = { 1920, 1080 }; - new_modes["DeviceId2"].m_refresh_rate = { 308500, 10000 }; + auto new_modes {DEFAULT_CURRENT_MODES}; + new_modes["DeviceId1"].m_resolution = {1920, 1080}; + new_modes["DeviceId1"].m_refresh_rate = {308500, 10000}; + new_modes["DeviceId2"].m_resolution = {1920, 1080}; + new_modes["DeviceId2"].m_refresh_rate = {308500, 10000}; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; @@ -857,14 +835,14 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, ResolutionAndRefreshRate, expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_resolution = { { 1920, 1080 } }, .m_refresh_rate = { { 30.85 } } }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_resolution = {{1920, 1080}}, .m_refresh_rate = {{30.85}}}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, CachedModesReused) { - auto new_modes { DEFAULT_CURRENT_MODES }; - new_modes["DeviceId1"].m_resolution = { 1920, 1080 }; + auto new_modes {DEFAULT_CURRENT_MODES}; + new_modes["DeviceId1"].m_resolution = {1920, 1080}; - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; @@ -879,14 +857,14 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, CachedModesReused) { expectedGetCurrentDisplayModesCall(sequence, display_device::win_utils::flattenTopology(DEFAULT_CURRENT_TOPOLOGY), new_modes); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_resolution = { { 1920, 1080 } } }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_resolution = {{1920, 1080}}}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, GuardInvoked) { - auto new_modes { DEFAULT_CURRENT_MODES }; - new_modes["DeviceId1"].m_resolution = { 1920, 1080 }; + auto new_modes {DEFAULT_CURRENT_MODES}; + new_modes["DeviceId1"].m_resolution = {1920, 1080}; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; @@ -906,14 +884,14 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, GuardInvoked) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_resolution = { { 1920, 1080 } } }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_resolution = {{1920, 1080}}}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, GuardNotInvoked) { - auto new_modes { DEFAULT_CURRENT_MODES }; - new_modes["DeviceId1"].m_resolution = { 1920, 1080 }; + auto new_modes {DEFAULT_CURRENT_MODES}; + new_modes["DeviceId1"].m_resolution = {1920, 1080}; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; @@ -931,11 +909,11 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSet, GuardNotInvoked) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_resolution = { { 1920, 1080 } } }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_resolution = {{1920, 1080}}}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSetSkipped) { - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; @@ -948,14 +926,14 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesSetSkipped) { expectedGetCurrentDisplayModesCall(sequence, display_device::win_utils::flattenTopology(DEFAULT_CURRENT_TOPOLOGY), DEFAULT_CURRENT_MODES); expectedPersistenceCall(sequence, persistence_input); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId3", .m_resolution = { { 2560, 1440 } } }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId3", .m_resolution = {{2560, 1440}}}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareDisplayModes, FailedToRestoreDisplayModes) { - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; - initial_state.m_modified.m_original_modes["DeviceId1"].m_resolution = { 1920, 1080 }; + initial_state.m_modified.m_original_modes["DeviceId1"].m_resolution = {1920, 1080}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence, DEFAULT_CURRENT_TOPOLOGY, initial_state); @@ -970,16 +948,16 @@ TEST_F_S_MOCKED(PrepareDisplayModes, FailedToRestoreDisplayModes) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::DisplayModePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::DisplayModePrepFailed); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesRestored) { - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; - initial_state.m_modified.m_original_modes["DeviceId1"].m_resolution = { 1920, 1080 }; + initial_state.m_modified.m_original_modes["DeviceId1"].m_resolution = {1920, 1080}; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; InSequence sequence; @@ -994,16 +972,16 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesRestored) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesRestored, PersistenceFailed) { - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; - initial_state.m_modified.m_original_modes["DeviceId1"].m_resolution = { 1920, 1080 }; + initial_state.m_modified.m_original_modes["DeviceId1"].m_resolution = {1920, 1080}; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; InSequence sequence; @@ -1022,15 +1000,15 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesRestored, PersistenceFailed) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesRestoreSkipped, PersistenceFailed) { - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_modes = DEFAULT_CURRENT_MODES; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; InSequence sequence; @@ -1045,7 +1023,7 @@ TEST_F_S_MOCKED(PrepareDisplayModes, DisplayModesRestoreSkipped, PersistenceFail expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PrepareHdrStates, FailedToGetHdrStates) { @@ -1060,11 +1038,11 @@ TEST_F_S_MOCKED(PrepareHdrStates, FailedToGetHdrStates) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled }), display_device::SettingsManager::ApplyResult::HdrStatePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled}), display_device::SettingsManager::ApplyResult::HdrStatePrepFailed); } TEST_F_S_MOCKED(PrepareHdrStates, FailedToSetHdrStates) { - auto new_states { DEFAULT_CURRENT_HDR_STATES }; + auto new_states {DEFAULT_CURRENT_HDR_STATES}; new_states["DeviceId1"] = display_device::HdrState::Enabled; InSequence sequence; @@ -1080,14 +1058,14 @@ TEST_F_S_MOCKED(PrepareHdrStates, FailedToSetHdrStates) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled }), display_device::SettingsManager::ApplyResult::HdrStatePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled}), display_device::SettingsManager::ApplyResult::HdrStatePrepFailed); } TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSet) { - auto new_states { DEFAULT_CURRENT_HDR_STATES }; + auto new_states {DEFAULT_CURRENT_HDR_STATES}; new_states["DeviceId1"] = display_device::HdrState::Enabled; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; @@ -1102,15 +1080,15 @@ TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSet) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSet, PrimaryDeviceSpecified) { - auto new_states { DEFAULT_CURRENT_HDR_STATES }; + auto new_states {DEFAULT_CURRENT_HDR_STATES}; new_states["DeviceId1"] = display_device::HdrState::Enabled; new_states["DeviceId2"] = display_device::HdrState::Enabled; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; @@ -1125,14 +1103,14 @@ TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSet, PrimaryDeviceSpecified) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_hdr_state = display_device::HdrState::Enabled }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_hdr_state = display_device::HdrState::Enabled}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSet, CachedModesReused) { - auto new_states { DEFAULT_CURRENT_HDR_STATES }; + auto new_states {DEFAULT_CURRENT_HDR_STATES}; new_states["DeviceId1"] = display_device::HdrState::Enabled; - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; @@ -1146,14 +1124,14 @@ TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSet, CachedModesReused) { expectedSetHdrStatesCall(sequence, new_states); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSet, GuardInvoked) { - auto new_states { DEFAULT_CURRENT_HDR_STATES }; + auto new_states {DEFAULT_CURRENT_HDR_STATES}; new_states["DeviceId1"] = display_device::HdrState::Enabled; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; @@ -1172,11 +1150,11 @@ TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSet, GuardInvoked) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_hdr_state = display_device::HdrState::Enabled}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSetSkipped) { - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; persistence_input.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; @@ -1189,11 +1167,11 @@ TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesSetSkipped) { expectedGetCurrentHdrStatesCall(sequence, display_device::win_utils::flattenTopology(DEFAULT_CURRENT_TOPOLOGY), DEFAULT_CURRENT_HDR_STATES); expectedPersistenceCall(sequence, persistence_input); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId3", .m_hdr_state = display_device::HdrState::Enabled }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId3", .m_hdr_state = display_device::HdrState::Enabled}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareHdrStates, FailedToRestoreHdrStates) { - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; initial_state.m_modified.m_original_hdr_states["DeviceId1"] = display_device::HdrState::Enabled; @@ -1211,16 +1189,16 @@ TEST_F_S_MOCKED(PrepareHdrStates, FailedToRestoreHdrStates) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::HdrStatePrepFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::HdrStatePrepFailed); } TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesRestored) { - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; initial_state.m_modified.m_original_hdr_states["DeviceId1"] = display_device::HdrState::Enabled; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; InSequence sequence; @@ -1234,16 +1212,16 @@ TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesRestored) { expectedPersistenceCall(sequence, persistence_input); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesRestored, PersistenceFailed) { - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; initial_state.m_modified.m_original_hdr_states["DeviceId1"] = display_device::HdrState::Enabled; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; InSequence sequence; @@ -1261,15 +1239,15 @@ TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesRestored, PersistenceFailed) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesRestoreSkipped, PersistenceFailed) { - auto initial_state { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto initial_state {DEFAULT_PERSISTENCE_INPUT_BASE}; initial_state.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; initial_state.m_modified.m_original_hdr_states = DEFAULT_CURRENT_HDR_STATES; - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; persistence_input.m_modified.m_topology = DEFAULT_CURRENT_TOPOLOGY; InSequence sequence; @@ -1284,34 +1262,34 @@ TEST_F_S_MOCKED(PrepareHdrStates, HdrStatesRestoreSkipped, PersistenceFailed) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(AudioContextDelayedRelease) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { *ut_consts::SDCS_NO_MODIFICATIONS }; - persistence_input.m_modified = { { { "DeviceId1" } } }; + auto persistence_input {*ut_consts::SDCS_NO_MODIFICATIONS}; + persistence_input.m_modified = {{{"DeviceId1"}}}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence, DEFAULT_CURRENT_TOPOLOGY, ut_consts::SDCS_NO_MODIFICATIONS); expectedIsCapturedCall(sequence, false); expectedDeviceEnumCall(sequence); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, {{"DeviceId1"}}); expectedIsCapturedCall(sequence, true); expectedSetTopologyCall(sequence, persistence_input.m_initial.m_topology); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, {{"DeviceId1"}}); expectedPersistenceCall(sequence, persistence_input); expectedReleaseCall(sequence); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay }), display_device::SettingsManager::ApplyResult::Ok); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay}), display_device::SettingsManager::ApplyResult::Ok); } TEST_F_S_MOCKED(FailedToSaveNewState) { - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified = { DEFAULT_CURRENT_TOPOLOGY }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified = {DEFAULT_CURRENT_TOPOLOGY}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); @@ -1323,24 +1301,24 @@ TEST_F_S_MOCKED(FailedToSaveNewState) { expectedTopologyGuardTopologyCall(sequence); expectedTopologyGuardNewlyCapturedContextCall(sequence, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(AudioContextDelayedRelease, ViaGuard) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { *ut_consts::SDCS_NO_MODIFICATIONS }; - persistence_input.m_modified = { { { "DeviceId1" } } }; + auto persistence_input {*ut_consts::SDCS_NO_MODIFICATIONS}; + persistence_input.m_modified = {{{"DeviceId1"}}}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence, DEFAULT_CURRENT_TOPOLOGY, ut_consts::SDCS_NO_MODIFICATIONS); expectedIsCapturedCall(sequence, false); expectedDeviceEnumCall(sequence); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, {{"DeviceId1"}}); expectedIsCapturedCall(sequence, true); expectedSetTopologyCall(sequence, persistence_input.m_initial.m_topology); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, {{"DeviceId1"}}); expectedPersistenceCall(sequence, persistence_input, false); @@ -1349,24 +1327,24 @@ TEST_F_S_MOCKED(AudioContextDelayedRelease, ViaGuard) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(AudioContextDelayedRelease, SkippedDueToFailure) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - auto persistence_input { *ut_consts::SDCS_NO_MODIFICATIONS }; - persistence_input.m_modified = { { { "DeviceId1" } } }; + auto persistence_input {*ut_consts::SDCS_NO_MODIFICATIONS}; + persistence_input.m_modified = {{{"DeviceId1"}}}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence, DEFAULT_CURRENT_TOPOLOGY, ut_consts::SDCS_NO_MODIFICATIONS); expectedIsCapturedCall(sequence, false); expectedDeviceEnumCall(sequence); - expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, { { "DeviceId1" } }); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, DEFAULT_CURRENT_TOPOLOGY, {{"DeviceId1"}}); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_modified.m_topology, {{"DeviceId1"}}); expectedIsCapturedCall(sequence, true); expectedSetTopologyCall(sequence, persistence_input.m_initial.m_topology); - expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, { { "DeviceId1" } }); + expectedIsTopologyTheSameCall(sequence, ut_consts::SDCS_FULL->m_initial.m_topology, {{"DeviceId1"}}); expectedPersistenceCall(sequence, persistence_input, false); @@ -1374,12 +1352,12 @@ TEST_F_S_MOCKED(AudioContextDelayedRelease, SkippedDueToFailure) { expectedTopologyGuardNewlyCapturedContextCall(sequence, false); expectedHdrWorkaroundCalls(sequence); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1", .m_device_prep = DevicePrep::EnsureOnlyDisplay}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(TopologyGuardFailedButNoContextIsReleased) { - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified = { DEFAULT_CURRENT_TOPOLOGY }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified = {DEFAULT_CURRENT_TOPOLOGY}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); @@ -1390,12 +1368,12 @@ TEST_F_S_MOCKED(TopologyGuardFailedButNoContextIsReleased) { expectedTopologyGuardTopologyCall(sequence, DEFAULT_CURRENT_TOPOLOGY, false); - EXPECT_EQ(getImpl().applySettings({ .m_device_id = "DeviceId1" }), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); + EXPECT_EQ(getImpl().applySettings({.m_device_id = "DeviceId1"}), display_device::SettingsManager::ApplyResult::PersistenceSaveFailed); } TEST_F_S_MOCKED(PrepareTopology, PrimaryDeviceIsUsed) { - auto persistence_input { DEFAULT_PERSISTENCE_INPUT_BASE }; - persistence_input.m_modified = { DEFAULT_CURRENT_TOPOLOGY }; + auto persistence_input {DEFAULT_PERSISTENCE_INPUT_BASE}; + persistence_input.m_modified = {DEFAULT_CURRENT_TOPOLOGY}; InSequence sequence; expectedDefaultCallsUntilTopologyPrep(sequence); diff --git a/tests/unit/windows/test_settings_manager_general.cpp b/tests/unit/windows/test_settings_manager_general.cpp index a9e7ac5..30dbef3 100644 --- a/tests/unit/windows/test_settings_manager_general.cpp +++ b/tests/unit/windows/test_settings_manager_general.cpp @@ -20,8 +20,7 @@ namespace { // Test fixture(s) for this file class SettingsManagerGeneralMocked: public BaseTest { public: - display_device::SettingsManager & - getImpl() { + display_device::SettingsManager &getImpl() { if (!m_impl) { m_impl = std::make_unique(m_dd_api, m_audio_context_api, std::make_unique(m_settings_persistence_api), display_device::WinWorkarounds {}); } @@ -29,9 +28,9 @@ namespace { return *m_impl; } - std::shared_ptr> m_dd_api { std::make_shared>() }; - std::shared_ptr> m_settings_persistence_api { std::make_shared>() }; - std::shared_ptr> m_audio_context_api { std::make_shared>() }; + std::shared_ptr> m_dd_api {std::make_shared>()}; + std::shared_ptr> m_settings_persistence_api {std::make_shared>()}; + std::shared_ptr> m_audio_context_api {std::make_shared>()}; private: std::unique_ptr m_impl; @@ -42,8 +41,10 @@ namespace { } // namespace TEST_F_S_MOCKED(NullptrDisplayDeviceApiProvided) { - EXPECT_THAT([]() { const display_device::SettingsManager settings_manager(nullptr, nullptr, nullptr, {}); }, - ThrowsMessage(HasSubstr("Nullptr provided for WinDisplayDeviceInterface in SettingsManager!"))); + EXPECT_THAT([]() { + const display_device::SettingsManager settings_manager(nullptr, nullptr, nullptr, {}); + }, + ThrowsMessage(HasSubstr("Nullptr provided for WinDisplayDeviceInterface in SettingsManager!"))); } TEST_F_S_MOCKED(NoopAudioContext) { @@ -53,21 +54,23 @@ TEST_F_S_MOCKED(NoopAudioContext) { using SettingsManager::SettingsManager; }; - const NakedSettingsManager settings_manager { m_dd_api, nullptr, std::make_unique(nullptr), {} }; + const NakedSettingsManager settings_manager {m_dd_api, nullptr, std::make_unique(nullptr), {}}; EXPECT_TRUE(std::dynamic_pointer_cast(settings_manager.m_audio_context_api) != nullptr); } TEST_F_S_MOCKED(NullptrPersistentStateProvided) { - EXPECT_THAT([this]() { const display_device::SettingsManager settings_manager(m_dd_api, nullptr, nullptr, {}); }, - ThrowsMessage(HasSubstr("Nullptr provided for PersistentState in SettingsManager!"))); + EXPECT_THAT([this]() { + const display_device::SettingsManager settings_manager(m_dd_api, nullptr, nullptr, {}); + }, + ThrowsMessage(HasSubstr("Nullptr provided for PersistentState in SettingsManager!"))); } TEST_F_S_MOCKED(EnumAvailableDevices) { const display_device::EnumeratedDeviceList test_list { - { "DeviceId1", - "", - "FriendlyName1", - std::nullopt } + {"DeviceId1", + "", + "FriendlyName1", + std::nullopt} }; EXPECT_CALL(*m_settings_persistence_api, load()) diff --git a/tests/unit/windows/test_settings_manager_revert.cpp b/tests/unit/windows/test_settings_manager_revert.cpp index 862f311..855e570 100644 --- a/tests/unit/windows/test_settings_manager_revert.cpp +++ b/tests/unit/windows/test_settings_manager_revert.cpp @@ -17,44 +17,41 @@ namespace { using ::testing::StrictMock; // Additional convenience global const(s) - const display_device::ActiveTopology CURRENT_TOPOLOGY { { "DeviceId4" } }; + const display_device::ActiveTopology CURRENT_TOPOLOGY {{"DeviceId4"}}; const display_device::HdrStateMap CURRENT_MODIFIED_HDR_STATES { - { "DeviceId1", { display_device::HdrState::Enabled } }, - { "DeviceId3", std::nullopt } + {"DeviceId1", {display_device::HdrState::Enabled}}, + {"DeviceId3", std::nullopt} }; const display_device::DeviceDisplayModeMap CURRENT_MODIFIED_DISPLAY_MODES { - { "DeviceId1", { { 123, 456 }, { 120, 1 } } }, - { "DeviceId3", { { 456, 123 }, { 60, 1 } } } + {"DeviceId1", {{123, 456}, {120, 1}}}, + {"DeviceId3", {{456, 123}, {60, 1}}} }; - const std::string CURRENT_MODIFIED_PRIMARY_DEVICE { "DeviceId3" }; + const std::string CURRENT_MODIFIED_PRIMARY_DEVICE {"DeviceId3"}; const display_device::EnumeratedDeviceList CURRENT_DEVICES { - { .m_device_id = "DeviceId1" }, - { .m_device_id = "DeviceId3" }, - { .m_device_id = "DeviceId4" } + {.m_device_id = "DeviceId1"}, + {.m_device_id = "DeviceId3"}, + {.m_device_id = "DeviceId4"} }; const display_device::ActiveTopology FULL_EXTENDED_TOPOLOGY { - { "DeviceId1" }, - { "DeviceId3" }, - { "DeviceId4" } + {"DeviceId1"}, + {"DeviceId3"}, + {"DeviceId4"} }; // Test fixture(s) for this file class SettingsManagerRevertMocked: public BaseTest { public: - display_device::SettingsManager & - getImpl() { + display_device::SettingsManager &getImpl() { if (!m_impl) { - m_impl = std::make_unique(m_dd_api, m_audio_context_api, std::make_unique(m_settings_persistence_api), - display_device::WinWorkarounds { - .m_hdr_blank_delay = std::chrono::milliseconds { 123 } // Value is irrelevant for the tests - }); + m_impl = std::make_unique(m_dd_api, m_audio_context_api, std::make_unique(m_settings_persistence_api), display_device::WinWorkarounds { + .m_hdr_blank_delay = std::chrono::milliseconds {123} // Value is irrelevant for the tests + }); } return *m_impl; } - void - expectedDefaultCallsUntilModifiedSettings(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &state = ut_consts::SDCS_FULL) { + void expectedDefaultCallsUntilModifiedSettings(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &state = ut_consts::SDCS_FULL) { EXPECT_CALL(*m_settings_persistence_api, load()) .Times(1) .WillOnce(Return(serializeState(state))) @@ -62,8 +59,7 @@ namespace { expectedDefaultCallsUntilModifiedSettingsNoPersistence(sequence); } - void - expectedDefaultCallsUntilModifiedSettingsNoPersistence(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultCallsUntilModifiedSettingsNoPersistence(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, isApiAccessAvailable()) .Times(1) .WillOnce(Return(true)) @@ -78,8 +74,7 @@ namespace { .RetiresOnSaturation(); } - void - expectedDefaultMofifiedTopologyCalls(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultMofifiedTopologyCalls(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, isTopologyValid(ut_consts::SDCS_FULL->m_modified.m_topology)) .Times(1) .WillOnce(Return(true)) @@ -94,40 +89,35 @@ namespace { .RetiresOnSaturation(); } - void - expectedDefaultHdrStateGuardInitCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultHdrStateGuardInitCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, getCurrentHdrStates(display_device::win_utils::flattenTopology(ut_consts::SDCS_FULL->m_modified.m_topology))) .Times(1) .WillOnce(Return(CURRENT_MODIFIED_HDR_STATES)) .RetiresOnSaturation(); } - void - expectedDefaultHdrStateGuardCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultHdrStateGuardCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, setHdrStates(CURRENT_MODIFIED_HDR_STATES)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedDefaultDisplayModeGuardInitCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultDisplayModeGuardInitCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, getCurrentDisplayModes(display_device::win_utils::flattenTopology(ut_consts::SDCS_FULL->m_modified.m_topology))) .Times(1) .WillOnce(Return(CURRENT_MODIFIED_DISPLAY_MODES)) .RetiresOnSaturation(); } - void - expectedDefaultDisplayModeGuardCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultDisplayModeGuardCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, setDisplayModes(CURRENT_MODIFIED_DISPLAY_MODES)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedDefaultPrimaryDeviceGuardInitCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultPrimaryDeviceGuardInitCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, isPrimary("DeviceId1")) .Times(1) .WillOnce(Return(false)) @@ -138,24 +128,21 @@ namespace { .RetiresOnSaturation(); } - void - expectedDefaultPrimaryDeviceGuardCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultPrimaryDeviceGuardCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, setAsPrimary(CURRENT_MODIFIED_PRIMARY_DEVICE)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedDefaultHdrStateCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultHdrStateCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, setHdrStates(ut_consts::SDCS_FULL->m_modified.m_original_hdr_states)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedDefaultDisplayModeCall(InSequence & /* To ensure that sequence is created outside this scope */, bool has_changed = true) { + void expectedDefaultDisplayModeCall(InSequence & /* To ensure that sequence is created outside this scope */, bool has_changed = true) { EXPECT_CALL(*m_dd_api, setDisplayModes(ut_consts::SDCS_FULL->m_modified.m_original_modes)) .Times(1) .WillOnce(Return(true)) @@ -166,18 +153,16 @@ namespace { .RetiresOnSaturation(); } - void - expectedDefaultPrimaryDeviceCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultPrimaryDeviceCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, setAsPrimary(ut_consts::SDCS_FULL->m_modified.m_original_primary_device)) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedDefaultRevertModifiedSettingsCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &state = ut_consts::SDCS_FULL) { - auto expected_persistent_input { state }; - expected_persistent_input->m_modified = { expected_persistent_input->m_modified.m_topology }; + void expectedDefaultRevertModifiedSettingsCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &state = ut_consts::SDCS_FULL) { + auto expected_persistent_input {state}; + expected_persistent_input->m_modified = {expected_persistent_input->m_modified.m_topology}; expectedDefaultMofifiedTopologyCalls(sequence); expectedDefaultHdrStateGuardInitCall(sequence); @@ -192,8 +177,7 @@ namespace { .RetiresOnSaturation(); } - void - expectedDefaultInitialTopologyCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &state = ut_consts::SDCS_FULL) { + void expectedDefaultInitialTopologyCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &state = ut_consts::SDCS_FULL) { EXPECT_CALL(*m_dd_api, isTopologyValid(state->m_initial.m_topology)) .Times(1) .WillOnce(Return(true)) @@ -208,16 +192,14 @@ namespace { .RetiresOnSaturation(); } - void - expectedDefaultFinalPersistenceCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */) { + void expectedDefaultFinalPersistenceCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_settings_persistence_api, clear()) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); } - void - expectedDefaultAudioContextCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */, const bool audio_captured) { + void expectedDefaultAudioContextCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */, const bool audio_captured) { EXPECT_CALL(*m_audio_context_api, isCaptured()) .Times(1) .WillOnce(Return(audio_captured)) @@ -230,8 +212,7 @@ namespace { } } - void - expectedDefaultTopologyGuardCall(InSequence & /* To ensure that sequence is created outside this scope */) { + void expectedDefaultTopologyGuardCall(InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_dd_api, enumAvailableDevices()) .Times(1) .WillOnce(Return(CURRENT_DEVICES)) @@ -250,8 +231,7 @@ namespace { .RetiresOnSaturation(); } - void - expectedHdrWorkaroundCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */) { + void expectedHdrWorkaroundCalls(InSequence &sequence /* To ensure that sequence is created outside this scope */) { // Using the "failure" path, to keep it simple EXPECT_CALL(*m_dd_api, getCurrentTopology()) .Times(1) @@ -263,9 +243,9 @@ namespace { .RetiresOnSaturation(); } - std::shared_ptr> m_dd_api { std::make_shared>() }; - std::shared_ptr> m_settings_persistence_api { std::make_shared>() }; - std::shared_ptr> m_audio_context_api { std::make_shared>() }; + std::shared_ptr> m_dd_api {std::make_shared>()}; + std::shared_ptr> m_settings_persistence_api {std::make_shared>()}; + std::shared_ptr> m_audio_context_api {std::make_shared>()}; private: std::unique_ptr m_impl; @@ -347,7 +327,7 @@ TEST_F_S_MOCKED(RevertModifiedSettings, FailedToSetModifiedTopology) { } TEST_F_S_MOCKED(RevertModifiedSettings, FailedToRevertHdrStates) { - auto sdcs_stripped { ut_consts::SDCS_FULL }; + auto sdcs_stripped {ut_consts::SDCS_FULL}; sdcs_stripped->m_modified.m_original_modes.clear(); sdcs_stripped->m_modified.m_original_primary_device.clear(); @@ -367,7 +347,7 @@ TEST_F_S_MOCKED(RevertModifiedSettings, FailedToRevertHdrStates) { } TEST_F_S_MOCKED(RevertModifiedSettings, FailedToRevertDisplayModes) { - auto sdcs_stripped { ut_consts::SDCS_FULL }; + auto sdcs_stripped {ut_consts::SDCS_FULL}; sdcs_stripped->m_modified.m_original_hdr_states.clear(); sdcs_stripped->m_modified.m_original_primary_device.clear(); @@ -387,12 +367,12 @@ TEST_F_S_MOCKED(RevertModifiedSettings, FailedToRevertDisplayModes) { } TEST_F_S_MOCKED(RevertModifiedSettings, RevertedDisplayModes, PersistenceFailed, GuardNotInvoked) { - auto sdcs_stripped { ut_consts::SDCS_FULL }; + auto sdcs_stripped {ut_consts::SDCS_FULL}; sdcs_stripped->m_modified.m_original_hdr_states.clear(); sdcs_stripped->m_modified.m_original_primary_device.clear(); - auto expected_persistent_input { ut_consts::SDCS_FULL }; - expected_persistent_input->m_modified = { expected_persistent_input->m_modified.m_topology }; + auto expected_persistent_input {ut_consts::SDCS_FULL}; + expected_persistent_input->m_modified = {expected_persistent_input->m_modified.m_topology}; InSequence sequence; expectedDefaultCallsUntilModifiedSettings(sequence, sdcs_stripped); @@ -411,7 +391,7 @@ TEST_F_S_MOCKED(RevertModifiedSettings, RevertedDisplayModes, PersistenceFailed, } TEST_F_S_MOCKED(RevertModifiedSettings, FailedToRevertPrimaryDevice) { - auto sdcs_stripped { ut_consts::SDCS_FULL }; + auto sdcs_stripped {ut_consts::SDCS_FULL}; sdcs_stripped->m_modified.m_original_hdr_states.clear(); sdcs_stripped->m_modified.m_original_modes.clear(); @@ -431,8 +411,8 @@ TEST_F_S_MOCKED(RevertModifiedSettings, FailedToRevertPrimaryDevice) { } TEST_F_S_MOCKED(RevertModifiedSettings, FailedToSetPersistence) { - auto expected_persistent_input { ut_consts::SDCS_FULL }; - expected_persistent_input->m_modified = { expected_persistent_input->m_modified.m_topology }; + auto expected_persistent_input {ut_consts::SDCS_FULL}; + expected_persistent_input->m_modified = {expected_persistent_input->m_modified.m_topology}; InSequence sequence; expectedDefaultCallsUntilModifiedSettings(sequence); @@ -614,7 +594,7 @@ TEST_F_S_MOCKED(SuccesfullyReverted, NoAudioCapture) { } TEST_F_S_MOCKED(SuccesfullyReverted, TopologySetToBackToInitialSinceItWasChangedToModified) { - auto initial_state { ut_consts::SDCS_FULL }; + auto initial_state {ut_consts::SDCS_FULL}; initial_state->m_initial.m_topology = CURRENT_TOPOLOGY; InSequence sequence; @@ -653,12 +633,12 @@ TEST_F_S_MOCKED(RevertModifiedSettings, CachedSettingsAreUpdated) { TEST_F_S_MOCKED(CurrentSettingsMatchPersistentOnes) { display_device::SingleDisplayConfigState state { - { CURRENT_TOPOLOGY, - { "DeviceId4" } }, - { CURRENT_TOPOLOGY, - CURRENT_MODIFIED_DISPLAY_MODES, - CURRENT_MODIFIED_HDR_STATES, - "DeviceId4" } + {CURRENT_TOPOLOGY, + {"DeviceId4"}}, + {CURRENT_TOPOLOGY, + CURRENT_MODIFIED_DISPLAY_MODES, + CURRENT_MODIFIED_HDR_STATES, + "DeviceId4"} }; InSequence sequence; @@ -669,8 +649,8 @@ TEST_F_S_MOCKED(CurrentSettingsMatchPersistentOnes) { EXPECT_CALL(*m_dd_api, getCurrentDisplayModes(display_device::win_utils::flattenTopology(state.m_modified.m_topology))).Times(1).WillOnce(Return(CURRENT_MODIFIED_DISPLAY_MODES)).RetiresOnSaturation(); EXPECT_CALL(*m_dd_api, isPrimary(state.m_modified.m_original_primary_device)).Times(1).WillOnce(Return(true)).RetiresOnSaturation(); - auto cleared_modifications { state }; - cleared_modifications.m_modified = { cleared_modifications.m_modified.m_topology }; + auto cleared_modifications {state}; + cleared_modifications.m_modified = {cleared_modifications.m_modified.m_topology}; EXPECT_CALL(*m_settings_persistence_api, store(*serializeState(cleared_modifications))).Times(1).WillOnce(Return(true)).RetiresOnSaturation(); EXPECT_CALL(*m_dd_api, isTopologyValid(state.m_initial.m_topology)).Times(1).WillOnce(Return(true)).RetiresOnSaturation(); EXPECT_CALL(*m_dd_api, isTopologyTheSame(CURRENT_TOPOLOGY, state.m_initial.m_topology)).Times(1).WillOnce(Return(true)).RetiresOnSaturation(); diff --git a/tests/unit/windows/test_settings_utils.cpp b/tests/unit/windows/test_settings_utils.cpp index 792f355..055acab 100644 --- a/tests/unit/windows/test_settings_utils.cpp +++ b/tests/unit/windows/test_settings_utils.cpp @@ -21,22 +21,22 @@ namespace { #define TEST_F_S_MOCKED(...) DD_MAKE_TEST(TEST_F, SettingsUtilsMocked, __VA_ARGS__) // Additional convenience global const(s) - const display_device::ActiveTopology DEFAULT_INITIAL_TOPOLOGY { { "DeviceId1", "DeviceId2" }, { "DeviceId3" } }; + const display_device::ActiveTopology DEFAULT_INITIAL_TOPOLOGY {{"DeviceId1", "DeviceId2"}, {"DeviceId3"}}; const display_device::DeviceDisplayModeMap DEFAULT_CURRENT_MODES { - { "DeviceId1", { { 1080, 720 }, { 120, 1 } } }, - { "DeviceId2", { { 1920, 1080 }, { 60, 1 } } }, - { "DeviceId3", { { 2560, 1440 }, { 30, 1 } } } + {"DeviceId1", {{1080, 720}, {120, 1}}}, + {"DeviceId2", {{1920, 1080}, {60, 1}}}, + {"DeviceId3", {{2560, 1440}, {30, 1}}} }; const display_device::HdrStateMap DEFAULT_CURRENT_HDR_STATES { - { "DeviceId1", { display_device::HdrState::Disabled } }, - { "DeviceId2", { display_device::HdrState::Disabled } }, - { "DeviceId3", std::nullopt } + {"DeviceId1", {display_device::HdrState::Disabled}}, + {"DeviceId2", {display_device::HdrState::Disabled}}, + {"DeviceId3", std::nullopt} }; } // namespace TEST_F_S_MOCKED(FlattenTopology) { - EXPECT_EQ(display_device::win_utils::flattenTopology({ { "DeviceId1" }, { "DeviceId2", "DeviceId3" }, {}, { "DeviceId2" } }), (std::set { "DeviceId1", "DeviceId2", "DeviceId3" })); - EXPECT_EQ(display_device::win_utils::flattenTopology({ {}, {}, {} }), std::set {}); + EXPECT_EQ(display_device::win_utils::flattenTopology({{"DeviceId1"}, {"DeviceId2", "DeviceId3"}, {}, {"DeviceId2"}}), (std::set {"DeviceId1", "DeviceId2", "DeviceId3"})); + EXPECT_EQ(display_device::win_utils::flattenTopology({{}, {}, {}}), std::set {}); EXPECT_EQ(display_device::win_utils::flattenTopology({}), std::set {}); } @@ -49,11 +49,11 @@ TEST_F_S_MOCKED(CreateFullExtendedTopology, NoDevicesAreAvailable) { } TEST_F_S_MOCKED(CreateFullExtendedTopology, TopologyCreated) { - const display_device::ActiveTopology expected_topology { { "DeviceId1" }, { "DeviceId2" }, { "DeviceId3" } }; + const display_device::ActiveTopology expected_topology {{"DeviceId1"}, {"DeviceId2"}, {"DeviceId3"}}; const display_device::EnumeratedDeviceList devices { - { .m_device_id = "DeviceId1" }, - { .m_device_id = "DeviceId2" }, - { .m_device_id = "DeviceId3" } + {.m_device_id = "DeviceId1"}, + {.m_device_id = "DeviceId2"}, + {.m_device_id = "DeviceId3"} }; EXPECT_CALL(m_dd_api, enumAvailableDevices()).Times(1).WillOnce(Return(devices)); @@ -61,184 +61,177 @@ TEST_F_S_MOCKED(CreateFullExtendedTopology, TopologyCreated) { } TEST_F_S_MOCKED(ComputeInitialState, PreviousStateIsUsed) { - const display_device::SingleDisplayConfigState::Initial prev_state { DEFAULT_INITIAL_TOPOLOGY }; + const display_device::SingleDisplayConfigState::Initial prev_state {DEFAULT_INITIAL_TOPOLOGY}; EXPECT_EQ(display_device::win_utils::computeInitialState(prev_state, {}, {}), std::make_optional(prev_state)); } TEST_F_S_MOCKED(ComputeInitialState, NewStateIsComputed) { - const display_device::ActiveTopology topology_before_changes { DEFAULT_INITIAL_TOPOLOGY }; + const display_device::ActiveTopology topology_before_changes {DEFAULT_INITIAL_TOPOLOGY}; const display_device::EnumeratedDeviceList devices { - { .m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } }, - { .m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } }, - { .m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info { .m_primary = false } }, - { .m_device_id = "DeviceId4" } + {.m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}, + {.m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}, + {.m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info {.m_primary = false}}, + {.m_device_id = "DeviceId4"} }; - EXPECT_EQ(display_device::win_utils::computeInitialState(std::nullopt, topology_before_changes, devices), - (display_device::SingleDisplayConfigState::Initial { topology_before_changes, { "DeviceId1", "DeviceId2" } })); + EXPECT_EQ(display_device::win_utils::computeInitialState(std::nullopt, topology_before_changes, devices), (display_device::SingleDisplayConfigState::Initial {topology_before_changes, {"DeviceId1", "DeviceId2"}})); } TEST_F_S_MOCKED(ComputeInitialState, NoPrimaryDevices) { - EXPECT_EQ(display_device::win_utils::computeInitialState(std::nullopt, { { "DeviceId1", "DeviceId2" } }, {}), std::nullopt); + EXPECT_EQ(display_device::win_utils::computeInitialState(std::nullopt, {{"DeviceId1", "DeviceId2"}}, {}), std::nullopt); } TEST_F_S_MOCKED(ComputeNewTopology, VerifyOnly) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::VerifyOnly, false, "DeviceId4", { "DeviceId5", "DeviceId6" }, DEFAULT_INITIAL_TOPOLOGY), DEFAULT_INITIAL_TOPOLOGY); + EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::VerifyOnly, false, "DeviceId4", {"DeviceId5", "DeviceId6"}, DEFAULT_INITIAL_TOPOLOGY), DEFAULT_INITIAL_TOPOLOGY); } TEST_F_S_MOCKED(ComputeNewTopology, EnsureOnlyDisplay) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsureOnlyDisplay, true, "DeviceId4", { "DeviceId5", "DeviceId6" }, DEFAULT_INITIAL_TOPOLOGY), - (display_device::ActiveTopology { { "DeviceId4", "DeviceId5", "DeviceId6" } })); - EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsureOnlyDisplay, false, "DeviceId4", { "DeviceId5", "DeviceId6" }, DEFAULT_INITIAL_TOPOLOGY), - display_device::ActiveTopology { { "DeviceId4" } }); + EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsureOnlyDisplay, true, "DeviceId4", {"DeviceId5", "DeviceId6"}, DEFAULT_INITIAL_TOPOLOGY), (display_device::ActiveTopology {{"DeviceId4", "DeviceId5", "DeviceId6"}})); + EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsureOnlyDisplay, false, "DeviceId4", {"DeviceId5", "DeviceId6"}, DEFAULT_INITIAL_TOPOLOGY), display_device::ActiveTopology {{"DeviceId4"}}); } TEST_F_S_MOCKED(ComputeNewTopology, EnsureActive) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsureActive, true, "DeviceId4", { "DeviceId5", "DeviceId6" }, { { "DeviceId4" } }), - display_device::ActiveTopology { { "DeviceId4" } }); - EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsureActive, true, "DeviceId4", { "DeviceId5", "DeviceId6" }, { { "DeviceId3" } }), - (display_device::ActiveTopology { { "DeviceId3" }, { "DeviceId4" } })); + EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsureActive, true, "DeviceId4", {"DeviceId5", "DeviceId6"}, {{"DeviceId4"}}), display_device::ActiveTopology {{"DeviceId4"}}); + EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsureActive, true, "DeviceId4", {"DeviceId5", "DeviceId6"}, {{"DeviceId3"}}), (display_device::ActiveTopology {{"DeviceId3"}, {"DeviceId4"}})); } TEST_F_S_MOCKED(ComputeNewTopology, EnsurePrimary) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsurePrimary, true, "DeviceId4", { "DeviceId5", "DeviceId6" }, { { "DeviceId4" } }), - display_device::ActiveTopology { { "DeviceId4" } }); - EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsurePrimary, true, "DeviceId4", { "DeviceId5", "DeviceId6" }, { { "DeviceId3" } }), - (display_device::ActiveTopology { { "DeviceId3" }, { "DeviceId4" } })); + EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsurePrimary, true, "DeviceId4", {"DeviceId5", "DeviceId6"}, {{"DeviceId4"}}), display_device::ActiveTopology {{"DeviceId4"}}); + EXPECT_EQ(display_device::win_utils::computeNewTopology(DevicePrep::EnsurePrimary, true, "DeviceId4", {"DeviceId5", "DeviceId6"}, {{"DeviceId3"}}), (display_device::ActiveTopology {{"DeviceId3"}, {"DeviceId4"}})); } TEST_F_S_MOCKED(ComputeNewDisplayModes, PrimaryDevices, DoubleFloatType) { - auto expected_modes { DEFAULT_CURRENT_MODES }; - expected_modes["DeviceId1"] = { { 1920, 1080 }, { 1200000, 10000 } }; - expected_modes["DeviceId2"] = { { 1920, 1080 }, { 1200000, 10000 } }; + auto expected_modes {DEFAULT_CURRENT_MODES}; + expected_modes["DeviceId1"] = {{1920, 1080}, {1200000, 10000}}; + expected_modes["DeviceId2"] = {{1920, 1080}, {1200000, 10000}}; - EXPECT_EQ(display_device::win_utils::computeNewDisplayModes({ { 1920, 1080 } }, { 120. }, true, "DeviceId1", { "DeviceId2" }, DEFAULT_CURRENT_MODES), expected_modes); + EXPECT_EQ(display_device::win_utils::computeNewDisplayModes({{1920, 1080}}, {120.}, true, "DeviceId1", {"DeviceId2"}, DEFAULT_CURRENT_MODES), expected_modes); } TEST_F_S_MOCKED(ComputeNewDisplayModes, NonPrimaryDevices, DoubleFloatType) { - auto expected_modes { DEFAULT_CURRENT_MODES }; - expected_modes["DeviceId1"] = { { 1920, 1080 }, { 1200000, 10000 } }; - expected_modes["DeviceId2"] = { { 1920, 1080 }, expected_modes["DeviceId2"].m_refresh_rate }; + auto expected_modes {DEFAULT_CURRENT_MODES}; + expected_modes["DeviceId1"] = {{1920, 1080}, {1200000, 10000}}; + expected_modes["DeviceId2"] = {{1920, 1080}, expected_modes["DeviceId2"].m_refresh_rate}; - EXPECT_EQ(display_device::win_utils::computeNewDisplayModes({ { 1920, 1080 } }, { 120. }, false, "DeviceId1", { "DeviceId2" }, DEFAULT_CURRENT_MODES), expected_modes); + EXPECT_EQ(display_device::win_utils::computeNewDisplayModes({{1920, 1080}}, {120.}, false, "DeviceId1", {"DeviceId2"}, DEFAULT_CURRENT_MODES), expected_modes); } TEST_F_S_MOCKED(ComputeNewDisplayModes, PrimaryDevices, RationalFloatType) { - auto expected_modes { DEFAULT_CURRENT_MODES }; - expected_modes["DeviceId1"] = { { 1920, 1080 }, { 120, 1 } }; - expected_modes["DeviceId2"] = { { 1920, 1080 }, { 120, 1 } }; + auto expected_modes {DEFAULT_CURRENT_MODES}; + expected_modes["DeviceId1"] = {{1920, 1080}, {120, 1}}; + expected_modes["DeviceId2"] = {{1920, 1080}, {120, 1}}; - EXPECT_EQ(display_device::win_utils::computeNewDisplayModes({ { 1920, 1080 } }, { display_device::Rational { 120, 1 } }, true, "DeviceId1", { "DeviceId2" }, DEFAULT_CURRENT_MODES), expected_modes); + EXPECT_EQ(display_device::win_utils::computeNewDisplayModes({{1920, 1080}}, {display_device::Rational {120, 1}}, true, "DeviceId1", {"DeviceId2"}, DEFAULT_CURRENT_MODES), expected_modes); } TEST_F_S_MOCKED(ComputeNewDisplayModes, NonPrimaryDevices, RationalFloatType) { - auto expected_modes { DEFAULT_CURRENT_MODES }; - expected_modes["DeviceId1"] = { { 1920, 1080 }, { 120, 1 } }; - expected_modes["DeviceId2"] = { { 1920, 1080 }, expected_modes["DeviceId2"].m_refresh_rate }; + auto expected_modes {DEFAULT_CURRENT_MODES}; + expected_modes["DeviceId1"] = {{1920, 1080}, {120, 1}}; + expected_modes["DeviceId2"] = {{1920, 1080}, expected_modes["DeviceId2"].m_refresh_rate}; - EXPECT_EQ(display_device::win_utils::computeNewDisplayModes({ { 1920, 1080 } }, { display_device::Rational { 120, 1 } }, false, "DeviceId1", { "DeviceId2" }, DEFAULT_CURRENT_MODES), expected_modes); + EXPECT_EQ(display_device::win_utils::computeNewDisplayModes({{1920, 1080}}, {display_device::Rational {120, 1}}, false, "DeviceId1", {"DeviceId2"}, DEFAULT_CURRENT_MODES), expected_modes); } TEST_F_S_MOCKED(ComputeNewHdrStates, PrimaryDevices) { - auto expected_states { DEFAULT_CURRENT_HDR_STATES }; + auto expected_states {DEFAULT_CURRENT_HDR_STATES}; expected_states["DeviceId1"] = display_device::HdrState::Enabled; expected_states["DeviceId2"] = display_device::HdrState::Enabled; - EXPECT_EQ(display_device::win_utils::computeNewHdrStates(display_device::HdrState::Enabled, true, "DeviceId1", { "DeviceId2", "DeviceId3" }, DEFAULT_CURRENT_HDR_STATES), expected_states); + EXPECT_EQ(display_device::win_utils::computeNewHdrStates(display_device::HdrState::Enabled, true, "DeviceId1", {"DeviceId2", "DeviceId3"}, DEFAULT_CURRENT_HDR_STATES), expected_states); } TEST_F_S_MOCKED(ComputeNewHdrStates, NonPrimaryDevices) { - auto expected_states { DEFAULT_CURRENT_HDR_STATES }; + auto expected_states {DEFAULT_CURRENT_HDR_STATES}; expected_states["DeviceId1"] = display_device::HdrState::Enabled; - EXPECT_EQ(display_device::win_utils::computeNewHdrStates(display_device::HdrState::Enabled, false, "DeviceId1", { "DeviceId2", "DeviceId3" }, DEFAULT_CURRENT_HDR_STATES), expected_states); - EXPECT_EQ(display_device::win_utils::computeNewHdrStates(std::nullopt, false, "DeviceId1", { "DeviceId2", "DeviceId3" }, DEFAULT_CURRENT_HDR_STATES), DEFAULT_CURRENT_HDR_STATES); + EXPECT_EQ(display_device::win_utils::computeNewHdrStates(display_device::HdrState::Enabled, false, "DeviceId1", {"DeviceId2", "DeviceId3"}, DEFAULT_CURRENT_HDR_STATES), expected_states); + EXPECT_EQ(display_device::win_utils::computeNewHdrStates(std::nullopt, false, "DeviceId1", {"DeviceId2", "DeviceId3"}, DEFAULT_CURRENT_HDR_STATES), DEFAULT_CURRENT_HDR_STATES); } TEST_F_S_MOCKED(ComputeNewHdrStates, NoStateProvided) { - EXPECT_EQ(display_device::win_utils::computeNewHdrStates(std::nullopt, true, "DeviceId1", { "DeviceId2", "DeviceId3" }, DEFAULT_CURRENT_HDR_STATES), DEFAULT_CURRENT_HDR_STATES); - EXPECT_EQ(display_device::win_utils::computeNewHdrStates(std::nullopt, false, "DeviceId1", { "DeviceId2", "DeviceId3" }, DEFAULT_CURRENT_HDR_STATES), DEFAULT_CURRENT_HDR_STATES); + EXPECT_EQ(display_device::win_utils::computeNewHdrStates(std::nullopt, true, "DeviceId1", {"DeviceId2", "DeviceId3"}, DEFAULT_CURRENT_HDR_STATES), DEFAULT_CURRENT_HDR_STATES); + EXPECT_EQ(display_device::win_utils::computeNewHdrStates(std::nullopt, false, "DeviceId1", {"DeviceId2", "DeviceId3"}, DEFAULT_CURRENT_HDR_STATES), DEFAULT_CURRENT_HDR_STATES); } TEST_F_S_MOCKED(StripInitialState, NoStripIsPerformed) { - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const display_device::EnumeratedDeviceList devices { - { .m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } }, - { .m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } }, - { .m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info { .m_primary = false } }, - { .m_device_id = "DeviceId4" } + {.m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}, + {.m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}, + {.m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info {.m_primary = false}}, + {.m_device_id = "DeviceId4"} }; EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), initial_state); } TEST_F_S_MOCKED(StripInitialState, AllDevicesAreStripped) { - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const display_device::EnumeratedDeviceList devices { - { .m_device_id = "DeviceId4" } + {.m_device_id = "DeviceId4"} }; EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), std::nullopt); } TEST_F_S_MOCKED(StripInitialState, OneNonPrimaryDeviceStripped) { - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const display_device::EnumeratedDeviceList devices { - { .m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } }, - { .m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } } + {.m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}, + {.m_device_id = "DeviceId2", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}} }; - EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), (display_device::SingleDisplayConfigState::Initial { { { "DeviceId1", "DeviceId2" } }, { "DeviceId1", "DeviceId2" } })); + EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), (display_device::SingleDisplayConfigState::Initial {{{"DeviceId1", "DeviceId2"}}, {"DeviceId1", "DeviceId2"}})); } TEST_F_S_MOCKED(StripInitialState, OnePrimaryDeviceStripped) { - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const display_device::EnumeratedDeviceList devices { - { .m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info { .m_primary = false } }, - { .m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } }, + {.m_device_id = "DeviceId1", .m_info = display_device::EnumeratedDevice::Info {.m_primary = false}}, + {.m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}}, }; - EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), (display_device::SingleDisplayConfigState::Initial { { { "DeviceId1" }, { "DeviceId3" } }, { "DeviceId1" } })); + EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), (display_device::SingleDisplayConfigState::Initial {{{"DeviceId1"}, {"DeviceId3"}}, {"DeviceId1"}})); } TEST_F_S_MOCKED(StripInitialState, PrimaryDevicesCompletelyStripped) { - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const display_device::EnumeratedDeviceList devices { - { .m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info { .m_primary = false } } + {.m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info {.m_primary = false}} }; EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), std::nullopt); } TEST_F_S_MOCKED(StripInitialState, PrimaryDevicesCompletelyReplaced) { - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const display_device::EnumeratedDeviceList devices { - { .m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info { .m_primary = true } } + {.m_device_id = "DeviceId3", .m_info = display_device::EnumeratedDevice::Info {.m_primary = true}} }; - EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), (display_device::SingleDisplayConfigState::Initial { { { "DeviceId3" } }, { "DeviceId3" } })); + EXPECT_EQ(display_device::win_utils::stripInitialState(initial_state, devices), (display_device::SingleDisplayConfigState::Initial {{{"DeviceId3"}}, {"DeviceId3"}})); } TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, EmptyDeviceId, AdditionalDevicesNotStripped) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; const std::string device_id {}; - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const auto &[new_topology, device_to_configure, additional_devices_to_configure] = display_device::win_utils::computeNewTopologyAndMetadata(DevicePrep::EnsureActive, device_id, initial_state); EXPECT_EQ(new_topology, DEFAULT_INITIAL_TOPOLOGY); EXPECT_EQ(device_to_configure, "DeviceId1"); - EXPECT_EQ(additional_devices_to_configure, std::set { "DeviceId2" }); + EXPECT_EQ(additional_devices_to_configure, std::set {"DeviceId2"}); } TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, EmptyDeviceId, AdditionalDevicesStripped) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; const std::string device_id {}; - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId3", "DeviceId4" } }; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId3", "DeviceId4"}}; const auto &[new_topology, device_to_configure, additional_devices_to_configure] = display_device::win_utils::computeNewTopologyAndMetadata(DevicePrep::EnsureActive, device_id, initial_state); @@ -249,35 +242,35 @@ TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, EmptyDeviceId, AdditionalDevicesS TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, ValidDeviceId, WithAdditionalDevices) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - const std::string device_id { "DeviceId1" }; - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const std::string device_id {"DeviceId1"}; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const auto &[new_topology, device_to_configure, additional_devices_to_configure] = display_device::win_utils::computeNewTopologyAndMetadata(DevicePrep::EnsureActive, device_id, initial_state); EXPECT_EQ(new_topology, DEFAULT_INITIAL_TOPOLOGY); EXPECT_EQ(device_to_configure, device_id); - EXPECT_EQ(additional_devices_to_configure, std::set { "DeviceId2" }); + EXPECT_EQ(additional_devices_to_configure, std::set {"DeviceId2"}); } TEST_F_S_MOCKED(ComputeNewTopologyAndMetadata, ValidDeviceId, NoAdditionalDevices) { using DevicePrep = display_device::SingleDisplayConfiguration::DevicePreparation; - const std::string device_id { "DeviceId1" }; - const display_device::SingleDisplayConfigState::Initial initial_state { DEFAULT_INITIAL_TOPOLOGY, { "DeviceId1", "DeviceId2" } }; + const std::string device_id {"DeviceId1"}; + const display_device::SingleDisplayConfigState::Initial initial_state {DEFAULT_INITIAL_TOPOLOGY, {"DeviceId1", "DeviceId2"}}; const auto &[new_topology, device_to_configure, additional_devices_to_configure] = display_device::win_utils::computeNewTopologyAndMetadata(DevicePrep::EnsureOnlyDisplay, device_id, initial_state); - EXPECT_EQ(new_topology, display_device::ActiveTopology { { "DeviceId1" } }); + EXPECT_EQ(new_topology, display_device::ActiveTopology {{"DeviceId1"}}); EXPECT_EQ(device_to_configure, device_id); EXPECT_EQ(additional_devices_to_configure, std::set {}); } TEST_F_S_MOCKED(TopologyGuardFn, Success) { - EXPECT_CALL(m_dd_api, setTopology(display_device::ActiveTopology { { "DeviceId1" } })) + EXPECT_CALL(m_dd_api, setTopology(display_device::ActiveTopology {{"DeviceId1"}})) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); - const auto guard_fn { display_device::win_utils::topologyGuardFn(m_dd_api, { { "DeviceId1" } }) }; + const auto guard_fn {display_device::win_utils::topologyGuardFn(m_dd_api, {{"DeviceId1"}})}; EXPECT_NO_THROW(guard_fn()); } @@ -309,12 +302,12 @@ TEST_F_S_MOCKED(BlankHdrStates, NothingToApply) { TEST_F_S_MOCKED(BlankHdrStates, FailedToApplyInverseStates) { const display_device::HdrStateMap initial_states { - { "DeviceId1", { display_device::HdrState::Enabled } }, - { "DeviceId2", { display_device::HdrState::Disabled } }, - { "DeviceId3", std::nullopt } + {"DeviceId1", {display_device::HdrState::Enabled}}, + {"DeviceId2", {display_device::HdrState::Disabled}}, + {"DeviceId3", std::nullopt} }; const display_device::HdrStateMap inverse_states { - { "DeviceId1", { display_device::HdrState::Disabled } } + {"DeviceId1", {display_device::HdrState::Disabled}} }; Sequence sequence; @@ -328,15 +321,15 @@ TEST_F_S_MOCKED(BlankHdrStates, FailedToApplyInverseStates) { TEST_F_S_MOCKED(BlankHdrStates, FailedToApplyOriginalStates) { const display_device::HdrStateMap initial_states { - { "DeviceId1", { display_device::HdrState::Enabled } }, - { "DeviceId2", { display_device::HdrState::Disabled } }, - { "DeviceId3", std::nullopt } + {"DeviceId1", {display_device::HdrState::Enabled}}, + {"DeviceId2", {display_device::HdrState::Disabled}}, + {"DeviceId3", std::nullopt} }; const display_device::HdrStateMap inverse_states { - { "DeviceId1", { display_device::HdrState::Disabled } } + {"DeviceId1", {display_device::HdrState::Disabled}} }; const display_device::HdrStateMap original_states { - { "DeviceId1", { display_device::HdrState::Enabled } } + {"DeviceId1", {display_device::HdrState::Enabled}} }; Sequence sequence; @@ -355,15 +348,15 @@ TEST_F_S_MOCKED(BlankHdrStates, NullDelay) { TEST_F_S_MOCKED(BlankHdrStates, Success) { const display_device::HdrStateMap initial_states { - { "DeviceId1", { display_device::HdrState::Enabled } }, - { "DeviceId2", { display_device::HdrState::Disabled } }, - { "DeviceId3", std::nullopt } + {"DeviceId1", {display_device::HdrState::Enabled}}, + {"DeviceId2", {display_device::HdrState::Disabled}}, + {"DeviceId3", std::nullopt} }; const display_device::HdrStateMap inverse_states { - { "DeviceId1", { display_device::HdrState::Disabled } } + {"DeviceId1", {display_device::HdrState::Disabled}} }; const display_device::HdrStateMap original_states { - { "DeviceId1", { display_device::HdrState::Enabled } } + {"DeviceId1", {display_device::HdrState::Enabled}} }; Sequence sequence; @@ -377,40 +370,40 @@ TEST_F_S_MOCKED(BlankHdrStates, Success) { } TEST_F_S_MOCKED(TopologyGuardFn, Failure) { - EXPECT_CALL(m_dd_api, setTopology(display_device::ActiveTopology { { "DeviceId1" } })) + EXPECT_CALL(m_dd_api, setTopology(display_device::ActiveTopology {{"DeviceId1"}})) .Times(1) .WillOnce(Return(false)) .RetiresOnSaturation(); - const auto guard_fn { display_device::win_utils::topologyGuardFn(m_dd_api, { { "DeviceId1" } }) }; + const auto guard_fn {display_device::win_utils::topologyGuardFn(m_dd_api, {{"DeviceId1"}})}; EXPECT_NO_THROW(guard_fn()); } TEST_F_S_MOCKED(ModeGuardFn, Success) { - EXPECT_CALL(m_dd_api, getCurrentDisplayModes(std::set { "DeviceId1" })) + EXPECT_CALL(m_dd_api, getCurrentDisplayModes(std::set {"DeviceId1"})) .Times(1) - .WillOnce(Return(display_device::DeviceDisplayModeMap { { "DeviceId1", {} } })) + .WillOnce(Return(display_device::DeviceDisplayModeMap {{"DeviceId1", {}}})) .RetiresOnSaturation(); - EXPECT_CALL(m_dd_api, setDisplayModes(display_device::DeviceDisplayModeMap { { "DeviceId1", {} } })) + EXPECT_CALL(m_dd_api, setDisplayModes(display_device::DeviceDisplayModeMap {{"DeviceId1", {}}})) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); - const auto guard_fn { display_device::win_utils::modeGuardFn(m_dd_api, { { "DeviceId1" } }) }; + const auto guard_fn {display_device::win_utils::modeGuardFn(m_dd_api, {{"DeviceId1"}})}; EXPECT_NO_THROW(guard_fn()); } TEST_F_S_MOCKED(ModeGuardFn, Failure) { - EXPECT_CALL(m_dd_api, getCurrentDisplayModes(std::set { "DeviceId1" })) + EXPECT_CALL(m_dd_api, getCurrentDisplayModes(std::set {"DeviceId1"})) .Times(1) - .WillOnce(Return(display_device::DeviceDisplayModeMap { { "DeviceId1", {} } })) + .WillOnce(Return(display_device::DeviceDisplayModeMap {{"DeviceId1", {}}})) .RetiresOnSaturation(); - EXPECT_CALL(m_dd_api, setDisplayModes(display_device::DeviceDisplayModeMap { { "DeviceId1", {} } })) + EXPECT_CALL(m_dd_api, setDisplayModes(display_device::DeviceDisplayModeMap {{"DeviceId1", {}}})) .Times(1) .WillOnce(Return(false)) .RetiresOnSaturation(); - const auto guard_fn { display_device::win_utils::modeGuardFn(m_dd_api, { { "DeviceId1" } }) }; + const auto guard_fn {display_device::win_utils::modeGuardFn(m_dd_api, {{"DeviceId1"}})}; EXPECT_NO_THROW(guard_fn()); } @@ -424,7 +417,7 @@ TEST_F_S_MOCKED(PrimaryGuardFn, Success) { .WillOnce(Return(true)) .RetiresOnSaturation(); - const auto guard_fn { display_device::win_utils::primaryGuardFn(m_dd_api, display_device::ActiveTopology { { "DeviceId1" } }) }; + const auto guard_fn {display_device::win_utils::primaryGuardFn(m_dd_api, display_device::ActiveTopology {{"DeviceId1"}})}; EXPECT_NO_THROW(guard_fn()); } @@ -438,34 +431,34 @@ TEST_F_S_MOCKED(PrimaryGuardFn, Failure) { .WillOnce(Return(false)) .RetiresOnSaturation(); - const auto guard_fn { display_device::win_utils::primaryGuardFn(m_dd_api, display_device::ActiveTopology { { "DeviceId1" } }) }; + const auto guard_fn {display_device::win_utils::primaryGuardFn(m_dd_api, display_device::ActiveTopology {{"DeviceId1"}})}; EXPECT_NO_THROW(guard_fn()); } TEST_F_S_MOCKED(HdrStateGuardFn, Success) { - EXPECT_CALL(m_dd_api, getCurrentHdrStates(std::set { "DeviceId1" })) + EXPECT_CALL(m_dd_api, getCurrentHdrStates(std::set {"DeviceId1"})) .Times(1) - .WillOnce(Return(display_device::HdrStateMap { { "DeviceId1", {} } })) + .WillOnce(Return(display_device::HdrStateMap {{"DeviceId1", {}}})) .RetiresOnSaturation(); - EXPECT_CALL(m_dd_api, setHdrStates(display_device::HdrStateMap { { "DeviceId1", {} } })) + EXPECT_CALL(m_dd_api, setHdrStates(display_device::HdrStateMap {{"DeviceId1", {}}})) .Times(1) .WillOnce(Return(true)) .RetiresOnSaturation(); - const auto guard_fn { display_device::win_utils::hdrStateGuardFn(m_dd_api, { { "DeviceId1" } }) }; + const auto guard_fn {display_device::win_utils::hdrStateGuardFn(m_dd_api, {{"DeviceId1"}})}; EXPECT_NO_THROW(guard_fn()); } TEST_F_S_MOCKED(HdrStateGuardFn, Failure) { - EXPECT_CALL(m_dd_api, getCurrentHdrStates(std::set { "DeviceId1" })) + EXPECT_CALL(m_dd_api, getCurrentHdrStates(std::set {"DeviceId1"})) .Times(1) - .WillOnce(Return(display_device::HdrStateMap { { "DeviceId1", {} } })) + .WillOnce(Return(display_device::HdrStateMap {{"DeviceId1", {}}})) .RetiresOnSaturation(); - EXPECT_CALL(m_dd_api, setHdrStates(display_device::HdrStateMap { { "DeviceId1", {} } })) + EXPECT_CALL(m_dd_api, setHdrStates(display_device::HdrStateMap {{"DeviceId1", {}}})) .Times(1) .WillOnce(Return(false)) .RetiresOnSaturation(); - const auto guard_fn { display_device::win_utils::hdrStateGuardFn(m_dd_api, { { "DeviceId1" } }) }; + const auto guard_fn {display_device::win_utils::hdrStateGuardFn(m_dd_api, {{"DeviceId1"}})}; EXPECT_NO_THROW(guard_fn()); } diff --git a/tests/unit/windows/test_win_api_layer.cpp b/tests/unit/windows/test_win_api_layer.cpp index 3a2537e..acafff5 100644 --- a/tests/unit/windows/test_win_api_layer.cpp +++ b/tests/unit/windows/test_win_api_layer.cpp @@ -18,9 +18,9 @@ namespace { DISPLAYCONFIG_PATH_INFO path; // This is a gamble, but no one sane uses the maximum values as their IDs - path.sourceInfo.adapterId = { std::numeric_limits::max(), std::numeric_limits::max() }; + path.sourceInfo.adapterId = {std::numeric_limits::max(), std::numeric_limits::max()}; path.sourceInfo.id = std::numeric_limits::max(); - path.targetInfo.adapterId = { std::numeric_limits::max(), std::numeric_limits::max() }; + path.targetInfo.adapterId = {std::numeric_limits::max(), std::numeric_limits::max()}; path.targetInfo.id = std::numeric_limits::max(); return path; @@ -39,8 +39,8 @@ TEST_F_S(GetErrorString) { } TEST_F_S(QueryDisplayConfig, PathAndModeCount) { - const auto active_devices { m_layer.queryDisplayConfig(display_device::QueryType::Active) }; - const auto all_devices { m_layer.queryDisplayConfig(display_device::QueryType::All) }; + const auto active_devices {m_layer.queryDisplayConfig(display_device::QueryType::Active)}; + const auto all_devices {m_layer.queryDisplayConfig(display_device::QueryType::All)}; ASSERT_TRUE(active_devices); ASSERT_TRUE(all_devices); @@ -52,7 +52,7 @@ TEST_F_S(QueryDisplayConfig, PathAndModeCount) { } TEST_F_S(QueryDisplayConfig, ActivePaths) { - const auto active_devices { m_layer.queryDisplayConfig(display_device::QueryType::Active) }; + const auto active_devices {m_layer.queryDisplayConfig(display_device::QueryType::Active)}; ASSERT_TRUE(active_devices); for (const auto &path : active_devices->m_paths) { @@ -67,10 +67,10 @@ TEST_F_S(QueryDisplayConfig, ModeIndexValidity) { // The docs state, however, that it is only available when DISPLAYCONFIG_PATH_SUPPORT_VIRTUAL_MODE flag is set, but // that is just BS (maybe copy-pasta mistake), because some cases were found where the flag is not set and the union // is still being used. - const auto active_devices { m_layer.queryDisplayConfig(display_device::QueryType::Active) }; - const auto all_devices { m_layer.queryDisplayConfig(display_device::QueryType::All) }; + const auto active_devices {m_layer.queryDisplayConfig(display_device::QueryType::Active)}; + const auto all_devices {m_layer.queryDisplayConfig(display_device::QueryType::All)}; - for (const auto &devices : { active_devices, all_devices }) { + for (const auto &devices : {active_devices, all_devices}) { ASSERT_TRUE(devices); for (const auto &path : devices->m_paths) { @@ -101,29 +101,27 @@ TEST_F_S(QueryDisplayConfig, ModeIndexValidity) { } TEST_F_S(GetDeviceId) { - const auto all_devices { m_layer.queryDisplayConfig(display_device::QueryType::All) }; + const auto all_devices {m_layer.queryDisplayConfig(display_device::QueryType::All)}; ASSERT_TRUE(all_devices); std::map device_id_per_device_path; for (const auto &path : all_devices->m_paths) { - const auto device_id { m_layer.getDeviceId(path) }; - const auto device_id_2 { m_layer.getDeviceId(path) }; - const auto device_path { m_layer.getMonitorDevicePath(path) }; + const auto device_id {m_layer.getDeviceId(path)}; + const auto device_id_2 {m_layer.getDeviceId(path)}; + const auto device_path {m_layer.getMonitorDevicePath(path)}; // Testing soft persistence - ids remain the same between calls EXPECT_EQ(device_id, device_id_2); if (device_id.empty()) { EXPECT_EQ(path.targetInfo.targetAvailable, FALSE); - } - else { - auto path_it { device_id_per_device_path.find(device_path) }; + } else { + auto path_it {device_id_per_device_path.find(device_path)}; if (path_it != std::end(device_id_per_device_path)) { // Devices with the same paths must have the same device ids. EXPECT_EQ(path_it->second, device_id); - } - else { - EXPECT_TRUE(device_id_per_device_path.insert({ device_path, device_id }).second); + } else { + EXPECT_TRUE(device_id_per_device_path.insert({device_path, device_id}).second); } } } @@ -134,27 +132,25 @@ TEST_F_S(GetDeviceId, InvalidPath) { } TEST_F_S(GetMonitorDevicePath) { - const auto all_devices { m_layer.queryDisplayConfig(display_device::QueryType::All) }; + const auto all_devices {m_layer.queryDisplayConfig(display_device::QueryType::All)}; ASSERT_TRUE(all_devices); std::set current_device_paths; for (const auto &path : all_devices->m_paths) { - const auto device_path { m_layer.getMonitorDevicePath(path) }; - const auto device_path_2 { m_layer.getMonitorDevicePath(path) }; + const auto device_path {m_layer.getMonitorDevicePath(path)}; + const auto device_path_2 {m_layer.getMonitorDevicePath(path)}; // Testing soft persistence - paths remain the same between calls EXPECT_EQ(device_path, device_path_2); if (device_path.empty()) { EXPECT_EQ(path.targetInfo.targetAvailable, FALSE); - } - else if (current_device_paths.contains(device_path)) { + } else if (current_device_paths.contains(device_path)) { // In case we have a duplicate device path, the path must be inactive, because // active paths are always in the front of the list and therefore will be added // first (only 1 active path is possible). EXPECT_FALSE(static_cast(path.flags & DISPLAYCONFIG_PATH_ACTIVE)); - } - else { + } else { EXPECT_TRUE(current_device_paths.insert(device_path).second); } } @@ -165,12 +161,12 @@ TEST_F_S(GetMonitorDevicePath, InvalidPath) { } TEST_F_S(GetFriendlyName) { - const auto all_devices { m_layer.queryDisplayConfig(display_device::QueryType::All) }; + const auto all_devices {m_layer.queryDisplayConfig(display_device::QueryType::All)}; ASSERT_TRUE(all_devices); for (const auto &path : all_devices->m_paths) { - const auto friendly_name { m_layer.getFriendlyName(path) }; - const auto friendly_name_2 { m_layer.getFriendlyName(path) }; + const auto friendly_name {m_layer.getFriendlyName(path)}; + const auto friendly_name_2 {m_layer.getFriendlyName(path)}; // Testing soft persistence - ids remain the same between calls EXPECT_EQ(friendly_name, friendly_name_2); @@ -185,12 +181,12 @@ TEST_F_S(GetFriendlyName, InvalidPath) { } TEST_F_S(GetDisplayName) { - const auto all_devices { m_layer.queryDisplayConfig(display_device::QueryType::All) }; + const auto all_devices {m_layer.queryDisplayConfig(display_device::QueryType::All)}; ASSERT_TRUE(all_devices); for (const auto &path : all_devices->m_paths) { - const auto display_name { m_layer.getDisplayName(path) }; - const auto display_name_2 { m_layer.getDisplayName(path) }; + const auto display_name {m_layer.getDisplayName(path)}; + const auto display_name_2 {m_layer.getDisplayName(path)}; // Testing soft persistence - ids remain the same between calls EXPECT_EQ(display_name, display_name_2); @@ -214,7 +210,7 @@ TEST_F_S(SetHdrState, InvalidPath) { } TEST_F_S(GetDisplayScale) { - const auto active_devices { m_layer.queryDisplayConfig(display_device::QueryType::Active) }; + const auto active_devices {m_layer.queryDisplayConfig(display_device::QueryType::Active)}; ASSERT_TRUE(active_devices); for (const auto &path : active_devices->m_paths) { @@ -226,22 +222,22 @@ TEST_F_S(GetDisplayScale) { // Valid case { - const auto scale { m_layer.getDisplayScale(m_layer.getDisplayName(path), active_devices->m_modes[source_mode_index].sourceMode) }; + const auto scale {m_layer.getDisplayScale(m_layer.getDisplayName(path), active_devices->m_modes[source_mode_index].sourceMode)}; EXPECT_TRUE(scale.has_value()); // Can't really compare against anything... } // Invalid display name case { - const auto scale { m_layer.getDisplayScale("FAKE", active_devices->m_modes[source_mode_index].sourceMode) }; + const auto scale {m_layer.getDisplayScale("FAKE", active_devices->m_modes[source_mode_index].sourceMode)}; EXPECT_FALSE(scale.has_value()); } // Zero width case { - auto mode { active_devices->m_modes[source_mode_index].sourceMode }; + auto mode {active_devices->m_modes[source_mode_index].sourceMode}; mode.width = 0; - const auto scale { m_layer.getDisplayScale(m_layer.getDisplayName(path), mode) }; + const auto scale {m_layer.getDisplayScale(m_layer.getDisplayName(path), mode)}; EXPECT_FALSE(scale.has_value()); } } diff --git a/tests/unit/windows/test_win_api_utils.cpp b/tests/unit/windows/test_win_api_utils.cpp index efa690c..3d3203c 100644 --- a/tests/unit/windows/test_win_api_utils.cpp +++ b/tests/unit/windows/test_win_api_utils.cpp @@ -14,8 +14,7 @@ namespace { // Test fixture(s) for this file class WinApiUtilsMocked: public BaseTest { public: - void - setupExpectCallForValidPaths(int number_of_calls, InSequence & /* To ensure that sequence is created outside this scope */) { + void setupExpectCallForValidPaths(int number_of_calls, InSequence & /* To ensure that sequence is created outside this scope */) { for (int i = 1; i <= number_of_calls; ++i) { EXPECT_CALL(m_layer, getMonitorDevicePath(_)) .Times(1) @@ -96,31 +95,31 @@ namespace { std::vector paths; paths.push_back(AVAILABLE_AND_ACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 1; paths.push_back(AVAILABLE_AND_ACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 2, 2 }; + paths.back().sourceInfo.adapterId = {2, 2}; paths.back().sourceInfo.id = 0; paths.push_back(AVAILABLE_AND_INACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 0; paths.push_back(AVAILABLE_AND_INACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 3, 3 }; + paths.back().sourceInfo.adapterId = {3, 3}; paths.back().sourceInfo.id = 4; paths.push_back(AVAILABLE_AND_INACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 2, 2 }; + paths.back().sourceInfo.adapterId = {2, 2}; paths.back().sourceInfo.id = 1; paths.push_back(AVAILABLE_AND_INACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 0; paths.push_back(AVAILABLE_AND_INACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 1; return paths; @@ -129,15 +128,14 @@ namespace { const display_device::PathSourceIndexDataMap EXPECTED_SOURCE_INDEX_DATA { // Contains the expected data if generated from PATHS_WITH_SOURCE_IDS and some // sensibly chosen device paths and device ids. - { "DeviceId1", { { { 0, 2 }, { 1, 0 } }, { 1, 1 }, { 1 } } }, - { "DeviceId2", { { { 0, 1 }, { 1, 4 } }, { 2, 2 }, { 0 } } }, - { "DeviceId3", { { { 4, 3 } }, { 3, 3 }, std::nullopt } }, - { "DeviceId4", { { { 0, 5 }, { 1, 6 } }, { 1, 1 }, std::nullopt } } + {"DeviceId1", {{{0, 2}, {1, 0}}, {1, 1}, {1}}}, + {"DeviceId2", {{{0, 1}, {1, 4}}, {2, 2}, {0}}}, + {"DeviceId3", {{{4, 3}}, {3, 3}, std::nullopt}}, + {"DeviceId4", {{{0, 5}, {1, 6}}, {1, 1}, std::nullopt}} }; // Helper functions - void - wipeIndexesAndActivatePaths(std::vector &paths) { + void wipeIndexesAndActivatePaths(std::vector &paths) { for (auto &path : paths) { display_device::win_utils::setSourceIndex(path, std::nullopt); display_device::win_utils::setTargetIndex(path, std::nullopt); @@ -186,9 +184,9 @@ TEST_F_S_MOCKED(IsPrimary) { DISPLAYCONFIG_SOURCE_MODE non_primary_mode_1; DISPLAYCONFIG_SOURCE_MODE non_primary_mode_2; - primary_mode.position = { 0, 0 }; - non_primary_mode_1.position = { 1, 0 }; - non_primary_mode_2.position = { 0, 2 }; + primary_mode.position = {0, 0}; + non_primary_mode_1.position = {1, 0}; + non_primary_mode_2.position = {0, 2}; EXPECT_TRUE(display_device::win_utils::isPrimary(primary_mode)); EXPECT_FALSE(display_device::win_utils::isPrimary(non_primary_mode_1)); @@ -280,32 +278,32 @@ TEST_F_S_MOCKED(SetCloneGroupId) { } TEST_F_S_MOCKED(GetSourceMode) { - auto *mode { display_device::win_utils::getSourceMode(1, TARGET_AND_SOURCE_MODES) }; - auto *const_mode { display_device::win_utils::getSourceMode(1, const_cast &>(TARGET_AND_SOURCE_MODES)) }; + auto *mode {display_device::win_utils::getSourceMode(1, TARGET_AND_SOURCE_MODES)}; + auto *const_mode {display_device::win_utils::getSourceMode(1, const_cast &>(TARGET_AND_SOURCE_MODES))}; EXPECT_EQ(mode, const_mode); EXPECT_EQ(mode, &TARGET_AND_SOURCE_MODES.at(1).sourceMode); } TEST_F_S_MOCKED(GetSourceMode, InvalidIndex) { - auto *mode { display_device::win_utils::getSourceMode(std::nullopt, TARGET_AND_SOURCE_MODES) }; - auto *const_mode { display_device::win_utils::getSourceMode(std::nullopt, const_cast &>(TARGET_AND_SOURCE_MODES)) }; + auto *mode {display_device::win_utils::getSourceMode(std::nullopt, TARGET_AND_SOURCE_MODES)}; + auto *const_mode {display_device::win_utils::getSourceMode(std::nullopt, const_cast &>(TARGET_AND_SOURCE_MODES))}; EXPECT_EQ(mode, const_mode); EXPECT_EQ(mode, nullptr); } TEST_F_S_MOCKED(GetSourceMode, OutOfRangeIndex) { - auto *mode { display_device::win_utils::getSourceMode(2, TARGET_AND_SOURCE_MODES) }; - auto *const_mode { display_device::win_utils::getSourceMode(2, const_cast &>(TARGET_AND_SOURCE_MODES)) }; + auto *mode {display_device::win_utils::getSourceMode(2, TARGET_AND_SOURCE_MODES)}; + auto *const_mode {display_device::win_utils::getSourceMode(2, const_cast &>(TARGET_AND_SOURCE_MODES))}; EXPECT_EQ(mode, const_mode); EXPECT_EQ(mode, nullptr); } TEST_F_S_MOCKED(GetSourceMode, InvalidModeType) { - auto *mode { display_device::win_utils::getSourceMode(0, TARGET_AND_SOURCE_MODES) }; - auto *const_mode { display_device::win_utils::getSourceMode(0, const_cast &>(TARGET_AND_SOURCE_MODES)) }; + auto *mode {display_device::win_utils::getSourceMode(0, TARGET_AND_SOURCE_MODES)}; + auto *const_mode {display_device::win_utils::getSourceMode(0, const_cast &>(TARGET_AND_SOURCE_MODES))}; EXPECT_EQ(mode, const_mode); EXPECT_EQ(mode, nullptr); @@ -314,8 +312,8 @@ TEST_F_S_MOCKED(GetSourceMode, InvalidModeType) { TEST_F_S_MOCKED(GetSourceMode, EmptyList) { std::vector modes; - auto *mode { display_device::win_utils::getSourceMode(2, modes) }; - auto *const_mode { display_device::win_utils::getSourceMode(2, const_cast &>(modes)) }; + auto *mode {display_device::win_utils::getSourceMode(2, modes)}; + auto *const_mode {display_device::win_utils::getSourceMode(2, const_cast &>(modes))}; EXPECT_EQ(mode, const_mode); EXPECT_EQ(mode, nullptr); @@ -332,7 +330,7 @@ TEST_F_S_MOCKED(GetDeviceInfo, AvailablePath, ActivePath, MustBeActiveIsTrue) { .Times(1) .WillOnce(Return("DisplayName")); - const auto result { display_device::win_utils::getDeviceInfoForValidPath(m_layer, AVAILABLE_AND_ACTIVE_PATH, display_device::ValidatedPathType::Active) }; + const auto result {display_device::win_utils::getDeviceInfoForValidPath(m_layer, AVAILABLE_AND_ACTIVE_PATH, display_device::ValidatedPathType::Active)}; ASSERT_TRUE(result); EXPECT_EQ(result->m_device_path, "DevicePath"); @@ -350,7 +348,7 @@ TEST_F_S_MOCKED(GetDeviceInfo, AvailablePath, ActivePath, MustBeActiveIsFalse) { .Times(1) .WillOnce(Return("DisplayName")); - const auto result { display_device::win_utils::getDeviceInfoForValidPath(m_layer, AVAILABLE_AND_ACTIVE_PATH, display_device::ValidatedPathType::Any) }; + const auto result {display_device::win_utils::getDeviceInfoForValidPath(m_layer, AVAILABLE_AND_ACTIVE_PATH, display_device::ValidatedPathType::Any)}; ASSERT_TRUE(result); EXPECT_EQ(result->m_device_path, "DevicePath"); @@ -382,7 +380,7 @@ TEST_F_S_MOCKED(GetDeviceInfo, AvailablePath, InactivePath, MustBeActiveIsFalse) .Times(1) .WillOnce(Return("DisplayName")); - const auto result { display_device::win_utils::getDeviceInfoForValidPath(m_layer, AVAILABLE_AND_INACTIVE_PATH, display_device::ValidatedPathType::Any) }; + const auto result {display_device::win_utils::getDeviceInfoForValidPath(m_layer, AVAILABLE_AND_INACTIVE_PATH, display_device::ValidatedPathType::Any)}; ASSERT_TRUE(result); EXPECT_EQ(result->m_device_path, "DevicePath"); @@ -432,8 +430,8 @@ TEST_F_S_MOCKED(GetActivePath, InstantMatch) { .Times(2) .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) }; + 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)}; EXPECT_EQ(path, const_path); EXPECT_EQ(path, &PATHS_WITH_SOURCE_IDS.at(0)); @@ -456,8 +454,8 @@ TEST_F_S_MOCKED(GetActivePath, SecondMatch) { .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) }; + 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)}; EXPECT_EQ(path, const_path); EXPECT_EQ(path, &PATHS_WITH_SOURCE_IDS.at(1)); @@ -468,8 +466,8 @@ TEST_F_S_MOCKED(GetActivePath, NoMatch) { .Times(4) .WillOnce(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) }; + 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)}; EXPECT_EQ(path, const_path); EXPECT_EQ(path, nullptr); @@ -523,7 +521,7 @@ TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, TransientPathIssues) { .WillOnce(Return("DeviceId4")) .WillOnce(Return("DeviceId4")); - display_device::PathSourceIndexDataMap expected_data { EXPECTED_SOURCE_INDEX_DATA }; + display_device::PathSourceIndexDataMap expected_data {EXPECTED_SOURCE_INDEX_DATA}; expected_data.erase(expected_data.find("DeviceId3")); EXPECT_EQ(display_device::win_utils::collectSourceDataForMatchingPaths(m_layer, PATHS_WITH_SOURCE_IDS), expected_data); @@ -565,7 +563,7 @@ TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, DifferentPathsWithSameId) { } TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, MismatchingAdapterIdsForPaths, HighPart) { - std::vector paths { PATHS_WITH_SOURCE_IDS }; + std::vector paths {PATHS_WITH_SOURCE_IDS}; // Invalidate the adapter id paths.at(2).sourceInfo.adapterId.HighPart++; @@ -589,7 +587,7 @@ TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, MismatchingAdapterIdsForPaths } TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, MismatchingAdapterIdsForPaths, LowPart) { - std::vector paths { PATHS_WITH_SOURCE_IDS }; + std::vector paths {PATHS_WITH_SOURCE_IDS}; // Invalidate the adapter id paths.at(2).sourceInfo.adapterId.LowPart++; @@ -613,7 +611,7 @@ TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, MismatchingAdapterIdsForPaths } TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, ActiveDeviceNotFirst) { - std::vector paths { PATHS_WITH_SOURCE_IDS }; + std::vector paths {PATHS_WITH_SOURCE_IDS}; // Swapping around the active/inactive pair std::swap(paths.at(0), paths.at(2)); @@ -637,7 +635,7 @@ TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, ActiveDeviceNotFirst) { } TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, DuplicateSourceIds) { - std::vector paths { PATHS_WITH_SOURCE_IDS }; + std::vector paths {PATHS_WITH_SOURCE_IDS}; // Making sure source ids match (adapter ids don't matter) paths.at(0).sourceInfo.id = paths.at(2).sourceInfo.id; @@ -668,10 +666,10 @@ TEST_F_S_MOCKED(CollectSourceDataForMatchingPaths, EmptyList) { } TEST_F_S_MOCKED(MakePathsForNewTopology) { - const display_device::ActiveTopology new_topology { { "DeviceId1" }, { "DeviceId2" }, { "DeviceId3", "DeviceId4" } }; - const std::vector paths { PATHS_WITH_SOURCE_IDS }; + const display_device::ActiveTopology new_topology {{"DeviceId1"}, {"DeviceId2"}, {"DeviceId3", "DeviceId4"}}; + const std::vector paths {PATHS_WITH_SOURCE_IDS}; - std::vector expected_paths { { paths.at(0), paths.at(1), paths.at(3), paths.at(5) } }; + std::vector expected_paths {{paths.at(0), paths.at(1), paths.at(3), paths.at(5)}}; wipeIndexesAndActivatePaths(expected_paths); display_device::win_utils::setCloneGroupId(expected_paths.at(0), 0); @@ -683,10 +681,10 @@ TEST_F_S_MOCKED(MakePathsForNewTopology) { } TEST_F_S_MOCKED(MakePathsForNewTopology, DevicesFromSameAdapterInAGroup) { - const display_device::ActiveTopology new_topology { { "DeviceId1", "DeviceId4" } }; - const std::vector paths { PATHS_WITH_SOURCE_IDS }; + const display_device::ActiveTopology new_topology {{"DeviceId1", "DeviceId4"}}; + const std::vector paths {PATHS_WITH_SOURCE_IDS}; - std::vector expected_paths { paths.at(0), paths.at(6) }; + std::vector expected_paths {paths.at(0), paths.at(6)}; wipeIndexesAndActivatePaths(expected_paths); display_device::win_utils::setCloneGroupId(expected_paths.at(0), 0); @@ -696,7 +694,7 @@ TEST_F_S_MOCKED(MakePathsForNewTopology, DevicesFromSameAdapterInAGroup) { } TEST_F_S_MOCKED(MakePathsForNewTopology, UnknownDeviceInNewTopology) { - const display_device::ActiveTopology new_topology { { "DeviceIdX", "DeviceId4" } }; + const display_device::ActiveTopology new_topology {{"DeviceIdX", "DeviceId4"}}; const std::vector expected_paths {}; EXPECT_EQ(display_device::win_utils::makePathsForNewTopology(new_topology, EXPECTED_SOURCE_INDEX_DATA, PATHS_WITH_SOURCE_IDS), expected_paths); @@ -706,20 +704,20 @@ TEST_F_S_MOCKED(MakePathsForNewTopology, MissingPathsForDuplicatedDisplays) { // There must be N-1 (up to a GPU limit) amount of source ids (for each path/deviceId combination) available. // For the same adapter, only devices with matching ids can be grouped (duplicated). // In this case, have only 0 and 1 ids. You may also notice that 0 != 1, and thus we cannot group them. - const display_device::ActiveTopology new_topology { { "DeviceId1", "DeviceId2" } }; + const display_device::ActiveTopology new_topology {{"DeviceId1", "DeviceId2"}}; std::vector paths {}; paths.push_back(AVAILABLE_AND_ACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 0; paths.push_back(AVAILABLE_AND_INACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 1; const display_device::PathSourceIndexDataMap path_source_data { - { "DeviceId1", { { { 0, 0 } }, { 1, 1 }, { 0 } } }, - { "DeviceId2", { { { 1, 1 } }, { 1, 1 }, std::nullopt } } + {"DeviceId1", {{{0, 0}}, {1, 1}, {0}}}, + {"DeviceId2", {{{1, 1}}, {1, 1}, std::nullopt}} }; const std::vector expected_paths {}; @@ -729,23 +727,23 @@ TEST_F_S_MOCKED(MakePathsForNewTopology, MissingPathsForDuplicatedDisplays) { TEST_F_S_MOCKED(MakePathsForNewTopology, GpuLimit, DuplicatedDisplays) { // We can only render 1 source, however since they are duplicated, source is reused // and can be rendered to different devices. - const display_device::ActiveTopology new_topology { { "DeviceId1", "DeviceId2" } }; + const display_device::ActiveTopology new_topology {{"DeviceId1", "DeviceId2"}}; std::vector paths {}; paths.push_back(AVAILABLE_AND_ACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 0; paths.push_back(AVAILABLE_AND_INACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 0; const display_device::PathSourceIndexDataMap path_source_data { - { "DeviceId1", { { { 0, 0 } }, { 1, 1 }, { 0 } } }, - { "DeviceId2", { { { 0, 1 } }, { 1, 1 }, std::nullopt } } + {"DeviceId1", {{{0, 0}}, {1, 1}, {0}}}, + {"DeviceId2", {{{0, 1}}, {1, 1}, std::nullopt}} }; - std::vector expected_paths { paths.at(0), paths.at(1) }; + std::vector expected_paths {paths.at(0), paths.at(1)}; wipeIndexesAndActivatePaths(expected_paths); display_device::win_utils::setCloneGroupId(expected_paths.at(0), 0); @@ -756,20 +754,20 @@ TEST_F_S_MOCKED(MakePathsForNewTopology, GpuLimit, DuplicatedDisplays) { TEST_F_S_MOCKED(MakePathsForNewTopology, GpuLimit, ExtendedDisplays) { // We can only render 1 source and since want extended displays, we must have 2 and that's impossible. - const display_device::ActiveTopology new_topology { { "DeviceId1" }, { "DeviceId2" } }; + const display_device::ActiveTopology new_topology {{"DeviceId1"}, {"DeviceId2"}}; std::vector paths {}; paths.push_back(AVAILABLE_AND_ACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 0; paths.push_back(AVAILABLE_AND_INACTIVE_PATH); - paths.back().sourceInfo.adapterId = { 1, 1 }; + paths.back().sourceInfo.adapterId = {1, 1}; paths.back().sourceInfo.id = 0; const display_device::PathSourceIndexDataMap path_source_data { - { "DeviceId1", { { { 0, 0 } }, { 1, 1 }, { 0 } } }, - { "DeviceId2", { { { 0, 1 } }, { 1, 1 }, std::nullopt } } + {"DeviceId1", {{{0, 0}}, {1, 1}, {0}}}, + {"DeviceId2", {{{0, 1}}, {1, 1}, std::nullopt}} }; const std::vector expected_paths {}; @@ -777,7 +775,7 @@ TEST_F_S_MOCKED(MakePathsForNewTopology, GpuLimit, ExtendedDisplays) { } TEST_F_S_MOCKED(MakePathsForNewTopology, IndexOutOfRange) { - const display_device::ActiveTopology new_topology { { "DeviceId1", "DeviceId4" } }; + const display_device::ActiveTopology new_topology {{"DeviceId1", "DeviceId4"}}; const std::vector expected_paths {}; EXPECT_EQ(display_device::win_utils::makePathsForNewTopology(new_topology, EXPECTED_SOURCE_INDEX_DATA, {}), expected_paths); @@ -814,7 +812,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates) { setupExpectCallForValidPaths(4, sequence); } - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, { "DeviceId1", "DeviceId2" }), (std::set { "DeviceId1", "DeviceId2", "DeviceId3" })); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId1", "DeviceId2"}), (std::set {"DeviceId1", "DeviceId2", "DeviceId3"})); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToQueryDevices) { @@ -822,7 +820,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToQueryDevices) { .Times(1) .WillOnce(Return(ut_consts::PAM_NULL)); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, { "DeviceId2" }), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), std::set {}); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, EmptyDeviceIdInProvidedList) { @@ -832,7 +830,7 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, EmptyDeviceIdInProvidedLis .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, { "" }), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {""}), std::set {}); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToFindActivePath) { @@ -843,11 +841,11 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, FailedToFindActivePath) { .Times(4) .WillOnce(Return("")); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, { "DeviceId2" }), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), std::set {}); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, NoSourceModeFound) { - auto pam_no_modes { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto pam_no_modes {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; pam_no_modes->m_modes.clear(); InSequence sequence; @@ -856,11 +854,11 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, NoSourceModeFound) { .WillOnce(Return(pam_no_modes)); setupExpectCallForValidPaths(2, sequence); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, { "DeviceId2" }), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId2"}), std::set {}); } TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, IncompleteListOfSources) { - auto pam_no_modes { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto pam_no_modes {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; pam_no_modes->m_modes.resize(2); InSequence sequence; @@ -874,32 +872,20 @@ TEST_F_S_MOCKED(GetAllDeviceIdsAndMatchingDuplicates, IncompleteListOfSources) { .RetiresOnSaturation(); setupExpectCallForValidPaths(1, sequence); - EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, { "DeviceId1" }), std::set {}); + EXPECT_EQ(display_device::win_utils::getAllDeviceIdsAndMatchingDuplicates(m_layer, {"DeviceId1"}), std::set {}); } TEST_F_S_MOCKED(FuzzyCompareRefreshRates) { - EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational { 60, 1 }, display_device::Rational { 5985, 100 }), true); - EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational { 60, 1 }, display_device::Rational { 5920, 100 }), true); - EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational { 60, 1 }, display_device::Rational { 5900, 100 }), false); - EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational { 60, 0 }, display_device::Rational { 5985, 100 }), false); - EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational { 60, 1 }, display_device::Rational { 5985, 0 }), false); + EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational {60, 1}, display_device::Rational {5985, 100}), true); + EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational {60, 1}, display_device::Rational {5920, 100}), true); + EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational {60, 1}, display_device::Rational {5900, 100}), false); + EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational {60, 0}, display_device::Rational {5985, 100}), false); + EXPECT_EQ(display_device::win_utils::fuzzyCompareRefreshRates(display_device::Rational {60, 1}, display_device::Rational {5985, 0}), false); } TEST_F_S_MOCKED(FuzzyCompareModes) { - EXPECT_EQ(display_device::win_utils::fuzzyCompareModes( - display_device::DisplayMode { 1920, 1080, { 60, 1 } }, - display_device::DisplayMode { 1920, 1080, { 60, 1 } }), - true); - EXPECT_EQ(display_device::win_utils::fuzzyCompareModes( - display_device::DisplayMode { 123, 1080, { 60, 1 } }, - display_device::DisplayMode { 1920, 1080, { 60, 1 } }), - false); - EXPECT_EQ(display_device::win_utils::fuzzyCompareModes( - display_device::DisplayMode { 1920, 123, { 60, 1 } }, - display_device::DisplayMode { 1920, 1080, { 60, 1 } }), - false); - EXPECT_EQ(display_device::win_utils::fuzzyCompareModes( - display_device::DisplayMode { 1920, 1080, { 60, 1 } }, - display_device::DisplayMode { 1920, 1080, { 50, 1 } }), - false); + EXPECT_EQ(display_device::win_utils::fuzzyCompareModes(display_device::DisplayMode {1920, 1080, {60, 1}}, display_device::DisplayMode {1920, 1080, {60, 1}}), true); + EXPECT_EQ(display_device::win_utils::fuzzyCompareModes(display_device::DisplayMode {123, 1080, {60, 1}}, display_device::DisplayMode {1920, 1080, {60, 1}}), false); + EXPECT_EQ(display_device::win_utils::fuzzyCompareModes(display_device::DisplayMode {1920, 123, {60, 1}}, display_device::DisplayMode {1920, 1080, {60, 1}}), false); + EXPECT_EQ(display_device::win_utils::fuzzyCompareModes(display_device::DisplayMode {1920, 1080, {60, 1}}, display_device::DisplayMode {1920, 1080, {50, 1}}), false); } diff --git a/tests/unit/windows/test_win_display_device_general.cpp b/tests/unit/windows/test_win_display_device_general.cpp index 24b4ab8..67f89bd 100644 --- a/tests/unit/windows/test_win_display_device_general.cpp +++ b/tests/unit/windows/test_win_display_device_general.cpp @@ -19,14 +19,14 @@ namespace { // Test fixture(s) for this file class WinDisplayDeviceGeneral: public BaseTest { public: - std::shared_ptr m_layer { std::make_shared() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr m_layer {std::make_shared()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; class WinDisplayDeviceGeneralMocked: public BaseTest { public: - std::shared_ptr> m_layer { std::make_shared>() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr> m_layer {std::make_shared>()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; // Specialized TEST macro(s) for this test file @@ -34,12 +34,14 @@ namespace { #define TEST_F_S_MOCKED(...) DD_MAKE_TEST(TEST_F, WinDisplayDeviceGeneralMocked, __VA_ARGS__) // Additional convenience global const(s) - const UINT32 FLAGS { SDC_VALIDATE | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_VIRTUAL_MODE_AWARE }; + const UINT32 FLAGS {SDC_VALIDATE | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_VIRTUAL_MODE_AWARE}; } // namespace TEST_F_S(NullptrLayerProvided) { - EXPECT_THAT([]() { const auto win_dd { display_device::WinDisplayDevice { nullptr } }; }, - ThrowsMessage(HasSubstr("Nullptr provided for WinApiLayerInterface in WinDisplayDevice!"))); + EXPECT_THAT([]() { + const auto win_dd {display_device::WinDisplayDevice {nullptr}}; + }, + ThrowsMessage(HasSubstr("Nullptr provided for WinApiLayerInterface in WinDisplayDevice!"))); } TEST_F_S(IsApiAccessAvailable) { @@ -87,17 +89,17 @@ TEST_F_S(EnumAvailableDevices) { // Note: we can't verify live data precisely, so just basic check // is performed regarding active vs. inactive devices - const auto available_devices { getAvailableDevices(*m_layer, false) }; + const auto available_devices {getAvailableDevices(*m_layer, false)}; ASSERT_TRUE(available_devices); - const auto enum_devices { m_win_dd.enumAvailableDevices() }; + const auto enum_devices {m_win_dd.enumAvailableDevices()}; ASSERT_EQ(available_devices->size(), enum_devices.size()); - const auto topology { display_device::win_utils::flattenTopology(m_win_dd.getCurrentTopology()) }; + const auto topology {display_device::win_utils::flattenTopology(m_win_dd.getCurrentTopology())}; for (const auto &device_id : *available_devices) { - auto enum_it { std::find_if(std::begin(enum_devices), std::end(enum_devices), [&device_id](const auto &entry) { + auto enum_it {std::find_if(std::begin(enum_devices), std::end(enum_devices), [&device_id](const auto &entry) { return entry.m_device_id == device_id; - }) }; + })}; ASSERT_TRUE(enum_it != std::end(enum_devices)); EXPECT_EQ(enum_it->m_info.has_value(), topology.contains(device_id)); @@ -105,12 +107,12 @@ TEST_F_S(EnumAvailableDevices) { } TEST_F_S_MOCKED(EnumAvailableDevices) { - const auto pam_active_and_inactive { []() { - auto pam { ut_consts::PAM_3_ACTIVE }; + const auto pam_active_and_inactive {[]() { + auto pam {ut_consts::PAM_3_ACTIVE}; pam->m_paths.at(0).targetInfo.refreshRate.Denominator = 0; pam->m_paths.at(2).flags &= ~DISPLAYCONFIG_PATH_ACTIVE; return pam; - }() }; + }()}; InSequence sequence; EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All)) @@ -160,7 +162,7 @@ TEST_F_S_MOCKED(EnumAvailableDevices) { .RetiresOnSaturation(); EXPECT_CALL(*m_layer, getDisplayScale(_, _)) .Times(1) - .WillOnce(Return(display_device::Rational { 175, 100 })) + .WillOnce(Return(display_device::Rational {175, 100})) .RetiresOnSaturation(); EXPECT_CALL(*m_layer, getHdrState(_)) .Times(1) @@ -173,36 +175,38 @@ TEST_F_S_MOCKED(EnumAvailableDevices) { .RetiresOnSaturation(); const display_device::EnumeratedDeviceList expected_list { - { "DeviceId1", - "DisplayName1", - "FriendlyName1", - display_device::EnumeratedDevice::Info { - { 1920, 1080 }, - display_device::Rational { 0, 1 }, - display_device::Rational { 0, 1 }, - true, - { 0, 0 }, - std::nullopt } }, - { "DeviceId2", - "DisplayName2", - "FriendlyName2", - display_device::EnumeratedDevice::Info { - { 1920, 2160 }, - display_device::Rational { 175, 100 }, - display_device::Rational { 119995, 1000 }, - false, - { 1921, 0 }, - display_device::HdrState::Enabled } }, - { "DeviceId3", - "", - "FriendlyName3", - std::nullopt } + {"DeviceId1", + "DisplayName1", + "FriendlyName1", + display_device::EnumeratedDevice::Info { + {1920, 1080}, + display_device::Rational {0, 1}, + display_device::Rational {0, 1}, + true, + {0, 0}, + std::nullopt + }}, + {"DeviceId2", + "DisplayName2", + "FriendlyName2", + display_device::EnumeratedDevice::Info { + {1920, 2160}, + display_device::Rational {175, 100}, + display_device::Rational {119995, 1000}, + false, + {1921, 0}, + display_device::HdrState::Enabled + }}, + {"DeviceId3", + "", + "FriendlyName3", + std::nullopt} }; EXPECT_EQ(m_win_dd.enumAvailableDevices(), expected_list); } TEST_F_S_MOCKED(EnumAvailableDevices, MissingSourceModes) { - auto pam_missing_modes { ut_consts::PAM_3_ACTIVE }; + auto pam_missing_modes {ut_consts::PAM_3_ACTIVE}; pam_missing_modes->m_paths.resize(2); pam_missing_modes->m_modes.resize(1); @@ -254,20 +258,21 @@ TEST_F_S_MOCKED(EnumAvailableDevices, MissingSourceModes) { .RetiresOnSaturation(); const display_device::EnumeratedDeviceList expected_list { - { "DeviceId1", - "DisplayName1", - "FriendlyName1", - display_device::EnumeratedDevice::Info { - { 1920, 1080 }, - display_device::Rational { 0, 1 }, - display_device::Rational { 120, 1 }, - true, - { 0, 0 }, - std::nullopt } }, - { "DeviceId2", - "DisplayName2", - "FriendlyName2", - std::nullopt } + {"DeviceId1", + "DisplayName1", + "FriendlyName1", + display_device::EnumeratedDevice::Info { + {1920, 1080}, + display_device::Rational {0, 1}, + display_device::Rational {120, 1}, + true, + {0, 0}, + std::nullopt + }}, + {"DeviceId2", + "DisplayName2", + "FriendlyName2", + std::nullopt} }; EXPECT_EQ(m_win_dd.enumAvailableDevices(), expected_list); } @@ -289,18 +294,17 @@ TEST_F_S_MOCKED(EnumAvailableDevices, FailedToCollectSourceData) { } TEST_F_S(GetDisplayName) { - const auto all_devices { m_layer->queryDisplayConfig(display_device::QueryType::All) }; + const auto all_devices {m_layer->queryDisplayConfig(display_device::QueryType::All)}; ASSERT_TRUE(all_devices); for (const auto &path : all_devices->m_paths) { - const auto device_id { m_layer->getDeviceId(path) }; - const auto display_name { m_win_dd.getDisplayName(device_id) }; - const auto active_path { display_device::win_utils::getActivePath(*m_layer, device_id, all_devices->m_paths) }; + const auto device_id {m_layer->getDeviceId(path)}; + const auto display_name {m_win_dd.getDisplayName(device_id)}; + const auto active_path {display_device::win_utils::getActivePath(*m_layer, device_id, all_devices->m_paths)}; if (&path == active_path) { EXPECT_EQ(display_name, m_layer->getDisplayName(path)); - } - else { + } else { EXPECT_EQ(display_name, active_path ? m_layer->getDisplayName(*active_path) : std::string {}); } } diff --git a/tests/unit/windows/test_win_display_device_hdr.cpp b/tests/unit/windows/test_win_display_device_hdr.cpp index f8dabec..985a785 100644 --- a/tests/unit/windows/test_win_display_device_hdr.cpp +++ b/tests/unit/windows/test_win_display_device_hdr.cpp @@ -17,19 +17,17 @@ namespace { // Test fixture(s) for this file class WinDisplayDeviceHdr: public BaseTest { public: - bool - isSystemTest() const override { + bool isSystemTest() const override { return true; } - std::shared_ptr m_layer { std::make_shared() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr m_layer {std::make_shared()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; class WinDisplayDeviceHdrMocked: public BaseTest { public: - void - setupExpectedGetActivePathCall(int id_number, InSequence & /* To ensure that sequence is created outside this scope */) { + void setupExpectedGetActivePathCall(int id_number, InSequence & /* To ensure that sequence is created outside this scope */) { for (int i = 1; i <= id_number; ++i) { EXPECT_CALL(*m_layer, getMonitorDevicePath(_)) .Times(1) @@ -46,8 +44,8 @@ namespace { } } - std::shared_ptr> m_layer { std::make_shared>() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr> m_layer {std::make_shared>()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; // Specialized TEST macro(s) for this test file @@ -55,37 +53,38 @@ namespace { #define TEST_F_S_MOCKED(...) DD_MAKE_TEST(TEST_F, WinDisplayDeviceHdrMocked, __VA_ARGS__) // Helper functions - display_device::ActiveTopology - makeExtendedTopology(const std::vector &device_ids) { + display_device::ActiveTopology makeExtendedTopology(const std::vector &device_ids) { display_device::ActiveTopology topology; for (const auto &device_id : device_ids) { - topology.push_back({ device_id }); + topology.push_back({device_id}); } return topology; } } // namespace TEST_F_S(GetSetHdrStates) { - const auto available_devices { getAvailableDevices(*m_layer) }; + const auto available_devices {getAvailableDevices(*m_layer)}; ASSERT_TRUE(available_devices); - const auto topology_guard { makeTopologyGuard(m_win_dd) }; + const auto topology_guard {makeTopologyGuard(m_win_dd)}; 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 { return static_cast(entry.second); })) { + 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 { + return static_cast(entry.second); + })) { GTEST_SKIP_("No HDR display is available in the system."); } - auto flipped_states { hdr_states }; + auto flipped_states {hdr_states}; for (auto &[key, state] : flipped_states) { state = state ? (*state == display_device::HdrState::Disabled ? - display_device::HdrState::Enabled : - display_device::HdrState::Disabled) : + display_device::HdrState::Enabled : + display_device::HdrState::Disabled) : state; } - const auto hdr_state_guard { makeHdrStateGuard(m_win_dd) }; + const auto hdr_state_guard {makeHdrStateGuard(m_win_dd)}; ASSERT_TRUE(m_win_dd.setHdrStates(flipped_states)); ASSERT_TRUE(m_win_dd.setHdrStates(hdr_states)); } @@ -116,11 +115,11 @@ TEST_F_S_MOCKED(GetHdrStates) { .RetiresOnSaturation(); const display_device::HdrStateMap expected_states { - { "DeviceId1", std::make_optional(display_device::HdrState::Disabled) }, - { "DeviceId2", std::nullopt }, - { "DeviceId3", std::make_optional(display_device::HdrState::Enabled) } + {"DeviceId1", std::make_optional(display_device::HdrState::Disabled)}, + {"DeviceId2", std::nullopt}, + {"DeviceId3", std::make_optional(display_device::HdrState::Enabled)} }; - EXPECT_EQ(m_win_dd.getCurrentHdrStates({ "DeviceId1", "DeviceId2", "DeviceId3" }), expected_states); + EXPECT_EQ(m_win_dd.getCurrentHdrStates({"DeviceId1", "DeviceId2", "DeviceId3"}), expected_states); } TEST_F_S_MOCKED(GetHdrStates, EmptyIdList) { @@ -132,7 +131,7 @@ TEST_F_S_MOCKED(GetHdrStates, FailedToGetDisplayData) { .Times(1) .WillOnce(Return(ut_consts::PAM_NULL)); - EXPECT_EQ(m_win_dd.getCurrentHdrStates({ "DeviceId1" }), display_device::HdrStateMap {}); + EXPECT_EQ(m_win_dd.getCurrentHdrStates({"DeviceId1"}), display_device::HdrStateMap {}); } TEST_F_S_MOCKED(GetHdrStates, FailedToGetActivePath) { @@ -140,7 +139,7 @@ TEST_F_S_MOCKED(GetHdrStates, FailedToGetActivePath) { .Times(1) .WillOnce(Return(ut_consts::PAM_EMPTY)); - EXPECT_EQ(m_win_dd.getCurrentHdrStates({ "DeviceId1" }), display_device::HdrStateMap {}); + EXPECT_EQ(m_win_dd.getCurrentHdrStates({"DeviceId1"}), display_device::HdrStateMap {}); } TEST_F_S_MOCKED(SetHdrStates) { @@ -167,18 +166,18 @@ TEST_F_S_MOCKED(SetHdrStates) { .RetiresOnSaturation(); const display_device::HdrStateMap new_states { - { "DeviceId1", std::make_optional(display_device::HdrState::Enabled) }, - { "DeviceId2", std::nullopt }, - { "DeviceId3", std::make_optional(display_device::HdrState::Enabled) } + {"DeviceId1", std::make_optional(display_device::HdrState::Enabled)}, + {"DeviceId2", std::nullopt}, + {"DeviceId3", std::make_optional(display_device::HdrState::Enabled)} }; EXPECT_TRUE(m_win_dd.setHdrStates(new_states)); } TEST_F_S_MOCKED(SetHdrStates, AllDevicesWithOptStates) { const display_device::HdrStateMap new_states { - { "DeviceId1", std::nullopt }, - { "DeviceId2", std::nullopt }, - { "DeviceId3", std::nullopt } + {"DeviceId1", std::nullopt}, + {"DeviceId2", std::nullopt}, + {"DeviceId3", std::nullopt} }; EXPECT_TRUE(m_win_dd.setHdrStates(new_states)); } @@ -197,9 +196,9 @@ TEST_F_S_MOCKED(SetHdrStates, FailedToGetHdrState) { .RetiresOnSaturation(); const display_device::HdrStateMap new_states { - { "DeviceId1", std::make_optional(display_device::HdrState::Enabled) }, - { "DeviceId2", std::nullopt }, - { "DeviceId3", std::make_optional(display_device::HdrState::Enabled) } + {"DeviceId1", std::make_optional(display_device::HdrState::Enabled)}, + {"DeviceId2", std::nullopt}, + {"DeviceId3", std::make_optional(display_device::HdrState::Enabled)} }; EXPECT_FALSE(m_win_dd.setHdrStates(new_states)); } @@ -250,10 +249,10 @@ TEST_F_S_MOCKED(SetHdrStates, FailedToSetHdrState, LastDevice) { } const display_device::HdrStateMap new_states { - { "DeviceId1", std::make_optional(display_device::HdrState::Enabled) }, - { "DeviceId2", std::nullopt }, - { "DeviceId3", std::make_optional(display_device::HdrState::Disabled) }, - { "DeviceId4", std::make_optional(display_device::HdrState::Enabled) } + {"DeviceId1", std::make_optional(display_device::HdrState::Enabled)}, + {"DeviceId2", std::nullopt}, + {"DeviceId3", std::make_optional(display_device::HdrState::Disabled)}, + {"DeviceId4", std::make_optional(display_device::HdrState::Enabled)} }; EXPECT_FALSE(m_win_dd.setHdrStates(new_states)); } @@ -334,10 +333,10 @@ TEST_F_S_MOCKED(SetHdrStates, FailedToSetHdrState, LastDevice, NoEarlyExitInReco } const display_device::HdrStateMap new_states { - { "DeviceId1", std::make_optional(display_device::HdrState::Enabled) }, - { "DeviceId2", std::make_optional(display_device::HdrState::Enabled) }, - { "DeviceId3", std::make_optional(display_device::HdrState::Enabled) }, - { "DeviceId4", std::make_optional(display_device::HdrState::Enabled) } + {"DeviceId1", std::make_optional(display_device::HdrState::Enabled)}, + {"DeviceId2", std::make_optional(display_device::HdrState::Enabled)}, + {"DeviceId3", std::make_optional(display_device::HdrState::Enabled)}, + {"DeviceId4", std::make_optional(display_device::HdrState::Enabled)} }; EXPECT_FALSE(m_win_dd.setHdrStates(new_states)); } @@ -351,7 +350,7 @@ TEST_F_S_MOCKED(SetHdrStates, FailedToGetDisplayData) { .Times(1) .WillOnce(Return(ut_consts::PAM_NULL)); - EXPECT_FALSE(m_win_dd.setHdrStates({ { "DeviceId1", std::make_optional(display_device::HdrState::Disabled) } })); + EXPECT_FALSE(m_win_dd.setHdrStates({{"DeviceId1", std::make_optional(display_device::HdrState::Disabled)}})); } TEST_F_S_MOCKED(SetHdrStates, FailedToGetActivePath) { @@ -359,5 +358,5 @@ TEST_F_S_MOCKED(SetHdrStates, FailedToGetActivePath) { .Times(1) .WillOnce(Return(ut_consts::PAM_EMPTY)); - EXPECT_FALSE(m_win_dd.setHdrStates({ { "DeviceId1", std::make_optional(display_device::HdrState::Disabled) } })); + EXPECT_FALSE(m_win_dd.setHdrStates({{"DeviceId1", std::make_optional(display_device::HdrState::Disabled)}})); } diff --git a/tests/unit/windows/test_win_display_device_modes.cpp b/tests/unit/windows/test_win_display_device_modes.cpp index db35952..d0b0ab4 100644 --- a/tests/unit/windows/test_win_display_device_modes.cpp +++ b/tests/unit/windows/test_win_display_device_modes.cpp @@ -21,19 +21,17 @@ namespace { // Test fixture(s) for this file class WinDisplayDeviceModes: public BaseTest { public: - bool - isSystemTest() const override { + bool isSystemTest() const override { return true; } - std::shared_ptr m_layer { std::make_shared() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr m_layer {std::make_shared()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; class WinDisplayDeviceModesMocked: public BaseTest { public: - void - setupExpectedGetActivePathCall(int id_number, InSequence & /* To ensure that sequence is created outside this scope */) { + void setupExpectedGetActivePathCall(int id_number, InSequence & /* To ensure that sequence is created outside this scope */) { for (int i = 1; i <= id_number; ++i) { EXPECT_CALL(*m_layer, getMonitorDevicePath(_)) .Times(1) @@ -50,8 +48,7 @@ namespace { } } - void - setupExpectedGetCurrentDisplayModesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &pam = ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES) { + void setupExpectedGetCurrentDisplayModesCall(InSequence &sequence /* To ensure that sequence is created outside this scope */, const std::optional &pam = ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES) { EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::Active)) .Times(1) .WillOnce(Return(pam)) @@ -62,8 +59,7 @@ namespace { } } - void - setupExpectedGetAllDeviceIdsCall(InSequence & /* To ensure that sequence is created outside this scope */, const std::set &entries = { 1, 2, 3, 4 }) { + void setupExpectedGetAllDeviceIdsCall(InSequence & /* To ensure that sequence is created outside this scope */, const std::set &entries = {1, 2, 3, 4}) { EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::Active)) .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)) @@ -102,8 +98,8 @@ namespace { } } - std::shared_ptr> m_layer { std::make_shared>() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr> m_layer {std::make_shared>()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; // Specialized TEST macro(s) for this test file @@ -111,13 +107,12 @@ namespace { #define TEST_F_S_MOCKED(...) DD_MAKE_TEST(TEST_F, WinDisplayDeviceModesMocked, __VA_ARGS__) // Additional convenience global const(s) - const UINT32 RELAXED_FLAGS { SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE | SDC_ALLOW_CHANGES }; - const UINT32 STRICT_FLAGS { SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE }; - const UINT32 UNDO_FLAGS { SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE }; + const UINT32 RELAXED_FLAGS {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE | SDC_ALLOW_CHANGES}; + const UINT32 STRICT_FLAGS {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE}; + const UINT32 UNDO_FLAGS {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE}; // Helper functions - std::optional - applyExpectedModesOntoInput(std::optional input, const display_device::DeviceDisplayModeMap &modes, const std::set &excluded_ids = {}) { + std::optional applyExpectedModesOntoInput(std::optional input, const display_device::DeviceDisplayModeMap &modes, const std::set &excluded_ids = {}) { if (!input) { return std::nullopt; } @@ -127,8 +122,8 @@ namespace { continue; } - auto path_index { std::stoi(device_id.substr(device_id.size() - 1, 1)) - 1 }; - input->m_paths.at(path_index).targetInfo.refreshRate = { mode.m_refresh_rate.m_numerator, mode.m_refresh_rate.m_denominator }; + auto path_index {std::stoi(device_id.substr(device_id.size() - 1, 1)) - 1}; + input->m_paths.at(path_index).targetInfo.refreshRate = {mode.m_refresh_rate.m_numerator, mode.m_refresh_rate.m_denominator}; input->m_modes.at(input->m_paths.at(path_index).sourceInfo.sourceModeInfoIdx).sourceMode.width = mode.m_resolution.m_width; input->m_modes.at(input->m_paths.at(path_index).sourceInfo.sourceModeInfoIdx).sourceMode.height = mode.m_resolution.m_height; @@ -139,104 +134,103 @@ namespace { return input; } - display_device::DisplayMode - getTestMode(const int number) { + display_device::DisplayMode getTestMode(const int number) { if (number == 1) { - return { 1024, 768, { 60, 1 } }; + return {1024, 768, {60, 1}}; } - return { 1920, 1080, { 60, 1 } }; + return {1920, 1080, {60, 1}}; } } // namespace TEST_F_S(GetCurrentDisplayModes) { - const auto flattened_topology { display_device::win_utils::flattenTopology(m_win_dd.getCurrentTopology()) }; - const auto current_modes { m_win_dd.getCurrentDisplayModes(flattened_topology) }; + const auto flattened_topology {display_device::win_utils::flattenTopology(m_win_dd.getCurrentTopology())}; + const auto current_modes {m_win_dd.getCurrentDisplayModes(flattened_topology)}; // Can't really compare anything else without knowing system specs - const auto mode_keys_view { std::ranges::views::keys(current_modes) }; - const std::set mode_keys { std::begin(mode_keys_view), std::end(mode_keys_view) }; + const auto mode_keys_view {std::ranges::views::keys(current_modes)}; + const std::set mode_keys {std::begin(mode_keys_view), std::end(mode_keys_view)}; EXPECT_EQ(flattened_topology, mode_keys); } TEST_F_S(SetCurrentDisplayModes, ExtendedTopology) { - const auto available_devices { getAvailableDevices(*m_layer) }; + const auto available_devices {getAvailableDevices(*m_layer)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 2) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto topology_guard { makeTopologyGuard(m_win_dd) }; - ASSERT_TRUE(m_win_dd.setTopology({ { available_devices->at(0) }, { available_devices->at(1) } })); + const auto topology_guard {makeTopologyGuard(m_win_dd)}; + ASSERT_TRUE(m_win_dd.setTopology({{available_devices->at(0)}, {available_devices->at(1)}})); const display_device::DeviceDisplayModeMap mixed_modes_1 { - { available_devices->at(0), getTestMode(0) }, - { available_devices->at(1), getTestMode(1) } + {available_devices->at(0), getTestMode(0)}, + {available_devices->at(1), getTestMode(1)} }; const display_device::DeviceDisplayModeMap mixed_modes_2 { - { available_devices->at(0), getTestMode(1) }, - { available_devices->at(1), getTestMode(0) } + {available_devices->at(0), getTestMode(1)}, + {available_devices->at(1), getTestMode(0)} }; - const auto mode_guard { makeModeGuard(m_win_dd) }; + const auto mode_guard {makeModeGuard(m_win_dd)}; ASSERT_TRUE(m_win_dd.setDisplayModes(mixed_modes_1)); ASSERT_TRUE(m_win_dd.setDisplayModes(mixed_modes_2)); } TEST_F_S(SetCurrentDisplayModes, DuplicatedTopology) { - const auto available_devices { getAvailableDevices(*m_layer) }; + const auto available_devices {getAvailableDevices(*m_layer)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 2) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto topology_guard { makeTopologyGuard(m_win_dd) }; - ASSERT_TRUE(m_win_dd.setTopology({ { available_devices->at(0), available_devices->at(1) } })); + const auto topology_guard {makeTopologyGuard(m_win_dd)}; + ASSERT_TRUE(m_win_dd.setTopology({{available_devices->at(0), available_devices->at(1)}})); const display_device::DeviceDisplayModeMap same_modes_1 { - { available_devices->at(0), getTestMode(1) }, - { available_devices->at(1), getTestMode(1) } + {available_devices->at(0), getTestMode(1)}, + {available_devices->at(1), getTestMode(1)} }; const display_device::DeviceDisplayModeMap same_modes_2 { - { available_devices->at(0), getTestMode(0) }, - { available_devices->at(1), getTestMode(0) } + {available_devices->at(0), getTestMode(0)}, + {available_devices->at(1), getTestMode(0)} }; const display_device::DeviceDisplayModeMap mixed_modes { - { available_devices->at(0), getTestMode(1) }, - { available_devices->at(1), getTestMode(0) } + {available_devices->at(0), getTestMode(1)}, + {available_devices->at(1), getTestMode(0)} }; - const auto mode_guard { makeModeGuard(m_win_dd) }; + const auto mode_guard {makeModeGuard(m_win_dd)}; ASSERT_TRUE(m_win_dd.setDisplayModes(same_modes_1)); ASSERT_TRUE(m_win_dd.setDisplayModes(same_modes_2)); ASSERT_FALSE(m_win_dd.setDisplayModes(mixed_modes)); } TEST_F_S(SetCurrentDisplayModes, MixedTopology) { - const auto available_devices { getAvailableDevices(*m_layer) }; + const auto available_devices {getAvailableDevices(*m_layer)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 3) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto topology_guard { makeTopologyGuard(m_win_dd) }; - ASSERT_TRUE(m_win_dd.setTopology({ { available_devices->at(0) }, { available_devices->at(1), available_devices->at(2) } })); + const auto topology_guard {makeTopologyGuard(m_win_dd)}; + ASSERT_TRUE(m_win_dd.setTopology({{available_devices->at(0)}, {available_devices->at(1), available_devices->at(2)}})); const display_device::DeviceDisplayModeMap mixed_modes_1 { - { available_devices->at(0), getTestMode(0) }, - { available_devices->at(1), getTestMode(1) }, - { available_devices->at(2), getTestMode(1) } + {available_devices->at(0), getTestMode(0)}, + {available_devices->at(1), getTestMode(1)}, + {available_devices->at(2), getTestMode(1)} }; const display_device::DeviceDisplayModeMap mixed_modes_2 { - { available_devices->at(0), getTestMode(1) }, - { available_devices->at(1), getTestMode(0) }, - { available_devices->at(2), getTestMode(0) } + {available_devices->at(0), getTestMode(1)}, + {available_devices->at(1), getTestMode(0)}, + {available_devices->at(2), getTestMode(0)} }; - const auto mode_guard { makeModeGuard(m_win_dd) }; + const auto mode_guard {makeModeGuard(m_win_dd)}; ASSERT_TRUE(m_win_dd.setDisplayModes(mixed_modes_1)); ASSERT_TRUE(m_win_dd.setDisplayModes(mixed_modes_2)); } @@ -245,18 +239,18 @@ TEST_F_S_MOCKED(GetCurrentDisplayModes) { InSequence sequence; setupExpectedGetCurrentDisplayModesCall(sequence); - const auto current_modes { m_win_dd.getCurrentDisplayModes({ "DeviceId1", "DeviceId2", "DeviceId3", "DeviceId4" }) }; + const auto current_modes {m_win_dd.getCurrentDisplayModes({"DeviceId1", "DeviceId2", "DeviceId3", "DeviceId4"})}; const display_device::DeviceDisplayModeMap expected_modes { - { "DeviceId1", { 1920, 1080, { 120, 1 } } }, - { "DeviceId2", { 1920, 2160, { 119995, 1000 } } }, - { "DeviceId3", { 1920, 2160, { 60, 1 } } }, - { "DeviceId4", { 3840, 2160, { 90, 1 } } }, + {"DeviceId1", {1920, 1080, {120, 1}}}, + {"DeviceId2", {1920, 2160, {119995, 1000}}}, + {"DeviceId3", {1920, 2160, {60, 1}}}, + {"DeviceId4", {3840, 2160, {90, 1}}}, }; EXPECT_EQ(current_modes, expected_modes); } TEST_F_S_MOCKED(GetCurrentDisplayModes, EmptyIdList) { - const auto current_modes { m_win_dd.getCurrentDisplayModes({}) }; + const auto current_modes {m_win_dd.getCurrentDisplayModes({})}; EXPECT_TRUE(current_modes.empty()); } @@ -265,7 +259,7 @@ TEST_F_S_MOCKED(GetCurrentDisplayModes, NoDisplayData) { .Times(1) .WillOnce(Return(ut_consts::PAM_NULL)); - const auto current_modes { m_win_dd.getCurrentDisplayModes({ "DeviceId1" }) }; + const auto current_modes {m_win_dd.getCurrentDisplayModes({"DeviceId1"})}; EXPECT_TRUE(current_modes.empty()); } @@ -274,7 +268,7 @@ TEST_F_S_MOCKED(GetCurrentDisplayModes, EmptyDeviceId) { .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)); - const auto current_modes { m_win_dd.getCurrentDisplayModes({ "", "DeviceId2" }) }; + const auto current_modes {m_win_dd.getCurrentDisplayModes({"", "DeviceId2"})}; EXPECT_TRUE(current_modes.empty()); } @@ -283,12 +277,12 @@ TEST_F_S_MOCKED(GetCurrentDisplayModes, FailedToGetActivePath) { .Times(1) .WillOnce(Return(ut_consts::PAM_EMPTY)); - const auto current_modes { m_win_dd.getCurrentDisplayModes({ "DeviceId1" }) }; + const auto current_modes {m_win_dd.getCurrentDisplayModes({"DeviceId1"})}; EXPECT_TRUE(current_modes.empty()); } TEST_F_S_MOCKED(GetCurrentDisplayModes, FailedToGetSourceMode) { - auto pam_no_modes { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto pam_no_modes {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; pam_no_modes->m_modes.clear(); EXPECT_CALL(*m_layer, getMonitorDevicePath(_)) @@ -304,20 +298,20 @@ TEST_F_S_MOCKED(GetCurrentDisplayModes, FailedToGetSourceMode) { .Times(1) .WillOnce(Return(pam_no_modes)); - const auto current_modes { m_win_dd.getCurrentDisplayModes({ "DeviceId1" }) }; + const auto current_modes {m_win_dd.getCurrentDisplayModes({"DeviceId1"})}; EXPECT_TRUE(current_modes.empty()); } TEST_F_S_MOCKED(SetDisplayModes, Relaxed) { const display_device::DeviceDisplayModeMap new_modes { - { "DeviceId1", { 1920, 1080, { 120, 1 } } }, - { "DeviceId2", { 1920, 1000, { 144, 1 } } }, - { "DeviceId3", { 1000, 1000, { 90, 1 } } }, - { "DeviceId4", { 1000, 2160, { 90, 10 } } }, + {"DeviceId1", {1920, 1080, {120, 1}}}, + {"DeviceId2", {1920, 1000, {144, 1}}}, + {"DeviceId3", {1000, 1000, {90, 1}}}, + {"DeviceId4", {1000, 2160, {90, 10}}}, }; - const auto pam_initial { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; - const auto pam_submitted { applyExpectedModesOntoInput(pam_initial, new_modes, { "DeviceId1" }) }; + const auto pam_initial {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; + const auto pam_submitted {applyExpectedModesOntoInput(pam_initial, new_modes, {"DeviceId1"})}; InSequence sequence; setupExpectedGetAllDeviceIdsCall(sequence); @@ -345,14 +339,14 @@ TEST_F_S_MOCKED(SetDisplayModes, Relaxed) { TEST_F_S_MOCKED(SetDisplayModes, Strict) { const display_device::DeviceDisplayModeMap new_modes { - { "DeviceId1", { 1920, 1080, { 120, 10 } } }, - { "DeviceId2", { 1000, 2160, { 119995, 100 } } }, - { "DeviceId3", { 1000, 1000, { 90, 1 } } }, - { "DeviceId4", { 3840, 2160, { 90, 1 } } }, + {"DeviceId1", {1920, 1080, {120, 10}}}, + {"DeviceId2", {1000, 2160, {119995, 100}}}, + {"DeviceId3", {1000, 1000, {90, 1}}}, + {"DeviceId4", {3840, 2160, {90, 1}}}, }; - const auto pam_initial { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; - const auto pam_submitted { applyExpectedModesOntoInput(pam_initial, new_modes, { "DeviceId4" }) }; + const auto pam_initial {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; + const auto pam_submitted {applyExpectedModesOntoInput(pam_initial, new_modes, {"DeviceId4"})}; InSequence sequence; setupExpectedGetAllDeviceIdsCall(sequence); @@ -402,10 +396,10 @@ TEST_F_S_MOCKED(SetDisplayModes, Strict) { TEST_F_S_MOCKED(SetDisplayModes, NoChanges) { const display_device::DeviceDisplayModeMap new_modes { - { "DeviceId1", { 1920, 1080, { 120, 1 } } }, - { "DeviceId2", { 1920, 2160, { 119995, 1000 } } }, - { "DeviceId3", { 1920, 2160, { 60, 1 } } }, - { "DeviceId4", { 3840, 2160, { 90, 1 } } }, + {"DeviceId1", {1920, 1080, {120, 1}}}, + {"DeviceId2", {1920, 2160, {119995, 1000}}}, + {"DeviceId3", {1920, 2160, {60, 1}}}, + {"DeviceId4", {3840, 2160, {90, 1}}}, }; InSequence sequence; @@ -437,30 +431,30 @@ TEST_F_S_MOCKED(SetDisplayModes, FailedToGetDuplicateDevices) { .WillOnce(Return(ut_consts::PAM_NULL)) .RetiresOnSaturation(); - EXPECT_FALSE(m_win_dd.setDisplayModes({ { "DeviceId1", {} } })); + EXPECT_FALSE(m_win_dd.setDisplayModes({{"DeviceId1", {}}})); } TEST_F_S_MOCKED(SetDisplayModes, MissingDuplicateDisplayModes) { InSequence sequence; - setupExpectedGetAllDeviceIdsCall(sequence, { 2 }); + setupExpectedGetAllDeviceIdsCall(sequence, {2}); - EXPECT_FALSE(m_win_dd.setDisplayModes({ { "DeviceId2", {} } })); + EXPECT_FALSE(m_win_dd.setDisplayModes({{"DeviceId2", {}}})); } TEST_F_S_MOCKED(SetDisplayModes, FailedToGetOriginalData) { InSequence sequence; - setupExpectedGetAllDeviceIdsCall(sequence, { 1 }); + setupExpectedGetAllDeviceIdsCall(sequence, {1}); EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All)) .Times(1) .WillOnce(Return(ut_consts::PAM_NULL)) .RetiresOnSaturation(); - EXPECT_FALSE(m_win_dd.setDisplayModes({ { "DeviceId1", {} } })); + EXPECT_FALSE(m_win_dd.setDisplayModes({{"DeviceId1", {}}})); } TEST_F_S_MOCKED(SetDisplayModes, DoSetModes, FailedToGetDisplayConfig) { InSequence sequence; - setupExpectedGetAllDeviceIdsCall(sequence, { 1 }); + setupExpectedGetAllDeviceIdsCall(sequence, {1}); EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All)) .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)) @@ -470,12 +464,12 @@ TEST_F_S_MOCKED(SetDisplayModes, DoSetModes, FailedToGetDisplayConfig) { .WillOnce(Return(ut_consts::PAM_NULL)) .RetiresOnSaturation(); - EXPECT_FALSE(m_win_dd.setDisplayModes({ { "DeviceId1", {} } })); + EXPECT_FALSE(m_win_dd.setDisplayModes({{"DeviceId1", {}}})); } TEST_F_S_MOCKED(SetDisplayModes, DoSetModes, EmptyListFromGetDisplayConfig) { InSequence sequence; - setupExpectedGetAllDeviceIdsCall(sequence, { 1 }); + setupExpectedGetAllDeviceIdsCall(sequence, {1}); EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All)) .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)) @@ -485,12 +479,12 @@ TEST_F_S_MOCKED(SetDisplayModes, DoSetModes, EmptyListFromGetDisplayConfig) { .WillOnce(Return(ut_consts::PAM_EMPTY)) .RetiresOnSaturation(); - EXPECT_FALSE(m_win_dd.setDisplayModes({ { "DeviceId1", {} } })); + EXPECT_FALSE(m_win_dd.setDisplayModes({{"DeviceId1", {}}})); } TEST_F_S_MOCKED(SetDisplayModes, DoSetModes, FailedToGetActivePath) { InSequence sequence; - setupExpectedGetAllDeviceIdsCall(sequence, { 1 }); + setupExpectedGetAllDeviceIdsCall(sequence, {1}); EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All)) .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)) @@ -504,15 +498,15 @@ TEST_F_S_MOCKED(SetDisplayModes, DoSetModes, FailedToGetActivePath) { .WillOnce(Return("")) .RetiresOnSaturation(); - EXPECT_FALSE(m_win_dd.setDisplayModes({ { "DeviceId1", {} } })); + EXPECT_FALSE(m_win_dd.setDisplayModes({{"DeviceId1", {}}})); } TEST_F_S_MOCKED(SetDisplayModes, DoSetModes, FailedToGetSourceMode) { - auto pam_no_modes { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto pam_no_modes {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; pam_no_modes->m_modes.clear(); InSequence sequence; - setupExpectedGetAllDeviceIdsCall(sequence, { 1 }); + setupExpectedGetAllDeviceIdsCall(sequence, {1}); EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All)) .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)) @@ -523,19 +517,19 @@ TEST_F_S_MOCKED(SetDisplayModes, DoSetModes, FailedToGetSourceMode) { .RetiresOnSaturation(); setupExpectedGetActivePathCall(1, sequence); - EXPECT_FALSE(m_win_dd.setDisplayModes({ { "DeviceId1", {} } })); + EXPECT_FALSE(m_win_dd.setDisplayModes({{"DeviceId1", {}}})); } TEST_F_S_MOCKED(SetDisplayModes, Relaxed, FailedToSetDisplayConfig) { const display_device::DeviceDisplayModeMap new_modes { - { "DeviceId1", { 1920, 1080, { 120, 1 } } }, - { "DeviceId2", { 1920, 1000, { 144, 1 } } }, - { "DeviceId3", { 1000, 1000, { 90, 1 } } }, - { "DeviceId4", { 1000, 2160, { 90, 10 } } }, + {"DeviceId1", {1920, 1080, {120, 1}}}, + {"DeviceId2", {1920, 1000, {144, 1}}}, + {"DeviceId3", {1000, 1000, {90, 1}}}, + {"DeviceId4", {1000, 2160, {90, 10}}}, }; - const auto pam_initial { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; - const auto pam_submitted { applyExpectedModesOntoInput(pam_initial, new_modes, { "DeviceId1" }) }; + const auto pam_initial {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; + const auto pam_submitted {applyExpectedModesOntoInput(pam_initial, new_modes, {"DeviceId1"})}; InSequence sequence; setupExpectedGetAllDeviceIdsCall(sequence); @@ -566,14 +560,14 @@ TEST_F_S_MOCKED(SetDisplayModes, Relaxed, FailedToSetDisplayConfig) { TEST_F_S_MOCKED(SetDisplayModes, Relaxed, FailedToGetCurrentDisplayModes) { const display_device::DeviceDisplayModeMap new_modes { - { "DeviceId1", { 1920, 1080, { 120, 1 } } }, - { "DeviceId2", { 1920, 1000, { 144, 1 } } }, - { "DeviceId3", { 1000, 1000, { 90, 1 } } }, - { "DeviceId4", { 1000, 2160, { 90, 10 } } }, + {"DeviceId1", {1920, 1080, {120, 1}}}, + {"DeviceId2", {1920, 1000, {144, 1}}}, + {"DeviceId3", {1000, 1000, {90, 1}}}, + {"DeviceId4", {1000, 2160, {90, 10}}}, }; - const auto pam_initial { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; - const auto pam_submitted { applyExpectedModesOntoInput(pam_initial, new_modes, { "DeviceId1" }) }; + const auto pam_initial {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; + const auto pam_submitted {applyExpectedModesOntoInput(pam_initial, new_modes, {"DeviceId1"})}; InSequence sequence; setupExpectedGetAllDeviceIdsCall(sequence); @@ -608,14 +602,14 @@ TEST_F_S_MOCKED(SetDisplayModes, Relaxed, FailedToGetCurrentDisplayModes) { TEST_F_S_MOCKED(SetDisplayModes, Strict, FailedToSetDisplayConfig) { const display_device::DeviceDisplayModeMap new_modes { - { "DeviceId1", { 1920, 1080, { 120, 10 } } }, - { "DeviceId2", { 1000, 2160, { 119995, 100 } } }, - { "DeviceId3", { 1000, 1000, { 90, 1 } } }, - { "DeviceId4", { 3840, 2160, { 90, 1 } } }, + {"DeviceId1", {1920, 1080, {120, 10}}}, + {"DeviceId2", {1000, 2160, {119995, 100}}}, + {"DeviceId3", {1000, 1000, {90, 1}}}, + {"DeviceId4", {3840, 2160, {90, 1}}}, }; - const auto pam_initial { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; - const auto pam_submitted { applyExpectedModesOntoInput(pam_initial, new_modes, { "DeviceId4" }) }; + const auto pam_initial {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; + const auto pam_submitted {applyExpectedModesOntoInput(pam_initial, new_modes, {"DeviceId4"})}; InSequence sequence; setupExpectedGetAllDeviceIdsCall(sequence); @@ -672,14 +666,14 @@ TEST_F_S_MOCKED(SetDisplayModes, Strict, FailedToSetDisplayConfig) { TEST_F_S_MOCKED(SetDisplayModes, Strict, FailedToGetCurrentDisplayModes) { const display_device::DeviceDisplayModeMap new_modes { - { "DeviceId1", { 1920, 1080, { 120, 10 } } }, - { "DeviceId2", { 1000, 2160, { 119995, 100 } } }, - { "DeviceId3", { 1000, 1000, { 90, 1 } } }, - { "DeviceId4", { 3840, 2160, { 90, 1 } } }, + {"DeviceId1", {1920, 1080, {120, 10}}}, + {"DeviceId2", {1000, 2160, {119995, 100}}}, + {"DeviceId3", {1000, 1000, {90, 1}}}, + {"DeviceId4", {3840, 2160, {90, 1}}}, }; - const auto pam_initial { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; - const auto pam_submitted { applyExpectedModesOntoInput(pam_initial, new_modes, { "DeviceId4" }) }; + const auto pam_initial {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; + const auto pam_submitted {applyExpectedModesOntoInput(pam_initial, new_modes, {"DeviceId4"})}; InSequence sequence; setupExpectedGetAllDeviceIdsCall(sequence); @@ -736,14 +730,14 @@ TEST_F_S_MOCKED(SetDisplayModes, Strict, FailedToGetCurrentDisplayModes) { TEST_F_S_MOCKED(SetDisplayModes, Strict, ModesDidNotChange) { const display_device::DeviceDisplayModeMap new_modes { - { "DeviceId1", { 1920, 1080, { 120, 10 } } }, - { "DeviceId2", { 1000, 2160, { 119995, 100 } } }, - { "DeviceId3", { 1000, 1000, { 90, 1 } } }, - { "DeviceId4", { 3840, 2160, { 90, 1 } } }, + {"DeviceId1", {1920, 1080, {120, 10}}}, + {"DeviceId2", {1000, 2160, {119995, 100}}}, + {"DeviceId3", {1000, 1000, {90, 1}}}, + {"DeviceId4", {3840, 2160, {90, 1}}}, }; - const auto pam_initial { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; - const auto pam_submitted { applyExpectedModesOntoInput(pam_initial, new_modes, { "DeviceId4" }) }; + const auto pam_initial {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; + const auto pam_submitted {applyExpectedModesOntoInput(pam_initial, new_modes, {"DeviceId4"})}; InSequence sequence; setupExpectedGetAllDeviceIdsCall(sequence); diff --git a/tests/unit/windows/test_win_display_device_primary.cpp b/tests/unit/windows/test_win_display_device_primary.cpp index 9fb1659..3548c52 100644 --- a/tests/unit/windows/test_win_display_device_primary.cpp +++ b/tests/unit/windows/test_win_display_device_primary.cpp @@ -18,19 +18,17 @@ namespace { // Test fixture(s) for this file class WinDisplayDevicePrimary: public BaseTest { public: - bool - isSystemTest() const override { + bool isSystemTest() const override { return true; } - std::shared_ptr m_layer { std::make_shared() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr m_layer {std::make_shared()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; class WinDisplayDevicePrimaryMocked: public BaseTest { public: - void - setupExpectedGetActivePathCall(int id_number, InSequence & /* To ensure that sequence is created outside this scope */) { + void setupExpectedGetActivePathCall(int id_number, InSequence & /* To ensure that sequence is created outside this scope */) { for (int i = 1; i <= id_number; ++i) { EXPECT_CALL(*m_layer, getMonitorDevicePath(_)) .Times(1) @@ -47,8 +45,8 @@ namespace { } } - std::shared_ptr> m_layer { std::make_shared>() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr> m_layer {std::make_shared>()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; // Specialized TEST macro(s) for this test file @@ -56,66 +54,67 @@ namespace { #define TEST_F_S_MOCKED(...) DD_MAKE_TEST(TEST_F, WinDisplayDevicePrimaryMocked, __VA_ARGS__) // Additional convenience global const(s) - const UINT32 FLAGS { SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE }; + const UINT32 FLAGS {SDC_APPLY | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_SAVE_TO_DATABASE | SDC_VIRTUAL_MODE_AWARE}; // Helper functions - void - shiftModeBy(std::optional &pam, int path_index, POINTL point) { - auto &mode { pam->m_modes.at(pam->m_paths.at(path_index).sourceInfo.sourceModeInfoIdx) }; + void shiftModeBy(std::optional &pam, int path_index, POINTL point) { + auto &mode {pam->m_modes.at(pam->m_paths.at(path_index).sourceInfo.sourceModeInfoIdx)}; mode.sourceMode.position.x -= point.x; mode.sourceMode.position.y -= point.y; } } // namespace TEST_F_S(IsPrimary) { - const auto flat_topology { display_device::win_utils::flattenTopology(m_win_dd.getCurrentTopology()) }; - EXPECT_TRUE(std::ranges::any_of(flat_topology, [&](auto device_id) { return m_win_dd.isPrimary(device_id); })); + const auto flat_topology {display_device::win_utils::flattenTopology(m_win_dd.getCurrentTopology())}; + EXPECT_TRUE(std::ranges::any_of(flat_topology, [&](auto device_id) { + return m_win_dd.isPrimary(device_id); + })); } TEST_F_S(SetAsPrimary, ExtendedTopology) { - const auto available_devices { getAvailableDevices(*m_layer) }; + const auto available_devices {getAvailableDevices(*m_layer)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 2) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto topology_guard { makeTopologyGuard(m_win_dd) }; - ASSERT_TRUE(m_win_dd.setTopology({ { available_devices->at(0) }, { available_devices->at(1) } })); + const auto topology_guard {makeTopologyGuard(m_win_dd)}; + ASSERT_TRUE(m_win_dd.setTopology({{available_devices->at(0)}, {available_devices->at(1)}})); - const auto primary_guard { makePrimaryGuard(m_win_dd) }; + const auto primary_guard {makePrimaryGuard(m_win_dd)}; ASSERT_TRUE(m_win_dd.setAsPrimary(available_devices->at(0))); ASSERT_TRUE(m_win_dd.setAsPrimary(available_devices->at(1))); } TEST_F_S(SetAsPrimary, DuplicatedTopology) { - const auto available_devices { getAvailableDevices(*m_layer) }; + const auto available_devices {getAvailableDevices(*m_layer)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 2) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto topology_guard { makeTopologyGuard(m_win_dd) }; - ASSERT_TRUE(m_win_dd.setTopology({ { available_devices->at(0), available_devices->at(1) } })); + const auto topology_guard {makeTopologyGuard(m_win_dd)}; + ASSERT_TRUE(m_win_dd.setTopology({{available_devices->at(0), available_devices->at(1)}})); - const auto primary_guard { makePrimaryGuard(m_win_dd) }; + const auto primary_guard {makePrimaryGuard(m_win_dd)}; ASSERT_TRUE(m_win_dd.setAsPrimary(available_devices->at(0))); ASSERT_TRUE(m_win_dd.setAsPrimary(available_devices->at(1))); } TEST_F_S(SetAsPrimary, MixedTopology) { - const auto available_devices { getAvailableDevices(*m_layer) }; + const auto available_devices {getAvailableDevices(*m_layer)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 3) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto topology_guard { makeTopologyGuard(m_win_dd) }; - ASSERT_TRUE(m_win_dd.setTopology({ { available_devices->at(0) }, { available_devices->at(1), available_devices->at(2) } })); + const auto topology_guard {makeTopologyGuard(m_win_dd)}; + ASSERT_TRUE(m_win_dd.setTopology({{available_devices->at(0)}, {available_devices->at(1), available_devices->at(2)}})); - const auto primary_guard { makePrimaryGuard(m_win_dd) }; + const auto primary_guard {makePrimaryGuard(m_win_dd)}; ASSERT_TRUE(m_win_dd.setAsPrimary(available_devices->at(0))); ASSERT_TRUE(m_win_dd.setAsPrimary(available_devices->at(1))); ASSERT_TRUE(m_win_dd.setAsPrimary(available_devices->at(2))); @@ -163,7 +162,7 @@ TEST_F_S_MOCKED(IsPrimary, FailedToGetActivePath) { } TEST_F_S_MOCKED(IsPrimary, FailedToGetSourceMode) { - auto pam_no_modes { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto pam_no_modes {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; pam_no_modes->m_modes.clear(); InSequence sequence; @@ -186,10 +185,10 @@ TEST_F_S_MOCKED(SetAsPrimary, AlreadyPrimary) { } TEST_F_S_MOCKED(SetAsPrimary, DuplicatePrimaryDevicesSet) { - const auto initial_pam { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + const auto initial_pam {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; - auto origin_point { initial_pam->m_modes.at(initial_pam->m_paths.at(1).sourceInfo.sourceModeInfoIdx).sourceMode.position }; - auto expected_pam { initial_pam }; + auto origin_point {initial_pam->m_modes.at(initial_pam->m_paths.at(1).sourceInfo.sourceModeInfoIdx).sourceMode.position}; + auto expected_pam {initial_pam}; shiftModeBy(expected_pam, 0, origin_point); shiftModeBy(expected_pam, 1, origin_point); shiftModeBy(expected_pam, 2, origin_point); @@ -216,10 +215,10 @@ TEST_F_S_MOCKED(SetAsPrimary, DuplicatePrimaryDevicesSet) { } TEST_F_S_MOCKED(SetAsPrimary, NonDuplicatePrimaryDeviceSet) { - const auto initial_pam { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + const auto initial_pam {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; - auto origin_point { initial_pam->m_modes.at(initial_pam->m_paths.at(3).sourceInfo.sourceModeInfoIdx).sourceMode.position }; - auto expected_pam { initial_pam }; + auto origin_point {initial_pam->m_modes.at(initial_pam->m_paths.at(3).sourceInfo.sourceModeInfoIdx).sourceMode.position}; + auto expected_pam {initial_pam}; shiftModeBy(expected_pam, 0, origin_point); shiftModeBy(expected_pam, 1, origin_point); shiftModeBy(expected_pam, 2, origin_point); @@ -246,11 +245,11 @@ TEST_F_S_MOCKED(SetAsPrimary, NonDuplicatePrimaryDeviceSet) { } TEST_F_S_MOCKED(SetAsPrimary, SharedModeShiftedOnce) { - auto initial_pam { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto initial_pam {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; initial_pam->m_paths.at(2).sourceInfo.sourceModeInfoIdx = initial_pam->m_paths.at(1).sourceInfo.sourceModeInfoIdx; - auto origin_point { initial_pam->m_modes.at(initial_pam->m_paths.at(1).sourceInfo.sourceModeInfoIdx).sourceMode.position }; - auto expected_pam { initial_pam }; + auto origin_point {initial_pam->m_modes.at(initial_pam->m_paths.at(1).sourceInfo.sourceModeInfoIdx).sourceMode.position}; + auto expected_pam {initial_pam}; shiftModeBy(expected_pam, 0, origin_point); shiftModeBy(expected_pam, 1, origin_point); shiftModeBy(expected_pam, 3, origin_point); @@ -296,7 +295,7 @@ TEST_F_S_MOCKED(SetAsPrimary, FailedToGetActivePath) { } TEST_F_S_MOCKED(SetAsPrimary, FailedToGetSourceMode) { - auto pam_no_modes { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto pam_no_modes {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; pam_no_modes->m_modes.clear(); InSequence sequence; @@ -309,7 +308,7 @@ TEST_F_S_MOCKED(SetAsPrimary, FailedToGetSourceMode) { } TEST_F_S_MOCKED(SetAsPrimary, FailedToGetSourceIndex, DuringShift) { - auto pam_invalid_mode_idx { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto pam_invalid_mode_idx {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; display_device::win_utils::setSourceIndex(pam_invalid_mode_idx->m_paths.at(0), std::nullopt); InSequence sequence; @@ -326,7 +325,7 @@ TEST_F_S_MOCKED(SetAsPrimary, FailedToGetSourceIndex, DuringShift) { } TEST_F_S_MOCKED(SetAsPrimary, FailedToGetSourceMode, DuringShift) { - auto pam_invalid_mode_type { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + auto pam_invalid_mode_type {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; pam_invalid_mode_type->m_modes.at(pam_invalid_mode_type->m_paths.at(0).sourceInfo.sourceModeInfoIdx).infoType = DISPLAYCONFIG_MODE_INFO_TYPE_TARGET; InSequence sequence; @@ -343,10 +342,10 @@ TEST_F_S_MOCKED(SetAsPrimary, FailedToGetSourceMode, DuringShift) { } TEST_F_S_MOCKED(SetAsPrimary, FailedToSetDisplayConfig) { - const auto initial_pam { ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES }; + const auto initial_pam {ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES}; - auto origin_point { initial_pam->m_modes.at(initial_pam->m_paths.at(3).sourceInfo.sourceModeInfoIdx).sourceMode.position }; - auto expected_pam { initial_pam }; + auto origin_point {initial_pam->m_modes.at(initial_pam->m_paths.at(3).sourceInfo.sourceModeInfoIdx).sourceMode.position}; + auto expected_pam {initial_pam}; shiftModeBy(expected_pam, 0, origin_point); shiftModeBy(expected_pam, 1, origin_point); shiftModeBy(expected_pam, 2, origin_point); diff --git a/tests/unit/windows/test_win_display_device_topology.cpp b/tests/unit/windows/test_win_display_device_topology.cpp index b756fae..8ada0f7 100644 --- a/tests/unit/windows/test_win_display_device_topology.cpp +++ b/tests/unit/windows/test_win_display_device_topology.cpp @@ -18,19 +18,17 @@ namespace { // Test fixture(s) for this file class WinDisplayDeviceTopology: public BaseTest { public: - bool - isSystemTest() const override { + bool isSystemTest() const override { return true; } - std::shared_ptr m_layer { std::make_shared() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr m_layer {std::make_shared()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; class WinDisplayDeviceTopologyMocked: public BaseTest { public: - void - setupExpectCallFor3ActivePathsAndModes(const display_device::QueryType query_type, InSequence & /* To ensure that sequence is created outside this scope */) { + void setupExpectCallFor3ActivePathsAndModes(const display_device::QueryType query_type, InSequence & /* To ensure that sequence is created outside this scope */) { EXPECT_CALL(*m_layer, queryDisplayConfig(query_type)) .Times(1) .WillOnce(Return(ut_consts::PAM_3_ACTIVE)) @@ -52,9 +50,8 @@ namespace { } } - static std::vector - getExpectedPathToBeSet() { - auto path { ut_consts::PAM_3_ACTIVE->m_paths.at(0) }; + static std::vector getExpectedPathToBeSet() { + auto path {ut_consts::PAM_3_ACTIVE->m_paths.at(0)}; display_device::win_utils::setCloneGroupId(path, 0); display_device::win_utils::setSourceIndex(path, std::nullopt); @@ -62,11 +59,11 @@ namespace { display_device::win_utils::setDesktopIndex(path, std::nullopt); display_device::win_utils::setActive(path); - return std::vector { path }; + return std::vector {path}; }; - std::shared_ptr> m_layer { std::make_shared>() }; - display_device::WinDisplayDevice m_win_dd { m_layer }; + std::shared_ptr> m_layer {std::make_shared>()}; + display_device::WinDisplayDevice m_win_dd {m_layer}; }; // Specialized TEST macro(s) for this test file @@ -76,7 +73,7 @@ namespace { } // namespace TEST_F_S(GetCurrentTopology) { - const auto active_devices { m_layer->queryDisplayConfig(display_device::QueryType::Active) }; + const auto active_devices {m_layer->queryDisplayConfig(display_device::QueryType::Active)}; ASSERT_TRUE(active_devices); if (active_devices->m_paths.empty()) { @@ -85,7 +82,7 @@ TEST_F_S(GetCurrentTopology) { std::set expected_devices; for (const auto &path : active_devices->m_paths) { - const auto device_id { m_layer->getDeviceId(path) }; + const auto device_id {m_layer->getDeviceId(path)}; EXPECT_FALSE(device_id.empty()); EXPECT_TRUE(expected_devices.insert(device_id).second); } @@ -95,60 +92,60 @@ TEST_F_S(GetCurrentTopology) { } TEST_F_S(SetCurrentTopology, ExtendedTopology) { - const auto available_devices { getAvailableDevices(*m_layer, false) }; + const auto available_devices {getAvailableDevices(*m_layer, false)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 2) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto cleanup_guard { makeTopologyGuard(m_win_dd) }; + const auto cleanup_guard {makeTopologyGuard(m_win_dd)}; // We are changing to a single device to ensure that we are not in the "final" state - const display_device::ActiveTopology single_device_topology { { available_devices->at(0) } }; + const display_device::ActiveTopology single_device_topology {{available_devices->at(0)}}; ASSERT_TRUE(m_win_dd.setTopology(single_device_topology)); // We are limiting ourselves to 3 devices only to avoid GPU limitation issues (even if very unlikely) - display_device::ActiveTopology multiple_device_topology { { available_devices->at(0) }, { available_devices->at(1) } }; + display_device::ActiveTopology multiple_device_topology {{available_devices->at(0)}, {available_devices->at(1)}}; if (available_devices->size() > 2) { - multiple_device_topology.push_back({ available_devices->at(2) }); + multiple_device_topology.push_back({available_devices->at(2)}); } ASSERT_TRUE(m_win_dd.setTopology(multiple_device_topology)); } TEST_F_S(SetCurrentTopology, DuplicatedTopology) { - const auto available_devices { getAvailableDevices(*m_layer, false) }; + const auto available_devices {getAvailableDevices(*m_layer, false)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 2) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto cleanup_guard { makeTopologyGuard(m_win_dd) }; + const auto cleanup_guard {makeTopologyGuard(m_win_dd)}; // We are changing to a single device to ensure that we are not in the "final" state - const display_device::ActiveTopology single_device_topology { { available_devices->at(0) } }; + const display_device::ActiveTopology single_device_topology {{available_devices->at(0)}}; ASSERT_TRUE(m_win_dd.setTopology(single_device_topology)); - display_device::ActiveTopology multiple_device_topology { { available_devices->at(0), available_devices->at(1) } }; + display_device::ActiveTopology multiple_device_topology {{available_devices->at(0), available_devices->at(1)}}; ASSERT_TRUE(m_win_dd.setTopology(multiple_device_topology)); } TEST_F_S(SetCurrentTopology, MixedTopology) { - const auto available_devices { getAvailableDevices(*m_layer, false) }; + const auto available_devices {getAvailableDevices(*m_layer, false)}; ASSERT_TRUE(available_devices); if (available_devices->size() < 3) { GTEST_SKIP_("Not enough devices are available in the system."); } - const auto cleanup_guard { makeTopologyGuard(m_win_dd) }; + const auto cleanup_guard {makeTopologyGuard(m_win_dd)}; // We are changing to a single device to ensure that we are not in the "final" state - const display_device::ActiveTopology single_device_topology { { available_devices->at(0) } }; + const display_device::ActiveTopology single_device_topology {{available_devices->at(0)}}; ASSERT_TRUE(m_win_dd.setTopology(single_device_topology)); - display_device::ActiveTopology multiple_device_topology { { available_devices->at(0), available_devices->at(1) }, { available_devices->at(2) } }; + display_device::ActiveTopology multiple_device_topology {{available_devices->at(0), available_devices->at(1)}, {available_devices->at(2)}}; ASSERT_TRUE(m_win_dd.setTopology(multiple_device_topology)); } @@ -156,7 +153,7 @@ TEST_F_S_MOCKED(GetCurrentTopology, ExtendedDisplaysOnly) { InSequence sequence; setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::Active, sequence); - const display_device::ActiveTopology expected_topology { { "DeviceId1" }, { "DeviceId2" }, { "DeviceId3" } }; + const display_device::ActiveTopology expected_topology {{"DeviceId1"}, {"DeviceId2"}, {"DeviceId3"}}; EXPECT_EQ(m_win_dd.getCurrentTopology(), expected_topology); } @@ -177,7 +174,7 @@ TEST_F_S_MOCKED(GetCurrentTopology, ExtendedAndDuplicatedDisplays) { .Times(1) .WillOnce(Return(ut_consts::PAM_4_ACTIVE_WITH_2_DUPLICATES)); - const display_device::ActiveTopology expected_topology { { "DeviceId1" }, { "DeviceId2", "DeviceId3" }, { "DeviceId4" } }; + const display_device::ActiveTopology expected_topology {{"DeviceId1"}, {"DeviceId2", "DeviceId3"}, {"DeviceId4"}}; EXPECT_EQ(m_win_dd.getCurrentTopology(), expected_topology); } @@ -217,7 +214,7 @@ TEST_F_S_MOCKED(GetCurrentTopology, TransientDisplayIssues) { .Times(1) .WillOnce(Return(ut_consts::PAM_3_ACTIVE)); - const display_device::ActiveTopology expected_topology { { "DeviceId1" }, { "DeviceId3" } }; + const display_device::ActiveTopology expected_topology {{"DeviceId1"}, {"DeviceId3"}}; EXPECT_EQ(m_win_dd.getCurrentTopology(), expected_topology); } @@ -240,31 +237,31 @@ TEST_F_S_MOCKED(GetCurrentTopology, NullDeviceList) { } TEST_F_S_MOCKED(IsTopologyValid) { - EXPECT_EQ(m_win_dd.isTopologyValid({ /* no groups */ }), false); - EXPECT_EQ(m_win_dd.isTopologyValid({ { /* empty group */ } }), false); - EXPECT_EQ(m_win_dd.isTopologyValid({ { "ID_1" } }), true); - EXPECT_EQ(m_win_dd.isTopologyValid({ { "ID_1" }, { "ID_2" } }), true); - EXPECT_EQ(m_win_dd.isTopologyValid({ { "ID_1", "ID_2" } }), true); - EXPECT_EQ(m_win_dd.isTopologyValid({ { "ID_1", "ID_1" } }), false); - EXPECT_EQ(m_win_dd.isTopologyValid({ { "ID_1" }, { "ID_1" } }), false); - EXPECT_EQ(m_win_dd.isTopologyValid({ { "ID_1", "ID_2", "ID_3" } }), false); - EXPECT_EQ(m_win_dd.isTopologyValid({ { "ID_1" }, { "ID_2" }, { "ID_3" }, { "ID_4" }, { "ID_5" } }), true); + EXPECT_EQ(m_win_dd.isTopologyValid({/* no groups */}), false); + EXPECT_EQ(m_win_dd.isTopologyValid({{/* empty group */}}), false); + EXPECT_EQ(m_win_dd.isTopologyValid({{"ID_1"}}), true); + EXPECT_EQ(m_win_dd.isTopologyValid({{"ID_1"}, {"ID_2"}}), true); + EXPECT_EQ(m_win_dd.isTopologyValid({{"ID_1", "ID_2"}}), true); + EXPECT_EQ(m_win_dd.isTopologyValid({{"ID_1", "ID_1"}}), false); + EXPECT_EQ(m_win_dd.isTopologyValid({{"ID_1"}, {"ID_1"}}), false); + EXPECT_EQ(m_win_dd.isTopologyValid({{"ID_1", "ID_2", "ID_3"}}), false); + EXPECT_EQ(m_win_dd.isTopologyValid({{"ID_1"}, {"ID_2"}, {"ID_3"}, {"ID_4"}, {"ID_5"}}), true); } TEST_F_S_MOCKED(isTopologyTheSame) { - EXPECT_EQ(m_win_dd.isTopologyTheSame({ /* no groups */ }, { /* no groups */ }), true); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { /* empty group */ } }, { { /* empty group */ } }), true); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { /* empty group */ } }, { { /* empty group */ }, { /* empty group */ } }), false); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1" } }, { { "ID_1" } }), true); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1" } }, { { "ID_1" }, { "ID_2" } }), false); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1" }, { "ID_2" } }, { { "ID_1" }, { "ID_2" } }), true); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1" }, { "ID_2" } }, { { "ID_2" }, { "ID_1" } }), true); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1" }, { "ID_2" } }, { { "ID_1", "ID_2" } }), false); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1", "ID_2" } }, { { "ID_1", "ID_2" } }), true); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1", "ID_2" } }, { { "ID_2", "ID_1" } }), true); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1", "ID_2" } }, { { "ID_2", "ID_1" }, { "ID_3" } }), false); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_1", "ID_2" }, { "ID_3" } }, { { "ID_2", "ID_1" }, { "ID_3" } }), true); - EXPECT_EQ(m_win_dd.isTopologyTheSame({ { "ID_3" }, { "ID_1", "ID_2" } }, { { "ID_2", "ID_1" }, { "ID_3" } }), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({/* no groups */}, {/* no groups */}), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{/* empty group */}}, {{/* empty group */}}), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{/* empty group */}}, {{/* empty group */}, {/* empty group */}}), false); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1"}}, {{"ID_1"}}), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1"}}, {{"ID_1"}, {"ID_2"}}), false); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1"}, {"ID_2"}}, {{"ID_1"}, {"ID_2"}}), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1"}, {"ID_2"}}, {{"ID_2"}, {"ID_1"}}), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1"}, {"ID_2"}}, {{"ID_1", "ID_2"}}), false); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1", "ID_2"}}, {{"ID_1", "ID_2"}}), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1", "ID_2"}}, {{"ID_2", "ID_1"}}), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1", "ID_2"}}, {{"ID_2", "ID_1"}, {"ID_3"}}), false); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_1", "ID_2"}, {"ID_3"}}, {{"ID_2", "ID_1"}, {"ID_3"}}), true); + EXPECT_EQ(m_win_dd.isTopologyTheSame({{"ID_3"}, {"ID_1", "ID_2"}}, {{"ID_2", "ID_1"}, {"ID_3"}}), true); } TEST_F_S_MOCKED(SetCurrentTopology) { @@ -272,15 +269,15 @@ TEST_F_S_MOCKED(SetCurrentTopology) { setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::Active, sequence); setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::All, sequence); - auto expected_path { ut_consts::PAM_3_ACTIVE->m_paths.at(0) }; + auto expected_path {ut_consts::PAM_3_ACTIVE->m_paths.at(0)}; display_device::win_utils::setCloneGroupId(expected_path, 0); display_device::win_utils::setSourceIndex(expected_path, std::nullopt); display_device::win_utils::setTargetIndex(expected_path, std::nullopt); display_device::win_utils::setDesktopIndex(expected_path, std::nullopt); display_device::win_utils::setActive(expected_path); - UINT32 expected_flags { SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE }; - EXPECT_CALL(*m_layer, setDisplayConfig(std::vector { expected_path }, std::vector {}, expected_flags)) + UINT32 expected_flags {SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE}; + EXPECT_CALL(*m_layer, setDisplayConfig(std::vector {expected_path}, std::vector {}, expected_flags)) .Times(1) .WillOnce(Return(ERROR_SUCCESS)); @@ -288,8 +285,9 @@ TEST_F_S_MOCKED(SetCurrentTopology) { EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::Active)) .Times(1) .WillOnce(Return(display_device::PathAndModeData { - { ut_consts::PAM_3_ACTIVE->m_paths.at(0) }, - { ut_consts::PAM_3_ACTIVE->m_modes.at(0) } })) + {ut_consts::PAM_3_ACTIVE->m_paths.at(0)}, + {ut_consts::PAM_3_ACTIVE->m_modes.at(0)} + })) .RetiresOnSaturation(); EXPECT_CALL(*m_layer, getMonitorDevicePath(_)) .Times(1) @@ -304,7 +302,7 @@ TEST_F_S_MOCKED(SetCurrentTopology) { .WillOnce(Return("DisplayName1")) .RetiresOnSaturation(); - EXPECT_TRUE(m_win_dd.setTopology({ { "DeviceId1" } })); + EXPECT_TRUE(m_win_dd.setTopology({{"DeviceId1"}})); } TEST_F_S_MOCKED(SetCurrentTopology, InvalidTopologyProvided) { @@ -316,14 +314,14 @@ TEST_F_S_MOCKED(SetCurrentTopology, FailedToGetCurrentTopology) { .Times(1) .WillOnce(Return(ut_consts::PAM_NULL)); - EXPECT_FALSE(m_win_dd.setTopology({ { "DeviceId1" } })); + EXPECT_FALSE(m_win_dd.setTopology({{"DeviceId1"}})); } TEST_F_S_MOCKED(SetCurrentTopology, CurrentTopologyIsTheSame) { InSequence sequence; setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::Active, sequence); - const display_device::ActiveTopology current_topology { { "DeviceId1" }, { "DeviceId2" }, { "DeviceId3" } }; + const display_device::ActiveTopology current_topology {{"DeviceId1"}, {"DeviceId2"}, {"DeviceId3"}}; EXPECT_TRUE(m_win_dd.setTopology(current_topology)); } @@ -334,7 +332,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, FailedToQueryForAllDevices) { .Times(1) .WillOnce(Return(ut_consts::PAM_NULL)); - EXPECT_FALSE(m_win_dd.setTopology({ { "DeviceId1" } })); + EXPECT_FALSE(m_win_dd.setTopology({{"DeviceId1"}})); } TEST_F_S_MOCKED(SetCurrentTopology, DevicePathsAreNoLongerAvailable) { @@ -344,7 +342,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, DevicePathsAreNoLongerAvailable) { .Times(1) .WillOnce(Return(ut_consts::PAM_EMPTY)); - EXPECT_FALSE(m_win_dd.setTopology({ { "DeviceId1" } })); + EXPECT_FALSE(m_win_dd.setTopology({{"DeviceId1"}})); } TEST_F_S_MOCKED(SetCurrentTopology, FailedToMakePathSourceData) { @@ -352,7 +350,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, FailedToMakePathSourceData) { setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::Active, sequence); setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::All, sequence); - EXPECT_FALSE(m_win_dd.setTopology({ { "DeviceIdUnknown" } })); + EXPECT_FALSE(m_win_dd.setTopology({{"DeviceIdUnknown"}})); } TEST_F_S_MOCKED(SetCurrentTopology, WindowsDoesNotKnowAboutTheTopology, FailedToSetTopology) { @@ -360,7 +358,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, WindowsDoesNotKnowAboutTheTopology, FailedTo setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::Active, sequence); setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::All, sequence); - UINT32 expected_flags { SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE }; + UINT32 expected_flags {SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE}; EXPECT_CALL(*m_layer, setDisplayConfig(getExpectedPathToBeSet(), std::vector {}, expected_flags)) .Times(1) .WillOnce(Return(ERROR_GEN_FAILURE)); @@ -378,7 +376,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, WindowsDoesNotKnowAboutTheTopology, FailedTo .Times(1) .WillRepeatedly(Return("ErrorDesc")); - EXPECT_FALSE(m_win_dd.setTopology({ { "DeviceId1" } })); + EXPECT_FALSE(m_win_dd.setTopology({{"DeviceId1"}})); } TEST_F_S_MOCKED(SetCurrentTopology, FailedToSetTopology, NoRecovery) { @@ -386,7 +384,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, FailedToSetTopology, NoRecovery) { setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::Active, sequence); setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::All, sequence); - UINT32 expected_flags { SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE }; + UINT32 expected_flags {SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE}; EXPECT_CALL(*m_layer, setDisplayConfig(getExpectedPathToBeSet(), std::vector {}, expected_flags)) .Times(1) .WillOnce(Return(ERROR_INVALID_PARAMETER)); @@ -395,7 +393,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, FailedToSetTopology, NoRecovery) { .Times(1) .WillRepeatedly(Return("ErrorDesc")); - EXPECT_FALSE(m_win_dd.setTopology({ { "DeviceId1" } })); + EXPECT_FALSE(m_win_dd.setTopology({{"DeviceId1"}})); } TEST_F_S_MOCKED(SetCurrentTopology, TopologyWasSetAccordingToWinApi, CouldNotGetCurrentTopologyToVerify) { @@ -403,7 +401,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, TopologyWasSetAccordingToWinApi, CouldNotGet setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::Active, sequence); setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::All, sequence); - UINT32 expected_flags { SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE }; + UINT32 expected_flags {SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE}; EXPECT_CALL(*m_layer, setDisplayConfig(getExpectedPathToBeSet(), std::vector {}, expected_flags)) .Times(1) .WillOnce(Return(ERROR_SUCCESS)); @@ -419,7 +417,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, TopologyWasSetAccordingToWinApi, CouldNotGet .Times(1) .WillOnce(Return(ERROR_SUCCESS)); - EXPECT_FALSE(m_win_dd.setTopology({ { "DeviceId1" } })); + EXPECT_FALSE(m_win_dd.setTopology({{"DeviceId1"}})); } TEST_F_S_MOCKED(SetCurrentTopology, TopologyWasSetAccordingToWinApi, WinApiLied) { @@ -427,7 +425,7 @@ TEST_F_S_MOCKED(SetCurrentTopology, TopologyWasSetAccordingToWinApi, WinApiLied) setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::Active, sequence); setupExpectCallFor3ActivePathsAndModes(display_device::QueryType::All, sequence); - UINT32 expected_flags { SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE }; + UINT32 expected_flags {SDC_APPLY | SDC_TOPOLOGY_SUPPLIED | SDC_ALLOW_PATH_ORDER_CHANGES | SDC_VIRTUAL_MODE_AWARE}; EXPECT_CALL(*m_layer, setDisplayConfig(getExpectedPathToBeSet(), std::vector {}, expected_flags)) .Times(1) .WillOnce(Return(ERROR_SUCCESS)); @@ -441,5 +439,5 @@ TEST_F_S_MOCKED(SetCurrentTopology, TopologyWasSetAccordingToWinApi, WinApiLied) .Times(1) .WillOnce(Return(ERROR_SUCCESS)); - EXPECT_FALSE(m_win_dd.setTopology({ { "DeviceId1" } })); + EXPECT_FALSE(m_win_dd.setTopology({{"DeviceId1"}})); } diff --git a/tests/unit/windows/test_win_playground.cpp b/tests/unit/windows/test_win_playground.cpp index f999513..f87bbb9 100644 --- a/tests/unit/windows/test_win_playground.cpp +++ b/tests/unit/windows/test_win_playground.cpp @@ -14,25 +14,24 @@ namespace { class GTEST_DISABLED_CLASS_NAME(WinPlayground): public BaseTest { public: - bool - isOutputSuppressed() const override { + bool isOutputSuppressed() const override { return false; } - std::optional - getDefaultLogLevel() const override { + std::optional getDefaultLogLevel() const override { // Unless user explicitly has overriden the level via ENV, we don't want all // that noise from verbose logs... return BaseTest::getDefaultLogLevel().value_or(display_device::Logger::LogLevel::info); } - display_device::SettingsManager & - getImpl(const display_device::WinWorkarounds &workarounds = {}) { + display_device::SettingsManager &getImpl(const display_device::WinWorkarounds &workarounds = {}) { if (!m_impl) { m_impl = std::make_unique( std::make_shared(std::make_shared()), nullptr, - std::make_unique(nullptr), workarounds); + std::make_unique(nullptr), + workarounds + ); } return *m_impl; @@ -61,7 +60,7 @@ TEST_F_S(ApplySettings) { // 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) }; + const auto config_arg {getArgWithMatchingPattern(R"(^config=)", true)}; if (!config_arg) { GTEST_FAIL() << "\"config=\" argument not found!"; } @@ -72,7 +71,7 @@ TEST_F_S(ApplySettings) { GTEST_FAIL() << "Config argument could not be parsed!\nArgument:\n " << *config_arg << "\nError:\n " << parse_error; } - if (const auto workarounds_arg { getArgWithMatchingPattern(R"(^workarounds=)", true) }) { + if (const auto workarounds_arg {getArgWithMatchingPattern(R"(^workarounds=)", true)}) { display_device::WinWorkarounds workarounds; if (!fromJson(*workarounds_arg, workarounds, &parse_error)) { GTEST_FAIL() << "Workarounds argument could not be parsed!\nArgument:\n " << *workarounds_arg << "\nError:\n " << parse_error; @@ -82,7 +81,9 @@ TEST_F_S(ApplySettings) { getImpl(workarounds); } - const boost::scope::scope_exit cleanup { [this]() { static_cast(getImpl().revertSettings()); } }; + const boost::scope::scope_exit cleanup {[this]() { + static_cast(getImpl().revertSettings()); + }}; std::cout << "Applying settings. Press enter to continue..." << std::endl; std::cin.get(); diff --git a/tests/unit/windows/utils/comparison.cpp b/tests/unit/windows/utils/comparison.cpp index d5e078f..710c6b7 100644 --- a/tests/unit/windows/utils/comparison.cpp +++ b/tests/unit/windows/utils/comparison.cpp @@ -1,33 +1,27 @@ // local includes #include "comparison.h" -bool -operator==(const LUID &lhs, const LUID &rhs) { +bool operator==(const LUID &lhs, const LUID &rhs) { return lhs.HighPart == rhs.HighPart && lhs.LowPart == rhs.LowPart; } -bool -operator==(const POINTL &lhs, const POINTL &rhs) { +bool operator==(const POINTL &lhs, const POINTL &rhs) { return lhs.x == rhs.x && lhs.y == rhs.y; } -bool -operator==(const RECTL &lhs, const RECTL &rhs) { +bool operator==(const RECTL &lhs, const RECTL &rhs) { return lhs.bottom == rhs.bottom && lhs.left == rhs.left && lhs.right == rhs.right && lhs.top == rhs.top; } -bool -operator==(const DISPLAYCONFIG_RATIONAL &lhs, const DISPLAYCONFIG_RATIONAL &rhs) { +bool operator==(const DISPLAYCONFIG_RATIONAL &lhs, const DISPLAYCONFIG_RATIONAL &rhs) { return lhs.Denominator == rhs.Denominator && lhs.Numerator == rhs.Numerator; } -bool -operator==(const DISPLAYCONFIG_2DREGION &lhs, const DISPLAYCONFIG_2DREGION &rhs) { +bool operator==(const DISPLAYCONFIG_2DREGION &lhs, const DISPLAYCONFIG_2DREGION &rhs) { return lhs.cx == rhs.cx && lhs.cy == rhs.cy; } -bool -operator==(const DISPLAYCONFIG_PATH_SOURCE_INFO &lhs, const DISPLAYCONFIG_PATH_SOURCE_INFO &rhs) { +bool operator==(const DISPLAYCONFIG_PATH_SOURCE_INFO &lhs, const DISPLAYCONFIG_PATH_SOURCE_INFO &rhs) { // clang-format off return lhs.adapterId == rhs.adapterId && lhs.id == rhs.id && @@ -37,8 +31,7 @@ operator==(const DISPLAYCONFIG_PATH_SOURCE_INFO &lhs, const DISPLAYCONFIG_PATH_S // clang-format on } -bool -operator==(const DISPLAYCONFIG_PATH_TARGET_INFO &lhs, const DISPLAYCONFIG_PATH_TARGET_INFO &rhs) { +bool operator==(const DISPLAYCONFIG_PATH_TARGET_INFO &lhs, const DISPLAYCONFIG_PATH_TARGET_INFO &rhs) { // clang-format off return lhs.adapterId == rhs.adapterId && lhs.id == rhs.id && @@ -54,17 +47,15 @@ operator==(const DISPLAYCONFIG_PATH_TARGET_INFO &lhs, const DISPLAYCONFIG_PATH_T // clang-format on } -bool -operator==(const DISPLAYCONFIG_PATH_INFO &lhs, const DISPLAYCONFIG_PATH_INFO &rhs) { +bool operator==(const DISPLAYCONFIG_PATH_INFO &lhs, const DISPLAYCONFIG_PATH_INFO &rhs) { return lhs.sourceInfo == rhs.sourceInfo && lhs.targetInfo == rhs.targetInfo && lhs.flags == rhs.flags; } -bool -operator==(const DISPLAYCONFIG_SOURCE_MODE &lhs, const DISPLAYCONFIG_SOURCE_MODE &rhs) { +bool operator==(const DISPLAYCONFIG_SOURCE_MODE &lhs, const DISPLAYCONFIG_SOURCE_MODE &rhs) { return lhs.width == rhs.width && lhs.height == rhs.height && lhs.pixelFormat == rhs.pixelFormat && lhs.position == rhs.position; } -bool -operator==(const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &lhs, const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &rhs) { + +bool operator==(const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &lhs, const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &rhs) { // clang-format on return lhs.pixelRate == rhs.pixelRate && lhs.hSyncFreq == rhs.hSyncFreq && @@ -76,30 +67,24 @@ operator==(const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &lhs, const DISPLAYCONFIG_VIDEO // clang-format oon } -bool -operator==(const DISPLAYCONFIG_TARGET_MODE &lhs, const DISPLAYCONFIG_TARGET_MODE &rhs) { +bool operator==(const DISPLAYCONFIG_TARGET_MODE &lhs, const DISPLAYCONFIG_TARGET_MODE &rhs) { return lhs.targetVideoSignalInfo == rhs.targetVideoSignalInfo; } -bool -operator==(const DISPLAYCONFIG_DESKTOP_IMAGE_INFO &lhs, const DISPLAYCONFIG_DESKTOP_IMAGE_INFO &rhs) { +bool operator==(const DISPLAYCONFIG_DESKTOP_IMAGE_INFO &lhs, const DISPLAYCONFIG_DESKTOP_IMAGE_INFO &rhs) { return lhs.PathSourceSize == rhs.PathSourceSize && lhs.DesktopImageRegion == rhs.DesktopImageRegion && lhs.DesktopImageClip == rhs.DesktopImageClip; } -bool -operator==(const DISPLAYCONFIG_MODE_INFO &lhs, const DISPLAYCONFIG_MODE_INFO &rhs) { +bool operator==(const DISPLAYCONFIG_MODE_INFO &lhs, const DISPLAYCONFIG_MODE_INFO &rhs) { if (lhs.infoType == rhs.infoType && lhs.id == rhs.id && lhs.adapterId == rhs.adapterId) { if (lhs.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE) { return lhs.sourceMode == rhs.sourceMode; - } - else if (lhs.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET) { + } else if (lhs.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET) { return lhs.targetMode == rhs.targetMode; - } - else if (lhs.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE) { + } else if (lhs.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE) { // TODO: fix once implemented return false; - } - else { + } else { return true; } } @@ -107,8 +92,7 @@ operator==(const DISPLAYCONFIG_MODE_INFO &lhs, const DISPLAYCONFIG_MODE_INFO &rh } namespace display_device { - bool - operator==(const PathSourceIndexData &lhs, const PathSourceIndexData &rhs) { + bool operator==(const PathSourceIndexData &lhs, const PathSourceIndexData &rhs) { return lhs.m_source_id_to_path_index == rhs.m_source_id_to_path_index && lhs.m_adapter_id == rhs.m_adapter_id && lhs.m_active_source == rhs.m_active_source; } } // namespace display_device diff --git a/tests/unit/windows/utils/comparison.h b/tests/unit/windows/utils/comparison.h index 4119bb9..f7f9899 100644 --- a/tests/unit/windows/utils/comparison.h +++ b/tests/unit/windows/utils/comparison.h @@ -4,46 +4,32 @@ #include "display_device/windows/types.h" // Helper comparison operators -bool -operator==(const LUID &lhs, const LUID &rhs); +bool operator==(const LUID &lhs, const LUID &rhs); -bool -operator==(const POINTL &lhs, const POINTL &rhs); +bool operator==(const POINTL &lhs, const POINTL &rhs); -bool -operator==(const RECTL &lhs, const RECTL &rhs); +bool operator==(const RECTL &lhs, const RECTL &rhs); -bool -operator==(const DISPLAYCONFIG_RATIONAL &lhs, const DISPLAYCONFIG_RATIONAL &rhs); +bool operator==(const DISPLAYCONFIG_RATIONAL &lhs, const DISPLAYCONFIG_RATIONAL &rhs); -bool -operator==(const DISPLAYCONFIG_2DREGION &lhs, const DISPLAYCONFIG_2DREGION &rhs); +bool operator==(const DISPLAYCONFIG_2DREGION &lhs, const DISPLAYCONFIG_2DREGION &rhs); -bool -operator==(const DISPLAYCONFIG_PATH_SOURCE_INFO &lhs, const DISPLAYCONFIG_PATH_SOURCE_INFO &rhs); +bool operator==(const DISPLAYCONFIG_PATH_SOURCE_INFO &lhs, const DISPLAYCONFIG_PATH_SOURCE_INFO &rhs); -bool -operator==(const DISPLAYCONFIG_PATH_TARGET_INFO &lhs, const DISPLAYCONFIG_PATH_TARGET_INFO &rhs); +bool operator==(const DISPLAYCONFIG_PATH_TARGET_INFO &lhs, const DISPLAYCONFIG_PATH_TARGET_INFO &rhs); -bool -operator==(const DISPLAYCONFIG_PATH_INFO &lhs, const DISPLAYCONFIG_PATH_INFO &rhs); +bool operator==(const DISPLAYCONFIG_PATH_INFO &lhs, const DISPLAYCONFIG_PATH_INFO &rhs); -bool -operator==(const DISPLAYCONFIG_SOURCE_MODE &lhs, const DISPLAYCONFIG_SOURCE_MODE &rhs); +bool operator==(const DISPLAYCONFIG_SOURCE_MODE &lhs, const DISPLAYCONFIG_SOURCE_MODE &rhs); -bool -operator==(const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &lhs, const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &rhs); +bool operator==(const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &lhs, const DISPLAYCONFIG_VIDEO_SIGNAL_INFO &rhs); -bool -operator==(const DISPLAYCONFIG_TARGET_MODE &lhs, const DISPLAYCONFIG_TARGET_MODE &rhs); +bool operator==(const DISPLAYCONFIG_TARGET_MODE &lhs, const DISPLAYCONFIG_TARGET_MODE &rhs); -bool -operator==(const DISPLAYCONFIG_DESKTOP_IMAGE_INFO &lhs, const DISPLAYCONFIG_DESKTOP_IMAGE_INFO &rhs); +bool operator==(const DISPLAYCONFIG_DESKTOP_IMAGE_INFO &lhs, const DISPLAYCONFIG_DESKTOP_IMAGE_INFO &rhs); -bool -operator==(const DISPLAYCONFIG_MODE_INFO &lhs, const DISPLAYCONFIG_MODE_INFO &rhs); +bool operator==(const DISPLAYCONFIG_MODE_INFO &lhs, const DISPLAYCONFIG_MODE_INFO &rhs); namespace display_device { - bool - operator==(const PathSourceIndexData &lhs, const PathSourceIndexData &rhs); + bool operator==(const PathSourceIndexData &lhs, const PathSourceIndexData &rhs); } // namespace display_device diff --git a/tests/unit/windows/utils/guards.cpp b/tests/unit/windows/utils/guards.cpp index da48c3a..814b5e5 100644 --- a/tests/unit/windows/utils/guards.cpp +++ b/tests/unit/windows/utils/guards.cpp @@ -4,22 +4,18 @@ // local includes #include "display_device/windows/settings_utils.h" -boost::scope::scope_exit -makeTopologyGuard(display_device::WinDisplayDeviceInterface &win_dd) { +boost::scope::scope_exit makeTopologyGuard(display_device::WinDisplayDeviceInterface &win_dd) { return boost::scope::scope_exit(display_device::win_utils::topologyGuardFn(win_dd, win_dd.getCurrentTopology())); } -boost::scope::scope_exit -makeModeGuard(display_device::WinDisplayDeviceInterface &win_dd) { +boost::scope::scope_exit makeModeGuard(display_device::WinDisplayDeviceInterface &win_dd) { return boost::scope::scope_exit(display_device::win_utils::modeGuardFn(win_dd, win_dd.getCurrentTopology())); } -boost::scope::scope_exit -makePrimaryGuard(display_device::WinDisplayDeviceInterface &win_dd) { +boost::scope::scope_exit makePrimaryGuard(display_device::WinDisplayDeviceInterface &win_dd) { return boost::scope::scope_exit(display_device::win_utils::primaryGuardFn(win_dd, win_dd.getCurrentTopology())); } -boost::scope::scope_exit -makeHdrStateGuard(display_device::WinDisplayDeviceInterface &win_dd) { +boost::scope::scope_exit makeHdrStateGuard(display_device::WinDisplayDeviceInterface &win_dd) { return boost::scope::scope_exit(display_device::win_utils::hdrStateGuardFn(win_dd, win_dd.getCurrentTopology())); } diff --git a/tests/unit/windows/utils/guards.h b/tests/unit/windows/utils/guards.h index 3be687c..682a7b6 100644 --- a/tests/unit/windows/utils/guards.h +++ b/tests/unit/windows/utils/guards.h @@ -8,14 +8,10 @@ #include "helpers.h" // Helper functions to make guards for restoring previous state -boost::scope::scope_exit -makeTopologyGuard(display_device::WinDisplayDeviceInterface &win_dd); +boost::scope::scope_exit makeTopologyGuard(display_device::WinDisplayDeviceInterface &win_dd); -boost::scope::scope_exit -makeModeGuard(display_device::WinDisplayDeviceInterface &win_dd); +boost::scope::scope_exit makeModeGuard(display_device::WinDisplayDeviceInterface &win_dd); -boost::scope::scope_exit -makePrimaryGuard(display_device::WinDisplayDeviceInterface &win_dd); +boost::scope::scope_exit makePrimaryGuard(display_device::WinDisplayDeviceInterface &win_dd); -boost::scope::scope_exit -makeHdrStateGuard(display_device::WinDisplayDeviceInterface &win_dd); +boost::scope::scope_exit makeHdrStateGuard(display_device::WinDisplayDeviceInterface &win_dd); diff --git a/tests/unit/windows/utils/helpers.cpp b/tests/unit/windows/utils/helpers.cpp index 3d8d718..26addf3 100644 --- a/tests/unit/windows/utils/helpers.cpp +++ b/tests/unit/windows/utils/helpers.cpp @@ -1,10 +1,11 @@ -// local includes +// header include #include "helpers.h" + +// local includes #include "display_device/windows/json.h" -std::optional> -getAvailableDevices(display_device::WinApiLayer &layer, const bool only_valid_output) { - const auto all_devices { layer.queryDisplayConfig(display_device::QueryType::All) }; +std::optional> getAvailableDevices(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; } @@ -15,26 +16,25 @@ getAvailableDevices(display_device::WinApiLayer &layer, const bool only_valid_ou continue; } - const auto device_id { layer.getDeviceId(path) }; + const auto device_id {layer.getDeviceId(path)}; if (!device_id.empty()) { device_ids.insert(device_id); } } - return std::vector { device_ids.begin(), device_ids.end() }; + return std::vector {device_ids.begin(), device_ids.end()}; } -std::optional> -serializeState(const std::optional &state) { +std::optional> serializeState(const std::optional &state) { if (state) { if (state->m_initial.m_topology.empty() && state->m_initial.m_primary_devices.empty() && state->m_modified.m_topology.empty() && !state->m_modified.hasModifications()) { return std::vector {}; } - bool is_ok { false }; - const auto data_string { toJson(*state, 2, &is_ok) }; + bool is_ok {false}; + const auto data_string {toJson(*state, 2, &is_ok)}; if (is_ok) { - return std::vector { std::begin(data_string), std::end(data_string) }; + return std::vector {std::begin(data_string), std::end(data_string)}; } } diff --git a/tests/unit/windows/utils/helpers.h b/tests/unit/windows/utils/helpers.h index 67d5954..0a9aff5 100644 --- a/tests/unit/windows/utils/helpers.h +++ b/tests/unit/windows/utils/helpers.h @@ -8,8 +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(display_device::WinApiLayer &layer, bool only_valid_output = true); -std::optional> -serializeState(const std::optional &state); +std::optional> serializeState(const std::optional &state); diff --git a/tests/unit/windows/utils/mock_win_api_layer.cpp b/tests/unit/windows/utils/mock_win_api_layer.cpp index 5fc04bb..7a6630f 100644 --- a/tests/unit/windows/utils/mock_win_api_layer.cpp +++ b/tests/unit/windows/utils/mock_win_api_layer.cpp @@ -2,8 +2,7 @@ #include "mock_win_api_layer.h" namespace { - display_device::PathAndModeData - make3ActiveDeviceGroups(const bool include_duplicate) { + display_device::PathAndModeData make3ActiveDeviceGroups(const bool include_duplicate) { display_device::PathAndModeData data; // 1st group (1 device) @@ -11,15 +10,15 @@ namespace { data.m_paths.push_back({}); data.m_paths.back().flags = DISPLAYCONFIG_PATH_ACTIVE; data.m_paths.back().sourceInfo.sourceModeInfoIdx = data.m_modes.size(); - data.m_paths.back().sourceInfo.adapterId = { 1, 1 }; + data.m_paths.back().sourceInfo.adapterId = {1, 1}; data.m_paths.back().sourceInfo.id = 0; data.m_paths.back().targetInfo.targetAvailable = TRUE; - data.m_paths.back().targetInfo.refreshRate = { 120, 1 }; + data.m_paths.back().targetInfo.refreshRate = {120, 1}; data.m_modes.push_back({}); data.m_modes.back().infoType = DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE; data.m_modes.back().sourceMode = {}; // Set the union - data.m_modes.back().sourceMode.position = { 0, 0 }; + data.m_modes.back().sourceMode.position = {0, 0}; data.m_modes.back().sourceMode.width = 1920; data.m_modes.back().sourceMode.height = 1080; } @@ -29,15 +28,15 @@ namespace { data.m_paths.push_back({}); data.m_paths.back().flags = DISPLAYCONFIG_PATH_ACTIVE; data.m_paths.back().sourceInfo.sourceModeInfoIdx = data.m_modes.size(); - data.m_paths.back().sourceInfo.adapterId = { 2, 2 }; + data.m_paths.back().sourceInfo.adapterId = {2, 2}; data.m_paths.back().sourceInfo.id = 0; data.m_paths.back().targetInfo.targetAvailable = TRUE; - data.m_paths.back().targetInfo.refreshRate = { 119995, 1000 }; + data.m_paths.back().targetInfo.refreshRate = {119995, 1000}; data.m_modes.push_back({}); data.m_modes.back().infoType = DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE; data.m_modes.back().sourceMode = {}; // Set the union - data.m_modes.back().sourceMode.position = { 1921, 0 }; + data.m_modes.back().sourceMode.position = {1921, 0}; data.m_modes.back().sourceMode.width = 1920; data.m_modes.back().sourceMode.height = 2160; @@ -45,15 +44,15 @@ namespace { data.m_paths.push_back({}); data.m_paths.back().flags = DISPLAYCONFIG_PATH_ACTIVE; data.m_paths.back().sourceInfo.sourceModeInfoIdx = data.m_modes.size(); - data.m_paths.back().sourceInfo.adapterId = { 3, 3 }; + data.m_paths.back().sourceInfo.adapterId = {3, 3}; data.m_paths.back().sourceInfo.id = 0; data.m_paths.back().targetInfo.targetAvailable = TRUE; - data.m_paths.back().targetInfo.refreshRate = { 60, 1 }; + data.m_paths.back().targetInfo.refreshRate = {60, 1}; data.m_modes.push_back({}); data.m_modes.back().infoType = DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE; data.m_modes.back().sourceMode = {}; // Set the union - data.m_modes.back().sourceMode.position = { 1921, 0 }; + data.m_modes.back().sourceMode.position = {1921, 0}; data.m_modes.back().sourceMode.width = 1920; data.m_modes.back().sourceMode.height = 2160; } @@ -64,15 +63,15 @@ namespace { data.m_paths.push_back({}); data.m_paths.back().flags = DISPLAYCONFIG_PATH_ACTIVE; data.m_paths.back().sourceInfo.sourceModeInfoIdx = data.m_modes.size(); - data.m_paths.back().sourceInfo.adapterId = { 4, 4 }; + data.m_paths.back().sourceInfo.adapterId = {4, 4}; data.m_paths.back().sourceInfo.id = 0; data.m_paths.back().targetInfo.targetAvailable = TRUE; - data.m_paths.back().targetInfo.refreshRate = { 90, 1 }; + data.m_paths.back().targetInfo.refreshRate = {90, 1}; data.m_modes.push_back({}); data.m_modes.back().infoType = DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE; data.m_modes.back().sourceMode = {}; // Set the union - data.m_modes.back().sourceMode.position = { 0, 1081 }; + data.m_modes.back().sourceMode.position = {0, 1081}; data.m_modes.back().sourceMode.width = 3840; data.m_modes.back().sourceMode.height = 2160; } @@ -82,19 +81,19 @@ namespace { } // namespace namespace ut_consts { - const std::optional PAM_NULL { std::nullopt }; - const std::optional PAM_EMPTY { display_device::PathAndModeData {} }; - const std::optional PAM_3_ACTIVE { make3ActiveDeviceGroups(false) }; - const std::optional PAM_3_ACTIVE_WITH_INVALID_MODE_IDX { []() { - auto data { make3ActiveDeviceGroups(false) }; + const std::optional PAM_NULL {std::nullopt}; + const std::optional PAM_EMPTY {display_device::PathAndModeData {}}; + const std::optional PAM_3_ACTIVE {make3ActiveDeviceGroups(false)}; + const std::optional PAM_3_ACTIVE_WITH_INVALID_MODE_IDX {[]() { + auto data {make3ActiveDeviceGroups(false)}; // Scramble the indexes - auto invalid_idx { DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID }; + auto invalid_idx {DISPLAYCONFIG_PATH_SOURCE_MODE_IDX_INVALID}; for (auto &item : data.m_paths) { item.sourceInfo.sourceModeInfoIdx = invalid_idx--; } return data; - }() }; - const std::optional PAM_4_ACTIVE_WITH_2_DUPLICATES { make3ActiveDeviceGroups(true) }; + }()}; + const std::optional PAM_4_ACTIVE_WITH_2_DUPLICATES {make3ActiveDeviceGroups(true)}; } // namespace ut_consts diff --git a/tests/unit/windows/utils/mock_win_display_device.cpp b/tests/unit/windows/utils/mock_win_display_device.cpp index 0e4435e..f926789 100644 --- a/tests/unit/windows/utils/mock_win_display_device.cpp +++ b/tests/unit/windows/utils/mock_win_display_device.cpp @@ -1,34 +1,37 @@ -// local includes +// header include #include "mock_win_display_device.h" + +// local includes #include "helpers.h" namespace ut_consts { - const std::optional SDCS_NULL { std::nullopt }; - const std::optional SDCS_EMPTY { display_device::SingleDisplayConfigState {} }; - const std::optional SDCS_FULL { []() { + const std::optional SDCS_NULL {std::nullopt}; + const std::optional SDCS_EMPTY {display_device::SingleDisplayConfigState {}}; + const std::optional SDCS_FULL {[]() { const display_device::SingleDisplayConfigState state { - { { { "DeviceId1" } }, - { "DeviceId1" } }, - { display_device::SingleDisplayConfigState::Modified { - { { "DeviceId1" }, { "DeviceId3" } }, - { { "DeviceId1", { { 1920, 1080 }, { 120, 1 } } }, - { "DeviceId3", { { 1920, 1080 }, { 60, 1 } } } }, - { { "DeviceId1", { display_device::HdrState::Disabled } }, - { "DeviceId3", display_device::HdrState::Enabled } }, - { "DeviceId1" }, - } } + {{{"DeviceId1"}}, + {"DeviceId1"}}, + {display_device::SingleDisplayConfigState::Modified { + {{"DeviceId1"}, {"DeviceId3"}}, + {{"DeviceId1", {{1920, 1080}, {120, 1}}}, + {"DeviceId3", {{1920, 1080}, {60, 1}}}}, + {{"DeviceId1", {display_device::HdrState::Disabled}}, + {"DeviceId3", display_device::HdrState::Enabled}}, + {"DeviceId1"}, + }} }; return state; - }() }; - const std::optional SDCS_NO_MODIFICATIONS { []() { + }()}; + const std::optional SDCS_NO_MODIFICATIONS {[]() { const display_device::SingleDisplayConfigState state { - { { { "DeviceId1" } }, - { "DeviceId1" } }, - { display_device::SingleDisplayConfigState::Modified { - { { "DeviceId1" }, { "DeviceId3" } } } } + {{{"DeviceId1"}}, + {"DeviceId1"}}, + {display_device::SingleDisplayConfigState::Modified { + {{"DeviceId1"}, {"DeviceId3"}} + }} }; return state; - }() }; + }()}; } // namespace ut_consts