summaryrefslogtreecommitdiffstats
path: root/test/source/util
diff options
context:
space:
mode:
Diffstat (limited to 'test/source/util')
-rw-r--r--test/source/util/searchdescriptor.cxx63
-rw-r--r--test/source/util/xindent.cxx54
-rw-r--r--test/source/util/xmergeable.cxx33
-rw-r--r--test/source/util/xrefreshable.cxx64
-rw-r--r--test/source/util/xreplaceable.cxx85
-rw-r--r--test/source/util/xreplacedescriptor.cxx37
-rw-r--r--test/source/util/xsearchable.cxx65
-rw-r--r--test/source/util/xsearchdescriptor.cxx36
8 files changed, 437 insertions, 0 deletions
diff --git a/test/source/util/searchdescriptor.cxx b/test/source/util/searchdescriptor.cxx
new file mode 100644
index 000000000..d82994558
--- /dev/null
+++ b/test/source/util/searchdescriptor.cxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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 <test/util/searchdescriptor.hxx>
+#include <test/unoapi_property_testers.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include <com/sun/star/uno/Reference.hxx>
+
+using namespace css;
+
+namespace apitest
+{
+void SearchDescriptor::testSearchDescriptorProperties()
+{
+ uno::Reference<beans::XPropertySet> xPS(init(), uno::UNO_QUERY_THROW);
+
+ OUString aPropName;
+
+ aPropName = "SearchBackwards";
+ testBooleanProperty(xPS, aPropName);
+
+ aPropName = "SearchCaseSensitive";
+ testBooleanProperty(xPS, aPropName);
+
+ aPropName = "SearchWords";
+ testBooleanProperty(xPS, aPropName);
+
+ aPropName = "SearchRegularExpression";
+ testBooleanProperty(xPS, aPropName);
+
+ aPropName = "SearchStyles";
+ testBooleanProperty(xPS, aPropName);
+
+ aPropName = "SearchSimilarity";
+ testBooleanProperty(xPS, aPropName);
+
+ aPropName = "SearchSimilarityRelax";
+ testBooleanProperty(xPS, aPropName);
+
+ aPropName = "SearchSimilarityRemove";
+ testShortProperty(xPS, aPropName);
+
+ aPropName = "SearchSimilarityAdd";
+ testShortProperty(xPS, aPropName);
+
+ aPropName = "SearchSimilarityExchange";
+ testShortProperty(xPS, aPropName);
+
+ aPropName = "SearchWildcard";
+ testBooleanOptionalProperty(xPS, aPropName);
+}
+
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/util/xindent.cxx b/test/source/util/xindent.cxx
new file mode 100644
index 000000000..6b15407f9
--- /dev/null
+++ b/test/source/util/xindent.cxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+* 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 <test/util/xindent.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/util/XIndent.hpp>
+
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+
+namespace apitest
+{
+void XIndent::testIncrementIndent()
+{
+ uno::Reference<util::XIndent> xIndent(init(), UNO_QUERY_THROW);
+ uno::Reference<beans::XPropertySet> xPropertySet(xIndent, UNO_QUERY_THROW);
+ uno::Any aAny = xPropertySet->getPropertyValue("ParaIndent");
+ sal_Int32 nOldValue = aAny.get<sal_Int32>();
+
+ xIndent->incrementIndent();
+
+ uno::Any aAny2 = xPropertySet->getPropertyValue("ParaIndent");
+ sal_Int32 nNewValue = aAny2.get<sal_Int32>();
+ CPPUNIT_ASSERT_MESSAGE("Successfully able to Increment Indent", nOldValue < nNewValue);
+}
+void XIndent::testDecrementIndent()
+{
+ uno::Reference<util::XIndent> xIndent(init(), UNO_QUERY_THROW);
+ uno::Reference<beans::XPropertySet> xPropertySet(xIndent, UNO_QUERY_THROW);
+ xIndent->incrementIndent();
+ uno::Any aAny = xPropertySet->getPropertyValue("ParaIndent");
+ sal_Int32 nOldValue = aAny.get<sal_Int32>();
+
+ xIndent->decrementIndent();
+
+ uno::Any aAny2 = xPropertySet->getPropertyValue("ParaIndent");
+ sal_Int32 nNewValue = aAny2.get<sal_Int32>();
+ CPPUNIT_ASSERT_MESSAGE("Successfully able to Decrement Indent", nOldValue > nNewValue);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/util/xmergeable.cxx b/test/source/util/xmergeable.cxx
new file mode 100644
index 000000000..211b2b67f
--- /dev/null
+++ b/test/source/util/xmergeable.cxx
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+* 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 <test/util/xmergeable.hxx>
+
+#include <com/sun/star/util/XMergeable.hpp>
+
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+
+namespace apitest
+{
+void XMergeable::testGetIsMergedMerge()
+{
+ uno::Reference<util::XMergeable> xMergeable(init(), UNO_QUERY_THROW);
+ bool aIsMerged = xMergeable->getIsMerged();
+ xMergeable->merge(!aIsMerged);
+ bool aIsMerged2 = xMergeable->getIsMerged();
+ CPPUNIT_ASSERT_MESSAGE("Successfully able to Get is Merged and Merge", aIsMerged != aIsMerged2);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/util/xrefreshable.cxx b/test/source/util/xrefreshable.cxx
new file mode 100644
index 000000000..f448d93e5
--- /dev/null
+++ b/test/source/util/xrefreshable.cxx
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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 <test/util/xrefreshable.hxx>
+
+#include <com/sun/star/lang/EventObject.hpp>
+#include <com/sun/star/util/XRefreshListener.hpp>
+#include <com/sun/star/util/XRefreshable.hpp>
+
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppuhelper/implbase.hxx>
+#include <rtl/ref.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace com::sun::star;
+using namespace com::sun::star::uno;
+
+namespace apitest
+{
+namespace
+{
+class MockedRefreshListener : public ::cppu::WeakImplHelper<util::XRefreshListener>
+{
+public:
+ MockedRefreshListener()
+ : m_bListenerCalled(false)
+ {
+ }
+
+ bool m_bListenerCalled;
+ virtual void SAL_CALL refreshed(const lang::EventObject& /* xEvent */) override
+ {
+ m_bListenerCalled = true;
+ }
+ virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {}
+};
+}
+
+void XRefreshable::testRefreshListener()
+{
+ uno::Reference<util::XRefreshable> xRefreshable(init(), uno::UNO_QUERY_THROW);
+
+ rtl::Reference<MockedRefreshListener> xListener = new MockedRefreshListener();
+ xRefreshable->addRefreshListener(uno::Reference<util::XRefreshListener>(xListener.get()));
+
+ xRefreshable->refresh();
+ CPPUNIT_ASSERT(xListener->m_bListenerCalled);
+
+ xListener->m_bListenerCalled = false;
+ xRefreshable->removeRefreshListener(uno::Reference<util::XRefreshListener>(xListener.get()));
+ xRefreshable->refresh();
+ CPPUNIT_ASSERT(!xListener->m_bListenerCalled);
+}
+
+} // namespace apitest
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/util/xreplaceable.cxx b/test/source/util/xreplaceable.cxx
new file mode 100644
index 000000000..ac9d1a4dc
--- /dev/null
+++ b/test/source/util/xreplaceable.cxx
@@ -0,0 +1,85 @@
+/* -*- 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 <test/util/xreplaceable.hxx>
+
+#include <com/sun/star/util/XReplaceable.hpp>
+#include <com/sun/star/util/XReplaceDescriptor.hpp>
+#include <com/sun/star/util/XSearchDescriptor.hpp>
+#include <cppunit/TestAssert.h>
+
+#include <iostream>
+
+#include <test/callgrind.hxx>
+
+using namespace css;
+using namespace css::uno;
+
+namespace apitest {
+
+void XReplaceable::testCreateReplaceDescriptor()
+{
+ uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW);
+ uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor();
+ CPPUNIT_ASSERT(xReplaceDescr.is());
+}
+
+void XReplaceable::testReplaceAll()
+{
+ std::cout << "testReplaceAll" << std::endl;
+ uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW);
+ uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor();
+ CPPUNIT_ASSERT(xReplaceDescr.is());
+
+ uno::Reference< util::XSearchDescriptor > xSearchDescr = xReplaceable->createSearchDescriptor();
+ xSearchDescr->setSearchString(maSearchString);
+
+ //check that at least one object is there that will be replaced
+ uno::Reference< uno::XInterface > xElement = xReplaceable->findFirst(xSearchDescr);
+ CPPUNIT_ASSERT(xElement.is());
+
+ //check that there is none object with the replace string
+ xSearchDescr->setSearchString(maReplaceString);
+ xElement = xReplaceable->findFirst(xSearchDescr);
+ CPPUNIT_ASSERT(!xElement.is());
+
+ xReplaceDescr->setSearchString(maSearchString);
+ xReplaceDescr->setReplaceString(maReplaceString);
+
+ callgrindStart();
+ xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW));
+ callgrindDump("test:replace_all");
+
+ //check that now at least one element is found
+ xElement = xReplaceable->findFirst(xSearchDescr);
+ CPPUNIT_ASSERT(xElement.is());
+
+ xSearchDescr->setSearchString(maSearchString);
+ xElement = xReplaceable->findFirst(xSearchDescr);
+ CPPUNIT_ASSERT(!xElement.is());
+
+ //redo the whole thing
+ xReplaceDescr->setSearchString(maReplaceString);
+ xReplaceDescr->setReplaceString(maSearchString);
+
+ xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW));
+
+ //check that it works
+ xElement = xReplaceable->findFirst(xSearchDescr);
+ CPPUNIT_ASSERT(xElement.is());
+
+ //check that there is none object with the replace string
+ xSearchDescr->setSearchString(maReplaceString);
+ xElement = xReplaceable->findFirst(xSearchDescr);
+ CPPUNIT_ASSERT(!xElement.is());
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/source/util/xreplacedescriptor.cxx b/test/source/util/xreplacedescriptor.cxx
new file mode 100644
index 000000000..b3b042a2d
--- /dev/null
+++ b/test/source/util/xreplacedescriptor.cxx
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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 <test/util/xreplacedescriptor.hxx>
+#include <rtl/ustring.hxx>
+
+#include <com/sun/star/util/XReplaceDescriptor.hpp>
+
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace css;
+
+namespace apitest
+{
+void XReplaceDescriptor::testGetSetReplaceString()
+{
+ uno::Reference<util::XReplaceDescriptor> xRD(init(), uno::UNO_QUERY_THROW);
+ const OUString aReplaceStringOld = xRD->getReplaceString();
+ CPPUNIT_ASSERT(aReplaceStringOld.isEmpty());
+
+ xRD->setReplaceString("_XReplaceDescriptor");
+ const OUString aReplaceStringNew = xRD->getReplaceString();
+ CPPUNIT_ASSERT_EQUAL(OUString("_XReplaceDescriptor"), aReplaceStringNew);
+ CPPUNIT_ASSERT(aReplaceStringOld != aReplaceStringNew);
+}
+
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/util/xsearchable.cxx b/test/source/util/xsearchable.cxx
new file mode 100644
index 000000000..b636377d8
--- /dev/null
+++ b/test/source/util/xsearchable.cxx
@@ -0,0 +1,65 @@
+/* -*- 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 <com/sun/star/util/XSearchable.hpp>
+#include <com/sun/star/util/XSearchDescriptor.hpp>
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <cppunit/TestAssert.h>
+
+#include <test/util/xsearchable.hxx>
+
+using namespace css;
+using namespace css::uno;
+
+namespace apitest {
+
+void XSearchable::testFindAll()
+{
+ uno::Reference< util::XSearchable > xSearchable(init(), UNO_QUERY_THROW);
+ uno::Reference< util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor();
+ xSearchDescr->setSearchString(maSearchString);
+
+ uno::Reference< container::XIndexAccess > xIndex = xSearchable->findAll(xSearchDescr);
+ CPPUNIT_ASSERT(xIndex.is());
+ CPPUNIT_ASSERT_EQUAL(mnCount, xIndex->getCount());
+}
+
+void XSearchable::testFindFirst()
+{
+ uno::Reference< util::XSearchable > xSearchable(init(), UNO_QUERY_THROW);
+ uno::Reference< util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor();
+ xSearchDescr->setSearchString(maSearchString);
+
+ uno::Reference< uno::XInterface > xElement = xSearchable->findFirst(xSearchDescr);
+ CPPUNIT_ASSERT(xElement.is());
+}
+
+void XSearchable::testFindNext()
+{
+ uno::Reference< util::XSearchable > xSearchable(init(), UNO_QUERY_THROW);
+ uno::Reference< util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor();
+ xSearchDescr->setSearchString(maSearchString);
+
+ uno::Reference< uno::XInterface > xElement = xSearchable->findFirst(xSearchDescr);
+ CPPUNIT_ASSERT(xElement.is());
+
+ if (mnCount > 1)
+ {
+ uno::Reference< uno::XInterface > xElement2 = xSearchable->findNext(xElement, xSearchDescr);
+ CPPUNIT_ASSERT(xElement2.is());
+ }
+}
+
+XSearchable::~XSearchable()
+{
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/source/util/xsearchdescriptor.cxx b/test/source/util/xsearchdescriptor.cxx
new file mode 100644
index 000000000..2740b2e26
--- /dev/null
+++ b/test/source/util/xsearchdescriptor.cxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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 <test/util/xsearchdescriptor.hxx>
+
+#include <com/sun/star/util/XSearchDescriptor.hpp>
+
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace css;
+
+namespace apitest
+{
+void XSearchDescriptor::testGetSetSearchString()
+{
+ uno::Reference<util::XSearchDescriptor> xDS(init(), uno::UNO_QUERY_THROW);
+ const OUString aSearchStringOld = xDS->getSearchString();
+ CPPUNIT_ASSERT(aSearchStringOld.isEmpty());
+
+ xDS->setSearchString("_XSearchDescriptor");
+ const OUString aSearchStringNew = xDS->getSearchString();
+ CPPUNIT_ASSERT_EQUAL(OUString("_XSearchDescriptor"), aSearchStringNew);
+ CPPUNIT_ASSERT(aSearchStringOld != aSearchStringNew);
+}
+
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */