1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <swmodeltestbase.hxx>
12 #include <unotxdoc.hxx>
14 #include <SearchResultLocator.hxx>
18 class SearchResultLocatorTest
: public SwModelTestBase
21 SearchResultLocatorTest()
22 : SwModelTestBase(u
"/sw/qa/extras/indexing/data/"_ustr
)
26 void testSearchResultLocator();
27 void testSearchResultLocatorUsingXmlPayload();
28 void testSearchResultLocatorUsingJsonPayload();
29 void testSearchResultLocatorForSdrObjects();
30 void testSearchResultLocatorForSdrObjectsUsingJsonPayload();
32 CPPUNIT_TEST_SUITE(SearchResultLocatorTest
);
33 CPPUNIT_TEST(testSearchResultLocator
);
34 CPPUNIT_TEST(testSearchResultLocatorUsingXmlPayload
);
35 CPPUNIT_TEST(testSearchResultLocatorUsingJsonPayload
);
36 CPPUNIT_TEST(testSearchResultLocatorForSdrObjects
);
37 CPPUNIT_TEST(testSearchResultLocatorForSdrObjectsUsingJsonPayload
);
38 CPPUNIT_TEST_SUITE_END();
41 void SearchResultLocatorTest::testSearchResultLocator()
46 createSwDoc("IndexingExport_VariousParagraphs.odt");
47 SwDoc
* pDoc
= getSwDoc();
49 sw::search::SearchResultLocator
aLocator(pDoc
);
50 std::vector
<sw::search::SearchIndexData
> aDataVector
;
51 aDataVector
.emplace_back(sw::search::NodeType::WriterNode
, SwNodeOffset(14));
53 sw::search::LocationResult aResult
= aLocator
.find(aDataVector
);
54 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult
.maRectangles
.size());
56 // skip asserting exact values for macOS and Windows because of
57 // inconsistent results
58 #if !defined(_WIN32) && !defined(MACOSX)
59 auto aRectangle
= aResult
.maRectangles
[0];
60 CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle
.getMinX(), 1e-4);
61 CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle
.getMinY(), 1e-4);
63 CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle
.getWidth(), 1e-4);
64 CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle
.getHeight(), 1e-4);
68 void SearchResultLocatorTest::testSearchResultLocatorUsingXmlPayload()
73 createSwDoc("IndexingExport_VariousParagraphs.odt");
74 SwDoc
* pDoc
= getSwDoc();
76 sw::search::SearchResultLocator
aLocator(pDoc
);
77 OString payload
= "<indexing>"
78 "<paragraph node_type=\"writer\" index=\"14\" />"
81 sw::search::LocationResult aResult
= aLocator
.findForPayload(payload
.getStr());
82 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult
.maRectangles
.size());
84 // skip asserting exact values for macOS and Windows because of
85 // inconsistent results
86 #if !defined(_WIN32) && !defined(MACOSX)
87 auto aRectangle
= aResult
.maRectangles
[0];
88 CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle
.getMinX(), 1e-4);
89 CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle
.getMinY(), 1e-4);
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle
.getWidth(), 1e-4);
92 CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle
.getHeight(), 1e-4);
96 void SearchResultLocatorTest::testSearchResultLocatorUsingJsonPayload()
101 createSwDoc("IndexingExport_VariousParagraphs.odt");
102 SwDoc
* pDoc
= getSwDoc();
104 sw::search::SearchResultLocator
aLocator(pDoc
);
105 OString payload
= "["
106 "{ \"node_type\" : \"writer\", \"index\" : 14 }"
109 sw::search::LocationResult aResult
= aLocator
.findForPayload(payload
.getStr());
110 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult
.maRectangles
.size());
112 // skip asserting exact values for macOS and Windows because of
113 // inconsistent results
114 #if !defined(_WIN32) && !defined(MACOSX)
115 auto aRectangle
= aResult
.maRectangles
[0];
116 CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle
.getMinX(), 1e-4);
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle
.getMinY(), 1e-4);
119 CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle
.getWidth(), 1e-4);
120 CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle
.getHeight(), 1e-4);
124 void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects()
129 createSwDoc("IndexingExport_Shapes.odt");
130 SwDoc
* pDoc
= getSwDoc();
132 sw::search::SearchResultLocator
aLocator(pDoc
);
133 std::vector
<sw::search::SearchIndexData
> aDataVector
;
134 aDataVector
.emplace_back(sw::search::NodeType::CommonNode
, SwNodeOffset(1), u
"Circle"_ustr
);
136 sw::search::LocationResult aResult
= aLocator
.find(aDataVector
);
137 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult
.maRectangles
.size());
139 // skip asserting exact values for macOS and Windows because of
140 // inconsistent results
141 #if !defined(_WIN32) && !defined(MACOSX)
142 auto aRectangle
= aResult
.maRectangles
[0];
143 CPPUNIT_ASSERT_DOUBLES_EQUAL(2607.0, aRectangle
.getMinX(), 1e-4);
144 CPPUNIT_ASSERT_DOUBLES_EQUAL(5685.0, aRectangle
.getMinY(), 1e-4);
146 CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle
.getWidth(), 1e-4);
147 CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle
.getHeight(), 1e-4);
151 void SearchResultLocatorTest::testSearchResultLocatorForSdrObjectsUsingJsonPayload()
156 createSwDoc("IndexingExport_Shapes.odt");
157 SwDoc
* pDoc
= getSwDoc();
159 sw::search::SearchResultLocator
aLocator(pDoc
);
160 OString payload
= "["
161 "{ \"node_type\" : \"common\", \"index\" : 1, \"object_name\" : \"Circle\" }"
164 sw::search::LocationResult aResult
= aLocator
.findForPayload(payload
.getStr());
165 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult
.maRectangles
.size());
167 // skip asserting exact values for macOS and Windows because of
168 // inconsistent results
169 #if !defined(_WIN32) && !defined(MACOSX)
170 auto aRectangle
= aResult
.maRectangles
[0];
171 CPPUNIT_ASSERT_DOUBLES_EQUAL(2607.0, aRectangle
.getMinX(), 1e-4);
172 CPPUNIT_ASSERT_DOUBLES_EQUAL(5685.0, aRectangle
.getMinY(), 1e-4);
174 CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle
.getWidth(), 1e-4);
175 CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle
.getHeight(), 1e-4);
179 } // end of anonymous namespace
180 CPPUNIT_TEST_SUITE_REGISTRATION(SearchResultLocatorTest
);
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */