Kaydet (Commit) 4b983376 authored tarafından Jens Carl's avatar Jens Carl

Add missing XNameContainer tests to ScDataPilotFieldGroupsObj

Change-Id: Ia59b2a6136e2e56bf6c43a84e3cb6268471278a5
Reviewed-on: https://gerrit.libreoffice.org/68410
Tested-by: Jenkins
Reviewed-by: 's avatarJens Carl <j.carl43@gmx.de>
üst 48dc1e48
/* -*- 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. * This file is part of the LibreOffice project.
* *
...@@ -11,31 +11,50 @@ ...@@ -11,31 +11,50 @@
#define INCLUDED_TEST_CONTAINER_XNAMECONTAINER_HXX #define INCLUDED_TEST_CONTAINER_XNAMECONTAINER_HXX
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <test/testdllapi.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 class OOO_DLLPUBLIC_TEST XNameContainer
{ {
public: public:
// removes default entry // removes default entry
XNameContainer(); XNameContainer()
: m_aName("XNameContainer")
{
}
// removes given entry // removes given entry
XNameContainer(const OUString& rName); XNameContainer(const OUString& rNameToRemove)
: m_aName(rNameToRemove)
virtual css::uno::Reference< css::uno::XInterface > init() = 0; {
}
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 testRemoveByName();
void testRemoveByNameEmptyName();
void testRemoveByNameNoneExistingElement();
virtual ~XNameContainer() {} protected:
~XNameContainer() {}
private: private:
OUString const maNameToRemove; OUString const m_aName;
css::uno::Any m_aElement;
}; };
} } // namespace apitest
#endif // INCLUDED_TEST_CONTAINER_XNAMECONTAINER_HXX #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: */
/* -*- 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. * This file is part of the LibreOffice project.
* *
...@@ -80,7 +80,11 @@ public: ...@@ -80,7 +80,11 @@ public:
CPPUNIT_TEST(testHasByName); CPPUNIT_TEST(testHasByName);
// XNameContainer // XNameContainer
CPPUNIT_TEST(testInsertByName);
CPPUNIT_TEST(testInsertByNameEmptyName);
CPPUNIT_TEST(testRemoveByName); CPPUNIT_TEST(testRemoveByName);
CPPUNIT_TEST(testRemoveByNameEmptyName);
CPPUNIT_TEST(testRemoveByNameNoneExistingElement);
// XServiceInfo // XServiceInfo
CPPUNIT_TEST(testGetImplementationName); CPPUNIT_TEST(testGetImplementationName);
...@@ -199,6 +203,10 @@ uno::Reference<uno::XInterface> ScDataPilotFieldGroupItemObj::init() ...@@ -199,6 +203,10 @@ uno::Reference<uno::XInterface> ScDataPilotFieldGroupItemObj::init()
} }
} }
// set element for testing XNameContainer::insertByName()
uno::Any aElement;
setElement(aElement);
return aDPFGI.Groups; return aDPFGI.Groups;
} }
...@@ -221,4 +229,4 @@ CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupItemObj); ...@@ -221,4 +229,4 @@ CPPUNIT_TEST_SUITE_REGISTRATION(ScDataPilotFieldGroupItemObj);
CPPUNIT_PLUGIN_IMPLEMENT(); 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: */
/* -*- 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. * This file is part of the LibreOffice project.
* *
...@@ -8,47 +8,86 @@ ...@@ -8,47 +8,86 @@
*/ */
#include <test/container/xnamecontainer.hxx> #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/container/XNameContainer.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.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 <cppunit/extensions/HelperMacros.h>
#include <iostream> #include <iostream>
using namespace css; 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): void XNameContainer::testInsertByNameInvalidElement()
maNameToRemove(rNameToRemove)
{ {
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() void XNameContainer::testRemoveByName()
{ {
uno::Reference< container::XNameContainer > xNameContainer(init(),UNO_QUERY_THROW); uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT(xNameContainer->hasByName(maNameToRemove)); CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName));
xNameContainer->removeByName(maNameToRemove); xNameContainer->removeByName(m_aName);
CPPUNIT_ASSERT(!xNameContainer->hasByName(maNameToRemove)); CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName));
}
bool bExceptionThrown = false;
try void XNameContainer::testRemoveByNameEmptyName()
{ {
xNameContainer->removeByName(maNameToRemove); uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
}
catch( const container::NoSuchElementException& ) CPPUNIT_ASSERT_THROW(xNameContainer->removeByName(""), lang::IllegalArgumentException);
{
std::cout << "Exception Caught" << std::endl;
bExceptionThrown = true;
}
CPPUNIT_ASSERT_MESSAGE("no exception thrown", bExceptionThrown);
} }
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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment