From c01a98e42c2cc2e130c738d0656f7446aea2e119 Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Fri, 8 Apr 2016 20:08:38 +0530 Subject: lok context menu: unit test Reviewed-on: https://gerrit.libreoffice.org/23985 Tested-by: Jenkins Reviewed-by: pranavk (cherry picked from commit d76b1b5b06c064938986c0b921b8d537fdf8bf4c) Change-Id: I244fbf4b98368c7c0d66cdd865e1243639727026 Reviewed-on: https://gerrit.libreoffice.org/24732 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian --- desktop/CppunitTest_desktop_lib.mk | 2 + desktop/qa/data/blank_presentation.odp | Bin 0 -> 10864 bytes desktop/qa/desktop_lib/test_desktop_lib.cxx | 190 +++++++++++++++++++++++++--- 3 files changed, 172 insertions(+), 20 deletions(-) create mode 100644 desktop/qa/data/blank_presentation.odp (limited to 'desktop') diff --git a/desktop/CppunitTest_desktop_lib.mk b/desktop/CppunitTest_desktop_lib.mk index b6226fac7568..a80c097f8392 100644 --- a/desktop/CppunitTest_desktop_lib.mk +++ b/desktop/CppunitTest_desktop_lib.mk @@ -65,6 +65,8 @@ $(eval $(call gb_CppunitTest_use_components,desktop_lib,\ sw/util/swd \ sc/util/sc \ sc/util/scd \ + sd/util/sd \ + sd/util/sdd \ toolkit/util/tk \ ucb/source/core/ucb1 \ ucb/source/ucp/file/ucpfile1 \ diff --git a/desktop/qa/data/blank_presentation.odp b/desktop/qa/data/blank_presentation.odp new file mode 100644 index 000000000000..157901f9bb6c Binary files /dev/null and b/desktop/qa/data/blank_presentation.odp differ diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 60ddaa35270a..0f8be8fbf6d3 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -87,12 +87,15 @@ public: void testPasteWriter(); void testPasteWriterJPEG(); void testRowColumnHeaders(); - void testCellCursor(); void testHiddenRowHeaders(); + void testCellCursor(); void testCommandResult(); void testWriterComments(); void testModifiedStatus(); void testSheetOperations(); + void testContextMenuCalc(); + void testContextMenuWriter(); + void testContextMenuImpress(); void testNotificationCompression(); CPPUNIT_TEST_SUITE(DesktopLOKTest); @@ -109,12 +112,15 @@ public: CPPUNIT_TEST(testPasteWriter); CPPUNIT_TEST(testPasteWriterJPEG); CPPUNIT_TEST(testRowColumnHeaders); - CPPUNIT_TEST(testCellCursor); CPPUNIT_TEST(testHiddenRowHeaders); + CPPUNIT_TEST(testCellCursor); CPPUNIT_TEST(testCommandResult); CPPUNIT_TEST(testWriterComments); CPPUNIT_TEST(testModifiedStatus); CPPUNIT_TEST(testSheetOperations); + CPPUNIT_TEST(testContextMenuCalc); + CPPUNIT_TEST(testContextMenuWriter); + CPPUNIT_TEST(testContextMenuImpress); CPPUNIT_TEST(testNotificationCompression); CPPUNIT_TEST_SUITE_END(); @@ -132,6 +138,10 @@ public: // for testModifiedStatus osl::Condition m_aStateChangedCondition; bool m_bModified; + + // for testContextMenu{Calc, Writer} + osl::Condition m_aContextMenuCondition; + boost::property_tree::ptree m_aContextMenuResult; }; LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType) @@ -147,6 +157,9 @@ LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDoc case LOK_DOCTYPE_SPREADSHEET: aService = "com.sun.star.sheet.SpreadsheetDocument"; break; + case LOK_DOCTYPE_PRESENTATION: + aService = "com.sun.star.presentation.PresentationDocument"; + break; default: CPPUNIT_ASSERT(false); break; @@ -216,6 +229,14 @@ void DesktopLOKTest::callbackImpl(int nType, const char* pPayload) } } break; + case LOK_CALLBACK_CONTEXT_MENU: + { + m_aContextMenuResult.clear(); + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, m_aContextMenuResult); + m_aContextMenuCondition.set(); + } + break; } } @@ -558,24 +579,6 @@ void DesktopLOKTest::testRowColumnHeaders() } } -void DesktopLOKTest::testCellCursor() -{ - LibLODocument_Impl* pDocument = loadDoc("search.ods"); - - boost::property_tree::ptree aTree; - - char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:CellCursor?tileWidth=1&tileHeight=1&outputWidth=1&outputHeight=1"); - - std::stringstream aStream(pJSON); - free(pJSON); - CPPUNIT_ASSERT(!aStream.str().empty()); - - boost::property_tree::read_json(aStream, aTree); - - OString aRectangle(aTree.get("commandValues").c_str()); - CPPUNIT_ASSERT_EQUAL(aRectangle, OString("0, 0, 1278, 254")); -} - void DesktopLOKTest::testHiddenRowHeaders() { LibLODocument_Impl* pDocument = loadDoc("hidden-row.ods"); @@ -609,6 +612,24 @@ void DesktopLOKTest::testHiddenRowHeaders() } } +void DesktopLOKTest::testCellCursor() +{ + LibLODocument_Impl* pDocument = loadDoc("search.ods"); + + boost::property_tree::ptree aTree; + + char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:CellCursor?tileWidth=1&tileHeight=1&outputWidth=1&outputHeight=1"); + + std::stringstream aStream(pJSON); + free(pJSON); + CPPUNIT_ASSERT(!aStream.str().empty()); + + boost::property_tree::read_json(aStream, aTree); + + OString aRectangle(aTree.get("commandValues").c_str()); + CPPUNIT_ASSERT_EQUAL(aRectangle, OString("0, 0, 1278, 254")); +} + void DesktopLOKTest::testCommandResult() { LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); @@ -866,6 +887,135 @@ void DesktopLOKTest::testNotificationCompression() CPPUNIT_ASSERT_EQUAL(std::string("1"), std::get<1>(notifs[i++])); } +namespace { + + void verifyContextMenuStructure(boost::property_tree::ptree& aRoot) + { + for (const auto& aItemPair: aRoot) + { + // This is an array, so no key + CPPUNIT_ASSERT_EQUAL(std::string(aItemPair.first.data()), std::string("")); + + boost::property_tree::ptree aItemValue = aItemPair.second; + boost::optional aText = aItemValue.get_child_optional("text"); + boost::optional aType = aItemValue.get_child_optional("type"); + boost::optional aCommand = aItemValue.get_child_optional("command"); + boost::optional aSubmenu = aItemValue.get_child_optional("menu"); + boost::optional aEnabled = aItemValue.get_child_optional("enabled"); + boost::optional aChecktype = aItemValue.get_child_optional("checktype"); + boost::optional aChecked = aItemValue.get_child_optional("checked"); + + // type is omnipresent + CPPUNIT_ASSERT( aType ); + + // seperator doesn't have any other attribs + if ( aType.get().data() == "separator" ) + { + CPPUNIT_ASSERT( !aText && !aCommand && !aSubmenu && !aEnabled && !aChecktype && !aChecked ); + } + else if ( aType.get().data() == "command" ) + { + CPPUNIT_ASSERT( aCommand && aText ); + } + else if ( aType.get().data() == "menu") + { + CPPUNIT_ASSERT( aSubmenu && aText ); + verifyContextMenuStructure( aSubmenu.get() ); + } + + if ( aChecktype ) + { + CPPUNIT_ASSERT( aChecktype.get().data() == "radio" || + aChecktype.get().data() == "checkmark" || + aChecktype.get().data() == "auto" ); + + CPPUNIT_ASSERT( aChecked && + ( aChecked.get().data() == "true" || aChecked.get().data() == "false" ) ); + } + } + + } + +} // end anonymous namespace + +void DesktopLOKTest::testContextMenuCalc() +{ + comphelper::LibreOfficeKit::setActive(); + LibLODocument_Impl* pDocument = loadDoc("sheets.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; + + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + col1, row5, + 1, 4, 0); + Scheduler::ProcessEventsToIdle(); + + TimeValue aTimeValue = {2 , 0}; // 2 seconds max + m_aContextMenuCondition.wait(&aTimeValue); + + CPPUNIT_ASSERT( !m_aContextMenuResult.empty() ); + boost::optional aMenu = m_aContextMenuResult.get_child_optional("menu"); + CPPUNIT_ASSERT( aMenu ); + verifyContextMenuStructure( aMenu.get() ); + + comphelper::LibreOfficeKit::setActive(false); +} + +void DesktopLOKTest::testContextMenuWriter() +{ + comphelper::LibreOfficeKit::setActive(); + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt", LOK_DOCTYPE_TEXT); + pDocument->pClass->initializeForRendering(pDocument, nullptr); + pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); + + Point aRandomPoint(1150, 1100); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + aRandomPoint.X(), aRandomPoint.Y(), + 1, 4, 0); + Scheduler::ProcessEventsToIdle(); + + TimeValue aTimeValue = {2 , 0}; // 2 seconds max + m_aContextMenuCondition.wait(&aTimeValue); + + CPPUNIT_ASSERT( !m_aContextMenuResult.empty() ); + boost::optional aMenu = m_aContextMenuResult.get_child_optional("menu"); + CPPUNIT_ASSERT( aMenu ); + verifyContextMenuStructure( aMenu.get() ); + + comphelper::LibreOfficeKit::setActive(false); +} + +void DesktopLOKTest::testContextMenuImpress() +{ + comphelper::LibreOfficeKit::setActive(); + LibLODocument_Impl* pDocument = loadDoc("blank_presentation.odp", LOK_DOCTYPE_PRESENTATION); + pDocument->pClass->initializeForRendering(pDocument, nullptr); + pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); + + Point aRandomPoint(1150, 1100); + pDocument->pClass->postMouseEvent(pDocument, + LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + aRandomPoint.X(), aRandomPoint.Y(), + 1, 4, 0); + Scheduler::ProcessEventsToIdle(); + + TimeValue aTimeValue = {2 , 0}; // 2 seconds max + m_aContextMenuCondition.wait(&aTimeValue); + + CPPUNIT_ASSERT( !m_aContextMenuResult.empty() ); + boost::optional aMenu = m_aContextMenuResult.get_child_optional("menu"); + CPPUNIT_ASSERT( aMenu ); + verifyContextMenuStructure( aMenu.get() ); + + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3