| 1 | // ePDFView - Document Outline Test Fixture. |
|---|
| 2 | // Copyright (C) 2006 Emma's Software. |
|---|
| 3 | // |
|---|
| 4 | // This program is free software; you can redistribute it and/or modify |
|---|
| 5 | // it under the terms of the GNU General Public License as published by |
|---|
| 6 | // the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | // (at your option) any later version. |
|---|
| 8 | // |
|---|
| 9 | // This program is distributed in the hope that it will be useful, |
|---|
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | // GNU General Public License for more details. |
|---|
| 13 | // |
|---|
| 14 | // You should have received a copy of the GNU General Public License |
|---|
| 15 | // along with this program; if not, write to the Free Software |
|---|
| 16 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 | |
|---|
| 18 | #include <epdfview.h> |
|---|
| 19 | #include "Utils.h" |
|---|
| 20 | #include "DocumentOutlineTest.h" |
|---|
| 21 | |
|---|
| 22 | using namespace ePDFView; |
|---|
| 23 | |
|---|
| 24 | // Register the test suite into the `registry'. |
|---|
| 25 | CPPUNIT_TEST_SUITE_REGISTRATION (DocumentOutlineTest); |
|---|
| 26 | |
|---|
| 27 | /// |
|---|
| 28 | /// @brief Sets up the environment for each test. |
|---|
| 29 | /// |
|---|
| 30 | void |
|---|
| 31 | DocumentOutlineTest::setUp () |
|---|
| 32 | { |
|---|
| 33 | m_Document = new PDFDocument (); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | /// |
|---|
| 37 | /// @brief Cleans up after each test. |
|---|
| 38 | /// |
|---|
| 39 | void |
|---|
| 40 | DocumentOutlineTest::tearDown () |
|---|
| 41 | { |
|---|
| 42 | delete m_Document; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | /// |
|---|
| 46 | /// @brief Check the initial document's outline. |
|---|
| 47 | /// |
|---|
| 48 | /// Initially, the document doesn't had outline as it hasn't been loaded. |
|---|
| 49 | /// |
|---|
| 50 | void |
|---|
| 51 | DocumentOutlineTest::initialStatus () |
|---|
| 52 | { |
|---|
| 53 | CPPUNIT_ASSERT ( !m_Document->isLoaded ()); |
|---|
| 54 | CPPUNIT_ASSERT ( NULL == m_Document->getOutline ()); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /// |
|---|
| 58 | /// @brief Test a file without outline. |
|---|
| 59 | /// |
|---|
| 60 | /// When a loaded document doesn't have an outline, the DocumentOutline's |
|---|
| 61 | /// is empty. |
|---|
| 62 | /// |
|---|
| 63 | void |
|---|
| 64 | DocumentOutlineTest::noOutline () |
|---|
| 65 | { |
|---|
| 66 | gchar *testFile = getTestFile ("test2.pdf"); |
|---|
| 67 | CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); |
|---|
| 68 | CPPUNIT_ASSERT (m_Document->isLoaded ()); |
|---|
| 69 | DocumentOutline *outline = m_Document->getOutline (); |
|---|
| 70 | CPPUNIT_ASSERT ( NULL != outline ); |
|---|
| 71 | CPPUNIT_ASSERT_EQUAL (0, outline->getNumChildren ()); |
|---|
| 72 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("", outline->getTitle ())); |
|---|
| 73 | CPPUNIT_ASSERT_EQUAL (1, outline->getDestinationPage ()); |
|---|
| 74 | CPPUNIT_ASSERT (NULL == outline->getFirstChild ()); |
|---|
| 75 | CPPUNIT_ASSERT (NULL == outline->getNextChild ()); |
|---|
| 76 | |
|---|
| 77 | g_free (testFile); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | /// |
|---|
| 81 | /// @brief Test a file that has outline. |
|---|
| 82 | /// |
|---|
| 83 | /// The document I've gone test has the following outline: |
|---|
| 84 | /// |
|---|
| 85 | /// * |
|---|
| 86 | /// | |
|---|
| 87 | /// +- Test PDF 1 / page 3 |
|---|
| 88 | /// | |
|---|
| 89 | /// +- Table of Contents / page 4 |
|---|
| 90 | /// | |
|---|
| 91 | /// +- Chapter 1. First Chapter / page 5 |
|---|
| 92 | /// | |
|---|
| 93 | /// + First Section / page 5 |
|---|
| 94 | /// |
|---|
| 95 | void |
|---|
| 96 | DocumentOutlineTest::hasOutline () |
|---|
| 97 | { |
|---|
| 98 | gchar *testFile = getTestFile ("test1.pdf"); |
|---|
| 99 | CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); |
|---|
| 100 | CPPUNIT_ASSERT (m_Document->isLoaded ()); |
|---|
| 101 | DocumentOutline *outline = m_Document->getOutline (); |
|---|
| 102 | CPPUNIT_ASSERT ( NULL != outline ); |
|---|
| 103 | // The root outline must be the same empty one, except it has children. |
|---|
| 104 | CPPUNIT_ASSERT_EQUAL (3, outline->getNumChildren ()); |
|---|
| 105 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("", outline->getTitle ())); |
|---|
| 106 | CPPUNIT_ASSERT_EQUAL (1, outline->getDestinationPage ()); |
|---|
| 107 | |
|---|
| 108 | { |
|---|
| 109 | DocumentOutline *child = outline->getFirstChild(); |
|---|
| 110 | CPPUNIT_ASSERT ( NULL != child ); |
|---|
| 111 | CPPUNIT_ASSERT_EQUAL (0, child->getNumChildren ()); |
|---|
| 112 | CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("Test PDF 1", |
|---|
| 113 | child->getTitle ())); |
|---|
| 114 | CPPUNIT_ASSERT_EQUAL (3, child->getDestinationPage ()); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | { |
|---|
| 118 | DocumentOutline *child = outline->getNextChild(); |
|---|
| 119 | CPPUNIT_ASSERT ( NULL != child ); |
|---|
| 120 | CPPUNIT_ASSERT_EQUAL (0, child->getNumChildren ()); |
|---|
| 121 | CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("Table of Contents", |
|---|
| 122 | child->getTitle ())); |
|---|
| 123 | CPPUNIT_ASSERT_EQUAL (4, child->getDestinationPage ()); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | { |
|---|
| 127 | DocumentOutline *child = outline->getNextChild(); |
|---|
| 128 | CPPUNIT_ASSERT ( NULL != child ); |
|---|
| 129 | CPPUNIT_ASSERT_EQUAL (1, child->getNumChildren ()); |
|---|
| 130 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 131 | g_ascii_strcasecmp ("Chapter 1. First Chapter", |
|---|
| 132 | child->getTitle ())); |
|---|
| 133 | CPPUNIT_ASSERT_EQUAL (5, child->getDestinationPage ()); |
|---|
| 134 | |
|---|
| 135 | DocumentOutline *greatChild = child->getFirstChild (); |
|---|
| 136 | CPPUNIT_ASSERT ( NULL != greatChild ); |
|---|
| 137 | CPPUNIT_ASSERT_EQUAL (0, greatChild->getNumChildren ()); |
|---|
| 138 | CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("First Section", |
|---|
| 139 | greatChild->getTitle ())); |
|---|
| 140 | CPPUNIT_ASSERT_EQUAL (5, greatChild->getDestinationPage ()); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | // After the last child, it should return NULL. |
|---|
| 144 | CPPUNIT_ASSERT (NULL == outline->getNextChild ()); |
|---|
| 145 | |
|---|
| 146 | // Try again the "no outlined" file. |
|---|
| 147 | noOutline (); |
|---|
| 148 | |
|---|
| 149 | g_free (testFile); |
|---|
| 150 | } |
|---|