diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2017-10-06 21:23:59 +0200 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2017-10-16 12:24:01 +0200 |
commit | 1ca2a2119ad3e910f848344d51ba9ec173880715 (patch) | |
tree | 2894def2be4a56558da47239530d4a903d51d05e | |
parent | 2f2234102e450b5828d2633d2512d94f212a4362 (diff) |
tdf#99689 add tests for subscript attribute in ToX
And superscript.
Change-Id: Ia74fe20d3f105d2ce19064742f603d3df75c3581
Reviewed-on: https://gerrit.libreoffice.org/43211
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
-rw-r--r-- | sw/qa/extras/uiwriter/data/tdf99689.odt | bin | 0 -> 15771 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/data/tdf99689_figures.odt | bin | 0 -> 466344 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/data/tdf99689_tables.odt | bin | 0 -> 11267 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 102 |
4 files changed, 102 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/data/tdf99689.odt b/sw/qa/extras/uiwriter/data/tdf99689.odt Binary files differnew file mode 100644 index 000000000000..456309a96de4 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf99689.odt diff --git a/sw/qa/extras/uiwriter/data/tdf99689_figures.odt b/sw/qa/extras/uiwriter/data/tdf99689_figures.odt Binary files differnew file mode 100644 index 000000000000..973e48d39638 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf99689_figures.odt diff --git a/sw/qa/extras/uiwriter/data/tdf99689_tables.odt b/sw/qa/extras/uiwriter/data/tdf99689_tables.odt Binary files differnew file mode 100644 index 000000000000..15b386eabe28 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf99689_tables.odt diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 2b2f04eff480..23c95a805283 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -51,6 +51,7 @@ #include <svx/svdpage.hxx> #include <svx/svdview.hxx> +#include "svl/itemiter.hxx" #include <editeng/eeitem.hxx> #include <editeng/scripttypeitem.hxx> @@ -276,6 +277,9 @@ public: #endif void testLinesInSectionInTable(); void testParagraphOfTextRange(); + void testTdf99689TableOfContents(); + void testTdf99689TableOfFigures(); + void testTdf99689TableOfTables(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -435,6 +439,9 @@ public: #endif CPPUNIT_TEST(testLinesInSectionInTable); CPPUNIT_TEST(testParagraphOfTextRange); + CPPUNIT_TEST(testTdf99689TableOfContents); + CPPUNIT_TEST(testTdf99689TableOfFigures); + CPPUNIT_TEST(testTdf99689TableOfTables); CPPUNIT_TEST_SUITE_END(); private: @@ -3165,6 +3172,101 @@ void SwUiWriterTest::testTdf75137() CPPUNIT_ASSERT(firstIndex != secondIndex); } +namespace +{ + sal_Int32 lcl_getAttributeIDFromHints( const SwpHints& hints ) + { + for (size_t i = 0; i < hints.Count(); ++i) + { + const SwTextAttr* hint = hints.Get(i); + if( hint->Which() == RES_TXTATR_AUTOFMT ) + { + const SwFormatAutoFormat& rFmt = hint->GetAutoFormat(); + SfxItemIter aIter( *rFmt.GetStyleHandle() ); + return aIter.GetCurItem()->Which(); + } + } + return -1; + } +} + +void SwUiWriterTest::testTdf99689TableOfContents() +{ + SwDoc* pDoc = createDoc("tdf99689.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->GotoNextTOXBase(); + const SwTOXBase* pTOXBase = pWrtShell->GetCurTOX(); + pWrtShell->UpdateTableOf(*pTOXBase); + SwCursorShell * pShell(pDoc->GetEditShell()); + SwTextNode* pTitleNode = pShell->GetCursor()->GetNode().GetTextNode(); + SwNodeIndex aIdx ( *pTitleNode ); + // skip the title + pDoc->GetNodes().GoNext( &aIdx ); + + // skip the first header. No attributes there. + // next node should contain superscript + SwTextNode* pNext = static_cast<SwTextNode*> (pDoc->GetNodes().GoNext( &aIdx )); + CPPUNIT_ASSERT( pNext->HasHints() ); + sal_Int32 nAttrType = lcl_getAttributeIDFromHints( pNext->GetSwpHints() ); + CPPUNIT_ASSERT_EQUAL(RES_CHRATR_ESCAPEMENT, static_cast<RES_CHRATR>(nAttrType) ); + + // next node should contain subscript + pNext = static_cast<SwTextNode*> (pDoc->GetNodes().GoNext( &aIdx )); + CPPUNIT_ASSERT( pNext->HasHints() ); + nAttrType = lcl_getAttributeIDFromHints( pNext->GetSwpHints() ); + CPPUNIT_ASSERT_EQUAL(RES_CHRATR_ESCAPEMENT, static_cast<RES_CHRATR>(nAttrType) ); +} + +void SwUiWriterTest::testTdf99689TableOfFigures() +{ + SwDoc* pDoc = createDoc("tdf99689_figures.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->GotoNextTOXBase(); + const SwTOXBase* pTOXBase = pWrtShell->GetCurTOX(); + pWrtShell->UpdateTableOf(*pTOXBase); + SwCursorShell * pShell(pDoc->GetEditShell()); + SwTextNode* pTitleNode = pShell->GetCursor()->GetNode().GetTextNode(); + SwNodeIndex aIdx ( *pTitleNode ); + + // skip the title + // next node should contain subscript + SwTextNode* pNext = static_cast<SwTextNode*> (pDoc->GetNodes().GoNext( &aIdx )); + CPPUNIT_ASSERT( pNext->HasHints() ); + sal_Int32 nAttrType = lcl_getAttributeIDFromHints( pNext->GetSwpHints() ); + CPPUNIT_ASSERT_EQUAL(RES_CHRATR_ESCAPEMENT, static_cast<RES_CHRATR>(nAttrType) ); + + // next node should contain superscript + pNext = static_cast<SwTextNode*> (pDoc->GetNodes().GoNext( &aIdx )); + CPPUNIT_ASSERT( pNext->HasHints() ); + nAttrType = lcl_getAttributeIDFromHints( pNext->GetSwpHints() ); + CPPUNIT_ASSERT_EQUAL(RES_CHRATR_ESCAPEMENT, static_cast<RES_CHRATR>(nAttrType) ); +} + +void SwUiWriterTest::testTdf99689TableOfTables() +{ + SwDoc* pDoc = createDoc("tdf99689_tables.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->GotoNextTOXBase(); + const SwTOXBase* pTOXBase = pWrtShell->GetCurTOX(); + pWrtShell->UpdateTableOf(*pTOXBase); + SwCursorShell * pShell(pDoc->GetEditShell()); + SwTextNode* pTitleNode = pShell->GetCursor()->GetNode().GetTextNode(); + SwNodeIndex aIdx ( *pTitleNode ); + + // skip the title + // next node should contain superscript + SwTextNode* pNext = static_cast<SwTextNode*> (pDoc->GetNodes().GoNext( &aIdx )); + CPPUNIT_ASSERT( pNext->HasHints() ); + sal_Int32 nAttrType = lcl_getAttributeIDFromHints( pNext->GetSwpHints() ); + CPPUNIT_ASSERT_EQUAL(RES_CHRATR_ESCAPEMENT, static_cast<RES_CHRATR>(nAttrType) ); + + // next node should contain subscript + pNext = static_cast<SwTextNode*> (pDoc->GetNodes().GoNext( &aIdx )); + CPPUNIT_ASSERT( pNext->HasHints() ); + nAttrType = lcl_getAttributeIDFromHints( pNext->GetSwpHints() ); + CPPUNIT_ASSERT_EQUAL(RES_CHRATR_ESCAPEMENT, static_cast<RES_CHRATR>(nAttrType) ); +} + void SwUiWriterTest::testTdf83798() { SwDoc* pDoc = createDoc("tdf83798.odt"); |