Add preprocessing and integration test for transformation coordinate
[alexxy/gromacs.git] / src / programs / mdrun / tests / grompp.cpp
index c81c1ee8c68386430c7cdb037948769d8a398574..de7d8598eba7b196b5468ebfed72b32b682bbffe 100644 (file)
  */
 #include "gmxpre.h"
 
+#include "gromacs/utility/stringutil.h"
+#include "gromacs/gmxpreprocess/readir.h"
+
 #include <gtest/gtest.h>
 
 #include "moduletest.h"
 
+#include "testutils/testexceptions.h"
+
 namespace
 {
 
 //! Test fixture for grompp
-class GromppTest :
-    public gmx::test::MdrunTestFixture
+class GromppTest : public gmx::test::MdrunTestFixture
 {
-    public:
-        //! Execute the trajectory writing test
-        void runTest()
-        {
-            runner_.useTopGroAndNdxFromDatabase("spc-and-methanol");
-            EXPECT_EQ(0, runner_.callGrompp());
-        }
+public:
+    //! Execute the trajectory writing test
+    void runTest()
+    {
+        runner_.useTopGroAndNdxFromDatabase("spc-and-methanol");
+        EXPECT_EQ(0, runner_.callGrompp());
+    }
 };
 
 /* This test ensures that an empty .mdp file (ie. all default values) works. */
 TEST_F(GromppTest, EmptyMdpFileWorks)
 {
-    /* TODO Now that Verlet is the default, change the implementation
-       of useEmptyMdpFile() to do that. */
-    runner_.useStringAsMdpFile("");
+    runner_.useEmptyMdpFile();
     runTest();
 }
 
 /* Test for making sure grompp can handle simulated annealing data */
 TEST_F(GromppTest, SimulatedAnnealingWorks)
 {
-    runner_.useStringAsMdpFile("annealing = periodic\n"
-                               "annealing-npoints = 4\n"
-                               "annealing-time = 0 2 4 6\n"
-                               "annealing-temp = 298 320 320 298\n"
-                               );
+    runner_.useStringAsMdpFile(
+            "annealing = periodic\n"
+            "annealing-npoints = 4\n"
+            "annealing-time = 0 2 4 6\n"
+            "annealing-temp = 298 320 320 298\n");
     runTest();
 }
 
 TEST_F(GromppTest, SimulatedAnnealingWorksWithMultipleGroups)
 {
-    runner_.useStringAsMdpFile("tc-grps = Methanol SOL\n"
-                               "tau-t = 0.1 0.1\n"
-                               "ref_t = 298 298\n"
-                               "annealing = single periodic\n"
-                               "annealing-npoints = 3 4\n"
-                               "annealing-time = 0 3 6 0 2 4 6\n"
-                               "annealing-temp = 298 280 270 298 320 320 298\n"
-                               );
+    runner_.useStringAsMdpFile(
+            "tc-grps = Methanol SOL\n"
+            "tau-t = 0.1 0.1\n"
+            "ref_t = 298 298\n"
+            "annealing = single periodic\n"
+            "annealing-npoints = 3 4\n"
+            "annealing-time = 0 3 6 0 2 4 6\n"
+            "annealing-temp = 298 280 270 298 320 320 298\n");
+    runTest();
+}
+
+#if HAVE_MUPARSER
+
+TEST_F(GromppTest, ValidTransformationCoord)
+{
+    const char* inputMdpFile[] = {
+        "pull = yes",
+        "pull-ncoords = 2",
+        "pull-ngroups = 2",
+        "pull-group1-name = SOL",
+        "pull-group2-name = Methanol",
+        "pull-coord1-geometry = distance",
+        "pull-coord1-groups = 1 2",
+        "pull-coord2-geometry = transformation",
+        "pull-coord2-expression = x1", // Valid expression
+    };
+    runner_.useStringAsMdpFile(gmx::joinStrings(inputMdpFile, "\n"));
     runTest();
 }
 
+TEST_F(GromppTest, InvalidTransformationCoord)
+{
+    const char* inputMdpFile[] = {
+        "pull = yes",
+        "pull-ncoords = 2",
+        "pull-ngroups = 2",
+        "pull-group1-name = SOL",
+        "pull-group2-name = Methanol",
+        "pull-coord1-geometry = distance",
+        "pull-coord1-groups = 1 2",
+        "pull-coord2-geometry = transformation",
+        "pull-coord2-expression = x2", // Invalid expression -> evaluation should fail
+    };
+    runner_.useStringAsMdpFile(gmx::joinStrings(inputMdpFile, "\n"));
+    ASSERT_THROW(runTest(), gmx::InconsistentInputError);
+    done_inputrec_strings(); // This allows grompp to be called again in another test
+}
+#endif // HAVE_MUPARSER
+
 
 } // namespace