sw/qa/extras/tiledrendering/data/drop_down_form_field2.odt |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx             |   62 ++++++++++++-
 2 files changed, 61 insertions(+), 1 deletion(-)

New commits:
commit 286ee5a966d5c729fef5cefd58b572247697c4fc
Author:     Tamás Zolnai <tamas.zol...@collabora.com>
AuthorDate: Thu May 7 12:25:51 2020 +0200
Commit:     Tamás Zolnai <tamas.zol...@collabora.com>
CommitDate: Sat May 9 08:17:36 2020 +0200

    lok: MSForms: add a test case about editing drop down form field.
    
    Change-Id: I926b322d3af3047fc72c6ee9b923bc4435111328
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93661
    Tested-by: Tamás Zolnai <tamas.zol...@collabora.com>
    Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com>

diff --git a/sw/qa/extras/tiledrendering/data/drop_down_form_field2.odt 
b/sw/qa/extras/tiledrendering/data/drop_down_form_field2.odt
new file mode 100644
index 000000000000..7793aff4e91b
Binary files /dev/null and 
b/sw/qa/extras/tiledrendering/data/drop_down_form_field2.odt differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index f7cc2d67d16f..994188aaac6f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -48,6 +48,7 @@
 #include <svx/svxids.hrc>
 #include <flddat.hxx>
 #include <basesh.hxx>
+#include <vcl/ITiledRenderable.hxx>
 
 static char const DATA_DIRECTORY[] = "/sw/qa/extras/tiledrendering/data/";
 
@@ -129,6 +130,7 @@ public:
     void testHyperlink();
     void testFieldmark();
     void testDropDownFormFieldButton();
+    void testDropDownFormFieldButtonEditing();
 
     CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -196,6 +198,7 @@ public:
     CPPUNIT_TEST(testHyperlink);
     CPPUNIT_TEST(testFieldmark);
     CPPUNIT_TEST(testDropDownFormFieldButton);
+    CPPUNIT_TEST(testDropDownFormFieldButtonEditing);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -2557,7 +2560,7 @@ void SwTiledRenderingTest::testDropDownFormFieldButton()
     pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
     CPPUNIT_ASSERT(m_aFormFieldButton.isEmpty());
 
-    // Do a tile rendering to trigger the button message with a valide text 
area
+    // Do a tile rendering to trigger the button message with a valid text area
     size_t nCanvasWidth = 1024;
     size_t nCanvasHeight = 512;
     std::vector<unsigned char> aPixmap(nCanvasWidth * nCanvasHeight * 4, 0);
@@ -2615,6 +2618,63 @@ void SwTiledRenderingTest::testDropDownFormFieldButton()
     }
 }
 
+void SwTiledRenderingTest::testDropDownFormFieldButtonEditing()
+{
+    SwXTextDocument* pXTextDocument = createDoc("drop_down_form_field2.odt");
+    pXTextDocument->setClientVisibleArea(tools::Rectangle(0, 0, 10000, 4000));
+
+    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    
pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback,
 this);
+
+    // Move the cursor to trigger displaying of the field button.
+    pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    CPPUNIT_ASSERT(m_aFormFieldButton.isEmpty());
+
+    // Do a tile rendering to trigger the button message with a valid text area
+    size_t nCanvasWidth = 1024;
+    size_t nCanvasHeight = 512;
+    std::vector<unsigned char> aPixmap(nCanvasWidth * nCanvasHeight * 4, 0);
+    ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::DEFAULT);
+    pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+    pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, 
nCanvasHeight),
+                                                    Fraction(1.0), Point(), 
aPixmap.data());
+    pXTextDocument->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, 
/*nTilePosX=*/0,
+                              /*nTilePosY=*/0, /*nTileWidth=*/10000, 
/*nTileHeight=*/4000);
+
+    // The item with the index '1' is selected by default
+    CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty());
+    {
+        std::stringstream aStream(m_aFormFieldButton.getStr());
+        boost::property_tree::ptree aTree;
+        boost::property_tree::read_json(aStream, aTree);
+
+        OString sSelected = 
aTree.get_child("params").get_child("selected").get_value<std::string>().c_str();
+        CPPUNIT_ASSERT_EQUAL(OString("1"), sSelected);
+    }
+    m_aFormFieldButton = "";
+
+    // Trigger a form field event to select a different item.
+    vcl::ITiledRenderable::StringMap aArguments;
+    aArguments["type"] = "drop-down";
+    aArguments["cmd"] = "selected";
+    aArguments["data"] = "3";
+    pXTextDocument->executeFromFieldEvent(aArguments);
+
+    // Do a tile rendering to trigger the button message.
+    pXTextDocument->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, 
/*nTilePosX=*/0,
+                              /*nTilePosY=*/0, /*nTileWidth=*/10000, 
/*nTileHeight=*/4000);
+
+    CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty());
+    {
+        std::stringstream aStream(m_aFormFieldButton.getStr());
+        boost::property_tree::ptree aTree;
+        boost::property_tree::read_json(aStream, aTree);
+
+        OString sSelected = 
aTree.get_child("params").get_child("selected").get_value<std::string>().c_str();
+        CPPUNIT_ASSERT_EQUAL(OString("3"), sSelected);
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to