test_vector_test.cc 3.55 KB
Newer Older
1
/*
2 3 4 5 6 7 8
 *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
9 10 11 12 13 14
 */

#include <cstdio>
#include <cstdlib>
#include <string>
#include "third_party/googletest/src/include/gtest/gtest.h"
15
#include "./vpx_config.h"
16
#include "test/codec_factory.h"
17 18
#include "test/decode_test_driver.h"
#include "test/ivf_video_source.h"
19
#include "test/md5_helper.h"
20 21
#include "test/test_vectors.h"
#include "test/util.h"
22
#if CONFIG_WEBM_IO
23
#include "test/webm_video_source.h"
24
#endif
25 26 27 28
#include "vpx_mem/vpx_mem.h"

namespace {

29 30
class TestVectorTest : public ::libvpx_test::DecoderTest,
    public ::libvpx_test::CodecTestWithParam<const char*> {
31
 protected:
32
  TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(NULL) {}
33 34 35 36 37 38 39 40

  virtual ~TestVectorTest() {
    if (md5_file_)
      fclose(md5_file_);
  }

  void OpenMD5File(const std::string& md5_file_name_) {
    md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
41
    ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: "
42 43 44 45 46
        << md5_file_name_;
  }

  virtual void DecompressedFrameHook(const vpx_image_t& img,
                                     const unsigned int frame_number) {
47
    ASSERT_TRUE(md5_file_ != NULL);
48 49 50 51 52 53 54 55
    char expected_md5[33];
    char junk[128];

    // Read correct md5 checksums.
    const int res = fscanf(md5_file_, "%s  %s", expected_md5, junk);
    ASSERT_NE(res, EOF) << "Read md5 data failed";
    expected_md5[32] = '\0';

56 57 58
    ::libvpx_test::MD5 md5_res;
    md5_res.Add(&img);
    const char *actual_md5 = md5_res.Get();
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

    // Check md5 match.
    ASSERT_STREQ(expected_md5, actual_md5)
        << "Md5 checksums don't match: frame number = " << frame_number;
  }

 private:
  FILE *md5_file_;
};

// This test runs through the whole set of test vectors, and decodes them.
// The md5 checksums are computed for each frame in the video file. If md5
// checksums match the correct md5 data, then the test is passed. Otherwise,
// the test failed.
TEST_P(TestVectorTest, MD5Match) {
74
  const std::string filename = GET_PARAM(1);
75
  libvpx_test::CompressedVideoSource *video = NULL;
76

77 78 79 80
  // Open compressed video file.
  if (filename.substr(filename.length() - 3, 3) == "ivf") {
    video = new libvpx_test::IVFVideoSource(filename);
  } else if (filename.substr(filename.length() - 4, 4) == "webm") {
81
#if CONFIG_WEBM_IO
82
    video = new libvpx_test::WebMVideoSource(filename);
83 84 85 86 87
#else
    fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
            filename.c_str());
    return;
#endif
88 89
  }
  video->Init();
90 91 92 93 94 95

  // Construct md5 file name.
  const std::string md5_filename = filename + ".md5";
  OpenMD5File(md5_filename);

  // Decode frame, and check the md5 matching.
96 97
  ASSERT_NO_FATAL_FAILURE(RunLoop(video));
  delete video;
98 99
}

100
VP8_INSTANTIATE_TEST_CASE(TestVectorTest,
101 102 103
                          ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
                                              libvpx_test::kVP8TestVectors +
                                              libvpx_test::kNumVP8TestVectors));
104
VP9_INSTANTIATE_TEST_CASE(TestVectorTest,
105 106 107
                          ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
                                              libvpx_test::kVP9TestVectors +
                                              libvpx_test::kNumVP9TestVectors));
108 109

}  // namespace