Commit 76c61031 authored by Matt Pharr's avatar Matt Pharr Committed by Jan Scheffczyk

Pass temp file paths through a path remapping function in tests.

This is a no-op here, but allows a single point of modification in an
environment where tests aren't allowed to write to $CWD.
parent 1584180e
......@@ -32,6 +32,8 @@
using namespace pbrt;
static std::string inTestDir(const std::string &path) { return path; }
struct TestScene {
std::shared_ptr<Scene> scene;
std::string description;
......@@ -49,7 +51,7 @@ void PrintTo(const TestIntegrator &tr, ::std::ostream *os) {
*os << tr.description;
}
void CheckSceneAverage(const char *filename, float expected) {
void CheckSceneAverage(const std::string &filename, float expected) {
Point2i resolution;
std::unique_ptr<RGBSpectrum[]> image = ReadImage(filename, &resolution);
ASSERT_TRUE(image.get() != nullptr);
......@@ -276,7 +278,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.);
std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera =
std::make_shared<PerspectiveCamera>(
identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1.,
......@@ -296,7 +298,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.);
std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera =
std::make_shared<OrthographicCamera>(
identity, Bounds2f(Point2f(-.1, -.1), Point2f(.1, .1)), 0.,
......@@ -316,7 +318,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.);
std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera =
std::make_shared<PerspectiveCamera>(
identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1.,
......@@ -335,7 +337,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.);
std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera =
std::make_shared<OrthographicCamera>(
identity, Bounds2f(Point2f(-.1, -.1), Point2f(.1, .1)), 0.,
......@@ -356,7 +358,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.);
std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera =
std::make_shared<PerspectiveCamera>(
identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1.,
......@@ -376,7 +378,7 @@ std::vector<TestIntegrator> GetIntegrators() {
for (auto sampler : GetSamplers(Bounds2i(Point2i(0,0), resolution))) {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film = new Film(resolution, Bounds2f(Point2f(0,0), Point2f(1,1)),
std::move(filter), 1., "test.exr", 1.);
std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera = std::make_shared<OrthographicCamera>(
identity, Bounds2f(Point2f(-.1,-.1), Point2f(.1,.1)), 0., 1.,
0., 10., film, nullptr);
......@@ -394,7 +396,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.);
std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera =
std::make_shared<PerspectiveCamera>(
identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1.,
......@@ -422,7 +424,7 @@ TEST_P(RenderTest, RadianceMatches) {
const TestIntegrator &tr = GetParam();
tr.integrator->Render(*tr.scene.scene);
CheckSceneAverage("test.exr", tr.scene.expected);
CheckSceneAverage(inTestDir("test.exr"), tr.scene.expected);
// The SpatialLightDistribution class keeps a per-thread cache that
// must be cleared out between test runs. In turn, this means that we
// must delete the Integrator here in order to make sure that its
......@@ -431,7 +433,7 @@ TEST_P(RenderTest, RadianceMatches) {
pbrtCleanup();
EXPECT_EQ(0, remove("test.exr"));
EXPECT_EQ(0, remove(inTestDir("test.exr").c_str()));
}
INSTANTIATE_TEST_CASE_P(AnalyticTestScenes, RenderTest,
......
......@@ -17290,14 +17290,16 @@ static const uint8_t fourierData[] = {
0x61, 0x6c, 0x73, 0x65, 0xa, 0x7d,
};
static std::string inTestDir(const std::string &path) { return path; }
// Small smoke test to make sure we get back reasonable values for a few known
// inputs.
TEST(BSDFs, Fourier) {
// Write the serialized data to a temporary file
// TODO: improve FourierBSDFTable to also be able to deserialize from a
// given array.
const char *filename = "fourier.out";
FILE *f = fopen(filename, "wb");
std::string filename = inTestDir("fourier.out");
FILE *f = fopen(filename.c_str(), "wb");
ASSERT_TRUE(f);
int sz = sizeof(fourierData);
......@@ -17333,5 +17335,5 @@ TEST(BSDFs, Fourier) {
EXPECT_LT(err(w.z, 0.572980), .001);
// Cleanup.
EXPECT_EQ(0, remove(filename));
EXPECT_EQ(0, remove(filename.c_str()));
}
......@@ -7,6 +7,8 @@
using namespace pbrt;
static std::string inTestDir(const std::string &path) { return path; }
static void TestRoundTrip(const char *fn, bool gamma) {
Point2i res(16, 29);
std::vector<Float> pixels(3 * res[0] * res[1]);
......@@ -18,10 +20,11 @@ static void TestRoundTrip(const char *fn, bool gamma) {
pixels[offset + 2] = -1.5f;
}
WriteImage(fn, &pixels[0], Bounds2i({0, 0}, res), res);
std::string filename = inTestDir(fn);
WriteImage(filename, &pixels[0], Bounds2i({0, 0}, res), res);
Point2i readRes;
auto readPixels = ReadImage(fn, &readRes);
auto readPixels = ReadImage(filename, &readRes);
ASSERT_TRUE(readPixels.get() != nullptr);
EXPECT_EQ(readRes, res);
......@@ -36,13 +39,13 @@ static void TestRoundTrip(const char *fn, bool gamma) {
float wrote = pixels[3 * (y * res[0] + x) + c];
float delta = wrote - rgb[c];
if (HasExtension(fn, "pfm")) {
if (HasExtension(filename, "pfm")) {
// Everything should come out exact.
EXPECT_EQ(0, delta) << fn << ":(" << x << ", " << y
EXPECT_EQ(0, delta) << filename << ":(" << x << ", " << y
<< ") c = " << c << " wrote " << wrote
<< ", read " << rgb[c]
<< ", delta = " << delta;
} else if (HasExtension(fn, "exr")) {
} else if (HasExtension(filename, "exr")) {
if (c == 2)
// -1.5 is exactly representable as a float.
EXPECT_EQ(0, delta) << "(" << x << ", " << y
......@@ -51,7 +54,7 @@ static void TestRoundTrip(const char *fn, bool gamma) {
<< ", delta = " << delta;
else
EXPECT_LT(std::abs(delta), .001)
<< fn << ":(" << x << ", " << y << ") c = " << c
<< filename << ":(" << x << ", " << y << ") c = " << c
<< " wrote " << wrote << ", read " << rgb[c]
<< ", delta = " << delta;
} else {
......@@ -66,7 +69,7 @@ static void TestRoundTrip(const char *fn, bool gamma) {
// Allow a fair amount of slop, since there's an sRGB
// conversion before quantization to 8-bits...
EXPECT_LT(std::abs(delta), .02)
<< fn << ":(" << x << ", " << y << ") c = " << c
<< filename << ":(" << x << ", " << y << ") c = " << c
<< " wrote " << wrote << ", read " << rgb[c]
<< ", delta = " << delta;
}
......@@ -74,7 +77,7 @@ static void TestRoundTrip(const char *fn, bool gamma) {
}
// Clean up
EXPECT_EQ(0, remove(fn));
EXPECT_EQ(0, remove(filename.c_str()));
}
TEST(ImageIO, RoundTripEXR) { TestRoundTrip("out.exr", false); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment