]> granicus.if.org Git - libvpx/blobdiff - test/user_priv_test.cc
Merge "build/make/configure.sh: Fix armv7 builds in Xcode7."
[libvpx] / test / user_priv_test.cc
index 38eef1c926da10a5150607984407957dab918e18..8512d88cf43d3de988d9854f35dc318585893054 100644 (file)
@@ -13,6 +13,7 @@
 #include <string>
 #include "third_party/googletest/src/include/gtest/gtest.h"
 #include "./vpx_config.h"
+#include "test/acm_random.h"
 #include "test/codec_factory.h"
 #include "test/decode_test_driver.h"
 #include "test/ivf_video_source.h"
 #include "test/webm_video_source.h"
 #endif
 #include "vpx_mem/vpx_mem.h"
+#include "vpx/vp8.h"
 
 namespace {
 
 using std::string;
+using libvpx_test::ACMRandom;
 
 #if CONFIG_WEBM_IO
+
+void CheckUserPrivateData(void *user_priv, int *target) {
+  // actual pointer value should be the same as expected.
+  EXPECT_EQ(reinterpret_cast<void *>(target), user_priv) <<
+      "user_priv pointer value does not match.";
+}
+
 // Decodes |filename|. Passes in user_priv data when calling DecodeFrame and
 // compares the user_priv from return img with the original user_priv to see if
 // they match. Both the pointer values and the values inside the addresses
 // should match.
 string DecodeFile(const string &filename) {
+  ACMRandom rnd(ACMRandom::DeterministicSeed());
   libvpx_test::WebMVideoSource video(filename);
   video.Init();
 
-  vpx_codec_dec_cfg_t cfg = {0};
+  vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
   libvpx_test::VP9Decoder decoder(cfg, 0);
 
   libvpx_test::MD5 md5;
   int frame_num = 0;
-  for (video.Begin(); video.cxdata(); video.Next()) {
+  for (video.Begin(); !::testing::Test::HasFailure() && video.cxdata();
+       video.Next()) {
     void *user_priv = reinterpret_cast<void *>(&frame_num);
     const vpx_codec_err_t res =
         decoder.DecodeFrame(video.cxdata(), video.frame_size(),
@@ -56,16 +68,17 @@ string DecodeFile(const string &filename) {
     // Get decompressed data.
     while ((img = dec_iter.Next())) {
       if (frame_num == 0) {
-        // user_priv pointer value should be the same.
-        EXPECT_EQ(img->user_priv, reinterpret_cast<void *>(NULL)) <<
-            "user_priv pointer value does not match.";
+        CheckUserPrivateData(img->user_priv, NULL);
       } else {
-        // user_priv pointer value should be the same.
-        EXPECT_EQ(img->user_priv, reinterpret_cast<void *>(&frame_num)) <<
-            "user_priv pointer value does not match.";
-        // value in user_priv pointer should also be the same.
-        EXPECT_EQ(*reinterpret_cast<int *>(img->user_priv), frame_num) <<
-            "Value in user_priv does not match.";
+        CheckUserPrivateData(img->user_priv, &frame_num);
+
+        // Also test ctrl_get_reference api.
+        struct vp9_ref_frame ref;
+        // Randomly fetch a reference frame.
+        ref.idx = rnd.Rand8() % 3;
+        decoder.Control(VP9_GET_REFERENCE, &ref);
+
+        CheckUserPrivateData(ref.img.user_priv, NULL);
       }
       md5.Add(img);
     }