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_Basic_Constructor) {
41+ // Create a default fraction (should be 1/1)
42+ openshot::DummyReader r;
43+ r.Open (); // Open the reader
44+
45+ // Check values
46+ CHECK_EQUAL (1280 , r.info .width );
47+ CHECK_EQUAL (768 , r.info .height );
48+ CHECK_EQUAL (24 , 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_Constructor) {
56+ // Create a default fraction (should be 1/1)
57+ openshot::DummyReader r (openshot::Fraction (30 , 1 ), 1920 , 1080 , 44100 , 2 , 60.0 );
58+ r.Open (); // Open the reader
59+
60+ // Check values
61+ CHECK_EQUAL (1920 , r.info .width );
62+ CHECK_EQUAL (1080 , r.info .height );
63+ CHECK_EQUAL (30 , r.info .fps .num );
64+ CHECK_EQUAL (1 , r.info .fps .den );
65+ CHECK_EQUAL (44100 , r.info .sample_rate );
66+ CHECK_EQUAL (2 , r.info .channels );
67+ CHECK_EQUAL (60.0 , r.info .duration );
68+ }
69+
70+ TEST (DummyReader_Blank_Frame) {
71+ // Create a default fraction (should be 1/1)
72+ openshot::DummyReader r (openshot::Fraction (30 , 1 ), 1920 , 1080 , 44100 , 2 , 30.0 );
73+ r.Open (); // Open the reader
74+
75+ // Get a blank frame (because we have not passed a Cache object (full of Frame objects) to the constructor
76+ // Check values
77+ CHECK_EQUAL (1 , r.GetFrame (1 )->number );
78+ CHECK_EQUAL (1 , r.GetFrame (1 )->GetPixels (700 )[700 ] == 0 ); // black pixel
79+ CHECK_EQUAL (1 , r.GetFrame (1 )->GetPixels (701 )[701 ] == 0 ); // black pixel
80+ }
81+
82+ TEST (DummyReader_Fake_Frame) {
83+
84+ // Create cache object to hold test frames
85+ CacheMemory cache;
86+
87+ // Let's create some test frames
88+ for (int64_t frame_number = 1 ; frame_number <= 30 ; frame_number++) {
89+ // Create blank frame (with specific frame #, samples, and channels)
90+ // Sample count should be 44100 / 30 fps = 1470 samples per frame
91+ int sample_count = 1470 ;
92+ std::shared_ptr<openshot::Frame> f (new openshot::Frame (frame_number, sample_count, 2 ));
93+
94+ // Create test samples with incrementing value
95+ float *audio_buffer = new float [sample_count];
96+ for (int64_t sample_number = 0 ; sample_number < sample_count; sample_number++) {
97+ // Generate an incrementing audio sample value (just as an example)
98+ audio_buffer[sample_number] = float (frame_number) + (float (sample_number) / float (sample_count));
99+ }
100+
101+ // Add custom audio samples to Frame (bool replaceSamples, int destChannel, int destStartSample, const float* source,
102+ f->AddAudio (true , 0 , 0 , audio_buffer, sample_count, 1.0 ); // add channel 1
103+ f->AddAudio (true , 1 , 0 , audio_buffer, sample_count, 1.0 ); // add channel 2
104+
105+ // Add test frame to dummy reader
106+ cache.Add (f);
107+ }
108+
109+ // Create a default fraction (should be 1/1)
110+ openshot::DummyReader r (openshot::Fraction (30 , 1 ), 1920 , 1080 , 44100 , 2 , 30.0 , &cache);
111+ r.Open (); // Open the reader
112+
113+ // Verify our artificial audio sample data is correct
114+ CHECK_EQUAL (1 , r.GetFrame (1 )->number );
115+ CHECK_EQUAL (1 , r.GetFrame (1 )->GetAudioSamples (0 )[0 ]);
116+ CHECK_CLOSE (1.00068033 , r.GetFrame (1 )->GetAudioSamples (0 )[1 ], 0.00001 );
117+ CHECK_CLOSE (1.00136054 , r.GetFrame (1 )->GetAudioSamples (0 )[2 ], 0.00001 );
118+ CHECK_EQUAL (2 , r.GetFrame (2 )->GetAudioSamples (0 )[0 ]);
119+ CHECK_CLOSE (2.00068033 , r.GetFrame (2 )->GetAudioSamples (0 )[1 ], 0.00001 );
120+ CHECK_CLOSE (2.00136054 , r.GetFrame (2 )->GetAudioSamples (0 )[2 ], 0.00001 );
121+
122+ // Clean up
123+ cache.Clear ();
124+ r.Close ();
125+ }
126+
127+ TEST (DummyReader_Invalid_Fake_Frame) {
128+ // Create fake frames (with specific frame #, samples, and channels)
129+ std::shared_ptr<openshot::Frame> f1 (new openshot::Frame (1 , 1470 , 2 ));
130+ std::shared_ptr<openshot::Frame> f2 (new openshot::Frame (2 , 1470 , 2 ));
131+
132+ // Add test frames to cache object
133+ CacheMemory cache;
134+ cache.Add (f1);
135+ cache.Add (f2);
136+
137+ // Create a default fraction (should be 1/1)
138+ openshot::DummyReader r (openshot::Fraction (30 , 1 ), 1920 , 1080 , 44100 , 2 , 30.0 , &cache);
139+ r.Open ();
140+
141+ // Verify exception
142+ CHECK_EQUAL (1 , r.GetFrame (1 )->number );
143+ CHECK_EQUAL (2 , r.GetFrame (2 )->number );
144+ CHECK_THROW (r.GetFrame (3 )->number , InvalidFile);
145+
146+ // Clean up
147+ cache.Clear ();
148+ r.Close ();
149+ }
0 commit comments