nss: upgrade to release 3.73
[LibreOffice.git] / test / source / container / xnamecontainer.cxx
blob5df1e76b3e3c5e22e4e18529ca631e3497e5ea8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <test/container/xnamecontainer.hxx>
12 #include <com/sun/star/container/ElementExistException.hpp>
13 #include <com/sun/star/container/NoSuchElementException.hpp>
14 #include <com/sun/star/container/XNameContainer.hpp>
15 #include <com/sun/star/lang/IllegalArgumentException.hpp>
17 #include <com/sun/star/uno/Any.hxx>
18 #include <com/sun/star/uno/Reference.hxx>
20 #include <cppunit/TestAssert.h>
22 using namespace css;
24 namespace apitest
26 void XNameContainer::testInsertByName()
28 uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
30 CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName + "Insert"));
31 xNameContainer->insertByName(m_aName + "Insert", m_aElement);
32 CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName + "Insert"));
35 void XNameContainer::testInsertByNameEmptyName()
37 uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
39 uno::Any aAny;
40 CPPUNIT_ASSERT_THROW(xNameContainer->insertByName("", aAny), lang::IllegalArgumentException);
43 void XNameContainer::testInsertByNameInvalidElement()
45 uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
47 // TODO: Find a way to create an invalid element.
48 // CPPUNIT_ASSERT_THROW(xNameContainer->insertByName("Dummy", nullptr),
49 // lang::IllegalArgumentException);
52 void XNameContainer::testInsertByNameDuplicate()
54 uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
56 CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName + "Duplicate"));
57 xNameContainer->insertByName(m_aName + "Duplicate", m_aElement);
58 CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName + "Duplicate"));
60 bool bExceptionThrown = false;
61 try
63 xNameContainer->insertByName(m_aName + "Duplicate", m_aElement);
65 catch (const container::ElementExistException&)
67 bExceptionThrown = true;
69 catch (const lang::IllegalArgumentException&)
71 bExceptionThrown = true;
73 CPPUNIT_ASSERT(bExceptionThrown);
76 void XNameContainer::testRemoveByName()
78 uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
79 CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName));
80 xNameContainer->removeByName(m_aName);
81 CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName));
84 void XNameContainer::testRemoveByNameEmptyName()
86 uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
88 CPPUNIT_ASSERT_THROW(xNameContainer->removeByName(""), lang::IllegalArgumentException);
91 void XNameContainer::testRemoveByNameNoneExistingElement()
93 uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW);
95 CPPUNIT_ASSERT_THROW(xNameContainer->removeByName("UnitTest"),
96 container::NoSuchElementException);
99 } // namespace apitest
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */