[Libreoffice-commits] core.git: Branch 'feature/msforms' - 2 commits - sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Mar 8 21:05:12 UTC 2019


Rebased ref, commits from common ancestor:
commit ac595ff6e40ae59231711dfa2577bdaa662454a3
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Thu Mar 7 12:37:00 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Mar 8 22:04:29 2019 +0100

    MSForms: UITest for drop-down form field's propertis dialog
    
    Also changed the dialog's code a bit to work correctly with
    the UI test too.
    
    Change-Id: Idec85746f5ada979518d1fb0e09dc1c8e22ba7c1

diff --git a/sw/qa/uitest/writer_tests/data/drop_down_form_field.doc b/sw/qa/uitest/writer_tests/data/drop_down_form_field.doc
new file mode 100644
index 000000000000..cf94a1fdada1
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/drop_down_form_field.doc differ
diff --git a/sw/qa/uitest/writer_tests/data/drop_down_form_field.docx b/sw/qa/uitest/writer_tests/data/drop_down_form_field.docx
new file mode 100644
index 000000000000..d039cd2b60d3
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/drop_down_form_field.docx differ
diff --git a/sw/qa/uitest/writer_tests/data/drop_down_form_field.odt b/sw/qa/uitest/writer_tests/data/drop_down_form_field.odt
new file mode 100644
index 000000000000..f27b1157418c
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/drop_down_form_field.odt differ
diff --git a/sw/qa/uitest/writer_tests/data/empty_drop_down_form_field.odt b/sw/qa/uitest/writer_tests/data/empty_drop_down_form_field.odt
new file mode 100644
index 000000000000..bd85dc2a902d
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/empty_drop_down_form_field.odt differ
diff --git a/sw/qa/uitest/writer_tests5/DropDownFormFieldPropertiesDialog.py b/sw/qa/uitest/writer_tests5/DropDownFormFieldPropertiesDialog.py
new file mode 100644
index 000000000000..5628e83992e1
--- /dev/null
+++ b/sw/qa/uitest/writer_tests5/DropDownFormFieldPropertiesDialog.py
@@ -0,0 +1,266 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict
+from libreoffice.uno.propertyvalue import mkPropertyValues
+import org.libreoffice.unotest
+import pathlib
+import time
+
+def get_url_for_data_file(file_name):
+    return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
+class dropDownFormFieldDialog(UITestCase):
+
+    def test_add_new_items(self):
+
+        # open a file with an empty form field
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+
+        # open the dialog (cursor is at the field)
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        itemEntry = xDialog.getChild("item_entry")
+        addButton = xDialog.getChild("add_button")
+        itemsList = xDialog.getChild("items_treeview")
+
+        # initial state
+        self.assertEqual(get_state_as_dict(itemEntry)["Text"], "")
+        self.assertEqual(get_state_as_dict(addButton)["Enabled"], "false")
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "0")
+
+        # add some new items
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
+        self.assertEqual(get_state_as_dict(addButton)["Enabled"], "true")
+        addButton.executeAction("CLICK", tuple())
+        self.assertEqual(get_state_as_dict(addButton)["Enabled"], "false")
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
+        addButton.executeAction("CLICK", tuple())
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
+        addButton.executeAction("CLICK", tuple())
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
+        addButton.executeAction("CLICK", tuple())
+
+        # check whether the items are there in the list
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        # check whether items are the same after reopening
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        itemsList = xDialog.getChild("items_treeview")
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        self.ui_test.close_doc()
+
+    def test_remove_items(self):
+
+        # open a file with an empty form field
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+
+        # open the dialog (cursor is at the field)
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        itemEntry = xDialog.getChild("item_entry")
+        addButton = xDialog.getChild("add_button")
+        itemsList = xDialog.getChild("items_treeview")
+        removeButton = xDialog.getChild("remove_button")
+
+        # initial state
+        self.assertEqual(get_state_as_dict(itemEntry)["Text"], "")
+        self.assertEqual(get_state_as_dict(addButton)["Enabled"], "false")
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "0")
+        self.assertEqual(get_state_as_dict(removeButton)["Enabled"], "false")
+
+        # add some new items
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
+        self.assertEqual(get_state_as_dict(addButton)["Enabled"], "true")
+        addButton.executeAction("CLICK", tuple())
+        self.assertEqual(get_state_as_dict(removeButton)["Enabled"], "true")
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
+        addButton.executeAction("CLICK", tuple())
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
+        addButton.executeAction("CLICK", tuple())
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
+        addButton.executeAction("CLICK", tuple())
+
+        # check whether the items are there in the list
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")
+
+        # select an item from the list and remove it
+        itemsList.getChild("1").executeAction("SELECT", tuple());
+        removeButton.executeAction("CLICK", tuple())
+
+        # check whether the right item was removed
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "3")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "4000")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        # check whether items are the same after reopening
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        itemsList = xDialog.getChild("items_treeview")
+        removeButton = xDialog.getChild("remove_button")
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "3")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "4000")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        self.ui_test.close_doc()
+
+    def test_move_items(self):
+
+        # open a file with an empty form field
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+
+        # open the dialog (cursor is at the field)
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        itemEntry = xDialog.getChild("item_entry")
+        addButton = xDialog.getChild("add_button")
+        itemsList = xDialog.getChild("items_treeview")
+        upButton = xDialog.getChild("up_button")
+        downButton = xDialog.getChild("down_button")
+
+        # initial state
+        self.assertEqual(get_state_as_dict(itemEntry)["Text"], "")
+        self.assertEqual(get_state_as_dict(addButton)["Enabled"], "false")
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "0")
+        self.assertEqual(get_state_as_dict(upButton)["Enabled"], "false")
+        self.assertEqual(get_state_as_dict(downButton)["Enabled"], "false")
+
+        # add some new items
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
+        self.assertEqual(get_state_as_dict(addButton)["Enabled"], "true")
+        addButton.executeAction("CLICK", tuple())
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
+        addButton.executeAction("CLICK", tuple())
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
+        addButton.executeAction("CLICK", tuple())
+        itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
+        addButton.executeAction("CLICK", tuple())
+
+        # check whether the items are there in the list
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")
+
+        # select an item from the list and move it up
+        itemsList.getChild("1").executeAction("SELECT", tuple())
+        self.assertEqual(get_state_as_dict(upButton)["Enabled"], "true")
+        self.assertEqual(get_state_as_dict(downButton)["Enabled"], "true")
+        upButton.executeAction("CLICK", tuple())
+        self.assertEqual(get_state_as_dict(upButton)["Enabled"], "false")
+        self.assertEqual(get_state_as_dict(downButton)["Enabled"], "true")
+
+        # check whether the item was correctly moved
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "2000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")
+
+        # move down the selected item
+        downButton.executeAction("CLICK", tuple())
+        downButton.executeAction("CLICK", tuple())
+        downButton.executeAction("CLICK", tuple())
+        self.assertEqual(get_state_as_dict(upButton)["Enabled"], "true")
+        self.assertEqual(get_state_as_dict(downButton)["Enabled"], "false")
+
+        # check whether the item was correctly moved
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "4000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "2000")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        # check whether items are the same after reopening
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        itemsList = xDialog.getChild("items_treeview")
+        self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "3000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "4000")
+        self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "2000")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        self.ui_test.close_doc()
+
+    def test_drop_down_after_import(self):
+
+        files = ["drop_down_form_field.odt", "drop_down_form_field.doc", "drop_down_form_field.docx"]
+        for file in files:
+            # open a file with a drop-down for field with items and selection
+            writer_doc = self.ui_test.load_file(get_url_for_data_file(file))
+            document = self.ui_test.get_component()
+            xWriterDoc = self.xUITest.getTopFocusWindow()
+
+            # open the dialog (cursor is at the field)
+            self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+            xDialog = self.xUITest.getTopFocusWindow()
+
+            itemsList = xDialog.getChild("items_treeview")
+
+            # check whether the items are there in the list
+            self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
+            self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
+            self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
+            self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
+            self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")
+
+            self.assertEqual(get_state_as_dict(itemsList)["SelectEntryText"], "3000")
+
+            xOKBtn = xDialog.getChild("ok")
+            self.ui_test.close_dialog_through_button(xOKBtn)
+
+            self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/fldui/DropDownFormFieldDialog.cxx b/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
index 3b30aaf9131a..ccd9829ce5f2 100644
--- a/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
+++ b/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
@@ -28,7 +28,7 @@ DropDownFormFieldDialog::DropDownFormFieldDialog(weld::Window* pParent,
     , m_xListDownButton(m_xBuilder->weld_button("down_button"))
 {
     m_xListItemEntry->connect_key_press(LINK(this, DropDownFormFieldDialog, KeyPressedHdl));
-    m_xListItemEntry->connect_key_release(LINK(this, DropDownFormFieldDialog, KeyReleasedHdl));
+    m_xListItemEntry->connect_changed(LINK(this, DropDownFormFieldDialog, EntryChangedHdl));
 
     m_xListItemsTreeView->set_size_request(m_xListItemEntry->get_preferred_size().Width(),
                                            m_xListItemEntry->get_preferred_size().Height() * 5);
@@ -57,10 +57,9 @@ IMPL_LINK(DropDownFormFieldDialog, KeyPressedHdl, const KeyEvent&, rEvent, bool)
     return false;
 }
 
-IMPL_LINK_NOARG(DropDownFormFieldDialog, KeyReleasedHdl, const KeyEvent&, bool)
+IMPL_LINK_NOARG(DropDownFormFieldDialog, EntryChangedHdl, weld::Entry&, void)
 {
     UpdateButtons();
-    return false;
 }
 
 IMPL_LINK(DropDownFormFieldDialog, ButtonPushedHdl, weld::Button&, rButton, void)
diff --git a/sw/source/uibase/inc/DropDownFormFieldDialog.hxx b/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
index 3fbb59db0ebc..aee5c5232845 100644
--- a/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
+++ b/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
@@ -41,7 +41,7 @@ private:
 
     DECL_LINK(ListChangedHdl, weld::TreeView&, void);
     DECL_LINK(KeyPressedHdl, const KeyEvent&, bool);
-    DECL_LINK(KeyReleasedHdl, const KeyEvent&, bool);
+    DECL_LINK(EntryChangedHdl, weld::Entry&, void);
     DECL_LINK(ButtonPushedHdl, weld::Button&, void);
 
     void InitControls();
commit 814399eb593b1f2213a667f4e75fdc1baf5dc5fd
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Wed Mar 6 16:58:17 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Mar 8 22:04:13 2019 +0100

    MSForms: Test insertion of form fields and undo / redo of this insertion.
    
    Change-Id: I526faceab8eb1ce2f16d41ab1bed8cfb1bfcca24

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index dfd8d747f72f..2487957171cb 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -30,6 +30,7 @@
 #include <anchoredobject.hxx>
 #include <swtypes.hxx>
 #include <fmtornt.hxx>
+#include <xmloff/odffields.hxx>
 
 namespace
 {
@@ -89,6 +90,10 @@ public:
     CPPUNIT_TEST(testTdf52391);
     CPPUNIT_TEST(testTdf101873);
     CPPUNIT_TEST(testTableWidth);
+    CPPUNIT_TEST(testTextFormFieldInsertion);
+    CPPUNIT_TEST(testCheckboxFormFieldInsertion);
+    CPPUNIT_TEST(testDropDownFormFieldInsertion);
+    CPPUNIT_TEST(testMixedFormFieldInsertion);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -937,6 +942,150 @@ void SwUiWriterTest2::testTableWidth()
                          getProperty<sal_Int16>(xTables->getByIndex(0), "RelativeWidth"));
 }
 
