-
Notifications
You must be signed in to change notification settings - Fork 261
/
Frame_Tests.cpp
155 lines (117 loc) · 4.04 KB
/
Frame_Tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* @file
* @brief Unit tests for openshot::Frame
* @author Jonathan Thomas <jonathan@openshot.org>
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <memory>
#include "UnitTest++.h"
// Prevent name clashes with juce::UnitTest
#define DONT_SET_USING_JUCE_NAMESPACE 1
#include "Frame.h"
#include "Clip.h"
#include "Fraction.h"
#include <QImage>
using namespace openshot;
SUITE(Frame_Tests)
{
TEST(Default_Constructor)
{
// Create a "blank" default Frame
std::shared_ptr<Frame> f1(new Frame());
CHECK(f1 != nullptr); // Test aborts here if we didn't get a Frame
// Check basic default parameters
CHECK_EQUAL(1, f1->GetHeight());
CHECK_EQUAL(1, f1->GetWidth());
CHECK_EQUAL(44100, f1->SampleRate());
CHECK_EQUAL(2, f1->GetAudioChannelsCount());
// Should be false until we load or create contents
CHECK_EQUAL(false, f1->has_image_data);
CHECK_EQUAL(false, f1->has_audio_data);
// Calling GetImage() paints a blank frame, by default
std::shared_ptr<QImage> i1 = f1->GetImage();
CHECK(i1 != nullptr);
CHECK_EQUAL(true,f1->has_image_data);
CHECK_EQUAL(false,f1->has_audio_data);
}
TEST(Data_Access)
{
// Create a video clip
std::stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
Clip c1(path.str());
c1.Open();
// Get first frame
std::shared_ptr<Frame> f1 = c1.GetFrame(1);
CHECK(f1 != nullptr);
CHECK_EQUAL(1, f1->number);
CHECK_EQUAL(1280, f1->GetWidth());
CHECK_EQUAL(720, f1->GetHeight());
}
TEST(AddImage_QImage)
{
// Create a "blank" default Frame
std::shared_ptr<Frame> f1(new Frame());
// Load an image
std::stringstream path;
path << TEST_MEDIA_PATH << "front.png";
std::shared_ptr<QImage> i1(new QImage(QString::fromStdString(path.str()))) ;
CHECK(f1 != nullptr); // Test aborts here if we didn't get a Frame
CHECK_EQUAL(false, i1->isNull());
f1->AddImage(i1);
// Check loaded image parameters
CHECK_EQUAL(i1->height(), f1->GetHeight());
CHECK_EQUAL(i1->width(), f1->GetWidth());
CHECK_EQUAL(true, f1->has_image_data);
}
TEST(Copy_Constructor)
{
// Create a dummy Frame
openshot::Frame f1(1, 800, 600, "#000000");
// Load an image
std::stringstream path;
path << TEST_MEDIA_PATH << "front.png";
std::shared_ptr<QImage> i1( new QImage(QString::fromStdString(path.str())) );
CHECK_EQUAL(false, i1->isNull());
// Add image to f1, then copy f1 to f2
f1.AddImage(i1);
Frame f2 = f1;
CHECK_EQUAL(f1.GetHeight(), f2.GetHeight());
CHECK_EQUAL(f1.GetWidth(), f2.GetWidth());
CHECK_EQUAL(f1.has_image_data, f2.has_image_data);
CHECK_EQUAL(f1.has_audio_data, f2.has_audio_data);
Fraction par1 = f1.GetPixelRatio();
Fraction par2 = f2.GetPixelRatio();
CHECK_EQUAL(par1.num, par2.num);
CHECK_EQUAL(par1.den, par2.den);
CHECK_EQUAL(f1.SampleRate(), f2.SampleRate());
CHECK_EQUAL(f1.GetAudioChannelsCount(), f2.GetAudioChannelsCount());
CHECK_EQUAL(f1.ChannelsLayout(), f2.ChannelsLayout());
CHECK_EQUAL(f1.GetBytes(), f2.GetBytes());
CHECK_EQUAL(f1.GetAudioSamplesCount(), f2.GetAudioSamplesCount());
}
} // SUITE(Frame_Tests)