Kaydet (Commit) 22124767 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

lok: Unit test for setting of the language during load of the document.

Change-Id: Idf4d3ba6b55be1f885f9d8fc89157e7e498d4e42
üst 5fefac66
......@@ -73,6 +73,7 @@ public:
void testImpressSlideNames( Office* pOffice );
void testCalcSheetNames( Office* pOffice );
void testPaintPartTile( Office* pOffice );
void testDocumentLoadLanguage(Office* pOffice);
#if 0
void testOverlay( Office* pOffice );
#endif
......@@ -100,6 +101,7 @@ void TiledRenderingTest::runAllTests()
testImpressSlideNames( pOffice.get() );
testCalcSheetNames( pOffice.get() );
testPaintPartTile( pOffice.get() );
testDocumentLoadLanguage(pOffice.get());
#if 0
testOverlay( pOffice.get() );
#endif
......@@ -218,6 +220,93 @@ void TiledRenderingTest::testPaintPartTile(Office* pOffice)
pDocument->paintPartTile(aBuffer.data(), /*nPart=*/0, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/0, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
}
namespace {
void processEventsToIdle()
{
typedef void (ProcessEventsToIdleFn)(void);
static ProcessEventsToIdleFn *processFn = nullptr;
if (!processFn)
{
void *me = dlopen(nullptr, RTLD_NOW);
processFn = reinterpret_cast<ProcessEventsToIdleFn *>(dlsym(me, "unit_lok_process_events_to_idle"));
}
CPPUNIT_ASSERT(processFn);
(*processFn)();
}
void insertString(Document& rDocument, const std::string& s)
{
for (const char c : s)
{
rDocument.postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0);
rDocument.postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0);
}
processEventsToIdle();
}
}
void TiledRenderingTest::testDocumentLoadLanguage(Office* pOffice)
{
const string sDocPath = m_sSrcRoot + "/libreofficekit/qa/data/empty.ods";
const string sLockFile = m_sSrcRoot +"/libreofficekit/qa/data/.~lock.empty.ods#";
// FIXME: LOK will fail when trying to open a locked file
remove(sLockFile.c_str());
// first try with the en-US locale
std::unique_ptr<Document> pDocument(pOffice->documentLoad(sDocPath.c_str(), "Language=en-US"));
// assert that '.' is the decimal separator
insertString(*pDocument, "1.5");
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1027); // right arrow
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1027);
processEventsToIdle();
insertString(*pDocument, "=2*A1");
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1280); // enter
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1280);
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1025); // up arrow
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1025);
processEventsToIdle();
// we've got a meaningful result
OString aResult = pDocument->getTextSelection("text/plain;charset=utf-8");
CPPUNIT_ASSERT_EQUAL(OString("3\n"), aResult);
pDocument.reset(nullptr);
// FIXME: LOK will fail when trying to open a locked file
remove(sLockFile.c_str());
// load the file again, now in another language
pDocument.reset(pOffice->documentLoad(sDocPath.c_str(), "Language=cs-CZ"));
// with cs-CZ, the decimal separator is ',' instead, assert that
insertString(*pDocument, "1,5");
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1027); // right arrow
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1027);
processEventsToIdle();
insertString(*pDocument, "=2*A1");
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1280); // enter
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1280);
pDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 1025); // up arrow
pDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, 1025);
processEventsToIdle();
// we've got a meaningful result
aResult = pDocument->getTextSelection("text/plain;charset=utf-8");
CPPUNIT_ASSERT_EQUAL(OString("3\n"), aResult);
}
#if 0
static void dumpRGBABitmap( const OUString& rPath, const unsigned char* pBuffer,
const int nWidth, const int nHeight )
......
......@@ -544,6 +544,15 @@ void Scheduler::ProcessEventsToIdle()
}
}
extern "C" {
/// used by unit tests that test only via the LOK API
SAL_DLLPUBLIC_EXPORT void unit_lok_process_events_to_idle()
{
const SolarMutexGuard aGuard;
Scheduler::ProcessEventsToIdle();
}
}
void Application::Yield()
{
ImplYield(true, false, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment