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
16namespace webrtc {
17namespace test {
18
19const std::string kOutputFilename = "temp_outputfile.tmp";
20const int kFrameLength = 1000;
21
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) {
47  WebRtc_UWord8 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,
54            static_cast<int>(GetFileSize(kOutputFilename)));
55}
56
57TEST_F(FrameWriterTest, WriteFrameUninitialized) {
58  WebRtc_UWord8 buffer[3];
59  FrameWriterImpl frame_writer(kOutputFilename, kFrameLength);
60  ASSERT_FALSE(frame_writer.WriteFrame(buffer));
61}
62
63}  // namespace test
64}  // namespace webrtc
65