Make test encoder test driver less likely to leak on failure.
authorAlex Converse <aconverse@google.com>
Thu, 21 Jul 2016 18:36:41 +0000 (11:36 -0700)
committerAlex Converse <aconverse@google.com>
Thu, 21 Jul 2016 18:39:47 +0000 (11:39 -0700)
Individual tests still need to be updated.

Change-Id: Ic433d0f742e13560b136f136b72b2a9973970d78

test/encode_test_driver.cc

index b8c7371..e189d8f 100644 (file)
@@ -180,11 +180,11 @@ void EncoderTest::RunLoop(VideoSource *video) {
       cfg_.g_pass = VPX_RC_LAST_PASS;
 
     BeginPassHook(pass);
-    Encoder* const encoder = codec_->CreateEncoder(cfg_, deadline_, init_flags_,
-                                                   &stats_);
-    ASSERT_TRUE(encoder != NULL);
+    testing::internal::scoped_ptr<Encoder> encoder(
+        codec_->CreateEncoder(cfg_, deadline_, init_flags_, &stats_));
+    ASSERT_TRUE(encoder.get() != NULL);
 
-    video->Begin();
+    ASSERT_NO_FATAL_FAILURE(video->Begin());
     encoder->InitEncoder(video);
     ASSERT_FALSE(::testing::Test::HasFatalFailure());
 
@@ -193,13 +193,14 @@ void EncoderTest::RunLoop(VideoSource *video) {
     // NOTE: fragment decoder and partition encoder are only supported by VP8.
     if (init_flags_ & VPX_CODEC_USE_OUTPUT_PARTITION)
       dec_init_flags |= VPX_CODEC_USE_INPUT_FRAGMENTS;
-    Decoder* const decoder = codec_->CreateDecoder(dec_cfg, dec_init_flags, 0);
+    testing::internal::scoped_ptr<Decoder> decoder(
+        codec_->CreateDecoder(dec_cfg, dec_init_flags, 0));
     bool again;
     for (again = true; again; video->Next()) {
       again = (video->img() != NULL);
 
       PreEncodeFrameHook(video);
-      PreEncodeFrameHook(video, encoder);
+      PreEncodeFrameHook(video, encoder.get());
       encoder->EncodeFrame(video, frame_flags_);
 
       CxDataIterator iter = encoder->GetCxData();
@@ -212,11 +213,11 @@ void EncoderTest::RunLoop(VideoSource *video) {
         switch (pkt->kind) {
           case VPX_CODEC_CX_FRAME_PKT:
             has_cxdata = true;
-            if (decoder && DoDecode()) {
+            if (decoder.get() != NULL && DoDecode()) {
               vpx_codec_err_t res_dec = decoder->DecodeFrame(
                   (const uint8_t*)pkt->data.frame.buf, pkt->data.frame.sz);
 
-              if (!HandleDecodeResult(res_dec, *video, decoder))
+              if (!HandleDecodeResult(res_dec, *video, decoder.get()))
                 break;
 
               has_dxdata = true;
@@ -238,7 +239,7 @@ void EncoderTest::RunLoop(VideoSource *video) {
       // Flush the decoder when there are no more fragments.
       if ((init_flags_ & VPX_CODEC_USE_OUTPUT_PARTITION) && has_dxdata) {
         const vpx_codec_err_t res_dec = decoder->DecodeFrame(NULL, 0);
-        if (!HandleDecodeResult(res_dec, *video, decoder))
+        if (!HandleDecodeResult(res_dec, *video, decoder.get()))
           break;
       }
 
@@ -261,10 +262,6 @@ void EncoderTest::RunLoop(VideoSource *video) {
 
     EndPassHook();
 
-    if (decoder)
-      delete decoder;
-    delete encoder;
-
     if (!Continue())
       break;
   }