Kaydet (Commit) 9c4a374b authored tarafından Tamás Zolnai's avatar Tamás Zolnai

Unfloat: Add some tests about the visibility of the unfloat button

Change-Id: Id0bc6e5be5a55480233afeae44eccac24fa01434
Reviewed-on: https://gerrit.libreoffice.org/65820
Tested-by: Jenkins
Reviewed-by: 's avatarTamás Zolnai <tamas.zolnai@collabora.com>
üst c4218b36
......@@ -21,12 +21,20 @@
#include <swdtflvr.hxx>
#include <wrtsh.hxx>
#include <redline.hxx>
#include <flyfrms.hxx>
#include <UndoManager.hxx>
#include <edtwin.hxx>
#include <view.hxx>
#include <sortedobjs.hxx>
#include <anchoredobject.hxx>
#include <FrameControlsManager.hxx>
#include <FloatingTableButton.hxx>
namespace
{
char const DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data2/";
}
char const FLOATING_TABLE_DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data/floating_table/";
} // namespace
/// Second set of tests asserting the behavior of Writer user interface shells.
class SwUiWriterTest2 : public SwModelTestBase
......@@ -43,6 +51,9 @@ public:
void testTdf119019();
void testTdf119824();
void testTdf105413();
void testUnfloatButtonSmallTable();
void testUnfloatButton();
void testUnfloatButtonReadOnlyMode();
CPPUNIT_TEST_SUITE(SwUiWriterTest2);
CPPUNIT_TEST(testRedlineMoveInsertInDelete);
......@@ -56,6 +67,9 @@ public:
CPPUNIT_TEST(testTdf119019);
CPPUNIT_TEST(testTdf119824);
CPPUNIT_TEST(testTdf105413);
CPPUNIT_TEST(testUnfloatButtonSmallTable);
CPPUNIT_TEST(testUnfloatButton);
CPPUNIT_TEST(testUnfloatButtonReadOnlyMode);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -521,6 +535,106 @@ void SwUiWriterTest2::testTdf105413()
getProperty<OUString>(getParagraph(1), "ParaStyleName"));
}
void SwUiWriterTest2::testUnfloatButtonSmallTable()
{
// The floating table in the test document is too small, so we don't provide an unfloat button
load(FLOATING_TABLE_DATA_DIRECTORY, "small_floating_table.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
const SwSortedObjs* pAnchored
= pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
CPPUNIT_ASSERT(pAnchored);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pAnchored->size());
SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
SwFlyFrame* pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
CPPUNIT_ASSERT(pFlyFrame);
CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell));
SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
CPPUNIT_ASSERT(pObj);
pWrtShell->SelectObj(Point(), 0, pObj);
CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell));
}
void SwUiWriterTest2::testUnfloatButton()
{
// Different use cases where unfloat button should be visible
const std::vector<OUString> aTestFiles = {
"unfloatable_floating_table.odt", // Typical use case of multipage floating table
"unfloatable_floating_table.docx", // Need to test the DOCX import whether we detect the floating table correctly
"unfloatable_floating_table.doc", // Also the DOC import
"unfloatable_small_floating_table.docx" // Atypical use case, when the table is small, but because of it's position is it broken to two pages
};
for (const OUString& aTestFile : aTestFiles)
{
OString sTestFileName = OUStringToOString(aTestFile, RTL_TEXTENCODING_UTF8);
OString sFailureMessage = OString("Failure in the test file: ") + sTestFileName;
load(FLOATING_TABLE_DATA_DIRECTORY, sTestFileName.getStr());
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pWrtShell);
const SwSortedObjs* pAnchored;
if (sTestFileName == "unfloatable_small_floating_table.docx")
pAnchored = pWrtShell->GetLayout()
->GetLower()
->GetLower()
->GetLower()
->GetNext()
->GetDrawObjs();
else
pAnchored = pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pAnchored);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailureMessage.getStr(), static_cast<size_t>(1),
pAnchored->size());
SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
// The unfloat button is not visible until it gets selected
SwFlyFrame* pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pFlyFrame);
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(),
!pFlyFrame->IsShowUnfloatButton(pWrtShell));
SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pObj);
pWrtShell->SelectObj(Point(), 0, pObj);
CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pFlyFrame->IsShowUnfloatButton(pWrtShell));
}
}
void SwUiWriterTest2::testUnfloatButtonReadOnlyMode()
{
// In read only mode we don't show the unfloat button even if we have a multipage floating table
load(FLOATING_TABLE_DATA_DIRECTORY, "unfloatable_floating_table.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
pWrtShell->SetReadonlyOption(true);
const SwSortedObjs* pAnchored
= pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
CPPUNIT_ASSERT(pAnchored);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pAnchored->size());
SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
SwFlyFrame* pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
CPPUNIT_ASSERT(pFlyFrame);
CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell));
SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
CPPUNIT_ASSERT(pObj);
pWrtShell->SelectObj(Point(), 0, pObj);
CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell));
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -24,6 +24,7 @@
#include <vector>
#include <frmfmt.hxx>
#include <anchoredobject.hxx>
#include <swdllapi.h>
class SwFormatAnchor;
class SwPageFrame;
......@@ -58,7 +59,7 @@ bool CalcClipRect( const SdrObject *pSdrObj, SwRect &rRect, bool bMove = true );
#i26791# - inherit also from <SwAnchoredFlyFrame>
*/
class SwFlyFrame : public SwLayoutFrame, public SwAnchoredObject
class SW_DLLPUBLIC SwFlyFrame : public SwLayoutFrame, public SwAnchoredObject
{
// is allowed to lock, implemented in frmtool.cxx
friend void AppendObj(SwFrame *const pFrame, SwPageFrame *const pPage, SwFrameFormat *const pFormat, const SwFormatAnchor & rAnch);
......@@ -271,9 +272,9 @@ public:
void InvalidateContentPos();
void SelectionHasChanged(SwFEShell* pShell);
bool IsShowUnfloatButton(SwWrtShell* pWrtSh) const;
private:
bool IsShowUnfloatButton(SwWrtShell* pWrtSh) const;
void UpdateUnfloatButton(SwWrtShell* pWrtSh, bool bShow) const;
void PaintDecorators() const;
};
......
......@@ -20,6 +20,7 @@
#define INCLUDED_SW_SOURCE_CORE_INC_LAYFRM_HXX
#include "frame.hxx"
#include <swdllapi.h>
class SwAnchoredObject;
class SwContentFrame;
......@@ -31,7 +32,7 @@ class SwBorderAttrs;
class SwFormatFrameSize;
class SwCellFrame;
class SwLayoutFrame: public SwFrame
class SW_DLLPUBLIC SwLayoutFrame: public SwFrame
{
// The SwFrame in disguise
friend class SwFlowFrame;
......
......@@ -21,6 +21,7 @@
#include <sal/types.h>
#include <vector>
#include <swdllapi.h>
class SwAnchoredObject;
......@@ -45,7 +46,7 @@ class SwAnchoredObject;
If one of the sort criteria attributes of an anchored object changes,
the sorting has to be updated - use method <Update(..)>
*/
class SwSortedObjs
class SW_DLLPUBLIC SwSortedObjs
{
private:
std::vector< SwAnchoredObject* > maSortedObjLst;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment