Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: A few more Frame tests #446

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
12 changes: 6 additions & 6 deletions include/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ namespace openshot
* There are many ways to create an instance of an openshot::Frame:
* @code
*
* // Most basic: a blank frame (300x200 blank image, 48kHz audio silence)
* // Most basic: a blank frame (1x1 blank image, 44.2kHz audio silence)
musteresel marked this conversation as resolved.
Show resolved Hide resolved
* Frame();
*
* // Image only settings (48kHz audio silence)
* // Image only settings (44.2kHz audio silence)
* Frame(1, // Frame number
* 720, // Width of image
* 480, // Height of image
* "#000000" // HTML color code of background color
* );
*
* // Audio only (300x200 blank image)
* // Audio only (1x1 blank image)
* Frame(number, // Frame number
* 44100, // Sample rate of audio stream
* 2 // Number of audio channels
Expand Down Expand Up @@ -131,13 +131,13 @@ namespace openshot
bool has_image_data; ///< This frame has been loaded with pixel data


/// Constructor - blank frame (300x200 blank image, 48kHz audio silence)
/// Constructor - blank frame (1x1 blank image, 44.2kHz audio silence)
Frame();

/// Constructor - image only (48kHz audio silence)
/// Constructor - image only (44.2kHz audio silence)
Frame(int64_t number, int width, int height, std::string color);

/// Constructor - audio only (300x200 blank image)
/// Constructor - audio only (1x1 blank image)
Frame(int64_t number, int samples, int channels);

/// Constructor - image & audio
Expand Down
86 changes: 65 additions & 21 deletions tests/Frame_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,73 @@ 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
Frame f1;

// Check basic default parameters
CHECK_EQUAL(1, f1->GetHeight());
CHECK_EQUAL(1, f1->GetWidth());
CHECK_EQUAL(44100, f1->SampleRate());
CHECK_EQUAL(2, f1->GetAudioChannelsCount());
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);
CHECK_EQUAL(false, f1.has_image_data);
CHECK_EQUAL(false, f1.has_audio_data);
}

TEST(ImageOnly_Constructor)
{
Frame f(42, 100, 111, "#FAFBFC");

CHECK_EQUAL(100, f.GetWidth());
CHECK_EQUAL(111, f.GetHeight());
CHECK_EQUAL(44100, f.SampleRate());
CHECK_EQUAL(2, f.GetAudioChannelsCount());

CHECK_EQUAL(false, f.has_audio_data);
// CHECK_EQUAL(true, f.has_image_data); // TODO: This would be expected?
// CHECK(f.GetPixels(0)); // TODO: crashes
// CHECK(f.CheckPixel(0, 0, 0xFA, 0xFB, 0xFC, 0, 0));
}

TEST(AudioOnly_Constructor)
{
Frame f(42, 100, 1);
CHECK_EQUAL(1, f.GetHeight());
CHECK_EQUAL(1, f.GetWidth());
CHECK_EQUAL(44100, f.SampleRate());
CHECK_EQUAL(1, f.GetAudioChannelsCount());

// CHECK_EQUAL(true, f.has_audio_data); // TODO: This would be expected?
}

TEST(SetFrameNumber)
{
Frame f;
f.SetFrameNumber(42);
CHECK_EQUAL(42, f.number);
f.SetFrameNumber(21);
CHECK_EQUAL(21, f.number);
}

TEST(SampleRate_Change)
{
Frame f;
f.SampleRate(44800);
CHECK_EQUAL(44800, f.SampleRate());
// TODO: Test how this affects audio data?
}

// Calling GetImage() paints a blank frame, by default
std::shared_ptr<QImage> i1 = f1->GetImage();
TEST(GetImage)
{
Frame f1;
// Calling GetImage() paints a blank frame, by default.
// It also adds image data to the frame!
std::shared_ptr<QImage> i1 = f1.GetImage();

CHECK(i1 != nullptr);

CHECK_EQUAL(true,f1->has_image_data);
CHECK_EQUAL(false,f1->has_audio_data);
CHECK_EQUAL(true,f1.has_image_data);
CHECK_EQUAL(false,f1.has_audio_data);
}


Expand All @@ -78,8 +124,7 @@ TEST(Data_Access)

// Get first frame
std::shared_ptr<Frame> f1 = c1.GetFrame(1);

CHECK(f1 != nullptr);
REQUIRE CHECK(f1 != nullptr);

CHECK_EQUAL(1, f1->number);
CHECK_EQUAL(1280, f1->GetWidth());
Expand All @@ -90,22 +135,21 @@ TEST(Data_Access)
TEST(AddImage_QImage)
{
// Create a "blank" default Frame
std::shared_ptr<Frame> f1(new Frame());
Frame f1;

// 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);
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);
CHECK_EQUAL(i1->height(), f1.GetHeight());
CHECK_EQUAL(i1->width(), f1.GetWidth());
CHECK_EQUAL(true, f1.has_image_data);
}


Expand Down