kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 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 | |
| 21 | namespace webrtc { |
| 22 | namespace test { |
| 23 | |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 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. |
| 26 | class 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 | }; |
| 39 | FILE* VideoQualityAnalysisTest::logfile_ = NULL; |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 40 | |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 41 | TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsEmpty) { |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 42 | ResultsContainer result; |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 43 | PrintAnalysisResults(logfile_, "Empty", &result); |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 44 | } |
| 45 | |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 46 | TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsOneFrame) { |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 47 | ResultsContainer result; |
| 48 | result.frames.push_back(AnalysisResult(0, 35.0, 0.9)); |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 49 | PrintAnalysisResults(logfile_, "OneFrame", &result); |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 50 | } |
| 51 | |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 52 | TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsThreeFrames) { |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 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)); |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 57 | PrintAnalysisResults(logfile_, "ThreeFrames", &result); |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 58 | } |
| 59 | |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 60 | TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesInvalidFile) { |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 61 | std::string stats_filename = OutputPath() + "non-existing-stats-file.txt"; |
| 62 | remove(stats_filename.c_str()); |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 63 | PrintMaxRepeatedAndSkippedFrames(logfile_, "NonExistingStatsFile", |
| 64 | stats_filename); |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 65 | } |
| 66 | |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 67 | TEST_F(VideoQualityAnalysisTest, |
| 68 | PrintMaxRepeatedAndSkippedFramesEmptyStatsFile) { |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 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(); |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 73 | PrintMaxRepeatedAndSkippedFrames(logfile_, "EmptyStatsFile", stats_filename); |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 74 | } |
| 75 | |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 76 | TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesNormalFile) { |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 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 | |
kjellander@webrtc.org | f8a1798 | 2013-11-03 18:34:51 +0000 | [diff] [blame] | 86 | PrintMaxRepeatedAndSkippedFrames(logfile_, "NormalStatsFile", stats_filename); |
kjellander@webrtc.org | 3524ade | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | |
| 90 | } // namespace test |
| 91 | } // namespace webrtc |