Added test case for growing FixedSizeSecBlock. Fixed copy count during grow
parent
5849767735
commit
81482d8348
|
|
@ -399,7 +399,7 @@ public:
|
||||||
if (preserve && newSize)
|
if (preserve && newSize)
|
||||||
{
|
{
|
||||||
const size_t copySize = STDMIN(oldSize, newSize);
|
const size_t copySize = STDMIN(oldSize, newSize);
|
||||||
memcpy_s(newPointer, copySize, oldPtr, copySize);
|
memcpy_s(newPointer, sizeof(T)*newSize, oldPtr, sizeof(T)*copySize);
|
||||||
}
|
}
|
||||||
deallocate(oldPtr, oldSize);
|
deallocate(oldPtr, oldSize);
|
||||||
return newPointer;
|
return newPointer;
|
||||||
|
|
|
||||||
78
validat1.cpp
78
validat1.cpp
|
|
@ -483,7 +483,6 @@ bool TestSecBlock()
|
||||||
a += a;
|
a += a;
|
||||||
temp &= (a.SizeInBytes() == 16);
|
temp &= (a.SizeInBytes() == 16);
|
||||||
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2);
|
temp &= (a[0] == 1 && a[1] == 2 && a[2] == 1 && a[3] == 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(const Exception& /*ex*/)
|
catch(const Exception& /*ex*/)
|
||||||
{
|
{
|
||||||
|
|
@ -655,7 +654,6 @@ bool TestSecBlock()
|
||||||
AllocatorBase<word32> A;
|
AllocatorBase<word32> A;
|
||||||
const size_t max = A.max_size();
|
const size_t max = A.max_size();
|
||||||
SecBlock<word32> t(max+1);
|
SecBlock<word32> t(max+1);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(const Exception& /*ex*/)
|
catch(const Exception& /*ex*/)
|
||||||
{
|
{
|
||||||
|
|
@ -679,7 +677,6 @@ bool TestSecBlock()
|
||||||
AllocatorBase<word64> A;
|
AllocatorBase<word64> A;
|
||||||
const size_t max = A.max_size();
|
const size_t max = A.max_size();
|
||||||
SecBlock<word64> t(max+1);
|
SecBlock<word64> t(max+1);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(const Exception& /*ex*/)
|
catch(const Exception& /*ex*/)
|
||||||
{
|
{
|
||||||
|
|
@ -697,6 +694,81 @@ bool TestSecBlock()
|
||||||
cout << "passed:";
|
cout << "passed:";
|
||||||
cout << " Overflow word64" << endl;
|
cout << " Overflow word64" << endl;
|
||||||
|
|
||||||
|
//********** FixedSizeAllocatorWithCleanup and Grow **********//
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
static const unsigned int SIZE = 8;
|
||||||
|
SecBlockWithHint<byte, SIZE> block(SIZE);
|
||||||
|
memset(block, 0xaa, block.SizeInBytes());
|
||||||
|
|
||||||
|
temp = true;
|
||||||
|
block.CleanGrow(SIZE*2);
|
||||||
|
temp &= (block.size() == SIZE*2);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < block.size()/2; i++)
|
||||||
|
temp &= (block[i] == 0xaa);
|
||||||
|
for (size_t i = block.size()/2; i < block.size(); i++)
|
||||||
|
temp &= (block[i] == 0);
|
||||||
|
|
||||||
|
block.CleanNew(SIZE*4);
|
||||||
|
temp &= (block.size() == SIZE*4);
|
||||||
|
for (size_t i = 0; i < block.size(); i++)
|
||||||
|
temp &= (block[i] == 0);
|
||||||
|
|
||||||
|
result &= temp;
|
||||||
|
if (!temp)
|
||||||
|
cout << "FAILED:";
|
||||||
|
else
|
||||||
|
cout << "passed:";
|
||||||
|
cout << " FixedSizeAllocator and Grow with byte" << endl;
|
||||||
|
}
|
||||||
|
catch(const Exception& /*ex*/)
|
||||||
|
{
|
||||||
|
temp = false;
|
||||||
|
}
|
||||||
|
catch(const std::exception& /*ex*/)
|
||||||
|
{
|
||||||
|
temp = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
static const unsigned int SIZE = 8;
|
||||||
|
SecBlockWithHint<word32, SIZE> block(SIZE);
|
||||||
|
memset(block, 0xaa, block.SizeInBytes());
|
||||||
|
|
||||||
|
temp = true;
|
||||||
|
block.CleanGrow(SIZE*2);
|
||||||
|
temp &= (block.size() == SIZE*2);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < block.size()/2; i++)
|
||||||
|
temp &= (block[i] == 0xaaaaaaaa);
|
||||||
|
|
||||||
|
for (size_t i = block.size()/2; i < block.size(); i++)
|
||||||
|
temp &= (block[i] == 0);
|
||||||
|
|
||||||
|
block.CleanNew(SIZE*4);
|
||||||
|
temp &= (block.size() == SIZE*4);
|
||||||
|
for (size_t i = 0; i < block.size(); i++)
|
||||||
|
temp &= (block[i] == 0);
|
||||||
|
|
||||||
|
result &= temp;
|
||||||
|
if (!temp)
|
||||||
|
cout << "FAILED:";
|
||||||
|
else
|
||||||
|
cout << "passed:";
|
||||||
|
cout << " FixedSizeAllocator and Grow with word32" << endl;
|
||||||
|
}
|
||||||
|
catch(const Exception& /*ex*/)
|
||||||
|
{
|
||||||
|
temp = false;
|
||||||
|
}
|
||||||
|
catch(const std::exception& /*ex*/)
|
||||||
|
{
|
||||||
|
temp = false;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue