Skip to content

Commit

Permalink
Merge pull request #3 from aiforia/fix-inserting-before-current-list-…
Browse files Browse the repository at this point in the history
…item

Fix inserting before current list item
  • Loading branch information
reunanen authored Jan 17, 2025
2 parents 550bc99 + 469ac42 commit 7b11e37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dcmdata/libsrc/dclist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ DcmObject *DcmList::insert( DcmObject *obj, E_ListPos pos )
node->nextNode = currentNode;
currentNode->prevNode = node;
currentNode = node;
currentAbsolutePosition++;
// NB: no need to update currentAbsolutePosition
cardinality++;
}
else //( pos==ELP_next || pos==ELP_atpos )
Expand Down
22 changes: 17 additions & 5 deletions dcmdata/tests/tsequen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,31 @@ OFTEST(dcmdata_sequenceInsert)
DcmSequenceOfItems sequence(DCM_OtherPatientIDsSequence);
/* add a large number of items to the sequence */
unsigned long counter = 0;
DcmItem* initiallyInsertedItems[NUMBER_OF_ITEMS];
for (unsigned long i = 0; i < NUMBER_OF_ITEMS; ++i)
{
if (sequence.insert(new DcmItem()).good())
DcmItem* item = new DcmItem();
initiallyInsertedItems[i] = item;
if (sequence.insert(item).good())
++counter;
}
/* check whether that worked (for-loop shouldn't take too long) */
OFCHECK_EQUAL(counter, NUMBER_OF_ITEMS);
/* access specific items (performance should be no issue) */
OFCHECK(sequence.getItem(0) != NULL);
OFCHECK(sequence.getItem(2) != NULL);
OFCHECK(sequence.getItem(0) == initiallyInsertedItems[0]);
OFCHECK(sequence.getItem(2) == initiallyInsertedItems[2]);
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS) == NULL);
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS - 1) != NULL);
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS - 2) != NULL);
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS - 1) == initiallyInsertedItems[NUMBER_OF_ITEMS - 1]);
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS - 2) == initiallyInsertedItems[NUMBER_OF_ITEMS - 2]);
/* insert a single item before the current item */
DcmItem* item = new DcmItem();
OFBool before = true;
OFCHECK(sequence.insertAtCurrentPos(item, before).good());
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS - 2) == item);
/* the items after the new item should have been shifted by one */
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS - 1) == initiallyInsertedItems[NUMBER_OF_ITEMS - 2]);
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS) == initiallyInsertedItems[NUMBER_OF_ITEMS - 1]);
OFCHECK(sequence.getItem(NUMBER_OF_ITEMS + 1) == NULL);
}


Expand Down

0 comments on commit 7b11e37

Please sign in to comment.