From ea358f5d5b04a2a8e11a73d35643cd0afc5cb63b Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Tue, 13 Aug 2013 18:04:14 +0200 Subject: CharBrd 8.2: Tests for UNO API and ODF filter Use just those API tests which still alive. Export filter test use import so no need for distinct import tests. Change-Id: Idddc2ece10e20027551538f4e8c224edffa9bfe8 --- sw/qa/extras/inc/swmodeltestbase.hxx | 27 +++++ sw/qa/extras/odfexport/data/charborder.odt | Bin 0 -> 8841 bytes sw/qa/extras/odfexport/odfexport.cxx | 176 +++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 sw/qa/extras/odfexport/data/charborder.odt (limited to 'sw/qa/extras') diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx index 38c5a47b01d5..9bd8a46a0cd6 100644 --- a/sw/qa/extras/inc/swmodeltestbase.hxx +++ b/sw/qa/extras/inc/swmodeltestbase.hxx @@ -10,12 +10,15 @@ #include #include #include +#include +#include #include #include #include #include #include #include +#include #include #include @@ -120,6 +123,15 @@ protected: return xStyleFamily; } + /// Get a family of auto styles, see com.sun.star.style.StyleFamilies for possible values. + uno::Reference getAutoStyles(OUString aFamily) + { + uno::Reference< style::XAutoStylesSupplier > xAutoStylesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference< style::XAutoStyles > xAutoStyles(xAutoStylesSupplier->getAutoStyles()); + uno::Reference< style::XAutoStyleFamily > xAutoStyleFamily(xAutoStyles->getByName(aFamily), uno::UNO_QUERY); + return xAutoStyleFamily; + } + /** * Extract a value from the layout dump using an XPath expression and an attribute name. * @@ -326,6 +338,21 @@ protected: return xCursor->getPage(); } + void assertEqualBorder( + const table::BorderLine2& rLeft, const sal_Int32 nLeftDist, + const table::BorderLine2& rRight, const sal_Int32 nRightDist ) + { + // Border + CPPUNIT_ASSERT_EQUAL(rLeft.Color, rRight.Color); + CPPUNIT_ASSERT_EQUAL(rLeft.InnerLineWidth, rRight.InnerLineWidth); + CPPUNIT_ASSERT_EQUAL(rLeft.LineDistance, rRight.LineDistance); + CPPUNIT_ASSERT_EQUAL(rLeft.LineStyle, rRight.LineStyle); + CPPUNIT_ASSERT_EQUAL(rLeft.LineWidth, rRight.LineWidth); + CPPUNIT_ASSERT_EQUAL(rLeft.OuterLineWidth, rRight.OuterLineWidth); + // Padding + CPPUNIT_ASSERT_EQUAL(nLeftDist, nRightDist); + } + uno::Reference mxComponent; xmlBufferPtr mpXmlBuffer; diff --git a/sw/qa/extras/odfexport/data/charborder.odt b/sw/qa/extras/odfexport/data/charborder.odt new file mode 100644 index 000000000000..9f37d58b76c1 Binary files /dev/null and b/sw/qa/extras/odfexport/data/charborder.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index efbd931dcd6e..3fbf196d4c5e 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -19,6 +19,7 @@ public: void testTextframeGradient(); void testFdo60769(); void testFdo58949(); + void testCharacterBorder(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -38,6 +39,7 @@ void Test::run() {"textframe-gradient.odt", &Test::testTextframeGradient}, {"fdo60769.odt", &Test::testFdo60769}, {"fdo58949.docx", &Test::testFdo58949}, + {"charborder.odt", &Test::testCharacterBorder }, }; header(); for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i) @@ -162,6 +164,180 @@ void Test::testFdo58949() CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName("Obj102"))); } +void Test::testCharacterBorder() +{ + // Make sure paragraph and character attributes don't interfere + // First paragraph has a paragraph border and a character border included by the paragraph style + + // Paragraph border of first paragraph + { + const table::BorderLine2 aFirstParTopBorder(6711039,0,26,26,7,53); + const sal_Int32 aFirstParTopPadding(150); + uno::Reference xSet(getParagraph(1), uno::UNO_QUERY); + + // Top border + assertEqualBorder( + aFirstParTopBorder, aFirstParTopPadding, + getProperty(xSet,"TopBorder"), + getProperty(xSet,"TopBorderDistance")); + + // Bottom border (same as top border) + assertEqualBorder( + aFirstParTopBorder, aFirstParTopPadding, + getProperty(xSet,"BottomBorder"), + getProperty(xSet,"BottomBorderDistance")); + + // Left border (same as top border) + assertEqualBorder( + aFirstParTopBorder, aFirstParTopPadding, + getProperty(xSet,"LeftBorder"), + getProperty(xSet,"LeftBorderDistance")); + + // Right border (same as top border) + assertEqualBorder( + aFirstParTopBorder, aFirstParTopPadding, + getProperty(xSet,"RightBorder"), + getProperty(xSet,"RightBorderDistance")); + } + + // Character border for first paragraph + { + const table::BorderLine2 aFirstParCharTopBorder(16724787,0,37,0,2,37); + const sal_Int32 aFirstParCharTopPadding(450); + uno::Reference xSet(getParagraph(1), uno::UNO_QUERY); + + // Top border + assertEqualBorder( + aFirstParCharTopBorder, aFirstParCharTopPadding, + getProperty(xSet,"CharTopBorder"), + getProperty(xSet,"CharTopBorderDistance")); + + // Bottom border (same as top border) + assertEqualBorder( + aFirstParCharTopBorder, aFirstParCharTopPadding, + getProperty(xSet,"CharBottomBorder"), + getProperty(xSet,"CharBottomBorderDistance")); + + // Left border (same as top border) + assertEqualBorder( + aFirstParCharTopBorder, aFirstParCharTopPadding, + getProperty(xSet,"CharLeftBorder"), + getProperty(xSet,"CharLeftBorderDistance")); + + // Right border (same as top border) + assertEqualBorder( + aFirstParCharTopBorder, aFirstParCharTopPadding, + getProperty(xSet,"CharRightBorder"), + getProperty(xSet,"CharRightBorderDistance")); + + // Check autostyle + { + uno::Reference< style::XAutoStyleFamily > xAutoStyleFamily(getAutoStyles("ParagraphStyles")); + uno::Reference < container::XEnumeration > xAutoStylesEnum( xAutoStyleFamily->createEnumeration() ); + CPPUNIT_ASSERT_EQUAL((bool)xAutoStylesEnum->hasMoreElements(), true); + + // First paragraph autostyle + uno::Reference < beans::XPropertySet > xPSet( xAutoStylesEnum->nextElement(), uno::UNO_QUERY ); + + // Top border + assertEqualBorder( + aFirstParCharTopBorder, aFirstParCharTopPadding, + getProperty(xSet,"CharTopBorder"), + getProperty(xSet,"CharTopBorderDistance")); + + // Bottom border + assertEqualBorder( + aFirstParCharTopBorder, aFirstParCharTopPadding, + getProperty(xSet,"CharBottomBorder"), + getProperty(xSet,"CharBottomBorderDistance")); + + // Left border + assertEqualBorder( + aFirstParCharTopBorder, aFirstParCharTopPadding, + getProperty(xSet,"CharLeftBorder"), + getProperty(xSet,"CharLeftBorderDistance")); + + // Right border + assertEqualBorder( + aFirstParCharTopBorder, aFirstParCharTopPadding, + getProperty(xSet,"CharRightBorder"), + getProperty(xSet,"CharRightBorderDistance")); + } + } + + // Second paragraph's second text portion has a character style named CharDiffBor + // This style includes border with different sides + { + + table::BorderLine2 aBorderArray[4] = + { + table::BorderLine2(16724787,26,2,4,13,35), // Top + table::BorderLine2(10092390,26,26,53,11,106), // Bottom + table::BorderLine2(6711039,9,26,9,12,71), // Left + table::BorderLine2(0,0,0,0,0,0) // Right + }; + + sal_Int32 aDistances[4] = { 400 /*Top*/, 300 /*Bottom*/, 250 /*Left*/, 0 /*Right*/ }; + + // Get second text portion of second paragraph + uno::Reference < beans::XPropertySet > xSet( getRun(getParagraph(2),2), uno::UNO_QUERY ); + + // Top border + assertEqualBorder( + aBorderArray[0], aDistances[0], + getProperty(xSet,"CharTopBorder"), + getProperty(xSet,"CharTopBorderDistance")); + + // Bottom border + assertEqualBorder( + aBorderArray[1], aDistances[1], + getProperty(xSet,"CharBottomBorder"), + getProperty(xSet,"CharBottomBorderDistance")); + + // Left border + assertEqualBorder( + aBorderArray[2], aDistances[2], + getProperty(xSet,"CharLeftBorder"), + getProperty(xSet,"CharLeftBorderDistance")); + + // Right border + assertEqualBorder( + aBorderArray[3], aDistances[3], + getProperty(xSet,"CharRightBorder"), + getProperty(xSet,"CharRightBorderDistance")); + + // Check character style + { + uno::Reference< container::XNameAccess > xStyleFamily(getStyles("CharacterStyles"), uno::UNO_QUERY); + uno::Reference < beans::XPropertySet > xStyleSet(xStyleFamily->getByName("CharDiffBor"), uno::UNO_QUERY); + + // Top border + assertEqualBorder( + aBorderArray[0], aDistances[0], + getProperty(xStyleSet,"CharTopBorder"), + getProperty(xStyleSet,"CharTopBorderDistance")); + + // Bottom border + assertEqualBorder( + aBorderArray[1], aDistances[1], + getProperty(xStyleSet,"CharBottomBorder"), + getProperty(xStyleSet,"CharBottomBorderDistance")); + + // Left border + assertEqualBorder( + aBorderArray[2], aDistances[2], + getProperty(xStyleSet,"CharLeftBorder"), + getProperty(xStyleSet,"CharLeftBorderDistance")); + + // Right border + assertEqualBorder( + aBorderArray[3], aDistances[3], + getProperty(xStyleSet,"CharRightBorder"), + getProperty(xStyleSet,"CharRightBorderDistance")); + } + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3