diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-15 20:27:44 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-15 20:34:10 -0400 |
commit | 90f7bd61fb1c4665051f721bb7721277a79eb267 (patch) | |
tree | 6b0aaec3ff858d368bec6ba8d06b7ffad4d8ab45 /sc | |
parent | fd70beaccb8655ed962bb306ed34c6c134e3922e (diff) |
fdo#77537: Write export test for this.
Change-Id: I2960713b1005c5f91fe78d12e33f1786978eac67
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 113 |
1 files changed, 96 insertions, 17 deletions
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index f984e69e7e59..ab25140cf6e6 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -44,6 +44,7 @@ #include <editeng/section.hxx> #include <editeng/crossedoutitem.hxx> #include <editeng/borderline.hxx> +#include <editeng/fontitem.hxx> #include <formula/grammar.hxx> #include <com/sun/star/table/BorderLineStyle.hpp> @@ -441,6 +442,19 @@ void setAttribute( ScFieldEditEngine& rEE, sal_Int32 nPara, sal_Int32 nStart, sa } } +void setFont( ScFieldEditEngine& rEE, sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, const OUString& rFontName ) +{ + ESelection aSel; + aSel.nStartPara = aSel.nEndPara = nPara; + aSel.nStartPos = nStart; + aSel.nEndPos = nEnd; + + SfxItemSet aItemSet = rEE.GetEmptyItemSet(); + SvxFontItem aItem(FAMILY_MODERN, rFontName, "", PITCH_VARIABLE, RTL_TEXTENCODING_UTF8, EE_CHAR_FONTINFO); + aItemSet.Put(aItem); + rEE.QuickSetAttribs(aItemSet, aSel); +} + } void ScExportTest::testNamedRangeBugfdo62729() @@ -525,6 +539,23 @@ void ScExportTest::testRichTextExportODS() return false; } + static bool isFont(const editeng::Section& rAttr, const OUString& rFontName) + { + if (rAttr.maAttributes.empty()) + return false; + + std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end(); + for (; it != itEnd; ++it) + { + const SfxPoolItem* p = *it; + if (p->Which() != EE_CHAR_FONTINFO) + continue; + + return static_cast<const SvxFontItem*>(p)->GetFamilyName() == rFontName; + } + return false; + } + bool checkB2(const EditTextObject* pText) const { if (!pText) @@ -649,27 +680,62 @@ void ScExportTest::testRichTextExportODS() return true; } + bool checkB7(const EditTextObject* pText) const + { + if (!pText) + return false; + + if (pText->GetParagraphCount() != 1) + return false; + + if (pText->GetText(0) != "Font1 and Font2") + return false; + + std::vector<editeng::Section> aSecAttrs; + pText->GetAllSections(aSecAttrs); + if (aSecAttrs.size() != 3) + return false; + + // First section should have "Courier" font applied. + const editeng::Section* pAttr = &aSecAttrs[0]; + if (pAttr->mnParagraph != 0 ||pAttr->mnStart != 0 || pAttr->mnEnd != 5) + return false; + + if (pAttr->maAttributes.size() != 1 || !isFont(*pAttr, "Courier")) + return false; + + // Last section should have "Luxi Mono" applied. + pAttr = &aSecAttrs[2]; + if (pAttr->mnParagraph != 0 ||pAttr->mnStart != 10 || pAttr->mnEnd != 15) + return false; + + if (pAttr->maAttributes.size() != 1 || !isFont(*pAttr, "Luxi Mono")) + return false; + + return true; + } + } aCheckFunc; // Start with an empty document, put one edit text cell, and make sure it // survives the save and reload. - ScDocShellRef xOrigDocSh = loadDoc("empty.", ODS); + ScDocShellRef xOrigDocSh = loadDoc("empty.", ODS, true); ScDocument* pDoc = xOrigDocSh->GetDocument(); CPPUNIT_ASSERT(pDoc); CPPUNIT_ASSERT_MESSAGE("This document should at least have one sheet.", pDoc->GetTableCount() > 0); // Insert an edit text cell. - ScFieldEditEngine& rEE = pDoc->GetEditEngine(); - rEE.SetText("Bold and Italic"); + ScFieldEditEngine* pEE = &pDoc->GetEditEngine(); + pEE->SetText("Bold and Italic"); // Set the 'Bold' part bold. - setAttribute(rEE, 0, 0, 4, EE_CHAR_WEIGHT); + setAttribute(*pEE, 0, 0, 4, EE_CHAR_WEIGHT); // Set the 'Italic' part italic. - setAttribute(rEE, 0, 9, 15, EE_CHAR_ITALIC); + setAttribute(*pEE, 0, 9, 15, EE_CHAR_ITALIC); ESelection aSel; aSel.nStartPara = aSel.nEndPara = 0; // Set this edit text to cell B2. - pDoc->SetEditText(ScAddress(1,1,0), rEE.CreateTextObject()); + pDoc->SetEditText(ScAddress(1,1,0), pEE->CreateTextObject()); const EditTextObject* pEditText = pDoc->GetEditText(ScAddress(1,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B2 value.", aCheckFunc.checkB2(pEditText)); @@ -680,20 +746,22 @@ void ScExportTest::testRichTextExportODS() pDoc = xNewDocSh->GetDocument(); CPPUNIT_ASSERT(pDoc); CPPUNIT_ASSERT_MESSAGE("Reloaded document should at least have one sheet.", pDoc->GetTableCount() > 0); + pEE = &pDoc->GetEditEngine(); // Make sure the content of B2 is still intact. CPPUNIT_ASSERT_MESSAGE("Incorret B2 value.", aCheckFunc.checkB2(pEditText)); // Insert a multi-line content to B4. - rEE.Clear(); - rEE.SetText("One\nTwo\nThree"); - pDoc->SetEditText(ScAddress(3,1,0), rEE.CreateTextObject()); + pEE->Clear(); + pEE->SetText("One\nTwo\nThree"); + pDoc->SetEditText(ScAddress(3,1,0), pEE->CreateTextObject()); pEditText = pDoc->GetEditText(ScAddress(3,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B4 value.", aCheckFunc.checkB4(pEditText)); // Reload the doc again, and check the content of B2 and B4. ScDocShellRef xNewDocSh2 = saveAndReload(xNewDocSh, ODS); pDoc = xNewDocSh2->GetDocument(); + pEE = &pDoc->GetEditEngine(); xNewDocSh->DoClose(); pEditText = pDoc->GetEditText(ScAddress(1,1,0)); @@ -702,22 +770,31 @@ void ScExportTest::testRichTextExportODS() CPPUNIT_ASSERT_MESSAGE("Incorret B4 value.", aCheckFunc.checkB4(pEditText)); // Insert a multi-line content to B5, but this time, set some empty paragraphs. - rEE.Clear(); - rEE.SetText("\nTwo\nThree\n\nFive\n"); - pDoc->SetEditText(ScAddress(4,1,0), rEE.CreateTextObject()); + pEE->Clear(); + pEE->SetText("\nTwo\nThree\n\nFive\n"); + pDoc->SetEditText(ScAddress(4,1,0), pEE->CreateTextObject()); pEditText = pDoc->GetEditText(ScAddress(4,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B5 value.", aCheckFunc.checkB5(pEditText)); // Insert a text with strikethrough in B6. - rEE.Clear(); - rEE.SetText("Strike Me"); + pEE->Clear(); + pEE->SetText("Strike Me"); // Set the 'Strike' part strikethrough. - setAttribute(rEE, 0, 0, 6, EE_CHAR_STRIKEOUT); - pDoc->SetEditText(ScAddress(5,1,0), rEE.CreateTextObject()); + setAttribute(*pEE, 0, 0, 6, EE_CHAR_STRIKEOUT); + pDoc->SetEditText(ScAddress(5,1,0), pEE->CreateTextObject()); pEditText = pDoc->GetEditText(ScAddress(5,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B6 value.", aCheckFunc.checkB6(pEditText)); - // Reload the doc again, and check the content of B2, B4 and B6. + // Insert a text with different font segments in B7. + pEE->Clear(); + pEE->SetText("Font1 and Font2"); + setFont(*pEE, 0, 0, 5, "Courier"); + setFont(*pEE, 0, 10, 15, "Luxi Mono"); + pDoc->SetEditText(ScAddress(6,1,0), pEE->CreateTextObject()); + pEditText = pDoc->GetEditText(ScAddress(6,1,0)); + CPPUNIT_ASSERT_MESSAGE("Incorret B7 value.", aCheckFunc.checkB7(pEditText)); + + // Reload the doc again, and check the content of B2, B4, B6 and B7. ScDocShellRef xNewDocSh3 = saveAndReload(xNewDocSh2, ODS); pDoc = xNewDocSh3->GetDocument(); xNewDocSh2->DoClose(); @@ -730,6 +807,8 @@ void ScExportTest::testRichTextExportODS() CPPUNIT_ASSERT_MESSAGE("Incorret B5 value.", aCheckFunc.checkB5(pEditText)); pEditText = pDoc->GetEditText(ScAddress(5,1,0)); CPPUNIT_ASSERT_MESSAGE("Incorret B6 value.", aCheckFunc.checkB6(pEditText)); + pEditText = pDoc->GetEditText(ScAddress(6,1,0)); + CPPUNIT_ASSERT_MESSAGE("Incorret B7 value.", aCheckFunc.checkB7(pEditText)); xNewDocSh3->DoClose(); } |