Skip to content

Commit

Permalink
Bug 1170045 - part 0 - modify TestSegmentedVectors to use explicitly-…
Browse files Browse the repository at this point in the history
…updated counts; r=erahm

The scheme in TestSegmentedVectors to use manually-annotated points and
magic numbers corresponding to those annotations works OK for small
numbers of operations.  But for testing bulk push and pop, we're going
to be doing many more operations, so let's move to recording explicitly
in code the operations we expect to see, and checking those instead.
  • Loading branch information
froydnj committed Mar 4, 2016
1 parent 64fe772 commit 10eb1a5
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions mfbt/tests/TestSegmentedVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,43 @@ struct NonPOD
// destruct those elements.
void TestConstructorsAndDestructors()
{
size_t defaultCtorCalls = 0;
size_t explicitCtorCalls = 0;
size_t copyCtorCalls = 0;
size_t moveCtorCalls = 0;
size_t dtorCalls = 0;

{
// A SegmentedVector with a non-POD element type.
NonPOD x(1); // explicit constructor called
explicitCtorCalls++;
SegmentedVector<NonPOD, 64, InfallibleAllocPolicy> v;
// default constructor called 0 times
MOZ_RELEASE_ASSERT(v.IsEmpty());
gDummy = v.Append(x); // copy constructor called
copyCtorCalls++;
NonPOD y(1); // explicit constructor called
explicitCtorCalls++;
gDummy = v.Append(mozilla::Move(y)); // move constructor called
moveCtorCalls++;
NonPOD z(1); // explicit constructor called
explicitCtorCalls++;
v.InfallibleAppend(mozilla::Move(z)); // move constructor called
moveCtorCalls++;
v.PopLast(); // destructor called 1 time
MOZ_RELEASE_ASSERT(gNumDtors == 1);
dtorCalls++;
MOZ_RELEASE_ASSERT(gNumDtors == dtorCalls);
v.Clear(); // destructor called 2 times
dtorCalls += 2;

MOZ_RELEASE_ASSERT(gNumDefaultCtors == 0);
MOZ_RELEASE_ASSERT(gNumExplicitCtors == 3);
MOZ_RELEASE_ASSERT(gNumCopyCtors == 1);
MOZ_RELEASE_ASSERT(gNumMoveCtors == 2);
MOZ_RELEASE_ASSERT(gNumDtors == 3);
MOZ_RELEASE_ASSERT(gNumDefaultCtors == defaultCtorCalls);
MOZ_RELEASE_ASSERT(gNumExplicitCtors == explicitCtorCalls);
MOZ_RELEASE_ASSERT(gNumCopyCtors == copyCtorCalls);
MOZ_RELEASE_ASSERT(gNumMoveCtors == moveCtorCalls);
MOZ_RELEASE_ASSERT(gNumDtors == dtorCalls);
} // destructor called for x, y, z
MOZ_RELEASE_ASSERT(gNumDtors == 6);
dtorCalls += 3;
MOZ_RELEASE_ASSERT(gNumDtors == dtorCalls);
}

struct A { int mX; int mY; };
Expand Down

0 comments on commit 10eb1a5

Please sign in to comment.