summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew J. Francis <mjay.francis@gmail.com>2015-06-04 15:56:58 +0800
committerNorbert Thiebaud <nthiebaud@gmail.com>2015-06-14 15:03:58 +0000
commit46e12364dcf638e97831dc3d7507bb6b93377757 (patch)
treebf4111815f9ccb9437a7cd3fd23778890b0b177f
parentResolves: tdf#91393 autotext (etc) not fully drawn (diff)
downloadcore-46e12364dcf638e97831dc3d7507bb6b93377757.tar.gz
core-46e12364dcf638e97831dc3d7507bb6b93377757.zip
Fix insertion and deletion in IndexedPropertyValuesContainer
The cases for iterating to an element from the end (used for elements in the second half of the underlying array) had an off by one error causing the wrong elements to be inserted/removed Change-Id: Idcbf158cc31afaf02fce3f1975509edf6239d3ae Reviewed-on: https://gerrit.libreoffice.org/16073 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com>
-rw-r--r--comphelper/source/container/IndexedPropertyValuesContainer.cxx4
-rw-r--r--sw/qa/complex/writer/CheckIndexedPropertyValues.java18
2 files changed, 19 insertions, 3 deletions
diff --git a/comphelper/source/container/IndexedPropertyValuesContainer.cxx b/comphelper/source/container/IndexedPropertyValuesContainer.cxx
index cd329af150e9..b8b91f3ee48f 100644
--- a/comphelper/source/container/IndexedPropertyValuesContainer.cxx
+++ b/comphelper/source/container/IndexedPropertyValuesContainer.cxx
@@ -116,7 +116,7 @@ void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, c
else
{
aItr = maProperties.end();
- sal_Int32 i(nSize - 1);
+ sal_Int32 i(nSize);
while(i > nIndex)
{
--i;
@@ -151,7 +151,7 @@ void SAL_CALL IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex )
else
{
aItr = maProperties.end();
- sal_Int32 i(nSize - 1);
+ sal_Int32 i(nSize);
while(i > nIndex)
{
--i;
diff --git a/sw/qa/complex/writer/CheckIndexedPropertyValues.java b/sw/qa/complex/writer/CheckIndexedPropertyValues.java
index c52617642995..338f7065e02c 100644
--- a/sw/qa/complex/writer/CheckIndexedPropertyValues.java
+++ b/sw/qa/complex/writer/CheckIndexedPropertyValues.java
@@ -53,6 +53,11 @@ public class CheckIndexedPropertyValues {
prop2[0].Name = "Horst";
prop2[0].Value = "BadGuy";
+ PropertyValue[] prop3 = new PropertyValue[1];
+ prop3[0] = new PropertyValue();
+ prop3[0].Name = "Peter";
+ prop3[0].Value = "FamilyGuy";
+
Type t = xCont.getElementType();
assertEquals("Initial container is not empty", 0, xCont.getCount());
xCont.insertByIndex(0, prop1);
@@ -70,6 +75,17 @@ public class CheckIndexedPropertyValues {
xCont.insertByIndex(1, prop2);
assertTrue("Did not insert PropertyValue.",
xCont.hasElements() && xCont.getCount()==2);
+ try {
+ xCont.removeByIndex(1);
+ }
+ catch (com.sun.star.lang.IndexOutOfBoundsException e) {
+ fail("Could not remove last PropertyValue");
+ }
+ xCont.insertByIndex(1, prop2);
+ xCont.insertByIndex(1, prop3);
+ ret = (PropertyValue[])xCont.getByIndex(1);
+ assertEquals(prop3[0].Name, ret[0].Name);
+ assertEquals(prop3[0].Value, ret[0].Value);
try {
xCont.insertByIndex(25, prop2);
@@ -86,7 +102,7 @@ public class CheckIndexedPropertyValues {
}
try {
- xCont.insertByIndex(2, "Example String");
+ xCont.insertByIndex(3, "Example String");
fail("IllegalArgumentException was not thrown.");
}
catch(com.sun.star.lang.IllegalArgumentException e) {