summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorPranav Kant <pranavk@collabora.com>2016-04-08 20:08:38 +0530
committerAshod Nakashian <ashnakash@gmail.com>2016-05-07 20:44:13 +0000
commitc01a98e42c2cc2e130c738d0656f7446aea2e119 (patch)
treed97eb0cf44deb281c80603d5251c4e9a74a227a1 /desktop
parent21f93834c285afd5af85f97b2eba8df47f290aac (diff)
lok context menu: unit test
Reviewed-on: https://gerrit.libreoffice.org/23985 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: pranavk <pranavk@collabora.com> (cherry picked from commit d76b1b5b06c064938986c0b921b8d537fdf8bf4c) Change-Id: I244fbf4b98368c7c0d66cdd865e1243639727026 Reviewed-on: https://gerrit.libreoffice.org/24732 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/CppunitTest_desktop_lib.mk2
-rw-r--r--desktop/qa/data/blank_presentation.odpbin0 -> 10864 bytes
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx190
3 files changed, 172 insertions, 20 deletions
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
--- /dev/null
+++ b/desktop/qa/data/blank_presentation.odp
Binary files 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<std::string>("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<std::string>("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<boost::property_tree::ptree&> aText = aItemValue.get_child_optional("text");
+ boost::optional<boost::property_tree::ptree&> aType = aItemValue.get_child_optional("type");
+ boost::optional<boost::property_tree::ptree&> aCommand = aItemValue.get_child_optional("command");
+ boost::optional<boost::property_tree::ptree&> aSubmenu = aItemValue.get_child_optional("menu");
+ boost::optional<boost::property_tree::ptree&> aEnabled = aItemValue.get_child_optional("enabled");
+ boost::optional<boost::property_tree::ptree&> aChecktype = aItemValue.get_child_optional("checktype");
+ boost::optional<boost::property_tree::ptree&> 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<boost::property_tree::ptree&> 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<boost::property_tree::ptree&> 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<boost::property_tree::ptree&> 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();