Skip to content

Commit 073cbd5

Browse files
committed
Move GPU LUT files into the tests dir
Instead of creating temporary LUT files for GPU tests, read them from the testdata directory instead. This removes the need to clean them up after each run. Signed-off-by: Ananth Bhaskararaman <[email protected]>
1 parent 6998d6d commit 073cbd5

15 files changed

+277
-402
lines changed

tests/cpu/Context_tests.cpp

Lines changed: 131 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright Contributors to the OpenColorIO Project.
33

4-
54
#include <algorithm>
65

76
#include <pystring.h>
@@ -14,161 +13,162 @@
1413

1514
namespace OCIO = OCIO_NAMESPACE;
1615

17-
1816
#define STR(x) FIELD_STR(x)
1917

2018
#ifndef OCIO_SOURCE_DIR
21-
static_assert(0, "OCIO_SOURCE_DIR should be defined by tests/cpu/CMakeLists.txt");
19+
static_assert(0,
20+
"OCIO_SOURCE_DIR should be defined by tests/cpu/CMakeLists.txt");
2221
#endif // OCIO_SOURCE_DIR
2322
static const std::string ociodir(STR(OCIO_SOURCE_DIR));
2423

2524
// Method to compare paths.
26-
std::string SanitizePath(const char* path)
27-
{
28-
return { pystring::os::path::normpath(path) };
25+
std::string SanitizePath(const char *path) {
26+
return {pystring::os::path::normpath(path)};
2927
}
3028

31-
OCIO_ADD_TEST(Context, search_paths)
32-
{
33-
OCIO::ContextRcPtr con = OCIO::Context::Create();
34-
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0);
35-
const std::string empty{ "" };
36-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), empty);
37-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(42)), empty);
38-
39-
con->addSearchPath(empty.c_str());
40-
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0);
41-
42-
const std::string first{ "First" };
43-
con->addSearchPath(first.c_str());
44-
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 1);
45-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), first);
46-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first);
47-
con->clearSearchPaths();
48-
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0);
49-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), empty);
50-
51-
const std::string second{ "Second" };
52-
const std::string firstSecond{ first + ":" + second };
53-
con->addSearchPath(first.c_str());
54-
con->addSearchPath(second.c_str());
55-
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2);
56-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), firstSecond);
57-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first);
58-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(1)), second);
59-
con->addSearchPath(empty.c_str());
60-
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2);
61-
62-
con->setSearchPath(first.c_str());
63-
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 1);
64-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), first);
65-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first);
66-
67-
con->setSearchPath(firstSecond.c_str());
68-
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2);
69-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), firstSecond);
70-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first);
71-
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(1)), second);
29+
OCIO_ADD_TEST(Context, search_paths) {
30+
OCIO::ContextRcPtr con = OCIO::Context::Create();
31+
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0);
32+
const std::string empty{""};
33+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), empty);
34+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(42)), empty);
35+
36+
con->addSearchPath(empty.c_str());
37+
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0);
38+
39+
const std::string first{"First"};
40+
con->addSearchPath(first.c_str());
41+
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 1);
42+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), first);
43+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first);
44+
con->clearSearchPaths();
45+
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0);
46+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), empty);
47+
48+
const std::string second{"Second"};
49+
const std::string firstSecond{first + ":" + second};
50+
con->addSearchPath(first.c_str());
51+
con->addSearchPath(second.c_str());
52+
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2);
53+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), firstSecond);
54+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first);
55+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(1)), second);
56+
con->addSearchPath(empty.c_str());
57+
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2);
58+
59+
con->setSearchPath(first.c_str());
60+
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 1);
61+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), first);
62+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first);
63+
64+
con->setSearchPath(firstSecond.c_str());
65+
OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2);
66+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), firstSecond);
67+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first);
68+
OCIO_CHECK_EQUAL(std::string(con->getSearchPath(1)), second);
7269
}
7370

74-
OCIO_ADD_TEST(Context, abs_path)
75-
{
76-
const std::string contextpath(ociodir + std::string("/src/OpenColorIO/Context.cpp"));
77-
78-
OCIO::ContextRcPtr con = OCIO::Context::Create();
79-
con->addSearchPath(ociodir.c_str());
80-
con->setStringVar("non_abs", "src/OpenColorIO/Context.cpp");
81-
con->setStringVar("is_abs", contextpath.c_str());
82-
83-
OCIO_CHECK_NO_THROW(con->resolveFileLocation("${non_abs}"));
84-
85-
OCIO_CHECK_ASSERT(strcmp(SanitizePath(con->resolveFileLocation("${non_abs}")).c_str(),
86-
SanitizePath(contextpath.c_str()).c_str()) == 0);
87-
88-
OCIO_CHECK_NO_THROW(con->resolveFileLocation("${is_abs}"));
89-
OCIO_CHECK_ASSERT(strcmp(con->resolveFileLocation("${is_abs}"),
90-
SanitizePath(contextpath.c_str()).c_str()) == 0);
71+
OCIO_ADD_TEST(Context, abs_path) {
72+
const std::string contextpath(ociodir +
73+
std::string("/src/OpenColorIO/Context.cpp"));
74+
75+
OCIO::ContextRcPtr con = OCIO::Context::Create();
76+
con->addSearchPath(ociodir.c_str());
77+
con->setStringVar("non_abs", "src/OpenColorIO/Context.cpp");
78+
con->setStringVar("is_abs", contextpath.c_str());
79+
80+
OCIO_CHECK_NO_THROW(con->resolveFileLocation("${non_abs}"));
81+
82+
OCIO_CHECK_ASSERT(
83+
strcmp(SanitizePath(con->resolveFileLocation("${non_abs}")).c_str(),
84+
SanitizePath(contextpath.c_str()).c_str()) == 0);
85+
86+
OCIO_CHECK_NO_THROW(con->resolveFileLocation("${is_abs}"));
87+
OCIO_CHECK_ASSERT(strcmp(con->resolveFileLocation("${is_abs}"),
88+
SanitizePath(contextpath.c_str()).c_str()) == 0);
9189
}
9290

93-
OCIO_ADD_TEST(Context, var_search_path)
94-
{
95-
OCIO::ContextRcPtr context = OCIO::Context::Create();
96-
const std::string contextpath(ociodir + std::string("/src/OpenColorIO/Context.cpp"));
91+
OCIO_ADD_TEST(Context, var_search_path) {
92+
OCIO::ContextRcPtr context = OCIO::Context::Create();
93+
const std::string contextpath(ociodir +
94+
std::string("/src/OpenColorIO/Context.cpp"));
9795

98-
context->setStringVar("SOURCE_DIR", ociodir.c_str());
99-
context->addSearchPath("${SOURCE_DIR}/src/OpenColorIO");
96+
context->setStringVar("SOURCE_DIR", ociodir.c_str());
97+
context->addSearchPath("${SOURCE_DIR}/src/OpenColorIO");
10098

101-
std::string resolvedSource;
102-
OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("Context.cpp"));
103-
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
104-
SanitizePath(contextpath.c_str()).c_str()) == 0);
99+
std::string resolvedSource;
100+
OCIO_CHECK_NO_THROW(resolvedSource =
101+
context->resolveFileLocation("Context.cpp"));
102+
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
103+
SanitizePath(contextpath.c_str()).c_str()) == 0);
105104
}
106105

107-
OCIO_ADD_TEST(Context, use_searchpaths)
108-
{
109-
OCIO::ContextRcPtr context = OCIO::Context::Create();
110-
111-
// Add 2 absolute search paths.
112-
const std::string searchPath1 = ociodir + "/src/OpenColorIO";
113-
const std::string searchPath2 = ociodir + "/tests/gpu";
114-
context->addSearchPath(searchPath1.c_str());
115-
context->addSearchPath(searchPath2.c_str());
116-
117-
std::string resolvedSource;
118-
OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("Context.cpp"));
119-
const std::string res1 = searchPath1 + "/Context.cpp";
120-
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
121-
SanitizePath(res1.c_str()).c_str()) == 0);
122-
OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUHelpers.h"));
123-
const std::string res2 = searchPath2 + "/GPUHelpers.h";
124-
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
125-
SanitizePath(res2.c_str()).c_str()) == 0);
106+
OCIO_ADD_TEST(Context, use_searchpaths) {
107+
OCIO::ContextRcPtr context = OCIO::Context::Create();
108+
109+
// Add 2 absolute search paths.
110+
const std::string searchPath1 = ociodir + "/src/OpenColorIO";
111+
const std::string searchPath2 = ociodir + "/tests/gpu";
112+
context->addSearchPath(searchPath1.c_str());
113+
context->addSearchPath(searchPath2.c_str());
114+
115+
std::string resolvedSource;
116+
OCIO_CHECK_NO_THROW(resolvedSource =
117+
context->resolveFileLocation("Context.cpp"));
118+
const std::string res1 = searchPath1 + "/Context.cpp";
119+
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
120+
SanitizePath(res1.c_str()).c_str()) == 0);
121+
OCIO_CHECK_NO_THROW(resolvedSource =
122+
context->resolveFileLocation("GPUUnitTest.h"));
123+
const std::string res2 = searchPath2 + "/GPUUnitTest.h";
124+
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
125+
SanitizePath(res2.c_str()).c_str()) == 0);
126126
}
127127

128-
OCIO_ADD_TEST(Context, use_searchpaths_workingdir)
129-
{
130-
OCIO::ContextRcPtr context = OCIO::Context::Create();
131-
132-
// Set working directory and add 2 relative search paths.
133-
const std::string searchPath1 = "src/OpenColorIO";
134-
const std::string searchPath2 = "tests/gpu";
135-
context->setWorkingDir(ociodir.c_str());
136-
context->addSearchPath(searchPath1.c_str());
137-
context->addSearchPath(searchPath2.c_str());
138-
139-
std::string resolvedSource;
140-
OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("Context.cpp"));
141-
const std::string res1 = ociodir + "/" + searchPath1 + "/Context.cpp";
142-
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
143-
SanitizePath(res1.c_str()).c_str()) == 0);
144-
OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUHelpers.h"));
145-
const std::string res2 = ociodir + "/" + searchPath2 + "/GPUHelpers.h";
146-
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
147-
SanitizePath(res2.c_str()).c_str()) == 0);
128+
OCIO_ADD_TEST(Context, use_searchpaths_workingdir) {
129+
OCIO::ContextRcPtr context = OCIO::Context::Create();
130+
131+
// Set working directory and add 2 relative search paths.
132+
const std::string searchPath1 = "src/OpenColorIO";
133+
const std::string searchPath2 = "tests/gpu";
134+
context->setWorkingDir(ociodir.c_str());
135+
context->addSearchPath(searchPath1.c_str());
136+
context->addSearchPath(searchPath2.c_str());
137+
138+
std::string resolvedSource;
139+
OCIO_CHECK_NO_THROW(resolvedSource =
140+
context->resolveFileLocation("Context.cpp"));
141+
const std::string res1 = ociodir + "/" + searchPath1 + "/Context.cpp";
142+
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
143+
SanitizePath(res1.c_str()).c_str()) == 0);
144+
OCIO_CHECK_NO_THROW(resolvedSource =
145+
context->resolveFileLocation("GPUUnitTest.h"));
146+
const std::string res2 = ociodir + "/" + searchPath2 + "/GPUUnitTest.h";
147+
OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(),
148+
SanitizePath(res2.c_str()).c_str()) == 0);
148149
}
149150

150-
OCIO_ADD_TEST(Context, string_vars)
151-
{
152-
// Test Context::addStringVars().
151+
OCIO_ADD_TEST(Context, string_vars) {
152+
// Test Context::addStringVars().
153153

154-
OCIO::ContextRcPtr ctx1 = OCIO::Context::Create();
155-
ctx1->setStringVar("var1", "val1");
156-
ctx1->setStringVar("var2", "val2");
154+
OCIO::ContextRcPtr ctx1 = OCIO::Context::Create();
155+
ctx1->setStringVar("var1", "val1");
156+
ctx1->setStringVar("var2", "val2");
157157

158-
OCIO::ContextRcPtr ctx2 = OCIO::Context::Create();
159-
ctx2->setStringVar("var1", "val11");
160-
ctx2->setStringVar("var3", "val3");
158+
OCIO::ContextRcPtr ctx2 = OCIO::Context::Create();
159+
ctx2->setStringVar("var1", "val11");
160+
ctx2->setStringVar("var3", "val3");
161161

162-
OCIO::ConstContextRcPtr const_ctx2 = ctx2;
163-
ctx1->addStringVars(const_ctx2);
164-
OCIO_REQUIRE_EQUAL(3, ctx1->getNumStringVars());
162+
OCIO::ConstContextRcPtr const_ctx2 = ctx2;
163+
ctx1->addStringVars(const_ctx2);
164+
OCIO_REQUIRE_EQUAL(3, ctx1->getNumStringVars());
165165

166-
OCIO_CHECK_EQUAL(std::string("var1"), ctx1->getStringVarNameByIndex(0));
167-
OCIO_CHECK_EQUAL(std::string("val11"), ctx1->getStringVarByIndex(0));
166+
OCIO_CHECK_EQUAL(std::string("var1"), ctx1->getStringVarNameByIndex(0));
167+
OCIO_CHECK_EQUAL(std::string("val11"), ctx1->getStringVarByIndex(0));
168168

169-
OCIO_CHECK_EQUAL(std::string("var2"), ctx1->getStringVarNameByIndex(1));
170-
OCIO_CHECK_EQUAL(std::string("val2"), ctx1->getStringVarByIndex(1));
169+
OCIO_CHECK_EQUAL(std::string("var2"), ctx1->getStringVarNameByIndex(1));
170+
OCIO_CHECK_EQUAL(std::string("val2"), ctx1->getStringVarByIndex(1));
171171

172-
OCIO_CHECK_EQUAL(std::string("var3"), ctx1->getStringVarNameByIndex(2));
173-
OCIO_CHECK_EQUAL(std::string("val3"), ctx1->getStringVarByIndex(2));
172+
OCIO_CHECK_EQUAL(std::string("var3"), ctx1->getStringVarNameByIndex(2));
173+
OCIO_CHECK_EQUAL(std::string("val3"), ctx1->getStringVarByIndex(2));
174174
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CSPLUTV100
2+
3D
3+
4+
2
5+
0.0 1.0
6+
0.0 1.0
7+
2
8+
0.0 1.0
9+
0.0 1.0
10+
2
11+
0.0 1.0
12+
0.0 1.0
13+
14+
2 2 2
15+
0.100000 0.100000 0.100000
16+
1.100000 0.100000 0.100000
17+
0.100000 1.100000 0.100000
18+
1.100000 1.100000 0.100000
19+
0.100000 0.100000 1.100000
20+
1.100000 0.100000 1.100000
21+
0.100000 1.100000 1.100000
22+
1.100000 1.100000 1.100000
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CSPLUTV100
2+
3D
3+
4+
2
5+
0.0 1.0
6+
0.0 1.0
7+
2
8+
0.0 1.0
9+
0.0 1.0
10+
2
11+
0.0 1.0
12+
0.0 1.0
13+
14+
2 2 2
15+
0.100000 0.100000 0.100000
16+
1.100000 0.100000 0.100000
17+
0.100000 1.100000 0.100000
18+
1.100000 1.100000 0.100000
19+
0.100000 0.100000 1.100000
20+
1.100000 0.100000 1.100000
21+
0.100000 1.100000 1.100000
22+
1.100000 1.100000 1.100000
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CSPLUTV100
2+
3D
3+
4+
2
5+
0.0 1.0
6+
0.0 1.0
7+
2
8+
0.0 1.0
9+
0.0 1.0
10+
2
11+
0.0 1.0
12+
0.0 1.0
13+
14+
2 2 2
15+
0.0 0.0 0.0
16+
0.0 0.0 0.0
17+
0.0 0.0 0.0
18+
0.0 0.0 0.0
19+
0.0 0.0 1.0
20+
0.0 0.0 1.0
21+
0.0 0.0 1.0
22+
0.0 0.0 1.0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CSPLUTV100
2+
3D
3+
4+
2
5+
0.0 1.0
6+
0.0 1.0
7+
2
8+
0.0 1.0
9+
0.0 1.0
10+
2
11+
0.0 1.0
12+
0.0 1.0
13+
14+
2 2 2
15+
0.0 0.0 0.0
16+
0.0 0.0 0.0
17+
0.0 0.0 0.0
18+
0.0 0.0 0.0
19+
0.0 1.0 0.0
20+
0.0 1.0 0.0
21+
0.0 1.0 0.0
22+
0.0 1.0 0.0

0 commit comments

Comments
 (0)