/* * Version: MPL 1.1 / GPLv3+ / LGPLv3+ * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Initial Developer of the Original Code is * Miklos Vajna (SUSE, Inc.) * Portions created by the Initial Developer are Copyright (C) 2012 the * Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 3 or later (the "GPLv3+"), or * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable * instead of those above. */ #include "../swmodeltestbase.hxx" #include #include #include #include #include #include #include #include #include #include #include #include #include using rtl::OString; using rtl::OUString; using rtl::OUStringBuffer; class Test : public SwModelTestBase { public: void testN751054(); void testN751117(); void testN751017(); void testN750935(); void testN757890(); void testFdo49940(); void testN751077(); void testN705956_1(); void testN705956_2(); void testN747461(); void testN750255(); void testN652364(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) CPPUNIT_TEST(testN751054); CPPUNIT_TEST(testN751117); CPPUNIT_TEST(testN751017); CPPUNIT_TEST(testN750935); CPPUNIT_TEST(testN757890); CPPUNIT_TEST(testFdo49940); CPPUNIT_TEST(testN751077); CPPUNIT_TEST(testN705956_1); CPPUNIT_TEST(testN705956_2); CPPUNIT_TEST(testN747461); CPPUNIT_TEST(testN750255); CPPUNIT_TEST(testN652364); #endif CPPUNIT_TEST_SUITE_END(); private: /// Load an OOXML file and make the document available via mxComponent. void load(const OUString& rURL); }; void Test::load(const OUString& rFilename) { mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/ooxmltok/data/") + rFilename); } void Test::testN751054() { load("n751054.docx"); uno::Reference xDrawPageSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY); uno::Reference xPropertySet(xDraws->getByIndex(0), uno::UNO_QUERY); text::TextContentAnchorType eValue; xPropertySet->getPropertyValue("AnchorType") >>= eValue; CPPUNIT_ASSERT(eValue != text::TextContentAnchorType_AS_CHARACTER); } void Test::testN751117() { load("n751117.docx"); uno::Reference xDrawPageSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY); // First shape: the end should be an arrow, should be rotated and should be flipped. uno::Reference xPropertySet(xDraws->getByIndex(0), uno::UNO_QUERY); OUString aValue; xPropertySet->getPropertyValue("LineEndName") >>= aValue; CPPUNIT_ASSERT(aValue.indexOf("Arrow") != -1); sal_Int32 nValue = 0; xPropertySet->getPropertyValue("RotateAngle") >>= nValue; CPPUNIT_ASSERT_EQUAL(sal_Int32(90 * 100), nValue); uno::Reference xShape(xPropertySet, uno::UNO_QUERY); awt::Size aActualSize(xShape->getSize()); CPPUNIT_ASSERT(aActualSize.Width < 0); // The second shape should be a line uno::Reference xServiceInfo(xDraws->getByIndex(1), uno::UNO_QUERY); CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.drawing.LineShape")); } void Test::testN751017() { load("n751017.docx"); uno::Reference xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xMasters(xTextFieldsSupplier->getTextFieldMasters()); // Make sure we have a variable named foo. CPPUNIT_ASSERT(xMasters->hasByName("com.sun.star.text.FieldMaster.SetExpression.foo")); uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); uno::Reference xFields(xFieldsAccess->createEnumeration()); bool bFoundSet(false), bFoundGet(false); while (xFields->hasMoreElements()) { uno::Reference xServiceInfo(xFields->nextElement(), uno::UNO_QUERY); uno::Reference xPropertySet(xServiceInfo, uno::UNO_QUERY); sal_Int16 nValue = 0; OUString aValue; if (xServiceInfo->supportsService("com.sun.star.text.TextField.SetExpression")) { bFoundSet = true; uno::Reference xDependentTextField(xServiceInfo, uno::UNO_QUERY); uno::Reference xMasterProps(xDependentTextField->getTextFieldMaster()); // First step: did we set foo to "bar"? xMasterProps->getPropertyValue("Name") >>= aValue; CPPUNIT_ASSERT_EQUAL(OUString("foo"), aValue); xPropertySet->getPropertyValue("SubType") >>= nValue; CPPUNIT_ASSERT_EQUAL(text::SetVariableType::STRING, nValue); xPropertySet->getPropertyValue("Content") >>= aValue; CPPUNIT_ASSERT_EQUAL(OUString("bar"), aValue); } else if (xServiceInfo->supportsService("com.sun.star.text.TextField.GetExpression")) { // Second step: check the value of foo. bFoundGet = true; xPropertySet->getPropertyValue("Content") >>= aValue; CPPUNIT_ASSERT_EQUAL(OUString("foo"), aValue); xPropertySet->getPropertyValue("SubType") >>= nValue; CPPUNIT_ASSERT_EQUAL(text::SetVariableType::STRING, nValue); xPropertySet->getPropertyValue("CurrentPresentation") >>= aValue; CPPUNIT_ASSERT_EQUAL(OUString("bar"), aValue); } } CPPUNIT_ASSERT(bFoundSet); CPPUNIT_ASSERT(bFoundGet); } void Test::testN750935() { load("n750935.docx"); uno::Reference xModel(mxComponent, uno::UNO_QUERY); uno::Reference xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY); uno::Reference xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); xCursor->jumpToLastPage(); CPPUNIT_ASSERT_EQUAL(sal_Int16(5), xCursor->getPage()); } void Test::testN757890() { load("n757890.docx"); // The w:pStyle token affected the text outside the textbox. uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); uno::Reference xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY); uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); OUString aValue; xPara->getPropertyValue("ParaStyleName") >>= aValue; CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"), aValue); // This wan't centered uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY); uno::Reference xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY); sal_Int16 nValue; xFrame->getPropertyValue("HoriOrient") >>= nValue; CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::CENTER, nValue); } void Test::testFdo49940() { load("fdo49940.docx"); uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); uno::Reference xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY); uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); OUString aValue; xPara->getPropertyValue("PageStyleName") >>= aValue; CPPUNIT_ASSERT_EQUAL(OUString("First Page"), aValue); } void Test::testN751077() { load( "n751077.docx" ); /* enum = ThisComponent.Text.createEnumeration enum.NextElement para = enum.NextElement xray para.String xray para.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 paragraph uno::Reference paragraph(paraEnum->nextElement(), uno::UNO_QUERY); // text of the paragraph uno::Reference text(paragraph, uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL( OUString( "TEXT1" ), text->getString()); // we want to test the paragraph is on the first page (it was put onto another page without the fix), // use a small trick and instead of checking the page layout, check the page style uno::Reference paragraphProperties(paragraph, uno::UNO_QUERY); OUString pageStyle; paragraphProperties->getPropertyValue( "PageStyleName" ) >>= pageStyle; CPPUNIT_ASSERT_EQUAL( OUString( "First Page" ), pageStyle ); } void Test::testN705956_1() { load( "n705956-1.docx" ); /* Get the first image in the document and check it's the one image in the document. image = ThisComponent.DrawPage.getByIndex(0) graphic = image.Graphic xray graphic.Size */ uno::Reference textDocument(mxComponent, uno::UNO_QUERY); uno::Reference drawPageSupplier(textDocument, uno::UNO_QUERY); uno::Reference drawPage = drawPageSupplier->getDrawPage(); CPPUNIT_ASSERT_EQUAL( sal_Int32( 1 ), drawPage->getCount()); uno::Reference image; drawPage->getByIndex(0) >>= image; uno::Reference imageProperties(image, uno::UNO_QUERY); uno::Reference graphic; imageProperties->getPropertyValue( "Graphic" ) >>= graphic; uno::Reference bitmap(graphic, uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL( static_cast(120), bitmap->getSize().Width ); CPPUNIT_ASSERT_EQUAL( static_cast(106), bitmap->getSize().Height ); } void Test::testN705956_2() { load( "n705956-2.docx" ); /* must be global, reachable even from inside another image = ThisComponent.DrawPage.getByIndex(0) xray image.FillColor */ uno::Reference textDocument(mxComponent, uno::UNO_QUERY); uno::Reference drawPageSupplier(textDocument, uno::UNO_QUERY); uno::Reference drawPage = drawPageSupplier->getDrawPage(); uno::Reference image; drawPage->getByIndex(0) >>= image; uno::Reference imageProperties(image, uno::UNO_QUERY); sal_Int32 fillColor; imageProperties->getPropertyValue( "FillColor" ) >>= fillColor; CPPUNIT_ASSERT_EQUAL( sal_Int32( 0xc0504d ), fillColor ); } void Test::testN747461() { load( "n747461.docx" ); /* The document contains 3 images (Red, Black, Green, in this order), with explicit w:relativeHeight (300, 0, 225763766). Check that they are in the right ZOrder after they are loaded. */ uno::Reference textDocument(mxComponent, uno::UNO_QUERY); uno::Reference drawPageSupplier(textDocument, uno::UNO_QUERY); uno::Reference drawPage = drawPageSupplier->getDrawPage(); uno::Reference image1, image2, image3; drawPage->getByIndex( 0 ) >>= image1; drawPage->getByIndex( 1 ) >>= image2; drawPage->getByIndex( 2 ) >>= image3; sal_Int32 zOrder1, zOrder2, zOrder3; OUString descr1, descr2, descr3; uno::Reference imageProperties1(image1, uno::UNO_QUERY); imageProperties1->getPropertyValue( "ZOrder" ) >>= zOrder1; imageProperties1->getPropertyValue( "Description" ) >>= descr1; uno::Reference imageProperties2(image2, uno::UNO_QUERY); imageProperties2->getPropertyValue( "ZOrder" ) >>= zOrder2; imageProperties2->getPropertyValue( "Description" ) >>= descr2; uno::Reference imageProperties3(image3, uno::UNO_QUERY); imageProperties3->getPropertyValue( "ZOrder" ) >>= zOrder3; imageProperties3->getPropertyValue( "Description" ) >>= descr3; CPPUNIT_ASSERT_EQUAL( sal_Int32( 0 ), zOrder1 ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 1 ), zOrder2 ); CPPUNIT_ASSERT_EQUAL( sal_Int32( 2 ), zOrder3 ); CPPUNIT_ASSERT_EQUAL( OUString( "Black" ), descr1 ); CPPUNIT_ASSERT_EQUAL( OUString( "Red" ), descr2 ); CPPUNIT_ASSERT_EQUAL( OUString( "Green" ), descr3 ); } void Test::testN750255() { load( "n750255.docx" ); /* Column break without columns on the page is a page break, so check those paragraphs are on page 2 (page style 'Converted1') and page 3 (page style 'Converted2') 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( "Converted1" ), pageStyle1 ); CPPUNIT_ASSERT_EQUAL( OUString( "Converted2" ), pageStyle2 ); } void Test::testN652364() { load( "n652364.docx" ); /* 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 "Converted1"). CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1 ); CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2 ); } CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */