1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
|
/***************************************************************************
* Copyright 2010 Andreas Pakulat <apaku@gmx.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "test_projectmodel.h"
#include <QTest>
#include <QSortFilterProxyModel>
#include <QDir>
#include <QMimeType>
#include <QMimeDatabase>
#include <QSignalSpy>
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
#include <QAbstractItemModelTester>
#endif
#include <projectmodel.h>
#include <projectproxymodel.h>
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
#include <tests/modeltest.h>
#endif
#include <tests/testproject.h>
#include <tests/kdevsignalspy.h>
#include <tests/autotestshell.h>
#include <tests/testcore.h>
#include <util/path.h>
using namespace KDevelop;
void debugItemModel(QAbstractItemModel* m, const QModelIndex& parent=QModelIndex(), int depth=0)
{
Q_ASSERT(m);
qDebug() << QByteArray(depth*2, '-') << m->data(parent).toString();
for(int i=0; i<m->rowCount(parent); i++) {
debugItemModel(m, m->index(i, 0, parent), depth+1);
}
}
void TestProjectModel::initTestCase()
{
AutoTestShell::init();
TestCore::initialize(Core::NoUi);
qRegisterMetaType<QModelIndex>("QModelIndex");
model = ICore::self()->projectController()->projectModel();
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
new QAbstractItemModelTester( model, this );
#else
new ModelTest( model, this );
#endif
proxy = new ProjectProxyModel( model );
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
new QAbstractItemModelTester(proxy, proxy);
#else
new ModelTest(proxy, proxy);
#endif
proxy->setSourceModel(model);
}
void TestProjectModel::init()
{
model->clear();
}
void TestProjectModel::cleanupTestCase()
{
TestCore::shutdown();
}
void TestProjectModel::testCreateFileSystemItems()
{
QFETCH( int, itemType );
QFETCH( Path, itemPath );
QFETCH( Path, expectedItemPath );
QFETCH( QString, expectedItemText );
QFETCH( QStringList, expectedRelativeItemPath );
QFETCH( int, expectedItemRow );
ProjectBaseItem* newitem = nullptr;
switch( itemType ) {
case ProjectBaseItem::Folder:
newitem = new ProjectFolderItem( nullptr, itemPath );
break;
case ProjectBaseItem::BuildFolder:
newitem = new ProjectBuildFolderItem( nullptr, itemPath );
break;
case ProjectBaseItem::File:
newitem = new ProjectFileItem( nullptr, itemPath );
break;
}
int origRowCount = model->rowCount();
model->appendRow( newitem );
QCOMPARE( model->rowCount(), origRowCount+1 );
QCOMPARE( newitem->row(), expectedItemRow );
QModelIndex idx = model->index( expectedItemRow, 0, QModelIndex() );
QVERIFY( model->itemFromIndex( idx ) );
QCOMPARE( model->itemFromIndex( idx ), newitem );
QCOMPARE( newitem->text(), expectedItemText );
QCOMPARE( newitem->path(), expectedItemPath );
if( itemType == ProjectBaseItem::File ) {
QCOMPARE( dynamic_cast<ProjectFileItem*>( newitem )->fileName(), expectedItemText );
}
if( itemType == ProjectBaseItem::Folder || itemType == ProjectBaseItem::BuildFolder ) {
QCOMPARE( dynamic_cast<ProjectFolderItem*>( newitem )->folderName(), expectedItemText );
}
QCOMPARE( newitem->type(), itemType );
QCOMPARE( model->data( idx ).toString(), expectedItemText );
QCOMPARE( model->indexFromItem( newitem ), idx );
QCOMPARE( model->pathFromIndex( idx ), expectedRelativeItemPath );
QCOMPARE( model->pathToIndex( expectedRelativeItemPath ), idx );
}
void TestProjectModel::testCreateFileSystemItems_data()
{
QString testRootDir = QDir::rootPath() + QStringLiteral("rootdir");
QString testRootFile = QDir::rootPath() + QStringLiteral("rootfile");
QTest::addColumn<int>( "itemType" );
QTest::addColumn<Path>( "itemPath" );
QTest::addColumn<Path>( "expectedItemPath" );
QTest::addColumn<QString>( "expectedItemText" );
QTest::addColumn<QStringList>( "expectedRelativeItemPath" );
QTest::addColumn<int>( "expectedItemRow" );
QTest::newRow("RootFolder")
<< (int)ProjectBaseItem::Folder
<< Path(QUrl::fromLocalFile(testRootDir))
<< Path(QUrl::fromLocalFile(testRootDir))
<< QStringLiteral("rootdir")
<< ( QStringList() << QStringLiteral("rootdir") )
<< 0;
QTest::newRow("RootBuildFolder")
<< (int)ProjectBaseItem::BuildFolder
<< Path(QUrl::fromLocalFile(testRootDir))
<< Path(QUrl::fromLocalFile(testRootDir))
<< QStringLiteral("rootdir")
<< ( QStringList() << QStringLiteral("rootdir") )
<< 0;
QTest::newRow("RootFile")
<< (int)ProjectBaseItem::File
<< Path(QUrl::fromLocalFile(testRootFile))
<< Path(QUrl::fromLocalFile(testRootFile))
<< QStringLiteral("rootfile")
<< ( QStringList() << QStringLiteral("rootfile") )
<< 0;
}
void TestProjectModel::testCreateTargetItems()
{
QFETCH( int, itemType );
QFETCH( QString, itemText );
QFETCH( QString, expectedItemText );
QFETCH( QStringList, expectedItemPath );
QFETCH( int, expectedItemRow );
ProjectBaseItem* newitem = nullptr;
switch( itemType ) {
case ProjectBaseItem::Target:
newitem = new ProjectTargetItem( nullptr, itemText );
break;
case ProjectBaseItem::LibraryTarget:
newitem = new ProjectLibraryTargetItem( nullptr, itemText );
break;
}
int origRowCount = model->rowCount();
model->appendRow( newitem );
QCOMPARE( model->rowCount(), origRowCount+1 );
QCOMPARE( newitem->row(), expectedItemRow );
QModelIndex idx = model->index( expectedItemRow, 0, QModelIndex() );
QVERIFY( model->itemFromIndex( idx ) );
QCOMPARE( model->itemFromIndex( idx ), newitem );
QCOMPARE( newitem->text(), expectedItemText );
QCOMPARE( newitem->type(), itemType );
QCOMPARE( model->data( idx ).toString(), expectedItemText );
QCOMPARE( model->indexFromItem( newitem ), idx );
QCOMPARE( model->pathFromIndex( idx ), expectedItemPath );
QCOMPARE( model->pathToIndex( expectedItemPath ), idx );
}
void TestProjectModel::testCreateTargetItems_data()
{
QTest::addColumn<int>( "itemType" );
QTest::addColumn<QString>( "itemText" );
QTest::addColumn<QString>( "expectedItemText" );
QTest::addColumn<QStringList>( "expectedItemPath" );
QTest::addColumn<int>( "expectedItemRow" );
QTest::newRow("RootTarget")
<< (int)ProjectBaseItem::Target
<< "target"
<< QStringLiteral("target")
<< ( QStringList() << QStringLiteral("target") )
<< 0;
QTest::newRow("RootLibraryTarget")
<< (int)ProjectBaseItem::LibraryTarget
<< "libtarget"
<< QStringLiteral("libtarget")
<< ( QStringList() << QStringLiteral("libtarget") )
<< 0;
}
void TestProjectModel::testChangeWithProxyModel()
{
QString projectFolderPath = QDir::rootPath() + QStringLiteral("folder1");
QString projectFilePath = QDir::rootPath() + QStringLiteral("folder1/file1");
auto* proxy = new QSortFilterProxyModel( this );
proxy->setSourceModel( model );
auto* root = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile(projectFolderPath)) );
root->appendRow( new ProjectFileItem( nullptr, Path(QUrl::fromLocalFile(projectFilePath)) ) );
model->appendRow( root );
QCOMPARE( model->rowCount(), 1 );
QCOMPARE( proxy->rowCount(), 1 );
model->removeRow( 0 );
QCOMPARE( model->rowCount(), 0 );
QCOMPARE( proxy->rowCount(), 0 );
}
void TestProjectModel::testCreateSimpleHierarchy()
{
QString folderName = QStringLiteral("rootfolder");
QString fileName = QStringLiteral("file");
QString targetName = QStringLiteral("testtarged");
QString cppFileName = QStringLiteral("file.cpp");
auto* rootFolder = new ProjectFolderItem( nullptr, Path(QUrl::fromLocalFile( QDir::rootPath() + folderName )) );
QCOMPARE(rootFolder->baseName(), folderName);
auto* file = new ProjectFileItem( fileName, rootFolder );
QCOMPARE(file->baseName(), fileName);
auto* target = new ProjectTargetItem( nullptr, targetName );
rootFolder->appendRow( target );
auto* targetfile = new ProjectFileItem( nullptr, Path(rootFolder->path(), cppFileName), target );
model->appendRow( rootFolder );
QCOMPARE( model->rowCount(), 1 );
QModelIndex folderIdx = model->index( 0, 0, QModelIndex() );
QCOMPARE( model->data( folderIdx ).toString(), folderName );
QCOMPARE( model->rowCount( folderIdx ), 2 );
QCOMPARE( model->itemFromIndex( folderIdx ), rootFolder );
QVERIFY( rootFolder->hasFileOrFolder( fileName ) );
QModelIndex fileIdx = model->index( 0, 0, folderIdx );
QCOMPARE( model->data( fileIdx ).toString(), fileName );
QCOMPARE( model->rowCount( fileIdx ), 0 );
QCOMPARE( model->itemFromIndex( fileIdx ), file );
QModelIndex targetIdx = model->index( 1, 0, folderIdx );
QCOMPARE( model->data( targetIdx ).toString(), targetName );
QCOMPARE( model->rowCount( targetIdx ), 1 );
QCOMPARE( model->itemFromIndex( targetIdx ), target );
QModelIndex targetFileIdx = model->index( 0, 0, targetIdx );
QCOMPARE( model->data( targetFileIdx ).toString(), cppFileName );
QCOMPARE( model->rowCount( targetFileIdx ), 0 );
QCOMPARE( model->itemFromIndex( targetFileIdx ), targetfile );
rootFolder->removeRow( 1 );
QCOMPARE( model->rowCount( folderIdx ), 1 );
delete file;
file = nullptr;
// Check that we also find a folder with the fileName
new ProjectFolderItem( fileName, rootFolder );
QVERIFY( rootFolder->hasFileOrFolder( fileName ) );
delete rootFolder;
QCOMPARE( model->rowCount(), 0 );
}
void TestProjectModel::testItemSanity()
{
#ifdef Q_OS_WIN
QString child3Path = QStringLiteral("file:///c:/bcd");
QString child4Path = QStringLiteral("file:///c:/abcd");
#else
QString child3Path = QStringLiteral("file:///bcd");
QString child4Path = QStringLiteral("file:///abcd");
#endif
QString newtestPath = QDir::rootPath() + QStringLiteral("newtest");
auto* parent = new ProjectBaseItem(nullptr, QStringLiteral("test"));
auto* child = new ProjectBaseItem( nullptr, QStringLiteral("test"), parent );
auto* child2 = new ProjectBaseItem(nullptr, QStringLiteral("ztest"), parent);
auto* child3 = new ProjectFileItem(nullptr, Path(QUrl(child3Path)), parent);
auto* child4 = new ProjectFileItem(nullptr, Path(QUrl(child4Path)), parent);
// Just some basic santiy checks on the API
QCOMPARE( parent->child( 0 ), child );
QCOMPARE( parent->row(), -1 );
QVERIFY( !parent->child( -1 ) );
QVERIFY( !parent->file() );
QVERIFY( !parent->folder() );
QVERIFY( !parent->project() );
QVERIFY( !parent->child( parent->rowCount() ) );
QCOMPARE( parent->iconName(), QString() );
QCOMPARE( parent->index(), QModelIndex() );
QCOMPARE( child->type(), (int)ProjectBaseItem::BaseItem );
QCOMPARE( child->lessThan( child2 ), true );
QCOMPARE( child3->lessThan( child4 ), false );
// Check that model is properly emitting data-changes
model->appendRow( parent );
QCOMPARE( parent->index(), model->index(0, 0, QModelIndex()) );
QSignalSpy s( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)) );
parent->setPath( Path(newtestPath) );
QCOMPARE( s.count(), 1 );
QCOMPARE( model->data( parent->index() ).toString(), QStringLiteral("newtest") );
parent->removeRow( child->row() );
}
void TestProjectModel::testTakeRow()
{
QScopedPointer<ProjectBaseItem> parent(new ProjectBaseItem( nullptr, QStringLiteral("test") ));
QScopedPointer<ProjectBaseItem> child(new ProjectBaseItem( nullptr, QStringLiteral("test"), parent.data() ));
QScopedPointer<ProjectBaseItem> subchild(new ProjectBaseItem( nullptr, QStringLiteral("subtest"), child.data() ));
model->appendRow( parent.data() );
QCOMPARE( parent->model(), model );
QCOMPARE( child->model(), model );
QCOMPARE( subchild->model(), model );
parent->takeRow( child->row() );
QCOMPARE( child->model(), static_cast<ProjectModel*>(nullptr) );
QCOMPARE( subchild->model(), static_cast<ProjectModel*>(nullptr) );
}
void TestProjectModel::testRename()
{
QString projectFolderPath = QDir::rootPath() + QStringLiteral("dummyprojectfolder");
QFETCH( int, itemType );
QFETCH( QString, itemText );
QFETCH( QString, newName );
QFETCH( bool, datachangesignal );
QFETCH( QString, expectedItemText );
QFETCH( int, expectedRenameCode );
const Path projectFolder = Path(QUrl::fromLocalFile(projectFolderPath));
QScopedPointer<TestProject> proj(new TestProject());
auto* 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.data(), itemText, rootItem );
} else if( itemType == ProjectBaseItem::File ) {
item = new ProjectFileItem( itemText, rootItem );
} else if( itemType == ProjectBaseItem::Folder ) {
item = new ProjectFolderItem( itemText, rootItem );
} else if( itemType == ProjectBaseItem::BuildFolder ) {
item = new ProjectBuildFolderItem( itemText, rootItem );
}
Q_ASSERT( item );
QCOMPARE(item->model(), model);
QSignalSpy s( model, SIGNAL(dataChanged(QModelIndex,QModelIndex)) );
ProjectBaseItem::RenameStatus stat = item->rename( newName );
QCOMPARE( (int)stat, expectedRenameCode );
if( datachangesignal ) {
QCOMPARE( s.count(), 1 );
QCOMPARE( qvariant_cast<QModelIndex>( s.takeFirst().at(0) ), item->index() );
} else {
QCOMPARE( s.count(), 0 );
}
QCOMPARE( item->text(), expectedItemText );
}
void TestProjectModel::testRename_data()
{
QTest::addColumn<int>( "itemType" );
QTest::addColumn<QString>( "itemText" );
QTest::addColumn<QString>( "newName" );
QTest::addColumn<bool>( "datachangesignal" );
QTest::addColumn<QString>( "expectedItemText" );
QTest::addColumn<int>( "expectedRenameCode" );
QTest::newRow("RenameableTarget")
<< (int)ProjectBaseItem::Target
<< QStringLiteral("target")
<< QStringLiteral("othertarget")
<< true
<< QStringLiteral("othertarget")
<< (int)ProjectBaseItem::RenameOk;
QTest::newRow("RenameableFile")
<< (int)ProjectBaseItem::File
<< QStringLiteral("newfile.cpp")
<< QStringLiteral("otherfile.cpp")
<< true
<< QStringLiteral("otherfile.cpp")
<< (int)ProjectBaseItem::RenameOk;
QTest::newRow("SourceAndDestinationFileEqual")
<< (int)ProjectBaseItem::File
<< QStringLiteral("newfile.cpp")
<< QStringLiteral("newfile.cpp")
<< false
<< QStringLiteral("newfile.cpp")
<< (int)ProjectBaseItem::RenameOk;
QTest::newRow("RenameableFolder")
<< (int)ProjectBaseItem::Folder
<< QStringLiteral("newfolder")
<< QStringLiteral("otherfolder")
<< true
<< QStringLiteral("otherfolder")
<< (int)ProjectBaseItem::RenameOk;
QTest::newRow("SourceAndDestinationFolderEqual")
<< (int)ProjectBaseItem::Folder
<< QStringLiteral("newfolder")
<< QStringLiteral("newfolder")
<< false
<< QStringLiteral("newfolder")
<< (int)ProjectBaseItem::RenameOk;
QTest::newRow("RenameableBuildFolder")
<< (int)ProjectBaseItem::BuildFolder
<< QStringLiteral("newbfolder")
<< QStringLiteral("otherbfolder")
<< true
<< QStringLiteral("otherbfolder")
<< (int)ProjectBaseItem::RenameOk;
QTest::newRow("SourceAndDestinationBuildFolderEqual")
<< (int)ProjectBaseItem::BuildFolder
<< QStringLiteral("newbfolder")
<< QStringLiteral("newbfolder")
<< false
<< QStringLiteral("newbfolder")
<< (int)ProjectBaseItem::RenameOk;
QTest::newRow("ExistingFileError")
<< (int)ProjectBaseItem::Folder
<< QStringLiteral("mynew")
<< QStringLiteral("existing")
<< false
<< QStringLiteral("mynew")
<< (int)ProjectBaseItem::ExistingItemSameName;
QTest::newRow("InvalidNameError")
<< (int)ProjectBaseItem::File
<< QStringLiteral("mynew")
<< QStringLiteral("other/bash")
<< false
<< QStringLiteral("mynew")
<< (int)ProjectBaseItem::InvalidNewName;
}
void TestProjectModel::testWithProject()
{
QString projectFolderPath = QDir::rootPath() + QStringLiteral("dummyprojectfolder");
QScopedPointer<TestProject> proj(new TestProject());
auto* rootItem = new ProjectFolderItem( proj.data(), Path(QUrl::fromLocalFile(projectFolderPath)), nullptr);
proj->setProjectItem( rootItem );
ProjectBaseItem* item = model->itemFromIndex( model->index( 0, 0 ) );
QCOMPARE( item, rootItem );
QCOMPARE( item->text(), proj->name() );
QCOMPARE( item->path(), proj->path() );
}
void TestProjectModel::testItemsForPath()
{
QFETCH(Path, path);
QFETCH(ProjectBaseItem*, root);
QFETCH(int, matches);
model->appendRow(root);
const auto items = model->itemsForPath(IndexedString(path.pathOrUrl()));
QCOMPARE(items.size(), matches);
for (ProjectBaseItem* item : items) {
QVERIFY(item->path() == path);
}
model->clear();
}
void TestProjectModel::testItemsForPath_data()
{
QTest::addColumn<Path>("path");
QTest::addColumn<ProjectBaseItem*>("root");
QTest::addColumn<int>("matches");
{
auto* root = new ProjectFolderItem(nullptr, Path(QUrl::fromLocalFile(QDir::tempPath())));
auto* file = new ProjectFileItem(QStringLiteral("a"), root);
QTest::newRow("find one") << file->path() << static_cast<ProjectBaseItem*>(root) << 1;
}
{
auto* root = new ProjectFolderItem(nullptr, Path(QUrl::fromLocalFile(QDir::tempPath())));
auto* folder = new ProjectFolderItem(QStringLiteral("a"), root);
auto* file = new ProjectFileItem(QStringLiteral("foo"), folder);
auto* target = new ProjectTargetItem(nullptr, QStringLiteral("b"), root);
auto* file2 = new ProjectFileItem(nullptr, file->path(), target);
Q_UNUSED(file2);
QTest::newRow("find two") << file->path() << static_cast<ProjectBaseItem*>(root) << 2;
}
}
void TestProjectModel::testProjectProxyModel()
{
auto* root = new ProjectFolderItem(nullptr, Path(QUrl::fromLocalFile(QDir::tempPath())));
new ProjectFileItem(QStringLiteral("b1"), root);
new ProjectFileItem(QStringLiteral("a1"), root);
new ProjectFileItem(QStringLiteral("d1"), root);
new ProjectFileItem(QStringLiteral("c1"), root);
model->appendRow(root);
QModelIndex proxyRoot = proxy->mapFromSource(root->index());
QCOMPARE(model->rowCount(root->index()), 4);
QCOMPARE(proxy->rowCount(proxyRoot), 4);
QCOMPARE(proxy->index(0, 0, proxy->index(0, 0)).data().toString(), QStringLiteral("a1"));
QCOMPARE(proxy->index(1, 0, proxy->index(0, 0)).data().toString(), QStringLiteral("b1"));
QCOMPARE(proxy->index(2, 0, proxy->index(0, 0)).data().toString(), QStringLiteral("c1"));
QCOMPARE(proxy->index(3, 0, proxy->index(0, 0)).data().toString(), QStringLiteral("d1"));
model->clear();
}
void TestProjectModel::testProjectFileSet()
{
QScopedPointer<TestProject> project(new TestProject());
QVERIFY(project->fileSet().isEmpty());
Path path(QUrl::fromLocalFile(QDir::tempPath() + "/a"));
auto* item = new ProjectFileItem(project.data(), path, project->projectItem());
QCOMPARE(project->fileSet().size(), 1);
qDebug() << path << project->fileSet().values().at(0).toUrl();
QCOMPARE(Path(project->fileSet().values().at(0).toUrl()), path);
delete item;
QVERIFY(project->fileSet().isEmpty());
}
void TestProjectModel::testProjectFileIcon()
{
QMimeDatabase db;
QScopedPointer<ProjectFileItem> 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)
|