1+ /* *
2+ * @file
3+ * @brief Unit tests for openshot::DummyReader
4+ * @author Jonathan Thomas <[email protected] > 5+ *
6+ * @ref License
7+ */
8+
9+ /* LICENSE
10+ *
11+ * Copyright (c) 2008-2019 OpenShot Studios, LLC
12+ * <http://www.openshotstudios.com/>. This file is part of
13+ * OpenShot Library (libopenshot), an open-source project dedicated to
14+ * delivering high quality video editing and animation solutions to the
15+ * world. For more information visit <http://www.openshot.org/>.
16+ *
17+ * OpenShot Library (libopenshot) is free software: you can redistribute it
18+ * and/or modify it under the terms of the GNU Lesser General Public License
19+ * as published by the Free Software Foundation, either version 3 of the
20+ * License, or (at your option) any later version.
21+ *
22+ * OpenShot Library (libopenshot) is distributed in the hope that it will be
23+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+ * GNU Lesser General Public License for more details.
26+ *
27+ * You should have received a copy of the GNU Lesser General Public License
28+ * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29+ */
30+
31+ #include " UnitTest++.h"
32+ // Prevent name clashes with juce::UnitTest
33+ #define DONT_SET_USING_JUCE_NAMESPACE 1
34+
35+ #include " ../include/OpenShot.h"
36+
37+ using namespace std ;
38+ using namespace openshot ;
39+
40+ TEST (DummyReader_Constructor) {
41+ // Create a default fraction (should be 1/1)
42+ openshot::DummyReader r (openshot::Fraction (30 , 1 ), 1920 , 1080 , 44100 , 2 , 30.0 );
43+ r.Open (); // Open the reader
44+
45+ // Check values
46+ CHECK_EQUAL (1920 , r.info .width );
47+ CHECK_EQUAL (1080 , r.info .height );
48+ CHECK_EQUAL (30 , r.info .fps .num );
49+ CHECK_EQUAL (1 , r.info .fps .den );
50+ CHECK_EQUAL (44100 , r.info .sample_rate );
51+ CHECK_EQUAL (2 , r.info .channels );
52+ CHECK_EQUAL (30.0 , r.info .duration );
53+ }
54+
55+ TEST (DummyReader_Blank_Frame) {
56+ // Create a default fraction (should be 1/1)
57+ openshot::DummyReader r (openshot::Fraction (30 , 1 ), 1920 , 1080 , 44100 , 2 , 30.0 );
58+ r.Open (); // Open the reader
59+
60+ // Get a blank frame (because we have not added any frames using WriteFrame() yet)
61+ // Check values
62+ CHECK_EQUAL (1 , r.GetFrame (1 )->number );
63+ CHECK_EQUAL (1 , r.GetFrame (1 )->GetPixels (700 )[700 ] == 0 ); // black pixel
64+ CHECK_EQUAL (1 , r.GetFrame (1 )->GetPixels (701 )[701 ] == 0 ); // black pixel
65+ }
66+
67+ TEST (DummyReader_Fake_Frame) {
68+ // Create a default fraction (should be 1/1)
69+ openshot::DummyReader r (openshot::Fraction (30 , 1 ), 1920 , 1080 , 44100 , 2 , 30.0 );
70+ r.Open (); // Open the reader
71+
72+ // Let's create some test frames
73+ for (int64_t frame_number = 1 ; frame_number <= 30 ; frame_number++) {
74+ // Create blank frame (with specific frame #, samples, and channels)
75+ // Sample count should be 44100 / 30 fps = 1470 samples per frame
76+ int sample_count = 1470 ;
77+ std::shared_ptr<openshot::Frame> f (new openshot::Frame (frame_number, sample_count, 2 ));
78+
79+ // Create test samples with incrementing value
80+ float *audio_buffer = new float [sample_count];
81+ for (int64_t sample_number = 0 ; sample_number < sample_count; sample_number++) {
82+ // Generate an incrementing audio sample value (just as an example)
83+ audio_buffer[sample_number] = float (frame_number) + (float (sample_number) / float (sample_count));
84+ }
85+
86+ // Add custom audio samples to Frame (bool replaceSamples, int destChannel, int destStartSample, const float* source,
87+ f->AddAudio (true , 0 , 0 , audio_buffer, sample_count, 1.0 ); // add channel 1
88+ f->AddAudio (true , 1 , 0 , audio_buffer, sample_count, 1.0 ); // add channel 2
89+
90+ // Write test frame to dummy reader
91+ r.WriteFrame (f);
92+ }
93+
94+ // Verify our artificial audio sample data is correct
95+ CHECK_EQUAL (1 , r.GetFrame (1 )->number );
96+ CHECK_EQUAL (1 , r.GetFrame (1 )->GetAudioSamples (0 )[0 ]);
97+ CHECK_CLOSE (1.00068033 , r.GetFrame (1 )->GetAudioSamples (0 )[1 ], 0.00001 );
98+ CHECK_CLOSE (1.00136054 , r.GetFrame (1 )->GetAudioSamples (0 )[2 ], 0.00001 );
99+ CHECK_EQUAL (2 , r.GetFrame (2 )->GetAudioSamples (0 )[0 ]);
100+ CHECK_CLOSE (2.00068033 , r.GetFrame (2 )->GetAudioSamples (0 )[1 ], 0.00001 );
101+ CHECK_CLOSE (2.00136054 , r.GetFrame (2 )->GetAudioSamples (0 )[2 ], 0.00001 );
102+ }
0 commit comments