summaryrefslogtreecommitdiff
path: root/editeng/qa
diff options
context:
space:
mode:
Diffstat (limited to 'editeng/qa')
-rw-r--r--editeng/qa/editeng/editeng.cxx34
1 files changed, 32 insertions, 2 deletions
diff --git a/editeng/qa/editeng/editeng.cxx b/editeng/qa/editeng/editeng.cxx
index 5c1f23e7e389..71a99414e4aa 100644
--- a/editeng/qa/editeng/editeng.cxx
+++ b/editeng/qa/editeng/editeng.cxx
@@ -9,8 +9,6 @@
#include <test/bootstrapfixture.hxx>
-#include <memory>
-
#include <editeng/editeng.hxx>
#include <sfx2/app.hxx>
#include <svtools/parrtf.hxx>
@@ -54,6 +52,7 @@ public:
void NextToken(int nToken) override;
int m_nStyles = 0;
+ std::vector<int> m_aStyleValues;
};
StyleCounter::StyleCounter(SvStream& rStream)
@@ -66,6 +65,7 @@ void StyleCounter::NextToken(int nToken)
if (nToken == RTF_S)
{
++m_nStyles;
+ m_aStyleValues.push_back(nTokenValue);
}
}
@@ -94,6 +94,36 @@ CPPUNIT_TEST_FIXTURE(Test, testRTFStyleExport)
// i.e. unreferenced paragraph styles were exported.
CPPUNIT_ASSERT_EQUAL(0, xReader->m_nStyles);
}
+
+CPPUNIT_TEST_FIXTURE(Test, testRTFStyleExportReferToStyle)
+{
+ // Given a document with one unused and one used style:
+ EditEngine aEditEngine(mpItemPool.get());
+ rtl::Reference<SfxStyleSheetPool> xStyles(new SfxStyleSheetPool(*mpItemPool));
+ xStyles->Make("mystyle", SfxStyleFamily::Para);
+ xStyles->Make("mystyle2", SfxStyleFamily::Para);
+ auto pStyle = static_cast<SfxStyleSheet*>(xStyles->Find("mystyle2", SfxStyleFamily::Para));
+ aEditEngine.SetStyleSheetPool(xStyles.get());
+ OUString aText = u"mytest"_ustr;
+ aEditEngine.SetText(aText);
+ aEditEngine.SetStyleSheet(0, pStyle);
+
+ // When copying a word from that document:
+ uno::Reference<datatransfer::XTransferable> xData
+ = aEditEngine.CreateTransferable(ESelection(0, 0, 0, aText.getLength()));
+
+ // Then make sure the declared and referred style indexes for the used style match:
+ auto pData = dynamic_cast<EditDataObject*>(xData.get());
+ SvMemoryStream& rStream = pData->GetRTFStream();
+ tools::SvRef<StyleCounter> xReader(new StyleCounter(rStream));
+ CPPUNIT_ASSERT(xReader->CallParser() != SvParserState::Error);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), xReader->m_aStyleValues.size());
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1
+ // - Actual : 2
+ // i.e. \s2 was used to refer to \s1, so the paragraph style was lost.
+ CPPUNIT_ASSERT_EQUAL(xReader->m_aStyleValues[0], xReader->m_aStyleValues[1]);
+}
}
CPPUNIT_PLUGIN_IMPLEMENT();