Kaydet (Commit) a6c07d2c authored tarafından Katarina Behrens's avatar Katarina Behrens Kaydeden (comit) Caolán McNamara

Use template function to reduce copy'n'pasta code

Change-Id: I22964bfcfb80a3e97903674dbf71a1b7be3a0920
Reviewed-on: https://gerrit.libreoffice.org/16308Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst d5a0cb56
...@@ -71,6 +71,25 @@ ...@@ -71,6 +71,25 @@
#include <config_features.h> #include <config_features.h>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
CPPUNIT_NS_BEGIN
template<> struct assertion_traits<Color>
{
static bool equal( const Color& c1, const Color& c2 )
{
return c1 == c2;
}
static std::string toString( const Color& c )
{
OStringStream ost;
ost << static_cast<unsigned int>(c.GetColor());
return ost.str();
}
};
CPPUNIT_NS_END
using namespace ::com::sun::star; using namespace ::com::sun::star;
class SdExportTest : public SdModelTestBase class SdExportTest : public SdModelTestBase
...@@ -171,8 +190,8 @@ void SdExportTest::testN821567() ...@@ -171,8 +190,8 @@ void SdExportTest::testN821567()
namespace { namespace {
void checkFontAttributes(const SdrTextObj* pObj, sal_uInt32 nColor, template< typename ItemValue, typename ItemType >
bool bCheckWeight, FontWeight eWeight, bool bCheckItalic, FontItalic eItalic) void checkFontAttributes( const SdrTextObj* pObj, ItemValue nVal)
{ {
CPPUNIT_ASSERT_MESSAGE( "no object", pObj != NULL); CPPUNIT_ASSERT_MESSAGE( "no object", pObj != NULL);
const EditTextObject& aEdit = pObj->GetOutlinerParaObject()->GetTextObject(); const EditTextObject& aEdit = pObj->GetOutlinerParaObject()->GetTextObject();
...@@ -180,31 +199,12 @@ void checkFontAttributes(const SdrTextObj* pObj, sal_uInt32 nColor, ...@@ -180,31 +199,12 @@ void checkFontAttributes(const SdrTextObj* pObj, sal_uInt32 nColor,
aEdit.GetCharAttribs(0, rLst); aEdit.GetCharAttribs(0, rLst);
for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it) for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it)
{ {
const SvxColorItem *pCharColor = dynamic_cast<const SvxColorItem *>((*it).pAttr); const ItemType* pAttrib = dynamic_cast<const ItemType *>((*it).pAttr);
if( pCharColor ) if (pAttrib)
{ {
CPPUNIT_ASSERT_EQUAL( nColor, pCharColor->GetValue().GetColor()); CPPUNIT_ASSERT_EQUAL( nVal, (ItemValue)pAttrib->GetValue());
}
if(bCheckWeight)
{
const SvxWeightItem *pWeight = dynamic_cast<const SvxWeightItem *>((*it).pAttr);
if( pWeight )
{
CPPUNIT_ASSERT_EQUAL( eWeight, pWeight->GetWeight());
}
}
if(bCheckItalic)
{
const SvxPostureItem *pPosture = dynamic_cast<const SvxPostureItem *>((*it).pAttr);
if( pPosture )
{
CPPUNIT_ASSERT_EQUAL( eItalic, pPosture->GetPosture());
}
} }
} }
} }
} }
...@@ -224,15 +224,15 @@ void SdExportTest::testBnc870233_1() ...@@ -224,15 +224,15 @@ void SdExportTest::testBnc870233_1()
// First shape has red, bold font // First shape has red, bold font
{ {
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) ); const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) );
checkFontAttributes(pObj, sal_uInt32(0xff0000), checkFontAttributes<Color, SvxColorItem>( pObj, Color(0xff0000) );
true, WEIGHT_BOLD, true, ITALIC_NONE); checkFontAttributes<FontWeight, SvxWeightItem>( pObj, WEIGHT_BOLD );
} }
// Second shape has blue, italic font // Second shape has blue, italic font
{ {
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) ); const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) );
checkFontAttributes(pObj, sal_uInt32(0x0000ff), checkFontAttributes<Color, SvxColorItem>( pObj, Color(0x0000ff) );
true, WEIGHT_NORMAL, true, ITALIC_NORMAL); checkFontAttributes<FontItalic, SvxPostureItem>( pObj, ITALIC_NORMAL );
} }
xDocShRef->DoClose(); xDocShRef->DoClose();
...@@ -253,22 +253,19 @@ void SdExportTest::testBnc870233_2() ...@@ -253,22 +253,19 @@ void SdExportTest::testBnc870233_2()
// First smart art has blue font color (direct formatting) // First smart art has blue font color (direct formatting)
{ {
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) ); const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) );
checkFontAttributes(pObj, sal_uInt32(0x0000ff), checkFontAttributes<Color, SvxColorItem>( pObj, Color(0x0000ff) );
false, WEIGHT_DONTKNOW, false, ITALIC_NONE);
} }
// Second smart art has "dk2" font color (style) // Second smart art has "dk2" font color (style)
{ {
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) ); const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) );
checkFontAttributes(pObj, sal_uInt32(0x1F497D), checkFontAttributes<Color, SvxColorItem>( pObj, Color(0x1F497D) );
false, WEIGHT_DONTKNOW, false, ITALIC_NONE);
} }
// Third smart art has white font color (style) // Third smart art has white font color (style)
{ {
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 2 ) ); const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 2 ) );
checkFontAttributes(pObj, sal_uInt32(0xffffff), checkFontAttributes<Color, SvxColorItem>( pObj, Color(0xffffff) );
false, WEIGHT_DONTKNOW, false, ITALIC_NONE);
} }
xDocShRef->DoClose(); xDocShRef->DoClose();
......
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