1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/types.h>
11 #include <com/sun/star/xml/sax/SAXException.hpp>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
14 #include <cppunit/plugin/TestPlugIn.h>
16 #include <rtl/ref.hxx>
17 #include <sax/fastattribs.hxx>
20 using namespace css::xml
;
24 class AttributesTest
: public CppUnit::TestFixture
29 CPPUNIT_TEST_SUITE( AttributesTest
);
31 CPPUNIT_TEST_SUITE_END();
34 void AttributesTest::test()
36 rtl::Reference
<sax_fastparser::FastAttributeList
> xAttributeList( new sax_fastparser::FastAttributeList(nullptr) );
37 xAttributeList
->add(1, "1");
38 xAttributeList
->add(2, OString("2"));
40 // We can't test getValueToken() and getOptionalValueToken()
41 // without XFastTokenHandler :-(
42 // Uncomment to get segmentation fault:
43 // xAttributeList->getOptionalValueToken(1, 0);
44 // xAttributeList->getValueToken(2);
46 CPPUNIT_ASSERT( xAttributeList
->hasAttribute(1) );
47 CPPUNIT_ASSERT( !xAttributeList
->hasAttribute(3) );
49 CPPUNIT_ASSERT_EQUAL( OUString("2"), xAttributeList
->getOptionalValue(2) );
50 CPPUNIT_ASSERT_EQUAL( OUString(), xAttributeList
->getOptionalValue(3) );
52 CPPUNIT_ASSERT_EQUAL( OUString("1"), xAttributeList
->getValue(1) );
53 CPPUNIT_ASSERT_THROW( xAttributeList
->getValue(3), xml::sax::SAXException
);
55 xAttributeList
->addUnknown("a", "a");
56 xAttributeList
->addUnknown("b", "b", "b");
57 xAttributeList
->addUnknown("c", "c");
58 CPPUNIT_ASSERT_EQUAL( sal_Int32(3), xAttributeList
->getUnknownAttributes().getLength() );
60 CPPUNIT_ASSERT_EQUAL( sal_Int32(2), xAttributeList
->getFastAttributes().getLength() );
62 xAttributeList
->clear();
63 CPPUNIT_ASSERT( !xAttributeList
->hasAttribute(1) );
64 CPPUNIT_ASSERT( !xAttributeList
->getFastAttributes().hasElements() );
65 xAttributeList
->addUnknown("c", "c");
66 CPPUNIT_ASSERT_EQUAL( sal_Int32(1), xAttributeList
->getUnknownAttributes().getLength() );
69 CPPUNIT_TEST_SUITE_REGISTRATION( AttributesTest
);
73 CPPUNIT_PLUGIN_IMPLEMENT();
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */