Bump version to 5.0-14
[LibreOffice.git] / sax / qa / cppunit / attributes.cxx
bloba573f9ddb4b62e652bdfee09ae1b0d04605abe72
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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>
18 using namespace css;
19 using namespace css::xml;
21 namespace {
23 class AttributesTest: public CppUnit::TestFixture
25 bool mbException;
27 public:
28 void test();
30 CPPUNIT_TEST_SUITE( AttributesTest );
31 CPPUNIT_TEST( test );
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") );
54 mbException = false;
56 try { aAttributeList.getValue(3); }
57 catch (const sax::SAXException& )
59 mbException = true;
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: */