sw/qa/extras/tiledrendering/data/drop_down_form_field_noitem.odt |binary sw/qa/extras/tiledrendering/data/drop_down_form_field_noselection.odt |binary sw/qa/extras/tiledrendering/tiledrendering.cxx | 77 ++++++++++ sw/source/core/crsr/bookmrk.cxx | 4 4 files changed, 79 insertions(+), 2 deletions(-)
New commits: commit 313a0c7bb2aecb597ccab20712954cea216d5b58 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Sat May 9 13:35:16 2020 +0200 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Sat May 9 16:36:44 2020 +0200 lok: MSForms: test & fix two corner cases of drop-down field. Change-Id: I2c54e2e2a94d15d42b23e04a896211936e9e1852 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93845 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> diff --git a/sw/qa/extras/tiledrendering/data/drop_down_form_field_noitem.odt b/sw/qa/extras/tiledrendering/data/drop_down_form_field_noitem.odt new file mode 100644 index 000000000000..c0b703320bec Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/drop_down_form_field_noitem.odt differ diff --git a/sw/qa/extras/tiledrendering/data/drop_down_form_field_noselection.odt b/sw/qa/extras/tiledrendering/data/drop_down_form_field_noselection.odt new file mode 100644 index 000000000000..0c433c64707b Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/drop_down_form_field_noselection.odt differ diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 994188aaac6f..4d3e49f5643d 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -131,6 +131,8 @@ public: void testFieldmark(); void testDropDownFormFieldButton(); void testDropDownFormFieldButtonEditing(); + void testDropDownFormFieldButtonNoSelection(); + void testDropDownFormFieldButtonNoItem(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -199,6 +201,8 @@ public: CPPUNIT_TEST(testFieldmark); CPPUNIT_TEST(testDropDownFormFieldButton); CPPUNIT_TEST(testDropDownFormFieldButtonEditing); + CPPUNIT_TEST(testDropDownFormFieldButtonNoSelection); + CPPUNIT_TEST(testDropDownFormFieldButtonNoItem); CPPUNIT_TEST_SUITE_END(); private: @@ -2675,6 +2679,79 @@ void SwTiledRenderingTest::testDropDownFormFieldButtonEditing() } } +void SwTiledRenderingTest::testDropDownFormFieldButtonNoSelection() +{ + SwXTextDocument* pXTextDocument = createDoc("drop_down_form_field_noselection.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); + + // None of the items is selected + 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); + } +} + +void SwTiledRenderingTest::testDropDownFormFieldButtonNoItem() +{ + SwXTextDocument* pXTextDocument = createDoc("drop_down_form_field_noitem.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); + + // There is not item specified for the field + CPPUNIT_ASSERT(!m_aFormFieldButton.isEmpty()); + { + std::stringstream aStream(m_aFormFieldButton.getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + + boost::property_tree::ptree aItems = aTree.get_child("params").get_child("items"); + CPPUNIT_ASSERT_EQUAL(size_t(0), aItems.size()); + + OString sSelected = aTree.get_child("params").get_child("selected").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("-1"), sSelected); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index e39c5ced6a05..3efdbf98167d 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -755,12 +755,12 @@ namespace sw::mark // Selected item OUString sResultKey = ODF_FORMDROPDOWN_RESULT; auto pSelectedItemIter = pParameters->find(sResultKey); + sal_Int32 nSelection = -1; if (pSelectedItemIter != pParameters->end()) { - sal_Int32 nSelection = -1; pSelectedItemIter->second >>= nSelection; - sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\"}}"); } + sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\"}}"); } else { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits