blob: ea837a74b47b9ad473cf3829ff8e518bf890ff8b [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
pbos@webrtc.org34741c82013-05-27 08:02:22 +000011#include "webrtc/test/testsupport/frame_reader.h"
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000012
pbos@webrtc.org34741c82013-05-27 08:02:22 +000013#include "testing/gtest/include/gtest/gtest.h"
14#include "webrtc/test/testsupport/fileutils.h"
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000015
16namespace webrtc {
17namespace test {
18
19const std::string kInputFilename = "temp_inputfile.tmp";
kjellander@webrtc.orgf0901672013-04-17 14:59:28 +000020const std::string kInputFileContents = "baz";
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000021// Setting the kFrameLength value to a value much larger than the
22// file to test causes the ReadFrame test to fail on Windows.
kjellander@webrtc.orgfa53d872013-02-04 10:07:17 +000023const size_t kFrameLength = 1000;
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000024
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) {
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000057 uint8_t buffer[3];
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000058 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) {
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000066 uint8_t buffer[3];
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000067 FrameReaderImpl file_reader(kInputFilename, kFrameLength);
68 ASSERT_FALSE(file_reader.ReadFrame(buffer));
69}
70
71} // namespace test
72} // namespace webrtc