diff options
author | Chris Laplante <mostthingsweb@gmail.com> | 2014-04-06 22:20:15 -0400 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-04-09 10:23:27 +0000 |
commit | d8802562be87fabbbe7502c2daf39b00aa17f5d0 (patch) | |
tree | c60e685af82d7dc5adce1e18e0c245ff0b5d255f /sw | |
parent | 9c51f5b80640034097457de9603f4ffa021e42ff (diff) |
Fix and deduplicate the test code in SwStyleNameMapper::getHashTable.
The original test code didn't work because the same pool (GET_POOLID_TXTCOLL)
was being used for every test ID.
To cut down on duplication, I refactored the test code and
created 'testNameTable', a protected method of SwStyleNameMapper.
Change-Id: I8a28f136df2650ec2d246f10a8698e8f462c9973
Reviewed-on: https://gerrit.libreoffice.org/8877
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/SwStyleNameMapper.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/doc/SwStyleNameMapper.cxx | 173 |
2 files changed, 32 insertions, 142 deletions
diff --git a/sw/inc/SwStyleNameMapper.hxx b/sw/inc/SwStyleNameMapper.hxx index d80694271f5b..44569cadd144 100644 --- a/sw/inc/SwStyleNameMapper.hxx +++ b/sw/inc/SwStyleNameMapper.hxx @@ -124,6 +124,7 @@ protected: static const OUString& getNameFromId(sal_uInt16 nId, const OUString &rName, bool bProgName); static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, bool bProgName ); + static void testNameTable( SwGetPoolIdFromName const nFamily, sal_uInt16 const nStartIndex, sal_uInt16 const nEndIndex ); public: // This gets the UI Name from the programmatic name diff --git a/sw/source/core/doc/SwStyleNameMapper.cxx b/sw/source/core/doc/SwStyleNameMapper.cxx index 9de494d77b14..e6807d8e59b7 100644 --- a/sw/source/core/doc/SwStyleNameMapper.cxx +++ b/sw/source/core/doc/SwStyleNameMapper.cxx @@ -388,7 +388,25 @@ static void lcl_CheckSuffixAndDelete(OUString & rString) rString = rString.copy(0, rString.getLength() - 7); } } +} + +void SwStyleNameMapper::testNameTable( SwGetPoolIdFromName const nFamily, sal_uInt16 const nStartIndex, sal_uInt16 const nEndIndex ) +{ + sal_uInt16 nIndex; + sal_uInt16 nId; + for ( nIndex = 0, nId = nStartIndex ; nId < nEndIndex ; nId++,nIndex++ ) + { + OUString aString, bString; + FillUIName ( nId, aString ); + bString = GetProgName ( nFamily, aString ); + sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nFamily ); + FillProgName ( nNewId, aString ); + bString = GetUIName ( aString, nFamily ); + nNewId = GetPoolIdFromUIName ( aString, nFamily ); + if ( nNewId != nId ) + abort(); + } } const NameToIdHash & SwStyleNameMapper::getHashTable ( SwGetPoolIdFromName eFlags, bool bProgName ) @@ -512,153 +530,24 @@ const NameToIdHash & SwStyleNameMapper::getHashTable ( SwGetPoolIdFromName eFlag } break; } + #ifdef _NEED_TO_DEBUG_MAPPING static bool bTested = false; if ( !bTested ) { bTested = true; - { - for ( sal_uInt16 nIndex = 0, nId = RES_POOLCOLL_TEXT_BEGIN ; nId < RES_POOLCOLL_TEXT_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_LISTS_BEGIN ; nId < RES_POOLCOLL_LISTS_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_EXTRA_BEGIN ; nId < RES_POOLCOLL_EXTRA_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_REGISTER_BEGIN ; nId < RES_POOLCOLL_REGISTER_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_DOC_BEGIN ; nId < RES_POOLCOLL_DOC_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_HTML_BEGIN ; nId < RES_POOLCOLL_HTML_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } - { - for ( sal_uInt16 nIndex = 0, nId = RES_POOLCHR_NORMAL_BEGIN ; nId < RES_POOLCHR_NORMAL_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCHR_HTML_BEGIN ; nId < RES_POOLCHR_HTML_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } - { - for ( sal_uInt16 nIndex=0,nId = RES_POOLFRM_BEGIN ; nId < RES_POOLFRM_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } - { - for ( sal_uInt16 nIndex=0,nId = RES_POOLPAGE_BEGIN ; nId < RES_POOLPAGE_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } - { - for ( sal_uInt16 nIndex=0,nId = RES_POOLNUMRULE_BEGIN ; nId < RES_POOLNUMRULE_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } + + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_TEXT_BEGIN, RES_POOLCOLL_TEXT_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_LISTS_BEGIN, RES_POOLCOLL_LISTS_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_EXTRA_BEGIN, RES_POOLCOLL_EXTRA_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_REGISTER_BEGIN, RES_POOLCOLL_REGISTER_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_DOC_BEGIN, RES_POOLCOLL_DOC_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_HTML_BEGIN, RES_POOLCOLL_HTML_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, RES_POOLCHR_NORMAL_BEGIN, RES_POOLCHR_NORMAL_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, RES_POOLCHR_HTML_BEGIN, RES_POOLCHR_HTML_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_FRMFMT, RES_POOLFRM_BEGIN, RES_POOLFRM_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, RES_POOLPAGE_BEGIN, RES_POOLPAGE_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_NUMRULE, RES_POOLNUMRULE_BEGIN, RES_POOLNUMRULE_END ); } #endif return *pHash; |