Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / selection / tests / poscalc.cpp
index 50f3325a76c5a9f8d95689fb73f8233da4a29410..1608a5b11b599847c823f1db12454413dfca30ca 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2013,2014, 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.
  *
  * GROMACS is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_selection
  */
-#include <gtest/gtest.h>
+#include "gmxpre.h"
+
+#include "gromacs/selection/poscalc.h"
 
 #include <vector>
 
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/legacyheaders/vec.h"
+#include <gtest/gtest.h>
 
+#include "gromacs/fileio/trx.h"
+#include "gromacs/math/vec.h"
 #include "gromacs/selection/indexutil.h"
-#include "gromacs/selection/poscalc.h"
 #include "gromacs/selection/position.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/uniqueptr.h"
 
 #include "testutils/refdata.h"
 
@@ -121,16 +125,17 @@ class PositionCalculationTest : public ::testing::Test
         gmx::PositionCalculationCollection  pcc_;
 
     private:
+        typedef gmx::gmx_unique_ptr<gmx_ana_pos_t>::type PositionPointer;
+
         struct PositionTest
         {
-            PositionTest() : pos(NULL), pc(NULL), name(NULL) {}
-            PositionTest(gmx_ana_pos_t *pos, gmx_ana_poscalc_t *pc,
+            PositionTest(PositionPointer pos, gmx_ana_poscalc_t *pc,
                          const char *name)
-                : pos(pos), pc(pc), name(name)
+                : pos(gmx::move(pos)), pc(pc), name(name)
             {
             }
 
-            gmx_ana_pos_t                  *pos;
+            PositionPointer                 pos;
             gmx_ana_poscalc_t              *pc;
             const char                     *name;
         };
@@ -160,12 +165,6 @@ PositionCalculationTest::~PositionCalculationTest()
     {
         gmx_ana_poscalc_free(*pci);
     }
-
-    PositionTestList::iterator pi;
-    for (pi = posList_.begin(); pi != posList_.end(); ++pi)
-    {
-        gmx_ana_pos_free(pi->pos);
-    }
 }
 
 void PositionCalculationTest::generateCoordinates()
@@ -212,11 +211,11 @@ gmx_ana_pos_t *
 PositionCalculationTest::initPositions(gmx_ana_poscalc_t *pc, const char *name)
 {
     posList_.reserve(posList_.size() + 1);
-    gmx_ana_pos_t *p;
-    snew(p, 1);
-    posList_.push_back(PositionTest(p, pc, name));
-    gmx_ana_poscalc_init_pos(pc, p);
-    return p;
+    PositionPointer p(new gmx_ana_pos_t());
+    gmx_ana_pos_t  *result = p.get();
+    posList_.push_back(PositionTest(gmx::move(p), pc, name));
+    gmx_ana_poscalc_init_pos(pc, result);
+    return result;
 }
 
 void PositionCalculationTest::checkInitialized()
@@ -226,7 +225,7 @@ void PositionCalculationTest::checkInitialized()
     PositionTestList::const_iterator pi;
     for (pi = posList_.begin(); pi != posList_.end(); ++pi)
     {
-        checkPositions(&compound, pi->name, pi->pos, false);
+        checkPositions(&compound, pi->name, pi->pos.get(), false);
     }
 }
 
@@ -234,8 +233,6 @@ void PositionCalculationTest::updateAndCheck(
         gmx_ana_poscalc_t *pc, gmx_ana_pos_t *p, int count, const int atoms[],
         gmx::test::TestReferenceChecker *checker, const char *name)
 {
-    // TODO: The group reference may get stored in p and stays there after this
-    // function returns.
     gmx_ana_index_t g;
     g.isize = count;
     g.index = const_cast<int *>(atoms);
@@ -313,12 +310,9 @@ void PositionCalculationTest::checkPositions(
         gmx::test::TestReferenceChecker *checker,
         const char *name, gmx_ana_pos_t *p, bool bCoordinates)
 {
-    EXPECT_EQ(p->nr, p->m.nr);
-    EXPECT_EQ(p->nr, p->m.mapb.nr);
-    ASSERT_TRUE(p->g != NULL);
     gmx::test::TestReferenceChecker compound(
             checker->checkCompound("Positions", name));
-    compound.checkInteger(p->nr, "Count");
+    compound.checkInteger(p->count(), "Count");
     const char *type = "???";
     switch (p->m.type)
     {
@@ -329,18 +323,14 @@ void PositionCalculationTest::checkPositions(
         case INDEX_ALL:     type = "single";    break;
     }
     compound.checkString(type, "Type");
-    compound.checkSequenceArray(p->nr + 1, p->m.mapb.index, "Block");
-    for (int i = 0; i < p->nr; ++i)
+    compound.checkSequenceArray(p->count() + 1, p->m.mapb.index, "Block");
+    for (int i = 0; i < p->count(); ++i)
     {
         gmx::test::TestReferenceChecker posCompound(
                 compound.checkCompound("Position", NULL));
-        // Always true; should satisfy clang.
-        if (p->g != NULL)
-        {
-            posCompound.checkSequence(&p->g->index[p->m.mapb.index[i]],
-                                      &p->g->index[p->m.mapb.index[i+1]],
-                                      "Atoms");
-        }
+        posCompound.checkSequence(&p->m.mapb.a[p->m.mapb.index[i]],
+                                  &p->m.mapb.a[p->m.mapb.index[i+1]],
+                                  "Atoms");
         posCompound.checkInteger(p->m.refid[i], "RefId");
         if (bCoordinates)
         {