lok context menu: Add module specific unit tests

For calc, now click on the image to have more diverse context
menu with checkbuttons etc.

Change-Id: Ibe2471348b2572523f2684144bd18664ab48a2bb
Reviewed-on: https://gerrit.libreoffice.org/24006
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: pranavk <pranavk@collabora.com>
This commit is contained in:
Pranav Kant
2016-04-12 11:04:56 +05:30
committed by pranavk
parent 9a31442171
commit f00fd79f8a
6 changed files with 323 additions and 46 deletions

Binary file not shown.

View File

@@ -942,22 +942,39 @@ namespace {
}
boost::optional<boost::property_tree::ptree>
getContextMenuItem(boost::property_tree::ptree& aMenu, std::string unoSelector)
{
boost::optional<boost::property_tree::ptree> aMenuItem;
for (const auto& aItemPair: aMenu)
{
boost::property_tree::ptree aItemValue = aItemPair.second;
boost::optional<boost::property_tree::ptree&> aCommand = aItemValue.get_child_optional("command");
if (aCommand && aCommand.get().data() == unoSelector )
{
aMenuItem = aItemValue;
break;
}
}
return aMenuItem;
}
} // end anonymous namespace
void DesktopLOKTest::testContextMenuCalc()
{
comphelper::LibreOfficeKit::setActive();
LibLODocument_Impl* pDocument = loadDoc("sheets.ods", LOK_DOCTYPE_SPREADSHEET);
LibLODocument_Impl* pDocument = loadDoc("sheet_with_image.ods", LOK_DOCTYPE_SPREADSHEET);
pDocument->pClass->initializeForRendering(pDocument, nullptr);
pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
// Values in twips
int row5 = 1150;
int col1 = 1100;
Point aPointOnImage(1150, 1100);
pDocument->pClass->postMouseEvent(pDocument,
LOK_MOUSEEVENT_MOUSEBUTTONDOWN,
col1, row5,
aPointOnImage.X(), aPointOnImage.Y(),
1, 4, 0);
TimeValue aTimeValue = {2 , 0}; // 2 seconds max
@@ -968,6 +985,91 @@ void DesktopLOKTest::testContextMenuCalc()
CPPUNIT_ASSERT( aMenu );
verifyContextMenuStructure( aMenu.get() );
// tests for calc specific context menu
// Cut is enabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Cut");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("true"));
}
// Copy is enabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Copy");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("true"));
}
// Paste is enabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Paste");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("true"));
}
// Remove hyperlink is disabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:DeleteShapeHyperlink");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("false"));
}
// open hyperlink is disabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:OpenHyperlinkOnCursor");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("false"));
}
// checkbutton tests
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:AnchorMenu");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aSubmenu = aMenuItem.get().get_child_optional("menu");
CPPUNIT_ASSERT(aSubmenu);
boost::optional<boost::property_tree::ptree> aMenuItemToPage = getContextMenuItem(aSubmenu.get(), ".uno:SetAnchorToPage");
CPPUNIT_ASSERT(aMenuItemToPage);
boost::optional<boost::property_tree::ptree> aMenuItemToCell = getContextMenuItem(aSubmenu.get(), ".uno:SetAnchorToCell");
CPPUNIT_ASSERT(aMenuItemToCell);
// these are radio buttons
boost::optional<boost::property_tree::ptree&> aChecktypeToPage = aMenuItemToPage.get().get_child_optional("checktype");
CPPUNIT_ASSERT(aChecktypeToPage);
CPPUNIT_ASSERT_EQUAL(std::string(aChecktypeToPage.get().data()), std::string("radio"));
boost::optional<boost::property_tree::ptree&> aChecktypeToCell = aMenuItemToCell.get().get_child_optional("checktype");
CPPUNIT_ASSERT(aChecktypeToCell);
CPPUNIT_ASSERT_EQUAL(std::string(aChecktypeToCell.get().data()), std::string("radio"));
// ToPage is checked
boost::optional<boost::property_tree::ptree&> aCheckedToPage = aMenuItemToPage.get().get_child_optional("checked");
CPPUNIT_ASSERT(aCheckedToPage);
CPPUNIT_ASSERT_EQUAL(std::string(aCheckedToPage.get().data()), std::string("true"));
// ToCell is unchecked
boost::optional<boost::property_tree::ptree&> aCheckedToCell = aMenuItemToCell.get().get_child_optional("checked");
CPPUNIT_ASSERT(aCheckedToCell);
CPPUNIT_ASSERT_EQUAL(std::string(aCheckedToCell.get().data()), std::string("false"));
}
comphelper::LibreOfficeKit::setActive(false);
}
@@ -992,6 +1094,37 @@ void DesktopLOKTest::testContextMenuWriter()
CPPUNIT_ASSERT( aMenu );
verifyContextMenuStructure( aMenu.get() );
// tests for writer specific context menu
// Cut is disabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Cut");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("false"));
}
// Copy is disabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Copy");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("false"));
}
// Paste is enabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Paste");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("true"));
}
comphelper::LibreOfficeKit::setActive(false);
}
@@ -1016,6 +1149,107 @@ void DesktopLOKTest::testContextMenuImpress()
CPPUNIT_ASSERT( aMenu );
verifyContextMenuStructure( aMenu.get() );
// tests for impress specific context menu
// Cut is disabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Cut");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("false"));
}
// Copy is disabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Copy");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("false"));
}
// Paste is enabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:Paste");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("true"));
}
// SaveBackground is disabled
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:SaveBackground");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aEnabled = aMenuItem.get().get_child_optional("enabled");
CPPUNIT_ASSERT(aEnabled);
CPPUNIT_ASSERT_EQUAL(std::string(aEnabled.get().data()), std::string("false"));
}
// checkbutton tests
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:ShowRuler");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aChecktype = aMenuItem.get().get_child_optional("checktype");
CPPUNIT_ASSERT(aChecktype);
CPPUNIT_ASSERT_EQUAL(std::string(aChecktype.get().data()), std::string("checkmark"));
boost::optional<boost::property_tree::ptree&> aChecked = aMenuItem.get().get_child_optional("checked");
CPPUNIT_ASSERT(aChecked);
CPPUNIT_ASSERT_EQUAL(std::string(aChecked.get().data()), std::string("false"));
}
// Checkbutton tests inside SnapLines submenu
{
boost::optional<boost::property_tree::ptree> aMenuItem = getContextMenuItem(aMenu.get(), ".uno:SnapLinesMenu");
CPPUNIT_ASSERT(aMenuItem);
boost::optional<boost::property_tree::ptree&> aSubmenu = aMenuItem.get().get_child_optional("menu");
CPPUNIT_ASSERT(aSubmenu);
boost::optional<boost::property_tree::ptree> aMenuItemHelpVis = getContextMenuItem(aSubmenu.get(), ".uno:HelplinesVisible");
CPPUNIT_ASSERT(aMenuItemHelpVis);
boost::optional<boost::property_tree::ptree> aMenuItemHelpUse = getContextMenuItem(aSubmenu.get(), ".uno:HelplinesUse");
CPPUNIT_ASSERT(aMenuItemHelpUse);
boost::optional<boost::property_tree::ptree> aMenuItemHelpFront = getContextMenuItem(aSubmenu.get(), ".uno:HelplinesFront");
CPPUNIT_ASSERT(aMenuItemHelpFront);
// these are checkmarks
boost::optional<boost::property_tree::ptree&> aChecktypeHelpVis = aMenuItemHelpVis.get().get_child_optional("checktype");
CPPUNIT_ASSERT(aChecktypeHelpVis);
CPPUNIT_ASSERT_EQUAL(std::string(aChecktypeHelpVis.get().data()), std::string("checkmark"));
boost::optional<boost::property_tree::ptree&> aChecktypeHelpUse = aMenuItemHelpUse.get().get_child_optional("checktype");
CPPUNIT_ASSERT(aChecktypeHelpUse);
CPPUNIT_ASSERT_EQUAL(std::string(aChecktypeHelpUse.get().data()), std::string("checkmark"));
boost::optional<boost::property_tree::ptree&> aChecktypeHelpFront = aMenuItemHelpFront.get().get_child_optional("checktype");
CPPUNIT_ASSERT(aChecktypeHelpFront);
CPPUNIT_ASSERT_EQUAL(std::string(aChecktypeHelpFront.get().data()), std::string("checkmark"));
// HelplineVisible is unchecked
boost::optional<boost::property_tree::ptree&> aCheckedHelpVis = aMenuItemHelpVis.get().get_child_optional("checked");
CPPUNIT_ASSERT(aCheckedHelpVis);
CPPUNIT_ASSERT_EQUAL(std::string(aCheckedHelpVis.get().data()), std::string("false"));
// HelplineUse is checked
boost::optional<boost::property_tree::ptree&> aCheckedHelpUse = aMenuItemHelpUse.get().get_child_optional("checked");
CPPUNIT_ASSERT(aCheckedHelpUse);
CPPUNIT_ASSERT_EQUAL(std::string(aCheckedHelpUse.get().data()), std::string("true"));
// HelplineFront is checked
boost::optional<boost::property_tree::ptree&> aCheckedHelpFront = aMenuItemHelpFront.get().get_child_optional("checked");
CPPUNIT_ASSERT(aCheckedHelpFront);
CPPUNIT_ASSERT_EQUAL(std::string(aCheckedHelpFront.get().data()), std::string("true"));
}
comphelper::LibreOfficeKit::setActive(false);
}

