[Libreoffice-commits] core.git: desktop/qa sw/qa sw/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 8 04:58:41 UTC 2021


 desktop/qa/desktop_lib/test_desktop_lib.cxx       |    2 -
 sw/qa/extras/indexing/IndexingExportTest.cxx      |   34 +++++++++++++---------
 sw/qa/extras/indexing/SearchResultLocatorTest.cxx |    6 +--
 sw/source/core/inc/SearchResultLocator.hxx        |    2 -
 sw/source/core/model/SearchResultLocator.cxx      |   24 +++++++++++----
 sw/source/filter/indexing/IndexingExport.cxx      |   14 ++++-----
 6 files changed, 51 insertions(+), 31 deletions(-)

New commits:
commit 83da70de985e1f9f7193676bef8dc71226803bb0
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Sep 7 15:40:42 2021 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Sep 8 06:58:07 2021 +0200

    indexing: rename "type" for prargraph an object nodes
    
    They are conflicting, so rename the one for paragraphs to
    "node_type and the one for objects to "object_type". This needs
    adusting all the tests. Also change the node_type from numerical
    value (correcponding to a enum) to string based - "writer" or
    "commom" values.
    
    Change-Id: I0465cd4c2c6989e436d5a675db20c87066d19208
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121743
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 85e09ab13a51..28a5e76a6e1e 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3119,7 +3119,7 @@ void DesktopLOKTest::testRenderSearchResult()
     unsigned char* pBuffer = nullptr;
     OString aPayload =
     "<indexing>"
-        "<paragraph type=\"1\" index=\"19\">ABC</paragraph>"
+        "<paragraph node_type=\"writer\" index=\"19\">ABC</paragraph>"
     "</indexing>";
 
     int nWidth = 0;
diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx b/sw/qa/extras/indexing/IndexingExportTest.cxx
index 9d40d887f30d..c08cdcd282c9 100644
--- a/sw/qa/extras/indexing/IndexingExportTest.cxx
+++ b/sw/qa/extras/indexing/IndexingExportTest.cxx
@@ -74,7 +74,7 @@ void IndexingExportTest::testIndexingExport_Paragraphs()
 
     assertXPath(pXmlDoc, "/indexing");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Title");
-    assertXPath(pXmlDoc, "/indexing/paragraph[1]", "type", "1");
+    assertXPath(pXmlDoc, "/indexing/paragraph[1]", "node_type", "writer");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Heading 1");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Heading 2");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "Paragraph 1");
@@ -91,6 +91,7 @@ void IndexingExportTest::testIndexingExport_Paragraphs()
     assertXPathContent(pXmlDoc, "/indexing/paragraph[15]", "Center");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[16]", "Right");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[17]", "Bold Italic Underline Strikeout");
+    assertXPath(pXmlDoc, "/indexing/paragraph[17]", "node_type", "writer");
 }
 
 void IndexingExportTest::testIndexingExport_Images()
@@ -109,10 +110,10 @@ void IndexingExportTest::testIndexingExport_Images()
     assertXPath(pXmlDoc, "/indexing");
     assertXPath(pXmlDoc, "/indexing/object[1]", "alt", "Image_NonCaption - Alternative text");
     assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Image_NonCaption");
-    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "graphic");
+    assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "graphic");
     assertXPath(pXmlDoc, "/indexing/object[2]", "alt", "Image_InCaption - Alternative text");
     assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Image_InCaption");
-    assertXPath(pXmlDoc, "/indexing/object[2]", "type", "graphic");
+    assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "graphic");
 }
 
 void IndexingExportTest::testIndexingExport_OLE()
@@ -131,7 +132,7 @@ void IndexingExportTest::testIndexingExport_OLE()
     assertXPath(pXmlDoc, "/indexing");
     assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Object - Chart");
     assertXPath(pXmlDoc, "/indexing/object[1]", "alt", "Alt Text");
-    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "ole");
+    assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "ole");
 }
 
 void IndexingExportTest::testIndexingExport_Shapes()
