Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <sal/types.h>
11 :
12 : #include <cppunit/TestFixture.h>
13 : #include <cppunit/extensions/HelperMacros.h>
14 : #include <cppunit/plugin/TestPlugIn.h>
15 :
16 : #include <sax/fastattribs.hxx>
17 :
18 : using namespace css;
19 : using namespace css::xml;
20 :
21 : namespace {
22 :
23 6 : class AttributesTest: public CppUnit::TestFixture
24 : {
25 : bool mbException;
26 :
27 : public:
28 : void test();
29 :
30 4 : CPPUNIT_TEST_SUITE( AttributesTest );
31 2 : CPPUNIT_TEST( test );
32 4 : CPPUNIT_TEST_SUITE_END();
33 : };
34 :
35 2 : void AttributesTest::test()
36 : {
37 2 : sax_fastparser::FastAttributeList aAttributeList( NULL );
38 2 : aAttributeList.add(1, "1");
39 2 : aAttributeList.add(2, OString("2"));
40 :
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);
46 :
47 2 : CPPUNIT_ASSERT( aAttributeList.hasAttribute(1) );
48 2 : CPPUNIT_ASSERT( !aAttributeList.hasAttribute(3) );
49 :
50 2 : CPPUNIT_ASSERT_EQUAL( aAttributeList.getOptionalValue(2), OUString("2") );
51 2 : CPPUNIT_ASSERT_EQUAL( aAttributeList.getOptionalValue(3), OUString() );
52 :
53 2 : CPPUNIT_ASSERT_EQUAL( aAttributeList.getValue(1), OUString("1") );
54 2 : mbException = false;
55 :
56 2 : try { aAttributeList.getValue(3); }
57 4 : catch (const sax::SAXException& )
58 : {
59 2 : mbException = true;
60 : }
61 2 : CPPUNIT_ASSERT( mbException );
62 :
63 2 : aAttributeList.addUnknown("a", "a");
64 2 : aAttributeList.addUnknown("b", "b", "b");
65 2 : aAttributeList.addUnknown("c", "c");
66 2 : CPPUNIT_ASSERT_EQUAL( (sal_Int32) 3, aAttributeList.getUnknownAttributes().getLength() );
67 :
68 2 : CPPUNIT_ASSERT_EQUAL( (sal_Int32) 2, aAttributeList.getFastAttributes().getLength() );
69 :
70 2 : aAttributeList.clear();
71 2 : CPPUNIT_ASSERT( !aAttributeList.hasAttribute(1) );
72 2 : CPPUNIT_ASSERT_EQUAL( (sal_Int32) 0, aAttributeList.getFastAttributes().getLength() );
73 2 : aAttributeList.addUnknown("c", "c");
74 2 : CPPUNIT_ASSERT_EQUAL( (sal_Int32) 1, aAttributeList.getUnknownAttributes().getLength() );
75 2 : }
76 :
77 2 : CPPUNIT_TEST_SUITE_REGISTRATION( AttributesTest );
78 :
79 : }
80 :
81 8 : CPPUNIT_PLUGIN_IMPLEMENT();
82 :
83 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|