summaryrefslogtreecommitdiffstats
path: root/linguistic/qa
diff options
context:
space:
mode:
Diffstat (limited to 'linguistic/qa')
-rw-r--r--linguistic/qa/complex/linguistic/HangulHanjaConversion.java344
-rw-r--r--linguistic/qa/complex/linguistic/TestDocument.java32
-rw-r--r--linguistic/qa/complex/linguistic/testdocuments/hangulhanja.sxcbin0 -> 6366 bytes
-rw-r--r--linguistic/qa/restprotocol.cxx185
-rw-r--r--linguistic/qa/unoapi/knownissues.xcl27
-rw-r--r--linguistic/qa/unoapi/lng.sce3
6 files changed, 591 insertions, 0 deletions
diff --git a/linguistic/qa/complex/linguistic/HangulHanjaConversion.java b/linguistic/qa/complex/linguistic/HangulHanjaConversion.java
new file mode 100644
index 0000000000..b407c46426
--- /dev/null
+++ b/linguistic/qa/complex/linguistic/HangulHanjaConversion.java
@@ -0,0 +1,344 @@
+/*
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package complex.linguistic;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.container.ElementExistException;
+import com.sun.star.container.NoSuchElementException;
+import com.sun.star.container.XNameContainer;
+import com.sun.star.i18n.TextConversionOption;
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.linguistic2.ConversionDictionaryType;
+import com.sun.star.linguistic2.ConversionDirection;
+import com.sun.star.linguistic2.XConversionDictionary;
+import com.sun.star.linguistic2.XConversionDictionaryList;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.XCell;
+
+import com.sun.star.uno.UnoRuntime;
+
+
+
+import util.DesktopTools;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openoffice.test.OfficeConnection;
+import static org.junit.Assert.*;
+
+public class HangulHanjaConversion {
+ XMultiServiceFactory xMSF = null;
+ boolean disposed = false;
+ Locale aLocale = new Locale("ko", "KR", "");
+ short dictType = ConversionDictionaryType.HANGUL_HANJA;
+
+ @Before public void before() {
+ xMSF = getMSF();
+ }
+
+ @Test public void ConversionDictionaryList() {
+ Object ConversionDictionaryList = null;
+
+ try {
+ ConversionDictionaryList = xMSF.createInstance(
+ "com.sun.star.linguistic2.ConversionDictionaryList");
+ } catch (com.sun.star.uno.Exception e) {
+ fail("Couldn't create ConversionDictionaryList");
+ }
+
+ if (ConversionDictionaryList == null) {
+ fail("Couldn't create ConversionDictionaryList");
+ }
+
+ boolean bList = checkXConversionDictionaryList(
+ ConversionDictionaryList);
+ assertTrue("XConversionDictionaryList doesn't work as expected", bList);
+ }
+
+ private boolean checkXConversionDictionaryList(Object list) {
+ boolean res = true;
+ XConversionDictionaryList xCList = UnoRuntime.queryInterface(XConversionDictionaryList.class, list);
+ XConversionDictionary xDict = null;
+
+ try {
+ xDict = xCList.addNewDictionary("addNewDictionary", aLocale,
+ dictType);
+ } catch (com.sun.star.lang.NoSupportException e) {
+ res = false;
+ fail("Couldn't add Dictionary");
+ } catch (com.sun.star.container.ElementExistException e) {
+ res = false;
+ fail("Couldn't add Dictionary");
+ }
+
+ try {
+ xCList.addNewDictionary("addNewDictionary", aLocale, dictType);
+ res = false;
+ fail("wrong exception while adding Dictionary again");
+ } catch (com.sun.star.lang.NoSupportException e) {
+ res = false;
+ fail("wrong exception while adding Dictionary again");
+ } catch (com.sun.star.container.ElementExistException e) {
+ }
+
+ boolean localRes = checkNameContainer(xCList.getDictionaryContainer());
+ res &= localRes;
+ assertTrue("getDictionaryContainer didn't work as expected", localRes);
+
+ String FileToLoad = TestDocument.getUrl("hangulhanja.sxc");
+
+XComponent xDoc = DesktopTools.loadDoc(xMSF, FileToLoad,
+ new PropertyValue[] { });
+ XSpreadsheet xSheet = getSheet(xDoc);
+ boolean done = false;
+ int counter = 0;
+ String wordToCheck = "";
+ String expectedConversion = "";
+
+ while (!done) {
+ String[] HangulHanja = getLeftAndRight(counter, xSheet);
+ done = HangulHanja[0].equals("");
+ counter++;
+
+ if (!done) {
+ try {
+ xDict.addEntry(HangulHanja[0], HangulHanja[1]);
+ wordToCheck += HangulHanja[0];
+ expectedConversion += HangulHanja[1];
+ } catch (com.sun.star.lang.IllegalArgumentException e) {
+ e.printStackTrace();
+ res = false;
+ fail("Exception while checking adding entry");
+ } catch (com.sun.star.container.ElementExistException e) {
+ //ignored
+ }
+ }
+ }
+
+ try {
+ xDict.addEntry(wordToCheck, expectedConversion);
+ } catch (com.sun.star.lang.IllegalArgumentException e) {
+ e.printStackTrace();
+ res = false;
+ fail("Exception while checking adding entry");
+ } catch (com.sun.star.container.ElementExistException e) {
+ //ignored
+ }
+
+ localRes = xCList.queryMaxCharCount(aLocale, dictType,
+ ConversionDirection.FROM_LEFT) == 42;
+ res &= localRes;
+ assertTrue("queryMaxCharCount returned the wrong value", localRes);
+
+ String[] conversion = null;
+
+ try {
+ conversion = xCList.queryConversions(wordToCheck, 0,
+ wordToCheck.length(), aLocale,
+ dictType,
+ ConversionDirection.FROM_LEFT,
+ TextConversionOption.NONE);
+ } catch (com.sun.star.lang.IllegalArgumentException e) {
+ res = false;
+ fail("Exception while calling queryConversions");
+ } catch (com.sun.star.lang.NoSupportException e) {
+ res = false;
+ fail("Exception while calling queryConversions");
+ }
+
+ localRes = conversion[0].equals(expectedConversion);
+ res &= localRes;
+ assertTrue("queryConversions didn't work as expected", localRes);
+
+ try {
+ xCList.getDictionaryContainer().removeByName("addNewDictionary");
+ } catch (com.sun.star.container.NoSuchElementException e) {
+ res = false;
+ fail("exception while removing Dictionary again");
+ } catch (com.sun.star.lang.WrappedTargetException e) {
+ res = false;
+ fail("exception while removing Dictionary again");
+ }
+
+ localRes = !xCList.getDictionaryContainer()
+ .hasByName("addNewDictionary");
+ res &= localRes;
+ assertTrue("Dictionary hasn't been removed properly", localRes);
+
+ XComponent dicList = UnoRuntime.queryInterface(XComponent.class, xCList);
+ XEventListener listen = new EventListener();
+ dicList.addEventListener(listen);
+ dicList.dispose();
+ assertTrue("dispose didn't work", disposed);
+ dicList.removeEventListener(listen);
+
+ DesktopTools.closeDoc(xDoc);
+
+ return res;
+ }
+
+ private boolean checkNameContainer(XNameContainer xNC) {
+ boolean res = true;
+
+ try {
+ res &= xNC.hasByName("addNewDictionary");
+
+ XConversionDictionary myCD = new ConversionDictionary();
+ xNC.insertByName("insertByName", myCD);
+ res &= xNC.hasByName("insertByName");
+ xNC.removeByName("insertByName");
+ res &= !(xNC.hasByName("insertByName"));
+ } catch (com.sun.star.lang.IllegalArgumentException e) {
+ res = false;
+ e.printStackTrace();
+ } catch (com.sun.star.container.NoSuchElementException e) {
+ res = false;
+ e.printStackTrace();
+ } catch (com.sun.star.container.ElementExistException e) {
+ res = false;
+ e.printStackTrace();
+ } catch (com.sun.star.lang.WrappedTargetException e) {
+ res = false;
+ e.printStackTrace();
+ }
+
+ return res;
+ }
+
+ private XSpreadsheet getSheet(XComponent xDoc) {
+ XSpreadsheetDocument xSheetDoc = UnoRuntime.queryInterface(XSpreadsheetDocument.class, xDoc);
+ XSpreadsheet xSheet = null;
+
+ try {
+ xSheet = UnoRuntime.queryInterface(XSpreadsheet.class, xSheetDoc.getSheets().getByName(xSheetDoc.getSheets().getElementNames()[0]));
+ } catch (com.sun.star.container.NoSuchElementException e) {
+ System.out.println("Couldn't get sheet");
+ e.printStackTrace();
+ } catch (com.sun.star.lang.WrappedTargetException e) {
+ System.out.println("Couldn't get sheet");
+ e.printStackTrace();
+ }
+
+ return xSheet;
+ }
+
+ private String[] getLeftAndRight(int counter, XSpreadsheet xSpreadsheet) {
+ String[] re = new String[] {
+ getCell(0, counter, xSpreadsheet).getFormula().trim(),
+ getCell(1, counter, xSpreadsheet).getFormula().trim() };
+
+ return re;
+ }
+
+ private XCell getCell(int x, int y, XSpreadsheet xSpreadsheet) {
+ XCell re = null;
+
+ try {
+ re = xSpreadsheet.getCellByPosition(x, y);
+ } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
+ System.out.println("Couldn't get word");
+ e.printStackTrace();
+ }
+
+ return re;
+ }
+
+ private class ConversionDictionary implements XConversionDictionary {
+ boolean active = false;
+
+ public void addEntry(String str, String str1)
+ throws IllegalArgumentException, ElementExistException {
+ }
+
+ public void clear() {
+ }
+
+ public String[] getConversionEntries(ConversionDirection conversionDirection) {
+ return new String[] { "getConversionEntries" };
+ }
+
+ public short getConversionType() {
+ return ConversionDictionaryType.HANGUL_HANJA;
+ }
+
+ public String[] getConversions(String str, int param, int param2,
+ ConversionDirection conversionDirection,
+ int param4)
+ throws IllegalArgumentException {
+ return new String[] { "getConversion" };
+ }
+
+ public com.sun.star.lang.Locale getLocale() {
+ return new Locale("de", "DE", "");
+ }
+
+ public short getMaxCharCount(ConversionDirection conversionDirection) {
+ return (short) 2;
+ }
+
+ public String getName() {
+ return "insertByName";
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void removeEntry(String str, String str1)
+ throws NoSuchElementException {
+ }
+
+ public void setActive(boolean param) {
+ active = param;
+ }
+ }
+
+ private class EventListener implements XEventListener {
+ public void disposing(com.sun.star.lang.EventObject eventObject) {
+ disposed = true;
+ }
+ }
+
+ private XMultiServiceFactory getMSF()
+ {
+ return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
+ }
+
+ // setup and close connections
+ @BeforeClass public static void setUpConnection() throws Exception {
+ System.out.println("setUpConnection()");
+ connection.setUp();
+ }
+
+ @AfterClass public static void tearDownConnection()
+ throws InterruptedException, com.sun.star.uno.Exception
+ {
+ System.out.println("tearDownConnection()");
+ connection.tearDown();
+ }
+
+ private static final OfficeConnection connection = new OfficeConnection();
+
+}
diff --git a/linguistic/qa/complex/linguistic/TestDocument.java b/linguistic/qa/complex/linguistic/TestDocument.java
new file mode 100644
index 0000000000..3384fa9e75
--- /dev/null
+++ b/linguistic/qa/complex/linguistic/TestDocument.java
@@ -0,0 +1,32 @@
+/*
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package complex.linguistic;
+
+import java.io.File;
+import org.openoffice.test.OfficeFileUrl;
+
+final class TestDocument
+{
+ public static String getUrl(String name)
+ {
+ return OfficeFileUrl.getAbsolute(new File("testdocuments", name));
+ }
+
+ private TestDocument() {}
+}
diff --git a/linguistic/qa/complex/linguistic/testdocuments/hangulhanja.sxc b/linguistic/qa/complex/linguistic/testdocuments/hangulhanja.sxc
new file mode 100644
index 0000000000..823ce57d32
--- /dev/null
+++ b/linguistic/qa/complex/linguistic/testdocuments/hangulhanja.sxc
Binary files differ
diff --git a/linguistic/qa/restprotocol.cxx b/linguistic/qa/restprotocol.cxx
new file mode 100644
index 0000000000..d5783d0a90
--- /dev/null
+++ b/linguistic/qa/restprotocol.cxx
@@ -0,0 +1,185 @@
+/* -*- 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 <sal/config.h>
+
+#include <algorithm>
+#include <cassert>
+#include <cstring>
+
+#include <sal/log.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <rtl/strbuf.hxx>
+#include <osl/socket.hxx>
+#include <osl/thread.hxx>
+#include <unotest/bootstrapfixturebase.hxx>
+#include <officecfg/Office/Linguistic.hxx>
+
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/connection/XAcceptor.hpp>
+#include <com/sun/star/connection/XConnector.hpp>
+#include <com/sun/star/linguistic2/XProofreader.hpp>
+#include <com/sun/star/linguistic2/ProofreadingResult.hpp>
+
+using namespace ::com::sun::star::uno;
+
+namespace
+{
+class MockServerThread : public ::osl::Thread
+{
+public:
+ MockServerThread()
+ : m_aSocketAddr("localhost", 2022)
+ {
+ }
+
+ virtual void SAL_CALL run()
+ {
+ if (m_aAcceptorSocket.acceptConnection(m_aStreamSocket) != osl_Socket_Ok)
+ {
+ return;
+ }
+
+ sal_Int32 nReadBytes;
+ Sequence<sal_Int8> aBuffer(512);
+ sal_Int32 nTcpNoDelay = sal_Int32(true);
+ m_aStreamSocket.setOption(osl_Socket_OptionTcpNoDelay, &nTcpNoDelay, sizeof(nTcpNoDelay),
+ osl_Socket_LevelTcp);
+
+ nReadBytes = m_aStreamSocket.recv(aBuffer.getArray(), aBuffer.getLength());
+ if (nReadBytes)
+ {
+ std::string aText(reinterpret_cast<const char*>(aBuffer.getConstArray()), nReadBytes);
+
+ if (aText.find("POST /api/check") == std::string::npos)
+ {
+ NotFound();
+ }
+ else if (aText.find("Content-Type: application/json") == std::string::npos)
+ {
+ NotFound();
+ }
+ else
+ {
+ ResponseOK();
+ }
+ }
+ }
+
+ void ResponseOK()
+ {
+ OString aResponse(
+ "HTTP/1.1 200 OK\r\n"
+ "Server: MockServer\r\n"
+ "Cache-Control: no-cache\r\n"
+ "Content-Type: application/json\r\n"
+ "\r\n"
+ "{\"check-positions\":[{\"offset\":15,\"length\":6,\"errorcode\":4711,\"type\":"
+ "\"orth\","
+ "\"severity\":1,\"proposals\":[\"Entwurf\",\"Entw\u00fcrfe\"]},"
+ "{\"offset\":22,\"length\":3,\"errorcode\":8221,\"type\":\"orth\",\"severity\":1}]}"_ostr);
+
+ m_aStreamSocket.write(aResponse.getStr(), aResponse.getLength());
+ m_aStreamSocket.close();
+ }
+
+ void NotFound()
+ {
+ OString aResponse("HTTP/1.1 404 Not Found\r\n"
+ "Connection: Closed\r\n"
+ "\r\n"_ostr);
+
+ m_aStreamSocket.write(aResponse.getStr(), aResponse.getLength());
+ m_aStreamSocket.close();
+ }
+
+ void stop()
+ {
+ m_aAcceptorSocket.close();
+ join();
+ }
+
+ void init()
+ {
+ m_aAcceptorSocket.setOption(osl_Socket_OptionReuseAddr, 1);
+ CPPUNIT_ASSERT(m_aAcceptorSocket.bind(m_aSocketAddr));
+ CPPUNIT_ASSERT(m_aAcceptorSocket.listen());
+ }
+
+private:
+ ::osl::SocketAddr m_aSocketAddr;
+ ::osl::AcceptorSocket m_aAcceptorSocket;
+ ::osl::StreamSocket m_aStreamSocket;
+};
+}
+
+MockServerThread aMockServer;
+
+class TestRestProtocol : public test::BootstrapFixtureBase
+{
+public:
+ virtual void setUp() override;
+ virtual void tearDown() override;
+
+private:
+ CPPUNIT_TEST_SUITE(TestRestProtocol);
+ CPPUNIT_TEST(testProofreading);
+ CPPUNIT_TEST_SUITE_END();
+
+ void testProofreading();
+};
+
+void TestRestProtocol::testProofreading()
+{
+ css::lang::Locale aLocale("en", "US", "");
+ using LanguageToolCfg = officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
+ auto batch(comphelper::ConfigurationChanges::create());
+
+ LanguageToolCfg::BaseURL::set("http://127.0.0.1:2022/api", batch);
+ LanguageToolCfg::Username::set("hcastro", batch);
+ LanguageToolCfg::ApiKey::set("hcvhcvhcv", batch);
+ LanguageToolCfg::IsEnabled::set(true, batch);
+ LanguageToolCfg::SSLCertVerify::set(false, batch);
+ LanguageToolCfg::RestProtocol::set("duden", batch);
+
+ batch->commit();
+
+ CPPUNIT_ASSERT_EQUAL(OUString("duden"), *LanguageToolCfg::RestProtocol::get());
+
+ Reference<::com::sun::star::linguistic2::XProofreader> xProofreader(
+ m_xSFactory->createInstance("com.sun.star.linguistic2.Proofreader"), UNO_QUERY);
+ CPPUNIT_ASSERT(xProofreader.is());
+
+ com::sun::star::linguistic2::ProofreadingResult aResult
+ = xProofreader->doProofreading("id", "ths is a tst", aLocale, 0, 0, {});
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aResult.aErrors.getLength());
+}
+
+void TestRestProtocol::setUp()
+{
+ test::BootstrapFixtureBase::setUp();
+
+ aMockServer.init();
+ aMockServer.create();
+ osl::Thread::wait(std::chrono::seconds(1));
+}
+
+void TestRestProtocol::tearDown()
+{
+ aMockServer.stop();
+
+ test::BootstrapFixtureBase::tearDown();
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestRestProtocol);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/linguistic/qa/unoapi/knownissues.xcl b/linguistic/qa/unoapi/knownissues.xcl
new file mode 100644
index 0000000000..27f9dacc17
--- /dev/null
+++ b/linguistic/qa/unoapi/knownissues.xcl
@@ -0,0 +1,27 @@
+#
+# 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/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+### i84435 ##
+lng.LngSvcMgr
+#uncommented in lng.sce
+
+### i88538 ###
+lng.DicList::com::sun::star::linguistic2::XSearchableDictionaryList
+
+### i96846 ###
+lng.LinguProps::com::sun::star::linguistic2::LinguProperties
diff --git a/linguistic/qa/unoapi/lng.sce b/linguistic/qa/unoapi/lng.sce
new file mode 100644
index 0000000000..fd41284386
--- /dev/null
+++ b/linguistic/qa/unoapi/lng.sce
@@ -0,0 +1,3 @@
+-o lng.DicList
+-o lng.LinguProps
+#i84435 -o lng.LngSvcMgr