diff options
Diffstat (limited to 'tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp')
-rw-r--r-- | tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp | 168 |
1 files changed, 49 insertions, 119 deletions
diff --git a/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp b/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp index fddc98011..a1804e179 100644 --- a/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp +++ b/tests/auto/pdf/qpdfbookmarkmodel/tst_qpdfbookmarkmodel.cpp @@ -1,38 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <QtTest/QtTest> @@ -57,8 +24,8 @@ private slots: void setLoadedDocument(); void unloadDocument(); void testTreeStructure(); - void testListStructure(); void testPageNumberRole(); + void testLocationAndZoomRoles(); }; void tst_QPdfBookmarkModel::emptyModel() @@ -66,7 +33,6 @@ void tst_QPdfBookmarkModel::emptyModel() QPdfBookmarkModel model; QVERIFY(!model.document()); - QCOMPARE(model.structureMode(), QPdfBookmarkModel::TreeMode); QCOMPARE(model.rowCount(), 0); QCOMPARE(model.columnCount(), 1); QCOMPARE(model.index(0, 0).isValid(), false); @@ -80,7 +46,6 @@ void tst_QPdfBookmarkModel::setEmptyDocument() model.setDocument(&document); QCOMPARE(model.document(), &document); - QCOMPARE(model.structureMode(), QPdfBookmarkModel::TreeMode); QCOMPARE(model.rowCount(), 0); QCOMPARE(model.columnCount(), 1); QCOMPARE(model.index(0, 0).isValid(), false); @@ -96,10 +61,10 @@ void tst_QPdfBookmarkModel::setEmptyDocumentAndLoad() QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset())); QSignalSpy modelResetSpy(&model, SIGNAL(modelReset())); - QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::Error::None); - QCOMPARE(modelAboutToBeResetSpy.count(), 1); - QCOMPARE(modelResetSpy.count(), 1); + QCOMPARE(modelAboutToBeResetSpy.size(), 1); + QCOMPARE(modelResetSpy.size(), 1); QCOMPARE(model.rowCount(), 3); } @@ -107,7 +72,7 @@ void tst_QPdfBookmarkModel::setEmptyDocumentAndLoad() void tst_QPdfBookmarkModel::setLoadedDocument() { QPdfDocument document; - QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::Error::None); QPdfBookmarkModel model; @@ -116,8 +81,8 @@ void tst_QPdfBookmarkModel::setLoadedDocument() model.setDocument(&document); - QCOMPARE(modelAboutToBeResetSpy.count(), 1); - QCOMPARE(modelResetSpy.count(), 1); + QCOMPARE(modelAboutToBeResetSpy.size(), 1); + QCOMPARE(modelResetSpy.size(), 1); QCOMPARE(model.rowCount(), 3); } @@ -125,7 +90,7 @@ void tst_QPdfBookmarkModel::setLoadedDocument() void tst_QPdfBookmarkModel::unloadDocument() { QPdfDocument document; - QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::Error::None); QPdfBookmarkModel model; model.setDocument(&document); @@ -137,8 +102,8 @@ void tst_QPdfBookmarkModel::unloadDocument() document.close(); - QCOMPARE(modelAboutToBeResetSpy.count(), 1); - QCOMPARE(modelResetSpy.count(), 1); + QCOMPARE(modelAboutToBeResetSpy.size(), 1); + QCOMPARE(modelResetSpy.size(), 1); QCOMPARE(model.rowCount(), 0); } @@ -146,7 +111,7 @@ void tst_QPdfBookmarkModel::unloadDocument() void tst_QPdfBookmarkModel::testTreeStructure() { QPdfDocument document; - QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::Error::None); QPdfBookmarkModel model; model.setDocument(&document); @@ -154,115 +119,76 @@ void tst_QPdfBookmarkModel::testTreeStructure() QCOMPARE(model.rowCount(), 3); const QModelIndex index1 = model.index(0, 0); - QCOMPARE(index1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1")); - QCOMPARE(index1.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(index1.data(int(QPdfBookmarkModel::Role::Title)).toString(), QLatin1String("Section 1")); + QCOMPARE(index1.data(int(QPdfBookmarkModel::Role::Level)).toInt(), 0); QCOMPARE(model.rowCount(index1), 2); const QModelIndex index1_1 = model.index(0, 0, index1); - QCOMPARE(index1_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1.1")); - QCOMPARE(index1_1.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(index1_1.data(int(QPdfBookmarkModel::Role::Title)).toString(), QLatin1String("Section 1.1")); + QCOMPARE(index1_1.data(int(QPdfBookmarkModel::Role::Level)).toInt(), 1); QCOMPARE(model.rowCount(index1_1), 0); const QModelIndex index1_2 = model.index(1, 0, index1); - QCOMPARE(index1_2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1.2")); - QCOMPARE(index1_2.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(index1_2.data(int(QPdfBookmarkModel::Role::Title)).toString(), QLatin1String("Section 1.2")); + QCOMPARE(index1_2.data(int(QPdfBookmarkModel::Role::Level)).toInt(), 1); QCOMPARE(model.rowCount(index1_2), 0); const QModelIndex index2 = model.index(1, 0); - QCOMPARE(index2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2")); - QCOMPARE(index2.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(index2.data(int(QPdfBookmarkModel::Role::Title)).toString(), QLatin1String("Section 2")); + QCOMPARE(index2.data(int(QPdfBookmarkModel::Role::Level)).toInt(), 0); QCOMPARE(model.rowCount(index2), 2); const QModelIndex index2_1 = model.index(0, 0, index2); - QCOMPARE(index2_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.1")); - QCOMPARE(index2_1.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(index2_1.data(int(QPdfBookmarkModel::Role::Title)).toString(), QLatin1String("Section 2.1")); + QCOMPARE(index2_1.data(int(QPdfBookmarkModel::Role::Level)).toInt(), 1); QCOMPARE(model.rowCount(index2_1), 1); const QModelIndex index2_1_1 = model.index(0, 0, index2_1); - QCOMPARE(index2_1_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.1.1")); - QCOMPARE(index2_1_1.data(QPdfBookmarkModel::LevelRole).toInt(), 2); + QCOMPARE(index2_1_1.data(int(QPdfBookmarkModel::Role::Title)).toString(), QLatin1String("Section 2.1.1")); + QCOMPARE(index2_1_1.data(int(QPdfBookmarkModel::Role::Level)).toInt(), 2); QCOMPARE(model.rowCount(index2_1_1), 0); const QModelIndex index2_2 = model.index(1, 0, index2); - QCOMPARE(index2_2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.2")); - QCOMPARE(index2_2.data(QPdfBookmarkModel::LevelRole).toInt(), 1); + QCOMPARE(index2_2.data(int(QPdfBookmarkModel::Role::Title)).toString(), QLatin1String("Section 2.2")); + QCOMPARE(index2_2.data(int(QPdfBookmarkModel::Role::Level)).toInt(), 1); QCOMPARE(model.rowCount(index2_2), 0); const QModelIndex index3 = model.index(2, 0); - QCOMPARE(index3.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 3")); - QCOMPARE(index3.data(QPdfBookmarkModel::LevelRole).toInt(), 0); + QCOMPARE(index3.data(int(QPdfBookmarkModel::Role::Title)).toString(), QLatin1String("Section 3")); + QCOMPARE(index3.data(int(QPdfBookmarkModel::Role::Level)).toInt(), 0); QCOMPARE(model.rowCount(index3), 0); const QModelIndex index4 = model.index(3, 0); QCOMPARE(index4, QModelIndex()); } -void tst_QPdfBookmarkModel::testListStructure() +void tst_QPdfBookmarkModel::testPageNumberRole() { QPdfDocument document; - QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks.pdf")), QPdfDocument::NoError); + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks_pages.pdf")), QPdfDocument::Error::None); QPdfBookmarkModel model; model.setDocument(&document); - QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset())); - QSignalSpy modelResetSpy(&model, SIGNAL(modelReset())); - - model.setStructureMode(QPdfBookmarkModel::ListMode); - - QCOMPARE(modelAboutToBeResetSpy.count(), 1); - QCOMPARE(modelResetSpy.count(), 1); - - QCOMPARE(model.rowCount(), 8); + QCOMPARE(model.rowCount(), 3); const QModelIndex index1 = model.index(0, 0); - QCOMPARE(index1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1")); - QCOMPARE(index1.data(QPdfBookmarkModel::LevelRole).toInt(), 0); - QCOMPARE(model.rowCount(index1), 0); - - const QModelIndex index1_1 = model.index(1, 0); - QCOMPARE(index1_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1.1")); - QCOMPARE(index1_1.data(QPdfBookmarkModel::LevelRole).toInt(), 1); - QCOMPARE(model.rowCount(index1_1), 0); - - const QModelIndex index1_2 = model.index(2, 0); - QCOMPARE(index1_2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 1.2")); - QCOMPARE(index1_2.data(QPdfBookmarkModel::LevelRole).toInt(), 1); - QCOMPARE(model.rowCount(index1_2), 0); + QCOMPARE(index1.data(int(QPdfBookmarkModel::Role::Page)).toInt(), 0); - const QModelIndex index2 = model.index(3, 0); - QCOMPARE(index2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2")); - QCOMPARE(index2.data(QPdfBookmarkModel::LevelRole).toInt(), 0); - QCOMPARE(model.rowCount(index2), 0); - - const QModelIndex index2_1 = model.index(4, 0); - QCOMPARE(index2_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.1")); - QCOMPARE(index2_1.data(QPdfBookmarkModel::LevelRole).toInt(), 1); - QCOMPARE(model.rowCount(index2_1), 0); - - const QModelIndex index2_1_1 = model.index(5, 0); - QCOMPARE(index2_1_1.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.1.1")); - QCOMPARE(index2_1_1.data(QPdfBookmarkModel::LevelRole).toInt(), 2); - QCOMPARE(model.rowCount(index2_1_1), 0); - - const QModelIndex index2_2 = model.index(6, 0); - QCOMPARE(index2_2.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 2.2")); - QCOMPARE(index2_2.data(QPdfBookmarkModel::LevelRole).toInt(), 1); - QCOMPARE(model.rowCount(index2_2), 0); + const QModelIndex index2 = model.index(1, 0); + QCOMPARE(index2.data(int(QPdfBookmarkModel::Role::Page)).toInt(), 1); - const QModelIndex index3 = model.index(7, 0); - QCOMPARE(index3.data(QPdfBookmarkModel::TitleRole).toString(), QLatin1String("Section 3")); - QCOMPARE(index3.data(QPdfBookmarkModel::LevelRole).toInt(), 0); - QCOMPARE(model.rowCount(index3), 0); + const QModelIndex index2_1 = model.index(0, 0, index2); + QCOMPARE(index2_1.data(int(QPdfBookmarkModel::Role::Page)).toInt(), 1); - const QModelIndex index4 = model.index(8, 0); - QCOMPARE(index4, QModelIndex()); + const QModelIndex index3 = model.index(2, 0); + QCOMPARE(index3.data(int(QPdfBookmarkModel::Role::Page)).toInt(), 2); } -void tst_QPdfBookmarkModel::testPageNumberRole() +void tst_QPdfBookmarkModel::testLocationAndZoomRoles() { QPdfDocument document; - QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks_pages.pdf")), QPdfDocument::NoError); + QCOMPARE(document.load(QFINDTESTDATA("pdf-sample.bookmarks_pages.pdf")), QPdfDocument::Error::None); QPdfBookmarkModel model; model.setDocument(&document); @@ -270,16 +196,20 @@ void tst_QPdfBookmarkModel::testPageNumberRole() QCOMPARE(model.rowCount(), 3); const QModelIndex index1 = model.index(0, 0); - QCOMPARE(index1.data(QPdfBookmarkModel::PageNumberRole).toInt(), 0); + QCOMPARE(index1.data(int(QPdfBookmarkModel::Role::Location)).toPoint(), QPoint(57, 69)); + QCOMPARE(index1.data(int(QPdfBookmarkModel::Role::Zoom)).toInt(), 0); const QModelIndex index2 = model.index(1, 0); - QCOMPARE(index2.data(QPdfBookmarkModel::PageNumberRole).toInt(), 1); + QCOMPARE(index2.data(int(QPdfBookmarkModel::Role::Location)).toPoint(), QPoint(57, 57)); + QCOMPARE(index2.data(int(QPdfBookmarkModel::Role::Zoom)).toInt(), 0); const QModelIndex index2_1 = model.index(0, 0, index2); - QCOMPARE(index2_1.data(QPdfBookmarkModel::PageNumberRole).toInt(), 1); + QCOMPARE(index2_1.data(int(QPdfBookmarkModel::Role::Location)).toPoint(), QPoint(57, 526)); + QCOMPARE(index2_1.data(int(QPdfBookmarkModel::Role::Zoom)).toInt(), 0); const QModelIndex index3 = model.index(2, 0); - QCOMPARE(index3.data(QPdfBookmarkModel::PageNumberRole).toInt(), 2); + QCOMPARE(index3.data(int(QPdfBookmarkModel::Role::Location)).toPoint(), QPoint(57, 402)); + QCOMPARE(index3.data(int(QPdfBookmarkModel::Role::Zoom)).toInt(), 0); } QTEST_MAIN(tst_QPdfBookmarkModel) |