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_writer.h" |
| 12 | |
| 13 | #include "gtest/gtest.h" |
| 14 | #include "testsupport/fileutils.h" |
| 15 | |
| 16 | namespace webrtc { |
| 17 | namespace test { |
| 18 | |
| 19 | const std::string kOutputFilename = "temp_outputfile.tmp"; |
kjellander@webrtc.org | fa53d87 | 2013-02-04 10:07:17 +0000 | [diff] [blame] | 20 | const size_t kFrameLength = 1000; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 21 | |
| 22 | class FrameWriterTest: public testing::Test { |
| 23 | protected: |
| 24 | FrameWriterTest() {} |
| 25 | virtual ~FrameWriterTest() {} |
| 26 | void SetUp() { |
| 27 | // Cleanup any previous output file. |
| 28 | std::remove(kOutputFilename.c_str()); |
| 29 | frame_writer_ = new FrameWriterImpl(kOutputFilename, kFrameLength); |
| 30 | ASSERT_TRUE(frame_writer_->Init()); |
| 31 | } |
| 32 | void TearDown() { |
| 33 | delete frame_writer_; |
| 34 | // Cleanup the temporary file. |
| 35 | std::remove(kOutputFilename.c_str()); |
| 36 | } |
| 37 | FrameWriter* frame_writer_; |
| 38 | }; |
| 39 | |
| 40 | TEST_F(FrameWriterTest, InitSuccess) { |
| 41 | FrameWriterImpl frame_writer(kOutputFilename, kFrameLength); |
| 42 | ASSERT_TRUE(frame_writer.Init()); |
| 43 | ASSERT_EQ(kFrameLength, frame_writer.FrameLength()); |
| 44 | } |
| 45 | |
| 46 | TEST_F(FrameWriterTest, WriteFrame) { |
pbos@webrtc.org | a5f1787 | 2013-04-09 11:10:21 +0000 | [diff] [blame^] | 47 | uint8_t buffer[kFrameLength]; |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 48 | memset(buffer, 9, kFrameLength); // Write lots of 9s to the buffer |
| 49 | bool result = frame_writer_->WriteFrame(buffer); |
| 50 | ASSERT_TRUE(result); // success |
| 51 | // Close the file and verify the size. |
| 52 | frame_writer_->Close(); |
kjellander@webrtc.org | fa53d87 | 2013-02-04 10:07:17 +0000 | [diff] [blame] | 53 | ASSERT_EQ(kFrameLength, GetFileSize(kOutputFilename)); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | TEST_F(FrameWriterTest, WriteFrameUninitialized) { |
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 | FrameWriterImpl frame_writer(kOutputFilename, kFrameLength); |
| 59 | ASSERT_FALSE(frame_writer.WriteFrame(buffer)); |
| 60 | } |
| 61 | |
| 62 | } // namespace test |
| 63 | } // namespace webrtc |