@@ -149,21 +150,28 @@ void IndexingExportTest::testIndexingExport_Shapes()
 
     assertXPath(pXmlDoc, "/indexing");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Drawing : Just a Diamond");
+    assertXPath(pXmlDoc, "/indexing/paragraph[1]", "node_type", "writer");
 
     assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Circle");
-    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "shape");
+    assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "shape");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "This is a circle");
+    assertXPath(pXmlDoc, "/indexing/paragraph[2]", "node_type", "common");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "This is a second paragraph");
+    assertXPath(pXmlDoc, "/indexing/paragraph[3]", "node_type", "common");
 
     assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Diamond");
-    assertXPath(pXmlDoc, "/indexing/object[2]", "type", "shape");
+    assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "shape");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "This is a diamond");
+    assertXPath(pXmlDoc, "/indexing/paragraph[4]", "node_type", "common");
 
     assertXPath(pXmlDoc, "/indexing/object[3]", "name", "Text Frame 1");
-    assertXPath(pXmlDoc, "/indexing/object[3]", "type", "shape");
+    assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", "shape");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "This is a TextBox - Para1");
+    assertXPath(pXmlDoc, "/indexing/paragraph[5]", "node_type", "common");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Para2");
+    assertXPath(pXmlDoc, "/indexing/paragraph[6]", "node_type", "common");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "Para3");
+    assertXPath(pXmlDoc, "/indexing/paragraph[7]", "node_type", "common");
 }
 
 void IndexingExportTest::testIndexingExport_Tables()
@@ -182,7 +190,7 @@ void IndexingExportTest::testIndexingExport_Tables()
     assertXPath(pXmlDoc, "/indexing");
 
     assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Table1");
-    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "table");
+    assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "table");
     assertXPath(pXmlDoc, "/indexing/object[1]", "index", "9");
     // Search paragraph with parent = 9
     assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][1]", "A");
@@ -191,7 +199,7 @@ void IndexingExportTest::testIndexingExport_Tables()
     assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=9][4]", "2");
 
     assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Table2");
-    assertXPath(pXmlDoc, "/indexing/object[2]", "type", "table");
+    assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "table");
     assertXPath(pXmlDoc, "/indexing/object[2]", "index", "24");
     // Search paragraph with parent = 24
     assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][1]", "A");
@@ -211,7 +219,7 @@ void IndexingExportTest::testIndexingExport_Tables()
     assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=24][15]", "400");
 
     assertXPath(pXmlDoc, "/indexing/object[3]", "name", "WeirdTable");
-    assertXPath(pXmlDoc, "/indexing/object[3]", "type", "table");
+    assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", "table");
     assertXPath(pXmlDoc, "/indexing/object[3]", "index", "72");
     // Search paragraph with parent = 72
     assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent=72][1]", "A1");
@@ -249,7 +257,7 @@ void IndexingExportTest::testIndexingExport_Sections()
     assertXPath(pXmlDoc, "/indexing");
 
     assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Section1");
-    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "section");
+    assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "section");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "This is a paragraph in a Section1");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Section1 - Paragraph 2");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Section1 - Paragraph 3");
@@ -257,7 +265,7 @@ void IndexingExportTest::testIndexingExport_Sections()
     assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "This is a paragraph outside sections");
 
     assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Section2");
-    assertXPath(pXmlDoc, "/indexing/object[2]", "type", "section");
+    assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "section");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "Section2 - Paragraph 1");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Section2 - Paragraph 2");
 
@@ -280,7 +288,7 @@ void IndexingExportTest::testIndexingExport_Fontwork()
     assertXPath(pXmlDoc, "/indexing");
 
     assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Gray");
-    assertXPath(pXmlDoc, "/indexing/object[1]", "type", "shape");
+    assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "shape");
 
     assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Fontwork Text 1");
     assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Fontwork Text 2");
diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
index fd9e8c4f3827..d495f649b870 100644
--- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
+++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx
@@ -88,7 +88,7 @@ void SearchResultLocatorTest::testSearchResultLocatorUsingXmlPayload()
 
     sw::search::SearchResultLocator aLocator(pDoc);
     OString payload = "<indexing>"
