File: PagesTreeTest.h

package info (click to toggle)
libpodofo 0.9.6%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,228 kB
  • sloc: cpp: 61,697; ansic: 347; sh: 96; makefile: 15
file content (166 lines) | stat: -rw-r--r-- 5,937 bytes parent folder | download | duplicates (5)
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
/***************************************************************************
 *   Copyright (C) 2008 by Dominik Seichter                                *
 *   domseichter@web.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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef _PAGES_TREE_TEST_H_
#define _PAGES_TREE_TEST_H_

#include <vector>

#include <cppunit/extensions/HelperMacros.h>

namespace PoDoFo {
class PdfMemDocument;
class PdfPage;
class PdfObject;
};

/** This test tests the class PdfPagesTree
 */
class PagesTreeTest : public CppUnit::TestFixture
{
  CPPUNIT_TEST_SUITE( PagesTreeTest );
  CPPUNIT_TEST( testEmptyTree );
  CPPUNIT_TEST( testEmptyDoc );
  CPPUNIT_TEST( testCyclicTree );
  CPPUNIT_TEST( testEmptyKidsTree );
  CPPUNIT_TEST( testNestedArrayTree );
  CPPUNIT_TEST( testCreateDelete );
  CPPUNIT_TEST( testGetPagesCustom );
  CPPUNIT_TEST( testGetPagesPoDoFo );
  CPPUNIT_TEST( testGetPagesReverseCustom );
  CPPUNIT_TEST( testGetPagesReversePoDoFo );
  CPPUNIT_TEST( testInsertCustom );
  CPPUNIT_TEST( testInsertPoDoFo );
  CPPUNIT_TEST( testDeleteAllCustom );
  CPPUNIT_TEST( testDeleteAllPoDoFo );
  CPPUNIT_TEST_SUITE_END();

 public:
  void setUp();
  void tearDown();

  void testEmptyTree();
  void testEmptyDoc();
  void testCyclicTree();
  void testEmptyKidsTree();
  void testNestedArrayTree();
  void testCreateDelete();
  void testGetPagesCustom();
  void testGetPagesPoDoFo();
  void testGetPagesReverseCustom();
  void testGetPagesReversePoDoFo();
  void testInsertCustom();
  void testInsertPoDoFo();
  void testDeleteAllCustom();
  void testDeleteAllPoDoFo();
    
 private:
  void testGetPages( PoDoFo::PdfMemDocument & doc );
  void testGetPagesReverse( PoDoFo::PdfMemDocument & doc );
  void testInsert( PoDoFo::PdfMemDocument & doc );
  void testDeleteAll( PoDoFo::PdfMemDocument & doc );

  /**
   * Create a pages tree with 100 pages,
   * where every page object has an additional
   * key PoDoFoTestPageNumber with the original 
   * page number of the page.
   *
   * This method uses PoDoFo's build in PdfPagesTree
   * which creates a flat tree.
   *
   * You can check the page number ussing IsPageNumber()
   *
   * @see IsPageNumber
   */
  void CreateTestTreePoDoFo( PoDoFo::PdfMemDocument & rDoc );

  /**
   * Create a pages tree with 100 pages,
   * where every page object has an additional
   * key PoDoFoTestPageNumber with the original 
   * page number of the page.
   *
   * This builds a pages tree manually an makes
   * sure a real tree structure is build.
   *
   * You can check the page number ussing IsPageNumber()
   *
   * @see IsPageNumber
   */
  void CreateTestTreeCustom( PoDoFo::PdfMemDocument & rDoc );

  /**
   * Create a pages tree with cycles to test prevention of endless
   * recursion as mentioned in different CVE reports.
   *
   * \param bCreateCycle if true a cyclic tree is created, otherwise a
   *                     valid tree without cycles
   */
  void CreateCyclicTree( PoDoFo::PdfMemDocument & rDoc,
                         bool bCreateCycle );

  /**
   * Create a pages tree with nodes containing empty kids.
   *
   * This is completely valid according to the PDF spec, i.e. the
   * required keys may have the values "/Kids [ ]" and "/Count 0"
   * Such a tree must still be parsable by a conforming reader:
   *
   * <BLOCKQUOTE>The tree contains nodes of two types—intermediate
   * nodes, called page tree nodes, and leaf nodes, called page
   * objects—whose form is described in the subsequent subclauses.
   * Conforming products shall be prepared to handle any form
   * of tree structure built of such nodes.</BLOCKQUOTE>
   */
  void CreateEmptyKidsTree( PoDoFo::PdfMemDocument & rDoc );
  
  /**
  * Ceate a pages tree with a nested kids array.
  *
  * Such a tree is not valid to the PDF spec, which requires they key
  * "Kids" to be an array of indirect references. And the children shall
  * only be page objects or other page tree nodes.
  */
  void CreateNestedArrayTree( PoDoFo::PdfMemDocument & rDoc );

 /**
  * Create page object nodes (leaf nodes),
  * where every page object has an additional
  * key PoDoFoTestPageNumber with the original 
  * page number of the page.
  */  
  std::vector<PoDoFo::PdfPage*> CreateSamplePages( PoDoFo::PdfMemDocument & rDoc,
                                                   int nPageCount);

  /**
  * Create page tree nodes (internal nodes)
  */
  std::vector<PoDoFo::PdfObject*> CreateNodes( PoDoFo::PdfMemDocument & rDoc,
                                               int nNodeCount);

  bool IsPageNumber( PoDoFo::PdfPage* pPage, int nNumber );

  void AppendChildNode(PoDoFo::PdfObject* pParent, PoDoFo::PdfObject* pChild);
};

#endif // _PAGES_TREE_TEST_H_