diff --git a/src/OpenColorIO/Config.cpp b/src/OpenColorIO/Config.cpp index 665d522390..c8f2a4bb83 100644 --- a/src/OpenColorIO/Config.cpp +++ b/src/OpenColorIO/Config.cpp @@ -1996,7 +1996,7 @@ void Config::validate() const { std::ostringstream os; os << "Inactive '" << name << "' is neither a color space nor a named transform."; - LogWarning(os.str()); + LogInfo(os.str()); } } } diff --git a/src/apps/ociocheck/main.cpp b/src/apps/ociocheck/main.cpp index c4298e1eaf..b3c8c33854 100644 --- a/src/apps/ociocheck/main.cpp +++ b/src/apps/ociocheck/main.cpp @@ -56,6 +56,9 @@ int main(int argc, const char **argv) return 1; } + // Set the logging level to INFO. + OCIO::SetLoggingLevel(OCIO::LOGGING_LEVEL_INFO); + try { OCIO::ConstConfigRcPtr srcConfig; diff --git a/tests/cpu/Config_tests.cpp b/tests/cpu/Config_tests.cpp index 362c69fc55..695625d6d9 100644 --- a/tests/cpu/Config_tests.cpp +++ b/tests/cpu/Config_tests.cpp @@ -357,51 +357,19 @@ OCIO_ADD_TEST(Config, required_roles_for_version_2_2) } { - // Test that all errors appears when all required roles are missing. + // Test that all errors appear when all required roles are missing. OCIO::LogGuard logGuard; OCIO_CHECK_NO_THROW(config->validate()); - - StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output()); - OCIO_CHECK_ASSERT( - StringUtils::Contain( - svec, - "[OpenColorIO Error]: The scene_linear role is required for a config version 2.2 "\ - "or higher." - ) - ); - - OCIO_CHECK_ASSERT( - StringUtils::Contain( - svec, - "[OpenColorIO Error]: The compositing_log role is required for a config version "\ - "2.2 or higher." - ) - ); - - OCIO_CHECK_ASSERT( - StringUtils::Contain( - svec, - "[OpenColorIO Error]: The color_timing role is required for a config version 2.2 "\ - "or higher." - ) - ); - - OCIO_CHECK_ASSERT( - StringUtils::Contain( - svec, - "[OpenColorIO Error]: The aces_interchange role is required when there are "\ - "scene-referred color spaces and the config version is 2.2 or higher." - ) - ); - - OCIO_CHECK_ASSERT( - StringUtils::Contain( - svec, - "[OpenColorIO Error]: The cie_xyz_d65_interchange role is required when there are"\ - " display-referred color spaces and the config version is 2.2 or higher." - ) - ); + // Check that the log contains the expected error messages for the missing roles and mute + // them so that (only) those messages don't appear in the test output. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteDisplayInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); } // Set colorspace for all required roles. @@ -416,11 +384,7 @@ OCIO_ADD_TEST(Config, required_roles_for_version_2_2) OCIO::LogGuard logGuard; OCIO_CHECK_NO_THROW(config->validate()); - - StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output()); - OCIO_CHECK_ASSERT( - !StringUtils::Contain(svec, "[OpenColorIO Error]") - ); + OCIO_CHECK_ASSERT(logGuard.empty()); } { @@ -454,12 +418,7 @@ OCIO_ADD_TEST(Config, required_roles_for_version_2_2) OCIO_CHECK_NO_THROW(config->validate()); StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output()); - OCIO_CHECK_ASSERT( - StringUtils::Contain( - svec, - "[OpenColorIO Error]: The compositing_log role is required for a config version 2.2 "\ - "or higher.") - ); + checkAndMuteCompositingLogRoleError(logGuard); // Set compositing_log for next test. config->setRole(OCIO::ROLE_COMPOSITING_LOG, dcs->getName()); @@ -475,12 +434,7 @@ OCIO_ADD_TEST(Config, required_roles_for_version_2_2) OCIO_CHECK_NO_THROW(config->validate()); StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output()); - OCIO_CHECK_ASSERT( - StringUtils::Contain( - svec, - "[OpenColorIO Error]: The color_timing role is required for a config version 2.2 or "\ - "higher.") - ); + checkAndMuteColorTimingRoleError(logGuard); // Set color_timing for next test. config->setRole(OCIO::ROLE_COLOR_TIMING, dcs->getName()); @@ -494,13 +448,7 @@ OCIO_ADD_TEST(Config, required_roles_for_version_2_2) OCIO::LogGuard logGuard; OCIO_CHECK_NO_THROW(config->validate()); - OCIO_CHECK_ASSERT( - StringUtils::StartsWith( - logGuard.output(), - "[OpenColorIO Error]: The aces_interchange role is required when there are "\ - "scene-referred color spaces and the config version is 2.2 or higher." - ) - ); + OCIO::checkAndMuteAcesInterchangeRoleError(logGuard); // Set aces_interchange for next test. config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, scs->getName()); @@ -514,21 +462,14 @@ OCIO_ADD_TEST(Config, required_roles_for_version_2_2) OCIO::LogGuard logGuard; OCIO_CHECK_NO_THROW(config->validate()); - - StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output()); - OCIO_CHECK_ASSERT( - StringUtils::Contain( - svec, - "[OpenColorIO Error]: The cie_xyz_d65_interchange role is required when there are "\ - "display-referred color spaces and the config version is 2.2 or higher.") - ); + OCIO::checkAndMuteDisplayInterchangeRoleError(logGuard); // Set cie_xyz_d65_interchange for next test. config->setRole(OCIO::ROLE_INTERCHANGE_DISPLAY, dcs->getName()); } { - // Test that aces_interchange role has the wrong colorspace type. + // Test detection of the aces_interchange role having the wrong colorspace type. // Set a display-referred colorspace to both interchange roles. config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, dcs->getName()); @@ -544,7 +485,7 @@ OCIO_ADD_TEST(Config, required_roles_for_version_2_2) } { - // Test that cie_xyz_d65_interchange role has the wrong colorspace type. + // Test detection of the cie_xyz_d65_interchange role having the wrong colorspace type. // Set a scene-referred colorspace to both interchange roles. config->setRole(OCIO::ROLE_INTERCHANGE_SCENE, scs->getName()); @@ -574,8 +515,7 @@ OCIO_ADD_TEST(Config, required_roles_for_version_2_2) OCIO::LogGuard logGuard; OCIO_CHECK_NO_THROW(config->validate()); - OCIO_CHECK_ASSERT( - StringUtils::StartsWith(logGuard.output(), "")); + OCIO_CHECK_ASSERT(logGuard.empty()); } } @@ -5906,7 +5846,7 @@ OCIO_ADD_TEST(Config, inactive_color_space_read_write) OCIO::LogGuard log; OCIO_CHECK_NO_THROW(config->validate()); OCIO_CHECK_EQUAL(log.output(), - "[OpenColorIO Warning]: Inactive 'unknown' is neither a color " + "[OpenColorIO Info]: Inactive 'unknown' is neither a color " "space nor a named transform.\n"); } @@ -6365,6 +6305,8 @@ OCIO_ADD_TEST(Config, display_view) config->addColorSpace(cs); } + config->setVersion(2, 1); + // Add a scene-referred and a display-referred color space. auto cs = OCIO::ColorSpace::Create(OCIO::REFERENCE_SPACE_SCENE); cs->setName("scs"); @@ -6406,7 +6348,7 @@ OCIO_ADD_TEST(Config, display_view) std::stringstream os; os << *config.get(); - constexpr char expected[]{ R"(ocio_profile_version: 2.2 + constexpr char expected[]{ R"(ocio_profile_version: 2.1 environment: {} @@ -9038,7 +8980,13 @@ OCIO_ADD_TEST(Config, create_builtin_config) ); 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 @@ -9055,7 +9003,11 @@ OCIO_ADD_TEST(Config, create_builtin_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 @@ -9072,7 +9024,11 @@ OCIO_ADD_TEST(Config, create_builtin_config) ); 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 @@ -9151,7 +9107,11 @@ OCIO_ADD_TEST(Config, create_builtin_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") @@ -9165,8 +9125,12 @@ OCIO_ADD_TEST(Config, create_builtin_config) 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") diff --git a/tests/cpu/FileRules_tests.cpp b/tests/cpu/FileRules_tests.cpp index 1163499418..0f6e7529be 100644 --- a/tests/cpu/FileRules_tests.cpp +++ b/tests/cpu/FileRules_tests.cpp @@ -1372,7 +1372,19 @@ strictparsing: true // Upgrading is making sure to build a valid v2 config. config->upgradeToLatestVersion(); - OCIO_CHECK_NO_THROW(config->validate()); + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(config->validate()); + // Check that the log contains the expected error messages for the missing roles and mute + // them so that (only) those messages don't appear in the test output. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } // Check the new version. @@ -1439,7 +1451,19 @@ strictparsing: true // Upgrading is making sure to build a valid v2 config. config->upgradeToLatestVersion(); - OCIO_CHECK_NO_THROW(config->validate()); + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(config->validate()); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } // Check the new version. @@ -1514,7 +1538,19 @@ strictparsing: true cfg->setInactiveColorSpaces("cs1"); cfg->upgradeToLatestVersion(); - OCIO_CHECK_NO_THROW(cfg->validate()); + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(cfg->validate()); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } // Check the new version. @@ -1554,7 +1590,18 @@ strictparsing: true l.output()); } - OCIO_CHECK_NO_THROW(cfg->validate()); + { + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(cfg->validate()); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } // Check the new version. @@ -1598,18 +1645,42 @@ OCIO_ADD_TEST(FileRules, config_v1_to_v2_from_memory) OCIO::ColorSpaceRcPtr raw = OCIO::ColorSpace::Create(); raw->setName("rAw"); config->addColorSpace(raw); - OCIO_CHECK_NO_THROW(config->validate()); // because file rules are not validated. + OCIO_CHECK_NO_THROW(config->validate()); // (does not fail since the major version is 1) // Default rule is using 'Default' role that does not exist. config->setMajorVersion(2); - OCIO_CHECK_THROW_WHAT(config->validate(), OCIO::Exception, "rule named 'Default' is " - "referencing 'default' that is neither a color space nor a named " - "transform"); + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_THROW_WHAT(config->validate(), OCIO::Exception, "rule named 'Default' is " + "referencing 'default' that is neither a color space nor a named " + "transform"); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } // Upgrading is making sure to build a valid v2 config. config->setMajorVersion(1); config->upgradeToLatestVersion(); - OCIO_CHECK_NO_THROW(config->validate()); + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(config->validate()); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } // Check the new version. @@ -1636,18 +1707,42 @@ OCIO_ADD_TEST(FileRules, config_v1_to_v2_from_memory) OCIO::ColorSpaceRcPtr raw = OCIO::ColorSpace::Create(); raw->setName("rAw"); config->addColorSpace(raw); - OCIO_CHECK_NO_THROW(config->validate()); // because file rules are not validated. + OCIO_CHECK_NO_THROW(config->validate()); // (does not fail since the major version is 1) // Default rule is using 'Default' role but the associated color space does not exist. config->setMajorVersion(2); - OCIO_CHECK_THROW_WHAT(config->validate(), OCIO::Exception, "rule named 'Default' is " - "referencing 'default' that is neither a color space nor a named " - "transform"); + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_THROW_WHAT(config->validate(), OCIO::Exception, "rule named 'Default' is " + "referencing 'default' that is neither a color space nor a named " + "transform"); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } // Upgrading is making sure to build a valid v2 config. config->setMajorVersion(1); config->upgradeToLatestVersion(); - OCIO_CHECK_NO_THROW(config->validate()); + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(config->validate()); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } // Check the new version. @@ -1673,32 +1768,56 @@ OCIO_ADD_TEST(FileRules, config_v1_to_v2_from_memory) OCIO::ColorSpaceRcPtr cs1 = OCIO::ColorSpace::Create(); cs1->setName("cs1"); config->addColorSpace(cs1); - OCIO_CHECK_NO_THROW(config->validate()); // because file rules are not validated. + OCIO_CHECK_NO_THROW(config->validate()); // (does not fail since the major version is 1) // Default rule is using 'Default' role but the associated color space does not exist. config->setInactiveColorSpaces("cs1"); config->setMajorVersion(2); - OCIO_CHECK_THROW_WHAT(config->validate(), OCIO::Exception, "rule named 'Default' is " - "referencing 'default' that is neither a color space nor a named " - "transform"); + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_THROW_WHAT(config->validate(), OCIO::Exception, "rule named 'Default' is " + "referencing 'default' that is neither a color space nor a named " + "transform"); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); + } config->setMajorVersion(1); - + { - OCIO::LogGuard l; - + OCIO::LogGuard logGuard; config->upgradeToLatestVersion(); - - OCIO_CHECK_EQUAL( - std::string("[OpenColorIO Warning]: The default rule creation falls back to the"\ - " first color space because no suitable color space exists.\n"), - l.output()); + StringUtils::StringVec svec = StringUtils::SplitByLines(logGuard.output()); + OCIO_CHECK_ASSERT( + StringUtils::Contain( + svec, + "[OpenColorIO Warning]: The default rule creation falls back to the"\ + " first color space because no suitable color space exists." + ) + ); + } + + { + OCIO::LogGuard logGuard; + OCIO_CHECK_NO_THROW(config->validate()); + // Ignore (only) the errors logged regarding the missing roles that are required in + // configs with version >= 2.2. + OCIO_CHECK_ASSERT(OCIO::checkAndMuteSceneLinearRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteCompositingLogRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteColorTimingRoleError(logGuard)); + OCIO_CHECK_ASSERT(OCIO::checkAndMuteAcesInterchangeRoleError(logGuard)); + // If there are any unexpected log messages, print them to the shell. + logGuard.print(); } - - OCIO_CHECK_NO_THROW(config->validate()); // Check the new version. - OCIO_CHECK_EQUAL(config->getMajorVersion(), 2); // Check the 'default' rule. As there is not 'data' or active color space, the default diff --git a/tests/cpu/UnitTestLogUtils.cpp b/tests/cpu/UnitTestLogUtils.cpp index 28a2d3ee55..6fd3896561 100644 --- a/tests/cpu/UnitTestLogUtils.cpp +++ b/tests/cpu/UnitTestLogUtils.cpp @@ -4,6 +4,11 @@ #include +#include +#include + +#include "Platform.h" +#include "testutils/UnitTest.h" #include "UnitTestLogUtils.h" namespace OCIO_NAMESPACE @@ -54,6 +59,45 @@ bool LogGuard::empty() const return g_output.empty(); } +// Find and remove specified line from g_output. +// Return true if found, otherwise, false. +bool LogGuard::findAndRemove(const std::string & line) const +{ + // Escape the line to prevent error in regex if the line contains regex character. + std::string escaped_line = std::regex_replace(line, std::regex("[\\[\\](){}*+?.^$|\\\\]"), "\\$&"); + std::regex pattern(escaped_line + R"([\r\n]+)"); + std::smatch match; + if (std::regex_search(g_output, match, pattern)) + { + // If the line is found, remove it. + auto pos = std::next(g_output.begin(), match.position()); + auto end = std::next(pos, match.length()); + g_output.erase(pos, end); + return true; + } + return false; +} + +bool LogGuard::findAllAndRemove(const std::string & sPattern) const +{ + bool found = false; + std::regex pattern(sPattern); + std::smatch match; + while (std::regex_search(g_output, match, pattern)) + { + found = true; + auto pos = std::next(g_output.begin(), match.position()); + auto end = std::next(pos, match.length()); + g_output.erase(pos, end); + } + return found; +} + +void LogGuard::print() +{ + std::cout << g_output; +} + MuteLogging::MuteLogging() { SetLoggingFunction(&MuteLoggingFunction); @@ -64,5 +108,49 @@ MuteLogging::~MuteLogging() ResetToDefaultLoggingFunction(); } +bool checkAndMuteSceneLinearRoleError(LogGuard & logGuard) +{ + const std::string interchange_scene = "[OpenColorIO Error]: The scene_linear role is "\ + "required for a config version 2.2 or higher."; + return logGuard.findAndRemove(interchange_scene); +} + +bool checkAndMuteCompositingLogRoleError(LogGuard & logGuard) +{ + const std::string compositing_log = "[OpenColorIO Error]: The compositing_log role is "\ + "required for a config version 2.2 or higher."; + return logGuard.findAndRemove(compositing_log); +} + +bool checkAndMuteColorTimingRoleError(LogGuard & logGuard) +{ + const std::string color_timing = "[OpenColorIO Error]: The color_timing role is required "\ + "for a config version 2.2 or higher."; + return logGuard.findAndRemove(color_timing); +} + +bool checkAndMuteAcesInterchangeRoleError(LogGuard & logGuard) +{ + const std::string aces_interchange = "[OpenColorIO Error]: The aces_interchange role is "\ + "required when there are scene-referred color spaces and "\ + "the config version is 2.2 or higher."; + return logGuard.findAndRemove(aces_interchange); +} + +bool checkAndMuteDisplayInterchangeRoleError(LogGuard & logGuard) +{ + const std::string interchange_display = "[OpenColorIO Error]: The cie_xyz_d65_interchange "\ + "role is required when there are display-referred "\ + "color spaces and the config version is 2.2 or higher."; + return logGuard.findAndRemove(interchange_display); +} + +void muteInactiveColorspaceInfo(LogGuard & logGuard) +{ + const std::string str = "- Display' is neither a color space nor a named transform."; + const std::string pattern = R"(^\[OpenColorIO Info\]: Inactive.*)" + str + R"([\r\n]+)"; + logGuard.findAllAndRemove(pattern); +} + } // namespace OCIO_NAMESPACE diff --git a/tests/cpu/UnitTestLogUtils.h b/tests/cpu/UnitTestLogUtils.h index aa961ba4a6..ba05ecf1f6 100644 --- a/tests/cpu/UnitTestLogUtils.h +++ b/tests/cpu/UnitTestLogUtils.h @@ -25,6 +25,9 @@ class LogGuard void clear(); bool empty() const; + bool findAndRemove(const std::string & str) const; + bool findAllAndRemove(const std::string & sPattern) const; + void print(); private: LoggingLevel m_logLevel; }; @@ -37,6 +40,14 @@ class MuteLogging ~MuteLogging(); }; +bool checkAndMuteSceneLinearRoleError(LogGuard & logGuard); +bool checkAndMuteCompositingLogRoleError(LogGuard & logGuard); +bool checkAndMuteColorTimingRoleError(LogGuard & logGuard); +bool checkAndMuteAcesInterchangeRoleError(LogGuard & logGuard); +bool checkAndMuteDisplayInterchangeRoleError(LogGuard & logGuard); + +void muteInactiveColorspaceInfo(LogGuard & logGuard); + } // namespace OCIO_NAMESPACE #endif // INCLUDED_OCIO_UNITTEST_LOGUTILS_H diff --git a/tests/cpu/transforms/builtins/BuiltinTransformRegistry_tests.cpp b/tests/cpu/transforms/builtins/BuiltinTransformRegistry_tests.cpp index 8eb529f06c..ceaed13ee0 100644 --- a/tests/cpu/transforms/builtins/BuiltinTransformRegistry_tests.cpp +++ b/tests/cpu/transforms/builtins/BuiltinTransformRegistry_tests.cpp @@ -105,7 +105,11 @@ strictparsing: true luma: [0.2126, 0.7152, 0.0722] roles: + aces_interchange: test + color_timing: test + compositing_log: test default: ref + scene_linear: test file_rules: - ! {name: Default, colorspace: default} diff --git a/tests/python/ConfigTest.py b/tests/python/ConfigTest.py index 1ea0e2d928..a687a5f0e2 100644 --- a/tests/python/ConfigTest.py +++ b/tests/python/ConfigTest.py @@ -11,7 +11,8 @@ SIMPLE_CONFIG_VIRTUAL_DISPLAY_ACTIVE_DISPLAY, SIMPLE_CONFIG_VIRTUAL_DISPLAY_V1, SIMPLE_CONFIG_VIRTUAL_DISPLAY_EXCEPTION, - TEST_DATAFILES_DIR) + TEST_DATAFILES_DIR, + MuteLogging) # Legacy tests kept for reference. # @@ -911,7 +912,13 @@ def test_create_builtin_config(self): 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") - 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) @@ -919,7 +926,11 @@ def test_create_builtin_config(self): try: OCIO.SetEnvVariable('OCIO', 'ocio://cg-config-v1.0.0_aces-v1.3_ocio-v2.1') builtinCfgB = OCIO.Config.CreateFromEnv() - 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: @@ -927,7 +938,11 @@ def test_create_builtin_config(self): # 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") - 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) @@ -935,7 +950,7 @@ def test_create_builtin_config(self): # Testing STUDIO config. # ******************************** - numberOfExpectedColorspaces = 39; + 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() @@ -966,7 +981,11 @@ def test_create_builtin_config(self): try: OCIO.SetEnvVariable('OCIO', 'ocio://default') builtinCfgD = OCIO.Config.CreateFromEnv() - builtinCfgD.validate() + + log = MuteLogging() + with log: + builtinCfgD.validate() + self.assertEqual(builtinCfgD.getName(), "cg-config-v1.0.0_aces-v1.3_ocio-v2.1") self.assertEqual(len(builtinCfgD.getColorSpaceNames()), 14) finally: @@ -974,7 +993,11 @@ def test_create_builtin_config(self): # Testing CreateFromFile with the default config using URI Syntax. builtinCfgE = OCIO.Config.CreateFromFile("ocio://default") - builtinCfgE.validate() + + 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) diff --git a/tests/python/UnitTestUtils.py b/tests/python/UnitTestUtils.py index 23d11d5a33..1b83c1cb92 100644 --- a/tests/python/UnitTestUtils.py +++ b/tests/python/UnitTestUtils.py @@ -2,6 +2,8 @@ import sys from random import randint +import PyOpenColorIO as OCIO + def assertEqualRGBM(testCase, first, second): testCase.assertEqual(first.red, second.red) testCase.assertEqual(first.green, second.green) @@ -65,6 +67,17 @@ def assertEqualRGBCurve(testCase, first, second): assertEqualBSpline(testCase, first.blue, second.blue) assertEqualBSpline(testCase, first.master, second.master) +class MuteLogging: + def __init__(self): + self.previous_function = None + + def __enter__(self): + self.previous_function = OCIO.SetLoggingFunction(lambda message: None) + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + OCIO.ResetToDefaultLoggingFunction() + # ----------------------------------------------------------------------------- # Python 2/3 compatibility # -----------------------------------------------------------------------------