forked from f3d-app/f3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request f3d-app#911 from mwestphal/improve_exclude_depreca…
…ted_ci Improve upon f3d-app#858
- Loading branch information
Showing
9 changed files
with
196 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import sys | ||
if sys.platform.startswith('win32'): | ||
import os | ||
os.add_dll_directory(sys.argv[1]) | ||
|
||
import f3d | ||
|
||
engine = f3d.engine(f3d.window.NATIVE_OFFSCREEN) | ||
window = engine.getWindow() | ||
window.setSize(300, 200) | ||
|
||
|
||
'''with background -> RGB image''' | ||
|
||
img = window.renderToImage() | ||
width = img.getWidth() | ||
height = img.getHeight() | ||
depth = img.getChannelCount() | ||
data = img.getData() | ||
|
||
assert width == window.getWidth() | ||
assert height == window.getHeight() | ||
assert depth == 3 | ||
assert isinstance(data, (bytes, bytearray)) | ||
assert len(data) == depth * width * height | ||
|
||
|
||
'''without background -> RGBA image''' | ||
|
||
img = window.renderToImage(True) | ||
width = img.getWidth() | ||
height = img.getHeight() | ||
depth = img.getChannelCount() | ||
data = img.getData() | ||
|
||
assert width == window.getWidth() | ||
assert height == window.getHeight() | ||
assert depth == 4 | ||
assert isinstance(data, (bytes, bytearray)) | ||
assert len(data) == depth * width * height | ||
|
||
|
||
'''set data back''' | ||
|
||
img.setData(data) | ||
assert img.getData() == data | ||
|
||
|
||
'''attempt to set partial data back''' | ||
|
||
try: | ||
img.setData(data[:-1]) | ||
assert False, 'expected exception' | ||
except ValueError: | ||
assert True |