tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / qa / unit / tokenmap-test.cxx
blobfd2b7cc08de9df4b42ed6053b50d8c57d50cf9dd
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:
26 void test_roundTrip();
27 void test_listEquality();
29 CPPUNIT_TEST_SUITE(TokenmapTest);
31 CPPUNIT_TEST(test_roundTrip);
32 CPPUNIT_TEST(test_listEquality);
34 CPPUNIT_TEST_SUITE_END();
37 void TokenmapTest::test_roundTrip()
39 for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken )
41 // check that the getIdentifier <-> getToken roundtrip works
42 Sequence< sal_Int8 > rUtf8Name = token::TokenMap::getUtf8TokenName(nToken);
43 CPPUNIT_ASSERT_MESSAGE("Token name sequence should not be empty", rUtf8Name.getLength());
44 const char* pChar = reinterpret_cast< const char * >(rUtf8Name.getConstArray());
45 CPPUNIT_ASSERT_MESSAGE("Token name sequence array pointer failed", pChar);
46 sal_Int32 ret = token::TokenMap::getTokenFromUtf8( std::string_view(pChar, rUtf8Name.getLength()) );
47 CPPUNIT_ASSERT_EQUAL_MESSAGE("No roundtrip for token", ret, nToken);
51 void TokenmapTest::test_listEquality()
53 //make sure the two token lists stay in sync
54 // This depends on same order in three places: XMLTokenEnum in include/xmloff/xmltoken.hxx,
55 // aTokenList in xmloff/source/core/xmltoken.cxx, and xmloff/source/token/tokens.txt
56 for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken )
58 Sequence<sal_Int8> rUtf8Name = token::TokenMap::getUtf8TokenName(nToken);
59 const OUString aName( reinterpret_cast< const char* >(
60 rUtf8Name.getConstArray() ), rUtf8Name.getLength(), RTL_TEXTENCODING_UTF8 );
61 if ( aName.endsWith("_DUMMY") )
62 continue;
63 const OUString& rTokenName = GetXMLToken( static_cast<xmloff::token::XMLTokenEnum>(nToken) );
64 CPPUNIT_ASSERT_EQUAL(aName, rTokenName);
67 for ( sal_Int32 nToken = xmloff::token::XMLTokenEnum::XML_TOKEN_START + 1;
68 nToken < xmloff::token::XMLTokenEnum::XML_TOKEN_END; ++nToken )
70 const OUString& rTokenName = GetXMLToken( static_cast<xmloff::token::XMLTokenEnum>(nToken) );
71 Sequence<sal_Int8> rUtf8Name = token::TokenMap::getUtf8TokenName(nToken);
72 const OUString aName( reinterpret_cast< const char* >(
73 rUtf8Name.getConstArray() ), rUtf8Name.getLength(), RTL_TEXTENCODING_UTF8 );
74 if ( !aName.endsWith("_DUMMY") )
75 CPPUNIT_ASSERT_EQUAL(rTokenName, aName);
79 CPPUNIT_TEST_SUITE_REGISTRATION(TokenmapTest);