Repository navigation
Conversation
…tify Add GoogleTest unit tests for the core manager and DBus classes: - CPickerManager: 27 cases (launch mode, mouse handling, screen mapping) - CScreenshotWidget: 9 cases (pixmap storage, key/wheel/paint events) - DBusNotify: 22 cases (dbus message construction and sending) These sources are picked up automatically by the opt-in CMake test framework (BUILD_TESTS=ON, file(GLOB test_*.cpp)). Under the default qmake build they are not referenced by deepin-picker.pro, so this PR does not affect the existing build. Verified: all 58 cases pass with Qt6/DTK6 once the framework is present.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideAdds 58 GoogleTest cases for CPickerManager, CScreenshotWidget, and DBusNotify, using Qt application fixtures and stubext-based isolation to exercise core control flow, DBus interactions, widget behavior, and documented platform/defect limitations; the tests are picked up only by the opt-in CMake framework and do not affect qmake builds. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning
详情 {
"unset": {
"autotests/src/test_CPickerManager.cpp": {
"b": [
" qunsetenv(\"XDG_SESSION_TYPE\");"
]
}
}
} |
There was a problem hiding this comment.
Hey - I've found 6 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="autotests/src/test_DBusNotify.cpp" line_range="16-21" />
<code_context>
+#include "dbusnotify.h"
+#include "stubext.h"
+
+// Qt5 QDBusConnection::connect 7-arg (non-const, non-static)
+// bool connect(service, path, interface, name, signature, receiver, slot)
+using DbusConnect7 = bool (QDBusConnection::*)(
+ const QString&, const QString&, const QString&,
+ const QString&, const QString&,
+ QObject*, const char*);
+using DbusDisconnect7 = bool (QDBusConnection::*)(
+ const QString&, const QString&, const QString&,
</code_context>
<issue_to_address>
**issue (bug_risk):** The QtDBus `connect` and `disconnect` overloads are const member functions in Qt6, but these aliases declare non-const member-function pointers. The `static_cast` therefore fails to compile when the CMake tests are built with the Qt6 configuration described in the PR.
**Triggers:** When BUILD_TESTS is enabled with Qt6.
**Suggested fix:** Declare both aliases as const member-function pointers, for example `bool (QDBusConnection::*)(...) const`.
</issue_to_address>
### Comment 2
<location path="autotests/src/test_CPickerManager.cpp" line_range="257-270" />
<code_context>
+ delete mgr;
+}
+
+TEST_F(CPickerManagerTest, Constructor_OnWayland_ScalesShadowWithoutRatio) {
+ // Arrange — stub isWaylandPlatform to return true via environment variable
+ // isWaylandPlatform uses static QProcessEnvironment, so we stub it at a lower level
+ stub.set_lamda(static_cast<qreal(QGuiApplication::*)() const>(&QGuiApplication::devicePixelRatio),
+ []() -> qreal { __DBG_STUB_INVOKE__ return 2.0; });
+
+ // Act
+ CPickerManager *mgr = new CPickerManager();
+
+ // Assert — constructor completed; on Wayland, scaled() is called with just (w, h)
+ EXPECT_EQ(g_quitCallCount, 0);
+ EXPECT_NE(mgr, nullptr);
+
+ delete mgr;
+}
+
</code_context>
<issue_to_address>
**issue (testing):** Changing `devicePixelRatio()` to return 2.0 does not make `isWaylandPlatform()` return true; that method reads the session environment. On an X11 test runner, both this test and the delayed-focus test execute the X11 path, so the Wayland branches they claim to cover are never exercised.
**Triggers:** When the tests run on an X11 or offscreen environment, which is the ordinary CI configuration.
**Suggested fix:** Run the Wayland cases in a separate process with controlled environment variables, or stub `isWaylandPlatform()` directly if the test framework supports private-method stubbing.
</issue_to_address>
### Comment 3
<location path="autotests/src/test_CPickerManager.cpp" line_range="367-387" />
<code_context>
+TEST_F(CPickerManagerTest, IsWaylandPlatform_StaticCacheLimitation) {
</code_context>
<issue_to_address>
**issue (testing):** The test changes `XDG_SESSION_TYPE` and then unconditionally removes it, rather than restoring its previous value. If the test process started with that variable set, the test permanently changes the environment for later tests and makes their platform-dependent behavior order-dependent.
**Triggers:** When the test runner already has `XDG_SESSION_TYPE` set, including a real Wayland environment.
**Suggested fix:** Save the original value and restore it after the test, and avoid relying on process-global static environment caching for branch coverage.
</issue_to_address>
### Comment 4
<location path="autotests/src/test_DBusNotify.cpp" line_range="189-212" />
<code_context>
+ EXPECT_TRUE(disconnectCalled);
+}
+
+TEST_F(DBusNotifyTest, Destructor_WhenDestroyed_DisconnectsWithCorrectParams) {
+ // Arrange
+ QString capturedIface;
+ QString capturedSignal;
+ stubConnectSimple();
+ auto fnD = static_cast<DbusDisconnect7>(&QDBusConnection::disconnect);
+ stub.set_lamda(fnD, [&capturedIface, &capturedSignal](
+ QDBusConnection*, const QString&, const QString&,
+ const QString& iface, const QString& name,
+ const QString&, QObject*, const char*) -> bool {
+ capturedIface = iface;
+ capturedSignal = name;
+ return true;
+ });
+
+ // Act
+ {
+ DBusNotify notify(nullptr);
+ }
+
+ // Assert
</code_context>
<issue_to_address>
**issue (bug_risk):** The destructor test captures only the interface and signal name, not the slot string passed to `QDBusConnection::disconnect`. It therefore passes even though the implementation disconnects `propertyChanged(QDBusMessage)` while the constructor connects `__propertyChanged__(QDBusMessage)`, leaving the registered signal connection active.
**Triggers:** When validating the destructor's cleanup behavior.
**Suggested fix:** Capture and assert the receiver and slot arguments, requiring the disconnect call to use `SLOT(__propertyChanged__(QDBusMessage))`.
</issue_to_address>
### Comment 5
<location path="autotests/src/test_DBusNotify.cpp" line_range="438-445" />
<code_context>
+
+TEST_F(DBusNotifyTest, PropertyChanged_TwoArgs_EarlyReturnNoCrash) {
+ // Arrange
+ stubConnectSimple();
+ stubDisconnectSimple();
+ DBusNotify notify(nullptr);
+ QDBusMessage msg = QDBusMessage::createSignal("/path",
+ "org.freedesktop.Notifications", "test");
+ QList<QVariant> args;
+ args << QString("org.freedesktop.Notifications") << QVariantMap();
+ msg.setArguments(args);
+
+ // Act
</code_context>
<issue_to_address>
**issue (testing):** The property-change tests put a `QVariantMap` directly into the message arguments, while `__propertyChanged__` reads argument 1 as a `QDBusArgument` and converts it with `qdbus_cast<QVariantMap>`. The tests therefore do not supply the DBus wire representation consumed by the slot and cannot validate changed-property decoding or notification behavior.
**Triggers:** When the slot receives a real DBus signal encoded as `sa{sv}as`.
**Suggested fix:** Construct argument 1 as a `QDBusArgument` containing the dictionary, or invoke the slot with the same encoded argument type that QtDBus delivers.
</issue_to_address>
### Comment 6
<location path="autotests/src/test_CPickerManager.cpp" line_range="440-456" />
<code_context>
+ EXPECT_TRUE(grabWindowCalled);
+}
+
+TEST_F(CPickerManagerTest, GetScreenShotPixmap_OnX11_GrabsWindow) {
+ // Arrange — on X11 (current CI env), getScreenShotPixmap uses grabWindow
+ bool grabWindowCalled = false;
+ stub.set_lamda(static_cast<QPixmap(QScreen::*)(WId, int, int, int, int)>(&QScreen::grabWindow),
+ [&grabWindowCalled](QScreen *, WId, int, int, int, int) -> QPixmap {
+ __DBG_STUB_INVOKE__
+ grabWindowCalled = true;
+ return QPixmap(200, 200);
+ });
+
+ CPickerManager mgr;
+
+ // Act
+ mgr.handleMouseMove();
+
+ // Assert — on X11, grabWindow IS called
+ EXPECT_TRUE(grabWindowCalled);
+}
+
</code_context>
<issue_to_address>
**issue (testing):** The test calls the public `handleMouseMove()` path but never provides a screen from `screenAt()` or a widget mapping for that screen. With the fixture's default `screenAt()` stub returning null, `autoUpdate()` returns before the per-screen `getScreenShotPixmap()` path, so `grabWindowCalled` only observes the desktop-grab path.
**Triggers:** When the default fixture stubs are used, as in this test.
**Suggested fix:** Stub `screenAt()` to return a real screen and arrange a corresponding screenshot widget, then assert the grab made by `getScreenShotPixmap()` separately from the desktop capture.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| // Qt5 QDBusConnection::connect 7-arg (non-const, non-static) | ||
| // bool connect(service, path, interface, name, signature, receiver, slot) | ||
| using DbusConnect7 = bool (QDBusConnection::*)( | ||
| const QString&, const QString&, const QString&, | ||
| const QString&, const QString&, | ||
| QObject*, const char*); |
There was a problem hiding this comment.
issue (bug_risk): The QtDBus connect and disconnect overloads are const member functions in Qt6, but these aliases declare non-const member-function pointers. The static_cast therefore fails to compile when the CMake tests are built with the Qt6 configuration described in the PR.
Triggers: When BUILD_TESTS is enabled with Qt6.
Suggested fix: Declare both aliases as const member-function pointers, for example bool (QDBusConnection::*)(...) const.
| TEST_F(CPickerManagerTest, Constructor_OnWayland_ScalesShadowWithoutRatio) { | ||
| // Arrange — stub isWaylandPlatform to return true via environment variable | ||
| // isWaylandPlatform uses static QProcessEnvironment, so we stub it at a lower level | ||
| stub.set_lamda(static_cast<qreal(QGuiApplication::*)() const>(&QGuiApplication::devicePixelRatio), | ||
| []() -> qreal { __DBG_STUB_INVOKE__ return 2.0; }); | ||
|
|
||
| // Act | ||
| CPickerManager *mgr = new CPickerManager(); | ||
|
|
||
| // Assert — constructor completed; on Wayland, scaled() is called with just (w, h) | ||
| EXPECT_EQ(g_quitCallCount, 0); | ||
| EXPECT_NE(mgr, nullptr); | ||
|
|
||
| delete mgr; |
There was a problem hiding this comment.
issue (testing): Changing devicePixelRatio() to return 2.0 does not make isWaylandPlatform() return true; that method reads the session environment. On an X11 test runner, both this test and the delayed-focus test execute the X11 path, so the Wayland branches they claim to cover are never exercised.
Triggers: When the tests run on an X11 or offscreen environment, which is the ordinary CI configuration.
Suggested fix: Run the Wayland cases in a separate process with controlled environment variables, or stub isWaylandPlatform() directly if the test framework supports private-method stubbing.
| TEST_F(CPickerManagerTest, IsWaylandPlatform_StaticCacheLimitation) { | ||
| // Arrange — isWaylandPlatform() uses static QProcessEnvironment that caches on first call. | ||
| // After the first CPickerManager construction (in earlier tests), the env is already cached. | ||
| // qputenv("XDG_SESSION_TYPE", "wayland") has no effect after caching. | ||
| // This test documents the limitation: Wayland code paths require separate process. | ||
| qputenv("XDG_SESSION_TYPE", "wayland"); | ||
| bool grabWindowCalled = false; | ||
| stub.set_lamda(static_cast<QPixmap(QScreen::*)(WId, int, int, int, int)>(&QScreen::grabWindow), | ||
| [&grabWindowCalled](QScreen *, WId, int, int, int, int) -> QPixmap { | ||
| __DBG_STUB_INVOKE__ | ||
| grabWindowCalled = true; | ||
| return QPixmap(100, 100); | ||
| }); | ||
|
|
||
| CPickerManager mgr; | ||
| mgr.handleMouseMove(); | ||
|
|
||
| // Assert — static cache means X11 path still active despite env change | ||
| EXPECT_TRUE(grabWindowCalled); | ||
| qunsetenv("XDG_SESSION_TYPE"); | ||
| } |
There was a problem hiding this comment.
issue (testing): The test changes XDG_SESSION_TYPE and then unconditionally removes it, rather than restoring its previous value. If the test process started with that variable set, the test permanently changes the environment for later tests and makes their platform-dependent behavior order-dependent.
Triggers: When the test runner already has XDG_SESSION_TYPE set, including a real Wayland environment.
Suggested fix: Save the original value and restore it after the test, and avoid relying on process-global static environment caching for branch coverage.
| TEST_F(DBusNotifyTest, Destructor_WhenDestroyed_DisconnectsWithCorrectParams) { | ||
| // Arrange | ||
| QString capturedIface; | ||
| QString capturedSignal; | ||
| stubConnectSimple(); | ||
| auto fnD = static_cast<DbusDisconnect7>(&QDBusConnection::disconnect); | ||
| stub.set_lamda(fnD, [&capturedIface, &capturedSignal]( | ||
| QDBusConnection*, const QString&, const QString&, | ||
| const QString& iface, const QString& name, | ||
| const QString&, QObject*, const char*) -> bool { | ||
| capturedIface = iface; | ||
| capturedSignal = name; | ||
| return true; | ||
| }); | ||
|
|
||
| // Act | ||
| { | ||
| DBusNotify notify(nullptr); | ||
| } | ||
|
|
||
| // Assert | ||
| EXPECT_EQ(capturedIface, QString("org.freedesktop.DBus.Properties")); | ||
| EXPECT_EQ(capturedSignal, QString("PropertiesChanged")); | ||
| } |
There was a problem hiding this comment.
issue (bug_risk): The destructor test captures only the interface and signal name, not the slot string passed to QDBusConnection::disconnect. It therefore passes even though the implementation disconnects propertyChanged(QDBusMessage) while the constructor connects __propertyChanged__(QDBusMessage), leaving the registered signal connection active.
Triggers: When validating the destructor's cleanup behavior.
Suggested fix: Capture and assert the receiver and slot arguments, requiring the disconnect call to use SLOT(__propertyChanged__(QDBusMessage)).
| stubConnectSimple(); | ||
| stubDisconnectSimple(); | ||
| DBusNotify notify(nullptr); | ||
| QDBusMessage msg = QDBusMessage::createSignal("/path", | ||
| "org.freedesktop.Notifications", "test"); | ||
| QList<QVariant> args; | ||
| args << QString("org.freedesktop.Notifications") << QVariantMap(); | ||
| msg.setArguments(args); |
There was a problem hiding this comment.
issue (testing): The property-change tests put a QVariantMap directly into the message arguments, while __propertyChanged__ reads argument 1 as a QDBusArgument and converts it with qdbus_cast<QVariantMap>. The tests therefore do not supply the DBus wire representation consumed by the slot and cannot validate changed-property decoding or notification behavior.
Triggers: When the slot receives a real DBus signal encoded as sa{sv}as.
Suggested fix: Construct argument 1 as a QDBusArgument containing the dictionary, or invoke the slot with the same encoded argument type that QtDBus delivers.
| TEST_F(CPickerManagerTest, GetScreenShotPixmap_OnX11_GrabsWindow) { | ||
| // Arrange — on X11 (current CI env), getScreenShotPixmap uses grabWindow | ||
| bool grabWindowCalled = false; | ||
| stub.set_lamda(static_cast<QPixmap(QScreen::*)(WId, int, int, int, int)>(&QScreen::grabWindow), | ||
| [&grabWindowCalled](QScreen *, WId, int, int, int, int) -> QPixmap { | ||
| __DBG_STUB_INVOKE__ | ||
| grabWindowCalled = true; | ||
| return QPixmap(200, 200); | ||
| }); | ||
|
|
||
| CPickerManager mgr; | ||
|
|
||
| // Act | ||
| mgr.handleMouseMove(); | ||
|
|
||
| // Assert — on X11, grabWindow IS called | ||
| EXPECT_TRUE(grabWindowCalled); |
There was a problem hiding this comment.
issue (testing): The test calls the public handleMouseMove() path but never provides a screen from screenAt() or a widget mapping for that screen. With the fixture's default screenAt() stub returning null, autoUpdate() returns before the per-screen getScreenShotPixmap() path, so grabWindowCalled only observes the desktop-grab path.
Triggers: When the default fixture stubs are used, as in this test.
Suggested fix: Stub screenAt() to return a real screen and arrange a corresponding screenshot widget, then assert the grab made by getScreenShotPixmap() separately from the desktop capture.
What
Add GoogleTest unit tests for the core manager and DBus classes:
autotests/src/test_CPickerManager.cpp— 27 casesautotests/src/test_CScreenshotWidget.cpp— 9 casesautotests/src/test_DBusNotify.cpp— 22 casesPart of a 3-part series upstreaming unit tests for deepin-picker.
Why
Extend test coverage to the screenshot manager, the per-screen screenshot widget and the DBus notification helper.
Notes
file(GLOB test_*.cpp),BUILD_TESTS=ON) introduced in the framework PR (test: add CMake unit test framework and tests for utils/settings/desktopinfo #59).deepin-picker.pro) these files are not referenced, so this PR does not affect the existing build and introduces no compile errors.Verification
qmake6 && make) succeeds; the test sources are not compiled by it (notest_*.oproduced).Summary by Sourcery
Expand automated unit-test coverage across the picker manager, screenshot widget, and DBus notification components.
Enhancements:
Tests: