-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG:
ParameterObject::WriteParameterFiles
should write all maps
With this commit `ParameterObject::WriteParameterFiles` writes _each_ maps to a file, including the first one. Aims to address issue #904 "ParameterObject::WriteParameterFiles does not write the first map!" A GoogleTest unit test is added, testing that each of the files specified by the `parameterFileNameVector` parameter is indeed written to disk.
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*========================================================================= | ||
* | ||
* Copyright UMC Utrecht and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0.txt | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*=========================================================================*/ | ||
|
||
// First include the header file to be tested: | ||
#include "elxParameterObject.h" | ||
|
||
#include "GTesting/elxGTestUtilities.h" | ||
|
||
#include "elxCoreMainGTestUtilities.h" | ||
#include "elxDefaultConstruct.h" | ||
|
||
// ITK header file: | ||
#include <itkFileTools.h> | ||
#include <itksys/SystemTools.hxx> | ||
|
||
// GoogleTest header file: | ||
#include <gtest/gtest.h> | ||
|
||
#include <string> | ||
|
||
// Type aliases: | ||
using ParameterMapType = elx::ParameterObject::ParameterMapType; | ||
using ParameterMapVectorType = elx::ParameterObject::ParameterMapVectorType; | ||
using ParameterFileNameVectorType = elx::ParameterObject::ParameterFileNameVectorType; | ||
|
||
// Using-declarations: | ||
using elx::CoreMainGTestUtilities::GetCurrentBinaryDirectoryPath; | ||
using elx::CoreMainGTestUtilities::GetNameOfTest; | ||
|
||
// Tests that ParameterObject::WriteParameterFiles writes all the specified files. | ||
GTEST_TEST(ParameterObject, WriteParameterFiles) | ||
{ | ||
const std::string rootOutputDirectoryPath = GetCurrentBinaryDirectoryPath() + '/' + GetNameOfTest(*this); | ||
itk::FileTools::CreateDirectory(rootOutputDirectoryPath); | ||
|
||
elx::DefaultConstruct<elx::ParameterObject> parameterObject{}; | ||
|
||
for (const std::size_t numberOfMaps : { 0, 1, 2 }) | ||
{ | ||
const std::string outputDirectoryPath = rootOutputDirectoryPath + '/' + std::to_string(numberOfMaps); | ||
itk::FileTools::CreateDirectory(outputDirectoryPath); | ||
|
||
parameterObject.SetParameterMaps(ParameterMapVectorType(numberOfMaps)); | ||
|
||
ParameterFileNameVectorType fileNames{}; | ||
|
||
for (std::size_t i{}; i < numberOfMaps; ++i) | ||
{ | ||
fileNames.push_back(outputDirectoryPath + '/' + "ParameterFile." + std::to_string(i) + ".txt"); | ||
} | ||
|
||
parameterObject.WriteParameterFiles(fileNames); | ||
|
||
// Check that each of the specified files is written to disk. | ||
for (const auto & fileName : fileNames) | ||
{ | ||
EXPECT_TRUE(itksys::SystemTools::FileExists(fileName.c_str(), true)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters