-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor fixes to
TestSDKHelpers.h
(#1614)
* add missing includes * turn class into namespace
- Loading branch information
Showing
1 changed file
with
46 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,65 @@ | ||
#ifndef TestSDKHelpers_h | ||
#define TestSDKHelpers_h | ||
|
||
#include <image.h> | ||
#include <window.h> | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
class TestSDKHelpers | ||
namespace TestSDKHelpers | ||
{ | ||
public: | ||
static bool RenderTest(const f3d::image& img, const std::string& baselinePath, | ||
const std::string& outputPath, const std::string& name, double threshold = 0.05) | ||
{ | ||
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::ifstream file(baseline.c_str()); | ||
if (!file.good()) | ||
{ | ||
img.save(output); | ||
std::cerr << "Reference image " | ||
<< baseline + " does not exist, current rendering has been outputted to " | ||
<< output << std::endl; | ||
return false; | ||
} | ||
} | ||
static bool RenderTest(const f3d::image& img, const std::string& baselinePath, | ||
const std::string& outputPath, const std::string& name, double threshold = 0.05) | ||
{ | ||
if (baselinePath.empty() || outputPath.empty() || name.empty()) | ||
{ | ||
std::cerr << "A path or name is empty, aborting" << std::endl; | ||
return false; | ||
} | ||
|
||
f3d::image reference(baseline); | ||
double error; | ||
std::string baseline = baselinePath + name + ".png"; | ||
std::string output = outputPath + name + ".png"; | ||
|
||
if (!img.compare(reference, threshold, error)) | ||
{ | ||
std::ifstream file(baseline.c_str()); | ||
if (!file.good()) | ||
{ | ||
std::cerr << "Current rendering difference with reference image: " << error | ||
<< " is higher than the threshold of " << threshold << std::endl; | ||
std::cerr << "Result resolution: " << img.getWidth() << "x" << img.getHeight() << std::endl; | ||
std::cerr << "Reference resolution: " << reference.getWidth() << "x" << reference.getHeight() | ||
<< std::endl; | ||
img.save(output); | ||
std::cerr << "Reference image " | ||
<< baseline + " does not exist, current rendering has been outputted to " << output | ||
<< std::endl; | ||
return false; | ||
} | ||
|
||
std::cout << "Successful render test against " << baseline + " with an error of " << error | ||
<< std::endl; | ||
return true; | ||
} | ||
|
||
static bool RenderTest(f3d::window& win, const std::string& baselinePath, | ||
const std::string& outputPath, const std::string& name, double threshold = 50, | ||
bool noBackground = false) | ||
f3d::image reference(baseline); | ||
double error; | ||
|
||
if (!img.compare(reference, threshold, error)) | ||
{ | ||
return TestSDKHelpers::RenderTest( | ||
win.renderToImage(noBackground), baselinePath, outputPath, name, threshold); | ||
std::cerr << "Current rendering difference with reference image: " << error | ||
<< " is higher than the threshold of " << threshold << std::endl; | ||
std::cerr << "Result resolution: " << img.getWidth() << "x" << img.getHeight() << std::endl; | ||
std::cerr << "Reference resolution: " << reference.getWidth() << "x" << reference.getHeight() | ||
<< std::endl; | ||
img.save(output); | ||
return false; | ||
} | ||
}; | ||
|
||
std::cout << "Successful render test against " << baseline + " with an error of " << error | ||
<< std::endl; | ||
return true; | ||
} | ||
|
||
static bool RenderTest(f3d::window& win, const std::string& baselinePath, | ||
const std::string& outputPath, const std::string& name, double threshold = 50, | ||
bool noBackground = false) | ||
{ | ||
return TestSDKHelpers::RenderTest( | ||
win.renderToImage(noBackground), baselinePath, outputPath, name, threshold); | ||
} | ||
|
||
} | ||
#endif |