summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Anthony Giusti <kgiusti@apache.org>2011-02-03 15:56:08 +0000
committerKenneth Anthony Giusti <kgiusti@apache.org>2011-02-03 15:56:08 +0000
commit85be68c870d58685d748d282dba301efd75d642d (patch)
treebb6f189ffca1b9b5bc1eb4cfa2d480a6319b74f9
parentd35058e5d23d011faf76629b3daeec5ca846b6e2 (diff)
downloadqpid-python-85be68c870d58685d748d282dba301efd75d642d.tar.gz
QPID-3035: fix incorrect removal at end of SequenceSet
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1066841 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--cpp/include/qpid/RangeSet.h4
-rw-r--r--cpp/src/tests/SequenceSet.cpp44
2 files changed, 46 insertions, 2 deletions
diff --git a/cpp/include/qpid/RangeSet.h b/cpp/include/qpid/RangeSet.h
index 1b2e4201a6..36991fd784 100644
--- a/cpp/include/qpid/RangeSet.h
+++ b/cpp/include/qpid/RangeSet.h
@@ -265,8 +265,8 @@ template <class T> void RangeSet<T>::removeRange(const Range<T>& r) {
}
for (j = i; j != ranges.end() && r.contains(*j); ++j)
; // Ranges to erase.
- if (j != ranges.end() && j->end() > r.end())
- j->begin(r.end()); // Truncate j
+ if (j != ranges.end() && r.end() > j->begin())
+ j->begin(r.end()); // Truncate j
ranges.erase(i,j);
}
}
diff --git a/cpp/src/tests/SequenceSet.cpp b/cpp/src/tests/SequenceSet.cpp
index aaeb68e3c5..bc0a8ea509 100644
--- a/cpp/src/tests/SequenceSet.cpp
+++ b/cpp/src/tests/SequenceSet.cpp
@@ -138,6 +138,50 @@ QPID_AUTO_TEST_CASE(testRemove) {
RangeExpectations().expect(3, 5).expect(7, 7).expect(9, 10).check(t);
}
+
+QPID_AUTO_TEST_CASE(testOutOfOrderRemove) {
+
+ SequenceSet s(2, 20);
+
+ // test remove from middle:
+ s.remove(7);
+ RangeExpectations().expect(2, 6).expect(8, 20).check(s);
+ s.remove(14);
+ RangeExpectations().expect(2, 6).expect(8, 13).expect(15, 20).check(s);
+
+ // remove from front of subrange:
+ s.remove(8, 8);
+ RangeExpectations().expect(2, 6).expect(9, 13).expect(15, 20).check(s);
+
+ // remove from tail of subrange:
+ s.remove(6);
+ RangeExpectations().expect(2, 5).expect(9, 13).expect(15, 20).check(s);
+
+ // remove across subrange:
+ s.remove(13, 15);
+ RangeExpectations().expect(2, 5).expect(9, 12).expect(16, 20).check(s);
+
+ // remove within subrange:
+ s.remove(6, 8);
+ RangeExpectations().expect(2, 5).expect(9, 12).expect(16, 20).check(s);
+
+ // remove overlap subrange tail:
+ s.remove(11, 15);
+ RangeExpectations().expect(2, 5).expect(9, 10).expect(16, 20).check(s);
+
+ // remove overlap subrange head:
+ s.remove(14, 17);
+ RangeExpectations().expect(2, 5).expect(9, 10).expect(18, 20).check(s);
+
+ // remove overlap sequence tail:
+ s.remove(20, 22);
+ RangeExpectations().expect(2, 5).expect(9, 10).expect(18, 19).check(s);
+
+ // remove overlap sequence head:
+ s.remove(1, 3);
+ RangeExpectations().expect(4, 5).expect(9, 10).expect(18, 19).check(s);
+}
+
QPID_AUTO_TEST_SUITE_END()
}} // namespace qpid::tests