diff --git a/kdevplatform/project/tests/test_projectmodel.cpp b/kdevplatform/project/tests/test_projectmodel.cpp --- a/kdevplatform/project/tests/test_projectmodel.cpp +++ b/kdevplatform/project/tests/test_projectmodel.cpp @@ -321,6 +321,10 @@ QCOMPARE( child->model(), static_cast(nullptr) ); QCOMPARE( subchild->model(), static_cast(nullptr) ); + + delete subchild; + delete child; + delete parent; } void TestProjectModel::testRename() @@ -362,6 +366,7 @@ QCOMPARE( s.count(), 0 ); } QCOMPARE( item->text(), expectedItemText ); + delete proj; } void TestProjectModel::testRename_data() @@ -455,6 +460,7 @@ QCOMPARE( item, rootItem ); QCOMPARE( item->text(), proj->name() ); QCOMPARE( item->path(), proj->path() ); + delete proj; } void TestProjectModel::testItemsForPath() @@ -529,6 +535,7 @@ QCOMPARE(Path(project->fileSet().toList().at(0).toUrl()), path); delete item; QVERIFY(project->fileSet().isEmpty()); + delete project; } void TestProjectModel::testProjectFileIcon() @@ -541,6 +548,7 @@ item->setPath(Path(QDir::tempPath() + "/bar.cpp")); QCOMPARE(item->iconName(), db.mimeTypeForUrl(item->path().toUrl()).iconName()); QVERIFY(item->iconName() != txtIcon); + delete item; } QTEST_MAIN( TestProjectModel) diff --git a/kdevplatform/sublime/tests/test_areaoperation.cpp b/kdevplatform/sublime/tests/test_areaoperation.cpp --- a/kdevplatform/sublime/tests/test_areaoperation.cpp +++ b/kdevplatform/sublime/tests/test_areaoperation.cpp @@ -333,9 +333,7 @@ } return Area::ContinueWalker; } - char* message() { - return qstrdup(failureMessage.toLatin1().data()); - } + bool foundViewWithoutWidget = false; QString failureMessage; }; @@ -353,7 +351,7 @@ AreaWidgetChecker checker; m_area1->walkViews(checker, m_area1->rootIndex()); m_area1->walkToolViews(checker, Sublime::AllPositions); - QVERIFY2(!checker.foundViewWithoutWidget, checker.message()); + QVERIFY2(!checker.foundViewWithoutWidget, checker.failureMessage.toLatin1().data()); } void TestAreaOperation::simpleViewAdditionAndDeletion() diff --git a/kdevplatform/sublime/tests/test_controller.cpp b/kdevplatform/sublime/tests/test_controller.cpp --- a/kdevplatform/sublime/tests/test_controller.cpp +++ b/kdevplatform/sublime/tests/test_controller.cpp @@ -40,15 +40,15 @@ void TestController::areaDeletion() { - Controller* controller = new Controller; - Document *doc = new ToolDocument(QStringLiteral("tool"), controller, new SimpleToolWidgetFactory(QStringLiteral("tool"))); + Controller controller; + Document *doc = new ToolDocument(QStringLiteral("tool"), &controller, new SimpleToolWidgetFactory(QStringLiteral("tool"))); //create a view which does not belong to an area View* view1 = doc->createView(); Q_UNUSED(view1); //create an area and two views in it - Area *area = new Area(controller, QStringLiteral("MyArea")); - controller->addDefaultArea(area); - QCOMPARE(controller->defaultAreas().count(), 1); + Area *area = new Area(&controller, QStringLiteral("MyArea")); + controller.addDefaultArea(area); + QCOMPARE(controller.defaultAreas().count(), 1); View* view2 = doc->createView(); view2->setObjectName(QStringLiteral("VIEW2")); area->addView(view2); @@ -63,7 +63,7 @@ QEXPECT_FAIL("", "Fails because of delayed view deletion", Continue); QCOMPARE(doc->views().count(), 1); - QCOMPARE(controller->defaultAreas().count(), 0); + QCOMPARE(controller.defaultAreas().count(), 0); QTest::qWait(100); // wait for deleteLaters qDebug() << "Deleting doc"; diff --git a/kdevplatform/sublime/tests/test_toolviewtoolbar.cpp b/kdevplatform/sublime/tests/test_toolviewtoolbar.cpp --- a/kdevplatform/sublime/tests/test_toolviewtoolbar.cpp +++ b/kdevplatform/sublime/tests/test_toolviewtoolbar.cpp @@ -39,10 +39,22 @@ explicit ToolViewToolBarFactory(const QString &id): SimpleToolWidgetFactory(id) {} QList toolBarActions( QWidget* ) const override { - QAction* action = new QAction(actionText, nullptr); - return QList() << action; + return actionList; } - QString actionText; + + ~ToolViewToolBarFactory() override + { + qDeleteAll(actionList); + } + + void addAction(const QString &text) + { + QAction* action = new QAction(text, nullptr); + actionList.append(action); + } + +private: + QList actionList; }; void TestToolViewToolBar::init() @@ -55,7 +67,7 @@ // a horizontal tool with toolbar ToolViewToolBarFactory* factoryT1 = new ToolViewToolBarFactory(QStringLiteral("tool1factory")); actionTextT1 = QStringLiteral("Tool1Action"); - factoryT1->actionText = actionTextT1; + factoryT1->addAction(actionTextT1); tool1 = new ToolDocument( QStringLiteral("tool1"), controller, factoryT1 ); viewT11 = tool1->createView(); area->addToolView( viewT11, Sublime::Bottom ); @@ -63,7 +75,7 @@ // a vertical tool with toolbar ToolViewToolBarFactory* factoryT2 = new ToolViewToolBarFactory(QStringLiteral("tool2factory")); actionTextT2 = QStringLiteral("Tool2Action"); - factoryT2->actionText = actionTextT2; + factoryT2->addAction(actionTextT2); tool2 = new ToolDocument( QStringLiteral("tool2"), controller, factoryT2 ); viewT21 = tool2->createView(); area->addToolView( viewT21, Sublime::Left ); @@ -90,6 +102,7 @@ char* failMsg = qstrdup(QStringLiteral("Expected to find a toolbar but found %1").arg(barCount).toLatin1().data()); Q_UNUSED(failMsg); Q_ASSERT_X(barCount == 1, loc, failMsg); + delete [] failMsg; return toolBars.at(0); } diff --git a/kdevplatform/sublime/tests/test_viewactivation.cpp b/kdevplatform/sublime/tests/test_viewactivation.cpp --- a/kdevplatform/sublime/tests/test_viewactivation.cpp +++ b/kdevplatform/sublime/tests/test_viewactivation.cpp @@ -143,37 +143,38 @@ dock->setWidget(toolBreaker); mw->addDockWidget(Qt::LeftDockWidgetArea, dock); + QFocusEvent focusEvent(QEvent::FocusIn); //now post events to the widgets and see if mainwindow has the right active views //activate view - qApp->sendEvent(view212->widget(), new QFocusEvent(QEvent::FocusIn)); + qApp->sendEvent(view212->widget(), &focusEvent); QString failMsg = QStringLiteral("\nWas expecting %1 to be active but got %2"). arg(view212->objectName(), mw->activeView()->objectName()); QVERIFY2(mw->activeView() == view212, failMsg.toLatin1().data()); //activate tool view and check that both view and tool view are active - qApp->sendEvent(viewT31->widget(), new QFocusEvent(QEvent::FocusIn)); + qApp->sendEvent(viewT31->widget(), &focusEvent); QCOMPARE(mw->activeView(), view212); QCOMPARE(mw->activeToolView(), viewT31); //active another view - qApp->sendEvent(view241->widget(), new QFocusEvent(QEvent::FocusIn)); + qApp->sendEvent(view241->widget(), &focusEvent); QCOMPARE(mw->activeView(), view241); QCOMPARE(mw->activeToolView(), viewT31); //focus a widget not in the area - qApp->sendEvent(breaker, new QFocusEvent(QEvent::FocusIn)); + qApp->sendEvent(breaker, &focusEvent); QCOMPARE(mw->activeView(), view241); QCOMPARE(mw->activeToolView(), viewT31); //focus a dock not in the area - qApp->sendEvent(toolBreaker, new QFocusEvent(QEvent::FocusIn)); + qApp->sendEvent(toolBreaker, &focusEvent); QCOMPARE(mw->activeView(), view241); QCOMPARE(mw->activeToolView(), viewT31); //focus inner widget for view221 QListView *inner = mw->findChild(QStringLiteral("doc2_inner")); QVERIFY(inner); - qApp->sendEvent(inner, new QFocusEvent(QEvent::FocusIn)); + qApp->sendEvent(inner, &focusEvent); QCOMPARE(mw->activeView(), view221); QCOMPARE(mw->activeToolView(), viewT31); }