summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorKatarina Behrens <Katarina.Behrens@cib.de>2015-06-16 12:20:47 +0200
committerCaolán McNamara <caolanm@redhat.com>2015-06-16 15:48:09 +0000
commita6c07d2c263a39c829385d17cc125bd7d2b01531 (patch)
tree193c6f095090190b6ad3b94255d4d2b472c8c1b0 /sd
parentd5a0cb563bdc538a60938ea421183e4b67c0656f (diff)
Use template function to reduce copy'n'pasta code
Change-Id: I22964bfcfb80a3e97903674dbf71a1b7be3a0920 Reviewed-on: https://gerrit.libreoffice.org/16308 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/qa/unit/export-tests.cxx65
1 files changed, 31 insertions, 34 deletions
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index 3151afb42e87..3f5289815aaa 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -71,6 +71,25 @@
#include <config_features.h>
#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;
class SdExportTest : public SdModelTestBase
@@ -171,8 +190,8 @@ void SdExportTest::testN821567()
namespace {
-void checkFontAttributes(const SdrTextObj* pObj, sal_uInt32 nColor,
- bool bCheckWeight, FontWeight eWeight, bool bCheckItalic, FontItalic eItalic)
+template< typename ItemValue, typename ItemType >
+void checkFontAttributes( const SdrTextObj* pObj, ItemValue nVal)
{
CPPUNIT_ASSERT_MESSAGE( "no object", pObj != NULL);
const EditTextObject& aEdit = pObj->GetOutlinerParaObject()->GetTextObject();
@@ -180,31 +199,12 @@ void checkFontAttributes(const SdrTextObj* pObj, sal_uInt32 nColor,
aEdit.GetCharAttribs(0, rLst);
for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it)
{
- const SvxColorItem *pCharColor = dynamic_cast<const SvxColorItem *>((*it).pAttr);
- if( pCharColor )
+ const ItemType* pAttrib = dynamic_cast<const ItemType *>((*it).pAttr);
+ if (pAttrib)
{
- CPPUNIT_ASSERT_EQUAL( nColor, pCharColor->GetValue().GetColor());
- }
-
- 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());
- }
+ CPPUNIT_ASSERT_EQUAL( nVal, (ItemValue)pAttrib->GetValue());
}
}
-
}
}
@@ -224,15 +224,15 @@ void SdExportTest::testBnc870233_1()
// First shape has red, bold font
{
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) );
- checkFontAttributes(pObj, sal_uInt32(0xff0000),
- true, WEIGHT_BOLD, true, ITALIC_NONE);
+ checkFontAttributes<Color, SvxColorItem>( pObj, Color(0xff0000) );
+ checkFontAttributes<FontWeight, SvxWeightItem>( pObj, WEIGHT_BOLD );
}
// Second shape has blue, italic font
{
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) );
- checkFontAttributes(pObj, sal_uInt32(0x0000ff),
- true, WEIGHT_NORMAL, true, ITALIC_NORMAL);
+ checkFontAttributes<Color, SvxColorItem>( pObj, Color(0x0000ff) );
+ checkFontAttributes<FontItalic, SvxPostureItem>( pObj, ITALIC_NORMAL );
}
xDocShRef->DoClose();
@@ -253,22 +253,19 @@ void SdExportTest::testBnc870233_2()
// First smart art has blue font color (direct formatting)
{
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) );
- checkFontAttributes(pObj, sal_uInt32(0x0000ff),
- false, WEIGHT_DONTKNOW, false, ITALIC_NONE);
+ checkFontAttributes<Color, SvxColorItem>( pObj, Color(0x0000ff) );
}
// Second smart art has "dk2" font color (style)
{
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) );
- checkFontAttributes(pObj, sal_uInt32(0x1F497D),
- false, WEIGHT_DONTKNOW, false, ITALIC_NONE);
+ checkFontAttributes<Color, SvxColorItem>( pObj, Color(0x1F497D) );
}
// Third smart art has white font color (style)
{
const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 2 ) );
- checkFontAttributes(pObj, sal_uInt32(0xffffff),
- false, WEIGHT_DONTKNOW, false, ITALIC_NONE);
+ checkFontAttributes<Color, SvxColorItem>( pObj, Color(0xffffff) );
}
xDocShRef->DoClose();