Repository navigation
Conversation
Add GoogleTest unit tests for the UI helper classes: - ColorMenu: 35 cases (construction, color actions, signal emission) - clipboard: 14 cases (clipboard copy and color format handling) - Animation: 6 cases (animation state and transitions) 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 55 cases pass with Qt6/DTK6 once the framework is present.
Reviewer's GuideAdds 55 GoogleTest cases covering ColorMenu, Clipboard, and Animation behavior using Qt fixtures and stubbed platform/settings dependencies; the tests are picked up by the opt-in CMake framework while remaining outside the default qmake build. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="autotests/src/test_ColorMenu.cpp" line_range="54" />
<code_context>
+class ColorMenuTest : public ::testing::Test {
+protected:
+ static void SetUpTestSuite() {
+ argc_ = 1;
+ app_ = new QApplication(argc_, nullptr);
+ }
+ static void TearDownTestSuite() {
</code_context>
<issue_to_address>
**issue (testing):** `QApplication` is constructed with `argc_ == 1` and a null `argv`; Qt expects a valid argument vector when argc is nonzero, so test-suite setup dereferences invalid argument storage and crashes before any ColorMenu test runs.
**Triggers:** When the CMake test target executes the ColorMenu test suite.
**Suggested fix:** Provide a real `argv` array, as done in `test_Animation.cpp`, or construct the application with argc set to zero.
```suggestion
argc_ = 0;
```
</issue_to_address>
### Comment 2
<location path="autotests/src/test_Animation.cpp" line_range="82" />
<code_context>
+ stub.set_lamda(&QWidget::hide, [](QWidget *) {
+ __DBG_STUB_INVOKE__
+ });
+ // Stub QApplication::devicePixelRatio for paintEvent
+ stub.set_lamda(VADDR(QApplication, devicePixelRatio), []() -> qreal {
+ __DBG_STUB_INVOKE__
+ return 1.0;
+ });
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** The `VADDR(QApplication, devicePixelRatio)` stub is installed with a zero-argument lambda even though `devicePixelRatio` is an instance member call and receives a `QApplication *` argument; the stub therefore has an incompatible replacement signature and the test target fails to compile or invokes the replacement incorrectly.
**Triggers:** When `PaintEvent_WithValidWidget_DrawsCircleClip` calls `qApp->devicePixelRatio()`.
**Suggested fix:** Define the replacement as `[](QApplication *, ...) -> qreal` with the signature expected by `VADDR`/`set_lamda`.
```suggestion
stub.set_lamda(VADDR(QApplication, devicePixelRatio), [](QApplication *, ...) -> qreal {
```
</issue_to_address>
### Comment 3
<location path="autotests/src/test_clipboard.cpp" line_range="73-78" />
<code_context>
+
+ obj = new Clipboard();
+
+ // Stub QApplication::clipboard() to return nullptr;
+ // QClipboard::setText will be separately stubbed at call site
+ stub.set_lamda(QApplication::clipboard, []() -> QClipboard* {
+ __DBG_STUB_INVOKE__
+ return nullptr;
+ });
+
+ // Stub QClipboard::setText(const QString&, QClipboard::Mode) to capture text
</code_context>
<issue_to_address>
**issue (testing):** The test forces `QApplication::clipboard()` to return `nullptr` and then exercises production code that unconditionally calls `clipboard->setText(colorString)`; calling an instance method through a null `QClipboard *` is undefined behavior, so the tests depend on an unsafe stub-extension implementation detail and can crash instead of testing clipboard copying.
**Triggers:** When any `copyToClipboard` test reaches the clipboard write.
**Suggested fix:** Return a real test `QClipboard` object from the `QApplication::clipboard()` stub, or avoid stubbing the accessor and install a GUI application with a usable clipboard.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| class ColorMenuTest : public ::testing::Test { | ||
| protected: | ||
| static void SetUpTestSuite() { | ||
| argc_ = 1; |
There was a problem hiding this comment.
issue (testing): QApplication is constructed with argc_ == 1 and a null argv; Qt expects a valid argument vector when argc is nonzero, so test-suite setup dereferences invalid argument storage and crashes before any ColorMenu test runs.
Triggers: When the CMake test target executes the ColorMenu test suite.
Suggested fix: Provide a real argv array, as done in test_Animation.cpp, or construct the application with argc set to zero.
| argc_ = 1; | |
| argc_ = 0; |
| __DBG_STUB_INVOKE__ | ||
| }); | ||
| // Stub QApplication::devicePixelRatio for paintEvent | ||
| stub.set_lamda(VADDR(QApplication, devicePixelRatio), []() -> qreal { |
There was a problem hiding this comment.
issue (bug_risk): The VADDR(QApplication, devicePixelRatio) stub is installed with a zero-argument lambda even though devicePixelRatio is an instance member call and receives a QApplication * argument; the stub therefore has an incompatible replacement signature and the test target fails to compile or invokes the replacement incorrectly.
Triggers: When PaintEvent_WithValidWidget_DrawsCircleClip calls qApp->devicePixelRatio().
Suggested fix: Define the replacement as [](QApplication *, ...) -> qreal with the signature expected by VADDR/set_lamda.
| stub.set_lamda(VADDR(QApplication, devicePixelRatio), []() -> qreal { | |
| stub.set_lamda(VADDR(QApplication, devicePixelRatio), [](QApplication *, ...) -> qreal { |
| // Stub QApplication::clipboard() to return nullptr; | ||
| // QClipboard::setText will be separately stubbed at call site | ||
| stub.set_lamda(QApplication::clipboard, []() -> QClipboard* { | ||
| __DBG_STUB_INVOKE__ | ||
| return nullptr; | ||
| }); |
There was a problem hiding this comment.
issue (testing): The test forces QApplication::clipboard() to return nullptr and then exercises production code that unconditionally calls clipboard->setText(colorString); calling an instance method through a null QClipboard * is undefined behavior, so the tests depend on an unsafe stub-extension implementation detail and can crash instead of testing clipboard copying.
Triggers: When any copyToClipboard test reaches the clipboard write.
Suggested fix: Return a real test QClipboard object from the QApplication::clipboard() stub, or avoid stubbing the accessor and install a GUI application with a usable clipboard.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind 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 |
What
Add GoogleTest unit tests for the UI helper classes:
autotests/src/test_ColorMenu.cpp— 35 casesautotests/src/test_clipboard.cpp— 14 casesautotests/src/test_Animation.cpp— 6 casesPart of a 3-part series upstreaming unit tests for deepin-picker.
Why
Extend test coverage to the color menu, clipboard and animation classes.
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
Tests: