diff --git a/src/OpenColorIO/transforms/CDLTransform.cpp b/src/OpenColorIO/transforms/CDLTransform.cpp index 94e1cce167..d5c1e37fe6 100755 --- a/src/OpenColorIO/transforms/CDLTransform.cpp +++ b/src/OpenColorIO/transforms/CDLTransform.cpp @@ -202,7 +202,7 @@ void ClearCDLTransformFileCache() CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cccid_) { - if (!src || (strlen(src) == 0)) + if (!src || !*src) { std::ostringstream os; os << "Error loading CDL xml. "; @@ -217,7 +217,7 @@ CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cc AutoMutex lock(g_cacheMutex); // Use g_cacheSrcIsCC as a proxy for if we have loaded this source - // file already (in which case it must be in cache, or an error) + // file already (in which case it must be in cache, or an error). StringBoolMap::iterator srcIsCCiter = g_cacheSrcIsCC.find(src); if (srcIsCCiter != g_cacheSrcIsCC.end()) @@ -252,7 +252,7 @@ CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cc throw Exception (os.str().c_str()); } - // Try to read all ccs from the file, into cache + // Try to read all ccs from the file, into cache. std::ifstream istream(src); if (istream.fail()) { @@ -268,7 +268,7 @@ CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cc if (parser.isCC()) { - // Load a single ColorCorrection into the cache + // Load a single ColorCorrection into the cache. CDLTransformRcPtr cdl = CDLTransform::Create(); parser.getCDLTransform(cdl); @@ -276,10 +276,10 @@ CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cc g_cacheSrcIsCC[src] = true; g_cache[GetCDLLocalCacheKey(src, cccid)] = cdl; } - else if (parser.isCCC()) + else { - // Load all CCs from the ColorCorrectionCollection - // into the cache + // Load all CCs from the ColorCorrectionCollection or from the ColorDecisionList + // into the cache. CDLTransformMap transformMap; CDLTransformVec transformVec; FormatMetadataImpl metadata; diff --git a/tests/cpu/transforms/CDLTransform_tests.cpp b/tests/cpu/transforms/CDLTransform_tests.cpp index f75b3968e1..17305c699a 100644 --- a/tests/cpu/transforms/CDLTransform_tests.cpp +++ b/tests/cpu/transforms/CDLTransform_tests.cpp @@ -9,6 +9,7 @@ #include "transforms/CDLTransform.cpp" #include "testutils/UnitTest.h" +#include "UnitTestLogUtils.h" #include "UnitTestUtils.h" #include "Platform.h" @@ -165,6 +166,24 @@ OCIO_ADD_TEST(CDLTransform, create_from_ccc_file) } } +OCIO_ADD_TEST(CDLTransform, create_from_cdl_file) +{ + // As warning messages are expected, please mute them. + OCIO::MuteLogging mute; + + // Note: Detailed test is already done, this unit test only validates that + // this CDL file (i.e. containing a ColorDecisionList) correctly loads + // using a CDLTransform. + + const std::string filePath(std::string(OCIO::getTestFilesDir()) + "/cdl_test1.cdl"); + + OCIO::CDLTransformRcPtr transform; + + OCIO_CHECK_NO_THROW(transform = OCIO::CDLTransform::CreateFromFile(filePath.c_str(), "cc0003")); + OCIO_CHECK_EQUAL(std::string("cc0003"), std::string(transform->getID())); + OCIO_CHECK_EQUAL(transform->getStyle(), OCIO::CDL_NO_CLAMP); +} + OCIO_ADD_TEST(CDLTransform, create_from_ccc_file_failure) { const std::string filePath(std::string(OCIO::getTestFilesDir()) + "/cdl_test1.ccc");