60a3f35e63
Change-Id: Icea791684399fb15b5f7940b5691cdc76b3dde1f
292 lines
12 KiB
C++
292 lines
12 KiB
C++
/*
|
|
* 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 <com/sun/star/table/BorderLine2.hpp>
|
|
#include <com/sun/star/table/TableBorder.hpp>
|
|
#include <com/sun/star/text/XDependentTextField.hpp>
|
|
#include <com/sun/star/text/XTextFramesSupplier.hpp>
|
|
#include <com/sun/star/text/XTextTablesSupplier.hpp>
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <swmodeltestbase.hxx>
|
|
#include <bordertest.hxx>
|
|
|
|
#define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
|
|
|
|
class Test : public SwModelTestBase
|
|
{
|
|
public:
|
|
void testN757910();
|
|
void testN760294();
|
|
void testN750255();
|
|
void testN652364();
|
|
void testN757118();
|
|
void testN757905();
|
|
void testAllGapsWord();
|
|
void testFdo59530();
|
|
void testI120158();
|
|
void testN816603();
|
|
void testN816593();
|
|
void testPageBorder();
|
|
void testN823651();
|
|
|
|
CPPUNIT_TEST_SUITE(Test);
|
|
#if !defined(MACOSX) && !defined(WNT)
|
|
CPPUNIT_TEST(run);
|
|
#endif
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
void run();
|
|
};
|
|
|
|
void Test::run()
|
|
{
|
|
MethodEntry<Test> aMethods[] = {
|
|
{"n757910.doc", &Test::testN757910},
|
|
{"n760294.doc", &Test::testN760294},
|
|
{"n750255.doc", &Test::testN750255},
|
|
{"n652364.doc", &Test::testN652364},
|
|
{"n757118.doc", &Test::testN757118},
|
|
{"n757905.doc", &Test::testN757905},
|
|
{"all_gaps_word.doc", &Test::testAllGapsWord},
|
|
{"fdo59530.doc", &Test::testFdo59530},
|
|
{"i120158.doc", &Test::testI120158},
|
|
{"n816603.doc", &Test::testN816603},
|
|
{"n816593.doc", &Test::testN816593},
|
|
{"page-border.doc", &Test::testPageBorder},
|
|
{"n823651.doc", &Test::testN823651},
|
|
};
|
|
header();
|
|
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
|
|
{
|
|
MethodEntry<Test>& rEntry = aMethods[i];
|
|
load("/sw/qa/extras/ww8import/data/", rEntry.pName);
|
|
(this->*rEntry.pMethod)();
|
|
finish();
|
|
}
|
|
}
|
|
|
|
void Test::testN757910()
|
|
{
|
|
// The internal margin was larger than 0.28cm
|
|
uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
|
|
uno::Reference<beans::XPropertySet> xPropertySet(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
|
|
sal_Int32 nValue = 0;
|
|
xPropertySet->getPropertyValue("LeftBorderDistance") >>= nValue;
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(280), nValue);
|
|
|
|
// The border width was zero
|
|
table::BorderLine2 aBorder;
|
|
xPropertySet->getPropertyValue("LeftBorder") >>= aBorder;
|
|
CPPUNIT_ASSERT(aBorder.LineWidth > 0);
|
|
}
|
|
|
|
void Test::testN760294()
|
|
{
|
|
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
|
|
uno::Reference<beans::XPropertySet> xTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
|
|
table::TableBorder aTableBorder;
|
|
xTable->getPropertyValue("TableBorder") >>= aTableBorder;
|
|
CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.OuterLineWidth);
|
|
CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.LineDistance);
|
|
}
|
|
|
|
void Test::testN750255()
|
|
{
|
|
/*
|
|
Column break without columns on the page is a page break, so check those paragraphs
|
|
are on page 2 (page style 'Convert 1') and page 3 (page style 'Convert 2')
|
|
enum = ThisComponent.Text.createEnumeration
|
|
enum.nextElement
|
|
para1 = enum.nextElement
|
|
xray para1.String
|
|
xray para1.PageStyleName
|
|
para2 = enum.nextElement
|
|
xray para2.String
|
|
xray para2.PageStyleName
|
|
*/
|
|
uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
|
|
// list of paragraphs
|
|
uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
|
|
// go to 1st paragraph
|
|
(void) paraEnum->nextElement();
|
|
// get the 2nd and 3rd paragraph
|
|
uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
|
|
uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
|
|
uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
|
|
uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
|
|
CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1->getString());
|
|
CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2->getString());
|
|
uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
|
|
uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
|
|
OUString pageStyle1, pageStyle2;
|
|
paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
|
|
paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
|
|
CPPUNIT_ASSERT_EQUAL( OUString( "Convert 1" ), pageStyle1 );
|
|
CPPUNIT_ASSERT_EQUAL( OUString( "Convert 2" ), pageStyle2 );
|
|
|
|
}
|
|
|
|
void Test::testN652364()
|
|
{
|
|
/*
|
|
Related to 750255 above, column break with columns on the page however should be a column break.
|
|
enum = ThisComponent.Text.createEnumeration
|
|
enum.nextElement
|
|
para1 = enum.nextElement
|
|
xray para1.String
|
|
xray para1.PageStyleName
|
|
enum.nextElement
|
|
para2 = enum.nextElement
|
|
xray para2.String
|
|
xray para2.PageStyleName
|
|
*/
|
|
uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
|
|
// list of paragraphs
|
|
uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
|
|
// get the 2nd and 4th paragraph
|
|
(void) paraEnum->nextElement();
|
|
uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
|
|
(void) paraEnum->nextElement();
|
|
uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
|
|
uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
|
|
uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
|
|
CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1->getString());
|
|
CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2->getString());
|
|
uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
|
|
uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
|
|
OUString pageStyle1, pageStyle2;
|
|
paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
|
|
paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
|
|
// "Standard" is the style for the first page (2nd is "Convert 1").
|
|
CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1 );
|
|
CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2 );
|
|
}
|
|
|
|
void Test::testN757118()
|
|
{
|
|
/*
|
|
Two pairs of horizontal rules (one absolute width, one relative width)
|
|
have the same width (full page width, half page width).
|
|
xray ThisComponent.DrawPage.getByIndex(0).BoundRect
|
|
*/
|
|
uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<drawing::XShape> rule1 = getShape(1), rule2 = getShape(2), rule3 = getShape(3), rule4 = getShape(4);
|
|
uno::Reference<beans::XPropertySet> ruleProperties1(rule1, uno::UNO_QUERY);
|
|
uno::Reference<beans::XPropertySet> ruleProperties2(rule2, uno::UNO_QUERY);
|
|
uno::Reference<beans::XPropertySet> ruleProperties3(rule3, uno::UNO_QUERY);
|
|
uno::Reference<beans::XPropertySet> ruleProperties4(rule4, uno::UNO_QUERY);
|
|
awt::Rectangle boundRect1, boundRect2, boundRect3, boundRect4;
|
|
ruleProperties1->getPropertyValue( "BoundRect" ) >>= boundRect1;
|
|
ruleProperties2->getPropertyValue( "BoundRect" ) >>= boundRect2;
|
|
ruleProperties3->getPropertyValue( "BoundRect" ) >>= boundRect3;
|
|
ruleProperties4->getPropertyValue( "BoundRect" ) >>= boundRect4;
|
|
// compare, allow for < 5 differences because of rounding errors
|
|
CPPUNIT_ASSERT( abs( boundRect1.Width - boundRect3.Width ) < 5 );
|
|
CPPUNIT_ASSERT( abs( boundRect2.Width - boundRect4.Width ) < 5 );
|
|
}
|
|
|
|
void Test::testN757905()
|
|
{
|
|
// The problem was that the paragraph had only a single fly
|
|
// (as-character-anchored), and the height of that was smallar than the
|
|
// paragraph height. When in Word-compat mode, we should take the max of
|
|
// the two, not just the height of the fly.
|
|
|
|
OUString aHeight = parseDump("/root/page/body/txt/infos/bounds", "height");
|
|
CPPUNIT_ASSERT(sal_Int32(31) < aHeight.toInt32());
|
|
}
|
|
|
|
void Test::testAllGapsWord()
|
|
{
|
|
BorderTest borderTest;
|
|
borderTest.testTheBorders(mxComponent);
|
|
}
|
|
|
|
void Test::testFdo59530()
|
|
{
|
|
// See ooxmlexport's testFdo38244().
|
|
// Test comment range feature.
|
|
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
|
|
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
|
|
uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
|
|
uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
|
|
xRunEnum->nextElement();
|
|
uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
|
|
CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType"));
|
|
xRunEnum->nextElement();
|
|
xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
|
|
CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
|
|
|
|
// Test initials.
|
|
uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
|
|
uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
|
|
xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
|
|
CPPUNIT_ASSERT_EQUAL(OUString("346376201"), getProperty<OUString>(xPropertySet, "Name"));
|
|
CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
|
|
}
|
|
|
|
void Test::testI120158()
|
|
{
|
|
// See https://issues.apache.org/ooo/show_bug.cgi?id=120158
|
|
uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
|
|
// list of paragraphs
|
|
uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
|
|
// get contents of 1st paragraph as text
|
|
uno::Reference<uno::XInterface> paragraph0(paraEnum->nextElement(), uno::UNO_QUERY);
|
|
uno::Reference<text::XTextRange> text0(paragraph0, uno::UNO_QUERY);
|
|
OUString sFieldResult = text0->getString();
|
|
CPPUNIT_ASSERT(sFieldResult.endsWith("AM") || sFieldResult.endsWith("PM"));
|
|
}
|
|
|
|
void Test::testN816603()
|
|
{
|
|
// Bugdoc was 5 pages in Word, 1 in Writer due to pointlessly wrapping the
|
|
// table in a frame. Exact layout may depend on fonts available, etc. --
|
|
// but at least make sure that our table spans over multiple pages now.
|
|
CPPUNIT_ASSERT(getPages() > 1);
|
|
}
|
|
|
|
void Test::testN816593()
|
|
{
|
|
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
|
|
uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
|
|
// Make sure that even if we import the two tables as non-floating, we
|
|
// still consider them different, and not merge them.
|
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
|
|
}
|
|
|
|
void Test::testPageBorder()
|
|
{
|
|
// Page border was missing (LineWidth was 0), due to wrong interpretation of pgbApplyTo.
|
|
table::BorderLine2 aBorder = getProperty<table::BorderLine2>(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "TopBorder");
|
|
CPPUNIT_ASSERT_EQUAL(sal_uInt32(TWIP_TO_MM100(6 * 20)), aBorder.LineWidth);
|
|
}
|
|
|
|
void Test::testN823651()
|
|
{
|
|
// Character height was 10pt instead of 7.5pt in the header.
|
|
uno::Reference<beans::XPropertySet> xStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
|
|
uno::Reference<text::XText> xText = getProperty< uno::Reference<text::XTextRange> >(xStyle, "HeaderTextFirst")->getText();
|
|
CPPUNIT_ASSERT_EQUAL(7.5f, getProperty<float>(getParagraphOfText(1, xText), "CharHeight"));
|
|
}
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|