[Libreoffice-commits] core.git: oox/CppunitTest_oox_tokenmap.mk oox/Module_oox.mk oox/qa oox/source

David Ostrovsky david at ostrovsky.org
Mon Sep 22 23:08:32 PDT 2014


 oox/CppunitTest_oox_tokenmap.mk |   66 ++++++++++++++++++++++++++++++++++++++++
 oox/Module_oox.mk               |    4 ++
 oox/qa/token/tokenmap-test.cxx  |   54 ++++++++++++++++++++++++++++++++
 oox/source/token/tokenmap.cxx   |   14 --------
 4 files changed, 124 insertions(+), 14 deletions(-)

New commits:
commit b529efc45962cd451198df273f41fc69f16ac1a6
Author: David Ostrovsky <david at ostrovsky.org>
Date:   Sat Sep 20 16:57:13 2014 +0200

    Add unit test for oox::TokenMap
    
    Change-Id: Iced083868a84fd9fbb97ad91dfc0acbf5b69b766
    Reviewed-on: https://gerrit.libreoffice.org/11559
    Reviewed-by: David Ostrovsky <David.Ostrovsky at gmx.de>
    Tested-by: David Ostrovsky <David.Ostrovsky at gmx.de>

diff --git a/oox/CppunitTest_oox_tokenmap.mk b/oox/CppunitTest_oox_tokenmap.mk
new file mode 100644
index 0000000..9eac2a5
--- /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 8f4b302..361054d 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 0000000..1ebbb01
--- /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 2989a34..327dab0 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(


More information about the Libreoffice-commits mailing list