Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 1 | /* |
Frank Galligan | 38536f6 | 2013-12-12 08:36:34 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013 The WebM project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <cstdio> |
| 12 | #include <cstdlib> |
| 13 | #include <string> |
| 14 | #include "third_party/googletest/src/include/gtest/gtest.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 15 | #include "test/codec_factory.h" |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 16 | #include "test/decode_test_driver.h" |
| 17 | #include "test/ivf_video_source.h" |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 18 | #include "test/md5_helper.h" |
Frank Galligan | 52b2d50 | 2013-12-11 09:01:47 -0800 | [diff] [blame] | 19 | #include "test/test_vectors.h" |
| 20 | #include "test/util.h" |
| 21 | #include "test/webm_video_source.h" |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 22 | #include "vpx_mem/vpx_mem.h" |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 23 | |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 24 | namespace { |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 25 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 26 | class TestVectorTest : public ::libvpx_test::DecoderTest, |
| 27 | public ::libvpx_test::CodecTestWithParam<const char*> { |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 28 | protected: |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 29 | TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(NULL) {} |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 30 | |
| 31 | virtual ~TestVectorTest() { |
| 32 | if (md5_file_) |
| 33 | fclose(md5_file_); |
| 34 | } |
| 35 | |
| 36 | void OpenMD5File(const std::string& md5_file_name_) { |
| 37 | md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_); |
James Zern | 77e64d8 | 2013-12-18 17:00:40 -0800 | [diff] [blame^] | 38 | ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: " |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 39 | << md5_file_name_; |
| 40 | } |
| 41 | |
| 42 | virtual void DecompressedFrameHook(const vpx_image_t& img, |
| 43 | const unsigned int frame_number) { |
James Zern | 66c7dff | 2013-06-25 17:55:28 -0700 | [diff] [blame] | 44 | ASSERT_TRUE(md5_file_ != NULL); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 45 | char expected_md5[33]; |
| 46 | char junk[128]; |
| 47 | |
| 48 | // Read correct md5 checksums. |
| 49 | const int res = fscanf(md5_file_, "%s %s", expected_md5, junk); |
| 50 | ASSERT_NE(res, EOF) << "Read md5 data failed"; |
| 51 | expected_md5[32] = '\0'; |
| 52 | |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 53 | ::libvpx_test::MD5 md5_res; |
| 54 | md5_res.Add(&img); |
| 55 | const char *actual_md5 = md5_res.Get(); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 56 | |
| 57 | // Check md5 match. |
| 58 | ASSERT_STREQ(expected_md5, actual_md5) |
| 59 | << "Md5 checksums don't match: frame number = " << frame_number; |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | FILE *md5_file_; |
| 64 | }; |
| 65 | |
| 66 | // This test runs through the whole set of test vectors, and decodes them. |
| 67 | // The md5 checksums are computed for each frame in the video file. If md5 |
| 68 | // checksums match the correct md5 data, then the test is passed. Otherwise, |
| 69 | // the test failed. |
| 70 | TEST_P(TestVectorTest, MD5Match) { |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 71 | const std::string filename = GET_PARAM(1); |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 72 | libvpx_test::CompressedVideoSource *video = NULL; |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 73 | |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 74 | // Open compressed video file. |
| 75 | if (filename.substr(filename.length() - 3, 3) == "ivf") { |
| 76 | video = new libvpx_test::IVFVideoSource(filename); |
| 77 | } else if (filename.substr(filename.length() - 4, 4) == "webm") { |
| 78 | video = new libvpx_test::WebMVideoSource(filename); |
| 79 | } |
| 80 | video->Init(); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 81 | |
| 82 | // Construct md5 file name. |
| 83 | const std::string md5_filename = filename + ".md5"; |
| 84 | OpenMD5File(md5_filename); |
| 85 | |
| 86 | // Decode frame, and check the md5 matching. |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 87 | ASSERT_NO_FATAL_FAILURE(RunLoop(video)); |
| 88 | delete video; |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 91 | VP8_INSTANTIATE_TEST_CASE(TestVectorTest, |
Frank Galligan | 52b2d50 | 2013-12-11 09:01:47 -0800 | [diff] [blame] | 92 | ::testing::ValuesIn(libvpx_test::kVP8TestVectors)); |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 93 | VP9_INSTANTIATE_TEST_CASE(TestVectorTest, |
Frank Galligan | 52b2d50 | 2013-12-11 09:01:47 -0800 | [diff] [blame] | 94 | ::testing::ValuesIn(libvpx_test::kVP9TestVectors)); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 95 | |
| 96 | } // namespace |