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>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
14 #include <cppunit/plugin/TestPlugIn.h>
16 #include <sax/fastattribs.hxx>
19 using namespace css::xml
;
23 class AttributesTest
: public CppUnit::TestFixture
30 CPPUNIT_TEST_SUITE( AttributesTest
);
32 CPPUNIT_TEST_SUITE_END();
35 void AttributesTest::test()
37 sax_fastparser::FastAttributeList
aAttributeList( NULL
);
38 aAttributeList
.add(1, "1");
39 aAttributeList
.add(2, OString("2"));
41 // We can't test getValueToken() and getOptionalValueToken()
42 // without XFastTokenHandler :-(
43 // Uncomment to get segmantation fault:
44 // aAttributeList.getOptionalValueToken(1, 0);
45 // aAttributeList.getValueToken(2);
47 CPPUNIT_ASSERT( aAttributeList
.hasAttribute(1) );
48 CPPUNIT_ASSERT( !aAttributeList
.hasAttribute(3) );
50 CPPUNIT_ASSERT_EQUAL( aAttributeList
.getOptionalValue(2), OUString("2") );
51 CPPUNIT_ASSERT_EQUAL( aAttributeList
.getOptionalValue(3), OUString() );
53 CPPUNIT_ASSERT_EQUAL( aAttributeList
.getValue(1), OUString("1") );
56 try { aAttributeList
.getValue(3); }
57 catch (const sax::SAXException
& )
61 CPPUNIT_ASSERT( mbException
);
63 aAttributeList
.addUnknown("a", "a");
64 aAttributeList
.addUnknown("b", "b", "b");
65 aAttributeList
.addUnknown("c", "c");
66 CPPUNIT_ASSERT_EQUAL( (sal_Int32
) 3, aAttributeList
.getUnknownAttributes().getLength() );
68 CPPUNIT_ASSERT_EQUAL( (sal_Int32
) 2, aAttributeList
.getFastAttributes().getLength() );
70 aAttributeList
.clear();
71 CPPUNIT_ASSERT( !aAttributeList
.hasAttribute(1) );
72 CPPUNIT_ASSERT_EQUAL( (sal_Int32
) 0, aAttributeList
.getFastAttributes().getLength() );
73 aAttributeList
.addUnknown("c", "c");
74 CPPUNIT_ASSERT_EQUAL( (sal_Int32
) 1, aAttributeList
.getUnknownAttributes().getLength() );
77 CPPUNIT_TEST_SUITE_REGISTRATION( AttributesTest
);
81 CPPUNIT_PLUGIN_IMPLEMENT();
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */