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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
#include <cppunit/TestFixture.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cstdlib>
#include <string>
#include <sal/types.h>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKit.hxx>
using namespace ::boost;
using namespace ::lok;
using namespace ::std;
// We specifically don't use the usual BootStrapFixture, as LOK does
// all it's own setup and bootstrapping, and should be useable in a
// raw C++ program.
class TiledRenderingTest : public ::CppUnit::TestFixture
{
public:
TiledRenderingTest() {}
void testOverlay();
CPPUNIT_TEST_SUITE(TiledRenderingTest);
CPPUNIT_TEST(testOverlay);
CPPUNIT_TEST_SUITE_END();
};
void TiledRenderingTest::testOverlay()
{
const string sSrcRoot = getenv( "SRC_ROOT" );
const string sLOPath = sSrcRoot + "/instdir/program";
const string sDocPath = sSrcRoot + "/odk/examples/java/DocumentHandling/test/test1.odt";
scoped_ptr< Office > pOffice( lok_cpp_init(
sLOPath.c_str() ) );
assert( pOffice.get() );
scoped_ptr< Document> pDocument( pOffice->documentLoad(
sDocPath.c_str() ) );
if ( !pDocument.get() )
{
fprintf( stderr, "documentLoad failed: %s\n", pOffice->getError() );
CPPUNIT_FAIL( "Document could not be loaded -- tiled rendering not possible." );
}
// We render one large tile, then subdivide it into 4 and render those parts, and finally
// iterate over each smaller tile and check whether their contents match the large
// tile.
const int nTotalWidthPix = 512;
const int nTotalHeightPix = 512;
int nRowStride;
long nTotalWidthDoc;
long nTotalHeightDoc;
// pDocument->getDocumentSize( &nTotalWidthDoc, &nTotalHeightDoc );
// TODO: make sure we select an actually interesting part of the document
// for this comparison, i.e. ideally an image and lots of text, in order
// to test as many edge cases as possible.
// Alternatively we could rewrite this to actually grab the document size
// and iterate over it (subdividing into an arbitrary number of tiles rather
// than our less sophisticated test of just 4 sub-tiles).
nTotalWidthDoc = 8000;
nTotalHeightDoc = 9000;
scoped_array< unsigned char > pLarge( new unsigned char[ 4*nTotalWidthPix*nTotalHeightPix ] );
pDocument->paintTile( pLarge.get(), nTotalWidthPix, nTotalHeightPix, &nRowStride,
0, 0,
nTotalWidthDoc, nTotalHeightDoc );
scoped_array< unsigned char > pSmall[4];
for ( int i = 0; i < 4; i++ )
{
pSmall[i].reset( new unsigned char[ 4*(nTotalWidthPix/2)*(nTotalHeightPix/2) ] );
pDocument->paintTile( pSmall[i].get(), nTotalWidthPix / 2, nTotalHeightPix / 2, &nRowStride,
// Tile 0/2: left. Tile 1/3: right. Tile 0/1: top. Tile 2/3: bottom
((i%2 == 0) ? 0 : nTotalWidthDoc / 2), ((i < 2 ) ? 0 : nTotalHeightDoc / 2),
nTotalWidthDoc / 2, nTotalHeightDoc / 2);
}
// Iterate over each pixel of the sub-tile, and compare that pixel for every
// tile with the equivalent super-tile pixel.
for ( int i = 0; i < 4*nTotalWidthPix / 2 * nTotalHeightPix / 2; i++ )
{
int xSmall = i % (4*nTotalWidthPix/2);
int ySmall = i / (4*nTotalWidthPix/2);
// Iterate over our array of tiles
// However for now we only bother with the top-left
// tile as the other ones don't match yet...
for ( int x = 0; x < 1; x++ )
{
for ( int y = 0; y < 1; y++ )
{
int xLarge = (x * (4 * nTotalWidthPix / 2)) + xSmall;
int yLarge = (y * (nTotalHeightPix / 2)) + ySmall;
CPPUNIT_ASSERT( pSmall[2*y+x][i] == pLarge[yLarge*4*nTotalWidthPix + xLarge] );
}
}
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(TiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|