History

test end of stream for decoder API UT

huili2 committed 12 years ago

Commit ed12e6a1 parent 11bf5751 file · +74 −15Browse files

Showing the changes to test/decoder/DecUT_DecExt.cpp (1 of 1 file). Show all

Unified · Split

test/decoder/DecUT_DecExt.cpp+74−15
@@ -8,7 +8,9 @@ · 7 unmodified lines
88 #include "ls_defines.h"
99
1010 using namespace WelsDec;
11−
11+#define BUF_SIZE 100
12+//payload size exclude 6 bytes: 0001, nal type and final '\0'
13+#define PAYLOAD_SIZE (BUF_SIZE - 6)
1214 class DecoderInterfaceTest : public ::testing::Test {
1315 public:
1416 virtual void SetUp() {
@@ -27,7 +29,7 @@ class DecoderInterfaceTest : public ::testing::Test { · 12 unmodified lines
2729 //Uninit members
2830 void Uninit();
2931 //Mock input data for test
30− void MockPacketType (const EWelsNalUnitType eNalUnitType);
32+ void MockPacketType (const EWelsNalUnitType eNalUnitType, const int iPacketLength);
3133 //Test Initialize/Uninitialize
3234 void TestInitUninit();
3335 //DECODER_OPTION_DATAFORMAT
@@ -63,7 +65,7 @@ class DecoderInterfaceTest : public ::testing::Test { · 29 unmodified lines
6365 SDecodingParam m_sDecParam;
6466 SBufferInfo m_sBufferInfo;
6567 uint8_t* m_pData[3];
66− char m_szBuffer[100]; //for mocking packet
68+ unsigned char m_szBuffer[BUF_SIZE]; //for mocking packet
6769 int m_iBufLength; //record the valid data in m_szBuffer
6870 };
6971
@@ -99,35 +101,40 @@ void DecoderInterfaceTest::Uninit() { · 29 unmodified lines
99101 }
100102
101103 //Mock input data for test
102−void DecoderInterfaceTest::MockPacketType (const EWelsNalUnitType eNalUnitType) {
104+void DecoderInterfaceTest::MockPacketType (const EWelsNalUnitType eNalUnitType, const int iPacketLength) {
103105 switch (eNalUnitType) {
104106 case NAL_UNIT_SEI:
105− //TODO
107+ m_szBuffer[m_iBufLength++] = 6;
106108 break;
107109 case NAL_UNIT_SPS:
108− //TODO
110+ m_szBuffer[m_iBufLength++] = 67;
109111 break;
110112 case NAL_UNIT_PPS:
111− //TODO
113+ m_szBuffer[m_iBufLength++] = 68;
112114 break;
113115 case NAL_UNIT_SUBSET_SPS:
114− //TODO
116+ m_szBuffer[m_iBufLength++] = 15;
115117 break;
116118 case NAL_UNIT_PREFIX:
117− //TODO
119+ m_szBuffer[m_iBufLength++] = 14;
118120 break;
119121 case NAL_UNIT_CODED_SLICE:
120− //TODO
122+ m_szBuffer[m_iBufLength++] = 61;
121123 break;
122124 case NAL_UNIT_CODED_SLICE_IDR:
123− //TODO
125+ m_szBuffer[m_iBufLength++] = 65;
124126 break;
125127 default:
126− //TODO
128+ m_szBuffer[m_iBufLength++] = 0; //NAL_UNIT_UNSPEC_0
127129 break;
128130
129− m_szBuffer[m_iBufLength] = '\0';
130− m_iBufLength++; //including '\0'
131+ int iAddLength = iPacketLength - 5; //excluding 0001 and type
132+ if (iAddLength > PAYLOAD_SIZE)
133+ iAddLength = PAYLOAD_SIZE;
134+ for (int i = 0; i < iAddLength; ++i) {
135+ m_szBuffer[m_iBufLength++] = rand() % 256;
136+ }
137+ m_szBuffer[m_iBufLength++] = '\0';
131138
132139 }
133140 }
@@ -176,8 +183,60 @@ void DecoderInterfaceTest::TestDataFormat() { · 42 unmodified lines
176183
177184 //DECODER_OPTION_END_OF_STREAM
178185 void DecoderInterfaceTest::TestEndOfStream() {
179− //TODO
186+ int iTmp, iOut;
187+ CM_RETURN eRet;
188+
189+ //invalid input
190+ eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, NULL);
191+ EXPECT_EQ (eRet, cmInitParaError);
192+
193+ //valid random input
194+ for (int i = 0; i < 10; ++i) {
195+ iTmp = rand();
196+ eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
197+ EXPECT_EQ (eRet, cmResultSuccess);
198+ eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
199+ EXPECT_EQ (eRet, cmResultSuccess);
200+ EXPECT_EQ (iOut, iTmp != 0);
201+ }
202+
203+ //set false as input
204+ iTmp = false;
205+ eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
206+ EXPECT_EQ (eRet, cmResultSuccess);
207+ eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
208+ EXPECT_EQ (eRet, cmResultSuccess);
209+
210+ EXPECT_EQ (iOut, false);
211+
212+ //set true as input
213+ iTmp = true;
214+ eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, &iTmp);
215+ EXPECT_EQ (eRet, cmResultSuccess);
216+ eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
217+ EXPECT_EQ (eRet, cmResultSuccess);
218+
219+ EXPECT_EQ (iOut, true);
220+
221+ //Mock data packet in
222+ //Test NULL data input for decoder, should be true for EOS
223+ eRet = (CM_RETURN) m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
224+ EXPECT_EQ (eRet, 0); //decode should return OK
225+ eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
226+ EXPECT_EQ (iOut, true); //decoder should have EOS == true
227+
228+ //Test valid data input for decoder, should be false for EOS
229+ MockPacketType (NAL_UNIT_UNSPEC_0, 50);
230+ eRet = (CM_RETURN) m_pDec->DecodeFrame2 (m_szBuffer, m_iBufLength, m_pData, &m_sBufferInfo);
231+ eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
232+ EXPECT_EQ (iOut, false); //decoder should have EOS == false
233+ //Test NULL data input for decoder, should be true for EOS
234+ eRet = (CM_RETURN) m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
235+ eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
236+ EXPECT_EQ (iOut, true); //decoder should have EOS == true
180237 }
238+
239+
181240 //DECODER_OPTION_VCL_NAL
182241 void DecoderInterfaceTest::TestVclNal() {
183242 //TODO

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t