Showing the changes to test/decoder/DecUT_ParseSyntax.cpp (1 of 2 files). Show all
Unified · Split
| @@ -132,9 +132,9 @@ class DecoderParseSyntaxTest : public ::testing::Test { · 131 unmodified lines | ||
| 132 | 132 | //Uninit members |
| 133 | 133 | void Uninit(); |
| 134 | 134 | //Decoder real bitstream |
| 135 | − void DecodeBs (const char* sFileName); | |
| 135 | + bool DecodeBs (const char* sFileName); | |
| 136 | 136 | //Parse real bitstream |
| 137 | − void ParseBs (const char* sFileName); | |
| 137 | + bool ParseBs (const char* sFileName); | |
| 138 | 138 | //Scalinglist |
| 139 | 139 | void TestScalingList(); |
| 140 | 140 | //specific bitstream test |
| @@ -175,11 +175,16 @@ int32_t DecoderParseSyntaxTest::Init() { · 34 unmodified lines | ||
| 175 | 175 | m_iBufLength = 4; |
| 176 | 176 | // |
| 177 | 177 | m_pCtx = (PWelsDecoderContext)malloc (sizeof (SWelsDecoderContext)); |
| 178 | − | |
| 178 | + if (m_pCtx == NULL) | |
| 179 | + return ERR_MALLOC_FAILED; | |
| 179 | 180 | memset (m_pCtx, 0, sizeof (SWelsDecoderContext)); |
| 180 | 181 | m_pWelsTrace = new welsCodecTrace(); |
| 181 | 182 | if (m_pWelsTrace != NULL) { |
| 182 | 183 | m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR); |
| 184 | + } else { | |
| 185 | + free (m_pCtx); | |
| 186 | + m_pCtx = NULL; | |
| 187 | + return ERR_MALLOC_FAILED; | |
| 183 | 188 | } |
| 184 | 189 | CM_RETURN eRet = (CM_RETURN)Initialize (&m_sDecParam, m_pCtx, &m_pWelsTrace->m_sLogCtx); |
| 185 | 190 | return (int32_t)eRet; |
| @@ -199,7 +204,7 @@ void DecoderParseSyntaxTest::Uninit() { · 13 unmodified lines | ||
| 199 | 204 | m_iBufLength = 0; |
| 200 | 205 | } |
| 201 | 206 | |
| 202 | −void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { | |
| 207 | +bool DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { | |
| 203 | 208 | |
| 204 | 209 | uint8_t* pBuf = NULL; |
| 205 | 210 | int32_t iBufPos = 0; |
| @@ -213,15 +218,28 @@ void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { · 7 unmodified lines | ||
| 213 | 218 | |
| 214 | 219 | #if defined(ANDROID_NDK) |
| 215 | 220 | 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; | |
| 217 | 223 | #else |
| 218 | − ASSERT_TRUE ((pH264File = fopen (sFileName, "rb")) != NULL); | |
| 224 | + if ((pH264File = fopen (sFileName, "rb")) == NULL) | |
| 225 | + return false; | |
| 219 | 226 | #endif |
| 220 | 227 | fseek (pH264File, 0L, SEEK_END); |
| 221 | 228 | iFileSize = (int32_t) ftell (pH264File); |
| 222 | 229 | fseek (pH264File, 0L, SEEK_SET); |
| 223 | 230 | 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 | + } | |
| 225 | 243 | memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage |
| 226 | 244 | while (true) { |
| 227 | 245 | if (iBufPos >= iFileSize) { |
| @@ -250,9 +268,9 @@ void DecoderParseSyntaxTest::DecodeBs (const char* sFileName) { · 22 unmodified lines | ||
| 250 | 268 | pBuf = NULL; |
| 251 | 269 | } |
| 252 | 270 | |
| 253 | − | |
| 271 | + return true; | |
| 254 | 272 | } |
| 255 | −void DecoderParseSyntaxTest::ParseBs (const char* sFileName) { | |
| 273 | +bool DecoderParseSyntaxTest::ParseBs (const char* sFileName) { | |
| 256 | 274 | |
| 257 | 275 | uint8_t* pBuf = NULL; |
| 258 | 276 | int32_t iBufPos = 0; |
| @@ -267,15 +285,28 @@ void DecoderParseSyntaxTest::ParseBs (const char* sFileName) { · 8 unmodified lines | ||
| 267 | 285 | |
| 268 | 286 | #if defined(ANDROID_NDK) |
| 269 | 287 | 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; | |
| 271 | 290 | #else |
| 272 | − ASSERT_TRUE ((pH264File = fopen (sFileName, "rb")) != NULL); | |
| 291 | + if ((pH264File = fopen (sFileName, "rb")) == NULL) | |
| 292 | + return false; | |
| 273 | 293 | #endif |
| 274 | 294 | fseek (pH264File, 0L, SEEK_END); |
| 275 | 295 | iFileSize = (int32_t)ftell (pH264File); |
| 276 | 296 | fseek (pH264File, 0L, SEEK_SET); |
| 277 | 297 | 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 | + } | |
| 279 | 310 | memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage |
| 280 | 311 | while (true) { |
| 281 | 312 | if (iBufPos >= iFileSize) { |
| @@ -308,7 +339,7 @@ void DecoderParseSyntaxTest::ParseBs (const char* sFileName) { · 26 unmodified lines | ||
| 308 | 339 | pBuf = NULL; |
| 309 | 340 | } |
| 310 | 341 | |
| 311 | − | |
| 342 | + return true; | |
| 312 | 343 | } |
| 313 | 344 | |
| 314 | 345 | |
| @@ -335,7 +366,7 @@ void DecoderParseSyntaxTest::TestScalingList() { · 20 unmodified lines | ||
| 335 | 366 | int32_t iRet = ERR_NONE; |
| 336 | 367 | iRet = Init(); |
| 337 | 368 | ASSERT_EQ (iRet, ERR_NONE); |
| 338 | − DecodeBs ("res/BA_MW_D.264"); | |
| 369 | + ASSERT_TRUE (DecodeBs ("res/BA_MW_D.264")); | |
| 339 | 370 | ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag == false); |
| 340 | 371 | EXPECT_EQ (0, memcmp (iScalingListZero, m_pCtx->sSpsBuffer[0].iScalingList4x4, 6 * 16 * sizeof (uint8_t))); |
| 341 | 372 | ASSERT_TRUE (m_pCtx->sPpsBuffer[0].bPicScalingMatrixPresentFlag == false); |
| @@ -344,7 +375,7 @@ void DecoderParseSyntaxTest::TestScalingList() { · 2 unmodified lines | ||
| 344 | 375 | //Scalinglist value just written into sps and pps |
| 345 | 376 | iRet = Init(); |
| 346 | 377 | ASSERT_EQ (iRet, ERR_NONE); |
| 347 | − DecodeBs ("res/test_scalinglist_jm.264"); | |
| 378 | + ASSERT_TRUE (DecodeBs ("res/test_scalinglist_jm.264")); | |
| 348 | 379 | ASSERT_TRUE (m_pCtx->sSpsBuffer[0].bSeqScalingMatrixPresentFlag); |
| 349 | 380 | for (int i = 0; i < 6; i++) { |
| 350 | 381 | 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 | ||
| 364 | 395 | m_sDecParam.eEcActiveIdc = ERROR_CON_DISABLE; |
| 365 | 396 | iRet = m_pDec->Initialize (&m_sDecParam); |
| 366 | 397 | ASSERT_EQ (iRet, ERR_NONE); |
| 367 | − ParseBs ("res/jm_1080p_allslice.264"); | |
| 398 | + ASSERT_TRUE (ParseBs ("res/jm_1080p_allslice.264")); | |
| 368 | 399 | m_pDec->Uninitialize(); |
| 369 | 400 | //Uninit(); |
| 370 | 401 | } |