History

modify UT low memory cases

huili2 committed 9 years ago

Commit f7239b61 parent 2081df82 files · +68 −37Browse files

Showing the changes to test/decoder/DecUT_ParseSyntax.cpp (1 of 2 files). Show all

Unified · Split

test/decoder/DecUT_ParseSyntax.cpp+47−16
@@ -132,9 +132,9 @@ class DecoderParseSyntaxTest : public ::testing::Test { · 131 unmodified lines
132132 //Uninit members
133133 void Uninit();
134134 //Decoder real bitstream
135− void DecodeBs (const char* sFileName);
135+ bool DecodeBs (const char* sFileName);
136136 //Parse real bitstream
137− void ParseBs (const char* sFileName);
137+ bool ParseBs (const char* sFileName);
138138 //Scalinglist
139139 void TestScalingList();
140140 //specific bitstream test
@@ -175,11 +175,16 @@ int32_t DecoderParseSyntaxTest::Init() { · 34 unmodified lines
175175 m_iBufLength = 4;
176176 //
177177 m_pCtx = (PWelsDecoderContext)malloc (sizeof (SWelsDecoderContext));
178−
178+ if (m_pCtx == NULL)
179+ return ERR_MALLOC_FAILED;
179180 memset (m_pCtx, 0, sizeof (SWelsDecoderContext));
180181 m_pWelsTrace = new welsCodecTrace();
181182 if (m_pWelsTrace != NULL) {
182183 m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
184+ } else {
185+ free (m_pCtx);
186+ m_pCtx = NULL;
187+ return ERR_MALLOC_FAILED;
183188 }
184189 CM_RETURN eRet = (CM_RETURN)Initialize (&m_sDecParam, m_pCtx, &m_pWelsTrace->m_sLogCtx);
185190 return (int32_t)eRet;
@@ -199,7 +204,7 @@ void DecoderParseSyntaxTest::Uninit() { · 13 unmodified lines
199204 m_iBufLength = 0;
200205 }
201206
202−void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) {
207+bool DecoderParseSyntaxTest::DecodeBs (const char* sFileName) {
203208
204209 uint8_t* pBuf = NULL;
205210 int32_t iBufPos = 0;
@@ -213,15 +218,28 @@ void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { · 7 unmodified lines
213218
214219 #if defined(ANDROID_NDK)
215220 std::string filename = std::string ("/sdcard/") + sFileName;
216− ASSERT_TRUE ((pH264File = fopen (filename.c_str(), "rb")) != NULL);
221+ if ((pH264File = fopen (filename.c_str(), "rb")) == NULL)
222+ return false;
217223 #else
218− ASSERT_TRUE ((pH264File = fopen (sFileName, "rb")) != NULL);
224+ if ((pH264File = fopen (sFileName, "rb")) == NULL)
225+ return false;
219226 #endif
220227 fseek (pH264File, 0L, SEEK_END);
221228 iFileSize = (int32_t) ftell (pH264File);
222229 fseek (pH264File, 0L, SEEK_SET);
223230 pBuf = new uint8_t[iFileSize + 4];
224− ASSERT_EQ (fread (pBuf, 1, iFileSize, pH264File), (unsigned int) iFileSize);
231+ if (pBuf == NULL) {
232+ fclose (pH264File);
233+ return false;
234+ }
235+ if ((fread (pBuf, 1, iFileSize, pH264File) != (unsigned int) iFileSize)) {
236+ fclose (pH264File);
237+ if (pBuf) {
238+ delete[] pBuf;
239+ pBuf = NULL;
240+ }
241+ return false;
242+ }
225243 memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage
226244 while (true) {
227245 if (iBufPos >= iFileSize) {
@@ -250,9 +268,9 @@ void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { · 22 unmodified lines
250268 pBuf = NULL;
251269 }
252270
253−
271+ return true;
254272 }
255−void DecoderParseSyntaxTest::ParseBs (const char* sFileName) {
273+bool DecoderParseSyntaxTest::ParseBs (const char* sFileName) {
256274
257275 uint8_t* pBuf = NULL;
258276 int32_t iBufPos = 0;
@@ -267,15 +285,28 @@ void DecoderParseSyntaxTest::ParseBs (const char* sFileName) { · 8 unmodified lines
267285
268286 #if defined(ANDROID_NDK)
269287 std::string filename = std::string ("/sdcard/") + sFileName;
270− ASSERT_TRUE ((pH264File = fopen (filename.c_str(), "rb")) != NULL);
288+ if ((pH264File = fopen (filename.c_str(), "rb")) == NULL)
289+ return false;
271290 #else
272− ASSERT_TRUE ((pH264File = fopen (sFileName, "rb")) != NULL);
291+ if ((pH264File = fopen (sFileName, "rb")) == NULL)
292+ return false;
273293 #endif
274294 fseek (pH264File, 0L, SEEK_END);
275295 iFileSize = (int32_t)ftell (pH264File);
276296 fseek (pH264File, 0L, SEEK_SET);
277297 pBuf = new uint8_t[iFileSize + 4];
278− ASSERT_EQ (fread (pBuf, 1, iFileSize, pH264File), (unsigned int)iFileSize);
298+ if (pBuf == NULL) {
299+ fclose (pH264File);
300+ return false;
301+ }
302+ if (fread (pBuf, 1, iFileSize, pH264File) != (unsigned int)iFileSize) {
303+ fclose (pH264File);
304+ if (pBuf) {
305+ delete[] pBuf;
306+ pBuf = NULL;
307+ }
308+ return false;
309+ }
279310 memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage
280311 while (true) {
281312 if (iBufPos >= iFileSize) {
@@ -308,7 +339,7 @@ void DecoderParseSyntaxTest::ParseBs (const char* sFileName) { · 26 unmodified lines
308339 pBuf = NULL;
309340 }
310341
311−
342+ return true;
312343 }
313344
314345
@@ -335,7 +366,7 @@ void DecoderParseSyntaxTest::TestScalingList() { · 20 unmodified lines
335366 int32_t iRet = ERR_NONE;
336367 iRet = Init();
337368 ASSERT_EQ (iRet, ERR_NONE);
338− DecodeBs ("res/BA_MW_D.264");
369+ ASSERT_TRUE (DecodeBs ("res/BA_MW_D.264"));
339370 ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag == false);
340371 EXPECT_EQ (0, memcmp (iScalingListZero, m_pCtx->sSpsBuffer[0].iScalingList4x4, 6 * 16 * sizeof (uint8_t)));
341372 ASSERT_TRUE (m_pCtx->sPpsBuffer[0].bPicScalingMatrixPresentFlag == false);
@@ -344,7 +375,7 @@ void DecoderParseSyntaxTest::TestScalingList() { · 2 unmodified lines
344375 //Scalinglist value just written into sps and pps
345376 iRet = Init();
346377 ASSERT_EQ (iRet, ERR_NONE);
347− DecodeBs ("res/test_scalinglist_jm.264");
378+ ASSERT_TRUE (DecodeBs ("res/test_scalinglist_jm.264"));
348379 ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag);
349380 for (int i = 0; i < 6; i++) {
350381 EXPECT_EQ (0, memcmp (iScalingList[i], m_pCtx->sSpsBuffer[0].iScalingList4x4[i], 16 * sizeof (uint8_t)));
@@ -364,7 +395,7 @@ void DecoderParseSyntaxTest::TestSpecificBs() { · 13 unmodified lines
364395 m_sDecParam.eEcActiveIdc = ERROR_CON_DISABLE;
365396 iRet = m_pDec->Initialize (&m_sDecParam);
366397 ASSERT_EQ (iRet, ERR_NONE);
367− ParseBs ("res/jm_1080p_allslice.264");
398+ ASSERT_TRUE (ParseBs ("res/jm_1080p_allslice.264"));
368399 m_pDec->Uninitialize();
369400 //Uninit();
370401 }

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