File indexing completed on 2022-10-04 14:00:17

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0004 //
0005 
0006 #include <QTest>
0007 
0008 #include "GeoDataTreeModel.h"
0009 
0010 #include "GeoDataDocument.h"
0011 #include "GeoDataPlacemark.h"
0012 
0013 namespace Marble
0014 {
0015 
0016 class GeoDataTreeModelTest : public QObject
0017 {
0018     Q_OBJECT
0019 
0020 private Q_SLOTS:
0021     void defaultConstructor();
0022     void setRootDocument();
0023     void addDocument();
0024 };
0025 
0026 void GeoDataTreeModelTest::defaultConstructor()
0027 {
0028     const GeoDataTreeModel model;
0029 
0030     QCOMPARE( model.rowCount(), 0 );
0031     QCOMPARE( model.columnCount(), 4 );
0032 
0033     QCOMPARE( model.headerData( 0, Qt::Horizontal, Qt::DisplayRole ), QVariant( tr( "Name" ) ) );
0034     QCOMPARE( model.headerData( 1, Qt::Horizontal, Qt::DisplayRole ), QVariant( tr( "Type" ) ) );
0035     QCOMPARE( model.headerData( 2, Qt::Horizontal, Qt::DisplayRole ), QVariant( tr( "Popularity" ) ) );
0036     QCOMPARE( model.headerData( 3, Qt::Horizontal, Qt::DisplayRole ), QVariant( tr( "PopIndex", "Popularity index" ) ) );
0037 
0038     QCOMPARE( model.index( 0, 0 ), QModelIndex() );
0039     QCOMPARE( model.index( nullptr ), QModelIndex() );
0040     QCOMPARE( model.parent( QModelIndex() ), QModelIndex() );
0041     QCOMPARE( model.data( QModelIndex(), Qt::DisplayRole ), QVariant() );
0042     QCOMPARE( model.flags( QModelIndex() ), Qt::NoItemFlags );
0043 
0044     QVERIFY( const_cast<GeoDataTreeModel *>( &model )->rootDocument() != nullptr );
0045 }
0046 
0047 void GeoDataTreeModelTest::setRootDocument()
0048 {
0049     GeoDataDocument document;
0050 
0051     {
0052         GeoDataTreeModel model;
0053 
0054         model.setRootDocument( &document );
0055         // ~GeoDataTreeModel() shouldn't delete document
0056     }
0057 }
0058 
0059 void GeoDataTreeModelTest::addDocument()
0060 {
0061     {
0062         GeoDataDocument *document = new GeoDataDocument;
0063 
0064         GeoDataTreeModel model;
0065 
0066         model.addDocument( document );
0067         QCOMPARE( model.rowCount(), 1 );
0068     }
0069 }
0070 
0071 }
0072 
0073 QTEST_MAIN( Marble::GeoDataTreeModelTest )
0074 
0075 #include "GeoDataTreeModelTest.moc"