OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014 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. |
| 9 */ |
| 10 |
| 11 #include <cstdio> |
| 12 #include <cstdlib> |
| 13 #include <string> |
| 14 #include <vector> |
| 15 #include "third_party/googletest/src/include/gtest/gtest.h" |
| 16 #include "./vpx_config.h" |
| 17 #include "test/codec_factory.h" |
| 18 #include "test/decode_test_driver.h" |
| 19 #include "test/ivf_video_source.h" |
| 20 #include "test/util.h" |
| 21 #if CONFIG_WEBM_IO |
| 22 #include "test/webm_video_source.h" |
| 23 #endif |
| 24 #include "vpx_mem/vpx_mem.h" |
| 25 |
| 26 namespace { |
| 27 |
| 28 class InvalidFileTest |
| 29 : public ::libvpx_test::DecoderTest, |
| 30 public ::libvpx_test::CodecTestWithParam<const char*> { |
| 31 protected: |
| 32 InvalidFileTest() : DecoderTest(GET_PARAM(0)), res_file_(NULL) {} |
| 33 |
| 34 virtual ~InvalidFileTest() { |
| 35 if (res_file_ != NULL) |
| 36 fclose(res_file_); |
| 37 } |
| 38 |
| 39 void OpenResFile(const std::string &res_file_name_) { |
| 40 res_file_ = libvpx_test::OpenTestDataFile(res_file_name_); |
| 41 ASSERT_TRUE(res_file_ != NULL) << "Result file open failed. Filename: " |
| 42 << res_file_name_; |
| 43 } |
| 44 |
| 45 virtual bool HandleDecodeResult( |
| 46 const vpx_codec_err_t res_dec, |
| 47 const libvpx_test::CompressedVideoSource &video, |
| 48 libvpx_test::Decoder *decoder) { |
| 49 EXPECT_TRUE(res_file_ != NULL); |
| 50 int expected_res_dec; |
| 51 |
| 52 // Read integer result. |
| 53 const int res = fscanf(res_file_, "%d", &expected_res_dec); |
| 54 EXPECT_NE(res, EOF) << "Read result data failed"; |
| 55 |
| 56 // Check results match. |
| 57 EXPECT_EQ(expected_res_dec, res_dec) |
| 58 << "Results don't match: frame number = " << video.frame_number(); |
| 59 |
| 60 return !HasFailure(); |
| 61 } |
| 62 |
| 63 private: |
| 64 FILE *res_file_; |
| 65 }; |
| 66 |
| 67 TEST_P(InvalidFileTest, DISABLED_ReturnCode) { |
| 68 const std::string filename = GET_PARAM(1); |
| 69 libvpx_test::CompressedVideoSource *video = NULL; |
| 70 |
| 71 // Open compressed video file. |
| 72 if (filename.substr(filename.length() - 3, 3) == "ivf") { |
| 73 video = new libvpx_test::IVFVideoSource(filename); |
| 74 } else if (filename.substr(filename.length() - 4, 4) == "webm") { |
| 75 #if CONFIG_WEBM_IO |
| 76 video = new libvpx_test::WebMVideoSource(filename); |
| 77 #else |
| 78 fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n", |
| 79 filename.c_str()); |
| 80 return; |
| 81 #endif |
| 82 } |
| 83 video->Init(); |
| 84 |
| 85 // Construct result file name. The file holds a list of expected integer |
| 86 // results, one for each decoded frame. Any result that doesn't match |
| 87 // the files list will cause a test failure. |
| 88 const std::string res_filename = filename + ".res"; |
| 89 OpenResFile(res_filename); |
| 90 |
| 91 // Decode frame, and check the md5 matching. |
| 92 ASSERT_NO_FATAL_FAILURE(RunLoop(video)); |
| 93 delete video; |
| 94 } |
| 95 |
| 96 const char *const kVP9InvalidFileTests[] = { |
| 97 "invalid-vp90-01.webm" |
| 98 }; |
| 99 |
| 100 #define NELEMENTS(x) static_cast<int>(sizeof(x) / sizeof(x[0])) |
| 101 |
| 102 VP9_INSTANTIATE_TEST_CASE(InvalidFileTest, |
| 103 ::testing::ValuesIn(kVP9InvalidFileTests, |
| 104 kVP9InvalidFileTests + |
| 105 NELEMENTS(kVP9InvalidFileTests))); |
| 106 |
| 107 } // namespace |
OLD | NEW |