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#304 from mwestphal/window_doc_test
Add window testing Add window doc Add error ref param to image compare Improve TestSDKHelpers
- Loading branch information
Showing
14 changed files
with
189 additions
and
78 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
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 |
---|---|---|
@@ -1,26 +1,48 @@ | ||
#ifndef TestSDKHelpers_h | ||
#define TestSDKHelpers_h | ||
|
||
#include <filesystem> | ||
#include <iostream> | ||
|
||
class TestSDKHelpers | ||
{ | ||
public: | ||
static bool RenderTest(f3d::window& win, const std::string& baselinePath, | ||
const std::string& outputPath, const std::string& name, double threshold) | ||
const std::string& outputPath, const std::string& name, double threshold = 50, | ||
bool noBackground = false) | ||
{ | ||
if (baselinePath.empty() || outputPath.empty() || name.empty()) | ||
{ | ||
std::cerr << "A path or name is empty, aborting" << std::endl; | ||
return false; | ||
} | ||
|
||
std::string baseline = baselinePath + name + ".png"; | ||
std::string output = outputPath + name + ".png"; | ||
std::string diff = outputPath + name + ".diff.png"; | ||
|
||
f3d::image result = win.renderToImage(); | ||
if (!std::filesystem::exists(baseline)) | ||
{ | ||
win.renderToImage(noBackground).save(output); | ||
std::cerr << "Reference image " | ||
<< baseline + " does not exists, current rendering has been outputted to " << output | ||
<< std::endl; | ||
return false; | ||
} | ||
|
||
f3d::image result = win.renderToImage(noBackground); | ||
f3d::image diffRes; | ||
double error; | ||
|
||
bool ret = result.compare(f3d::image(baseline), diffRes, threshold); | ||
if (!ret) | ||
if (!result.compare(f3d::image(baseline), diffRes, threshold, error)) | ||
{ | ||
std::cerr << "Current rendering difference with reference image: " << error | ||
<< " is higher than the threshold of " << threshold << std::endl; | ||
result.save(output); | ||
diffRes.save(diff); | ||
return false; | ||
} | ||
return ret; | ||
return true; | ||
} | ||
}; | ||
#endif |
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,24 @@ | ||
#include <engine.h> | ||
#include <options.h> | ||
#include <window.h> | ||
|
||
#include "TestSDKHelpers.h" | ||
|
||
int TestSDKWindowStandard(int argc, char* argv[]) | ||
{ | ||
f3d::engine eng(f3d::engine::CREATE_WINDOW); | ||
f3d::window& win = eng.getWindow(); | ||
win.setWindowName("Test"); | ||
|
||
f3d::options& options = eng.getOptions(); | ||
options.set("resolution", { 300, 300 }) | ||
.set("background-color", { 0.8, 0.2, 0.9 }) | ||
.set("verbose", true); | ||
win.update(); | ||
|
||
// Use a higher threshold as background difference can be strong with mesa | ||
return TestSDKHelpers::RenderTest(win, std::string(argv[1]) + "baselines/", std::string(argv[2]), | ||
"TestSDKWindowStandard", 150) | ||
? EXIT_SUCCESS | ||
: EXIT_FAILURE; | ||
} |
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
Oops, something went wrong.