Skip to content

Commit 53a0ea5

Browse files
authored
fix(settings): better API test and clean persistence reset (#138)
1 parent f434ff2 commit 53a0ea5

File tree

6 files changed

+9
-40
lines changed

6 files changed

+9
-40
lines changed

src/common/include/display_device/settings_manager_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace display_device {
9898
*
9999
* In case the settings cannot be reverted, because the display is turned or some other reason,
100100
* this allows to "accept" the current state and start from scratch, but only if the persistence was
101-
* cleared successfuly.
101+
* cleared successfully.
102102
* @examples
103103
* SettingsManagerInterface* iface = getIface(...);
104104
* auto result = iface->applySettings(config);

src/windows/include/display_device/windows/win_display_device_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace display_device {
127127
* @brief Set new display modes for the devices.
128128
* @param modes A map of modes to set.
129129
* @returns True if modes were set, false otherwise.
130-
* @warning if any of the specified devices are duplicated, modes modes be provided
130+
* @warning if any of the specified devices are duplicated, modes be provided
131131
* for duplicates too!
132132
* @examples
133133
* WinDisplayDeviceInterface* iface = getIface(...);

src/windows/settings_manager_general.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ namespace display_device {
4646
}
4747

4848
bool SettingsManager::resetPersistence() {
49-
// Trying to revert one more time in case we succeed.
50-
if (revertSettings() == RevertResult::Ok) {
49+
DD_LOG(info) << "Trying to reset persistent display device settings.";
50+
if (const auto &cached_state {m_persistence_state->getState()}; !cached_state) {
5151
return true;
5252
}
5353

54-
DD_LOG(info) << "Trying to reset persistent display device settings.";
5554
if (!m_persistence_state->persistState(std::nullopt)) {
5655
DD_LOG(error) << "Failed to clear persistence!";
5756
return false;

src/windows/win_display_device_general.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,10 @@ namespace display_device {
1818
}
1919

2020
bool WinDisplayDevice::isApiAccessAvailable() const {
21-
const auto display_data {m_w_api->queryDisplayConfig(QueryType::All)};
22-
if (!display_data) {
23-
DD_LOG(debug) << "WinDisplayDevice::isApiAccessAvailable failed while querying display data.";
24-
return false;
25-
}
26-
27-
// Here we are supplying the retrieved display data back to SetDisplayConfig (with VALIDATE flag only, so that we make no actual changes).
2821
// Unless something is really broken on Windows, this call should never fail under normal circumstances - the configuration is 100% correct, since it was
2922
// provided by Windows.
30-
const UINT32 flags {SDC_VALIDATE | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_VIRTUAL_MODE_AWARE};
31-
const LONG result {m_w_api->setDisplayConfig(display_data->m_paths, display_data->m_modes, flags)};
23+
const UINT32 flags {SDC_VALIDATE | SDC_USE_DATABASE_CURRENT};
24+
const LONG result {m_w_api->setDisplayConfig({}, {}, flags)};
3225

3326
DD_LOG(debug) << "WinDisplayDevice::isApiAccessAvailable result: " << m_w_api->getErrorString(result);
3427
return result == ERROR_SUCCESS;

tests/unit/windows/test_settings_manager_general.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ TEST_F_S_MOCKED(ResetPersistence, FailedToReset) {
106106
EXPECT_CALL(*m_settings_persistence_api, load())
107107
.Times(1)
108108
.WillOnce(Return(serializeState(ut_consts::SDCS_FULL)));
109-
EXPECT_CALL(*m_dd_api, isApiAccessAvailable())
110-
.Times(1)
111-
.WillOnce(Return(false));
112109
EXPECT_CALL(*m_settings_persistence_api, clear())
113110
.Times(1)
114111
.WillOnce(Return(false));
@@ -120,9 +117,6 @@ TEST_F_S_MOCKED(ResetPersistence, PersistenceReset, NoCapturedDevice) {
120117
EXPECT_CALL(*m_settings_persistence_api, load())
121118
.Times(1)
122119
.WillOnce(Return(serializeState(ut_consts::SDCS_FULL)));
123-
EXPECT_CALL(*m_dd_api, isApiAccessAvailable())
124-
.Times(1)
125-
.WillOnce(Return(false));
126120
EXPECT_CALL(*m_settings_persistence_api, clear())
127121
.Times(1)
128122
.WillOnce(Return(true));
@@ -138,9 +132,6 @@ TEST_F_S_MOCKED(ResetPersistence, PersistenceReset, WithCapturedDevice) {
138132
EXPECT_CALL(*m_settings_persistence_api, load())
139133
.Times(1)
140134
.WillOnce(Return(serializeState(ut_consts::SDCS_FULL)));
141-
EXPECT_CALL(*m_dd_api, isApiAccessAvailable())
142-
.Times(1)
143-
.WillOnce(Return(false));
144135
EXPECT_CALL(*m_settings_persistence_api, clear())
145136
.Times(1)
146137
.WillOnce(Return(true));

tests/unit/windows/test_win_display_device_general.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace {
3434
#define TEST_F_S_MOCKED(...) DD_MAKE_TEST(TEST_F, WinDisplayDeviceGeneralMocked, __VA_ARGS__)
3535

3636
// Additional convenience global const(s)
37-
const UINT32 FLAGS {SDC_VALIDATE | SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_VIRTUAL_MODE_AWARE};
37+
const UINT32 FLAGS {SDC_VALIDATE | SDC_USE_DATABASE_CURRENT};
3838
} // namespace
3939

4040
TEST_F_S(NullptrLayerProvided) {
@@ -50,10 +50,7 @@ TEST_F_S(IsApiAccessAvailable) {
5050
}
5151

5252
TEST_F_S_MOCKED(IsApiAccessAvailable) {
53-
EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All))
54-
.Times(1)
55-
.WillOnce(Return(ut_consts::PAM_3_ACTIVE));
56-
EXPECT_CALL(*m_layer, setDisplayConfig(ut_consts::PAM_3_ACTIVE->m_paths, ut_consts::PAM_3_ACTIVE->m_modes, FLAGS))
53+
EXPECT_CALL(*m_layer, setDisplayConfig(std::vector<DISPLAYCONFIG_PATH_INFO> {}, std::vector<DISPLAYCONFIG_MODE_INFO> {}, FLAGS))
5754
.Times(1)
5855
.WillOnce(Return(ERROR_SUCCESS));
5956
EXPECT_CALL(*m_layer, getErrorString(ERROR_SUCCESS))
@@ -63,19 +60,8 @@ TEST_F_S_MOCKED(IsApiAccessAvailable) {
6360
EXPECT_TRUE(m_win_dd.isApiAccessAvailable());
6461
}
6562

66-
TEST_F_S_MOCKED(IsApiAccessAvailable, FailedToGetDisplayData) {
67-
EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All))
68-
.Times(1)
69-
.WillOnce(Return(ut_consts::PAM_NULL));
70-
71-
EXPECT_FALSE(m_win_dd.isApiAccessAvailable());
72-
}
73-
7463
TEST_F_S_MOCKED(IsApiAccessAvailable, FailedToSetDisplayConfig) {
75-
EXPECT_CALL(*m_layer, queryDisplayConfig(display_device::QueryType::All))
76-
.Times(1)
77-
.WillOnce(Return(ut_consts::PAM_3_ACTIVE));
78-
EXPECT_CALL(*m_layer, setDisplayConfig(ut_consts::PAM_3_ACTIVE->m_paths, ut_consts::PAM_3_ACTIVE->m_modes, FLAGS))
64+
EXPECT_CALL(*m_layer, setDisplayConfig(std::vector<DISPLAYCONFIG_PATH_INFO> {}, std::vector<DISPLAYCONFIG_MODE_INFO> {}, FLAGS))
7965
.Times(1)
8066
.WillOnce(Return(ERROR_ACCESS_DENIED));
8167
EXPECT_CALL(*m_layer, getErrorString(ERROR_ACCESS_DENIED))

0 commit comments

Comments
 (0)