Apply clang-format to source tree
[alexxy/gromacs.git] / src / testutils / tests / interactivetest.cpp
index eb1ac9914feea3f08121287dc16c47c806bd7089..21744bf4bdc884ff807eefb9e0fde7416f2eb151 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -57,84 +57,77 @@ namespace
 
 class InteractiveSession
 {
-    public:
-        explicit InteractiveSession(gmx::test::ReferenceDataMode mode)
-            : data_(mode), helper_(data_.rootChecker()), nextInputLine_(0)
-        {
-        }
+public:
+    explicit InteractiveSession(gmx::test::ReferenceDataMode mode) :
+        data_(mode),
+        helper_(data_.rootChecker()),
+        nextInputLine_(0)
+    {
+    }
 
-        void addOutput(const char *output)
-        {
-            events_.emplace_back(WriteOutput, output);
-        }
-        void addInputLine(const char *inputLine)
-        {
-            inputLines_.push_back(inputLine);
-        }
-        void addReadInput()
-        {
-            events_.emplace_back(ReadInput, "");
-        }
-        void addInput(const char *inputLine)
-        {
-            addInputLine(inputLine);
-            addReadInput();
-        }
-        void addInputNoNewline(const char *inputLine)
-        {
-            addInputLine(inputLine);
-            helper_.setLastNewline(false);
-            events_.emplace_back(ReadInputNoNewline, "");
-        }
+    void addOutput(const char* output) { events_.emplace_back(WriteOutput, output); }
+    void addInputLine(const char* inputLine) { inputLines_.push_back(inputLine); }
+    void addReadInput() { events_.emplace_back(ReadInput, ""); }
+    void addInput(const char* inputLine)
+    {
+        addInputLine(inputLine);
+        addReadInput();
+    }
+    void addInputNoNewline(const char* inputLine)
+    {
+        addInputLine(inputLine);
+        helper_.setLastNewline(false);
+        events_.emplace_back(ReadInputNoNewline, "");
+    }
 
-        void run()
+    void run()
+    {
+        gmx::TextInputStream&  input  = helper_.inputStream();
+        gmx::TextOutputStream& output = helper_.outputStream();
+        helper_.setInputLines(inputLines_);
+        std::vector<Event>::const_iterator event;
+        for (event = events_.begin(); event != events_.end(); ++event)
         {
-            gmx::TextInputStream              &input  = helper_.inputStream();
-            gmx::TextOutputStream             &output = helper_.outputStream();
-            helper_.setInputLines(inputLines_);
-            std::vector<Event>::const_iterator event;
-            for (event = events_.begin(); event != events_.end(); ++event)
+            if (event->first == WriteOutput)
             {
-                if (event->first == WriteOutput)
-                {
-                    output.write(event->second);
-                }
-                else
+                output.write(event->second);
+            }
+            else
+            {
+                std::string expectedLine;
+                const bool  bInputRemaining = (nextInputLine_ < inputLines_.size());
+                if (bInputRemaining)
                 {
-                    std::string expectedLine;
-                    const bool  bInputRemaining = (nextInputLine_ < inputLines_.size());
-                    if (bInputRemaining)
+                    expectedLine = inputLines_[nextInputLine_];
+                    if (event->first != ReadInputNoNewline)
                     {
-                        expectedLine = inputLines_[nextInputLine_];
-                        if (event->first != ReadInputNoNewline)
-                        {
-                            expectedLine.append("\n");
-                        }
+                        expectedLine.append("\n");
                     }
-                    ++nextInputLine_;
-                    std::string line;
-                    EXPECT_EQ(bInputRemaining, input.readLine(&line));
-                    EXPECT_EQ(expectedLine, line);
                 }
+                ++nextInputLine_;
+                std::string line;
+                EXPECT_EQ(bInputRemaining, input.readLine(&line));
+                EXPECT_EQ(expectedLine, line);
             }
-            helper_.checkSession();
         }
+        helper_.checkSession();
+    }
 
-    private:
-        enum EventType
-        {
-            ReadInput,
-            ReadInputNoNewline,
-            WriteOutput
-        };
-        // The latter is the output string.
-        typedef std::pair<EventType, const char *> Event;
+private:
+    enum EventType
+    {
+        ReadInput,
+        ReadInputNoNewline,
+        WriteOutput
+    };
+    // The latter is the output string.
+    typedef std::pair<EventType, const char*> Event;
 
-        gmx::test::TestReferenceData     data_;
-        gmx::test::InteractiveTestHelper helper_;
-        std::vector<const char *>        inputLines_;
-        size_t                           nextInputLine_;
-        std::vector<Event>               events_;
+    gmx::test::TestReferenceData     data_;
+    gmx::test::InteractiveTestHelper helper_;
+    std::vector<const char*>         inputLines_;
+    size_t                           nextInputLine_;
+    std::vector<Event>               events_;
 };
 
 TEST(InteractiveTestHelperTest, ChecksSimpleSession)