/* * 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 #include #include #include #include #include #include #include #include #include class Test : public SwModelTestBase { public: Test() : SwModelTestBase("/sw/qa/extras/rtfexport/data/", "Rich Text Format") {} bool mustTestImportOf(const char* filename) const SAL_OVERRIDE { // Don't test the first import of these, for some reason those tests fail const char* aBlacklist[] = { "math-eqarray.rtf", "math-escaping.rtf", "math-lim.rtf", "math-mso2007.rtf", "math-nary.rtf", "math-rad.rtf", "math-vertical-stacks.rtf", "math-runs.rtf", }; std::vector vBlacklist(aBlacklist, aBlacklist + SAL_N_ELEMENTS(aBlacklist)); // If the testcase is stored in some other format, it's pointless to test. return (OString(filename).endsWith(".rtf") && std::find(vBlacklist.begin(), vBlacklist.end(), filename) == vBlacklist.end()); } bool CjkNumberedListTestHelper(sal_Int16& rValue) { sal_Bool isNumber = false; uno::Reference xPara(getParagraph(1)); uno::Reference properties(xPara, uno::UNO_QUERY); properties->getPropertyValue("NumberingIsNumber") >>= isNumber; if (!isNumber) return false; uno::Reference xLevels(properties->getPropertyValue("NumberingRules"), uno::UNO_QUERY); uno::Sequence< beans::PropertyValue > aPropertyValue; xLevels->getByIndex(0) >>= aPropertyValue; for (int j = 0; j < aPropertyValue.getLength(); ++j) { beans::PropertyValue aProp= aPropertyValue[j]; if (aProp.Name == "NumberingType") { rValue = aProp.Value.get(); return true; } } return false; } }; DECLARE_RTFEXPORT_TEST(testZoom, "zoom.rtf") { uno::Reference xModel(mxComponent, uno::UNO_QUERY); uno::Reference xViewSettingsSupplier(xModel->getCurrentController(), uno::UNO_QUERY); uno::Reference xPropertySet(xViewSettingsSupplier->getViewSettings()); sal_Int16 nValue = 0; xPropertySet->getPropertyValue("ZoomValue") >>= nValue; CPPUNIT_ASSERT_EQUAL(sal_Int16(42), nValue); } DECLARE_RTFEXPORT_TEST(testFdo38176, "fdo38176.rtf") { CPPUNIT_ASSERT_EQUAL(9, getLength()); } DECLARE_RTFEXPORT_TEST(testFdo49683, "fdo49683.rtf") { uno::Reference xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDocumentProperties(xDocumentPropertiesSupplier->getDocumentProperties()); uno::Sequence aKeywords(xDocumentProperties->getKeywords()); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aKeywords.getLength()); CPPUNIT_ASSERT_EQUAL(OUString("one"), aKeywords[0]); CPPUNIT_ASSERT_EQUAL(OUString("two"), aKeywords[1]); } DECLARE_RTFEXPORT_TEST(testFdo44174, "fdo44174.rtf") { uno::Reference xModel(mxComponent, uno::UNO_QUERY); uno::Reference xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY); uno::Reference xPropertySet(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); OUString aValue; xPropertySet->getPropertyValue("PageStyleName") >>= aValue; CPPUNIT_ASSERT_EQUAL(OUString("First Page"), aValue); } DECLARE_RTFEXPORT_TEST(testFdo50087, "fdo50087.rtf") { uno::Reference xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDocumentProperties(xDocumentPropertiesSupplier->getDocumentProperties()); CPPUNIT_ASSERT_EQUAL(OUString("Title"), xDocumentProperties->getTitle()); CPPUNIT_ASSERT_EQUAL(OUString("Subject"), xDocumentProperties->getSubject()); CPPUNIT_ASSERT_EQUAL(OUString("First line.\nSecond line."), xDocumentProperties->getDescription()); } DECLARE_RTFEXPORT_TEST(testFdo50831, "fdo50831.rtf") { uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); uno::Reference xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY); uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); uno::Reference xPropertySet(xParaEnum->nextElement(), uno::UNO_QUERY); float fValue = 0; xPropertySet->getPropertyValue("CharHeight") >>= fValue; CPPUNIT_ASSERT_EQUAL(10.f, fValue); } DECLARE_RTFEXPORT_TEST(testFdo48335, "fdo48335.odt") { /* * The problem was that we exported a fake pagebreak, make sure it's just a soft one now. * * oParas = ThisComponent.Text.createEnumeration * oPara = oParas.nextElement * oPara = oParas.nextElement * oPara = oParas.nextElement * oRuns = oPara.createEnumeration * oRun = oRuns.nextElement * xray oRun.TextPortionType 'was Text, should be SoftPageBreak */ uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); uno::Reference xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY); uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); for (int i = 0; i < 2; i++) xParaEnum->nextElement(); uno::Reference xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY); uno::Reference xRunEnum = xRunEnumAccess->createEnumeration(); uno::Reference xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY); OUString aValue; xPropertySet->getPropertyValue("TextPortionType") >>= aValue; CPPUNIT_ASSERT_EQUAL(OUString("SoftPageBreak"), aValue); } DECLARE_RTFEXPORT_TEST(testFdo38244, "fdo38244.rtf") { // 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("Annotation"), getProperty(xPropertySet, "TextPortionType")); xRunEnum->nextElement(); xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), 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("M"), getProperty(xPropertySet, "Initials")); } DECLARE_RTFEXPORT_TEST(testCommentsNested, "comments-nested.odt") { uno::Reference xOuter(getProperty< uno::Reference >(getRun(getParagraph(1), 2), "TextField"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Outer"), getProperty(xOuter, "Content").trim()); uno::Reference xInner(getProperty< uno::Reference >(getRun(getParagraph(1), 4), "TextField"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Inner"), getProperty(xInner, "Content").trim()); } DECLARE_RTFEXPORT_TEST(testMathAccents, "math-accents.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("acute {a} grave {a} check {a} breve {a} circle {a} widevec {a} widetilde {a} widehat {a} dot {a} widevec {a} widevec {a} widetilde {a} underline {a}"); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathEqarray, "math-eqarray.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("y = left lbrace stack { 0, x < 0 # 1, x = 0 # {x} ^ {2} , x > 0 } right none"); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathD, "math-d.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("left (x mline y mline z right ) left (1 right ) left [2 right ] left ldbracket 3 right rdbracket left lline 4 right rline left ldline 5 right rdline left langle 6 right rangle left langle a mline b right rangle left ({x} over {y} right )"); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathEscaping, "math-escaping.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("\xc3\xa1 \\{", 5, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathLim, "math-lim.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("lim from {x \xe2\x86\x92 1} {x}", 22, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathMatrix, "math-matrix.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("left [matrix {1 # 2 ## 3 # 4} right ]"); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathBox, "math-mbox.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("a"); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathMso2007, "math-mso2007.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("A = \xcf\x80 {r} ^ {2}", 16, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(2), 1)); aExpected = OUString("{left (x + a right )} ^ {n} = sum from {k = 0} to {n} {left (stack { n # k } right ) {x} ^ {k} {a} ^ {n \xe2\x88\x92 k}}", 111, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(3), 1)); aExpected = OUString("{left (1 + x right )} ^ {n} = 1 + {nx} over {1 !} + {n left (n \xe2\x88\x92 1 right ) {x} ^ {2}} over {2 !} + \xe2\x80\xa6", 104, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(4), 1)); aExpected = OUString("f left (x right ) = {a} rsub {0} + sum from {n = 1} to {\xe2\x88\x9e} {left ({a} rsub {n} cos {n\xcf\x80x} over {L} + {b} rsub {n} sin {n\xcf\x80x} over {L} right )}", 144, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(5), 1)); aExpected = "{a} ^ {2} + {b} ^ {2} = {c} ^ {2}"; CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(6), 1)); aExpected = OUString("x = {\xe2\x88\x92 b \xc2\xb1 sqrt {{b} ^ {2} \xe2\x88\x92 4 ac}} over {2 a}", 51, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(7), 1)); aExpected = OUString("{e} ^ {x} = 1 + {x} over {1 !} + {{x} ^ {2}} over {2 !} + {{x} ^ {3}} over {3 !} + \xe2\x80\xa6 , \xe2\x88\x92 \xe2\x88\x9e < x < \xe2\x88\x9e", 106, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(8), 1)); aExpected = OUString("sin \xce\xb1 \xc2\xb1 sin \xce\xb2 = 2 sin {1} over {2} left (\xce\xb1 \xc2\xb1 \xce\xb2 right ) cos {1} over {2} left (\xce\xb1 \xe2\x88\x93 \xce\xb2 right )", 101, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); aActual = getFormula(getRun(getParagraph(9), 1)); aExpected = OUString("cos \xce\xb1 + cos \xce\xb2 = 2 cos {1} over {2} left (\xce\xb1 + \xce\xb2 right ) cos {1} over {2} left (\xce\xb1 \xe2\x88\x92 \xce\xb2 right )", 99, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathNary, "math-nary.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("lllint from {1} to {2} {x + 1} prod from {a} {b} sum to {2} {x}"); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathLimupp, "math-limupp.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); CPPUNIT_ASSERT_EQUAL(OUString("{abcd} overbrace {4}"), aActual); aActual = getFormula(getRun(getParagraph(2), 1)); CPPUNIT_ASSERT_EQUAL(OUString("{xyz} underbrace {3}"), aActual); } DECLARE_RTFEXPORT_TEST(testMathStrikeh, "math-strikeh.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); CPPUNIT_ASSERT_EQUAL(OUString("overstrike {abc}"), aActual); } DECLARE_RTFEXPORT_TEST(testMathPlaceholders, "math-placeholders.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); CPPUNIT_ASSERT_EQUAL(OUString("sum from to "), aActual); } DECLARE_RTFEXPORT_TEST(testMathRad, "math-rad.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); CPPUNIT_ASSERT_EQUAL(OUString("sqrt {4} nroot {3} {x + 1}"), aActual); } DECLARE_RTFEXPORT_TEST(testMathSepchr, "math-sepchr.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); CPPUNIT_ASSERT_EQUAL(OUString("AxByBzC"), aActual); } DECLARE_RTFEXPORT_TEST(testMathSubscripts, "math-subscripts.rtf") { OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("{x} ^ {y} + {e} ^ {x} {x} ^ {b} {x} rsub {b} {a} rsub {c} rsup {b} {x} lsub {2} lsup {1} {{x csup {6} csub {3}} lsub {4} lsup {5}} rsub {2} rsup {1}"); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testMathVerticalstacks, "math-vertical-stacks.rtf") { CPPUNIT_ASSERT_EQUAL(OUString("{a} over {b}"), getFormula(getRun(getParagraph(1), 1))); CPPUNIT_ASSERT_EQUAL(OUString("{a} / {b}"), getFormula(getRun(getParagraph(2), 1))); CPPUNIT_ASSERT_EQUAL(OUString("stack { a # b }"), getFormula(getRun(getParagraph(3), 1))); CPPUNIT_ASSERT_EQUAL(OUString("stack { a # stack { b # c } }"), getFormula(getRun(getParagraph(4), 1))); } DECLARE_RTFEXPORT_TEST(testMathRuns, "math-runs.rtf") { // was [](){}, i.e. first curly bracket had an incorrect position CPPUNIT_ASSERT_EQUAL(OUString("\\{ left [ right ] left ( right ) \\}"), getFormula(getRun(getParagraph(1), 1))); } DECLARE_RTFEXPORT_TEST(testFdo77979, "fdo77979.odt") { // font name is encoded with \fcharset of font OUString aExpected("\xE5\xBE\xAE\xE8\xBD\xAF\xE9\x9B\x85\xE9\xBB\x91", 12, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, getProperty(getRun(getParagraph(1), 1), "CharFontName")); } DECLARE_RTFEXPORT_TEST(testFdo53113, "fdo53113.odt") { /* * The problem was that a custom shape was missings its second (and all the other remaining) coordinates. * * oShape = ThisComponent.DrawPage(0) * oPathPropVec = oShape.CustomShapeGeometry(1).Value * oCoordinates = oPathPropVec(0).Value * xray oCoordinates(1).First.Value ' 535 * xray oCoordinates(1).Second.Value ' 102 */ uno::Sequence aProps = getProperty< uno::Sequence >(getShape(1), "CustomShapeGeometry"); uno::Sequence aPathProps; for (int i = 0; i < aProps.getLength(); ++i) { const beans::PropertyValue& rProp = aProps[i]; if (rProp.Name == "Path") rProp.Value >>= aPathProps; } uno::Sequence aPairs; for (int i = 0; i < aPathProps.getLength(); ++i) { const beans::PropertyValue& rProp = aPathProps[i]; if (rProp.Name == "Coordinates") rProp.Value >>= aPairs; } CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aPairs.getLength()); CPPUNIT_ASSERT_EQUAL(sal_Int32(535), aPairs[1].First.Value.get()); CPPUNIT_ASSERT_EQUAL(sal_Int32(102), aPairs[1].Second.Value.get()); } DECLARE_RTFEXPORT_TEST(testFdo55939, "fdo55939.odt") { // The problem was that the exported RTF was invalid. // Also, the 'Footnote text.' had an additional newline at its end. uno::Reference xParagraph(getParagraph(1)); getRun(xParagraph, 1, "Main text before footnote."); // Why the tab has to be removed here? CPPUNIT_ASSERT_EQUAL(OUString("Footnote text."), getProperty< uno::Reference >(getRun(xParagraph, 2), "Footnote")->getText()->getString().replaceAll("\t", "")); getRun(xParagraph, 3, " Text after the footnote."); // However, this leading space is intentional and OK. } DECLARE_RTFEXPORT_TEST(testTextFrames, "textframes.odt") { // The output was simply invalid, so let's check if all 3 frames were imported back. uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndexAccess->getCount()); } DECLARE_RTFEXPORT_TEST(testFdo53604, "fdo53604.odt") { // Invalid output on empty footnote. uno::Reference xFootnotesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xFootnotes->getCount()); } DECLARE_RTFEXPORT_TEST(testFdo52286, "fdo52286.odt") { // The problem was that font size wasn't reduced in sub/super script. CPPUNIT_ASSERT_EQUAL(sal_Int32(58), getProperty(getRun(getParagraph(1), 2), "CharEscapementHeight")); CPPUNIT_ASSERT_EQUAL(sal_Int32(58), getProperty(getRun(getParagraph(2), 2), "CharEscapementHeight")); } DECLARE_RTFEXPORT_TEST(testFdo61507, "fdo61507.rtf") { /* * Unicode-only characters in \title confused Wordpad. Once the exporter * was fixed to guard the problematic characters with \upr and \ud, the * importer didn't cope with these new keywords. */ uno::Reference xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xDocumentProperties(xDocumentPropertiesSupplier->getDocumentProperties()); OUString aExpected = OUString("\xc3\x89\xc3\x81\xc5\x90\xc5\xb0\xe2\x88\xad", 11, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, xDocumentProperties->getTitle()); // Only "Hello.", no additional characters. CPPUNIT_ASSERT_EQUAL(6, getLength()); } DECLARE_RTFEXPORT_TEST(testFdo30983, "fdo30983.rtf") { // These were 'page text area', not 'entire page', i.e. both the horizontal // and vertical positions were incorrect. CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty(getShape(1), "HoriOrientRelation")); CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty(getShape(1), "VertOrientRelation")); } DECLARE_RTFEXPORT_TEST(testPlaceholder, "placeholder.odt") { // Only the field text was exported, make sure we still have a field with the correct Hint text. uno::Reference xRun(getRun(getParagraph(1), 2)); CPPUNIT_ASSERT_EQUAL(OUString("TextField"), getProperty(xRun, "TextPortionType")); uno::Reference xField = getProperty< uno::Reference >(xRun, "TextField"); CPPUNIT_ASSERT_EQUAL(OUString("place holder"), getProperty(xField, "Hint")); } DECLARE_RTFEXPORT_TEST(testMnor, "mnor.rtf") { // \mnor wasn't handled, leading to missing quotes around "divF" and so on. OUString aActual = getFormula(getRun(getParagraph(1), 1)); OUString aExpected("iiint from {V} to {\"divF\"} dV = llint from {S} to {\"F\" \xe2\x88\x99 \"n\" dS}", 74, RTL_TEXTENCODING_UTF8); CPPUNIT_ASSERT_EQUAL(aExpected, aActual); } DECLARE_RTFEXPORT_TEST(testI120928, "i120928.rtf") { // \listpicture and \levelpicture0 was ignored, leading to missing graphic bullet in numbering. uno::Reference xPropertySet(getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY); uno::Reference xLevels(xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY); uno::Sequence aProps; xLevels->getByIndex(0) >>= aProps; // 1st level bool bIsGraphic = false; for (int i = 0; i < aProps.getLength(); ++i) { const beans::PropertyValue& rProp = aProps[i]; if (rProp.Name == "NumberingType") CPPUNIT_ASSERT_EQUAL(style::NumberingType::BITMAP, rProp.Value.get()); else if (rProp.Name == "GraphicURL") bIsGraphic = true; } CPPUNIT_ASSERT_EQUAL(true, bIsGraphic); } DECLARE_RTFEXPORT_TEST(testBookmark, "bookmark.rtf") { uno::Reference xBookmarksSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xBookmark(xBookmarksSupplier->getBookmarks()->getByName("firstword"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("Hello"), xBookmark->getAnchor()->getString()); } DECLARE_RTFEXPORT_TEST(testHyperlink, "hyperlink.rtf") { CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty(getRun(getParagraph(1), 1, "Hello"), "HyperLinkURL")); CPPUNIT_ASSERT_EQUAL(OUString("http://en.wikipedia.org/wiki/World"), getProperty(getRun(getParagraph(1), 2, "world"), "HyperLinkURL")); CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty(getRun(getParagraph(1), 3, "!"), "HyperLinkURL")); } DECLARE_RTFEXPORT_TEST(test78758, "fdo78758.rtf") { CPPUNIT_ASSERT_EQUAL(OUString("#__RefHeading___Toc264438068"), getProperty(getRun(getParagraph(2), 1, "EE5E EeEEE5EE"), "HyperLinkURL")); CPPUNIT_ASSERT_EQUAL(OUString("#__RefHeading___Toc264438068"), getProperty(getRun(getParagraph(2), 2, "e"), "HyperLinkURL")); CPPUNIT_ASSERT_EQUAL(OUString("#__RefHeading___Toc264438068"), getProperty(getRun(getParagraph(2), 3, "\t46"), "HyperLinkURL")); } DECLARE_RTFEXPORT_TEST(testTextFrameBorders, "textframe-borders.rtf") { uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY); uno::Reference xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD99594), getProperty(xFrame, "BackColor")); table::BorderLine2 aBorder = getProperty(xFrame, "TopBorder"); CPPUNIT_ASSERT_EQUAL(sal_Int32(0xC0504D), aBorder.Color); CPPUNIT_ASSERT_EQUAL(sal_uInt32(35), aBorder.LineWidth); table::ShadowFormat aShadowFormat = getProperty(xFrame, "ShadowFormat"); CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadowFormat.Location); CPPUNIT_ASSERT_EQUAL(sal_Int16(48), aShadowFormat.ShadowWidth); CPPUNIT_ASSERT_EQUAL(sal_Int32(0x622423), aShadowFormat.Color); } DECLARE_RTFEXPORT_TEST(testTextframeGradient, "textframe-gradient.rtf") { uno::Reference xTextFramesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount()); uno::Reference xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty(xFrame, "FillStyle")); awt::Gradient aGradient = getProperty(xFrame, "FillGradient"); CPPUNIT_ASSERT_EQUAL(sal_Int32(0xC0504D), aGradient.StartColor); CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD99594), aGradient.EndColor); CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style); xFrame.set(xIndexAccess->getByIndex(1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty(xFrame, "FillStyle")); aGradient = getProperty(xFrame, "FillGradient"); CPPUNIT_ASSERT_EQUAL(sal_Int32(0x000000), aGradient.StartColor); CPPUNIT_ASSERT_EQUAL(sal_Int32(0x666666), aGradient.EndColor); CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style); } DECLARE_RTFEXPORT_TEST(testRecordChanges, "record-changes.rtf") { // \revisions wasn't imported/exported. CPPUNIT_ASSERT_EQUAL(true, getProperty(mxComponent, "RecordChanges")); } DECLARE_RTFEXPORT_TEST(testTextframeTable, "textframe-table.rtf") { uno::Reference xTextRange(getShape(1), uno::UNO_QUERY); uno::Reference xText = xTextRange->getText(); CPPUNIT_ASSERT_EQUAL(OUString("First para."), getParagraphOfText(1, xText)->getString()); uno::Reference xTable(getParagraphOrTable(2, xText), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(OUString("A"), uno::Reference(xTable->getCellByName("A1"), uno::UNO_QUERY)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("B"), uno::Reference(xTable->getCellByName("B1"), uno::UNO_QUERY)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("Last para."), getParagraphOfText(3, xText)->getString()); } DECLARE_RTFEXPORT_TEST(testFdo66682, "fdo66682.rtf") { uno::Reference xPropertySet(getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY); uno::Reference xLevels(xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY); uno::Sequence aProps; xLevels->getByIndex(0) >>= aProps; // 1st level OUString aSuffix; for (int i = 0; i < aProps.getLength(); ++i) { const beans::PropertyValue& rProp = aProps[i]; if (rProp.Name == "Suffix") aSuffix = rProp.Value.get(); } // Suffix was '\0' instead of ' '. CPPUNIT_ASSERT_EQUAL(OUString(" "), aSuffix); } DECLARE_RTFEXPORT_TEST(testParaShadow, "para-shadow.rtf") { // The problem was that \brdrsh was ignored. table::ShadowFormat aShadow = getProperty(getParagraph(2), "ParaShadowFormat"); CPPUNIT_ASSERT_EQUAL(COL_BLACK, sal_uInt32(aShadow.Color)); CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location); CPPUNIT_ASSERT_EQUAL(sal_Int16(convertTwipToMm100(60)), aShadow.ShadowWidth); } DECLARE_RTFEXPORT_TEST(testCharacterBorder, "charborder.odt") { uno::Reference xRun(getRun(getParagraph(1),1), uno::UNO_QUERY); // RTF has just one border attribute (chbrdr) for text border so all side has // the same border with the same padding // Border { const table::BorderLine2 aTopBorder = getProperty(xRun,"CharTopBorder"); CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0xFF6600,0,318,0,0,318), aTopBorder); CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty(xRun,"CharLeftBorder")); CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty(xRun,"CharBottomBorder")); CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty(xRun,"CharRightBorder")); } // Padding (brsp) { const sal_Int32 nTopPadding = getProperty(xRun,"CharTopBorderDistance"); // In the original ODT file the padding is 150, but the unit conversion round it down. CPPUNIT_ASSERT_EQUAL(sal_Int32(141), nTopPadding); CPPUNIT_ASSERT_EQUAL(nTopPadding, getProperty(xRun,"CharLeftBorderDistance")); CPPUNIT_ASSERT_EQUAL(nTopPadding, getProperty(xRun,"CharBottomBorderDistance")); CPPUNIT_ASSERT_EQUAL(nTopPadding, getProperty(xRun,"CharRightBorderDistance")); } // Shadow (brdrsh) /* RTF use just one bool value for shadow so the next conversions are made during an export-import round color: any -> black location: any -> bottom-right width: any -> border width */ { const table::ShadowFormat aShadow = getProperty(xRun, "CharShadowFormat"); CPPUNIT_ASSERT_EQUAL(COL_BLACK, sal_uInt32(aShadow.Color)); CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location); CPPUNIT_ASSERT_EQUAL(sal_Int16(318), aShadow.ShadowWidth); } } DECLARE_RTFEXPORT_TEST(testFdo66743, "fdo66743.rtf") { uno::Reference xTable(getParagraphOrTable(1), uno::UNO_QUERY); uno::Reference xCell = xTable->getCellByName("A1"); // This was too dark, 0x7f7f7f. CPPUNIT_ASSERT_EQUAL(sal_Int32(0xd8d8d8), getProperty(xCell, "BackColor")); } DECLARE_RTFEXPORT_TEST(testFdo68787, "fdo68787.rtf") { uno::Reference xPageStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY); // This was 0, the 'lack of \chftnsep' <-> '0 line width' mapping was missing in the RTF tokenizer / exporter. CPPUNIT_ASSERT_EQUAL(sal_Int32(25), getProperty(xPageStyle, "FootnoteLineRelativeWidth")); } DECLARE_RTFEXPORT_TEST(testFdo74709, "fdo74709.rtf") { uno::Reference xCell = getCell(getParagraphOrTable(1), "B1"); // This was 0, as top/bottom/left/right padding wasn't imported. CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(360)), getProperty(xCell, "RightBorderDistance")); } DECLARE_RTFEXPORT_TEST(testRelsize, "relsize.rtf") { uno::Reference xShape = getShape(1); CPPUNIT_ASSERT_EQUAL(sal_Int16(40), getProperty(xShape, "RelativeWidth")); CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty(xShape, "RelativeWidthRelation")); CPPUNIT_ASSERT_EQUAL(sal_Int16(20), getProperty(xShape, "RelativeHeight")); CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty(xShape, "RelativeHeightRelation")); } DECLARE_RTFEXPORT_TEST(testLineNumbering, "linenumbering.rtf") { uno::Reference xLineNumberingProperties(mxComponent, uno::UNO_QUERY_THROW); uno::Reference xPropertySet = xLineNumberingProperties->getLineNumberingProperties(); CPPUNIT_ASSERT_EQUAL(true, bool(getProperty(xPropertySet, "IsOn"))); CPPUNIT_ASSERT_EQUAL(sal_Int32(5), getProperty(xPropertySet, "Interval")); } DECLARE_RTFEXPORT_TEST(testFdo77600, "fdo77600.rtf") { // This was 'Liberation Serif'. CPPUNIT_ASSERT_EQUAL(OUString("Arial"), getProperty(getRun(getParagraph(1), 3), "CharFontName")); } DECLARE_RTFEXPORT_TEST(testFdo79599, "fdo79599.rtf") { // test for \highlightNN, document has full \colortbl (produced in MS Word 2003 or 2007) // test \highlight11 = dark magenta uno::Reference xRun(getRun(getParagraph(11),1), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x800080), getProperty(xRun, "CharBackColor")); } DECLARE_RTFEXPORT_TEST(testFdo80167, "fdo80167.rtf") { // Problem was that after export, the page break was missing, so this was 1. CPPUNIT_ASSERT_EQUAL(2, getPages()); } DECLARE_RTFEXPORT_TEST(testFdo32613, "fdo32613.odt") { // This was AS_CHARACTER, RTF export did not support writing anchored pictures. CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER, getProperty(getShape(1), "AnchorType")); } DECLARE_RTFEXPORT_TEST(testPictureWrapPolygon, "picture-wrap-polygon.rtf") { // The problem was that the wrap polygon was ignored during import. drawing::PointSequenceSequence aSeqSeq = getProperty(getShape(1), "ContourPolyPolygon"); // This was 0: the polygon list was empty. CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aSeqSeq.getLength()); drawing::PointSequence aSeq = aSeqSeq[0]; CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aSeq.getLength()); // The shape also didn't have negative top / left coordinates. CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(-1177)), getProperty(getShape(1), "HoriOrientPosition")); CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(-67)), getProperty(getShape(1), "VertOrientPosition")); } DECLARE_RTFEXPORT_TEST(testAbi10039, "abi10039.odt") { // Make sure we don't just crash on export, and additionally the shape should not be inline (as it's at-page anchored originally). CPPUNIT_ASSERT(text::TextContentAnchorType_AS_CHARACTER != getProperty(getShape(1), "AnchorType")); } DECLARE_RTFEXPORT_TEST(testAbi10076, "abi10076.odt") { // Just make sure that we don't crash after exporting a fully calculated layout. } DECLARE_RTFEXPORT_TEST(testEm, "em.rtf") { // Test all possible \acc* control words. CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::NONE, getProperty(getRun(getParagraph(1), 1), "CharEmphasis")); CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::DOT_ABOVE, getProperty(getRun(getParagraph(1), 2), "CharEmphasis")); CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::ACCENT_ABOVE, getProperty(getRun(getParagraph(1), 3), "CharEmphasis")); // This was missing. CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::CIRCLE_ABOVE, getProperty(getRun(getParagraph(1), 4), "CharEmphasis")); // This one, too. CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::DOT_BELOW, getProperty(getRun(getParagraph(1), 5), "CharEmphasis")); } DECLARE_RTFEXPORT_TEST(testNumberingFont, "numbering-font.rtf") { uno::Reference xStyle(getStyles("CharacterStyles")->getByName("ListLabel 1"), uno::UNO_QUERY); // This was Liberation Serif, i.e. custom font of the numbering itself ("1.\t") was lost on import. CPPUNIT_ASSERT_EQUAL(OUString("Verdana"), getProperty(xStyle, "CharFontName")); } DECLARE_RTFEXPORT_TEST(testFdo82860, "fdo82860.odt") { // The problem was that: // 1) The import tried to use fieldmarks for SHAPE fields // 2) The exporter did not handle "shape with textbox" text. uno::Reference xTextRange(getShape(1), uno::UNO_QUERY); uno::Reference xText = xTextRange->getText(); CPPUNIT_ASSERT_EQUAL(OUString("hello"), getParagraphOfText(1, xText)->getString()); } DECLARE_RTFEXPORT_TEST(testFdo82858, "fdo82858.docx") { // This was table::BorderLineStyle::SOLID, exporter failed to write explicit no line when line color was written. CPPUNIT_ASSERT_EQUAL(table::BorderLineStyle::NONE, getProperty(getShape(1), "TopBorder").LineStyle); } DECLARE_RTFEXPORT_TEST(testCjklist12, "cjklist12.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::AIU_HALFWIDTH_JA, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist13, "cjklist13.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::IROHA_HALFWIDTH_JA, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist16, "cjklist16.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_TRADITIONAL_JA, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist20, "cjklist20.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::AIU_FULLWIDTH_JA, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist21, "cjklist21.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::IROHA_FULLWIDTH_JA, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist24, "cjklist24.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::HANGUL_SYLLABLE_KO, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist25, "cjklist25.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::HANGUL_JAMO_KO, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist30, "cjklist30.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::TIAN_GAN_ZH, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist31, "cjklist31.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::DI_ZI_ZH, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist34, "cjklist34.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_UPPER_ZH_TW, numFormat); } DECLARE_RTFEXPORT_TEST(testCjklist38, "cjklist38.rtf") { sal_Int16 numFormat; CPPUNIT_ASSERT(CjkNumberedListTestHelper(numFormat)); CPPUNIT_ASSERT_EQUAL(style::NumberingType::NUMBER_UPPER_ZH, numFormat); } DECLARE_RTFEXPORT_TEST(testTableRtl, "table-rtl.rtf") { uno::Reference xTablesSupplier(mxComponent, uno::UNO_QUERY); uno::Reference xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); // This was text::WritingMode2::LR_TB, i.e. direction of the table was ignored. CPPUNIT_ASSERT_EQUAL(text::WritingMode2::RL_TB, getProperty(xTable, "WritingMode")); } DECLARE_RTFEXPORT_TEST(testNumOverrideStart, "num-override-start.rtf") { // The numbering on the second level was "3.1", not "1.3". uno::Reference xRules = getProperty< uno::Reference >(getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules"); CPPUNIT_ASSERT_EQUAL(sal_Int16(1), comphelper::SequenceAsHashMap(xRules->getByIndex(0))["StartWith"].get()); CPPUNIT_ASSERT_EQUAL(sal_Int16(3), comphelper::SequenceAsHashMap(xRules->getByIndex(1))["StartWith"].get()); } DECLARE_RTFEXPORT_TEST(testFdo82006, "fdo82006.rtf") { // These were 176 (100 twips), as \sbauto and \sbbefore were ignored. CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(280)), getProperty(getParagraph(0), "ParaTopMargin")); CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(280)), getProperty(getParagraph(0), "ParaBottomMargin")); } DECLARE_RTFEXPORT_TEST(testTdf88583, "tdf88583.odt") { // This was FillStyle_NONE, as background color was missing from the color table during export. CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, getProperty(getParagraph(1), "FillStyle")); CPPUNIT_ASSERT_EQUAL(static_cast(0x00cc00), getProperty(getParagraph(1), "FillColor")); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */