unittests_cpp_11_features.cc 6.62 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3

#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
4
//#include <OpenMesh/Tools/Smoother/JacobiLaplaceSmootherT.hh>
Jan Möbius's avatar
Jan Möbius committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

namespace {

class OpenMesh_Poly : public OpenMeshBasePoly {

    protected:

        // This function is called before each test is run
        virtual void SetUp() {

            // Do some initial stuff with the member data here...
        }

        // This function is called after all tests are through
        virtual void TearDown() {

            // Do some final stuff with the member data here...
        }

    // Member already defined in OpenMeshBase
    //Mesh mesh_;
};

class OpenMesh_Triangle : public OpenMeshBase {

    protected:

        // This function is called before each test is run
        virtual void SetUp() {

            // Do some initial stuff with the member data here...
        }

        // This function is called after all tests are through
        virtual void TearDown() {

            // Do some final stuff with the member data here...
        }

    // Member already defined in OpenMeshBase
    //Mesh mesh_;
};



/*
 * ====================================================================
 * Define tests below
 * ====================================================================
 */

xan's avatar
xan committed
56
#if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
Jan Möbius's avatar
Jan Möbius committed
57 58 59 60 61 62 63 64 65 66 67 68 69

/*
 */
TEST_F(OpenMesh_Triangle, cpp11_initializer_test) {

  OpenMesh::Vec3d vec1 = { 1, 0, 0};
  OpenMesh::Vec3d vec2 = {0, 0.777971, 0.996969};


  EXPECT_EQ( dot(vec1,vec2) ,0.0 );

}

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

// ////////////////////////////////////////////////////////////////////
// C++11 Range tests
// ////////////////////////////////////////////////////////////////////


/**
 * @brief TEST_F test the vertexrange behaviour on trimeshes
 */
TEST_F(OpenMesh_Triangle, cpp11_vertexrange_test) {
  //check empty vertexrange
  mesh_.clear();
  for(Mesh::VertexHandle t : mesh_.vertices())
  {
    FAIL() << "The Vertexrange for an empty Mesh is not empty";
85
    EXPECT_TRUE(t.is_valid()); // Just so we don't get an unused variable warning.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  }

  //add vertices to mesh
  mesh_.add_vertex(Mesh::Point(0, 1, 0));
  mesh_.add_vertex(Mesh::Point(1, 0, 0));
  mesh_.add_vertex(Mesh::Point(2, 1, 0));
  mesh_.add_vertex(Mesh::Point(0,-1, 0));
  mesh_.add_vertex(Mesh::Point(2,-1, 0));

  //check nonempty mesh vertexrange
  int iteration_counter = 0;
  for(Mesh::VertexHandle t : mesh_.vertices())
  {
    EXPECT_TRUE(t.is_valid());
    ++iteration_counter;
  }
  EXPECT_EQ(iteration_counter,5);
}

/**
 * @brief TEST_F test the vertexrange behaviour on polymeshes
 */
TEST_F(OpenMesh_Poly, cpp11_vertexrange_test) {
  //check empty vertexrange
  mesh_.clear();
  for(PolyMesh::VertexHandle t : mesh_.vertices())
  {
    FAIL() << "The Vertexrange for an empty Mesh is not empty";
114
    EXPECT_TRUE(t.is_valid()); // Just so we don't get an unused variable warning.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
  }

  //add vertices to mesh
  mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
  mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
  mesh_.add_vertex(PolyMesh::Point(2, 1, 0));
  mesh_.add_vertex(PolyMesh::Point(0,-1, 0));
  mesh_.add_vertex(PolyMesh::Point(2,-1, 0));

  //check nonempty mesh vertexrange
  int iteration_counter = 0;
  for(PolyMesh::VertexHandle t : mesh_.vertices())
  {
    EXPECT_TRUE(t.is_valid());
    ++iteration_counter;
  }
  EXPECT_EQ(iteration_counter,5);
}

/**
 * @brief TEST_F test vvrange behaviour on trimeshes
 */
137
TEST_F(OpenMesh_Triangle, cpp11_vvrange_test) {
138
  //check empty vv_range
139
  mesh_.clear();
140 141 142
  Mesh::VertexHandle vhandle[5];
  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
  for(Mesh::VertexHandle t : mesh_.vv_range(vhandle[0]))
143
  {
144
    FAIL() << "The vvrange for a single vertex in a TriMesh is not empty";
145
    EXPECT_TRUE(t.is_valid()); // Just so we don't get an unused variable warning.
146
  }
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190

  //add more vertices
  vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
  vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
  vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
  vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));

  // Add 4 faces
  std::vector<Mesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[1]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  //check nonempty vvrange
  int iteration_counter = 0;
  for(Mesh::VertexHandle t : mesh_.vv_range(vhandle[1]))
  {
    EXPECT_TRUE(t.is_valid());
    ++iteration_counter;
  }
  EXPECT_EQ(iteration_counter,4);
191 192
}

193 194 195
/**
 * @brief TEST_F test the vvrange behaviour on polymeshes
 */
196
TEST_F(OpenMesh_Poly, cpp11_vvrange_test) {
197
  //check empty vv_range
198
  mesh_.clear();
199 200 201 202 203
  Mesh::VertexHandle vhandle[5];
  vhandle[0] = mesh_.add_vertex(PolyMesh::Point(0, 1, 0));
  for(PolyMesh::VertexHandle t : mesh_.vv_range(vhandle[0]))
  {
    FAIL() << "The vvrange for a single vertex in a PolyMesh is not empty";
204
    EXPECT_TRUE(t.is_valid()); // Just so we don't get an unused variable warning.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
  }

  //add more vertices
  vhandle[1] = mesh_.add_vertex(PolyMesh::Point(1, 0, 0));
  vhandle[2] = mesh_.add_vertex(PolyMesh::Point(2, 1, 0));
  vhandle[3] = mesh_.add_vertex(PolyMesh::Point(0,-1, 0));
  vhandle[4] = mesh_.add_vertex(PolyMesh::Point(2,-1, 0));

  // Add 4 faces
  std::vector<PolyMesh::VertexHandle> face_vhandles;

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[2]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[0]);
  face_vhandles.push_back(vhandle[3]);
  face_vhandles.push_back(vhandle[1]);
  mesh_.add_face(face_vhandles);

  face_vhandles.clear();

  face_vhandles.push_back(vhandle[2]);
  face_vhandles.push_back(vhandle[1]);
  face_vhandles.push_back(vhandle[4]);
  mesh_.add_face(face_vhandles);

  //check nonempty vvrange
  int iteration_counter = 0;
  for(PolyMesh::VertexHandle t : mesh_.vv_range(vhandle[1]))
245
  {
246 247
    EXPECT_TRUE(t.is_valid());
    ++iteration_counter;
248
  }
249
  EXPECT_EQ(iteration_counter,4);
250 251
}

Jan Möbius's avatar
Jan Möbius committed
252 253 254
#endif

}