From e91fa76b9e80d88077c54c54c0aeb7aef4c956f5 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Thu, 26 Sep 2019 19:50:00 +0200 Subject: [PATCH] Add tests for editconf file conversion with indexing The indexed output to gro files illustrates bug #3107 Fixed two memory leaks necessary to let the tests pass Refs #3107 Change-Id: Ie61430210ac8a804fb86783c8b76c41333b8d3cf --- src/gromacs/gmxpreprocess/editconf.cpp | 2 ++ src/gromacs/gmxpreprocess/tests/editconf.cpp | 41 +++++++++++++-------- src/gromacs/gmxpreprocess/tests/fragment1.ndx | 3 ++ ...atchingOutputStructureFileUsingIndexGroup_0.xml | 40 +++++++++++++++++++++ ...atchingOutputStructureFileUsingIndexGroup_1.xml | 37 +++++++++++++++++++ ...atchingOutputStructureFileUsingIndexGroup_2.xml | 42 ++++++++++++++++++++++ ...atchingOutputStructureFileUsingIndexGroup_3.xml | 40 +++++++++++++++++++++ ...atchingOutputStructureFileUsingIndexGroup_4.xml | 37 +++++++++++++++++++ ...atchingOutputStructureFileUsingIndexGroup_5.xml | 42 ++++++++++++++++++++++ ...atchingOutputStructureFileUsingIndexGroup_6.xml | 40 +++++++++++++++++++++ ...atchingOutputStructureFileUsingIndexGroup_7.xml | 37 +++++++++++++++++++ ...atchingOutputStructureFileUsingIndexGroup_8.xml | 42 ++++++++++++++++++++++ 12 files changed, 388 insertions(+), 15 deletions(-) create mode 100644 src/gromacs/gmxpreprocess/tests/fragment1.ndx create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_0.xml create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_1.xml create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_2.xml create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_3.xml create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_4.xml create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_5.xml create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_6.xml create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_7.xml create mode 100644 src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_8.xml diff --git a/src/gromacs/gmxpreprocess/editconf.cpp b/src/gromacs/gmxpreprocess/editconf.cpp index bbec8d7fc9..b51a984a11 100644 --- a/src/gromacs/gmxpreprocess/editconf.cpp +++ b/src/gromacs/gmxpreprocess/editconf.cpp @@ -1273,6 +1273,8 @@ int gmx_editconf(int argc, char *argv[]) { write_sto_conf_indexed(outfile, name, &atoms, x, bHaveV ? v : nullptr, ePBC, box, isize, index); } + sfree(grpname); + sfree(index); } else { diff --git a/src/gromacs/gmxpreprocess/tests/editconf.cpp b/src/gromacs/gmxpreprocess/tests/editconf.cpp index 75743dbd83..d4a2953322 100644 --- a/src/gromacs/gmxpreprocess/tests/editconf.cpp +++ b/src/gromacs/gmxpreprocess/tests/editconf.cpp @@ -71,35 +71,46 @@ class EditconfTest : public test::CommandLineTestBase, public: EditconfTest() { + const auto ¶ms = GetParam(); + setInputFile("-f", std::get<0>(params)); + + std::string outputfile = "output."; + outputfile += ftp2ext(std::get<1>(params)); + ExactTextMatch settings; + setOutputFile("-o", outputfile.c_str(), TextFileMatch(settings)); } - void runTest(const CommandLine &args) + void runTest(const char *testName) { + // Get the command line flags that were set up in the constructor CommandLine &cmdline = commandLine(); - cmdline.merge(args); - TestReferenceChecker rootChecker(this->rootChecker()); + // Provide the name of the module to call + std::string module[] = { + "editconf" + }; + cmdline.merge(CommandLine(module)); + // Call the module ASSERT_EQ(0, gmx_editconf(cmdline.argc(), cmdline.argv())); - auto extension = ftp2ext(std::get<1>(GetParam())); - rootChecker.checkString(extension, "Output file type"); + // Check the output + auto extension = ftp2ext(std::get<1>(GetParam())); + TestReferenceChecker rootChecker(this->rootChecker()); + rootChecker.checkString(extension, testName); checkOutputFiles(); } }; TEST_P(EditconfTest, ProducesMatchingOutputStructureFile) { - const auto ¶ms = GetParam(); - std::string cmdline[] = { - "editconf" - }; - setInputFile("-f", std::get<0>(params)); - std::string outputfile = "output."; - outputfile += ftp2ext(std::get<1>(params)); - ExactTextMatch settings; - setOutputFile("-o", outputfile.c_str(), TextFileMatch(settings)); - runTest(CommandLine(cmdline)); + runTest("Output file type"); +} + +TEST_P(EditconfTest, ProducesMatchingOutputStructureFileUsingIndexGroup) +{ + setInputFile("-n", "fragment1.ndx"); + runTest("Output file type using index group"); } // TODO These reproduce slightly differently in double precision, and diff --git a/src/gromacs/gmxpreprocess/tests/fragment1.ndx b/src/gromacs/gmxpreprocess/tests/fragment1.ndx new file mode 100644 index 0000000000..80eab3e616 --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/fragment1.ndx @@ -0,0 +1,3 @@ +[ two_residues ] + 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 + 28 29 30 31 32 33 34 35 diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_0.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_0.xml new file mode 100644 index 0000000000..1ba873791a --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_0.xml @@ -0,0 +1,40 @@ + + + + pdb + + + + + + diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_1.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_1.xml new file mode 100644 index 0000000000..c671f6084f --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_1.xml @@ -0,0 +1,37 @@ + + + + gro + + + + + + diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_2.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_2.xml new file mode 100644 index 0000000000..40826d51cc --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_2.xml @@ -0,0 +1,42 @@ + + + + g96 + + + + + + diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_3.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_3.xml new file mode 100644 index 0000000000..dbb354748f --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_3.xml @@ -0,0 +1,40 @@ + + + + pdb + + + + + + diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_4.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_4.xml new file mode 100644 index 0000000000..c671f6084f --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_4.xml @@ -0,0 +1,37 @@ + + + + gro + + + + + + diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_5.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_5.xml new file mode 100644 index 0000000000..237a087dde --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_5.xml @@ -0,0 +1,42 @@ + + + + g96 + + + + + + diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_6.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_6.xml new file mode 100644 index 0000000000..dbb354748f --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_6.xml @@ -0,0 +1,40 @@ + + + + pdb + + + + + + diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_7.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_7.xml new file mode 100644 index 0000000000..c671f6084f --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_7.xml @@ -0,0 +1,37 @@ + + + + gro + + + + + + diff --git a/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_8.xml b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_8.xml new file mode 100644 index 0000000000..237a087dde --- /dev/null +++ b/src/gromacs/gmxpreprocess/tests/refdata/SinglePeptideFragments_EditconfTest_ProducesMatchingOutputStructureFileUsingIndexGroup_8.xml @@ -0,0 +1,42 @@ + + + + g96 + + + + + + -- 2.11.4.GIT