View File

@@ -21,7 +21,8 @@ $(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/sta
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/crdbus50.bau,user/autotext/en-US/crdbus50.bau))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/.dummy,empty-directory-dummy))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/autocorr/acor_en-US.dat,user/autocorr/acor_fr.dat))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/modules/scalc/popupmenu/cell.xml,user/config/soffice.cfg/modules/scalc/popupmenu/cell.xml))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/modules/scalc/popupmenu/draw.xml,user/config/soffice.cfg/modules/scalc/popupmenu/draw.xml))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/modules/scalc/popupmenu/anchor.xml,user/config/soffice.cfg/modules/scalc/popupmenu/anchor.xml))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/modules/swriter/popupmenu/text.xml,user/config/soffice.cfg/modules/swriter/popupmenu/text.xml))
$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/modules/simpress/popupmenu/page.xml,user/config/soffice.cfg/modules/simpress/popupmenu/page.xml))

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of the LibreOffice project.
*
* 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/.
*
-->
<menu:menupopup xmlns:menu="http://openoffice.org/2001/menu">
<menu:menuitem menu:id=".uno:SetAnchorToPage" menu:style="radio"/>
<menu:menuitem menu:id=".uno:SetAnchorToCell" menu:style="radio"/>
</menu:menupopup>

View File

