kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC 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 "testsupport/frame_reader.h" |
| 12 | |
| 13 | #include "gtest/gtest.h" |
| 14 | #include "testsupport/fileutils.h" |
| 15 | |
| 16 | namespace webrtc { |
| 17 | namespace test { |
| 18 | |
| 19 | const std::string kInputFilename = "temp_inputfile.tmp"; |
kjellander@webrtc.org | f090167 | 2013-04-17 14:59:28 +0000 | [diff] [blame^] | 20 | const std::string kInputFileContents = "baz"; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 21 | // Setting the kFrameLength value to a value much larger than the |
| 22 | // file to test causes the ReadFrame test to fail on Windows. |
kjellander@webrtc.org | fa53d87 | 2013-02-04 10:07:17 +0000 | [diff] [blame] | 23 | const size_t kFrameLength = 1000; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 24 | |
| 25 | class FrameReaderTest: public testing::Test { |
| 26 | protected: |
| 27 | FrameReaderTest() {} |
| 28 | virtual ~FrameReaderTest() {} |
| 29 | void SetUp() { |
| 30 | // Cleanup any previous dummy input file. |
| 31 | std::remove(kInputFilename.c_str()); |
| 32 | |
| 33 | // Create a dummy input file. |
| 34 | FILE* dummy = fopen(kInputFilename.c_str(), "wb"); |
| 35 | fprintf(dummy, "%s", kInputFileContents.c_str()); |
| 36 | fclose(dummy); |
| 37 | |
| 38 | frame_reader_ = new FrameReaderImpl(kInputFilename, kFrameLength); |
| 39 | ASSERT_TRUE(frame_reader_->Init()); |
| 40 | } |
| 41 | void TearDown() { |
| 42 | delete frame_reader_; |
| 43 | // Cleanup the dummy input file. |
| 44 | std::remove(kInputFilename.c_str()); |
| 45 | } |
| 46 | FrameReader* frame_reader_; |
| 47 | }; |
| 48 | |
| 49 | TEST_F(FrameReaderTest, InitSuccess) { |
| 50 | FrameReaderImpl frame_reader(kInputFilename, kFrameLength); |
| 51 | ASSERT_TRUE(frame_reader.Init()); |
| 52 | ASSERT_EQ(kFrameLength, frame_reader.FrameLength()); |
| 53 | ASSERT_EQ(0, frame_reader.NumberOfFrames()); |
| 54 | } |
| 55 | |
| 56 | TEST_F(FrameReaderTest, ReadFrame) { |
pbos@webrtc.org | a5f1787 | 2013-04-09 11:10:21 +0000 | [diff] [blame] | 57 | uint8_t buffer[3]; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 58 | bool result = frame_reader_->ReadFrame(buffer); |
| 59 | ASSERT_FALSE(result); // No more files to read. |
| 60 | ASSERT_EQ(kInputFileContents[0], buffer[0]); |
| 61 | ASSERT_EQ(kInputFileContents[1], buffer[1]); |
| 62 | ASSERT_EQ(kInputFileContents[2], buffer[2]); |
| 63 | } |
| 64 | |
| 65 | TEST_F(FrameReaderTest, ReadFrameUninitialized) { |
pbos@webrtc.org | a5f1787 | 2013-04-09 11:10:21 +0000 | [diff] [blame] | 66 | uint8_t buffer[3]; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 67 | FrameReaderImpl file_reader(kInputFilename, kFrameLength); |
| 68 | ASSERT_FALSE(file_reader.ReadFrame(buffer)); |
| 69 | } |
| 70 | |
| 71 | } // namespace test |
| 72 | } // namespace webrtc |