-                      "<paragraph type=\"1\" index=\"14\" />"
+                      "<paragraph node_type=\"writer\" index=\"14\" />"
                       "</indexing>";
 
     sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr());
@@ -116,7 +116,7 @@ void SearchResultLocatorTest::testSearchResultLocatorUsingJsonPayload()
 
     sw::search::SearchResultLocator aLocator(pDoc);
     OString payload = "["
-                      "{ \"type\" : 1, \"index\" : 14 }"
+                      "{ \"node_type\" : \"writer\", \"index\" : 14 }"
                       "]";
 
     sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr());
@@ -144,7 +144,7 @@ void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects()
 
     sw::search::SearchResultLocator aLocator(pDoc);
     std::vector<sw::search::SearchIndexData> aDataVector;
-    aDataVector.emplace_back(sw::search::NodeType::SdrObject, 1, u"Circle");
+    aDataVector.emplace_back(sw::search::NodeType::CommonNode, 1, u"Circle");
 
     sw::search::LocationResult aResult = aLocator.find(aDataVector);
     CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
diff --git a/sw/source/core/inc/SearchResultLocator.hxx b/sw/source/core/inc/SearchResultLocator.hxx
index fb46c85253eb..8d146f87ecde 100644
--- a/sw/source/core/inc/SearchResultLocator.hxx
+++ b/sw/source/core/inc/SearchResultLocator.hxx
@@ -20,7 +20,7 @@ enum class NodeType
 {
     Undefined = 0,
     WriterNode = 1,
-    SdrObject = 2
+    CommonNode = 2 // node in a SdrObject
 };
 
 struct SearchIndexData
diff --git a/sw/source/core/model/SearchResultLocator.cxx b/sw/source/core/model/SearchResultLocator.cxx
index 089859683cb4..b4f10a16ca72 100644
--- a/sw/source/core/model/SearchResultLocator.cxx
+++ b/sw/source/core/model/SearchResultLocator.cxx
@@ -51,7 +51,7 @@ void SearchResultLocator::findOne(LocationResult& rResult, SearchIndexData const
                                               rArea.Top() + rArea.Height());
         }
     }
