//
//  First
//
TEST_F( SimplexSupportDoublyLinkedList, FirstReturnsLastElementPushedToFront )
{
    MockStruct* m1 = new MockStruct();
    MockStruct* m2 = new MockStruct();
    MockStruct* m3 = new MockStruct();

    DoublyLinkedList list;

    list.PushFront(m1);

    ASSERT_EQ(list.First()->Value, (MockStruct*)m1);

    list.PushFront(m2);

    ASSERT_EQ(list.First()->Value, (MockStruct*)m2);

    list.PushFront(m3);

    ASSERT_EQ(list.First()->Value, (MockStruct*)m3);

    delete(m1);
    delete(m2);
    delete(m3);

}
TEST_F( SimplexSupportDoublyLinkedList, PushBackSetsFirstElementIfNoElementPresent )
{
    MockStruct* m = new MockStruct();
    DoublyLinkedList list;

    list.PushBack( m );

    ASSERT_EQ ( (MockStruct*)list.First()->Value, m );

    delete(m);
}
TEST_F( SimplexSupportDoublyLinkedList, PopBackUpdatesFirstWhenListIsEmptied )
{
    MockStruct* m = new MockStruct();
    DoublyLinkedList list;

    list.PushBack( m );
    list.PopBack();

    ASSERT_EQ ( list.First(), nullptr );
    delete(m);
}
TEST_F( SimplexSupportDoublyLinkedList, PushFrontAddsElement )
{
    MockStruct* m = new MockStruct();
    DoublyLinkedList list;

    list.PushFront( m );

    ASSERT_EQ ( (MockStruct*)list.First()->Value, m );

    delete(m);
}
TEST_F( SimplexSupportDoublyLinkedList, PushFrontPreservesConnectionToPreviousFirst )
{
    MockStruct* m1 = new MockStruct();
    MockStruct* m2 = new MockStruct();

    DoublyLinkedList list;

    list.PushFront(m1);
    list.PushFront(m2);

    ASSERT_EQ(list.First()->Next->Value, (MockStruct*)m1);

    delete(m1);
    delete(m2);
}
TEST_F( SimplexSupportDoublyLinkedList, PushBackSetsPreviousAndNextCorrectly )
{
    MockStruct* m1 = new MockStruct();
    MockStruct* m2 = new MockStruct();

    DoublyLinkedList list;

    list.PushBack( m1 );
    list.PushBack( m2 );

    ASSERT_EQ( list.Last()->Previous->Value, m1);
    ASSERT_EQ( list.First()->Next->Value, m2);

    delete(m1);
    delete(m2);
}
//
//  RemoveAt
//
TEST_F( SimplexSupportDoublyLinkedList, RemoveAtLeavesAConsistentList )
{
    MockStruct* m1 = new MockStruct();
    MockStruct* m2 = new MockStruct();
    MockStruct* m3 = new MockStruct();

    DoublyLinkedList list;

    list.PushBack(m1);
    list.PushBack(m2);
    list.PushBack(m3);

    list.RemoveAt(1);

    ASSERT_EQ((MockStruct*)list.First()->Next->Value, m3);
    ASSERT_EQ((MockStruct*)list.Last()->Previous->Value, m1);

    delete(m1);
    delete(m2);
    delete(m3);
}
예제 #8
0
// RemoveAttribute
status_t
Node::RemoveAttribute(Attribute *attribute)
{
	status_t error = (attribute && attribute->GetNode() == this
					  ? B_OK : B_BAD_VALUE);
	if (error == B_OK) {
		// move all iterators pointing to the attribute to the next attribute
		if (GetVolume()->IteratorLock()) {
			// set the iterators' current entry
			Attribute *nextAttr = fAttributes.GetNext(attribute);
			DoublyLinkedList<AttributeIterator> *iterators
				= attribute->GetAttributeIteratorList();
			for (AttributeIterator *iterator = iterators->First();
				 iterator;
				 iterator = iterators->GetNext(iterator)) {
				iterator->SetCurrent(nextAttr, true);
			}
			// Move the iterators from one list to the other, or just remove
			// them, if there is no next attribute.
			if (nextAttr) {
				DoublyLinkedList<AttributeIterator> *nextIterators
					= nextAttr->GetAttributeIteratorList();
				nextIterators->MoveFrom(iterators);
			} else
				iterators->RemoveAll();
			GetVolume()->IteratorUnlock();
		} else
			error = B_ERROR;
		// remove the attribute
		if (error == B_OK) {
			error = GetVolume()->NodeAttributeRemoved(GetID(), attribute);
			if (error == B_OK) {
				fAttributes.Remove(attribute);
				attribute->SetNode(NULL);
				MarkModified();
			}
		}
	}
	return error;
}