summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i18npool/CppunitTest_i18npool_test_textsearch.mk38
-rw-r--r--i18npool/Module_i18npool.mk1
-rw-r--r--i18npool/qa/cppunit/test_textsearch.cxx144
-rw-r--r--qadevOOo/Jar_OOoRunner.mk2
-rw-r--r--qadevOOo/tests/java/ifc/util/_XTextSearch.java110
-rw-r--r--qadevOOo/tests/java/mod/_i18n/TextSearch.java72
6 files changed, 183 insertions, 184 deletions
diff --git a/i18npool/CppunitTest_i18npool_test_textsearch.mk b/i18npool/CppunitTest_i18npool_test_textsearch.mk
new file mode 100644
index 000000000000..8331cbda4ea3
--- /dev/null
+++ b/i18npool/CppunitTest_i18npool_test_textsearch.mk
@@ -0,0 +1,38 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,i18npool_test_textsearch))
+
+$(eval $(call gb_CppunitTest_use_api,i18npool_test_textsearch,\
+ udkapi \
+ offapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,i18npool_test_textsearch))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,i18npool_test_textsearch,\
+ i18npool/qa/cppunit/test_textsearch \
+))
+
+$(eval $(call gb_CppunitTest_use_components,i18npool_test_textsearch,\
+ i18npool/source/search/i18nsearch \
+ i18npool/util/i18npool \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,i18npool_test_textsearch,\
+ cppu \
+ cppuhelper \
+ sal \
+ icuuc \
+ icui18n \
+ unotest \
+ $(gb_UWINAPI) \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/i18npool/Module_i18npool.mk b/i18npool/Module_i18npool.mk
index 455d6f0b7d00..a8f211848bf5 100644
--- a/i18npool/Module_i18npool.mk
+++ b/i18npool/Module_i18npool.mk
@@ -64,6 +64,7 @@ $(eval $(call gb_Module_add_check_targets,i18npool,\
CppunitTest_i18npool_test_characterclassification \
CppunitTest_i18npool_test_languagetag \
CppunitTest_i18npool_test_ordinalsuffix \
+ CppunitTest_i18npool_test_textsearch \
))
# vim: set noet sw=4 ts=4:
diff --git a/i18npool/qa/cppunit/test_textsearch.cxx b/i18npool/qa/cppunit/test_textsearch.cxx
new file mode 100644
index 000000000000..682a60712c0a
--- /dev/null
+++ b/i18npool/qa/cppunit/test_textsearch.cxx
@@ -0,0 +1,144 @@
+/* -*- 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/.
+ *
+ * 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 .
+ */
+
+#include <cppuhelper/compbase1.hxx>
+#include <cppuhelper/bootstrap.hxx>
+#include <cppuhelper/basemutex.hxx>
+#include <com/sun/star/util/SearchFlags.hpp>
+#include <com/sun/star/util/SearchOptions.hpp>
+#include <com/sun/star/util/SearchAlgorithms.hpp>
+#include <com/sun/star/util/XTextSearch.hpp>
+#include <unotest/bootstrapfixturebase.hxx>
+
+#include <unicode/regex.h>
+
+#include <rtl/strbuf.hxx>
+#include <rtl/ustrbuf.hxx>
+
+using namespace ::com::sun::star;
+using namespace U_ICU_NAMESPACE;
+typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
+
+class TestTextSearch : public test::BootstrapFixtureBase
+{
+public:
+ virtual void setUp();
+ virtual void tearDown();
+
+ void testICU();
+ void testSearches();
+
+ CPPUNIT_TEST_SUITE(TestTextSearch);
+ CPPUNIT_TEST(testICU);
+ CPPUNIT_TEST(testSearches);
+ CPPUNIT_TEST_SUITE_END();
+private:
+ uno::Reference<util::XTextSearch> m_xSearch;
+};
+
+// Sanity check our ICU first ...
+void TestTextSearch::testICU()
+{
+ UErrorCode nErr = U_ZERO_ERROR;
+ RegexMatcher* pRegexMatcher;
+ sal_uInt32 nSearchFlags = UREGEX_UWORD | UREGEX_CASE_INSENSITIVE;
+
+ OUString aString( "abcdefgh" );
+ OUString aPattern( "e" );
+ IcuUniString aSearchPat( (const UChar*)aPattern.getStr(), aPattern.getLength() );
+
+ pRegexMatcher = new RegexMatcher( aSearchPat, nSearchFlags, nErr );
+
+ IcuUniString aSource( (const UChar*)aString.getStr(), aString.getLength() );
+ pRegexMatcher->reset( aSource );
+
+ CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
+ CPPUNIT_ASSERT( nErr == U_ZERO_ERROR );
+ CPPUNIT_ASSERT( pRegexMatcher->start( nErr ) == 4 );
+ CPPUNIT_ASSERT( nErr == U_ZERO_ERROR );
+ CPPUNIT_ASSERT( pRegexMatcher->end( nErr ) == 5 );
+ CPPUNIT_ASSERT( nErr == U_ZERO_ERROR );
+
+ delete pRegexMatcher;
+
+ OUString aString2( "acababaabcababadcdaa" );
+ OUString aPattern2( "a" );
+
+ IcuUniString aSearchPat2( (const UChar*)aPattern2.getStr(), aPattern2.getLength() );
+ pRegexMatcher = new RegexMatcher( aSearchPat2, nSearchFlags, nErr );
+
+ IcuUniString aSource2( (const UChar*)aString2.getStr(), aString2.getLength() );
+ pRegexMatcher->reset( aSource2 );
+
+ CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
+ CPPUNIT_ASSERT( nErr == U_ZERO_ERROR );
+ CPPUNIT_ASSERT( pRegexMatcher->start( nErr ) == 0 );
+ CPPUNIT_ASSERT( nErr == U_ZERO_ERROR );
+ CPPUNIT_ASSERT( pRegexMatcher->end( nErr ) == 1 );
+ CPPUNIT_ASSERT( nErr == U_ZERO_ERROR );
+}
+
+void TestTextSearch::testSearches()
+{
+ OUString str( "acababaabcababadcdaa" );
+ sal_Int32 startPos = 2, endPos = 20 ;
+ OUString searchStr( "(ab)*a(c|d)+" );
+ sal_Int32 fStartRes = 10, fEndRes = 18 ;
+ sal_Int32 bStartRes = 18, bEndRes = 14 ;
+
+ // set options
+ util::SearchOptions aOptions;
+ aOptions.algorithmType = util::SearchAlgorithms_REGEXP ;
+ aOptions.searchFlag = util::SearchFlags::ALL_IGNORE_CASE;
+ aOptions.searchString = searchStr;
+ m_xSearch->setOptions( aOptions );
+
+ util::SearchResult aRes;
+
+ // search forward
+ aRes = m_xSearch->searchForward( str, startPos, endPos );
+ CPPUNIT_ASSERT( aRes.subRegExpressions > 0 );
+ CPPUNIT_ASSERT( aRes.startOffset[0] == fStartRes );
+ CPPUNIT_ASSERT( aRes.endOffset[0] == fEndRes );
+
+ // search backwards
+ aRes = m_xSearch->searchBackward( str, endPos, startPos );
+ CPPUNIT_ASSERT( aRes.subRegExpressions > 0 );
+ CPPUNIT_ASSERT( aRes.startOffset[0] == bStartRes );
+ CPPUNIT_ASSERT( aRes.endOffset[0] == bEndRes );
+}
+
+void TestTextSearch::setUp()
+{
+ BootstrapFixtureBase::setUp();
+ m_xSearch = uno::Reference< util::XTextSearch >(m_xSFactory->createInstance(
+ "com.sun.star.util.TextSearch"), uno::UNO_QUERY_THROW);
+}
+
+void TestTextSearch::tearDown()
+{
+ m_xSearch.clear();
+ BootstrapFixtureBase::tearDown();
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestTextSearch);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/qadevOOo/Jar_OOoRunner.mk b/qadevOOo/Jar_OOoRunner.mk
index 4920dbcc2fc4..d6c5c9eceb9e 100644
--- a/qadevOOo/Jar_OOoRunner.mk
+++ b/qadevOOo/Jar_OOoRunner.mk
@@ -955,7 +955,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/ifc/util/_XSortable \
qadevOOo/tests/java/ifc/util/_XStringEscape \
qadevOOo/tests/java/ifc/util/_XStringSubstitution \
- qadevOOo/tests/java/ifc/util/_XTextSearch \
qadevOOo/tests/java/ifc/util/_XURLTransformer \
qadevOOo/tests/java/ifc/view/_XControlAccess \
qadevOOo/tests/java/ifc/view/_XFormLayerAccess \
@@ -1103,7 +1102,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/mod/_i18n/IndexEntrySupplier \
qadevOOo/tests/java/mod/_i18n/LocaleData \
qadevOOo/tests/java/mod/_i18n/NumberFormatCodeMapper \
- qadevOOo/tests/java/mod/_i18n/TextSearch \
qadevOOo/tests/java/mod/_i18n/Transliteration \
qadevOOo/tests/java/mod/_implreg/uno/ImplementationRegistration \
qadevOOo/tests/java/mod/_impreg/ImplementationRegistration \
diff --git a/qadevOOo/tests/java/ifc/util/_XTextSearch.java b/qadevOOo/tests/java/ifc/util/_XTextSearch.java
deleted file mode 100644
index abb47de60155..000000000000
--- a/qadevOOo/tests/java/ifc/util/_XTextSearch.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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 ifc.util;
-
-import lib.MultiMethodTest;
-
-import com.sun.star.util.SearchAlgorithms;
-import com.sun.star.util.SearchFlags;
-import com.sun.star.util.SearchOptions;
-import com.sun.star.util.SearchResult;
-import com.sun.star.util.XTextSearch;
-
-/**
-* Testing <code>com.sun.star.util.XTextSearch</code>
-* interface methods :
-* <ul>
-* <li><code> setOptions()</code></li>
-* <li><code> searchForward()</code></li>
-* <li><code> searchBackward()</code></li>
-* </ul> <p>
-* Test is <b> NOT </b> multithread compilant. <p>
-* @see com.sun.star.util.XTextSearch
-*/
-public class _XTextSearch extends MultiMethodTest {
-
- // oObj filled by MultiMethodTest
- public XTextSearch oObj = null ;
-
- protected final String str = "acababaabcababadcdaa" ;
- protected final int startPos = 2 , endPos = 20 ;
- protected final String searchStr = "(ab)*a(c|d)+" ;
- protected final int fStartRes = 10, fEndRes = 18 ;
- protected final int bStartRes = 18, bEndRes = 14 ;
-
- /**
- * Sets options for searching regular expression in a string,
- * ignoring case. <p>
- * Has <b>OK</b> status if no runtime exceptions occurred.
- */
- public void _setOptions() {
-
- SearchOptions opt = new SearchOptions() ;
- opt.algorithmType = SearchAlgorithms.REGEXP ;
- opt.searchFlag = SearchFlags.ALL_IGNORE_CASE ;
- opt.searchString = searchStr ;
-
- oObj.setOptions(opt) ;
-
- tRes.tested("setOptions()", true) ;
- }
-
-
- /**
- * Tries to find a substring matching regular expression. <p>
- * Has <b>OK</b> if the correct substring position returned.
- */
- public void _searchForward() {
- requiredMethod("setOptions()") ;
-
- SearchResult res = oObj.searchForward(str, startPos, endPos) ;
-
- log.println("Result of searching '" + searchStr + "' substring in \n'" +
- str + "' string (" + res.subRegExpressions + " matches):") ;
-
- for (int i = 0; i < res.subRegExpressions; i++)
- log.println(" (" + res.startOffset[i] + ", " + res.endOffset[i] + ")") ;
-
- tRes.tested("searchForward()", res.subRegExpressions > 0 &&
- res.startOffset[0] == fStartRes && res.endOffset[0] == fEndRes) ;
- }
-
- /**
- * Tries to find a substring matching regular expression walking
- * backward. <p>
- * Has <b>OK</b> if the correct substring position returned.
- */
- public void _searchBackward() {
- requiredMethod("setOptions()") ;
-
- SearchResult res = oObj.searchBackward(str, endPos, startPos) ;
-
- log.println("Result of searching '" + searchStr + "' substring in \n'" +
- str + "' string (" + res.subRegExpressions + " matches):") ;
-
- for (int i = 0; i < res.subRegExpressions; i++)
- log.println(" (" + res.startOffset[i] + ", " + res.endOffset[i] + ")") ;
-
- tRes.tested("searchBackward()", res.subRegExpressions > 0 &&
- res.startOffset[0] == bStartRes && res.endOffset[0] == bEndRes) ;
- }
-
-}
-
-
diff --git a/qadevOOo/tests/java/mod/_i18n/TextSearch.java b/qadevOOo/tests/java/mod/_i18n/TextSearch.java
deleted file mode 100644
index 485f8db8099f..000000000000
--- a/qadevOOo/tests/java/mod/_i18n/TextSearch.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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 mod._i18n;
-
-import java.io.PrintWriter;
-
-import lib.StatusException;
-import lib.TestCase;
-import lib.TestEnvironment;
-import lib.TestParameters;
-
-import com.sun.star.lang.XMultiServiceFactory;
-import com.sun.star.uno.XInterface;
-
-/**
-* Test for object which is represented by service
-* <code>com.sun.star.util.TextSearch</code>. <p>
-* Object implements the following interfaces :
-* <ul>
-* <li> <code>com::sun::star::util::XTextSearch</code></li>
-* </ul>
-* This object test <b> is NOT </b> designed to be run in several
-* threads concurently.
-* @see ifc.util._XTextSearch
-*/
-public class TextSearch extends TestCase {
-
- /**
- * Creating a Testenvironment for the interfaces to be tested.
- * Creates an instance of the service
- * <code>com.sun.star.util.TextSearch</code>.
- */
- public TestEnvironment createTestEnvironment( TestParameters Param,
- PrintWriter log )
- throws StatusException {
- XInterface oObj = null;
- Object oInterface = null;
-
- try {
- XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
- oInterface = xMSF.createInstance( "com.sun.star.util.TextSearch" );
- }
- catch( com.sun.star.uno.Exception e ) {
- log.println("Can't create an object." );
- throw new StatusException( "Can't create an object", e );
- }
-
- oObj = (XInterface) oInterface;
-
- TestEnvironment tEnv = new TestEnvironment( oObj );
-
- return tEnv;
- } // finish method getTestEnvironment
-
-}
-