1/*
2 *  Copyright (c) 2013 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// This test doesn't actually verify the output since it's just printed
12// to stdout by void functions, but it's still useful as it executes the code.
13
14#include <fstream>
15#include <string>
16
17#include "testing/gtest/include/gtest/gtest.h"
18#include "webrtc/test/testsupport/fileutils.h"
19#include "webrtc/tools/frame_analyzer/video_quality_analysis.h"
20
21namespace webrtc {
22namespace test {
23
24// Setup a log file to write the output to instead of stdout because we don't
25// want those numbers to be picked up as perf numbers.
26class VideoQualityAnalysisTest : public ::testing::Test {
27 protected:
28  static void SetUpTestCase() {
29    std::string log_filename = webrtc::test::OutputPath() +
30        "VideoQualityAnalysisTest.log";
31    logfile_ = fopen(log_filename.c_str(), "w");
32    ASSERT_TRUE(logfile_ != NULL);
33  }
34  static void TearDownTestCase() {
35    ASSERT_EQ(0, fclose(logfile_));
36  }
37  static FILE* logfile_;
38};
39FILE* VideoQualityAnalysisTest::logfile_ = NULL;
40
41TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsEmpty) {
42  ResultsContainer result;
43  PrintAnalysisResults(logfile_, "Empty", &result);
44}
45
46TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsOneFrame) {
47  ResultsContainer result;
48  result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
49  PrintAnalysisResults(logfile_, "OneFrame", &result);
50}
51
52TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsThreeFrames) {
53  ResultsContainer result;
54  result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
55  result.frames.push_back(AnalysisResult(1, 34.0, 0.8));
56  result.frames.push_back(AnalysisResult(2, 33.0, 0.7));
57  PrintAnalysisResults(logfile_, "ThreeFrames", &result);
58}
59
60TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesInvalidFile) {
61  std::string stats_filename = OutputPath() + "non-existing-stats-file.txt";
62  remove(stats_filename.c_str());
63  PrintMaxRepeatedAndSkippedFrames(logfile_, "NonExistingStatsFile",
64                                   stats_filename);
65}
66
67TEST_F(VideoQualityAnalysisTest,
68       PrintMaxRepeatedAndSkippedFramesEmptyStatsFile) {
69  std::string stats_filename = OutputPath() + "empty-stats.txt";
70  std::ofstream stats_file;
71  stats_file.open(stats_filename.c_str());
72  stats_file.close();
73  PrintMaxRepeatedAndSkippedFrames(logfile_, "EmptyStatsFile", stats_filename);
74}
75
76TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesNormalFile) {
77  std::string stats_filename = OutputPath() + "stats.txt";
78  std::ofstream stats_file;
79  stats_file.open(stats_filename.c_str());
80  stats_file << "frame_0001 0100\n";
81  stats_file << "frame_0002 0101\n";
82  stats_file << "frame_0003 0101\n";
83  stats_file << "frame_0004 0106\n";
84  stats_file.close();
85
86  PrintMaxRepeatedAndSkippedFrames(logfile_, "NormalStatsFile", stats_filename);
87}
88
89
90}  // namespace test
91}  // namespace webrtc
92