Backed out changeset 91536bfeff0f (bug 1201997)

--HG--
extra : rebase_source : 6f11d67034e876738ecda6f1e32c8e655252660f
This commit is contained in:
Carsten "Tomcat" Book 2015-10-30 15:52:21 +01:00
Родитель 4c0ed54e29
Коммит eb7db9ff93
2 изменённых файлов: 56 добавлений и 8 удалений

Просмотреть файл

@ -140,6 +140,11 @@ public:
*/
void* ObjectAt(int aIndex) const;
/**
* Remove all items from container without destroying them.
*/
void Empty();
/**
* Remove and delete all items from container.
* Deletes are handled by the deallocator nsDequeFunctor
@ -156,6 +161,8 @@ public:
*/
void ForEach(nsDequeFunctor& aFunctor) const;
void SetDeallocator(nsDequeFunctor* aDeallocator);
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
@ -185,11 +192,5 @@ private:
nsDeque& operator=(const nsDeque& aOther);
bool GrowCapacity();
void SetDeallocator(nsDequeFunctor* aDeallocator);
/**
* Remove all items from container without destroying them.
*/
void Empty();
};
#endif

Просмотреть файл

@ -67,7 +67,7 @@ namespace TestNsDeque {
using namespace TestNsDeque;
TEST(NsDeque, OriginalTest)
TEST(NsDeque, OriginalTest)
{
const int size = 200;
int ints[size];
@ -181,6 +181,8 @@ TEST(NsDeque, OriginalFlaw)
}
}
TEST(NsDeque, TestObjectAt)
{
nsDeque d;
@ -277,11 +279,27 @@ TEST(NsDeque,TestEmpty)
EXPECT_EQ(nullptr, d.ObjectAt(0)) << "Invalid operation should return nullptr";
}
TEST(NsDeque,TestEraseMethod)
TEST(NsDeque,TestEmptyMethod)
{
nsDeque d;
size_t numberOfEntries = 8;
// Fill it up before calling Empty
for (size_t i = 0; i < numberOfEntries; i++) {
d.Push((void*)0xAA);
}
// Call empty
d.Empty();
// Now check it again.
EXPECT_EQ(0, d.GetSize()) <<"Size should be 0";
EXPECT_EQ(nullptr, d.Pop()) <<"Invalid operation should return nullptr";
EXPECT_EQ(nullptr, d.PopFront()) << "Invalid operation should return nullptr";
EXPECT_EQ(nullptr, d.Peek()) << "Invalid operation should return nullptr";
EXPECT_EQ(nullptr, d.PeekFront()) <<"Invalid operation should return nullptr";
EXPECT_EQ(nullptr, d.ObjectAt(0)) << "Invalid operation should return nullptr";
// Fill it up before calling Erase
for (size_t i = 0; i < numberOfEntries; i++) {
d.Push((void*)0xAA);
@ -325,6 +343,35 @@ TEST(NsDeque,TestEraseShouldCallDeallocator)
for (size_t i=0; i < NumTestValues; i++)
{
EXPECT_EQ(-1, *(testArray[i])) << "Erase should call deallocator: " << *(testArray[i]);
}
}
TEST(NsDeque,TestEmptyShouldNotCallDeallocator)
{
nsDeque d(new Deallocator());
const int NumTestValues = 8;
int* testArray[NumTestValues];
for (size_t i=0; i < NumTestValues; i++)
{
testArray[i] = new int();
*(testArray[i]) = i;
d.Push((void*)testArray[i]);
}
d.Empty();
// Now check it again.
EXPECT_EQ(0, d.GetSize()) <<"Size should be 0";
EXPECT_EQ(nullptr, d.Pop()) <<"Invalid operation should return nullptr";
EXPECT_EQ(nullptr, d.PopFront()) << "Invalid operation should return nullptr";
EXPECT_EQ(nullptr, d.Peek()) << "Invalid operation should return nullptr";
EXPECT_EQ(nullptr, d.PeekFront()) <<"Invalid operation should return nullptr";
EXPECT_EQ(nullptr, d.ObjectAt(0)) << "Invalid operation should return nullptr";
for (size_t i=0; i < NumTestValues; i++)
{
EXPECT_EQ(i, *(testArray[i])) << "Empty should not call deallocator";
}
}