diff options
author | David Ostrovsky <david@ostrovsky.org> | 2014-09-20 16:57:13 +0200 |
---|---|---|
committer | David Ostrovsky <David.Ostrovsky@gmx.de> | 2014-09-23 06:08:01 +0000 |
commit | b529efc45962cd451198df273f41fc69f16ac1a6 (patch) | |
tree | 7c1052f56eabed8ce7f9498cc13a64a2b7fd7e2a /oox | |
parent | c5464f127d4d4707a5f92281c480266fd3f1b361 (diff) |
Add unit test for oox::TokenMap
Change-Id: Iced083868a84fd9fbb97ad91dfc0acbf5b69b766
Reviewed-on: https://gerrit.libreoffice.org/11559
Reviewed-by: David Ostrovsky <David.Ostrovsky@gmx.de>
Tested-by: David Ostrovsky <David.Ostrovsky@gmx.de>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/CppunitTest_oox_tokenmap.mk | 66 | ||||
-rw-r--r-- | oox/Module_oox.mk | 4 | ||||
-rw-r--r-- | oox/qa/token/tokenmap-test.cxx | 54 | ||||
-rw-r--r-- | oox/source/token/tokenmap.cxx | 14 |
4 files changed, 124 insertions, 14 deletions
diff --git a/oox/CppunitTest_oox_tokenmap.mk b/oox/CppunitTest_oox_tokenmap.mk new file mode 100644 index 000000000000..9eac2a544bff --- /dev/null +++ b/oox/CppunitTest_oox_tokenmap.mk @@ -0,0 +1,66 @@ +# -*- 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: diff --git a/oox/Module_oox.mk b/oox/Module_oox.mk index 8f4b3025476e..361054da884e 100644 --- a/oox/Module_oox.mk +++ b/oox/Module_oox.mk @@ -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: diff --git a/oox/qa/token/tokenmap-test.cxx b/oox/qa/token/tokenmap-test.cxx new file mode 100644 index 000000000000..1ebbb01474c7 --- /dev/null +++ b/oox/qa/token/tokenmap-test.cxx @@ -0,0 +1,54 @@ +/* -*- 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(); diff --git a/oox/source/token/tokenmap.cxx b/oox/source/token/tokenmap.cxx index 2989a343be92..327dab0c9af6 100644 --- a/oox/source/token/tokenmap.cxx +++ b/oox/source/token/tokenmap.cxx @@ -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( |