utJoinVertices.cpp 2.5 KB

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