Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / xmloff / qa / unit / tokenmap-test.cxx
blob395237b8adb17b0ee2661ed512a36cc3b50e79a4
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 <memory>
11 #include <cppunit/TestAssert.h>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
15 #include <fasttokenhandler.hxx>
16 #include <xmloff/token/tokens.hxx>
17 #include <xmloff/xmltoken.hxx>
19 using namespace com::sun::star::uno;
21 namespace xmloff {
23 class TokenmapTest: public CppUnit::TestFixture
25 public:
27 TokenmapTest();
29 void test_roundTrip();
30 void test_listEquality();
32 CPPUNIT_TEST_SUITE(TokenmapTest);
34 CPPUNIT_TEST(test_roundTrip);
35 CPPUNIT_TEST(test_listEquality);
37 CPPUNIT_TEST_SUITE_END();
39 private:
40 std::unique_ptr<token::TokenMap> pTokenMap;
43 TokenmapTest::TokenmapTest() : pTokenMap(new token::TokenMap)
47 void TokenmapTest::test_roundTrip()
49 for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken )
51 // check that the getIdentifier <-> getToken roundtrip works
52 Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken);
53 CPPUNIT_ASSERT_MESSAGE("Token name sequence should not be empty", rUtf8Name.getLength());
54 const char* pChar = reinterpret_cast< const char * >(rUtf8Name.getConstArray());
55 CPPUNIT_ASSERT_MESSAGE("Token name sequence array pointer failed", pChar);
56 sal_Int32 ret = token::TokenMap::getTokenFromUTF8( pChar, rUtf8Name.getLength() );
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("No roundtrip for token", ret, nToken);
61 void TokenmapTest::test_listEquality()
63 //make sure the two token lists stay in sync
64 // This depends on same order in three places: XMLTokenEnum in include/xmloff/xmltoken.hxx,
65 // aTokenList in xmloff/source/core/xmltoken.cxx, and xmloff/source/token/tokens.txt
66 for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken )
68 Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken);
69 const OUString& rName = OUString( reinterpret_cast< const char* >(
70 rUtf8Name.getConstArray() ), rUtf8Name.getLength(), RTL_TEXTENCODING_UTF8 );
71 if ( rName.endsWith("_DUMMY") )
72 continue;
73 const OUString& rTokenName = GetXMLToken( static_cast<xmloff::token::XMLTokenEnum>(nToken) );
74 CPPUNIT_ASSERT_EQUAL(rName, rTokenName);
77 for ( sal_Int32 nToken = xmloff::token::XMLTokenEnum::XML_TOKEN_START + 1;
78 nToken < xmloff::token::XMLTokenEnum::XML_TOKEN_END; ++nToken )
80 const OUString& rTokenName = GetXMLToken( static_cast<xmloff::token::XMLTokenEnum>(nToken) );
81 Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken);
82 const OUString& rName = OUString( reinterpret_cast< const char* >(
83 rUtf8Name.getConstArray() ), rUtf8Name.getLength(), RTL_TEXTENCODING_UTF8 );
84 if ( !rName.endsWith("_DUMMY") )
85 CPPUNIT_ASSERT_EQUAL(rTokenName, rName);
89 CPPUNIT_TEST_SUITE_REGISTRATION(TokenmapTest);