blob: 109ae7d7c05aab8985d20100a960f403f351f96f [file] [log] [blame]
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +00001/*
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
16namespace webrtc {
17namespace test {
18
19const std::string kOutputFilename = "temp_outputfile.tmp";
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000020const size_t kFrameLength = 1000;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000021
22class 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
40TEST_F(FrameWriterTest, InitSuccess) {
41 FrameWriterImpl frame_writer(kOutputFilename, kFrameLength);
42 ASSERT_TRUE(frame_writer.Init());
43 ASSERT_EQ(kFrameLength, frame_writer.FrameLength());
44}
45
46TEST_F(FrameWriterTest, WriteFrame) {
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000047 uint8_t buffer[kFrameLength];
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000048 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.orgfa53d872013-02-04 10:07:17 +000053 ASSERT_EQ(kFrameLength, GetFileSize(kOutputFilename));
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000054}
55
56TEST_F(FrameWriterTest, WriteFrameUninitialized) {
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000057 uint8_t buffer[3];
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000058 FrameWriterImpl frame_writer(kOutputFilename, kFrameLength);
59 ASSERT_FALSE(frame_writer.WriteFrame(buffer));
60}
61
62} // namespace test
63} // namespace webrtc