diff --git a/include/OpenColorIO/OpenColorIO.h b/include/OpenColorIO/OpenColorIO.h index dafe119b46..386269cd12 100644 --- a/include/OpenColorIO/OpenColorIO.h +++ b/include/OpenColorIO/OpenColorIO.h @@ -206,6 +206,28 @@ extern OCIOEXPORT ConstConfigRcPtr GetCurrentConfig(); /// Set the current configuration. This will then store a copy of the specified config. extern OCIOEXPORT void SetCurrentConfig(const ConstConfigRcPtr & config); +/** + * \brief Make a config path forward-compatible by replacing special built-in config names + * with the current name. + * + * Application developers should call this function on any config path they intend to persist + * (e.g., to include in a file saved from a DCC). + * + * As the built-in config collection evolves, special names such as "ocio://default" and + * "ocio://studio-config-latest" will point to newer versions of those configs. Therefore, it is + * recommended that application developers not save those strings and instead save the string that + * refers to the current version of that config. That way, it's guaranteed that there will be no + * change of behavior in the future. For example, as of OCIO 2.2, "ocio://default" should be saved + * as "ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1". + * + * Note that there is no validation done on the path. That is left to the application since + * typically the application will load the config before attempting to save its path + * and therefore catch, for example, a badly formed URI such as "ocio:default". + * + * \return Resolved path if possible. Otherwise, the original path is returned unmodified. + */ +extern OCIOEXPORT const char * ResolveConfigPath(const char * originalPath) noexcept; + /** * \brief Extract an OCIO Config archive. * @@ -298,13 +320,11 @@ class OCIOEXPORT Config /** * \brief Create a configuration using a specific config file. * - * Also supports the following OCIO URI format for Built-in configs: - * "ocio://default" - Default Built-in config. - * "ocio://" - A specific Built-in config. For the list of available - * strings, see \ref Config::CreateFromBuiltinConfig. - * - * Also supports archived configs (.ocioz files). + * Supports the OCIO URI format for Built-in configs. + * See \ref Config::CreateFromBuiltinConfig. * + * Supports archived configs (.ocioz files). + * * \throw Exception If the file may not be read or does not parse. * \return The Config object. */ @@ -342,7 +362,13 @@ class OCIOEXPORT Config /** * \brief Create a configuration using an OCIO built-in config. * - * \param configName Built-in config name. + * \param configName Built-in config name (with or without the "ocio://" URI prefix). + * + * Also supports the following OCIO URI format for Built-in configs: + * "ocio://default" - Default Built-in config. + * "ocio://cg-config-latest" - Latest Built-in CG config. + * "ocio://studio-config-latest" - Latest Built-in Studio config. + * "ocio://" - A specific Built-in config. * * The available configNames are: * @@ -3680,22 +3706,8 @@ class OCIOEXPORT BuiltinConfigRegistry */ virtual bool isBuiltinConfigRecommended(size_t configIndex) const = 0; - /** - * @brief Get the default recommended built-in config. - * - * Get the name of the built-in config that is currently recommended as the default config - * to use for applications looking for basic color management. - * - * As the built-in config collection evolves, the default config name will change in future - * releases. - * - * For backwards compatibility, the name provided here will always work as an argument - * to other methods so that any previous default config may be recovered. - * - * Throws if the name is not found. - * - * @return Default's built-in config name. - */ + // Return the full forward-compatible name of the default built-in config. + // Please use ResolveConfigPath(\"ocio://default\"). This method will be deprecated in OCIO 2.3. virtual const char * getDefaultBuiltinConfigName() const = 0; protected: BuiltinConfigRegistry() = default; diff --git a/include/OpenColorIO/OpenColorTypes.h b/include/OpenColorIO/OpenColorTypes.h index 5e28bbb175..0aa30bd2d5 100644 --- a/include/OpenColorIO/OpenColorTypes.h +++ b/include/OpenColorIO/OpenColorTypes.h @@ -945,6 +945,10 @@ extern OCIOEXPORT const char * OCIO_CONFIG_DEFAULT_NAME; extern OCIOEXPORT const char * OCIO_CONFIG_DEFAULT_FILE_EXT; extern OCIOEXPORT const char * OCIO_CONFIG_ARCHIVE_FILE_EXT; +// Built-in config feature +// URI Prefix +extern OCIOEXPORT const char * OCIO_BUILTIN_URI_PREFIX; + } // namespace OCIO_NAMESPACE #endif diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 305db0596a..b59e05c444 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -59,6 +59,8 @@ const char * OCIO_CONFIG_ARCHIVE_FILE_EXT = ".ocioz"; // has the same name as the display the shared view is used by. const char * OCIO_VIEW_USE_DISPLAY_NAME = ""; +const char * OCIO_BUILTIN_URI_PREFIX = "ocio://"; + namespace { @@ -1160,13 +1162,7 @@ ConstConfigRcPtr Config::CreateFromFile(const char * filename) const std::string uri = filename; if (std::regex_search(uri, match, uriPattern)) { - if (Platform::Strcasecmp(match.str(1).c_str(), "default") == 0) - { - // Processing ocio://default - const BuiltinConfigRegistry & reg = BuiltinConfigRegistry::Get(); - return CreateFromBuiltinConfig(reg.getDefaultBuiltinConfigName()); - } - return CreateFromBuiltinConfig(match.str(1).c_str()); + return CreateFromBuiltinConfig(uri.c_str()); } std::ifstream ifstream = Platform::CreateInputFileStream( @@ -1234,11 +1230,31 @@ ConstConfigRcPtr Config::CreateFromConfigIOProxy(ConfigIOProxyRcPtr ciop) ConstConfigRcPtr Config::CreateFromBuiltinConfig(const char * configName) { + std::string builtinConfigName = configName; + + // Normalize the input to the URI format. + if (!StringUtils::StartsWith(builtinConfigName, OCIO_BUILTIN_URI_PREFIX)) + { + builtinConfigName = std::string(OCIO_BUILTIN_URI_PREFIX) + builtinConfigName; + } + + // Resolve the URI if needed. + const std::string uri = ResolveConfigPath(builtinConfigName.c_str()); + + // Check if the config path starts with ocio:// + static const std::regex uriPattern(R"(ocio:\/\/([^\s]+))"); + std::smatch match; + if (std::regex_search(uri, match, uriPattern)) + { + // Store config path without the "ocio://" prefix, if present. + builtinConfigName = match.str(1).c_str(); + } + ConstConfigRcPtr builtinConfig; const BuiltinConfigRegistry & reg = BuiltinConfigRegistry::Get(); // getBuiltinConfigByName will throw if config name not found. - const char * builtinConfigStr = reg.getBuiltinConfigByName(configName); + const char * builtinConfigStr = reg.getBuiltinConfigByName(builtinConfigName.c_str()); std::istringstream iss; iss.str(builtinConfigStr); builtinConfig = Config::CreateFromStream(iss); diff --git a/src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.cpp b/src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.cpp index f9f3f95300..ad97a744ce 100644 --- a/src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.cpp +++ b/src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.cpp @@ -4,6 +4,7 @@ #include #include #include +#include // OpenColorIO must be first - order is important. #include @@ -15,11 +16,51 @@ #include "builtinconfigs/CGConfig.h" #include "builtinconfigs/StudioConfig.h" -#define OUT_OF_RANGE_EXCEPTION_TEXT "Config index is out of range." +static constexpr char OUT_OF_RANGE_EXCEPTION_TEXT[] = "Config index is out of range."; + +// TODO: Remove once getDefaultBuiltinConfigName is removed. +static constexpr char DEFAULT_BUILTIN_CONFIG[] = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; + +// These are used for ResolveConfigPath function and we need to return a variable that still exists +// once the function finishes since we are returning a const char *. +static constexpr char DEFAULT_BUILTIN_CONFIG_URI[] = "ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; +static constexpr char LATEST_CG_BUILTIN_CONFIG_URI[] = "ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; +static constexpr char LATEST_STUDIO_BUILTIN_CONFIG_URI[] = "ocio://studio-config-v1.0.0_aces-v1.3_ocio-v2.1"; + +static constexpr char BUILTIN_DEFAULT_NAME[] = "default"; +static constexpr char BUILTIN_LATEST_CG_NAME[] = "cg-config-latest"; +static constexpr char BUILTIN_LATEST_STUDIO_NAME[] = "studio-config-latest"; namespace OCIO_NAMESPACE { +// Note that this function does not require initializing the built-in config registry. +const char * ResolveConfigPath(const char * originalPath) noexcept +{ + static const std::regex uriPattern(R"(ocio:\/\/([^\s]+))"); + std::smatch match; + const std::string uri = originalPath; + // Check if original path starts with "ocio://". + if (std::regex_search(uri, match, uriPattern)) + { + if (Platform::Strcasecmp(match.str(1).c_str(), BUILTIN_DEFAULT_NAME) == 0) + { + return DEFAULT_BUILTIN_CONFIG_URI; + } + else if (Platform::Strcasecmp(match.str(1).c_str(), BUILTIN_LATEST_CG_NAME) == 0) + { + return LATEST_CG_BUILTIN_CONFIG_URI; + } + else if (Platform::Strcasecmp(match.str(1).c_str(), BUILTIN_LATEST_STUDIO_NAME) == 0) + { + return LATEST_STUDIO_BUILTIN_CONFIG_URI; + } + } + + // Return originalPath if no special path was used. + return originalPath; +} + const BuiltinConfigRegistry & BuiltinConfigRegistry::Get() noexcept { // Meyer's Singleton pattern. @@ -46,8 +87,6 @@ void BuiltinConfigRegistryImpl::init() noexcept CGCONFIG::Register(*this); STUDIOCONFIG::Register(*this); - - this->setDefaultBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1"); } } @@ -131,28 +170,7 @@ bool BuiltinConfigRegistryImpl::isBuiltinConfigRecommended(size_t configIndex) c const char * BuiltinConfigRegistryImpl::getDefaultBuiltinConfigName() const { - if (m_defaultBuiltinConfigName.empty()) - { - // Make sure that at least one default built-ins config is present. - throw Exception("Internal error - The default built-in config name has not been set yet."); - } - - return m_defaultBuiltinConfigName.c_str(); -} - -void BuiltinConfigRegistryImpl::setDefaultBuiltinConfig(const char * configName) -{ - // Search for config name. - for (auto & builtin : m_builtinConfigs) - { - if (Platform::Strcasecmp(configName, builtin.m_name.c_str()) == 0) - { - m_defaultBuiltinConfigName = configName; - return; - } - } - - throw Exception("Internal error - Config name does not exist."); + return DEFAULT_BUILTIN_CONFIG; } } // namespace OCIO_NAMESPACE diff --git a/src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.h b/src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.h index 7597695f9a..6395e96c74 100644 --- a/src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.h +++ b/src/OpenColorIO/builtinconfigs/BuiltinConfigRegistry.h @@ -94,14 +94,9 @@ using BuiltinConfigs = std::vector; bool isBuiltinConfigRecommended(size_t configIndex) const override; /// Get the default recommended built-in config. - /// Throws for illegal index. const char * getDefaultBuiltinConfigName() const override; - - /// Set the default built-in config. - void setDefaultBuiltinConfig(const char * configName); private: BuiltinConfigs m_builtinConfigs; - std::string m_defaultBuiltinConfigName; }; } // namespace OCIO_NAMESPACE diff --git a/src/OpenColorIO/builtinconfigs/CG.cpp.in b/src/OpenColorIO/builtinconfigs/CG.cpp.in index 62d2b19e22..0bf91c94ab 100644 --- a/src/OpenColorIO/builtinconfigs/CG.cpp.in +++ b/src/OpenColorIO/builtinconfigs/CG.cpp.in @@ -6,6 +6,6 @@ // It is included in the following places: // - CGConfig.cpp for the Built-in config feature. -// - BuiltinConfigRegistry_tests.cpp for the unit tests +// - BuiltinConfig_tests.cpp for the unit tests constexpr char CG_CONFIG_V100_ACES_V13_OCIO_V21[] = { @cg-config-v1.0.0_aces-v1.3_ocio-v2.1@ }; diff --git a/src/OpenColorIO/builtinconfigs/CGConfig.cpp b/src/OpenColorIO/builtinconfigs/CGConfig.cpp index 489e856bb5..029768536e 100644 --- a/src/OpenColorIO/builtinconfigs/CGConfig.cpp +++ b/src/OpenColorIO/builtinconfigs/CGConfig.cpp @@ -17,6 +17,9 @@ namespace CGCONFIG { void Register(BuiltinConfigRegistryImpl & registry) noexcept { + // If a new built-in config is added, do not forget to update the latestCGBuiltinConfigURI + // variable (in BuiltinConfigRegistry.h). + registry.addBuiltin( "cg-config-v1.0.0_aces-v1.3_ocio-v2.1", "Academy Color Encoding System - CG Config [COLORSPACES v1.0.0] [ACES v1.3] [OCIO v2.1]", diff --git a/src/OpenColorIO/builtinconfigs/StudioConfig.cpp b/src/OpenColorIO/builtinconfigs/StudioConfig.cpp index bb850999aa..f17239e788 100644 --- a/src/OpenColorIO/builtinconfigs/StudioConfig.cpp +++ b/src/OpenColorIO/builtinconfigs/StudioConfig.cpp @@ -17,6 +17,9 @@ namespace STUDIOCONFIG { void Register(BuiltinConfigRegistryImpl & registry) noexcept { + // If a new built-in config is added, do not forget to update the latestStudioBuiltinConfigURI + // variable (in BuiltinConfigRegistry.h). + registry.addBuiltin( "studio-config-v1.0.0_aces-v1.3_ocio-v2.1", "Academy Color Encoding System - Studio Config [COLORSPACES v1.0.0] [ACES v1.3] [OCIO v2.1]", diff --git a/src/bindings/python/PyConfig.cpp b/src/bindings/python/PyConfig.cpp index d7e188bf5a..6708c81e3b 100644 --- a/src/bindings/python/PyConfig.cpp +++ b/src/bindings/python/PyConfig.cpp @@ -1307,6 +1307,9 @@ void bindPyConfig(py::module & m) m.def("ExtractOCIOZArchive", &ExtractOCIOZArchive, DOC(PyOpenColorIO, ExtractOCIOZArchive)); + + m.def("ResolveConfigPath", &ResolveConfigPath, + DOC(PyOpenColorIO, ResolveConfigPath)); } } // namespace OCIO_NAMESPACE diff --git a/src/bindings/python/PyTypes.cpp b/src/bindings/python/PyTypes.cpp index 4f2a196e12..70f0ec99dd 100644 --- a/src/bindings/python/PyTypes.cpp +++ b/src/bindings/python/PyTypes.cpp @@ -880,6 +880,12 @@ void bindPyTypes(py::module & m) m.attr("OCIO_DISABLE_ALL_CACHES") = OCIO_DISABLE_ALL_CACHES; m.attr("OCIO_DISABLE_PROCESSOR_CACHES") = OCIO_DISABLE_PROCESSOR_CACHES; m.attr("OCIO_DISABLE_CACHE_FALLBACK") = OCIO_DISABLE_CACHE_FALLBACK; + + m.attr("OCIO_CONFIG_DEFAULT_NAME") = OCIO_CONFIG_DEFAULT_NAME; + m.attr("OCIO_CONFIG_DEFAULT_FILE_EXT") = OCIO_CONFIG_DEFAULT_FILE_EXT; + m.attr("OCIO_CONFIG_ARCHIVE_FILE_EXT") = OCIO_CONFIG_ARCHIVE_FILE_EXT; + + m.attr("OCIO_BUILTIN_URI_PREFIX") = OCIO_BUILTIN_URI_PREFIX; } } // namespace OCIO_NAMESPACE diff --git a/tests/cpu/CMakeLists.txt b/tests/cpu/CMakeLists.txt index fdc200a7c4..06ef8b2b83 100755 --- a/tests/cpu/CMakeLists.txt +++ b/tests/cpu/CMakeLists.txt @@ -174,7 +174,7 @@ set(TESTS apphelpers/MixingHelpers_tests.cpp Baker_tests.cpp BitDepthUtils_tests.cpp - builtinconfigs/BuiltinConfigRegistry_tests.cpp + builtinconfigs/BuiltinConfig_tests.cpp Caching_tests.cpp ColorSpace_tests.cpp ColorSpaceSet_tests.cpp diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index 95e798fe0f..bf8126b627 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: BSD-3-Clause +// SPDX-License-Identifer: BSD-3-Clause // Copyright Contributors to the OpenColorIO Project. @@ -9050,213 +9050,6 @@ OCIO_ADD_TEST(Config, look_fallback) } } -OCIO_ADD_TEST(Config, create_builtin_config) -{ - // ******************************** - // Testing CG config. - // ******************************** - int numberOfExpectedColorspaces = 14; - const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; - const std::string cgConfigURI = std::string("ocio://") + cgConfigName; - - { - // Testing CreateFromBuiltinConfig with a known built-in config name. - - OCIO::ConstConfigRcPtr config; - OCIO_CHECK_NO_THROW( - config = OCIO::Config::CreateFromBuiltinConfig(cgConfigName.c_str()) - ); - OCIO_REQUIRE_ASSERT(config); - - OCIO::LogGuard logGuard; - OCIO_CHECK_NO_THROW(config->validate()); - // Mute output related to a bug in the initial CG config where the inactive_colorspaces - // list has color spaces that don't exist. - OCIO::muteInactiveColorspaceInfo(logGuard); - logGuard.print(); - - OCIO_CHECK_EQUAL( - std::string(config->getName()), - cgConfigName - ); - OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); - } - - { - // Testing CreateFromEnv with an known built-in config name using URI Syntax. - - OCIO::EnvironmentVariableGuard guard("OCIO", cgConfigURI); - - OCIO::ConstConfigRcPtr config; - OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromEnv()); - OCIO_REQUIRE_ASSERT(config); - - OCIO::LogGuard logGuard; - OCIO_CHECK_NO_THROW(config->validate()); - OCIO::muteInactiveColorspaceInfo(logGuard); - logGuard.print(); - - OCIO_CHECK_EQUAL( - std::string(config->getName()), - cgConfigName - ); - OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); - } - - { - // Testing CreateFromFile with an known built-in config name using URI Syntax. - - OCIO::ConstConfigRcPtr config; - OCIO_CHECK_NO_THROW( - config = OCIO::Config::CreateFromFile(cgConfigURI.c_str()) - ); - OCIO_REQUIRE_ASSERT(config); - - OCIO::LogGuard logGuard; - OCIO_CHECK_NO_THROW(config->validate()); - OCIO::muteInactiveColorspaceInfo(logGuard); - logGuard.print(); - - OCIO_CHECK_EQUAL( - std::string(config->getName()), - cgConfigName - ); - OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); - } - - // ******************************** - // Testing STUDIO config. - // ******************************** - numberOfExpectedColorspaces = 39; - const std::string studioConfigName = "studio-config-v1.0.0_aces-v1.3_ocio-v2.1"; - const std::string studioConfigURI = std::string("ocio://") + studioConfigName; - - { - // Testing CreateFromBuiltinConfig with a known built-in config name. - - OCIO::ConstConfigRcPtr config; - OCIO_CHECK_NO_THROW( - config = OCIO::Config::CreateFromBuiltinConfig(studioConfigName.c_str()) - ); - OCIO_REQUIRE_ASSERT(config); - - OCIO_CHECK_NO_THROW(config->validate()); - OCIO_CHECK_EQUAL( - std::string(config->getName()), - studioConfigName - ); - OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); - } - - { - // Testing CreateFromEnv with an known built-in config name using URI Syntax. - - OCIO::EnvironmentVariableGuard guard("OCIO", studioConfigURI); - - OCIO::ConstConfigRcPtr config; - OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromEnv()); - OCIO_REQUIRE_ASSERT(config); - - OCIO_CHECK_NO_THROW(config->validate()); - OCIO_CHECK_EQUAL( - std::string(config->getName()), - studioConfigName - ); - OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); - } - - { - // Testing CreateFromFile with an known built-in config name using URI Syntax. - - OCIO::ConstConfigRcPtr config; - OCIO_CHECK_NO_THROW( - config = OCIO::Config::CreateFromFile(studioConfigURI.c_str()) - ); - OCIO_REQUIRE_ASSERT(config); - - OCIO_CHECK_NO_THROW(config->validate()); - OCIO_CHECK_EQUAL( - std::string(config->getName()), - studioConfigName - ); - OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); - } - - // ******************************** - // Testing default config. - // ******************************** - - { - // Testing CreateFromEnv with the default config using URI Syntax. - - OCIO::EnvironmentVariableGuard guard("OCIO", "ocio://default"); - - OCIO::ConstConfigRcPtr config; - OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromEnv()); - OCIO_REQUIRE_ASSERT(config); - - OCIO::LogGuard logGuard; - OCIO_CHECK_NO_THROW(config->validate()); - OCIO::muteInactiveColorspaceInfo(logGuard); - logGuard.print(); - - OCIO_CHECK_EQUAL( - std::string(config->getName()), - std::string("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - ); - OCIO_CHECK_EQUAL(config->getNumColorSpaces(), 14); - } - - { - // Testing CreateFromFile with the default config using URI Syntax. - - OCIO::ConstConfigRcPtr config; - OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromFile("ocio://default")); - OCIO_REQUIRE_ASSERT(config); - - OCIO::LogGuard logGuard; - OCIO_CHECK_NO_THROW(config->validate()); - OCIO::muteInactiveColorspaceInfo(logGuard); - logGuard.print(); - - OCIO_CHECK_EQUAL( - std::string(config->getName()), - std::string("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - ); - OCIO_CHECK_EQUAL(config->getNumColorSpaces(), 14); - } - - // ******************************** - // Testing some expected failures. - // ******************************** - - // Testing CreateFromBuiltinConfig with an unknown built-in config name. - OCIO_CHECK_THROW_WHAT( - OCIO::Config::CreateFromBuiltinConfig("I-do-not-exist"), - OCIO::Exception, - "Could not find 'I-do-not-exist' in the built-in configurations." - ); - - // Testing CreateFromFile with an unknown built-in config name using URI syntax. - OCIO_CHECK_THROW_WHAT( - OCIO::Config::CreateFromFile("ocio://I-do-not-exist"), - OCIO::Exception, - "Could not find 'I-do-not-exist' in the built-in configurations." - ); - - { - // Testing CreateFromEnv with an unknown built-in config. - - OCIO::EnvironmentVariableGuard guard("OCIO", "ocio://thedefault"); - - OCIO_CHECK_THROW_WHAT( - OCIO::Config::CreateFromEnv(), - OCIO::Exception, - "Could not find 'thedefault' in the built-in configurations." - ); - } -} - OCIO_ADD_TEST(Config, create_from_archive) { { diff --git a/tests/cpu/builtinconfigs/BuiltinConfigRegistry_tests.cpp b/tests/cpu/builtinconfigs/BuiltinConfigRegistry_tests.cpp deleted file mode 100644 index d452d60e24..0000000000 --- a/tests/cpu/builtinconfigs/BuiltinConfigRegistry_tests.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// Copyright Contributors to the OpenColorIO Project. - -#include "builtinconfigs/BuiltinConfigRegistry.cpp" -#include "testutils/UnitTest.h" - -#include "CG.cpp" -#include "Studio.cpp" - -namespace OCIO = OCIO_NAMESPACE; - -OCIO_ADD_TEST(BuiltinConfigs, basic) -{ - const OCIO::BuiltinConfigRegistry & registry = OCIO::BuiltinConfigRegistry::Get(); - - OCIO_CHECK_EQUAL(registry.getNumBuiltinConfigs(), 2); - - // Test default builtin config. - const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; - - OCIO_CHECK_EQUAL( - std::string(registry.getDefaultBuiltinConfigName()), - cgConfigName - ); - - // ******************************************* - // Testing the first config. (ACES CG config) - // ******************************************* - - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigName(0)), - cgConfigName - ); - - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigUIName(0)), - std::string("Academy Color Encoding System - CG Config [COLORSPACES v1.0.0] "\ - "[ACES v1.3] [OCIO v2.1]") - ); - - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfig(0)), - std::string(CG_CONFIG_V100_ACES_V13_OCIO_V21) - ); - - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigByName(cgConfigName.c_str())), - std::string(CG_CONFIG_V100_ACES_V13_OCIO_V21) - ); - - OCIO_CHECK_EQUAL(registry.isBuiltinConfigRecommended(0), true); - - // ************************************************ - // Testing the second config. (ACES Studio config) - // ************************************************ - const std::string studioConfigName = "studio-config-v1.0.0_aces-v1.3_ocio-v2.1"; - - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigName(1)), - studioConfigName - ); - - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigUIName(1)), - std::string("Academy Color Encoding System - Studio Config [COLORSPACES v1.0.0] "\ - "[ACES v1.3] [OCIO v2.1]") - ); - - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfig(1)), - std::string(STUDIO_CONFIG_V100_ACES_V13_OCIO_V21) - ); - - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigByName(studioConfigName.c_str())), - std::string(STUDIO_CONFIG_V100_ACES_V13_OCIO_V21) - ); - - OCIO_CHECK_EQUAL(registry.isBuiltinConfigRecommended(1), true); - - // ******************************** - // Testing some expected failures. - // ******************************** - - // Test isBuiltinConfigRecommended using an invalid config index. - OCIO_CHECK_THROW_WHAT( - registry.isBuiltinConfigRecommended(999), - OCIO::Exception, - "Config index is out of range." - ); - - // Test getBuiltinConfigName using an invalid config index. - OCIO_CHECK_THROW_WHAT( - registry.getBuiltinConfigName(999), - OCIO::Exception, - "Config index is out of range." - ); - - // Test getBuiltinConfigUIName using an invalid config index. - OCIO_CHECK_THROW_WHAT( - registry.getBuiltinConfigUIName(999), - OCIO::Exception, - "Config index is out of range." - ); - - // Test getBuiltinConfig using an invalid config index. - OCIO_CHECK_THROW_WHAT( - registry.getBuiltinConfig(999), - OCIO::Exception, - "Config index is out of range." - ); - - // Test getBuiltinConfigByName using an unknown config name. - OCIO_CHECK_THROW_WHAT( - registry.getBuiltinConfigByName("I do not exist"), - OCIO::Exception, - "Could not find 'I do not exist' in the built-in configurations." - ); -} - -OCIO_ADD_TEST(BuiltinConfigs, basic_impl) -{ - { - // Test the addBuiltin method. - - OCIO::BuiltinConfigRegistryImpl registry; - - // Add configs into the built-ins config registry - std::string SIMPLE_CONFIG = - "ocio_profile_version: 1\n" - "colorspaces:\n" - " - !\n" - " name: raw\n" - " - !\n" - " name: linear\n" - "roles:\n" - " default: raw\n" - "displays:\n" - " sRGB:\n" - " - ! {name: Raw, colorspace: raw}\n" - "\n"; - - // Add first config. - OCIO_CHECK_NO_THROW(registry.addBuiltin( - "My simple config name #1", - "My simple config display name #1", - SIMPLE_CONFIG.c_str(), - false - )); - // Add second config. - OCIO_CHECK_NO_THROW(registry.addBuiltin( - "My simple config name #2", - "My simple config display name #2", - SIMPLE_CONFIG.c_str(), - true - )); - - OCIO_CHECK_EQUAL(registry.getNumBuiltinConfigs(), 2); - - // Tests to check if the config #1 was added correctly. - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigName(0)), - std::string("My simple config name #1") - ); - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigUIName(0)), - std::string("My simple config display name #1") - ); - - // Tests to check if the config #2 was added correctly. - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigName(1)), - std::string("My simple config name #2") - ); - OCIO_CHECK_EQUAL( - std::string(registry.getBuiltinConfigUIName(1)), - std::string("My simple config display name #2") - ); - } -} \ No newline at end of file diff --git a/tests/cpu/builtinconfigs/BuiltinConfig_tests.cpp b/tests/cpu/builtinconfigs/BuiltinConfig_tests.cpp new file mode 100644 index 0000000000..8ef1ac4388 --- /dev/null +++ b/tests/cpu/builtinconfigs/BuiltinConfig_tests.cpp @@ -0,0 +1,397 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright Contributors to the OpenColorIO Project. + +#include "builtinconfigs/BuiltinConfigRegistry.cpp" +#include "testutils/UnitTest.h" +#include "UnitTestUtils.h" +#include "UnitTestLogUtils.h" + +#include "CG.cpp" +#include "Studio.cpp" + +namespace OCIO = OCIO_NAMESPACE; + +// See also the create_builtin_config and resolve_config_path tests in Config_tests.cpp. + +OCIO_ADD_TEST(BuiltinConfigs, basic) +{ + const OCIO::BuiltinConfigRegistry & registry = OCIO::BuiltinConfigRegistry::Get(); + + OCIO_CHECK_EQUAL(registry.getNumBuiltinConfigs(), 2); + + // Test default builtin config. + const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; + + // ******************************************* + // Testing the first config. (ACES CG config) + // ******************************************* + + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigName(0)), + cgConfigName + ); + + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigUIName(0)), + std::string("Academy Color Encoding System - CG Config [COLORSPACES v1.0.0] "\ + "[ACES v1.3] [OCIO v2.1]") + ); + + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfig(0)), + std::string(CG_CONFIG_V100_ACES_V13_OCIO_V21) + ); + + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigByName(cgConfigName.c_str())), + std::string(CG_CONFIG_V100_ACES_V13_OCIO_V21) + ); + + OCIO_CHECK_EQUAL(registry.isBuiltinConfigRecommended(0), true); + + // ************************************************ + // Testing the second config. (ACES Studio config) + // ************************************************ + const std::string studioConfigName = "studio-config-v1.0.0_aces-v1.3_ocio-v2.1"; + + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigName(1)), + studioConfigName + ); + + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigUIName(1)), + std::string("Academy Color Encoding System - Studio Config [COLORSPACES v1.0.0] "\ + "[ACES v1.3] [OCIO v2.1]") + ); + + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfig(1)), + std::string(STUDIO_CONFIG_V100_ACES_V13_OCIO_V21) + ); + + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigByName(studioConfigName.c_str())), + std::string(STUDIO_CONFIG_V100_ACES_V13_OCIO_V21) + ); + + OCIO_CHECK_EQUAL(registry.isBuiltinConfigRecommended(1), true); + + // ******************************** + // Testing some expected failures. + // ******************************** + + // Test isBuiltinConfigRecommended using an invalid config index. + OCIO_CHECK_THROW_WHAT( + registry.isBuiltinConfigRecommended(999), + OCIO::Exception, + "Config index is out of range." + ); + + // Test getBuiltinConfigName using an invalid config index. + OCIO_CHECK_THROW_WHAT( + registry.getBuiltinConfigName(999), + OCIO::Exception, + "Config index is out of range." + ); + + // Test getBuiltinConfigUIName using an invalid config index. + OCIO_CHECK_THROW_WHAT( + registry.getBuiltinConfigUIName(999), + OCIO::Exception, + "Config index is out of range." + ); + + // Test getBuiltinConfig using an invalid config index. + OCIO_CHECK_THROW_WHAT( + registry.getBuiltinConfig(999), + OCIO::Exception, + "Config index is out of range." + ); + + // Test getBuiltinConfigByName using an unknown config name. + OCIO_CHECK_THROW_WHAT( + registry.getBuiltinConfigByName("I do not exist"), + OCIO::Exception, + "Could not find 'I do not exist' in the built-in configurations." + ); +} + +OCIO_ADD_TEST(BuiltinConfigs, basic_impl) +{ + { + // Test the addBuiltin method. + + OCIO::BuiltinConfigRegistryImpl registry; + + // Add configs into the built-ins config registry + std::string SIMPLE_CONFIG = + "ocio_profile_version: 1\n" + "colorspaces:\n" + " - !\n" + " name: raw\n" + " - !\n" + " name: linear\n" + "roles:\n" + " default: raw\n" + "displays:\n" + " sRGB:\n" + " - ! {name: Raw, colorspace: raw}\n" + "\n"; + + // Add first config. + OCIO_CHECK_NO_THROW(registry.addBuiltin( + "simple_config_1", + "My simple config display name #1", + SIMPLE_CONFIG.c_str(), + false + )); + // Add second config. + OCIO_CHECK_NO_THROW(registry.addBuiltin( + "simple_config_2", + "My simple config display name #2", + SIMPLE_CONFIG.c_str(), + true + )); + + OCIO_CHECK_EQUAL(registry.getNumBuiltinConfigs(), 2); + + // Tests to check if the config #1 was added correctly. + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigName(0)), + std::string("simple_config_1") + ); + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigUIName(0)), + std::string("My simple config display name #1") + ); + + // Tests to check if the config #2 was added correctly. + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigName(1)), + std::string("simple_config_2") + ); + OCIO_CHECK_EQUAL( + std::string(registry.getBuiltinConfigUIName(1)), + std::string("My simple config display name #2") + ); + } +} + +OCIO_ADD_TEST(BuiltinConfigs, create_builtin_config) +{ + auto testFromBuiltinConfig = [](const std::string name, + int numberOfExpectedColorspaces, + const std::string expectedConfigName) + { + { + // Testing CreateFromBuiltinConfig with a known built-in config name. + + OCIO::ConstConfigRcPtr config; + OCIO_CHECK_NO_THROW( + config = OCIO::Config::CreateFromBuiltinConfig(name.c_str()) + ); + OCIO_REQUIRE_ASSERT(config); + + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(config->validate()); + // Mute output related to a bug in the initial CG config where the inactive_colorspaces + // list has color spaces that don't exist. + OCIO::muteInactiveColorspaceInfo(logGuard); + logGuard.print(); + + OCIO_CHECK_EQUAL( + std::string(config->getName()), + expectedConfigName.empty() ? name : expectedConfigName + ); + OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); + } + }; + + auto testFromEnvAndFromFile = [](const std::string uri, + int numberOfExpectedColorspaces, + const std::string expectedConfigName = "") + { + { + // Testing CreateFromEnv using URI Syntax. + + OCIO::EnvironmentVariableGuard guard("OCIO", uri); + + OCIO::ConstConfigRcPtr config; + OCIO_CHECK_NO_THROW(config = OCIO::Config::CreateFromEnv()); + OCIO_REQUIRE_ASSERT(config); + + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(config->validate()); + OCIO::muteInactiveColorspaceInfo(logGuard); + logGuard.print(); + + if (!expectedConfigName.empty()) + { + OCIO_CHECK_EQUAL( + std::string(config->getName()), + expectedConfigName + ); + } + OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); + } + + { + // Testing CreateFromFile using URI Syntax. + + OCIO::ConstConfigRcPtr config; + OCIO_CHECK_NO_THROW( + config = OCIO::Config::CreateFromFile(uri.c_str()) + ); + OCIO_REQUIRE_ASSERT(config); + + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(config->validate()); + OCIO::muteInactiveColorspaceInfo(logGuard); + + if (!expectedConfigName.empty()) + { + OCIO_CHECK_EQUAL( + std::string(config->getName()), + expectedConfigName + ); + } + OCIO_CHECK_EQUAL(config->getNumColorSpaces(), numberOfExpectedColorspaces); + } + }; + + const std::string uriPrefix = OCIO::OCIO_BUILTIN_URI_PREFIX; + const std::string cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1"; + const std::string studioConfigName = "studio-config-v1.0.0_aces-v1.3_ocio-v2.1"; + const std::string defaultName = BUILTIN_DEFAULT_NAME; + const std::string latestCGName = BUILTIN_LATEST_CG_NAME; + const std::string latestStudioName = BUILTIN_LATEST_STUDIO_NAME; + + int nbOfColorspacesForCGConfig = 14; + int nbOfColorspacesForStudioConfig = 39; + + // Test that CreateFromFile does not work without ocio:// prefix for built-in config. + OCIO_CHECK_THROW_WHAT( + OCIO::Config::CreateFromFile(cgConfigName.c_str()), + OCIO::Exception, + "Error could not read 'cg-config-v1.0.0_aces-v1.3_ocio-v2.1' OCIO profile." + ); + + // Test CG config. + testFromBuiltinConfig(cgConfigName, nbOfColorspacesForCGConfig, ""); + testFromEnvAndFromFile(uriPrefix + cgConfigName, nbOfColorspacesForCGConfig, cgConfigName); + + // Test STUDIO config. + testFromBuiltinConfig(studioConfigName, nbOfColorspacesForStudioConfig, ""); + testFromEnvAndFromFile(uriPrefix + studioConfigName, nbOfColorspacesForStudioConfig, studioConfigName); + + // Test default config. + testFromBuiltinConfig(defaultName, nbOfColorspacesForCGConfig, cgConfigName); + testFromBuiltinConfig(uriPrefix + defaultName, nbOfColorspacesForCGConfig, cgConfigName); + testFromEnvAndFromFile(uriPrefix + defaultName, nbOfColorspacesForCGConfig, cgConfigName); + + // Test cg-config-latest. + testFromBuiltinConfig(latestCGName, nbOfColorspacesForCGConfig, cgConfigName); + testFromBuiltinConfig(uriPrefix + latestCGName, nbOfColorspacesForCGConfig, cgConfigName); + testFromEnvAndFromFile(uriPrefix + latestCGName, nbOfColorspacesForCGConfig, cgConfigName); + + // Test studio-config-latest. + testFromBuiltinConfig(latestStudioName, nbOfColorspacesForStudioConfig, studioConfigName); + testFromBuiltinConfig(uriPrefix + latestStudioName, nbOfColorspacesForStudioConfig, studioConfigName); + testFromEnvAndFromFile(uriPrefix + latestStudioName, nbOfColorspacesForStudioConfig, studioConfigName); + + // ******************************** + // Test some expected failures. + // ******************************** + + // Test CreateFromBuiltinConfig with an unknown built-in config name. + OCIO_CHECK_THROW_WHAT( + OCIO::Config::CreateFromBuiltinConfig("I-do-not-exist"), + OCIO::Exception, + "Could not find 'I-do-not-exist' in the built-in configurations." + ); + + // Test CreateFromFile with an unknown built-in config name using URI syntax. + OCIO_CHECK_THROW_WHAT( + OCIO::Config::CreateFromFile("ocio://I-do-not-exist"), + OCIO::Exception, + "Could not find 'I-do-not-exist' in the built-in configurations." + ); + + { + // Testing CreateFromEnv with an unknown built-in config. + + OCIO::EnvironmentVariableGuard guard("OCIO", "ocio://thedefault"); + + OCIO_CHECK_THROW_WHAT( + OCIO::Config::CreateFromEnv(), + OCIO::Exception, + "Could not find 'thedefault' in the built-in configurations." + ); + } +} + +OCIO_ADD_TEST(BuiltinConfigs, resolve_config_path) +{ + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("ocio://default"), + std::string(DEFAULT_BUILTIN_CONFIG_URI) + ); + + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("ocio://cg-config-latest"), + std::string(LATEST_CG_BUILTIN_CONFIG_URI) + ); + + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("ocio://studio-config-latest"), + std::string(LATEST_STUDIO_BUILTIN_CONFIG_URI) + ); + + + // ****************************************************************************** + // Paths that are not starting with "ocio://" are simply returned unmodified. + // ****************************************************************************** + + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("studio-config-latest"), + std::string("studio-config-latest") + ); + + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("studio-config-latest.ocio"), + std::string("studio-config-latest.ocio") + ); + + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("/usr/local/share/aces.ocio"), + std::string("/usr/local/share/aces.ocio") + ); + + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("C:\\myconfig\\config.ocio"), + std::string("C:\\myconfig\\config.ocio") + ); + + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath(""), + std::string("") + ); + + // ***************************************************** + // The function does not try to validate to catch + // mistakes in URI usage. That's up to the application. + // ***************************************************** + + // Unknown built-in config. + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("ocio://not-a-builtin"), + std::string("ocio://not-a-builtin") + ); + + // Missing "//". + OCIO_CHECK_EQUAL( + OCIO::ResolveConfigPath("ocio:default"), + std::string("ocio:default") + ); +} \ No newline at end of file diff --git a/tests/python/ConfigTest.py b/tests/python/ConfigTest.py index ebc170c3df..f88eb736be 100644 --- a/tests/python/ConfigTest.py +++ b/tests/python/ConfigTest.py @@ -905,104 +905,85 @@ def test_virtual_display(self): self.assertEqual(0, len(cfg.getVirtualDisplayViews(OCIO.VIEW_SHARED))) def test_create_builtin_config(self): - # ******************************** - # Testing CG config. - # ******************************** - numberOfExpectedColorspaces = 14 - # Testing CreateFromBuiltinConfig with a known built-in config name. - builtinCfgA = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1") + def testFromBuiltinConfig(name, numberOfExpectedColorspaces, expectedConfigName): + # Testing CreateFromBuiltinConfig with a known built-in config name. + builtinCfgA = OCIO.Config.CreateFromBuiltinConfig(name) - # Mute output related to a bug in the initial CG config where the inactive_colorspaces - # list has color spaces that don't exist. - log = MuteLogging() - with log: - builtinCfgA.validate() + # Mute output related to a bug in the initial CG config where the inactive_colorspaces + # list has color spaces that don't exist. + log = MuteLogging() + with log: + builtinCfgA.validate() - self.assertEqual(builtinCfgA.getName(), "cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - self.assertEqual(len(builtinCfgA.getColorSpaceNames()), numberOfExpectedColorspaces) + self.assertEqual(builtinCfgA.getName(), expectedConfigName if expectedConfigName else name) + self.assertEqual(len(builtinCfgA.getColorSpaceNames()), numberOfExpectedColorspaces) - # Testing CreateFromEnv with an known built-in config name using URI Syntax. - try: - OCIO.SetEnvVariable('OCIO', 'ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1') - builtinCfgB = OCIO.Config.CreateFromEnv() + def testFromEnvAndFromFile(uri, numberOfExpectedColorspaces, expectedConfigName): + # Testing CreateFromEnv using URI Syntax. + try: + OCIO.SetEnvVariable('OCIO', uri) + builtinCfgB = OCIO.Config.CreateFromEnv() - log = MuteLogging() - with log: - builtinCfgB.validate() + log = MuteLogging() + with log: + builtinCfgB.validate() - self.assertEqual(builtinCfgB.getName(), "cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - self.assertEqual(len(builtinCfgB.getColorSpaceNames()), numberOfExpectedColorspaces) - finally: - OCIO.UnsetEnvVariable('OCIO') + self.assertEqual(builtinCfgB.getName(), expectedConfigName) + self.assertEqual(len(builtinCfgB.getColorSpaceNames()), numberOfExpectedColorspaces) + finally: + OCIO.UnsetEnvVariable('OCIO') - # Testing CreateFromFile with an known built-in config name using URI Syntax. - builtinCfgC = OCIO.Config.CreateFromFile("ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1") + # Testing CreateFromFile using URI Syntax. + builtinCfgC = OCIO.Config.CreateFromFile(uri) - log = MuteLogging() - with log: - builtinCfgC.validate() + log = MuteLogging() + with log: + builtinCfgC.validate() - self.assertEqual(builtinCfgC.getName(), "cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - self.assertEqual(len(builtinCfgC.getColorSpaceNames()), numberOfExpectedColorspaces) + self.assertEqual(builtinCfgC.getName(), expectedConfigName) + self.assertEqual(len(builtinCfgC.getColorSpaceNames()), numberOfExpectedColorspaces) - # ******************************** - # Testing STUDIO config. - # ******************************** + uriPrefix = OCIO.OCIO_BUILTIN_URI_PREFIX; + cgConfigName = "cg-config-v1.0.0_aces-v1.3_ocio-v2.1" + studioConfigName = "studio-config-v1.0.0_aces-v1.3_ocio-v2.1" + defaultName = "default" + latestCGName = "cg-config-latest" + latestStudioName = "studio-config-latest" - numberOfExpectedColorspaces = 39 - # Testing CreateFromBuiltinConfig with a known built-in config name. - builtinCfgA = OCIO.Config.CreateFromBuiltinConfig("studio-config-v1.0.0_aces-v1.3_ocio-v2.1") - builtinCfgA.validate() - self.assertEqual(builtinCfgA.getName(), "studio-config-v1.0.0_aces-v1.3_ocio-v2.1") - self.assertEqual(len(builtinCfgA.getColorSpaceNames()), numberOfExpectedColorspaces) + nbOfColorspacesForCGConfig = 14 + nbOfColorspacesForStudioConfig = 39 - # Testing CreateFromEnv with an known built-in config name using URI Syntax. - try: - OCIO.SetEnvVariable('OCIO', 'ocio://studio-config-v1.0.0_aces-v1.3_ocio-v2.1') - builtinCfgB = OCIO.Config.CreateFromEnv() - builtinCfgB.validate() - self.assertEqual(builtinCfgB.getName(), "studio-config-v1.0.0_aces-v1.3_ocio-v2.1") - self.assertEqual(len(builtinCfgB.getColorSpaceNames()), numberOfExpectedColorspaces) - finally: - OCIO.UnsetEnvVariable('OCIO') + # Test that CreateFromFile does not work without ocio:// prefix for built-in config. + with self.assertRaises(OCIO.Exception) as cm: + OCIO.Config.CreateFromFile(cgConfigName) - # Testing CreateFromFile with an known built-in config name using URI Syntax. - builtinCfgC = OCIO.Config.CreateFromFile("ocio://studio-config-v1.0.0_aces-v1.3_ocio-v2.1") - builtinCfgC.validate() - self.assertEqual(builtinCfgC.getName(), "studio-config-v1.0.0_aces-v1.3_ocio-v2.1") - self.assertEqual(len(builtinCfgC.getColorSpaceNames()), numberOfExpectedColorspaces) + # Test CG config. + testFromBuiltinConfig(cgConfigName, nbOfColorspacesForCGConfig, "") + testFromEnvAndFromFile(uriPrefix + cgConfigName, nbOfColorspacesForCGConfig, cgConfigName) - # ******************************** - # Testing default config. - # ******************************** - - # Testing CreateFromEnv with the default config using URI Syntax. - try: - OCIO.SetEnvVariable('OCIO', 'ocio://default') - builtinCfgD = OCIO.Config.CreateFromEnv() + # Test STUDIO config. + testFromBuiltinConfig(studioConfigName, nbOfColorspacesForStudioConfig, "") + testFromEnvAndFromFile(uriPrefix + studioConfigName, nbOfColorspacesForStudioConfig, studioConfigName) - log = MuteLogging() - with log: - builtinCfgD.validate() + # Test default config. + testFromBuiltinConfig(defaultName, nbOfColorspacesForCGConfig, cgConfigName) + testFromBuiltinConfig(uriPrefix + defaultName, nbOfColorspacesForCGConfig, cgConfigName) + testFromEnvAndFromFile(uriPrefix + defaultName, nbOfColorspacesForCGConfig, cgConfigName) - self.assertEqual(builtinCfgD.getName(), "cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - self.assertEqual(len(builtinCfgD.getColorSpaceNames()), 14) - finally: - OCIO.UnsetEnvVariable('OCIO') + # Test cg-config-latest. + testFromBuiltinConfig(latestCGName, nbOfColorspacesForCGConfig, cgConfigName) + testFromBuiltinConfig(uriPrefix + latestCGName, nbOfColorspacesForCGConfig, cgConfigName) + testFromEnvAndFromFile(uriPrefix + latestCGName, nbOfColorspacesForCGConfig, cgConfigName) - # Testing CreateFromFile with the default config using URI Syntax. - builtinCfgE = OCIO.Config.CreateFromFile("ocio://default") + # Test studio-config-latest. + testFromBuiltinConfig(latestStudioName, nbOfColorspacesForStudioConfig, studioConfigName) + testFromBuiltinConfig(uriPrefix + latestStudioName, nbOfColorspacesForStudioConfig, studioConfigName) + testFromEnvAndFromFile(uriPrefix + latestStudioName, nbOfColorspacesForStudioConfig, studioConfigName) - log = MuteLogging() - with log: - builtinCfgE.validate() - - self.assertEqual(builtinCfgE.getName(), "cg-config-v1.0.0_aces-v1.3_ocio-v2.1") - self.assertEqual(len(builtinCfgE.getColorSpaceNames()), 14) # ******************************** - # Testing some expected failures. + # Test some expected failures. # ******************************** # Testing CreateFromBuiltinConfig with an unknown built-in config name. @@ -1209,6 +1190,31 @@ def lutExists(filepath): processor = config.getProcessor("c1", "c2") processor.getDefaultCPUProcessor() + def test_resolve_config(self): + defaultBuiltinConfig = "ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1" + cgLatestBuiltinConfig = "ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1" + studioLatestBuiltinConfig = "ocio://studio-config-v1.0.0_aces-v1.3_ocio-v2.1" + + # Testing just a few built-in config path. + self.assertEqual( + OCIO.ResolveConfigPath("ocio://default"), + defaultBuiltinConfig + ) + + self.assertEqual( + OCIO.ResolveConfigPath("ocio://cg-config-latest"), + cgLatestBuiltinConfig + ) + + self.assertEqual( + OCIO.ResolveConfigPath("ocio://studio-config-latest"), + studioLatestBuiltinConfig + ) + + self.assertEqual( + OCIO.ResolveConfigPath("studio-config-latest.ocio"), + "studio-config-latest.ocio" + ) def test_inactive_colorspaces(self): config = OCIO.Config.CreateFromBuiltinConfig("cg-config-v1.0.0_aces-v1.3_ocio-v2.1")