summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-29 23:52:50 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-06-03 13:26:40 +0200
commit83d27791fed75941c75d3cc571c3d5cf27d14e8c (patch)
tree4fa75b80e322791796af560d110deebdd545d688 /vcl/qa
parent997a504f33bbd43c02a96a2a593a03e58bd3b72c (diff)
vcl: add search start position support for VectorGraphicSearch
By default we start at the begin of the page, but with this change make it possible to start at the end. This makes it possible to search in the backwards direction (set the start position at to the end and search with "previous"). Change-Id: I78fb1461b86bf9eab2f91c3b9a81cbb5c6557332 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95382 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/VectorGraphicSearchTest.cxx79
1 files changed, 59 insertions, 20 deletions
diff --git a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
index 7962c23f4e8f..5f65b4ba7e3d 100644
--- a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
+++ b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
@@ -93,32 +93,71 @@ void VectorGraphicSearchTest::testNextPrevious()
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
aGraphic.makeAvailable();
- VectorGraphicSearch aSearch(aGraphic);
- CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy"));
+ { // Start from the beginning of the page
+ VectorGraphicSearch aSearch(aGraphic);
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy"));
- // next - first match found
- CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
- CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+ // no previous - we are at the begin
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(0, aSearch.index()); // nothing was yet found, so it is 0
- // next - second match found
- CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
- CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+ // next - first position found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
- // next - not found, index unchanged
- CPPUNIT_ASSERT_EQUAL(false, aSearch.next());
- CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+ // next - second position found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
- // previous - first match
- CPPUNIT_ASSERT_EQUAL(true, aSearch.previous());
- CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+ // next - not found, index unchanged
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
- // previous - not found, index unchanged
- CPPUNIT_ASSERT_EQUAL(false, aSearch.previous());
- CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+ // previous - first position
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
- // next - second match found
- CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
- CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+ // previous - not found, index unchanged
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+
+ // next - second position found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+ }
+
+ { // Start from the end of the page
+ VectorGraphicSearch aSearch(aGraphic);
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy", SearchStartPosition::End));
+
+ // no next - we are at the end
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(0, aSearch.index()); // nothing was yet found, so it is 0
+
+ // previous - second position found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+
+ // previous - first position found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+
+ // previous - not found, index unchanged
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+
+ // next - second position
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+
+ // next - not found, index unchanged
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+
+ // previous - first match found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+ }
}
CPPUNIT_TEST_SUITE_REGISTRATION(VectorGraphicSearchTest);