+void SwUiWriterTest2::testTextFormFieldInsertion()
+{
+    load(DATA_DIRECTORY, "frame_size_export.docx");
+    SwDoc* pDoc = createDoc();
+    CPPUNIT_ASSERT(pDoc);
+    IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+    CPPUNIT_ASSERT(pMarkAccess);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+
+    // Insert a text form field
+    lcl_dispatchCommand(mxComponent, ".uno:TextFormField", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+
+    // Check whether the fieldmark is created
+    auto aIter = pMarkAccess->getAllMarksBegin();
+    CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
+    ::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(aIter->get());
+    CPPUNIT_ASSERT(pFieldmark);
+    CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMTEXT), pFieldmark->GetFieldname());
+
+    // The text form field has the placholder text in it
+    uno::Reference< text::XTextRange > xPara = getParagraph(1);
+    sal_Unicode vEnSpaces[5] = {8194, 8194, 8194, 8194, 8194};
+    CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), xPara->getString());
+
+    // Undo insertion
+    lcl_dispatchCommand(mxComponent, ".uno:Undo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+    xPara.set(getParagraph(1));
+    CPPUNIT_ASSERT(xPara->getString().isEmpty());
+
+    // Redo insertion
+    lcl_dispatchCommand(mxComponent, ".uno:Redo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+    xPara.set(getParagraph(1));
+    CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), xPara->getString());
+}
+
+void SwUiWriterTest2::testCheckboxFormFieldInsertion()
+{
+    SwDoc* pDoc = createDoc();
+    CPPUNIT_ASSERT(pDoc);
+
+    IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+    CPPUNIT_ASSERT(pMarkAccess);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+
+    // Insert a checkbox form field
+    lcl_dispatchCommand(mxComponent, ".uno:CheckBoxFormField", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+
+    // Check whether the fieldmark is created
+    auto aIter = pMarkAccess->getAllMarksBegin();
+    CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
+    ::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(aIter->get());
+    CPPUNIT_ASSERT(pFieldmark);
+    CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMCHECKBOX), pFieldmark->GetFieldname());
+    // The checkbox is not checked by default
+    ::sw::mark::ICheckboxFieldmark* pCheckBox = dynamic_cast< ::sw::mark::ICheckboxFieldmark* >(pFieldmark);
+    CPPUNIT_ASSERT(pCheckBox);
+    CPPUNIT_ASSERT(!pCheckBox->IsChecked());
+
+    // Undo insertion
+    lcl_dispatchCommand(mxComponent, ".uno:Undo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+
+    // Redo insertion
+    lcl_dispatchCommand(mxComponent, ".uno:Redo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+    aIter = pMarkAccess->getAllMarksBegin();
+    CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
+    pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(aIter->get());
+    CPPUNIT_ASSERT(pFieldmark);
+    CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMCHECKBOX), pFieldmark->GetFieldname());
+}
+
+void SwUiWriterTest2::testDropDownFormFieldInsertion()
+{
+    SwDoc* pDoc = createDoc();
+    CPPUNIT_ASSERT(pDoc);
+
+    IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+    CPPUNIT_ASSERT(pMarkAccess);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+
+    // Insert a drop-down form field
+    lcl_dispatchCommand(mxComponent, ".uno:DropDownFormField", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+
+    // Check whether the fieldmark is created
+    auto aIter = pMarkAccess->getAllMarksBegin();
+    CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
+    ::sw::mark::IFieldmark* pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(aIter->get());
+    CPPUNIT_ASSERT(pFieldmark);
+    CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDROPDOWN), pFieldmark->GetFieldname());
+    // Check drop down field's parameters. By default these params are not set
+    const sw::mark::IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters();
+    auto pListEntries = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
+    CPPUNIT_ASSERT(bool(pListEntries == pParameters->end()));
+    auto pResult = pParameters->find(ODF_FORMDROPDOWN_RESULT);
+    CPPUNIT_ASSERT(bool(pResult == pParameters->end()));
+
+    // Undo insertion
+    lcl_dispatchCommand(mxComponent, ".uno:Undo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+
+    // Redo insertion
+    lcl_dispatchCommand(mxComponent, ".uno:Redo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
+    aIter = pMarkAccess->getAllMarksBegin();
+    CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd());
+    pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(aIter->get());
+    CPPUNIT_ASSERT(pFieldmark);
+    CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDROPDOWN), pFieldmark->GetFieldname());
+}
+
+void SwUiWriterTest2::testMixedFormFieldInsertion()
+{
+    SwDoc* pDoc = createDoc();
+    CPPUNIT_ASSERT(pDoc);
+
+    IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+    CPPUNIT_ASSERT(pMarkAccess);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+
+    // Insert fields
+    lcl_dispatchCommand(mxComponent, ".uno:TextFormField", {});
+    lcl_dispatchCommand(mxComponent, ".uno:CheckBoxFormField", {});
+    lcl_dispatchCommand(mxComponent, ".uno:DropDownFormField", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), pMarkAccess->getAllMarksCount());
+
+    // Undo insertion
+    lcl_dispatchCommand(mxComponent, ".uno:Undo", {});
+    lcl_dispatchCommand(mxComponent, ".uno:Undo", {});
+    lcl_dispatchCommand(mxComponent, ".uno:Undo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount());
+
+    // Redo insertion
+    lcl_dispatchCommand(mxComponent, ".uno:Redo", {});
+    lcl_dispatchCommand(mxComponent, ".uno:Redo", {});
+    lcl_dispatchCommand(mxComponent, ".uno:Redo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), pMarkAccess->getAllMarksCount());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list