-    else if (rSearchIndexData.meType == NodeType::SdrObject)
+    else if (rSearchIndexData.meType == NodeType::CommonNode)
     {
         IDocumentDrawModelAccess& rDrawModelAccess = mpDocument->getIDocumentDrawModelAccess();
         auto* pModel = rDrawModelAccess.GetDrawModel();
@@ -109,12 +109,18 @@ bool SearchResultLocator::tryParseJSON(const char* pPayload,
     {
         auto const& rEach = rEachNode.second;
 
-        sal_Int32 nType = rEach.get<sal_Int32>("type", 0);
+        std::string sType = rEach.get<std::string>("node_type", "");
+        auto eNodeType = sw::search::NodeType::Undefined;
+        if (sType == "writer")
+            eNodeType = sw::search::NodeType::WriterNode;
+        else if (sType == "common")
+            eNodeType = sw::search::NodeType::CommonNode;
+
         sal_Int32 nIndex = rEach.get<sal_Int32>("index", -1);
 
         // Don't add search data elements that don't have valid data
-        if (nType > 0 && nIndex >= 0)
-            rDataVector.emplace_back(sw::search::NodeType(nType), nIndex);
+        if (eNodeType != sw::search::NodeType::Undefined && nIndex >= 0)
+            rDataVector.emplace_back(eNodeType, nIndex);
     }
 
     return true;
@@ -145,14 +151,20 @@ bool SearchResultLocator::tryParseXML(const char* pPayload,
     {
         if (aWalker.name() == "paragraph")
         {
-            OString sType = aWalker.attribute("type");
+            OString sType = aWalker.attribute("node_type");
             OString sIndex = aWalker.attribute("index");
 
             if (!sType.isEmpty() && !sIndex.isEmpty())
             {
                 sw::search::SearchIndexData aData;
                 aData.mnNodeIndex = sIndex.toInt32();
-                aData.meType = sw::search::NodeType(sType.toInt32());
+                auto eNodeType = sw::search::NodeType::Undefined;
+                if (sType == "writer")
+                    eNodeType = sw::search::NodeType::WriterNode;
+                else if (sType == "common")
+                    eNodeType = sw::search::NodeType::CommonNode;
+
+                aData.meType = eNodeType;
 
                 rDataVector.push_back(aData);
             }
diff --git a/sw/source/filter/indexing/IndexingExport.cxx b/sw/source/filter/indexing/IndexingExport.cxx
index 946c4aaddc06..122db33312c4 100644
--- a/sw/source/filter/indexing/IndexingExport.cxx
+++ b/sw/source/filter/indexing/IndexingExport.cxx
@@ -72,7 +72,7 @@ public:
         m_rXmlWriter.startElement("object");
         m_rXmlWriter.attribute("alt", pOleNode->GetTitle());
         m_rXmlWriter.attribute("name", pFrameFormat->GetName());
-        m_rXmlWriter.attribute("type", "ole");
+        m_rXmlWriter.attribute("object_type", "ole");
         m_rXmlWriter.endElement();
     }
 
@@ -82,7 +82,7 @@ public:
         m_rXmlWriter.startElement("object");
         m_rXmlWriter.attribute("alt", pGraphicNode->GetTitle());
         m_rXmlWriter.attribute("name", pFrameFormat->GetName());
-        m_rXmlWriter.attribute("type", "graphic");
+        m_rXmlWriter.attribute("object_type", "graphic");
         m_rXmlWriter.endElement();
     }
 
@@ -99,7 +99,7 @@ public:
             return;
         m_rXmlWriter.startElement("paragraph");
         m_rXmlWriter.attribute("index", pTextNode->GetIndex());
-        m_rXmlWriter.attribute("type", "1");
+        m_rXmlWriter.attribute("node_type", "writer");
         if (nParentIndex >= 0)
             m_rXmlWriter.attribute("parent", nParentIndex);
         m_rXmlWriter.content(rString);
@@ -114,7 +114,7 @@ public:
         m_rXmlWriter.startElement("object");
         m_rXmlWriter.attribute("name", pObject->GetName());
         m_rXmlWriter.attribute("alt", pObject->GetTitle());
-        m_rXmlWriter.attribute("type", "shape");
+        m_rXmlWriter.attribute("object_type", "shape");
         m_rXmlWriter.attribute("description", pObject->GetDescription());
 
         m_rXmlWriter.endElement();
@@ -130,7 +130,7 @@ public:
 
                 m_rXmlWriter.startElement("paragraph");
                 m_rXmlWriter.attribute("index", nParagraph);
-                m_rXmlWriter.attribute("type", "2");
+                m_rXmlWriter.attribute("node_type", "common");
                 m_rXmlWriter.attribute("parent", pObject->GetName());
                 m_rXmlWriter.content(sText);
                 m_rXmlWriter.endElement();
@@ -146,7 +146,7 @@ public:
         m_rXmlWriter.startElement("object");
         m_rXmlWriter.attribute("index", pTableNode->GetIndex());
         m_rXmlWriter.attribute("name", sName);
-        m_rXmlWriter.attribute("type", "table");
+        m_rXmlWriter.attribute("object_type", "table");
         m_rXmlWriter.endElement();
 
         maNodeStack.push_back(pTableNode);
@@ -157,7 +157,7 @@ public:
         m_rXmlWriter.startElement("object");
         m_rXmlWriter.attribute("index", pSectionNode->GetIndex());
         m_rXmlWriter.attribute("name", pSectionNode->GetSection().GetSectionName());
-        m_rXmlWriter.attribute("type", "section");
+        m_rXmlWriter.attribute("object_type", "section");
         m_rXmlWriter.endElement();
 
         maNodeStack.push_back(pSectionNode);


More information about the Libreoffice-commits mailing list