openh264/test/encoder/EncUT_MemoryAlloc.cpp

57 lines
2.2 KiB
C++
Raw Normal View History

2014-03-14 09:40:02 +01:00
#include "gtest/gtest.h"
#include "memory_align.h"
2014-03-10 09:28:05 +01:00
using namespace WelsEnc;
2014-03-10 09:28:05 +01:00
//Tests of WelsGetCacheLineSize Begin
2014-06-26 03:50:41 +02:00
TEST (MemoryAlignTest, GetCacheLineSize_LoopWithin16K) {
2014-03-10 09:28:05 +01:00
const unsigned int kuiTestBoundary16K = 16 * 1024;
2014-06-26 03:50:41 +02:00
unsigned int uiTargetAlign = 1;
while (uiTargetAlign < kuiTestBoundary16K) {
CMemoryAlign cTestMa (uiTargetAlign);
ASSERT_EQ ((uiTargetAlign & 0x0F) ? 16 : uiTargetAlign, cTestMa.WelsGetCacheLineSize());
++ uiTargetAlign;
}
2014-03-10 09:28:05 +01:00
}
2014-06-26 03:50:41 +02:00
TEST (MemoryAlignTest, GetCacheLineSize_Zero) {
CMemoryAlign cTestMa (0);
2014-05-22 10:03:41 +02:00
const uint32_t kuiSixteen = 16;
2014-06-26 03:50:41 +02:00
ASSERT_EQ (kuiSixteen, cTestMa.WelsGetCacheLineSize());
2014-03-10 09:28:05 +01:00
}
2014-06-26 03:50:41 +02:00
TEST (MemoryAlignTest, GetCacheLineSize_MaxUINT) {
CMemoryAlign cTestMa (0xFFFFFFFF);
const uint32_t kuiSixteen = 16;
ASSERT_EQ (kuiSixteen, cTestMa.WelsGetCacheLineSize());
2014-03-10 09:28:05 +01:00
}
//Tests of WelsGetCacheLineSize End
//Tests of WelsMallocAndFree Begin
2014-06-26 03:50:41 +02:00
TEST (MemoryAlignTest, WelsMallocAndFreeOnceFunctionVerify) {
2014-03-10 09:28:05 +01:00
const uint32_t kuiTargetAlignSize[4] = {32, 16, 64, 8};
2014-05-22 10:03:41 +02:00
const uint32_t kuiZero = 0;
2014-06-26 03:50:41 +02:00
for (int i = 0; i < 4; i++) {
2014-03-10 09:28:05 +01:00
const uint32_t kuiTestAlignSize = kuiTargetAlignSize[i];
2014-06-26 03:50:41 +02:00
const uint32_t kuiTestDataSize = abs (rand());
2014-03-10 09:28:05 +01:00
2014-06-26 03:50:41 +02:00
CMemoryAlign cTestMa (kuiTestAlignSize);
2014-03-10 09:28:05 +01:00
const uint32_t uiSize = kuiTestDataSize;
const char strUnitTestTag[100] = "pUnitTestData";
2014-06-26 03:50:41 +02:00
const uint32_t kuiUsedCacheLineSize = ((kuiTestAlignSize == 0)
|| (kuiTestAlignSize & 0x0F)) ? (16) : (kuiTestAlignSize);
const uint32_t kuiExtraAlignSize = kuiUsedCacheLineSize - 1;
const uint32_t kuiExpectedSize = sizeof (void**) + sizeof (int32_t) + kuiExtraAlignSize + uiSize;
uint8_t* pUnitTestData = static_cast<uint8_t*> (cTestMa.WelsMalloc (uiSize, strUnitTestTag));
if (pUnitTestData != NULL) {
ASSERT_TRUE ((((uintptr_t) (pUnitTestData)) & kuiExtraAlignSize) == 0);
EXPECT_EQ (kuiExpectedSize, cTestMa.WelsGetMemoryUsage());
cTestMa.WelsFree (pUnitTestData, strUnitTestTag);
EXPECT_EQ (kuiZero, cTestMa.WelsGetMemoryUsage());
} else {
EXPECT_EQ (NULL, pUnitTestData);
EXPECT_EQ (kuiZero, cTestMa.WelsGetMemoryUsage());
cTestMa.WelsFree (pUnitTestData, strUnitTestTag);
EXPECT_EQ (kuiZero, cTestMa.WelsGetMemoryUsage());
2014-03-10 09:28:05 +01:00
}
}
}