diff --git a/tests/cpu/Context_tests.cpp b/tests/cpu/Context_tests.cpp index c8d4052ffd..8796d05c01 100644 --- a/tests/cpu/Context_tests.cpp +++ b/tests/cpu/Context_tests.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright Contributors to the OpenColorIO Project. - #include #include @@ -14,161 +13,162 @@ namespace OCIO = OCIO_NAMESPACE; - #define STR(x) FIELD_STR(x) #ifndef OCIO_SOURCE_DIR -static_assert(0, "OCIO_SOURCE_DIR should be defined by tests/cpu/CMakeLists.txt"); +static_assert(0, + "OCIO_SOURCE_DIR should be defined by tests/cpu/CMakeLists.txt"); #endif // OCIO_SOURCE_DIR static const std::string ociodir(STR(OCIO_SOURCE_DIR)); // Method to compare paths. -std::string SanitizePath(const char* path) -{ - return { pystring::os::path::normpath(path) }; +std::string SanitizePath(const char *path) { + return {pystring::os::path::normpath(path)}; } -OCIO_ADD_TEST(Context, search_paths) -{ - OCIO::ContextRcPtr con = OCIO::Context::Create(); - OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0); - const std::string empty{ "" }; - OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), empty); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath(42)), empty); - - con->addSearchPath(empty.c_str()); - OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0); - - const std::string first{ "First" }; - con->addSearchPath(first.c_str()); - OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 1); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), first); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first); - con->clearSearchPaths(); - OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), empty); - - const std::string second{ "Second" }; - const std::string firstSecond{ first + ":" + second }; - con->addSearchPath(first.c_str()); - con->addSearchPath(second.c_str()); - OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), firstSecond); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath(1)), second); - con->addSearchPath(empty.c_str()); - OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2); - - con->setSearchPath(first.c_str()); - OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 1); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), first); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first); - - con->setSearchPath(firstSecond.c_str()); - OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), firstSecond); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first); - OCIO_CHECK_EQUAL(std::string(con->getSearchPath(1)), second); +OCIO_ADD_TEST(Context, search_paths) { + OCIO::ContextRcPtr con = OCIO::Context::Create(); + OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0); + const std::string empty{""}; + OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), empty); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath(42)), empty); + + con->addSearchPath(empty.c_str()); + OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0); + + const std::string first{"First"}; + con->addSearchPath(first.c_str()); + OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 1); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), first); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first); + con->clearSearchPaths(); + OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 0); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), empty); + + const std::string second{"Second"}; + const std::string firstSecond{first + ":" + second}; + con->addSearchPath(first.c_str()); + con->addSearchPath(second.c_str()); + OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), firstSecond); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath(1)), second); + con->addSearchPath(empty.c_str()); + OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2); + + con->setSearchPath(first.c_str()); + OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 1); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), first); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first); + + con->setSearchPath(firstSecond.c_str()); + OCIO_CHECK_EQUAL(con->getNumSearchPaths(), 2); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath()), firstSecond); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath(0)), first); + OCIO_CHECK_EQUAL(std::string(con->getSearchPath(1)), second); } -OCIO_ADD_TEST(Context, abs_path) -{ - const std::string contextpath(ociodir + std::string("/src/OpenColorIO/Context.cpp")); - - OCIO::ContextRcPtr con = OCIO::Context::Create(); - con->addSearchPath(ociodir.c_str()); - con->setStringVar("non_abs", "src/OpenColorIO/Context.cpp"); - con->setStringVar("is_abs", contextpath.c_str()); - - OCIO_CHECK_NO_THROW(con->resolveFileLocation("${non_abs}")); - - OCIO_CHECK_ASSERT(strcmp(SanitizePath(con->resolveFileLocation("${non_abs}")).c_str(), - SanitizePath(contextpath.c_str()).c_str()) == 0); - - OCIO_CHECK_NO_THROW(con->resolveFileLocation("${is_abs}")); - OCIO_CHECK_ASSERT(strcmp(con->resolveFileLocation("${is_abs}"), - SanitizePath(contextpath.c_str()).c_str()) == 0); +OCIO_ADD_TEST(Context, abs_path) { + const std::string contextpath(ociodir + + std::string("/src/OpenColorIO/Context.cpp")); + + OCIO::ContextRcPtr con = OCIO::Context::Create(); + con->addSearchPath(ociodir.c_str()); + con->setStringVar("non_abs", "src/OpenColorIO/Context.cpp"); + con->setStringVar("is_abs", contextpath.c_str()); + + OCIO_CHECK_NO_THROW(con->resolveFileLocation("${non_abs}")); + + OCIO_CHECK_ASSERT( + strcmp(SanitizePath(con->resolveFileLocation("${non_abs}")).c_str(), + SanitizePath(contextpath.c_str()).c_str()) == 0); + + OCIO_CHECK_NO_THROW(con->resolveFileLocation("${is_abs}")); + OCIO_CHECK_ASSERT(strcmp(con->resolveFileLocation("${is_abs}"), + SanitizePath(contextpath.c_str()).c_str()) == 0); } -OCIO_ADD_TEST(Context, var_search_path) -{ - OCIO::ContextRcPtr context = OCIO::Context::Create(); - const std::string contextpath(ociodir + std::string("/src/OpenColorIO/Context.cpp")); +OCIO_ADD_TEST(Context, var_search_path) { + OCIO::ContextRcPtr context = OCIO::Context::Create(); + const std::string contextpath(ociodir + + std::string("/src/OpenColorIO/Context.cpp")); - context->setStringVar("SOURCE_DIR", ociodir.c_str()); - context->addSearchPath("${SOURCE_DIR}/src/OpenColorIO"); + context->setStringVar("SOURCE_DIR", ociodir.c_str()); + context->addSearchPath("${SOURCE_DIR}/src/OpenColorIO"); - std::string resolvedSource; - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("Context.cpp")); - OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), - SanitizePath(contextpath.c_str()).c_str()) == 0); + std::string resolvedSource; + OCIO_CHECK_NO_THROW(resolvedSource = + context->resolveFileLocation("Context.cpp")); + OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), + SanitizePath(contextpath.c_str()).c_str()) == 0); } -OCIO_ADD_TEST(Context, use_searchpaths) -{ - OCIO::ContextRcPtr context = OCIO::Context::Create(); - - // Add 2 absolute search paths. - const std::string searchPath1 = ociodir + "/src/OpenColorIO"; - const std::string searchPath2 = ociodir + "/tests/gpu"; - context->addSearchPath(searchPath1.c_str()); - context->addSearchPath(searchPath2.c_str()); - - std::string resolvedSource; - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("Context.cpp")); - const std::string res1 = searchPath1 + "/Context.cpp"; - OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), - SanitizePath(res1.c_str()).c_str()) == 0); - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUHelpers.h")); - const std::string res2 = searchPath2 + "/GPUHelpers.h"; - OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), - SanitizePath(res2.c_str()).c_str()) == 0); +OCIO_ADD_TEST(Context, use_searchpaths) { + OCIO::ContextRcPtr context = OCIO::Context::Create(); + + // Add 2 absolute search paths. + const std::string searchPath1 = ociodir + "/src/OpenColorIO"; + const std::string searchPath2 = ociodir + "/tests/gpu"; + context->addSearchPath(searchPath1.c_str()); + context->addSearchPath(searchPath2.c_str()); + + std::string resolvedSource; + OCIO_CHECK_NO_THROW(resolvedSource = + context->resolveFileLocation("Context.cpp")); + const std::string res1 = searchPath1 + "/Context.cpp"; + OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), + SanitizePath(res1.c_str()).c_str()) == 0); + OCIO_CHECK_NO_THROW(resolvedSource = + context->resolveFileLocation("GPUUnitTest.h")); + const std::string res2 = searchPath2 + "/GPUUnitTest.h"; + OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), + SanitizePath(res2.c_str()).c_str()) == 0); } -OCIO_ADD_TEST(Context, use_searchpaths_workingdir) -{ - OCIO::ContextRcPtr context = OCIO::Context::Create(); - - // Set working directory and add 2 relative search paths. - const std::string searchPath1 = "src/OpenColorIO"; - const std::string searchPath2 = "tests/gpu"; - context->setWorkingDir(ociodir.c_str()); - context->addSearchPath(searchPath1.c_str()); - context->addSearchPath(searchPath2.c_str()); - - std::string resolvedSource; - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("Context.cpp")); - const std::string res1 = ociodir + "/" + searchPath1 + "/Context.cpp"; - OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), - SanitizePath(res1.c_str()).c_str()) == 0); - OCIO_CHECK_NO_THROW(resolvedSource = context->resolveFileLocation("GPUHelpers.h")); - const std::string res2 = ociodir + "/" + searchPath2 + "/GPUHelpers.h"; - OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), - SanitizePath(res2.c_str()).c_str()) == 0); +OCIO_ADD_TEST(Context, use_searchpaths_workingdir) { + OCIO::ContextRcPtr context = OCIO::Context::Create(); + + // Set working directory and add 2 relative search paths. + const std::string searchPath1 = "src/OpenColorIO"; + const std::string searchPath2 = "tests/gpu"; + context->setWorkingDir(ociodir.c_str()); + context->addSearchPath(searchPath1.c_str()); + context->addSearchPath(searchPath2.c_str()); + + std::string resolvedSource; + OCIO_CHECK_NO_THROW(resolvedSource = + context->resolveFileLocation("Context.cpp")); + const std::string res1 = ociodir + "/" + searchPath1 + "/Context.cpp"; + OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), + SanitizePath(res1.c_str()).c_str()) == 0); + OCIO_CHECK_NO_THROW(resolvedSource = + context->resolveFileLocation("GPUUnitTest.h")); + const std::string res2 = ociodir + "/" + searchPath2 + "/GPUUnitTest.h"; + OCIO_CHECK_ASSERT(strcmp(SanitizePath(resolvedSource.c_str()).c_str(), + SanitizePath(res2.c_str()).c_str()) == 0); } -OCIO_ADD_TEST(Context, string_vars) -{ - // Test Context::addStringVars(). +OCIO_ADD_TEST(Context, string_vars) { + // Test Context::addStringVars(). - OCIO::ContextRcPtr ctx1 = OCIO::Context::Create(); - ctx1->setStringVar("var1", "val1"); - ctx1->setStringVar("var2", "val2"); + OCIO::ContextRcPtr ctx1 = OCIO::Context::Create(); + ctx1->setStringVar("var1", "val1"); + ctx1->setStringVar("var2", "val2"); - OCIO::ContextRcPtr ctx2 = OCIO::Context::Create(); - ctx2->setStringVar("var1", "val11"); - ctx2->setStringVar("var3", "val3"); + OCIO::ContextRcPtr ctx2 = OCIO::Context::Create(); + ctx2->setStringVar("var1", "val11"); + ctx2->setStringVar("var3", "val3"); - OCIO::ConstContextRcPtr const_ctx2 = ctx2; - ctx1->addStringVars(const_ctx2); - OCIO_REQUIRE_EQUAL(3, ctx1->getNumStringVars()); + OCIO::ConstContextRcPtr const_ctx2 = ctx2; + ctx1->addStringVars(const_ctx2); + OCIO_REQUIRE_EQUAL(3, ctx1->getNumStringVars()); - OCIO_CHECK_EQUAL(std::string("var1"), ctx1->getStringVarNameByIndex(0)); - OCIO_CHECK_EQUAL(std::string("val11"), ctx1->getStringVarByIndex(0)); + OCIO_CHECK_EQUAL(std::string("var1"), ctx1->getStringVarNameByIndex(0)); + OCIO_CHECK_EQUAL(std::string("val11"), ctx1->getStringVarByIndex(0)); - OCIO_CHECK_EQUAL(std::string("var2"), ctx1->getStringVarNameByIndex(1)); - OCIO_CHECK_EQUAL(std::string("val2"), ctx1->getStringVarByIndex(1)); + OCIO_CHECK_EQUAL(std::string("var2"), ctx1->getStringVarNameByIndex(1)); + OCIO_CHECK_EQUAL(std::string("val2"), ctx1->getStringVarByIndex(1)); - OCIO_CHECK_EQUAL(std::string("var3"), ctx1->getStringVarNameByIndex(2)); - OCIO_CHECK_EQUAL(std::string("val3"), ctx1->getStringVarByIndex(2)); + OCIO_CHECK_EQUAL(std::string("var3"), ctx1->getStringVarNameByIndex(2)); + OCIO_CHECK_EQUAL(std::string("val3"), ctx1->getStringVarByIndex(2)); } diff --git a/tests/data/files/Lut3DOp_arbitrary_using_CSP_file.csp b/tests/data/files/Lut3DOp_arbitrary_using_CSP_file.csp new file mode 100644 index 0000000000..7babf7c08b --- /dev/null +++ b/tests/data/files/Lut3DOp_arbitrary_using_CSP_file.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.100000 0.100000 0.100000 +1.100000 0.100000 0.100000 +0.100000 1.100000 0.100000 +1.100000 1.100000 0.100000 +0.100000 0.100000 1.100000 +1.100000 0.100000 1.100000 +0.100000 1.100000 1.100000 +1.100000 1.100000 1.100000 diff --git a/tests/data/files/Lut3DOp_arbitrary_using_CSP_file_legacy_shader.csp b/tests/data/files/Lut3DOp_arbitrary_using_CSP_file_legacy_shader.csp new file mode 100644 index 0000000000..7babf7c08b --- /dev/null +++ b/tests/data/files/Lut3DOp_arbitrary_using_CSP_file_legacy_shader.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.100000 0.100000 0.100000 +1.100000 0.100000 0.100000 +0.100000 1.100000 0.100000 +1.100000 1.100000 0.100000 +0.100000 0.100000 1.100000 +1.100000 0.100000 1.100000 +0.100000 1.100000 1.100000 +1.100000 1.100000 1.100000 diff --git a/tests/data/files/Lut3DOp_blue_only_using_CSP_file_legacy_shader.csp b/tests/data/files/Lut3DOp_blue_only_using_CSP_file_legacy_shader.csp new file mode 100644 index 0000000000..e9f68bee8c --- /dev/null +++ b/tests/data/files/Lut3DOp_blue_only_using_CSP_file_legacy_shader.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 1.0 +0.0 0.0 1.0 +0.0 0.0 1.0 +0.0 0.0 1.0 diff --git a/tests/data/files/Lut3DOp_green_only_using_CSP_file_legacy_shader.csp b/tests/data/files/Lut3DOp_green_only_using_CSP_file_legacy_shader.csp new file mode 100644 index 0000000000..e62fa8fce6 --- /dev/null +++ b/tests/data/files/Lut3DOp_green_only_using_CSP_file_legacy_shader.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 +0.0 1.0 0.0 diff --git a/tests/data/files/Lut3DOp_red_only_using_CSP_file_legacy_shader.csp b/tests/data/files/Lut3DOp_red_only_using_CSP_file_legacy_shader.csp new file mode 100644 index 0000000000..7a08c38d81 --- /dev/null +++ b/tests/data/files/Lut3DOp_red_only_using_CSP_file_legacy_shader.csp @@ -0,0 +1,22 @@ +CSPLUTV100 +3D + +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 +2 +0.0 1.0 +0.0 1.0 + +2 2 2 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 +1.0 0.0 0.0 diff --git a/tests/gpu/CDLOp_test.cpp b/tests/gpu/CDLOp_test.cpp index 9f32d0d42a..ddf1b43eeb 100644 --- a/tests/gpu/CDLOp_test.cpp +++ b/tests/gpu/CDLOp_test.cpp @@ -9,7 +9,6 @@ #include #include "GPUUnitTest.h" -#include "GPUHelpers.h" namespace OCIO = OCIO_NAMESPACE; diff --git a/tests/gpu/CMakeLists.txt b/tests/gpu/CMakeLists.txt index 4e16243bfd..b525df8078 100644 --- a/tests/gpu/CMakeLists.txt +++ b/tests/gpu/CMakeLists.txt @@ -12,7 +12,6 @@ set(SOURCES ECOp_test.cpp FixedFunctionOp_test.cpp GammaOp_test.cpp - GPUHelpers.cpp GPUUnitTest.cpp GradingPrimaryOp_test.cpp GradingRGBCurveOp_test.cpp @@ -26,7 +25,7 @@ set(SOURCES add_executable(test_gpu_exec ${SOURCES}) -set_target_properties(test_gpu_exec PROPERTIES +set_target_properties(test_gpu_exec PROPERTIES COMPILE_OPTIONS "${PLATFORM_COMPILE_OPTIONS}" LINK_OPTIONS "${PLATFORM_LINK_OPTIONS}" ) diff --git a/tests/gpu/GPUHelpers.cpp b/tests/gpu/GPUHelpers.cpp deleted file mode 100644 index 317e772461..0000000000 --- a/tests/gpu/GPUHelpers.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright Contributors to the OpenColorIO Project. - - -#include -#include - -#if !defined(_WIN32) -#include -#include -#include -#endif - -#include - -#include "GPUHelpers.h" - -namespace OCIO = OCIO_NAMESPACE; - - -// TODO: Make OCIO::Platform::CreateTempFilename() public so it could be used here. - -std::string createTempFile(const std::string& fileExt, const std::string& fileContent) -{ - // Note: because of security issue, tmpnam could not be used - - std::string filename; - -#ifdef _WIN32 - - char tmpFilename[L_tmpnam]; - if(tmpnam_s(tmpFilename)) - { - throw OCIO::Exception("Could not create a temporary file"); - } - - // Note that when a file name is pre-pended with a backslash and no path information, such as \fname21, this - // indicates that the name is valid for the current working directory. - filename = tmpFilename[0] == '\\' ? tmpFilename + 1 : tmpFilename; - filename += fileExt; - -#else - - std::stringstream ss; - ss << "/tmp/ocio"; - ss << std::rand(); - ss << fileExt; - - filename = ss.str(); - -#endif - - std::ofstream ofs(filename.c_str(), std::ios_base::out); - ofs << fileContent; - ofs.close(); - - return filename; -} diff --git a/tests/gpu/GPUHelpers.h b/tests/gpu/GPUHelpers.h deleted file mode 100644 index e49be0e1d3..0000000000 --- a/tests/gpu/GPUHelpers.h +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright Contributors to the OpenColorIO Project. - - -#ifndef OPENCOLORIO_GPU_HELPERS_H -#define OPENCOLORIO_GPU_HELPERS_H - - -#include - -// FIXME: Duplicate function implemented in `src/OpenColorIO/Platform.h and cpp`. -// Implement a function or class for temporary file creation useable by all tests. -std::string createTempFile(const std::string& fileExt, const std::string& fileContent); - - -#endif \ No newline at end of file diff --git a/tests/gpu/GPUUnitTest.cpp b/tests/gpu/GPUUnitTest.cpp index 07b727f034..0a0cc3f590 100644 --- a/tests/gpu/GPUUnitTest.cpp +++ b/tests/gpu/GPUUnitTest.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -333,11 +332,11 @@ namespace OCIO::ConstProcessorRcPtr & processor = test->getProcessor(); OCIO::GpuShaderDescRcPtr & shaderDesc = test->getShaderDesc(); - + OCIO::ConstGPUProcessorRcPtr gpu; if (test->isLegacyShader()) { - gpu = processor->getOptimizedLegacyGPUProcessor(OCIO::OPTIMIZATION_DEFAULT, + gpu = processor->getOptimizedLegacyGPUProcessor(OCIO::OPTIMIZATION_DEFAULT, test->getLegacyShaderLutEdge()); } else @@ -575,7 +574,7 @@ int main(int argc, const char ** argv) // Step 1: Initialize the graphic library engines. OCIO::OglAppRcPtr app; - + try { if(useMetalRenderer) diff --git a/tests/gpu/GPUUnitTest.h b/tests/gpu/GPUUnitTest.h index 967325c943..3782b9a9bd 100644 --- a/tests/gpu/GPUUnitTest.h +++ b/tests/gpu/GPUUnitTest.h @@ -20,7 +20,7 @@ using OCIOTestFuncCallback = std::function; // // By default, the framework compares the GPU results to the CPU results // using an automatically generated neutral ramp for the standard range [0, 1]. -// +// class OCIOGPUTest { public: @@ -30,7 +30,7 @@ class OCIOGPUTest typedef std::vector Values; Values m_inputValues; - // Keeping the original input value size allows + // Keeping the original input value size allows // to avoid manipulating padded values added to fit // the predefined GPU texture size. size_t m_originalInputValueSize{ 0 }; @@ -50,7 +50,7 @@ class OCIOGPUTest void setProcessor(OCIO_NAMESPACE::TransformRcPtr transform); void setProcessor(OCIO_NAMESPACE::ConstProcessorRcPtr processor); - + void setShadingLanguage(OCIO_NAMESPACE::GpuLanguage gpuShadingLanguage) { m_gpuShadingLanguage = gpuShadingLanguage; @@ -75,7 +75,7 @@ class OCIOGPUTest inline void setTestInfinity(bool use) { m_testInfinity = use; } // Provide a set of RGBA values to test (otherwise a neutral ramp will be used). - // TestWideRange, TestNaN & TestInfinity are used when m_inputValues is empty. + // TestWideRange, TestNaN & TestInfinity are used when m_inputValues is empty. inline void setCustomValues(CustomValues & values) { m_values = values; } inline CustomValues & getCustomValues() { return m_values; } @@ -85,7 +85,7 @@ class OCIOGPUTest inline bool getRelativeComparison() const { return m_performRelativeComparison; } inline void setRelativeComparison(bool relCompare) { m_performRelativeComparison = relCompare; } - // This is the lower bound for the value that is divided into the absolute error + // This is the lower bound for the value that is divided into the absolute error // to obtain the relative error. inline float getExpectedMinimalValue() const { return m_expectedMinimalValue; } inline void setExpectedMinimalValue(float minValue) { m_expectedMinimalValue = minValue; } diff --git a/tests/gpu/Lut1DOp_test.cpp b/tests/gpu/Lut1DOp_test.cpp index 91d13446bb..cb76697619 100644 --- a/tests/gpu/Lut1DOp_test.cpp +++ b/tests/gpu/Lut1DOp_test.cpp @@ -9,7 +9,6 @@ #include #include "GPUUnitTest.h" -#include "GPUHelpers.h" namespace OCIO = OCIO_NAMESPACE; diff --git a/tests/gpu/Lut3DOp_test.cpp b/tests/gpu/Lut3DOp_test.cpp index d5fc45a0b6..a3356ae30c 100644 --- a/tests/gpu/Lut3DOp_test.cpp +++ b/tests/gpu/Lut3DOp_test.cpp @@ -1,53 +1,43 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright Contributors to the OpenColorIO Project. -#include -#include #include #include -#include "GPUHelpers.h" #include "GPUUnitTest.h" namespace OCIO = OCIO_NAMESPACE; +#ifndef OCIO_UNIT_TEST_FILES_DIR +#error Expecting OCIO_UNIT_TEST_FILES_DIR to be defined for tests. Check relevant CMakeLists.txt +#endif -OCIO_ADD_GPU_TEST(Lut3DOp, red_only_using_CSP_file_legacy_shader) +// For explanation, refer to https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html +#define _STR(x) #x +#define STR(x) _STR(x) + +static const std::string ocioTestFilesDir(STR(OCIO_UNIT_TEST_FILES_DIR)); + +namespace { - // Any other 3D LUT file format would have been good also. +OCIO::FileTransformRcPtr GetFileTransform(const std::string & filename) +{ + const std::string filepath(ocioTestFilesDir + std::string("/") + filename); + + OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); + file->setSrc(filepath.c_str()); - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - content << "1.0 0.0 0.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); + return file; +} +} +OCIO_ADD_GPU_TEST(Lut3DOp, red_only_using_CSP_file_legacy_shader) +{ + // Any other 3D LUT file format would have been good also. // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_red_only_using_CSP_file_legacy_shader.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -59,38 +49,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, red_only_using_CSP_file_legacy_shader) OCIO_ADD_GPU_TEST(Lut3DOp, green_only_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - content << "0.0 1.0 0.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_green_only_using_CSP_file_legacy_shader.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -102,38 +63,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, green_only_using_CSP_file_legacy_shader) OCIO_ADD_GPU_TEST(Lut3DOp, blue_only_using_CSP_file_legacy_shader) { // Any other 3D LUT file format would have been good also. - - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 0.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - content << "0.0 0.0 1.0" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_blue_only_using_CSP_file_legacy_shader.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -145,39 +77,9 @@ OCIO_ADD_GPU_TEST(Lut3DOp, blue_only_using_CSP_file_legacy_shader) OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file_legacy_shader) { - // Any other 3D LUT file format would have been good also. - - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.100000 0.100000 0.100000" << "\n"; - content << "1.100000 0.100000 0.100000" << "\n"; - content << "0.100000 1.100000 0.100000" << "\n"; - content << "1.100000 1.100000 0.100000" << "\n"; - content << "0.100000 0.100000 1.100000" << "\n"; - content << "1.100000 0.100000 1.100000" << "\n"; - content << "0.100000 1.100000 1.100000" << "\n"; - content << "1.100000 1.100000 1.100000" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_arbitrary_using_CSP_file_legacy_shader.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -186,40 +88,11 @@ OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file_legacy_shader) test.setErrorThreshold(2e-4f); } - OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file) { - std::ostringstream content; - content << "CSPLUTV100" << "\n"; - content << "3D" << "\n"; - content << "" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "2" << "\n"; - content << "0.0 1.0" << "\n"; - content << "0.0 1.0" << "\n"; - content << "" << "\n"; - content << "2 2 2" << "\n"; - content << "0.100000 0.100000 0.100000" << "\n"; - content << "1.100000 0.100000 0.100000" << "\n"; - content << "0.100000 1.100000 0.100000" << "\n"; - content << "1.100000 1.100000 0.100000" << "\n"; - content << "0.100000 0.100000 1.100000" << "\n"; - content << "1.100000 0.100000 1.100000" << "\n"; - content << "0.100000 1.100000 1.100000" << "\n"; - content << "1.100000 1.100000 1.100000" << "\n"; - - - const std::string filename = createTempFile(".csp", content.str()); - // Create the transform & set the unit test - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filename.c_str()); + OCIO::FileTransformRcPtr file = GetFileTransform("Lut3DOp_arbitrary_using_CSP_file.csp"); file->setInterpolation(OCIO::INTERP_LINEAR); test.setProcessor(file); @@ -231,34 +104,6 @@ OCIO_ADD_GPU_TEST(Lut3DOp, arbitrary_using_CSP_file) test.setErrorThreshold(1e-2f); } - - -#ifndef OCIO_UNIT_TEST_FILES_DIR -#error Expecting OCIO_UNIT_TEST_FILES_DIR to be defined for tests. Check relevant CMakeLists.txt -#endif - - -// For explanation, refer to https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html -#define _STR(x) #x -#define STR(x) _STR(x) - -static const std::string ocioTestFilesDir(STR(OCIO_UNIT_TEST_FILES_DIR)); - - -namespace -{ -OCIO::FileTransformRcPtr GetFileTransform(const std::string & filename) -{ - const std::string filepath(ocioTestFilesDir + std::string("/") + filename); - - OCIO::FileTransformRcPtr file = OCIO::FileTransform::Create(); - file->setSrc(filepath.c_str()); - - return file; -} -} - - OCIO_ADD_GPU_TEST(Lut3DOp, 3dlut_file_legacy_shader) { OCIO::FileTransformRcPtr file = GetFileTransform("lut3d_1.spi3d"); @@ -389,4 +234,3 @@ OCIO_ADD_GPU_TEST(Lut3DOp, 3dlut_biggest_supported) test.setErrorThreshold(1e-4f); } - diff --git a/tests/gpu/RangeOp_test.cpp b/tests/gpu/RangeOp_test.cpp index c94906cfe9..3ae2c90012 100644 --- a/tests/gpu/RangeOp_test.cpp +++ b/tests/gpu/RangeOp_test.cpp @@ -7,7 +7,6 @@ #include -#include "GPUHelpers.h" #include "GPUUnitTest.h" namespace OCIO = OCIO_NAMESPACE;