Make remaining print functions testable

This commit is contained in:
FeRD (Frank Dana)
2021-04-19 20:57:47 -04:00
parent 2a90aa09a9
commit 9d79b394c4
9 changed files with 89 additions and 69 deletions

View File

@@ -28,6 +28,9 @@
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <iomanip>
#include "WriterBase.h"
#include "Exceptions.h"
@@ -100,43 +103,43 @@ void WriterBase::CopyReaderInfo(ReaderBase* reader)
}
// Display file information
void WriterBase::DisplayInfo() {
std::cout << std::fixed << std::setprecision(2) << std::boolalpha;
std::cout << "----------------------------" << std::endl;
std::cout << "----- File Information -----" << std::endl;
std::cout << "----------------------------" << std::endl;
std::cout << "--> Has Video: " << info.has_video << std::endl;
std::cout << "--> Has Audio: " << info.has_audio << std::endl;
std::cout << "--> Has Single Image: " << info.has_single_image << std::endl;
std::cout << "--> Duration: " << info.duration << " Seconds" << std::endl;
std::cout << "--> File Size: " << double(info.file_size) / 1024 / 1024 << " MB" << std::endl;
std::cout << "----------------------------" << std::endl;
std::cout << "----- Video Attributes -----" << std::endl;
std::cout << "----------------------------" << std::endl;
std::cout << "--> Width: " << info.width << std::endl;
std::cout << "--> Height: " << info.height << std::endl;
std::cout << "--> Pixel Format: " << info.pixel_format << std::endl;
std::cout << "--> Frames Per Second: " << info.fps.ToDouble() << " (" << info.fps.num << "/" << info.fps.den << ")" << std::endl;
std::cout << "--> Video Bit Rate: " << info.video_bit_rate/1000 << " kb/s" << std::endl;
std::cout << "--> Pixel Ratio: " << info.pixel_ratio.ToDouble() << " (" << info.pixel_ratio.num << "/" << info.pixel_ratio.den << ")" << std::endl;
std::cout << "--> Display Aspect Ratio: " << info.display_ratio.ToDouble() << " (" << info.display_ratio.num << "/" << info.display_ratio.den << ")" << std::endl;
std::cout << "--> Video Codec: " << info.vcodec << std::endl;
std::cout << "--> Video Length: " << info.video_length << " Frames" << std::endl;
std::cout << "--> Video Stream Index: " << info.video_stream_index << std::endl;
std::cout << "--> Video Timebase: " << info.video_timebase.ToDouble() << " (" << info.video_timebase.num << "/" << info.video_timebase.den << ")" << std::endl;
std::cout << "--> Interlaced: " << info.interlaced_frame << std::endl;
std::cout << "--> Interlaced: Top Field First: " << info.top_field_first << std::endl;
std::cout << "----------------------------" << std::endl;
std::cout << "----- Audio Attributes -----" << std::endl;
std::cout << "----------------------------" << std::endl;
std::cout << "--> Audio Codec: " << info.acodec << std::endl;
std::cout << "--> Audio Bit Rate: " << info.audio_bit_rate/1000 << " kb/s" << std::endl;
std::cout << "--> Sample Rate: " << info.sample_rate << " Hz" << std::endl;
std::cout << "--> # of Channels: " << info.channels << std::endl;
std::cout << "--> Channel Layout: " << info.channel_layout << std::endl;
std::cout << "--> Audio Stream Index: " << info.audio_stream_index << std::endl;
std::cout << "--> Audio Timebase: " << info.audio_timebase.ToDouble() << " (" << info.audio_timebase.num << "/" << info.audio_timebase.den << ")" << std::endl;
std::cout << "----------------------------" << std::endl;
void WriterBase::DisplayInfo(std::ostream* out) {
*out << std::fixed << std::setprecision(2) << std::boolalpha;
*out << "----------------------------" << std::endl;
*out << "----- File Information -----" << std::endl;
*out << "----------------------------" << std::endl;
*out << "--> Has Video: " << info.has_video << std::endl;
*out << "--> Has Audio: " << info.has_audio << std::endl;
*out << "--> Has Single Image: " << info.has_single_image << std::endl;
*out << "--> Duration: " << info.duration << " Seconds" << std::endl;
*out << "--> File Size: " << double(info.file_size) / 1024 / 1024 << " MB" << std::endl;
*out << "----------------------------" << std::endl;
*out << "----- Video Attributes -----" << std::endl;
*out << "----------------------------" << std::endl;
*out << "--> Width: " << info.width << std::endl;
*out << "--> Height: " << info.height << std::endl;
*out << "--> Pixel Format: " << info.pixel_format << std::endl;
*out << "--> Frames Per Second: " << info.fps.ToDouble() << " (" << info.fps.num << "/" << info.fps.den << ")" << std::endl;
*out << "--> Video Bit Rate: " << info.video_bit_rate/1000 << " kb/s" << std::endl;
*out << "--> Pixel Ratio: " << info.pixel_ratio.ToDouble() << " (" << info.pixel_ratio.num << "/" << info.pixel_ratio.den << ")" << std::endl;
*out << "--> Display Aspect Ratio: " << info.display_ratio.ToDouble() << " (" << info.display_ratio.num << "/" << info.display_ratio.den << ")" << std::endl;
*out << "--> Video Codec: " << info.vcodec << std::endl;
*out << "--> Video Length: " << info.video_length << " Frames" << std::endl;
*out << "--> Video Stream Index: " << info.video_stream_index << std::endl;
*out << "--> Video Timebase: " << info.video_timebase.ToDouble() << " (" << info.video_timebase.num << "/" << info.video_timebase.den << ")" << std::endl;
*out << "--> Interlaced: " << info.interlaced_frame << std::endl;
*out << "--> Interlaced: Top Field First: " << info.top_field_first << std::endl;
*out << "----------------------------" << std::endl;
*out << "----- Audio Attributes -----" << std::endl;
*out << "----------------------------" << std::endl;
*out << "--> Audio Codec: " << info.acodec << std::endl;
*out << "--> Audio Bit Rate: " << info.audio_bit_rate/1000 << " kb/s" << std::endl;
*out << "--> Sample Rate: " << info.sample_rate << " Hz" << std::endl;
*out << "--> # of Channels: " << info.channels << std::endl;
*out << "--> Channel Layout: " << info.channel_layout << std::endl;
*out << "--> Audio Stream Index: " << info.audio_stream_index << std::endl;
*out << "--> Audio Timebase: " << info.audio_timebase.ToDouble() << " (" << info.audio_timebase.num << "/" << info.audio_timebase.den << ")" << std::endl;
*out << "----------------------------" << std::endl;
}
// Generate JSON string of this object