summaryrefslogtreecommitdiffstats
path: root/test/source/container
diff options
context:
space:
mode:
Diffstat (limited to 'test/source/container')
-rw-r--r--test/source/container/xchild.cxx38
-rw-r--r--test/source/container/xelementaccess.cxx36
-rw-r--r--test/source/container/xenumeration.cxx43
-rw-r--r--test/source/container/xenumerationaccess.cxx31
-rw-r--r--test/source/container/xindexaccess.cxx55
-rw-r--r--test/source/container/xnameaccess.cxx55
-rw-r--r--test/source/container/xnamecontainer.cxx101
-rw-r--r--test/source/container/xnamed.cxx65
-rw-r--r--test/source/container/xnamereplace.cxx37
9 files changed, 461 insertions, 0 deletions
diff --git a/test/source/container/xchild.cxx b/test/source/container/xchild.cxx
new file mode 100644
index 000000000..eac97b0eb
--- /dev/null
+++ b/test/source/container/xchild.cxx
@@ -0,0 +1,38 @@
+/* -*- 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/container/xchild.hxx>
+
+#include <com/sun/star/container/XChild.hpp>
+#include <com/sun/star/uno/XInterface.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 XChild::testGetSetParent()
+{
+ uno::Reference<container::XChild> xChild(init(), UNO_QUERY_THROW);
+ uno::Reference<uno::XInterface> xInterface(xChild, UNO_QUERY_THROW);
+ xInterface = xChild->getParent();
+
+ CPPUNIT_ASSERT_MESSAGE("Successfully able to Get Parent", xInterface);
+
+ xChild->setParent(xInterface);
+
+ CPPUNIT_ASSERT_MESSAGE("Successfully able to Set Parent", xChild);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/container/xelementaccess.cxx b/test/source/container/xelementaccess.cxx
new file mode 100644
index 000000000..4ec751520
--- /dev/null
+++ b/test/source/container/xelementaccess.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/container/xelementaccess.hxx>
+
+#include <com/sun/star/container/XElementAccess.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace css;
+using namespace css::uno;
+
+namespace apitest
+{
+void XElementAccess::testGetElementType()
+{
+ uno::Reference<container::XElementAccess> xElementAccess(init(), UNO_QUERY_THROW);
+ CPPUNIT_ASSERT_EQUAL(m_aType, xElementAccess->getElementType());
+}
+
+void XElementAccess::testHasElements()
+{
+ uno::Reference<container::XElementAccess> xElementAccess(init(), UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xElementAccess->hasElements());
+}
+
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/container/xenumeration.cxx b/test/source/container/xenumeration.cxx
new file mode 100644
index 000000000..190ef27fe
--- /dev/null
+++ b/test/source/container/xenumeration.cxx
@@ -0,0 +1,43 @@
+/* -*- 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/container/xenumeration.hxx>
+
+#include <com/sun/star/container/NoSuchElementException.hpp>
+#include <com/sun/star/container/XEnumeration.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 XEnumeration::testHasMoreElements()
+{
+ uno::Reference<container::XEnumeration> xEnumeration(init(), uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xEnumeration->hasMoreElements());
+}
+
+void XEnumeration::testNextElement()
+{
+ uno::Reference<container::XEnumeration> xEnumeration(init(), uno::UNO_QUERY_THROW);
+
+ // unwind all elements from the enumeration
+ while (xEnumeration->hasMoreElements())
+ CPPUNIT_ASSERT_NO_THROW(xEnumeration->nextElement());
+
+ CPPUNIT_ASSERT_THROW_MESSAGE("Incorrect exception", xEnumeration->nextElement(),
+ container::NoSuchElementException);
+}
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/container/xenumerationaccess.cxx b/test/source/container/xenumerationaccess.cxx
new file mode 100644
index 000000000..e3c53064e
--- /dev/null
+++ b/test/source/container/xenumerationaccess.cxx
@@ -0,0 +1,31 @@
+/* -*- 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/container/xenumerationaccess.hxx>
+
+#include <com/sun/star/container/XEnumerationAccess.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 XEnumerationAccess::testCreateEnumeration()
+{
+ uno::Reference<container::XEnumerationAccess> xEnumerationAccess(init(), UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT_MESSAGE("Unable to create enumeration", xEnumerationAccess->createEnumeration());
+}
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/container/xindexaccess.cxx b/test/source/container/xindexaccess.cxx
new file mode 100644
index 000000000..7fc08027c
--- /dev/null
+++ b/test/source/container/xindexaccess.cxx
@@ -0,0 +1,55 @@
+/* -*- 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/container/xindexaccess.hxx>
+
+#include <com/sun/star/container/XIndexAccess.hpp>
+
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace css;
+using namespace css::uno;
+
+namespace apitest
+{
+void XIndexAccess::testGetCount()
+{
+ uno::Reference<container::XIndexAccess> xIndexAccess(init(), UNO_QUERY_THROW);
+ CPPUNIT_ASSERT_EQUAL(m_nItems, xIndexAccess->getCount());
+}
+
+void XIndexAccess::testGetByIndex()
+{
+ uno::Reference<container::XIndexAccess> xIndexAccess(init(), UNO_QUERY_THROW);
+ CPPUNIT_ASSERT_EQUAL(m_nItems, xIndexAccess->getCount());
+
+ if (m_nItems > 0)
+ {
+ Any aAny = xIndexAccess->getByIndex(0);
+ CPPUNIT_ASSERT(aAny.hasValue());
+
+ aAny = xIndexAccess->getByIndex(m_nItems / 2);
+ CPPUNIT_ASSERT(aAny.hasValue());
+
+ aAny = xIndexAccess->getByIndex(m_nItems - 1);
+ CPPUNIT_ASSERT(aAny.hasValue());
+ }
+}
+
+void XIndexAccess::testGetByIndexException()
+{
+ uno::Reference<container::XIndexAccess> xIndexAccess(init(), UNO_QUERY_THROW);
+ xIndexAccess->getByIndex(m_nItems);
+}
+
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/source/container/xnameaccess.cxx b/test/source/container/xnameaccess.cxx
new file mode 100644
index 000000000..3616c4cda
--- /dev/null
+++ b/test/source/container/xnameaccess.cxx
@@ -0,0 +1,55 @@
+/* -*- 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/container/xnameaccess.hxx>
+
+#include <com/sun/star/container/NoSuchElementException.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace css;
+using namespace css::uno;
+
+namespace apitest
+{
+void XNameAccess::testGetByName()
+{
+ uno::Reference<container::XNameAccess> xNA(init(), uno::UNO_QUERY_THROW);
+
+ // test with existing name
+ CPPUNIT_ASSERT_NO_THROW(xNA->getByName(m_aName));
+ // test with non-existing name
+ CPPUNIT_ASSERT_THROW(xNA->getByName(m_aName + "UnitTest"), container::NoSuchElementException);
+}
+
+void XNameAccess::testGetElementNames()
+{
+ uno::Reference<container::XNameAccess> xNA(init(), uno::UNO_QUERY_THROW);
+ uno::Sequence<OUString> aNames = xNA->getElementNames();
+
+ CPPUNIT_ASSERT(aNames.hasElements());
+}
+
+void XNameAccess::testHasByName()
+{
+ uno::Reference<container::XNameAccess> xNA(init(), uno::UNO_QUERY_THROW);
+
+ // test with existing name
+ CPPUNIT_ASSERT(xNA->hasByName(m_aName));
+ // test with non-existing name
+ CPPUNIT_ASSERT(!xNA->hasByName(m_aName + "UnitTest"));
+}
+
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/container/xnamecontainer.cxx b/test/source/container/xnamecontainer.cxx
new file mode 100644
index 000000000..5df1e76b3
--- /dev/null
+++ b/test/source/container/xnamecontainer.cxx
@@ -0,0 +1,101 @@
+/* -*- 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/container/xnamecontainer.hxx>
+
+#include <com/sun/star/container/ElementExistException.hpp>
+#include <com/sun/star/container/NoSuchElementException.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace css;
+
+namespace apitest
+{
+void XNameContainer::testInsertByName()
+{
+ uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName + "Insert"));
+ xNameContainer->insertByName(m_aName + "Insert", m_aElement);
+ CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName + "Insert"));
+}
+
+void XNameContainer::testInsertByNameEmptyName()
+{
+ uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
+
+ uno::Any aAny;
+ CPPUNIT_ASSERT_THROW(xNameContainer->insertByName("", aAny), lang::IllegalArgumentException);
+}
+
+void XNameContainer::testInsertByNameInvalidElement()
+{
+ uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
+
+ // TODO: Find a way to create an invalid element.
+ // CPPUNIT_ASSERT_THROW(xNameContainer->insertByName("Dummy", nullptr),
+ // lang::IllegalArgumentException);
+}
+
+void XNameContainer::testInsertByNameDuplicate()
+{
+ uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName + "Duplicate"));
+ xNameContainer->insertByName(m_aName + "Duplicate", m_aElement);
+ CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName + "Duplicate"));
+
+ bool bExceptionThrown = false;
+ try
+ {
+ xNameContainer->insertByName(m_aName + "Duplicate", m_aElement);
+ }
+ catch (const container::ElementExistException&)
+ {
+ bExceptionThrown = true;
+ }
+ catch (const lang::IllegalArgumentException&)
+ {
+ bExceptionThrown = true;
+ }
+ CPPUNIT_ASSERT(bExceptionThrown);
+}
+
+void XNameContainer::testRemoveByName()
+{
+ uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName));
+ xNameContainer->removeByName(m_aName);
+ CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName));
+}
+
+void XNameContainer::testRemoveByNameEmptyName()
+{
+ uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT_THROW(xNameContainer->removeByName(""), lang::IllegalArgumentException);
+}
+
+void XNameContainer::testRemoveByNameNoneExistingElement()
+{
+ uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT_THROW(xNameContainer->removeByName("UnitTest"),
+ container::NoSuchElementException);
+}
+
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/test/source/container/xnamed.cxx b/test/source/container/xnamed.cxx
new file mode 100644
index 000000000..000a9f62e
--- /dev/null
+++ b/test/source/container/xnamed.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 <test/container/xnamed.hxx>
+#include <rtl/ustring.hxx>
+
+#include <com/sun/star/container/XNamed.hpp>
+#include <com/sun/star/uno/RuntimeException.hpp>
+
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace css;
+using namespace css::uno;
+
+namespace apitest
+{
+void XNamed::testGetName()
+{
+ uno::Reference<container::XNamed> xNamed(init(), UNO_QUERY_THROW);
+ CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName());
+}
+
+void XNamed::testSetName()
+{
+ uno::Reference<container::XNamed> xNamed(init(), UNO_QUERY_THROW);
+ OUString aTestName("NewName");
+
+ xNamed->setName(aTestName);
+ CPPUNIT_ASSERT_EQUAL(aTestName, xNamed->getName());
+
+ // restore old name
+ xNamed->setName(m_aTestName);
+ CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName());
+}
+
+void XNamed::testSetNameByScSheetLinkObj()
+{
+ uno::Reference<container::XNamed> xNamed(init(), uno::UNO_QUERY_THROW);
+ OUString aTestName(m_aTestName.replaceAll("ScSheetLinkObj", "NewScSheetLinkObj"));
+
+ xNamed->setName(aTestName);
+ CPPUNIT_ASSERT_EQUAL(aTestName, xNamed->getName());
+
+ // restore old name
+ xNamed->setName(m_aTestName);
+ CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName());
+}
+
+void XNamed::testSetNameThrowsException()
+{
+ uno::Reference<container::XNamed> xNamed(init(), uno::UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT_THROW(xNamed->setName("NewName"), uno::RuntimeException);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/source/container/xnamereplace.cxx b/test/source/container/xnamereplace.cxx
new file mode 100644
index 000000000..2475cb5a0
--- /dev/null
+++ b/test/source/container/xnamereplace.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/container/xnamereplace.hxx>
+
+#include <com/sun/star/container/XNameReplace.hpp>
+
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+
+#include <cppunit/TestAssert.h>
+
+using namespace css;
+
+namespace apitest
+{
+void XNameReplace::testReplaceByName()
+{
+ uno::Reference<container::XNameReplace> xNameReplace(init(), uno::UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT_NO_THROW(xNameReplace->replaceByName(m_aReplacementName, m_aReplacementElement));
+ uno::Any aAny = xNameReplace->getByName(m_aReplacementName);
+
+ // we deliberately avoid uno::UNO_QUERY_THROW, so a test on .is() can be made
+ uno::Reference<uno::XInterface> xElement(aAny, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xElement.is());
+}
+
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */