bump product version to 7.2.5.1
[LibreOffice.git] / xmloff / qa / unit / tokenmap-test.cxx
blob476416fc39330059d8999d6013997cdd395a9594
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 std;
20 using namespace com::sun::star::uno;
22 namespace xmloff {
24 class TokenmapTest: public CppUnit::TestFixture
26 public:
28 TokenmapTest();
30 void test_roundTrip();
31 void test_listEquality();
33 CPPUNIT_TEST_SUITE(TokenmapTest);
35 CPPUNIT_TEST(test_roundTrip);
36 CPPUNIT_TEST(test_listEquality);
38 CPPUNIT_TEST_SUITE_END();
40 private:
41 std::unique_ptr<token::TokenMap> pTokenMap;
44 TokenmapTest::TokenmapTest() : pTokenMap(new token::TokenMap)
48 void TokenmapTest::test_roundTrip()
50 for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken )
52 // check that the getIdentifier <-> getToken roundtrip works
53 Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken);
54 CPPUNIT_ASSERT_MESSAGE("Token name sequence should not be empty", rUtf8Name.getLength());
55 const char* pChar = reinterpret_cast< const char * >(rUtf8Name.getConstArray());
56 CPPUNIT_ASSERT_MESSAGE("Token name sequence array pointer failed", pChar);
57 sal_Int32 ret = token::TokenMap::getTokenFromUTF8( pChar, rUtf8Name.getLength() );
58 CPPUNIT_ASSERT_EQUAL_MESSAGE("No roundtrip for token", ret, nToken);
62 void TokenmapTest::test_listEquality()
64 //make sure the two token lists stay in sync
65 // This depends on same order in three places: XMLTokenEnum in include/xmloff/xmltoken.hxx,
66 // aTokenList in xmloff/source/core/xmltoken.cxx, and xmloff/source/token/tokens.txt
67 for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken )
69 Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken);
70 const OUString& rName = OUString( reinterpret_cast< const char* >(
71 rUtf8Name.getConstArray() ), rUtf8Name.getLength(), RTL_TEXTENCODING_UTF8 );
72 if ( rName.endsWith("_DUMMY") )
73 continue;
74 const OUString& rTokenName = GetXMLToken( static_cast<xmloff::token::XMLTokenEnum>(nToken) );
75 CPPUNIT_ASSERT_EQUAL(rName, rTokenName);
78 for ( sal_Int32 nToken = xmloff::token::XMLTokenEnum::XML_TOKEN_START + 1;
79 nToken < xmloff::token::XMLTokenEnum::XML_TOKEN_END; ++nToken )
81 const OUString& rTokenName = GetXMLToken( static_cast<xmloff::token::XMLTokenEnum>(nToken) );
82 Sequence< sal_Int8 > rUtf8Name = pTokenMap->getUtf8TokenName(nToken);
83 const OUString& rName = OUString( reinterpret_cast< const char* >(
84 rUtf8Name.getConstArray() ), rUtf8Name.getLength(), RTL_TEXTENCODING_UTF8 );
85 if ( !rName.endsWith("_DUMMY") )
86 CPPUNIT_ASSERT_EQUAL(rTokenName, rName);
90 CPPUNIT_TEST_SUITE_REGISTRATION(TokenmapTest);