utRemoveComponent.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "UnitTestPCH.h"
  2. #include <assimp/scene.h>
  3. #include <RemoveVCProcess.h>
  4. #include <MaterialSystem.h>
  5. using namespace std;
  6. using namespace Assimp;
  7. class RemoveVCProcessTest : public ::testing::Test
  8. {
  9. public:
  10. virtual void SetUp();
  11. virtual void TearDown();
  12. protected:
  13. RemoveVCProcess* piProcess;
  14. aiScene* pScene;
  15. };
  16. // ------------------------------------------------------------------------------------------------
  17. void RemoveVCProcessTest::SetUp()
  18. {
  19. // construct the process
  20. piProcess = new RemoveVCProcess();
  21. pScene = new aiScene();
  22. // fill the scene ..
  23. pScene->mMeshes = new aiMesh*[pScene->mNumMeshes = 2];
  24. pScene->mMeshes[0] = new aiMesh();
  25. pScene->mMeshes[1] = new aiMesh();
  26. pScene->mMeshes[0]->mNumVertices = 120;
  27. pScene->mMeshes[0]->mVertices = new aiVector3D[120];
  28. pScene->mMeshes[0]->mNormals = new aiVector3D[120];
  29. pScene->mMeshes[0]->mTextureCoords[0] = new aiVector3D[120];
  30. pScene->mMeshes[0]->mTextureCoords[1] = new aiVector3D[120];
  31. pScene->mMeshes[0]->mTextureCoords[2] = new aiVector3D[120];
  32. pScene->mMeshes[0]->mTextureCoords[3] = new aiVector3D[120];
  33. pScene->mMeshes[1]->mNumVertices = 120;
  34. pScene->mMeshes[1]->mVertices = new aiVector3D[120];
  35. pScene->mAnimations = new aiAnimation*[pScene->mNumAnimations = 2];
  36. pScene->mAnimations[0] = new aiAnimation();
  37. pScene->mAnimations[1] = new aiAnimation();
  38. pScene->mTextures = new aiTexture*[pScene->mNumTextures = 2];
  39. pScene->mTextures[0] = new aiTexture();
  40. pScene->mTextures[1] = new aiTexture();
  41. pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials = 2];
  42. pScene->mMaterials[0] = new aiMaterial();
  43. pScene->mMaterials[1] = new aiMaterial();
  44. pScene->mLights = new aiLight*[pScene->mNumLights = 2];
  45. pScene->mLights[0] = new aiLight();
  46. pScene->mLights[1] = new aiLight();
  47. pScene->mCameras = new aiCamera*[pScene->mNumCameras = 2];
  48. pScene->mCameras[0] = new aiCamera();
  49. pScene->mCameras[1] = new aiCamera();
  50. // COMPILE TEST: aiMaterial may no add any extra members,
  51. // so we don't need a virtual destructor
  52. char check[sizeof(aiMaterial) == sizeof(aiMaterial) ? 10 : -1];
  53. check[0] = 0;
  54. // to remove compiler warning
  55. EXPECT_TRUE( check );
  56. }
  57. // ------------------------------------------------------------------------------------------------
  58. void RemoveVCProcessTest::TearDown()
  59. {
  60. delete pScene;
  61. delete piProcess;
  62. }
  63. // ------------------------------------------------------------------------------------------------
  64. TEST_F(RemoveVCProcessTest, testMeshRemove)
  65. {
  66. piProcess->SetDeleteFlags(aiComponent_MESHES);
  67. piProcess->Execute(pScene);
  68. EXPECT_TRUE(NULL == pScene->mMeshes);
  69. EXPECT_EQ(0U, pScene->mNumMeshes);
  70. EXPECT_TRUE(pScene->mFlags == AI_SCENE_FLAGS_INCOMPLETE);
  71. }
  72. // ------------------------------------------------------------------------------------------------
  73. TEST_F(RemoveVCProcessTest, testAnimRemove)
  74. {
  75. piProcess->SetDeleteFlags(aiComponent_ANIMATIONS);
  76. piProcess->Execute(pScene);
  77. EXPECT_TRUE(NULL == pScene->mAnimations);
  78. EXPECT_EQ(0U, pScene->mNumAnimations);
  79. EXPECT_EQ(0U, pScene->mFlags);
  80. }
  81. // ------------------------------------------------------------------------------------------------
  82. TEST_F(RemoveVCProcessTest, testMaterialRemove)
  83. {
  84. piProcess->SetDeleteFlags(aiComponent_MATERIALS);
  85. piProcess->Execute(pScene);
  86. // there should be one default material now ...
  87. EXPECT_TRUE(1 == pScene->mNumMaterials &&
  88. pScene->mMeshes[0]->mMaterialIndex == 0 &&
  89. pScene->mMeshes[1]->mMaterialIndex == 0);
  90. EXPECT_EQ(0U, pScene->mFlags);
  91. }
  92. // ------------------------------------------------------------------------------------------------
  93. TEST_F(RemoveVCProcessTest, testTextureRemove)
  94. {
  95. piProcess->SetDeleteFlags(aiComponent_TEXTURES);
  96. piProcess->Execute(pScene);
  97. EXPECT_TRUE(NULL == pScene->mTextures);
  98. EXPECT_EQ(0U, pScene->mNumTextures);
  99. EXPECT_EQ(0U, pScene->mFlags);
  100. }
  101. // ------------------------------------------------------------------------------------------------
  102. TEST_F(RemoveVCProcessTest, testCameraRemove)
  103. {
  104. piProcess->SetDeleteFlags(aiComponent_CAMERAS);
  105. piProcess->Execute(pScene);
  106. EXPECT_TRUE(NULL == pScene->mCameras);
  107. EXPECT_EQ(0U, pScene->mNumCameras);
  108. EXPECT_EQ(0U, pScene->mFlags);
  109. }
  110. // ------------------------------------------------------------------------------------------------
  111. TEST_F(RemoveVCProcessTest, testLightRemove)
  112. {
  113. piProcess->SetDeleteFlags(aiComponent_LIGHTS);
  114. piProcess->Execute(pScene);
  115. EXPECT_TRUE(NULL == pScene->mLights);
  116. EXPECT_EQ(0U, pScene->mNumLights);
  117. EXPECT_EQ(0U, pScene->mFlags);
  118. }
  119. // ------------------------------------------------------------------------------------------------
  120. TEST_F(RemoveVCProcessTest, testMeshComponentsRemoveA)
  121. {
  122. piProcess->SetDeleteFlags(aiComponent_TEXCOORDSn(1) | aiComponent_TEXCOORDSn(2) | aiComponent_TEXCOORDSn(3));
  123. piProcess->Execute(pScene);
  124. EXPECT_TRUE(pScene->mMeshes[0]->mTextureCoords[0] &&
  125. !pScene->mMeshes[0]->mTextureCoords[1] &&
  126. !pScene->mMeshes[0]->mTextureCoords[2] &&
  127. !pScene->mMeshes[0]->mTextureCoords[3]);
  128. EXPECT_EQ(0U, pScene->mFlags);
  129. }
  130. // ------------------------------------------------------------------------------------------------
  131. TEST_F(RemoveVCProcessTest, testMeshComponentsRemoveB)
  132. {
  133. piProcess->SetDeleteFlags(aiComponent_TEXCOORDSn(1) | aiComponent_NORMALS);
  134. piProcess->Execute(pScene);
  135. EXPECT_TRUE(pScene->mMeshes[0]->mTextureCoords[0] &&
  136. pScene->mMeshes[0]->mTextureCoords[1] &&
  137. pScene->mMeshes[0]->mTextureCoords[2] && // shift forward ...
  138. !pScene->mMeshes[0]->mTextureCoords[3] &&
  139. !pScene->mMeshes[0]->mNormals);
  140. EXPECT_EQ(0U, pScene->mFlags);
  141. }
  142. // ------------------------------------------------------------------------------------------------
  143. TEST_F(RemoveVCProcessTest, testRemoveEverything)
  144. {
  145. piProcess->SetDeleteFlags(aiComponent_LIGHTS | aiComponent_ANIMATIONS |
  146. aiComponent_MATERIALS | aiComponent_MESHES | aiComponent_CAMERAS | aiComponent_TEXTURES);
  147. piProcess->Execute(pScene);
  148. EXPECT_EQ(0U, pScene->mNumAnimations);
  149. EXPECT_EQ(0U, pScene->mNumCameras);
  150. EXPECT_EQ(0U, pScene->mNumLights);
  151. EXPECT_EQ(0U, pScene->mNumMeshes);
  152. EXPECT_EQ(0U, pScene->mNumTextures);
  153. // Only the default material should remain.
  154. EXPECT_EQ(1U, pScene->mNumMaterials);
  155. }