@@ -768,6 +768,55 @@ OCIO_ADD_TEST(Config, serialize_searchpath)
768768 }
769769}
770770
771+ OCIO_ADD_TEST (Config, serialize_environment)
772+ {
773+ {
774+ OCIO::ConfigRcPtr config = OCIO::Config::Create ();
775+ config->setMajorVersion (1 );
776+ config->setMinorVersion (0 );
777+
778+ std::ostringstream os;
779+ config->serialize (os);
780+ StringUtils::StringVec osvec = StringUtils::SplitByLines (os.str ());
781+
782+ // A v1 config does not write the environment section if it's empty.
783+ const std::string expected{ " search_path: \"\" " };
784+ OCIO_CHECK_EQUAL (osvec[2 ], expected);
785+ }
786+ {
787+ OCIO::ConfigRcPtr config = OCIO::Config::Create ();
788+ config->setMajorVersion (2 );
789+ config->setMinorVersion (0 );
790+
791+ std::ostringstream os;
792+ config->serialize (os);
793+ StringUtils::StringVec osvec = StringUtils::SplitByLines (os.str ());
794+
795+ // A v2 config does write the environment section, even if it's empty.
796+ const std::string expected1{ " environment:" };
797+ const std::string expected2{ " {}" };
798+ OCIO_CHECK_EQUAL (osvec[2 ], expected1);
799+ OCIO_CHECK_EQUAL (osvec[3 ], expected2);
800+ }
801+ {
802+ OCIO::ConfigRcPtr config = OCIO::Config::Create ();
803+ config->setMajorVersion (1 );
804+ config->setMinorVersion (0 );
805+
806+ config->addEnvironmentVar (" SHOT" , " 0001" );
807+
808+ std::ostringstream os;
809+ config->serialize (os);
810+ StringUtils::StringVec osvec = StringUtils::SplitByLines (os.str ());
811+
812+ // A v1 config does write the environment section if it's not empty.
813+ const std::string expected1{ " environment:" };
814+ const std::string expected2{ " SHOT: 0001" };
815+ OCIO_CHECK_EQUAL (osvec[2 ], expected1);
816+ OCIO_CHECK_EQUAL (osvec[3 ], expected2);
817+ }
818+ }
819+
771820OCIO_ADD_TEST (Config, validation)
772821{
773822 {
0 commit comments