4f594deff9
This makes sure we don't accidentally return the same sequence of random numbers multiple times within one test (which would be very non-random). Every time srand(time()) is called, the pseudo random number generator is initialized to the same value (as long as time() returned the same value). By initializing the random number generator once and for all before starting to run the unit tests, we are sure we don't need to reinitialize it within all the tests and all the functions that use random numbers. This fixes occasional errors in MotionEstimateTest. MotionEstimateTest was designed to allow the test to occasionally not succeed - if it didn't succeed, it tried again, up to 100 times. However, since the YUVPixelDataGenerator function reset the random seed to time(), every attempt actually ran with the same random data (as long as all 100 attempts ran within 1 second) - thus if one attempt in MotionEstimateTest failed, all 100 of them would fail. If the utility functions don't touch the random seed, this is not an issue.
83 lines
2.4 KiB
C++
83 lines
2.4 KiB
C++
#include <gtest/gtest.h>
|
|
#include <math.h>
|
|
#include <string.h>
|
|
#include "cpu.h"
|
|
#include "cpu_core.h"
|
|
#include "IWelsVP.h"
|
|
#include "ScrollDetection.h"
|
|
#include "ScrollDetectionFuncs.h"
|
|
#include "utils/DataGenerator.h"
|
|
|
|
using namespace nsWelsVP;
|
|
|
|
#define ASSERT_MEMORY_FAIL2X(A, B) \
|
|
if (NULL == B) { \
|
|
delete []A;\
|
|
ASSERT_TRUE(0); \
|
|
}
|
|
|
|
TEST (ScrollDetectionTest, TestScroll) {
|
|
unsigned char* pSrc, *pRef;
|
|
int iWidthSets[4] = {640, 1024, 1280, 1980};
|
|
int iHeightSets[4] = {360, 768, 720, 1080};
|
|
int iStride = 0;
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
int iWidth = iWidthSets[i];
|
|
int iHeight = iHeightSets[i];
|
|
iStride = iWidth + 16;
|
|
pSrc = new unsigned char[iHeight * iStride];
|
|
ASSERT_TRUE (NULL != pSrc);
|
|
pRef = new unsigned char[iHeight * iStride];
|
|
ASSERT_MEMORY_FAIL2X (pSrc, pRef)
|
|
RandomPixelDataGenerator (pRef, iWidth, iHeight, iStride);
|
|
|
|
int iMvRange = iHeight / 3;
|
|
int iScrollMv = rand() % (iMvRange << 1) - iMvRange;
|
|
unsigned char* pSrcTmp = pSrc;
|
|
unsigned char* pRefTmp = pRef;
|
|
|
|
for (int j = 0; j < iHeight; j++) {
|
|
if ((j + iScrollMv) >= 0 && (j + iScrollMv) < iHeight)
|
|
for (int i = 0; i < iWidth; i++) {
|
|
memcpy (pSrcTmp , &pRefTmp[ (j + iScrollMv)*iStride], iWidth * sizeof (unsigned char));
|
|
}
|
|
else {
|
|
for (int i = 0; i < iWidth; i++)
|
|
pSrcTmp[i] = rand() % 256;
|
|
}
|
|
pSrcTmp += iStride;
|
|
}
|
|
|
|
|
|
SPixMap sSrcMap = { { 0 } };
|
|
SPixMap sRefMap = { { 0 } };
|
|
|
|
sSrcMap.pPixel[0] = pSrc;
|
|
sRefMap.pPixel[0] = pRef;
|
|
sSrcMap.iStride[0] = sRefMap.iStride[0] = iStride;
|
|
sSrcMap.sRect.iRectWidth = sRefMap.sRect.iRectWidth = iWidth;
|
|
sSrcMap.sRect.iRectHeight = sRefMap.sRect.iRectHeight = iHeight;
|
|
|
|
SScrollDetectionParam sScrollDetectionResult;
|
|
WelsMemset (&sScrollDetectionResult, 0, sizeof (sScrollDetectionResult));
|
|
int iCoreNum = 1;
|
|
unsigned int uiCPUFlag = WelsCPUFeatureDetect (&iCoreNum);
|
|
|
|
CScrollDetection* pTest = new CScrollDetection (uiCPUFlag);
|
|
int iMethodIdx = METHOD_SCROLL_DETECTION;
|
|
|
|
pTest->Set (iMethodIdx, (&sScrollDetectionResult));
|
|
int ret = pTest->Process (iMethodIdx, &sSrcMap, &sRefMap);
|
|
EXPECT_EQ (ret, 0);
|
|
pTest->Get (iMethodIdx, (&sScrollDetectionResult));
|
|
|
|
EXPECT_EQ (sScrollDetectionResult.bScrollDetectFlag, true);
|
|
EXPECT_EQ (sScrollDetectionResult.iScrollMvY, iScrollMv);
|
|
|
|
delete pTest;
|
|
delete []pSrc;
|
|
delete []pRef;
|
|
}
|
|
}
|