[Libreoffice-commits] core.git: include/test sc/qa test/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Feb 27 08:40:06 UTC 2019
include/test/container/xnamecontainer.hxx | 43 ++++++++++----
sc/qa/extras/scdatapilotfieldgroupsobj.cxx | 12 +++-
test/source/container/xnamecontainer.cxx | 87 +++++++++++++++++++++--------
3 files changed, 104 insertions(+), 38 deletions(-)
New commits:
commit 4b98337699e5e59a543d95c73ea7c64b3d9a1caf
Author: Jens Carl <j.carl43 at gmx.de>
AuthorDate: Tue Feb 26 21:43:29 2019 +0000
Commit: Jens Carl <j.carl43 at gmx.de>
CommitDate: Wed Feb 27 09:39:42 2019 +0100
Add missing XNameContainer tests to ScDataPilotFieldGroupsObj
Change-Id: Ia59b2a6136e2e56bf6c43a84e3cb6268471278a5
Reviewed-on: https://gerrit.libreoffice.org/68410
Tested-by: Jenkins
Reviewed-by: Jens Carl <j.carl43 at gmx.de>
diff --git a/include/test/container/xnamecontainer.hxx b/include/test/container/xnamecontainer.hxx
index 9ff614473795..6c0b24d20e0d 100644
--- a/include/test/container/xnamecontainer.hxx
+++ b/include/test/container/xnamecontainer.hxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -11,31 +11,50 @@
#define INCLUDED_TEST_CONTAINER_XNAMECONTAINER_HXX
#include <rtl/ustring.hxx>
-#include <com/sun/star/uno/Reference.hxx>
#include <test/testdllapi.hxx>
-namespace apitest {
+#include <com/sun/star/uno/XInterface.hpp>
+
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+namespace apitest
+{
class OOO_DLLPUBLIC_TEST XNameContainer
{
public:
// removes default entry
- XNameContainer();
+ XNameContainer()
+ : m_aName("XNameContainer")
+ {
+ }
// removes given entry
- XNameContainer(const OUString& rName);
-
- virtual css::uno::Reference< css::uno::XInterface > init() = 0;
-
+ XNameContainer(const OUString& rNameToRemove)
+ : m_aName(rNameToRemove)
+ {
+ }
+
+ virtual css::uno::Reference<css::uno::XInterface> init() = 0;
+ virtual void setElement(const css::uno::Any& rElement) { m_aElement = rElement; }
+
+ void testInsertByName();
+ void testInsertByNameEmptyName();
+ void testInsertByNameDuplicate();
+ void testInsertByNameInvalidElement();
void testRemoveByName();
+ void testRemoveByNameEmptyName();
+ void testRemoveByNameNoneExistingElement();
- virtual ~XNameContainer() {}
+protected:
+ ~XNameContainer() {}
private:
- OUString const maNameToRemove;
+ OUString const m_aName;
+ css::uno::Any m_aElement;
};
-}
+} // namespace apitest
#endif // INCLUDED_TEST_CONTAINER_XNAMECONTAINER_HXX
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sc/qa/extras/scdatapilotfieldgroupsobj.cxx b/sc/qa/extras/scdatapilotfieldgroupsobj.cxx
index 228075df34fd..9a9fdcb7e102 100644
--- a/sc/qa/extras/scdatapilotfieldgroupsobj.cxx
+++ b/sc/qa/extras/scdatapilotfieldgroupsobj.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -80,7 +80,11 @@ public:
CPPUNIT_TEST(testHasByName);
// XNameContainer
+ CPPUNIT_TEST(testInsertByName);
+ CPPUNIT_TEST(testInsertByNameEmptyName);
CPPUNIT_TEST(testRemoveByName);
+ CPPUNIT_TEST(testRemoveByNameEmptyName);
+ CPPUNIT_TEST(testRemoveByNameNoneExistingElement);
// XServiceInfo
CPPUNIT_TEST(testGetImplementationName);
@@ -199,6 +203,10 @@ uno::Reference<uno::XInterface> ScDataPilotFieldGroupItemObj::init()
}
}
+ // set element for testing XNameContainer::insertByName()
+ uno::Any aElement;
+ setElement(aElement);
+
return aDPFGI.Groups;
}
@@ -221,4 +229,4 @@ CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupItemObj);
CPPUNIT_PLUGIN_IMPLEMENT();
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+/* 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
index fefc5d35530e..c871debaecce 100644
--- a/test/source/container/xnamecontainer.cxx
+++ b/test/source/container/xnamecontainer.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -8,47 +8,86 @@
*/
#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/sheet/XSpreadsheetDocument.hpp>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Reference.hxx>
+
#include <cppunit/extensions/HelperMacros.h>
+
#include <iostream>
using namespace css;
-using namespace css::uno;
-namespace apitest {
+namespace apitest
+{
+void XNameContainer::testInsertByName()
+{
+ uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
-XNameContainer::XNameContainer(): maNameToRemove("XNameContainer")
+ 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);
}
-XNameContainer::XNameContainer(const OUString& rNameToRemove):
- maNameToRemove(rNameToRemove)
+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);
+
+ uno::Any aAny;
+ CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName));
+ xNameContainer->insertByName(m_aName, aAny);
+ CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName));
+
+ CPPUNIT_ASSERT_THROW(xNameContainer->insertByName(m_aName, aAny),
+ container::ElementExistException);
}
void XNameContainer::testRemoveByName()
{
- uno::Reference< container::XNameContainer > xNameContainer(init(),UNO_QUERY_THROW);
- CPPUNIT_ASSERT(xNameContainer->hasByName(maNameToRemove));
- xNameContainer->removeByName(maNameToRemove);
- CPPUNIT_ASSERT(!xNameContainer->hasByName(maNameToRemove));
-
- bool bExceptionThrown = false;
- try
- {
- xNameContainer->removeByName(maNameToRemove);
- }
- catch( const container::NoSuchElementException& )
- {
- std::cout << "Exception Caught" << std::endl;
- bExceptionThrown = true;
- }
-
- CPPUNIT_ASSERT_MESSAGE("no exception thrown", bExceptionThrown);
+ 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);
}
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+} // namespace apitest
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
More information about the Libreoffice-commits
mailing list