@@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of the LibreOffice project.
*
* 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/.
*
-->
<menu:menupopup xmlns:menu="http://openoffice.org/2001/menu">
<menu:menuitem menu:id=".uno:Cut"/>
<menu:menuitem menu:id=".uno:Copy"/>
<menu:menuitem menu:id=".uno:Paste"/>
<menu:menuitem menu:id=".uno:PasteSpecial"/>
<menu:menu menu:id=".uno:PasteOnly">
<menu:menupopup>
<menu:menuitem menu:id=".uno:PasteOnlyText"/>
<menu:menuitem menu:id=".uno:PasteOnlyValue"/>
<menu:menuitem menu:id=".uno:PasteOnlyFormula"/>
</menu:menupopup>
</menu:menu>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ResetAttributes"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:FormatCellDialog"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:InsertCell"/>
<menu:menuitem menu:id=".uno:DeleteCell"/>
<menu:menuitem menu:id=".uno:Delete"/>
<menu:menuitem menu:id=".uno:MergeCells"/>
<menu:menuitem menu:id=".uno:SplitCell"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:InsertAnnotation"/>
<menu:menuitem menu:id=".uno:EditAnnotation"/>
<menu:menuitem menu:id=".uno:DeleteNote"/>
<menu:menuitem menu:id=".uno:ShowNote"/>
<menu:menuitem menu:id=".uno:HideNote"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:DataSelect"/>
</menu:menupopup>

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of the LibreOffice project.
*
* 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/.
*
-->
<menu:menupopup xmlns:menu="http://openoffice.org/2001/menu">
<menu:menuitem menu:id=".uno:Cut"/>
<menu:menuitem menu:id=".uno:Copy"/>
<menu:menuitem menu:id=".uno:Paste"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:FormatLine"/>
<menu:menuitem menu:id=".uno:FormatArea"/>
<menu:menuitem menu:id=".uno:TextAttributes"/>
<menu:menuitem menu:id=".uno:TransformDialog"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ObjectTitleDescription"/>
<menu:menuitem menu:id=".uno:RenameObject"/>
<menu:menuseparator/>
<menu:menu menu:id=".uno:FlipMenu">
<menu:menupopup>
<menu:menuitem menu:id=".uno:ObjectMirrorVertical"/>
<menu:menuitem menu:id=".uno:ObjectMirrorHorizontal"/>
</menu:menupopup>
</menu:menu>
<menu:menu menu:id=".uno:ArrangeMenu">
<menu:menupopup>
<menu:menuitem menu:id=".uno:BringToFront"/>
<menu:menuitem menu:id=".uno:ObjectForwardOne"/>
<menu:menuitem menu:id=".uno:ObjectBackOne"/>
<menu:menuitem menu:id=".uno:SendToBack"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:SetObjectToForeground"/>
<menu:menuitem menu:id=".uno:SetObjectToBackground"/>
</menu:menupopup>
</menu:menu>
<menu:menu menu:id=".uno:ObjectAlign">
<menu:menupopup>
<menu:menuitem menu:id=".uno:ObjectAlignLeft"/>
<menu:menuitem menu:id=".uno:AlignCenter"/>
<menu:menuitem menu:id=".uno:ObjectAlignRight"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:AlignUp"/>
<menu:menuitem menu:id=".uno:AlignMiddle"/>
<menu:menuitem menu:id=".uno:AlignDown"/>
</menu:menupopup>
</menu:menu>
<menu:menuitem menu:id=".uno:AnchorMenu"/>
<menu:menuitem menu:id=".uno:AssignMacro"/>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:ToggleObjectBezierMode"/>
<menu:menuitem menu:id=".uno:FontWork"/>
<menu:menuseparator/>
<menu:menu menu:id=".uno:GroupMenu">
<menu:menupopup>
<menu:menuitem menu:id=".uno:FormatGroup"/>
<menu:menuitem menu:id=".uno:FormatUngroup"/>
<menu:menuitem menu:id=".uno:EnterGroup"/>
<menu:menuitem menu:id=".uno:LeaveGroup"/>
</menu:menupopup>
</menu:menu>
<menu:menuseparator/>
<menu:menuitem menu:id=".uno:EditShapeHyperlink"/>
<menu:menuitem menu:id=".uno:DeleteShapeHyperlink"/>
<menu:menuitem menu:id=".uno:OpenHyperlinkOnCursor"/>
</menu:menupopup>