/* -*- 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/.
*/
// We specifically don't use the usual BootStrapFixture, as LOK does // all its own setup and bootstrapping, and should be usable in a // raw C++ program. class TiledRenderingTest : public ::CppUnit::TestFixture
{ public: const string m_sSrcRoot; const string m_sInstDir; const string m_sLOPath;
// Currently it isn't possible to do multiple startup/shutdown // cycle of LOK in a single process -- hence we run all our tests // as one test, which simply carries out the individual test // components on the one Office instance that we retrieve. void runAllTests();
void TiledRenderingTest::testDocumentLoadFail( Office* pOffice )
{ const string sDocPath = m_sSrcRoot + "/libreofficekit/qa/data/IDONOTEXIST.odt";
std::unique_ptr< Document> pDocument( pOffice->documentLoad( sDocPath.c_str() ) );
CPPUNIT_ASSERT( !pDocument ); // TODO: we probably want to have some way of returning what // the cause of failure was. getError() will return // something along the lines of: // "Unsupported URL <file:///SRC_ROOT/libreofficekit/qa/data/IDONOTEXIST.odt>: "type detection failed""
}
// Our dumped .png files end up in // workdir/CppunitTest/libreofficekit_tiledrendering.test.core
CPPUNIT_ASSERT_EQUAL(3, pDocument->getParts());
CPPUNIT_ASSERT_EQUAL(std::string("TestText1"), std::string(pDocument->getPartName(0)));
CPPUNIT_ASSERT_EQUAL(std::string("TestText2"), std::string(pDocument->getPartName(1))); // The third slide hasn't had a name given to it (i.e. using the rename // context menu in Impress), thus it should (as far as I can determine) // have a localised version of "Slide 3".
}
// Create two views.
pDocument->getView();
pDocument->createView();
int nView2 = pDocument->getView();
// Destroy the current view
pDocument->destroyView(nView2);
int nCanvasWidth = 256; int nCanvasHeight = 256;
std::vector<unsignedchar> aBuffer(nCanvasWidth * nCanvasHeight * 4);
// And try to paintPartTile() - this used to crash when the current viewId // was destroyed
pDocument->paintPartTile(aBuffer.data(), /*nPart=*/0, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/0, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
}
// FIXME: this is a temporary hack: LOK will fail when trying to open a // locked file, and since we're reusing the file for a different unit // test it's entirely possible that an unwanted lock file will remain. // Hence forcefully remove it here.
remove( sLockFile.c_str() );
std::unique_ptr< Office > pOffice( lok_cpp_init(
m_sLOPath.c_str() ) );
assert( pOffice.get() );
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. constint nTotalWidthPix = 512; constint 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;
// 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 < 2; x++ )
{ for ( int y = 0; y < 2; 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] );
}
}
}
} #endif
// Create two views. int nViewA = pDocument->getView();
pDocument->initializeForRendering("{\".uno:Author\":{\"type\":\"string\",\"value\":\"jill\"}}");
pDocument->createView(); int nViewB = pDocument->getView();
pDocument->initializeForRendering("{\".uno:Author\":{\"type\":\"string\",\"value\":\"jack\"}}");
// First a key-stroke from a
pDocument->setView(nViewA);
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 97, 0); // a
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 512); // 'a
// A space on 'a' - force commit
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 32, 0); // ' '
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1284); // '' '
// Another 'a'
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 97, 0); // a
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 512); // 'a
// FIXME: Wait for writer input handler to commit that. // without this we fall foul of edtwin's KeyInputFlushTimer
std::this_thread::sleep_for(std::chrono::milliseconds(300));
// Quickly a new key-stroke from b
pDocument->setView(nViewB);
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 98, 0); // b
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 514); // 'b
// A space on 'b' - force commit
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 32, 0); // ' '
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1284); // '' '
// Wait for writer input handler to commit that.
std::this_thread::sleep_for(std::chrono::milliseconds(300));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.