Kaydet (Commit) b529efc4 authored tarafından David Ostrovsky's avatar David Ostrovsky Kaydeden (comit) David Ostrovsky

Add unit test for oox::TokenMap

Change-Id: Iced083868a84fd9fbb97ad91dfc0acbf5b69b766
Reviewed-on: https://gerrit.libreoffice.org/11559Reviewed-by: 's avatarDavid Ostrovsky <David.Ostrovsky@gmx.de>
Tested-by: 's avatarDavid Ostrovsky <David.Ostrovsky@gmx.de>
üst c5464f12
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_CppunitTest_CppunitTest,oox_tokenmap))
$(eval $(call gb_CppunitTest_add_exception_objects,oox_tokenmap,\
oox/qa/token/tokenmap-test \
))
$(eval $(call gb_CppunitTest_use_custom_headers,oox_tokenmap,oox/generated))
$(eval $(call gb_CppunitTest_use_api,oox_tokenmap,\
offapi \
udkapi \
))
$(eval $(call gb_CppunitTest_use_library_objects,oox_tokenmap,oox))
ifeq ($(TLS),OPENSSL)
$(eval $(call gb_CppunitTest_use_externals,oox_tokenmap,\
openssl \
openssl_headers \
))
else
ifeq ($(TLS),NSS)
$(eval $(call gb_CppunitTest_use_externals,oox_tokenmap,\
plc4 \
nss3 \
))
endif
endif
$(eval $(call gb_CppunitTest_use_libraries,oox_tokenmap,\
basegfx \
comphelper \
cppu \
cppuhelper \
editeng \
expwrap \
drawinglayer \
msfilter \
sal \
i18nlangtag \
sax \
sfx \
svl \
svt \
svx \
svxcore \
sot \
tl \
utl \
vcl \
xo \
xmlscript \
$(gb_UWINAPI) \
))
# vim: set noet sw=4 ts=4:
......@@ -16,4 +16,8 @@ $(eval $(call gb_Module_add_targets,oox,\
Package_generated \
))
$(eval $(call gb_Module_add_check_targets,oox,\
CppunitTest_oox_tokenmap \
))
# vim: set noet sw=4 ts=4:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include "oox/token/tokenmap.hxx"
#include "oox/token/tokens.hxx"
using namespace std;
using namespace com::sun::star::uno;
namespace oox {
class TokenmapTest: public CppUnit::TestFixture
{
public:
void test_roundTrip();
CPPUNIT_TEST_SUITE(TokenmapTest);
CPPUNIT_TEST(test_roundTrip);
CPPUNIT_TEST_SUITE_END();
private:
TokenMap tokenMap;
};
void TokenmapTest::test_roundTrip()
{
for ( sal_Int32 nToken = 0; nToken < XML_TOKEN_COUNT; ++nToken )
{
// check that the getIdentifier <-> getToken roundtrip works
Sequence< sal_Int8 > rUtf8Name = tokenMap.getUtf8TokenName(nToken);
sal_Int32 ret = tokenMap.getTokenFromUTF8(
reinterpret_cast< const char * >(rUtf8Name.getConstArray()),
rUtf8Name.getLength() );
CPPUNIT_ASSERT_EQUAL(ret, nToken);
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(TokenmapTest);
}
CPPUNIT_PLUGIN_IMPLEMENT();
......@@ -62,20 +62,6 @@ TokenMap::TokenMap() :
aIt->maUtf8Name = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUtf8Token.getStr() ), aUtf8Token.getLength() );
}
#if OSL_DEBUG_LEVEL > 0
// check that the perfect_hash is in sync with the token name list
bool bOk = true;
for( sal_Int32 nToken = 0; bOk && (nToken < XML_TOKEN_COUNT); ++nToken )
{
// check that the getIdentifier <-> getToken roundtrip works
OString aUtf8Name = OUStringToOString( maTokenNames[ nToken ].maUniName, RTL_TEXTENCODING_UTF8 );
const struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() );
bOk = pToken && (pToken->nToken == nToken);
OSL_ENSURE( bOk, OStringBuffer( "TokenMap::TokenMap - token list broken, #" ).
append( nToken ).append( ", '" ).append( aUtf8Name ).append( '\'' ).getStr() );
}
#endif
for (unsigned char c = 'a'; c <= 'z'; c++)
{
const struct xmltoken* pToken = Perfect_Hash::in_word_set(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment