|
1 | 1 | // SPDX-License-Identifier: BSD-3-Clause |
2 | 2 | // Copyright Contributors to the OpenColorIO Project. |
3 | 3 |
|
4 | | - |
5 | 4 | #include <algorithm> |
6 | 5 |
|
7 | 6 | #include <pystring.h> |
|
14 | 13 |
|
15 | 14 | namespace OCIO = OCIO_NAMESPACE; |
16 | 15 |
|
17 | | - |
18 | 16 | #define STR(x) FIELD_STR(x) |
19 | 17 |
|
20 | 18 | #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"); |
22 | 21 | #endif // OCIO_SOURCE_DIR |
23 | 22 | static const std::string ociodir(STR(OCIO_SOURCE_DIR)); |
24 | 23 |
|
25 | 24 | // 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)}; |
29 | 27 | } |
30 | 28 |
|
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); |
72 | 69 | } |
73 | 70 |
|
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); |
91 | 89 | } |
92 | 90 |
|
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")); |
97 | 95 |
|
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"); |
100 | 98 |
|
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); |
105 | 104 | } |
106 | 105 |
|
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); |
126 | 126 | } |
127 | 127 |
|
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); |
148 | 149 | } |
149 | 150 |
|
150 | | -OCIO_ADD_TEST(Context, string_vars) |
151 | | -{ |
152 | | - // Test Context::addStringVars(). |
| 151 | +OCIO_ADD_TEST(Context, string_vars) { |
| 152 | + // Test Context::addStringVars(). |
153 | 153 |
|
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"); |
157 | 157 |
|
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"); |
161 | 161 |
|
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()); |
165 | 165 |
|
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)); |
168 | 168 |
|
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)); |
171 | 171 |
|
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)); |
174 | 174 | } |
0 commit comments