You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

90 lines
2.7 KiB

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