tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sw / qa / extras / indexing / SearchResultLocatorTest.cxx
blob9e239430a0b525d26e212ff51a05bdd989cdaa01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <swmodeltestbase.hxx>
11 #include <docsh.hxx>
12 #include <unotxdoc.hxx>
14 #include <SearchResultLocator.hxx>
16 namespace
18 class SearchResultLocatorTest : public SwModelTestBase
20 public:
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()
43 if (!IsDefaultDPI())
44 return;
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);
65 #endif
68 void SearchResultLocatorTest::testSearchResultLocatorUsingXmlPayload()
70 if (!IsDefaultDPI())
71 return;
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\" />"
79 "</indexing>"_ostr;
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);
93 #endif
96 void SearchResultLocatorTest::testSearchResultLocatorUsingJsonPayload()
98 if (!IsDefaultDPI())
99 return;
101 createSwDoc("IndexingExport_VariousParagraphs.odt");
102 SwDoc* pDoc = getSwDoc();
104 sw::search::SearchResultLocator aLocator(pDoc);
105 OString payload = "["
106 "{ \"node_type\" : \"writer\", \"index\" : 14 }"
107 "]"_ostr;
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);
121 #endif
124 void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects()
126 if (!IsDefaultDPI())
127 return;
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);
148 #endif
151 void SearchResultLocatorTest::testSearchResultLocatorForSdrObjectsUsingJsonPayload()
153 if (!IsDefaultDPI())
154 return;
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\" }"
162 "]"_ostr;
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);
176 #endif
179 } // end of anonymous namespace
180 CPPUNIT_TEST_SUITE_REGISTRATION(SearchResultLocatorTest);
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */