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 @@ -307,11 +307,11 @@ void TestProjectModel::testTakeRow() { - ProjectBaseItem* parent = new ProjectBaseItem( nullptr, QStringLiteral("test") ); - ProjectBaseItem* child = new ProjectBaseItem( nullptr, QStringLiteral("test"), parent ); - ProjectBaseItem* subchild = new ProjectBaseItem( nullptr, QStringLiteral("subtest"), child ); + QScopedPointer parent(new ProjectBaseItem( nullptr, QStringLiteral("test") )); + QScopedPointer child(new ProjectBaseItem( nullptr, QStringLiteral("test"), parent.data() )); + QScopedPointer subchild(new ProjectBaseItem( nullptr, QStringLiteral("subtest"), child.data() )); - model->appendRow( parent ); + model->appendRow( parent.data() ); QCOMPARE( parent->model(), model ); QCOMPARE( child->model(), model ); @@ -333,15 +333,15 @@ QFETCH( int, expectedRenameCode ); const Path projectFolder = Path(QUrl::fromLocalFile(QStringLiteral("/dummyprojectfolder"))); - TestProject* proj = new TestProject; - ProjectFolderItem* rootItem = new ProjectFolderItem( proj, projectFolder, nullptr); + QScopedPointer proj(new TestProject()); + ProjectFolderItem* rootItem = new ProjectFolderItem( proj.data(), projectFolder, nullptr); proj->setProjectItem( rootItem ); new ProjectFileItem(QStringLiteral("existing"), rootItem); ProjectBaseItem* item = nullptr; if( itemType == ProjectBaseItem::Target ) { - item = new ProjectTargetItem( proj, itemText, rootItem ); + item = new ProjectTargetItem( proj.data(), itemText, rootItem ); } else if( itemType == ProjectBaseItem::File ) { item = new ProjectFileItem( itemText, rootItem ); } else if( itemType == ProjectBaseItem::Folder ) { @@ -448,8 +448,8 @@ void TestProjectModel::testWithProject() { - TestProject* proj = new TestProject(); - ProjectFolderItem* rootItem = new ProjectFolderItem( proj, Path(QUrl::fromLocalFile(QStringLiteral("/dummyprojectfolder"))), nullptr); + QScopedPointer proj(new TestProject()); + ProjectFolderItem* rootItem = new ProjectFolderItem( proj.data(), Path(QUrl::fromLocalFile(QStringLiteral("/dummyprojectfolder"))), nullptr); proj->setProjectItem( rootItem ); ProjectBaseItem* item = model->itemFromIndex( model->index( 0, 0 ) ); QCOMPARE( item, rootItem ); @@ -519,11 +519,11 @@ void TestProjectModel::testProjectFileSet() { - TestProject* project = new TestProject; + QScopedPointer project(new TestProject()); QVERIFY(project->fileSet().isEmpty()); Path path(QUrl::fromLocalFile(QDir::tempPath() + "/a")); - ProjectFileItem* item = new ProjectFileItem(project, path, project->projectItem()); + ProjectFileItem* item = new ProjectFileItem(project.data(), path, project->projectItem()); QCOMPARE(project->fileSet().size(), 1); qDebug() << path << project->fileSet().toList().at(0).toUrl(); QCOMPARE(Path(project->fileSet().toList().at(0).toUrl()), path); @@ -535,12 +535,12 @@ { QMimeDatabase db; - ProjectFileItem* item = new ProjectFileItem(nullptr, Path(QDir::tempPath() + "/foo.txt")); + QScopedPointer item(new ProjectFileItem(nullptr, Path(QDir::tempPath() + "/foo.txt"))); const QString txtIcon = db.mimeTypeForUrl(item->path().toUrl()).iconName(); QCOMPARE(item->iconName(), txtIcon); item->setPath(Path(QDir::tempPath() + "/bar.cpp")); QCOMPARE(item->iconName(), db.mimeTypeForUrl(item->path().toUrl()).iconName()); QVERIFY(item->iconName() != txtIcon); } -QTEST_MAIN( TestProjectModel) +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,15 +67,15 @@ // 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 ); // 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); }