utJoinVertices.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "UnitTestPCH.h"
  2. #include <assimp/scene.h>
  3. #include <JoinVerticesProcess.h>
  4. using namespace std;
  5. using namespace Assimp;
  6. class JoinVerticesTest : public ::testing::Test
  7. {
  8. public:
  9. virtual void SetUp();
  10. virtual void TearDown();
  11. protected:
  12. JoinVerticesProcess* piProcess;
  13. aiMesh* pcMesh;
  14. };
  15. // ------------------------------------------------------------------------------------------------
  16. void JoinVerticesTest::SetUp()
  17. {
  18. // construct the process
  19. piProcess = new JoinVerticesProcess();
  20. // create a quite small mesh for testing purposes -
  21. // the mesh itself is *something* but it has redundant vertices
  22. pcMesh = new aiMesh();
  23. pcMesh->mNumVertices = 900;
  24. aiVector3D*& pv = pcMesh->mVertices = new aiVector3D[900];
  25. for (unsigned int i = 0; i < 3;++i)
  26. {
  27. const unsigned int base = i*300;
  28. for (unsigned int a = 0; a < 300;++a)
  29. {
  30. pv[base+a].x = pv[base+a].y = pv[base+a].z = (float)a;
  31. }
  32. }
  33. // generate faces - each vertex is referenced once
  34. pcMesh->mNumFaces = 300;
  35. pcMesh->mFaces = new aiFace[300];
  36. for (unsigned int i = 0,p = 0; i < 300;++i)
  37. {
  38. aiFace& face = pcMesh->mFaces[i];
  39. face.mIndices = new unsigned int[ face.mNumIndices = 3 ];
  40. for (unsigned int a = 0; a < 3;++a)
  41. face.mIndices[a] = p++;
  42. }
  43. // generate extra members - set them to zero to make sure they're identical
  44. pcMesh->mTextureCoords[0] = new aiVector3D[900];
  45. for (unsigned int i = 0; i < 900;++i)pcMesh->mTextureCoords[0][i] = aiVector3D( 0.f );
  46. pcMesh->mNormals = new aiVector3D[900];
  47. for (unsigned int i = 0; i < 900;++i)pcMesh->mNormals[i] = aiVector3D( 0.f );
  48. pcMesh->mTangents = new aiVector3D[900];
  49. for (unsigned int i = 0; i < 900;++i)pcMesh->mTangents[i] = aiVector3D( 0.f );
  50. pcMesh->mBitangents = new aiVector3D[900];
  51. for (unsigned int i = 0; i < 900;++i)pcMesh->mBitangents[i] = aiVector3D( 0.f );
  52. }
  53. // ------------------------------------------------------------------------------------------------
  54. void JoinVerticesTest::TearDown()
  55. {
  56. delete this->pcMesh;
  57. delete this->piProcess;
  58. }
  59. // ------------------------------------------------------------------------------------------------
  60. TEST_F(JoinVerticesTest, testProcess)
  61. {
  62. // execute the step on the given data
  63. piProcess->ProcessMesh(pcMesh,0);
  64. // the number of faces shouldn't change
  65. ASSERT_EQ(300U, pcMesh->mNumFaces);
  66. ASSERT_EQ(300U, pcMesh->mNumVertices);
  67. ASSERT_TRUE(NULL != pcMesh->mNormals);
  68. ASSERT_TRUE(NULL != pcMesh->mTangents);
  69. ASSERT_TRUE(NULL != pcMesh->mBitangents);
  70. ASSERT_TRUE(NULL != pcMesh->mTextureCoords[0]);
  71. // the order doesn't care
  72. float fSum = 0.f;
  73. for (unsigned int i = 0; i < 300;++i)
  74. {
  75. aiVector3D& v = pcMesh->mVertices[i];
  76. fSum += v.x + v.y + v.z;
  77. EXPECT_FALSE(pcMesh->mNormals[i].x);
  78. EXPECT_FALSE(pcMesh->mTangents[i].x);
  79. EXPECT_FALSE(pcMesh->mBitangents[i].x);
  80. EXPECT_FALSE(pcMesh->mTextureCoords[0][i].x);
  81. }
  82. EXPECT_EQ(150.f*299.f*3.f, fSum); // gaussian sum equation
  83. }