summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2019-01-04 02:51:36 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-01-07 10:16:07 +0100
commit51f4cc7daba8df5f995702405631c24c8d9bf36c (patch)
tree2c9617839b9e2d9b4be495f68786ce6a8c74381e /sw/qa
parente562b6cc878a2f68c7e1b5b76f82d6b2548dbf2a (diff)
Unfloat: Add some tests about the visibility of the unfloat button
Reviewed-on: https://gerrit.libreoffice.org/65820 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> (cherry picked from commit 9c4a374baa4d18dec4066e547d76a40501b20d45) Change-Id: Id0bc6e5be5a55480233afeae44eccac24fa01434 Reviewed-on: https://gerrit.libreoffice.org/65871 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/uiwriter/data/floating_table/small_floating_table.odtbin0 -> 8977 bytes
-rw-r--r--sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.docbin0 -> 69120 bytes
-rw-r--r--sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.docxbin0 -> 14282 bytes
-rw-r--r--sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.odtbin0 -> 9331 bytes
-rw-r--r--sw/qa/extras/uiwriter/data/floating_table/unfloatable_small_floating_table.docxbin0 -> 13381 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx118
6 files changed, 117 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/data/floating_table/small_floating_table.odt b/sw/qa/extras/uiwriter/data/floating_table/small_floating_table.odt
new file mode 100644
index 000000000000..6b77569f2583
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/floating_table/small_floating_table.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.doc b/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.doc
new file mode 100644
index 000000000000..e5247f1598c2
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.doc
Binary files differ
diff --git a/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.docx b/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.docx
new file mode 100644
index 000000000000..cef1f7bf685d
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.docx
Binary files differ
diff --git a/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.odt b/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.odt
new file mode 100644
index 000000000000..eb2534ba4c52
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/floating_table/unfloatable_floating_table.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/data/floating_table/unfloatable_small_floating_table.docx b/sw/qa/extras/uiwriter/data/floating_table/unfloatable_small_floating_table.docx
new file mode 100644
index 000000000000..d51056af1177
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/floating_table/unfloatable_small_floating_table.docx
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 239700294b71..088d02ca4761 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -11,20 +11,36 @@
#include <com/sun/star/awt/FontSlant.hpp>
#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
{
public:
void testTdf101534();
+ void testUnfloatButtonSmallTable();
+ void testUnfloatButton();
+ void testUnfloatButtonReadOnlyMode();
CPPUNIT_TEST_SUITE(SwUiWriterTest2);
CPPUNIT_TEST(testTdf101534);
+ CPPUNIT_TEST(testUnfloatButtonSmallTable);
+ CPPUNIT_TEST(testUnfloatButton);
+ CPPUNIT_TEST(testUnfloatButtonReadOnlyMode);
CPPUNIT_TEST_SUITE_END();
};
@@ -55,6 +71,106 @@ void SwUiWriterTest2::testTdf101534()
CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE));
}
+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: */