OLD | NEW |
(Empty) | |
| 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 "webrtc/test/testsupport/frame_writer.h" |
| 12 |
| 13 #include "webrtc/test/gtest.h" |
| 14 #include "webrtc/test/testsupport/fileutils.h" |
| 15 |
| 16 namespace webrtc { |
| 17 namespace test { |
| 18 |
| 19 const size_t kFrameLength = 1000; |
| 20 |
| 21 class FrameWriterTest: public testing::Test { |
| 22 protected: |
| 23 FrameWriterTest() {} |
| 24 virtual ~FrameWriterTest() {} |
| 25 void SetUp() { |
| 26 temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), |
| 27 "frame_writer_unittest"); |
| 28 frame_writer_ = new FrameWriterImpl(temp_filename_, kFrameLength); |
| 29 ASSERT_TRUE(frame_writer_->Init()); |
| 30 } |
| 31 void TearDown() { |
| 32 delete frame_writer_; |
| 33 // Cleanup the temporary file. |
| 34 remove(temp_filename_.c_str()); |
| 35 } |
| 36 FrameWriter* frame_writer_; |
| 37 std::string temp_filename_; |
| 38 }; |
| 39 |
| 40 TEST_F(FrameWriterTest, InitSuccess) { |
| 41 FrameWriterImpl frame_writer(temp_filename_, kFrameLength); |
| 42 ASSERT_TRUE(frame_writer.Init()); |
| 43 ASSERT_EQ(kFrameLength, frame_writer.FrameLength()); |
| 44 } |
| 45 |
| 46 TEST_F(FrameWriterTest, WriteFrame) { |
| 47 uint8_t buffer[kFrameLength]; |
| 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(); |
| 53 ASSERT_EQ(kFrameLength, GetFileSize(temp_filename_)); |
| 54 } |
| 55 |
| 56 TEST_F(FrameWriterTest, WriteFrameUninitialized) { |
| 57 uint8_t buffer[3]; |
| 58 FrameWriterImpl frame_writer(temp_filename_, kFrameLength); |
| 59 ASSERT_FALSE(frame_writer.WriteFrame(buffer)); |
| 60 } |
| 61 |
| 62 } // namespace test |
| 63 } // namespace webrtc |
OLD | NEW |