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 19:01:53 +0100
commit221247679bcbc2507d6f904f519040fc4467d4a1 (patch)
tree71df17cce099a21572589e81c8c8ed5bda20efe2 /libreofficekit
parent5fefac660ae5d978843fd7abbc6db1fce0800566 (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/data/empty.odsbin0 -> 6845 bytes
-rw-r--r--libreofficekit/qa/unit/tiledrendering.cxx89
2 files changed, 89 insertions, 0 deletions
diff --git a/libreofficekit/qa/data/empty.ods b/libreofficekit/qa/data/empty.ods
new file mode 100644
index 000000000000..a36d1f97c405
--- /dev/null
+++ b/libreofficekit/qa/data/empty.ods
Binary files differ
diff --git a/libreofficekit/qa/unit/tiledrendering.cxx b/libreofficekit/qa/unit/tiledrendering.cxx
index 70d7a4ae814b..a4e84ee8d122 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 )