Merge pull request #1250 from huili2/test_EndOfStream

test end of stream for decoder API UT
This commit is contained in:
dongzha 2014-08-11 10:34:07 +08:00
commit f8e5d3a7bf

View File

@ -8,7 +8,9 @@
#include "ls_defines.h" #include "ls_defines.h"
using namespace WelsDec; using namespace WelsDec;
#define BUF_SIZE 100
//payload size exclude 6 bytes: 0001, nal type and final '\0'
#define PAYLOAD_SIZE (BUF_SIZE - 6)
class DecoderInterfaceTest : public ::testing::Test { class DecoderInterfaceTest : public ::testing::Test {
public: public:
virtual void SetUp() { virtual void SetUp() {
@ -27,7 +29,7 @@ class DecoderInterfaceTest : public ::testing::Test {
//Uninit members //Uninit members
void Uninit(); void Uninit();
//Mock input data for test //Mock input data for test
void MockPacketType (const EWelsNalUnitType eNalUnitType); void MockPacketType (const EWelsNalUnitType eNalUnitType, const int iPacketLength);
//Test Initialize/Uninitialize //Test Initialize/Uninitialize
void TestInitUninit(); void TestInitUninit();
//DECODER_OPTION_DATAFORMAT //DECODER_OPTION_DATAFORMAT
@ -63,7 +65,7 @@ class DecoderInterfaceTest : public ::testing::Test {
SDecodingParam m_sDecParam; SDecodingParam m_sDecParam;
SBufferInfo m_sBufferInfo; SBufferInfo m_sBufferInfo;
uint8_t* m_pData[3]; uint8_t* m_pData[3];
char m_szBuffer[100]; //for mocking packet unsigned char m_szBuffer[BUF_SIZE]; //for mocking packet
int m_iBufLength; //record the valid data in m_szBuffer int m_iBufLength; //record the valid data in m_szBuffer
}; };
@ -99,35 +101,40 @@ void DecoderInterfaceTest::Uninit() {
} }
//Mock input data for test //Mock input data for test
void DecoderInterfaceTest::MockPacketType (const EWelsNalUnitType eNalUnitType) { void DecoderInterfaceTest::MockPacketType (const EWelsNalUnitType eNalUnitType, const int iPacketLength) {
switch (eNalUnitType) { switch (eNalUnitType) {
case NAL_UNIT_SEI: case NAL_UNIT_SEI:
//TODO m_szBuffer[m_iBufLength++] = 6;
break; break;
case NAL_UNIT_SPS: case NAL_UNIT_SPS:
//TODO m_szBuffer[m_iBufLength++] = 67;
break; break;
case NAL_UNIT_PPS: case NAL_UNIT_PPS:
//TODO m_szBuffer[m_iBufLength++] = 68;
break; break;
case NAL_UNIT_SUBSET_SPS: case NAL_UNIT_SUBSET_SPS:
//TODO m_szBuffer[m_iBufLength++] = 15;
break; break;
case NAL_UNIT_PREFIX: case NAL_UNIT_PREFIX:
//TODO m_szBuffer[m_iBufLength++] = 14;
break; break;
case NAL_UNIT_CODED_SLICE: case NAL_UNIT_CODED_SLICE:
//TODO m_szBuffer[m_iBufLength++] = 61;
break; break;
case NAL_UNIT_CODED_SLICE_IDR: case NAL_UNIT_CODED_SLICE_IDR:
//TODO m_szBuffer[m_iBufLength++] = 65;
break; break;
default: default:
//TODO m_szBuffer[m_iBufLength++] = 0; //NAL_UNIT_UNSPEC_0
break; break;
m_szBuffer[m_iBufLength] = '\0'; int iAddLength = iPacketLength - 5; //excluding 0001 and type
m_iBufLength++; //including '\0' if (iAddLength > PAYLOAD_SIZE)
iAddLength = PAYLOAD_SIZE;
for (int i = 0; i < iAddLength; ++i) {
m_szBuffer[m_iBufLength++] = rand() % 256;
}
m_szBuffer[m_iBufLength++] = '\0';
} }
} }
@ -176,8 +183,60 @@ void DecoderInterfaceTest::TestDataFormat() {
//DECODER_OPTION_END_OF_STREAM //DECODER_OPTION_END_OF_STREAM
void DecoderInterfaceTest::TestEndOfStream() { void DecoderInterfaceTest::TestEndOfStream() {
//TODO int iTmp, iOut;
CM_RETURN eRet;
//invalid input
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, NULL);
EXPECT_EQ (eRet, cmInitParaError);
//valid random input
for (int i = 0; i < 10; ++i) {
iTmp = rand();
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
EXPECT_EQ (eRet, cmResultSuccess);
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
EXPECT_EQ (eRet, cmResultSuccess);
EXPECT_EQ (iOut, iTmp != 0);
}
//set false as input
iTmp = false;
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
EXPECT_EQ (eRet, cmResultSuccess);
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
EXPECT_EQ (eRet, cmResultSuccess);
EXPECT_EQ (iOut, false);
//set true as input
iTmp = true;
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
EXPECT_EQ (eRet, cmResultSuccess);
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
EXPECT_EQ (eRet, cmResultSuccess);
EXPECT_EQ (iOut, true);
//Mock data packet in
//Test NULL data input for decoder, should be true for EOS
eRet = (CM_RETURN) m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
EXPECT_EQ (eRet, 0); //decode should return OK
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
EXPECT_EQ (iOut, true); //decoder should have EOS == true
//Test valid data input for decoder, should be false for EOS
MockPacketType (NAL_UNIT_UNSPEC_0, 50);
eRet = (CM_RETURN) m_pDec->DecodeFrame2 (m_szBuffer, m_iBufLength, m_pData, &m_sBufferInfo);
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
EXPECT_EQ (iOut, false); //decoder should have EOS == false
//Test NULL data input for decoder, should be true for EOS
eRet = (CM_RETURN) m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
EXPECT_EQ (iOut, true); //decoder should have EOS == true
} }
//DECODER_OPTION_VCL_NAL //DECODER_OPTION_VCL_NAL
void DecoderInterfaceTest::TestVclNal() { void DecoderInterfaceTest::TestVclNal() {
//TODO //TODO