/* * 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 #include #include #include #include #include #include #include #include class Test : public SwModelTestBase { public: void testN757910(); void testN760294(); void testN750255(); void testN652364(); void testN757118(); void testN757905(); void testAllGapsWord(); void testFdo59530(); void testI120158(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) CPPUNIT_TEST(run); #endif CPPUNIT_TEST_SUITE_END(); private: void run(); }; void Test::run() { MethodEntry 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} }; header(); for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i) { MethodEntry& 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 xTextFramesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY); uno::Reference 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 xTextTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); uno::Reference 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 textDocument(mxComponent, uno::UNO_QUERY); uno::Reference paraEnumAccess(textDocument->getText(), uno::UNO_QUERY); // list of paragraphs uno::Reference paraEnum = paraEnumAccess->createEnumeration(); // go to 1st paragraph (void) paraEnum->nextElement(); // get the 2nd and 3rd paragraph uno::Reference paragraph1(paraEnum->nextElement(), uno::UNO_QUERY); uno::Reference paragraph2(paraEnum->nextElement(), uno::UNO_QUERY); uno::Reference text1(paragraph1, uno::UNO_QUERY); uno::Reference text2(paragraph2, uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1->getString()); CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2->getString()); uno::Reference paragraphProperties1(paragraph1, uno::UNO_QUERY); uno::Reference 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 textDocument(mxComponent, uno::UNO_QUERY); uno::Reference paraEnumAccess(textDocument->getText(), uno::UNO_QUERY); // list of paragraphs uno::Reference paraEnum = paraEnumAccess->createEnumeration(); // get the 2nd and 4th paragraph (void) paraEnum->nextElement(); uno::Reference paragraph1(paraEnum->nextElement(), uno::UNO_QUERY); (void) paraEnum->nextElement(); uno::Reference paragraph2(paraEnum->nextElement(), uno::UNO_QUERY); uno::Reference text1(paragraph1, uno::UNO_QUERY); uno::Reference text2(paragraph2, uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1->getString()); CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2->getString()); uno::Reference paragraphProperties1(paragraph1, uno::UNO_QUERY); uno::Reference 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 textDocument(mxComponent, uno::UNO_QUERY); uno::Reference drawPageSupplier(textDocument, uno::UNO_QUERY); uno::Reference drawPage = drawPageSupplier->getDrawPage(); uno::Reference rule1, rule2, rule3, rule4; drawPage->getByIndex(0) >>= rule1; drawPage->getByIndex(1) >>= rule2; drawPage->getByIndex(2) >>= rule3; drawPage->getByIndex(3) >>= rule4; uno::Reference ruleProperties1(rule1, uno::UNO_QUERY); uno::Reference ruleProperties2(rule2, uno::UNO_QUERY); uno::Reference ruleProperties3(rule3, uno::UNO_QUERY); uno::Reference 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 xTextDocument(mxComponent, uno::UNO_QUERY); uno::Reference xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY); uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); uno::Reference xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY); uno::Reference xRunEnum = xRunEnumAccess->createEnumeration(); xRunEnum->nextElement(); uno::Reference xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty(xPropertySet, "TextPortionType")); xRunEnum->nextElement(); xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty(xPropertySet, "TextPortionType")); // Test initials. uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); uno::Reference xFields(xFieldsAccess->createEnumeration()); xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("346376201"), getProperty(xPropertySet, "Name")); CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty(xPropertySet, "Initials")); } void Test::testI120158() { // See https://issues.apache.org/ooo/show_bug.cgi?id=120158 uno::Reference textDocument(mxComponent, uno::UNO_QUERY); uno::Reference paraEnumAccess(textDocument->getText(), uno::UNO_QUERY); // list of paragraphs uno::Reference paraEnum = paraEnumAccess->createEnumeration(); // get contents of 1st paragraph as text uno::Reference paragraph0(paraEnum->nextElement(), uno::UNO_QUERY); uno::Reference text0(paragraph0, uno::UNO_QUERY); OUString sFieldResult = text0->getString(); CPPUNIT_ASSERT(sFieldResult.endsWith("AM") || sFieldResult.endsWith("PM")); } CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */