summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2017-03-24 16:23:02 +0100
committerJan Holesovsky <kendy@collabora.com>2017-03-24 16:25:04 +0100
commit74acf925171dacdc4c0ad58a6d8edabb1e6c3144 (patch)
tree103478d114e74df3d21f7123cd0ce2e698e6085f /libreofficekit
parentc68a71026341b586e594048b42d18e2a94ad52d2 (diff)
lok: Unit test for setting of the language during load of the document.
Change-Id: Idf4d3ba6b55be1f885f9d8fc89157e7e498d4e42
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/qa/unit/tiledrendering.cxx89
1 files changed, 89 insertions, 0 deletions
diff --git a/libreofficekit/qa/unit/tiledrendering.cxx b/libreofficekit/qa/unit/tiledrendering.cxx
index f201f766ca7b..565eea040a93 100644
--- a/libreofficekit/qa/unit/tiledrendering.cxx
+++ b/libreofficekit/qa/unit/tiledrendering.cxx
@@ -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 )