OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/test/testsupport/frame_reader.h" | 11 #include "webrtc/test/testsupport/frame_reader.h" |
12 | 12 |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "webrtc/test/testsupport/fileutils.h" | 14 #include "webrtc/test/testsupport/fileutils.h" |
| 15 #include "webrtc/common_video/include/video_frame_buffer.h" |
15 | 16 |
16 namespace webrtc { | 17 namespace webrtc { |
17 namespace test { | 18 namespace test { |
18 | 19 |
19 const std::string kInputFileContents = "baz"; | 20 const std::string kInputFileContents = "baz"; |
20 // Setting the kFrameLength value to a value much larger than the | 21 const size_t kFrameLength = 3; |
21 // file to test causes the ReadFrame test to fail on Windows. | |
22 const size_t kFrameLength = 1000; | |
23 | 22 |
24 class FrameReaderTest: public testing::Test { | 23 class FrameReaderTest: public testing::Test { |
25 protected: | 24 protected: |
26 FrameReaderTest() {} | 25 FrameReaderTest() {} |
27 virtual ~FrameReaderTest() {} | 26 virtual ~FrameReaderTest() {} |
28 void SetUp() { | 27 void SetUp() { |
29 // Create a dummy input file. | 28 // Create a dummy input file. |
30 temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), | 29 temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), |
31 "frame_reader_unittest"); | 30 "frame_reader_unittest"); |
32 FILE* dummy = fopen(temp_filename_.c_str(), "wb"); | 31 FILE* dummy = fopen(temp_filename_.c_str(), "wb"); |
33 fprintf(dummy, "%s", kInputFileContents.c_str()); | 32 fprintf(dummy, "%s", kInputFileContents.c_str()); |
34 fclose(dummy); | 33 fclose(dummy); |
35 | 34 |
36 frame_reader_ = new FrameReaderImpl(temp_filename_, kFrameLength); | 35 frame_reader_ = new FrameReaderImpl(temp_filename_, 1, 1); |
37 ASSERT_TRUE(frame_reader_->Init()); | 36 ASSERT_TRUE(frame_reader_->Init()); |
38 } | 37 } |
39 void TearDown() { | 38 void TearDown() { |
40 delete frame_reader_; | 39 delete frame_reader_; |
41 // Cleanup the dummy input file. | 40 // Cleanup the dummy input file. |
42 remove(temp_filename_.c_str()); | 41 remove(temp_filename_.c_str()); |
43 } | 42 } |
44 FrameReader* frame_reader_; | 43 FrameReader* frame_reader_; |
45 std::string temp_filename_; | 44 std::string temp_filename_; |
46 }; | 45 }; |
47 | 46 |
48 TEST_F(FrameReaderTest, InitSuccess) { | 47 TEST_F(FrameReaderTest, InitSuccess) { |
49 FrameReaderImpl frame_reader(temp_filename_, kFrameLength); | 48 FrameReaderImpl frame_reader(temp_filename_, 1, 1); |
50 ASSERT_TRUE(frame_reader.Init()); | 49 ASSERT_TRUE(frame_reader.Init()); |
51 ASSERT_EQ(kFrameLength, frame_reader.FrameLength()); | 50 ASSERT_EQ(kFrameLength, frame_reader.FrameLength()); |
52 ASSERT_EQ(0, frame_reader.NumberOfFrames()); | 51 ASSERT_EQ(1, frame_reader.NumberOfFrames()); |
53 } | 52 } |
54 | 53 |
55 TEST_F(FrameReaderTest, ReadFrame) { | 54 TEST_F(FrameReaderTest, ReadFrame) { |
56 uint8_t buffer[3]; | 55 rtc::scoped_refptr<VideoFrameBuffer> buffer; |
57 bool result = frame_reader_->ReadFrame(buffer); | 56 buffer = frame_reader_->ReadFrame(); |
58 ASSERT_FALSE(result); // No more files to read. | 57 ASSERT_TRUE(buffer); |
59 ASSERT_EQ(kInputFileContents[0], buffer[0]); | 58 ASSERT_EQ(kInputFileContents[0], buffer->DataY()[0]); |
60 ASSERT_EQ(kInputFileContents[1], buffer[1]); | 59 ASSERT_EQ(kInputFileContents[1], buffer->DataU()[0]); |
61 ASSERT_EQ(kInputFileContents[2], buffer[2]); | 60 ASSERT_EQ(kInputFileContents[2], buffer->DataV()[0]); |
| 61 ASSERT_FALSE(frame_reader_->ReadFrame()); // End of file |
62 } | 62 } |
63 | 63 |
64 TEST_F(FrameReaderTest, ReadFrameUninitialized) { | 64 TEST_F(FrameReaderTest, ReadFrameUninitialized) { |
65 uint8_t buffer[3]; | 65 FrameReaderImpl file_reader(temp_filename_, 1, 1); |
66 FrameReaderImpl file_reader(temp_filename_, kFrameLength); | 66 ASSERT_FALSE(file_reader.ReadFrame()); |
67 ASSERT_FALSE(file_reader.ReadFrame(buffer)); | |
68 } | 67 } |
69 | 68 |
70 } // namespace test | 69 } // namespace test |
71 } // namespace webrtc | 70 } // namespace webrtc |
OLD | NEW |