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

Improve upon #858 #911

Merged
merged 8 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding a SDK Deprecated test
  • Loading branch information
mwestphal committed Jul 10, 2023
commit 33ca2c6ee3f3468146a7cf58647f48c633ea3322
4 changes: 4 additions & 0 deletions library/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ if(VTK_VERSION VERSION_GREATER 9.0.1)
TestSDKDynamicLightIntensity.cxx
TestSDKDynamicProperties.cxx
)
if(NOT F3D_EXCLUDE_DEPRECATED)
list(APPEND libf3dSDKTests_list
TestSDKImageDeprecated.cxx)
endif()
endif()

# Animation needs https://gitlab.kitware.com/vtk/vtk/-/merge_requests/7246
Expand Down
109 changes: 109 additions & 0 deletions library/testing/TestSDKImageDeprecated.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <image.h>

#include <algorithm>
#include <functional>
#include <iostream>
#include <random>

int TestSDKImageDeprecated(int argc, char* argv[])
{
constexpr unsigned int width = 64;
constexpr unsigned int height = 64;
constexpr unsigned int channels = 3;

std::vector<unsigned char> pixels(width * height * channels);

// fill with deterministic random values
// do not use std::uniform_int_distribution, it's not giving the same result on different
// platforms
std::mt19937 rand_generator;
std::generate(std::begin(pixels), std::end(pixels), [&]() { return rand_generator() % 256; });

f3d::image generated;
generated.setResolution(width, height).setChannelCount(channels).setData(pixels.data());
generated.save(std::string(argv[2]) + "TestSDKImageDeprecated.png");

// test exceptions
try
{
generated.save("/dummy/folder/img.png");

std::cerr << "An exception has not been thrown when saving to an incorrect path" << std::endl;
return EXIT_FAILURE;
}
catch (const f3d::image::write_exception&)
{
}

try
{
f3d::image img("/dummy/folder/img.png");

std::cerr << "An exception has not been thrown when reading an incorrect path" << std::endl;
return EXIT_FAILURE;
}
catch (const f3d::image::read_exception&)
{
}

f3d::image baseline(std::string(argv[1]) + "/baselines/TestSDKImage.png");

if (generated.getWidth() != width || generated.getHeight() != height)
{
std::cerr << "Image has wrong dimensions" << std::endl;
return EXIT_FAILURE;
}

if (generated.getChannelCount() != channels)
{
std::cerr << "Image has wrong number of channels" << std::endl;
return EXIT_FAILURE;
}

if (generated.getData() == nullptr)
{
std::cerr << "Image has no data" << std::endl;
return EXIT_FAILURE;
}

if (generated != baseline)
{
std::cerr << "Generated image is different from the baseline" << std::endl;
return EXIT_FAILURE;
}

// test operators
f3d::image imgCopy = generated; // copy constructor

if (imgCopy != generated)
{
std::cerr << "Copy constructor failed" << std::endl;
return EXIT_FAILURE;
}

imgCopy = baseline; // copy assignment

if (imgCopy != baseline)
{
std::cerr << "Copy assignment failed" << std::endl;
return EXIT_FAILURE;
}

f3d::image imgMove = std::move(imgCopy); // move constructor

if (imgMove != baseline)
{
std::cerr << "Move constructor failed" << std::endl;
return EXIT_FAILURE;
}

imgCopy = std::move(imgMove); // move assignment

if (imgCopy != baseline)
{
std::cerr << "Move assignment failed" << std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}