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
16namespace webrtc {
17namespace test {
18
19const std::string kInputFilename = "temp_inputfile.tmp";
20const std::string kInputFileContents = "baz";
21// Setting the kFrameLength value to a value much larger than the
22// file to test causes the ReadFrame test to fail on Windows.
23const int kFrameLength = 1000;
24
25class 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
49TEST_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
56TEST_F(FrameReaderTest, ReadFrame) {
57  WebRtc_UWord8 buffer[3];
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
65TEST_F(FrameReaderTest, ReadFrameUninitialized) {
66  WebRtc_UWord8 buffer[3];
67  FrameReaderImpl file_reader(kInputFilename, kFrameLength);
68  ASSERT_FALSE(file_reader.ReadFrame(buffer));
69}
70
71}  // namespace test
72}  // namespace webrtc
73