Skip to content

Commit

Permalink
Merge pull request #5079 from NREL/5076-Fix-static-XMLValidator-facto…
Browse files Browse the repository at this point in the history
…ries-temp-dir

Fix #5076 - /tmp/xmlvalidation directories not cleaned up for factory methods bclXMLValidator & gbxmlValidator
  • Loading branch information
jmarrec committed Jan 16, 2024
2 parents ecdc636 + c103518 commit 777fba9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/utilities/xml/Test/XMLValidator_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ TEST_F(XMLValidatorFixture, XMLValidator_schematronToXslt) {
EXPECT_TRUE(openstudio::filesystem::is_regular_file(expectedPath));
}

TEST_F(XMLValidatorFixture, XMLValidator_bclXMLValidator_Cleanup) {
openstudio::path tmpDir;
{
auto xmlValidator = XMLValidator::bclXMLValidator(BCLXMLType::MeasureXML, VersionString(3, 1));
tmpDir = xmlValidator.schemaPath().parent_path();
EXPECT_TRUE(openstudio::filesystem::exists(tmpDir));
EXPECT_TRUE(openstudio::filesystem::is_directory(tmpDir));
}
// #5076 - XMLValidator's dtor should clean up the tmpDir
EXPECT_FALSE(openstudio::filesystem::exists(tmpDir)) << "Expected tmpDir to be deleted: " << tmpDir;
}

TEST_F(XMLValidatorFixture, XMLValidator_gbxmlValidator_Cleanup) {
openstudio::path tmpDir;
{
auto xmlValidator = XMLValidator::gbxmlValidator();
tmpDir = xmlValidator.schemaPath().parent_path();
EXPECT_TRUE(openstudio::filesystem::exists(tmpDir));
EXPECT_TRUE(openstudio::filesystem::is_directory(tmpDir));
}
// #5076 - XMLValidator's dtor should clean up the tmpDir
EXPECT_FALSE(openstudio::filesystem::exists(tmpDir)) << "Expected tmpDir to be deleted: " << tmpDir;
}

TEST_P(GbXMLValidatorParametrizedFixture, XMLValidator_GBXMLvalidator_XSD) {
const auto& [filename, n_warnings, n_errors] = GetParam();

Expand Down
8 changes: 6 additions & 2 deletions src/utilities/xml/XMLValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ XMLValidator XMLValidator::gbxmlValidator() {
}
const bool quiet = true;
::openstudio::embedded_files::extractFile(":/xml/resources/GreenBuildingXML_Ver7.03.xsd", openstudio::toString(tmpDir), quiet);
return XMLValidator(tmpDir / "GreenBuildingXML_Ver7.03.xsd");
auto validator = XMLValidator(tmpDir / "GreenBuildingXML_Ver7.03.xsd");
validator.m_tempDir = tmpDir;
return validator;
}

XMLValidator XMLValidator::bclXMLValidator(openstudio::BCLXMLType bclXMLType, const VersionString& schemaVersion) {
Expand Down Expand Up @@ -510,7 +512,9 @@ XMLValidator XMLValidator::bclXMLValidator(openstudio::BCLXMLType bclXMLType, co

const bool quiet = true;
::openstudio::embedded_files::extractFile(fmt::format(":/xml/resources/bcl/{}", schemaName), openstudio::toString(tmpDir), quiet);
return XMLValidator(tmpDir / schemaName);
auto validator = XMLValidator(tmpDir / schemaName);
validator.m_tempDir = tmpDir;
return validator;
}

} // namespace openstudio

0 comments on commit 777fba9

Please sign in to comment.