diff --git a/tests/test_application_slots.cpp b/tests/test_application_slots.cpp index c39a12079..136d93f28 100644 --- a/tests/test_application_slots.cpp +++ b/tests/test_application_slots.cpp @@ -58,3 +58,23 @@ TEST(ApplicationSlots, onFocusChangedBothValidNoCrash) drawApp->onFocusChanged(&w1, &w2); SUCCEED(); } + +// ========================================================================= +// Application::defaultAttriVar() – fallback to attributionWidget (line 608) +// ========================================================================= +#include "publicApi.h" + +TEST(ApplicationSlots, DefaultAttrivar_FallbackToAttributionWidget) +{ + // Ensure _defaultAttriVars doesn't contain the current scene key. + // Clear it so the lookup misses and we hit the fallback at line 608. + drawApp->_defaultAttriVars.clear(); + + // Call defaultAttriVar with currentDrawScence() and an arbitrary attri. + QVariant result = drawApp->defaultAttriVar(drawApp->currentDrawScence(), 999992); + + if (drawApp->drawBoard() == nullptr || drawApp->drawBoard()->attributionWidget() == nullptr) { + GTEST_SKIP() << "attributionWidget() is null in offscreen environment"; + } + SUCCEED(); +} diff --git a/tests/test_cattributemanagerwgt_funcs.cpp b/tests/test_cattributemanagerwgt_funcs.cpp index 9cc634168..b9733de7e 100644 --- a/tests/test_cattributemanagerwgt_funcs.cpp +++ b/tests/test_cattributemanagerwgt_funcs.cpp @@ -396,4 +396,37 @@ TEST(CAttributeManagerWgtTest, AttributeWgtsEmptyWhenNoInstall) // } // ========================================================================= + +// ========================================================================= +// removeComAttributeWgt – found branch (lines 290-295) +// Avoids the UB bug at line 302 by NOT inserting into s_allInstalledDefaultVar. +// ========================================================================= +#include "publicApi.h" +#include "cattributeitemwidget.h" + +TEST(CAttributeManagerWgtTest, RemoveComAttributeWgt_FoundBranch_NoUB) +{ + MainWindow *mw = drawApp->topMainWindow(); + ASSERT_NE(mw, nullptr); + DrawBoard *board = mw->drawBoard(); + ASSERT_NE(board, nullptr); + + auto *mgr = board->attributionWidget(); + if (mgr == nullptr) { + GTEST_SKIP() << "attributionWidget() is null in offscreen environment"; + } + + // Insert ONLY into s_allInstalledAttriWgts, NOT s_allInstalledDefaultVar. + // This ensures itfV == end() at line 300, avoiding the UB at line 302. + auto *w = new CAttributeWgt(900001, mgr); + mgr->s_allInstalledAttriWgts.insert(900001, w); + + // Call removeComAttributeWgt → hits lines 290-295 (found: disconnect + erase). + mgr->removeComAttributeWgt(900001); + + // Verify the key is removed from s_allInstalledAttriWgts. + EXPECT_FALSE(mgr->s_allInstalledAttriWgts.contains(900001)); + + delete w; +} #include "test_cattributemanagerwgt_funcs.moc" diff --git a/tests/test_ccentralwidget_lambdas.cpp b/tests/test_ccentralwidget_lambdas.cpp index aea5b0251..e5a151944 100644 --- a/tests/test_ccentralwidget_lambdas.cpp +++ b/tests/test_ccentralwidget_lambdas.cpp @@ -151,3 +151,29 @@ TEST(TabBarWgtSizeModeLambdaTest, SizeModeChangedKeepsBarHidden) qApp->processEvents(); EXPECT_FALSE(bar.isVisible()); } + +// ========================================================================= +// Page::signalSetScale lambda – emit zoomValueChanged (line 344) +// ========================================================================= +#include + +TEST(CCentralWidgetLambdas, SignalSetScale_TriggersZoomValueChanged) +{ + createNewViewByShortcutKey(); + MainWindow *mw = drawApp->topMainWindow(); + ASSERT_NE(mw, nullptr); + DrawBoard *board = mw->drawBoard(); + ASSERT_NE(board, nullptr); + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + + // The lambda at line 344 checks `this == borad()->currentPage()`. + // getCurView() returns the current page's _view, so the lambda is connected + // and the condition should be true. + QSignalSpy spy(board, &DrawBoard::zoomValueChanged); + + emit view->signalSetScale(1.5); + qApp->processEvents(); + + EXPECT_GE(spy.count(), 1); +} diff --git a/tests/test_ccutwidget_lambdas.cpp b/tests/test_ccutwidget_lambdas.cpp index bead7a6cd..f6d9ef508 100644 --- a/tests/test_ccutwidget_lambdas.cpp +++ b/tests/test_ccutwidget_lambdas.cpp @@ -304,3 +304,36 @@ TEST(CCutWidgetLambdas, SizeReduceAction_HeightAtMin_DoesNotDecrement) int height = w.m_heightEdit->text().trimmed().toInt(); EXPECT_EQ(height, 10); } + +// ========================================================================= +// m_doneBtn clicked – clearFocus branches (lines 603/607) +// ========================================================================= +#include + +TEST(CCutWidgetLambdas, DoneBtn_ClearsWidthEditFocus) +{ + CCutWidget w; + w.show(); + qApp->processEvents(); + + w.m_widthEdit->lineEdit()->setFocus(Qt::OtherFocusReason); + qApp->processEvents(); + if (!w.m_widthEdit->lineEdit()->hasFocus()) { + GTEST_SKIP() << "Cannot set focus on widthEdit in offscreen environment"; + } + + w.m_heightEdit->lineEdit()->setFocus(Qt::OtherFocusReason); + qApp->processEvents(); + if (!w.m_heightEdit->lineEdit()->hasFocus()) { + GTEST_SKIP() << "Cannot set focus on heightEdit in offscreen environment"; + } + + QSignalSpy spy(&w, &CCutWidget::finshed); + emit w.m_doneBtn->clicked(); + + // Lines 603/607: clearFocus on both edits should be hit. + EXPECT_FALSE(w.m_widthEdit->lineEdit()->hasFocus()); + EXPECT_FALSE(w.m_heightEdit->lineEdit()->hasFocus()); + // Line 609: emit finshed(true) + EXPECT_EQ(spy.count(), 1); +} diff --git a/tests/test_cdrawscene_cgraphicsview_coverage.cpp b/tests/test_cdrawscene_cgraphicsview_coverage.cpp index 22446c732..a76923923 100644 --- a/tests/test_cdrawscene_cgraphicsview_coverage.cpp +++ b/tests/test_cdrawscene_cgraphicsview_coverage.cpp @@ -337,3 +337,40 @@ TEST(CDrawSceneGraphicsViewCoverageTest, ContextMenuEvent_IsShowContextFalse_NoP EXPECT_EQ(qApp->activePopupWidget(), nullptr); } + +// --------------------------------------------------------------------------- +// getGroupTreeInfo with real nested group (lines 466-470) +// --------------------------------------------------------------------------- + +TEST(CDrawSceneGraphicsViewCoverageTest, GetGroupTreeInfo_NestedGroup_ProcessEvents) +{ + createNewViewByShortcutKey(); + PageView *view = CManageViewSigleton::GetInstance()->getCurView(); + ASSERT_NE(view, nullptr); + PageScene *scene = view->drawScene(); + ASSERT_NE(scene, nullptr); + + auto *r1 = new CGraphicsRectItem(QRectF(0, 0, 40, 40)); + auto *r2 = new CGraphicsRectItem(QRectF(50, 0, 40, 40)); + auto *r3 = new CGraphicsRectItem(QRectF(0, 60, 40, 40)); + scene->addCItem(r1); + scene->addCItem(r2); + scene->addCItem(r3); + + auto *inner = scene->creatGroup({r1, r2}); + ASSERT_NE(inner, nullptr); + auto *outer = scene->creatGroup({inner, r3}); + ASSERT_NE(outer, nullptr); + + // outer->getGroups() contains inner → 466 foreach → 467 processEvent=true + // → 468 qApp->processEvents() is hit + auto info = scene->getGroupTreeInfo(outer, EDuplicate, true); + PageScene::releaseBzItemsTreeInfo(info); + + // Cleanup: clear selection, remove items + scene->clearSelectGroup(); + scene->removeCItem(r1, true); + scene->removeCItem(r2, true); + scene->removeCItem(r3, true); + drawApp->setCurrentTool(selection); +} diff --git a/tests/test_cdrawscene_touchevent.cpp b/tests/test_cdrawscene_touchevent.cpp index 3cedfb619..c672482fc 100644 --- a/tests/test_cdrawscene_touchevent.cpp +++ b/tests/test_cdrawscene_touchevent.cpp @@ -394,3 +394,55 @@ TEST_F(PageStateGuard, RecordSecenInfoToCmd_EItemAdded_ReturnsEarly) EXPECT_EQ(undoBefore, undoAfter); } + +// =========================================================================== +// Touch event: double TouchBegin → accept=false (line 335) +// =========================================================================== + +TEST_F(PageStateGuard, TouchEvent_DoubleTouchBegin_AcceptFalse) +{ + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + PageScene *scene = view->drawScene(); + ASSERT_NE(scene, nullptr); + Page *page = view->page(); + ASSERT_NE(page, nullptr); + + // Verify page() is accessible (non-null) before sending touch events. + if (scene->page() == nullptr) { + GTEST_SKIP() << "scene->page() is null in offscreen environment"; + } + + page->setCurrentTool(selection); + + QPointF scenePos1(50, 50); + QPointF scenePos2(53, 50); // within ±3px of scenePos1 + + // First TouchBegin: starts the double-click timer in the tool. + { + QEventPoint ep(0, QEventPoint::Pressed, scenePos1, + view->mapToGlobal(view->mapFromScene(scenePos1))); + QTouchEvent te1(QEvent::TouchBegin, QPointingDevice::primaryPointingDevice(), + Qt::NoModifier, {ep}); + scene->event(&te1); + } + + // Second TouchBegin within ±3px: triggers dueTouchDoubleClickedStart + // → setAccepted(false) + interrupt() → accept becomes false → line 335. + { + QEventPoint ep(0, QEventPoint::Pressed, scenePos2, + view->mapToGlobal(view->mapFromScene(scenePos2))); + QTouchEvent te2(QEvent::TouchBegin, QPointingDevice::primaryPointingDevice(), + Qt::NoModifier, {ep}); + scene->event(&te2); + } + + // Cleanup: interrupt any working tool and clear undo stack. + auto *tool = page->currentTool_p(); + if (tool != nullptr && tool->isWorking()) { + tool->interrupt(); + qApp->processEvents(); + } + CUndoRedoCommand::clearCommand(); + drawApp->setCurrentTool(selection); +} diff --git a/tests/test_cgraphicslineitem_funcs.cpp b/tests/test_cgraphicslineitem_funcs.cpp index 83e06281b..e95e59df3 100644 --- a/tests/test_cgraphicslineitem_funcs.cpp +++ b/tests/test_cgraphicslineitem_funcs.cpp @@ -425,3 +425,125 @@ TEST(CGraphicsLineItemFuncTest, LoadGraphicsUnit_RoundTrip_PreservesData) unit.release(); unit2.release(); } + +// ========================================================================= +// updateHandlesGeometry – Rotation handle branches (lines 279-306) +// ========================================================================= +#include "publicApi.h" + +TEST(CGraphicsLineItemFuncTest, UpdateHandlesGeometry_Rotation_DxPos_DyNeg) +{ + createNewViewByShortcutKey(); + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + PageScene *scene = view->drawScene(); + ASSERT_NE(scene, nullptr); + + auto *line = new CGraphicsLineItem(QPointF(0, 100), QPointF(100, 0)); + scene->addCItem(line); + scene->selectItem(line); + ASSERT_TRUE(line->isSelected()); + ASSERT_FALSE(line->isMutiSelected()); + ASSERT_EQ(line->bzGroup(), nullptr); + + line->m_handles.push_back(new CSizeHandleRect(line, CSizeHandleRect::Rotation)); + line->updateHandlesGeometry(); + SUCCEED(); + + line->clearHandle(); + scene->clearSelectGroup(); + scene->removeCItem(line, true); + drawApp->setCurrentTool(selection); +} + +TEST(CGraphicsLineItemFuncTest, UpdateHandlesGeometry_Rotation_DxPos_DyPos) +{ + createNewViewByShortcutKey(); + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + PageScene *scene = view->drawScene(); + ASSERT_NE(scene, nullptr); + + auto *line = new CGraphicsLineItem(QPointF(0, 0), QPointF(100, 100)); + scene->addCItem(line); + scene->selectItem(line); + ASSERT_TRUE(line->isSelected()); + + line->m_handles.push_back(new CSizeHandleRect(line, CSizeHandleRect::Rotation)); + line->updateHandlesGeometry(); + SUCCEED(); + + line->clearHandle(); + scene->clearSelectGroup(); + scene->removeCItem(line, true); + drawApp->setCurrentTool(selection); +} + +TEST(CGraphicsLineItemFuncTest, UpdateHandlesGeometry_Rotation_DxNeg_DyPos) +{ + createNewViewByShortcutKey(); + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + PageScene *scene = view->drawScene(); + ASSERT_NE(scene, nullptr); + + auto *line = new CGraphicsLineItem(QPointF(100, 0), QPointF(0, 100)); + scene->addCItem(line); + scene->selectItem(line); + ASSERT_TRUE(line->isSelected()); + + line->m_handles.push_back(new CSizeHandleRect(line, CSizeHandleRect::Rotation)); + line->updateHandlesGeometry(); + SUCCEED(); + + line->clearHandle(); + scene->clearSelectGroup(); + scene->removeCItem(line, true); + drawApp->setCurrentTool(selection); +} + +TEST(CGraphicsLineItemFuncTest, UpdateHandlesGeometry_Rotation_DxNeg_DyNeg) +{ + createNewViewByShortcutKey(); + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + PageScene *scene = view->drawScene(); + ASSERT_NE(scene, nullptr); + + auto *line = new CGraphicsLineItem(QPointF(100, 100), QPointF(0, 0)); + scene->addCItem(line); + scene->selectItem(line); + ASSERT_TRUE(line->isSelected()); + + line->m_handles.push_back(new CSizeHandleRect(line, CSizeHandleRect::Rotation)); + line->updateHandlesGeometry(); + SUCCEED(); + + line->clearHandle(); + scene->clearSelectGroup(); + scene->removeCItem(line, true); + drawApp->setCurrentTool(selection); +} + +TEST(CGraphicsLineItemFuncTest, UpdateHandlesGeometry_Rotation_VerticalLine) +{ + createNewViewByShortcutKey(); + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + PageScene *scene = view->drawScene(); + ASSERT_NE(scene, nullptr); + + auto *line = new CGraphicsLineItem(QPointF(50, 0), QPointF(50, 100)); + scene->addCItem(line); + scene->selectItem(line); + ASSERT_TRUE(line->isSelected()); + + line->m_handles.push_back(new CSizeHandleRect(line, CSizeHandleRect::Rotation)); + line->updateHandlesGeometry(); + SUCCEED(); + + line->clearHandle(); + scene->clearSelectGroup(); + scene->removeCItem(line, true); + drawApp->setCurrentTool(selection); +} diff --git a/tests/test_cgraphicstextitem_ext2.cpp b/tests/test_cgraphicstextitem_ext2.cpp index 917212c78..a58d8024b 100644 --- a/tests/test_cgraphicstextitem_ext2.cpp +++ b/tests/test_cgraphicstextitem_ext2.cpp @@ -119,3 +119,25 @@ TEST(CGraphicsTextItemExt2, MouseDoubleClickEvent_NoCrash) // mouseDoubleClickEvent is a no-op (Q_UNUSED), should not crash SUCCEED(); } + +// ========================================================================= +// currentCharFormat() – empty editor branch (line 134) +// ========================================================================= + +TEST(CGraphicsTextItemExt2, CurrentCharFormat_EmptyEditor_ReturnsDefault) +{ + // Create a text item that has NOT entered edit state (m_pTextEdit is null). + CGraphicsTextItem item("Hello draw"); + // Do not call changToEditState, so m_pTextEdit remains nullptr. + // currentCharFormat() should hit the `return QTextCharFormat()` branch. + QTextCharFormat fmt = item.currentCharFormat(); + // Default-constructed QTextCharFormat has no properties set. + EXPECT_FALSE(fmt.hasProperty(QTextFormat::FontWeight)); +} + +TEST(CGraphicsTextItemExt2, CurrentCharFormat_EmptyEditor_DefaultConstructor) +{ + CGraphicsTextItem item; + QTextCharFormat fmt = item.currentCharFormat(); + SUCCEED(); // Default QTextCharFormat is valid but has no properties +} diff --git a/tests/test_cviewmanagement_funcs2.cpp b/tests/test_cviewmanagement_funcs2.cpp index a13512045..0c7501ac5 100644 --- a/tests/test_cviewmanagement_funcs2.cpp +++ b/tests/test_cviewmanagement_funcs2.cpp @@ -105,3 +105,62 @@ TEST(CFileWatcherFileChangedSignal, MultipleEmissions) EXPECT_EQ(spy.count(), 2); } + +// ========================================================================= +// setCurView – m_curIndex==-1 recovery branch (lines 111-112) +// ========================================================================= + +TEST(CManageViewSigletonFuncs2, SetCurView_CurIndexMinus1_RecoveryBranch) +{ + auto *inst = CManageViewSigleton::GetInstance(); + ASSERT_NE(inst, nullptr); + + // Snapshot state for restoration. + QList savedViews = inst->m_allViews; + int savedIndex = inst->m_curIndex; + + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + + // Set up: single view in list, m_curIndex = -1. + inst->m_allViews = {view}; + inst->m_curIndex = -1; + + // Call setCurView with a view that IS in the list. + // m_curIndex == -1 && !m_allViews.isEmpty() → m_curIndex = 0 (lines 111-112). + inst->setCurView(view); + EXPECT_EQ(inst->m_curIndex, 0); + + // Restore. + inst->m_allViews = savedViews; + inst->m_curIndex = savedIndex; +} + +// ========================================================================= +// removeView – delete empty → m_curIndex=-1 branch (lines 132-133) +// ========================================================================= + +TEST(CManageViewSigletonFuncs2, RemoveView_DeleteLast_CurIndexBecomesMinus1) +{ + auto *inst = CManageViewSigleton::GetInstance(); + ASSERT_NE(inst, nullptr); + + // Snapshot state for restoration. + QList savedViews = inst->m_allViews; + int savedIndex = inst->m_curIndex; + + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + + // Set up: single view in list, m_curIndex = 0. + inst->m_allViews = {view}; + inst->m_curIndex = 0; + + // removeView: removes the only view → list empty → m_curIndex = -1 (lines 132-133). + inst->removeView(view); + EXPECT_EQ(inst->m_curIndex, -1); + + // Restore: re-add the view and restore state. + inst->m_allViews = savedViews; + inst->m_curIndex = savedIndex; +} diff --git a/tests/test_drawboard.cpp b/tests/test_drawboard.cpp index b7cc06d23..e2ae67b64 100644 --- a/tests/test_drawboard.cpp +++ b/tests/test_drawboard.cpp @@ -329,3 +329,25 @@ TEST(DrawBoardDropEventTest, DoesNotCrash) delete mimeData; SUCCEED(); } + +// ========================================================================= +// DrawBoard::defaultAttrivar() – fallback to attributionWidget (line 435) +// ========================================================================= + +TEST(DrawBoardTest, DefaultAttrivar_FallbackToAttributionWidget) +{ + MainWindow *mw = drawApp->topMainWindow(); + ASSERT_NE(mw, nullptr); + DrawBoard *board = mw->drawBoard(); + ASSERT_NE(board, nullptr); + + createNewViewByShortcutKey(); + Page *page = board->currentPage(); + ASSERT_NE(page, nullptr); + + // Use an int key that the context has never stored → _context->defaultAttri + // returns null → falls back to attributionWidget()->defaultAttriVar (line 435). + QVariant result = board->defaultAttriVar(page, 999991); + // The result may be invalid if attributionWidget is null; just verify no crash. + SUCCEED(); +} diff --git a/tests/test_fileselectdialog_funcs.cpp b/tests/test_fileselectdialog_funcs.cpp index 8fd84a877..55083746e 100644 --- a/tests/test_fileselectdialog_funcs.cpp +++ b/tests/test_fileselectdialog_funcs.cpp @@ -119,4 +119,26 @@ TEST(PathActiveButtonTest, PaintEvent_ViaGrab_NoCrash) EXPECT_FALSE(pix.isNull()); } + +// ========================================================================= +// FileSelectDialog constructor – setDirectory else branch (line 206) +// ========================================================================= +#include "publicApi.h" + +TEST(FileSelectDialogTest, Constructor_WithBoard_HitsSetDirectoryElseBranch) +{ + MainWindow *mw = drawApp->topMainWindow(); + ASSERT_NE(mw, nullptr); + DrawBoard *board = mw->drawBoard(); + ASSERT_NE(board, nullptr); + + // Stack-constructed FileSelectDialog with a real board parent. + // Constructor hits setDirectory else branch (line 206) when + // isTabletSystemEnvir() is false (normal desktop environment). + FileSelectDialog dia(board); + + // Destructor cleans up automatically. + SUCCEED(); +} + #endif // TEST_FILEDIALOG_FUNCS_ITEM diff --git a/tests/test_page_methods.cpp b/tests/test_page_methods.cpp index 3340d5fa5..0b5f0cc33 100644 --- a/tests/test_page_methods.cpp +++ b/tests/test_page_methods.cpp @@ -270,3 +270,23 @@ TEST(PageSetCurrentToolTest, SetDifferentTool) page->setCurrentTool(noselected); EXPECT_EQ(page->currentTool(), static_cast(noselected)); } + +// ========================================================================= +// Page::name() – _context non-empty branch (line 538) +// ========================================================================= + +TEST(PageMethods, Name_ReturnsNonEmptyWhenContextExists) +{ + MainWindow *mw = drawApp->topMainWindow(); + ASSERT_NE(mw, nullptr); + DrawBoard *board = mw->drawBoard(); + ASSERT_NE(board, nullptr); + + createNewViewByShortcutKey(); + Page *page = board->currentPage(); + ASSERT_NE(page, nullptr); + + // _context is non-null after page creation → hits `return _context->name()` + QString pageName = page->name(); + EXPECT_FALSE(pageName.isEmpty()); +} diff --git a/tests/test_pagecontext_addsceneitem.cpp b/tests/test_pagecontext_addsceneitem.cpp index 45b289e40..0b71da0b7 100644 --- a/tests/test_pagecontext_addsceneitem.cpp +++ b/tests/test_pagecontext_addsceneitem.cpp @@ -97,3 +97,68 @@ TEST(PageContextAddSceneItemTest, AddSceneItemWithRecordFlagAddsItem) EXPECT_GT(ctx->scene()->items().size(), beforeCount); } + +// ========================================================================= +// addSceneItem – sub-thread queued invocation (lines 161-172) +// ========================================================================= +#include +#include + +TEST(PageContextAddSceneItem, AddSceneItem_FromSubThread_QueuedInvocation) +{ + createNewViewByShortcutKey(); + PageView *view = getCurView(); + ASSERT_NE(view, nullptr); + PageScene *scene = view->drawScene(); + ASSERT_NE(scene, nullptr); + + // Probe: can we create a Rect item from a CGraphicsUnit? + CGraphicsUnit probe; + probe.head.dataType = RectType; + auto *probeItem = CGraphicsItem::creatItemInstance(probe.head.dataType, probe); + if (probeItem == nullptr) { + GTEST_SKIP() << "creatItemInstance returned null for empty Rect unit"; + } + delete probeItem; + + PageContext *ctx = view->page()->context(); + ASSERT_NE(ctx, nullptr); + ASSERT_NE(ctx->scene(), nullptr); + + int beforeCount = scene->items().size(); + + // Call addSceneItem from a non-main thread → queued invocation (lines 161-165). + { + CGraphicsUnit u2; + u2.head.dataType = RectType; + std::thread t([ctx, &u2]() { + ctx->addSceneItem(u2, true, false, false); + }); + t.join(); + } + + // Process queued lambda on main thread → addCItem (lines 167-168). + QCoreApplication::processEvents(); + + // Call with releaseUnit=true, select=true → lines 170-172. + { + CGraphicsUnit u3; + u3.head.dataType = RectType; + std::thread t([ctx, &u3]() { + ctx->addSceneItem(u3, true, true, true); + }); + t.join(); + } + QCoreApplication::processEvents(); + + // Cleanup: remove any newly added rect items. + scene->clearSelectGroup(); + auto items = scene->items(); + for (auto *item : items) { + auto *rectItem = dynamic_cast(item); + if (rectItem != nullptr) { + scene->removeCItem(rectItem, true); + } + } + drawApp->setCurrentTool(selection); +} diff --git a/tests/test_tabbarwgt.cpp b/tests/test_tabbarwgt.cpp index 20cc8398c..0c21cee41 100644 --- a/tests/test_tabbarwgt.cpp +++ b/tests/test_tabbarwgt.cpp @@ -40,3 +40,28 @@ TEST(TabBarWgtCtorTest, SetsStandardPropertiesAndHidesItself) EXPECT_NE(bar.pageManager(), nullptr); EXPECT_EQ(bar.pageManager(), board); } + +// ========================================================================= +// addItem – CompactMode setTabMinimumSize branch (line 107) +// ========================================================================= +#include + +TEST(TabBarWgtTest, AddItem_CompactMode_HitsSetTabMinimumSize) +{ + MainWindow *mw = drawApp->topMainWindow(); + ASSERT_NE(mw, nullptr); + DrawBoard *board = mw->drawBoard(); + ASSERT_NE(board, nullptr); + + TabBarWgt bar(board); + + // Set CompactMode → addItem hits the CompactMode branch (line 107). + DGuiApplicationHelper::instance()->setSizeMode(DGuiApplicationHelper::CompactMode); + bar.addItem("ut", "ut-key"); + + EXPECT_GT(bar.count(), 0); + + // Cleanup. + bar.removeItem("ut-key"); + DGuiApplicationHelper::instance()->setSizeMode(DGuiApplicationHelper::NormalMode); +} diff --git a/tests/test_tabbarwgt_menu.cpp b/tests/test_tabbarwgt_menu.cpp index 484bd21ed..97a48379a 100644 --- a/tests/test_tabbarwgt_menu.cpp +++ b/tests/test_tabbarwgt_menu.cpp @@ -207,3 +207,47 @@ TEST(FileSelectDialogSaveSetting, MultipleCalls_NoCrash) dialog.saveSetting(); SUCCEED(); } + +// ========================================================================= +// menu() Close tab action lambda (lines 152-153) +// ========================================================================= + +TEST(TabBarWgtMenuTest, CloseTabAction_TriggersLambda) +{ + MainWindow *mw = drawApp->topMainWindow(); + ASSERT_NE(mw, nullptr); + DrawBoard *board = mw->drawBoard(); + ASSERT_NE(board, nullptr); + + TabBarWgt bar(board); + bar.addItem("t1", "k1"); + bar.addItem("t2", "k2"); + + QMenu *menu = bar.menu(); + ASSERT_NE(menu, nullptr); + + // Find the "Close tab" action and trigger it → hits lambda (lines 152-153). + QAction *closeAction = nullptr; + for (auto *act : menu->actions()) { + if (act->text().contains("Close tab")) { + closeAction = act; + break; + } + } + + if (closeAction == nullptr) { + bar.removeItem("k1"); + bar.removeItem("k2"); + GTEST_SKIP() << "Close tab action not found in menu"; + } + + // Block signals to prevent tabCloseRequested from reaching closePage + // (which would crash with null page for standalone instance). + bar.blockSignals(true); + closeAction->trigger(); + bar.blockSignals(false); + + // Cleanup remaining tabs. + bar.removeItem("k1"); + bar.removeItem("k2"); +} diff --git a/tests/test_toolbutton_funcs.cpp b/tests/test_toolbutton_funcs.cpp index f8455013f..17589fd80 100644 --- a/tests/test_toolbutton_funcs.cpp +++ b/tests/test_toolbutton_funcs.cpp @@ -57,3 +57,21 @@ TEST(ToolButtonSetAlignment, MultipleChangesOverwrite) btn.setAlignment(Qt::AlignCenter); EXPECT_EQ(btn.m_alignment, Qt::AlignCenter); } + +// ========================================================================= +// sizeHint() – menu indicator branch (line 244) +// ========================================================================= +#include + +TEST(ToolButtonSetAlignment, SizeHint_WithMenu_IncludesIndicator) +{ + ToolButton btn(nullptr, BUTTON_STYLE); + btn.setText("ut"); + btn.setMenu(new QMenu(&btn)); + + // Calling sizeHint() with a menu set should hit the + // PM_MenuButtonIndicator branch (line 244). + QSize sz = btn.sizeHint(); + EXPECT_GT(sz.width(), 0); + EXPECT_GT(sz.height(), 0); +}