diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-09-06 14:17:01 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-09-08 06:57:23 +0200 |
commit | eac288d02cafc49c5a14fa27bb449c33eb4b1803 (patch) | |
tree | 18ad2fe9d037db7623ddf0810004e904130cf7a4 /sw/qa | |
parent | 8151f3a1d99ab740d2affdccc7115faa156bf3ad (diff) |
indexing: support JSON and XML as input for SearchResultLocator
JSON is much easier to deal with when using REST and javascript,
so support both.
Change-Id: I61035452d9a7ba889ac355a42201d79b9fafec6f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121742
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/extras/indexing/SearchResultLocatorTest.cxx | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx index c740f982b2c3..fd9e8c4f3827 100644 --- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx +++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx @@ -27,12 +27,14 @@ private: public: void testSearchResultLocator(); - void testSearchResultLocatorUsingPayload(); + void testSearchResultLocatorUsingXmlPayload(); + void testSearchResultLocatorUsingJsonPayload(); void testSearchResultLocatorForSdrObjects(); CPPUNIT_TEST_SUITE(SearchResultLocatorTest); CPPUNIT_TEST(testSearchResultLocator); - CPPUNIT_TEST(testSearchResultLocatorUsingPayload); + CPPUNIT_TEST(testSearchResultLocatorUsingXmlPayload); + CPPUNIT_TEST(testSearchResultLocatorUsingJsonPayload); CPPUNIT_TEST(testSearchResultLocatorForSdrObjects); CPPUNIT_TEST_SUITE_END(); }; @@ -76,7 +78,7 @@ void SearchResultLocatorTest::testSearchResultLocator() #endif } -void SearchResultLocatorTest::testSearchResultLocatorUsingPayload() +void SearchResultLocatorTest::testSearchResultLocatorUsingXmlPayload() { if (!IsDefaultDPI()) return; @@ -104,6 +106,34 @@ void SearchResultLocatorTest::testSearchResultLocatorUsingPayload() #endif } +void SearchResultLocatorTest::testSearchResultLocatorUsingJsonPayload() +{ + if (!IsDefaultDPI()) + return; + + SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt"); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + OString payload = "[" + "{ \"type\" : 1, \"index\" : 14 }" + "]"; + + sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr()); + CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size()); + + // skip asserting exact values for macOS and Windows because of + // inconsistent results +#if !defined(_WIN32) && !defined(MACOSX) + auto aRectangle = aResult.maRectangles[0]; + CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4); +#endif +} + void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects() { if (!IsDefaultDPI()) |