RenamedNodesMapTests.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/std/smart_ptr/make_shared.h>
  9. #include <AzCore/std/smart_ptr/shared_ptr.h>
  10. #include <AzTest/AzTest.h>
  11. #include <SceneAPI/SceneBuilder/Importers/Utilities/RenamedNodesMap.h>
  12. #include <SceneAPI/SceneCore/Containers/SceneGraph.h>
  13. #include <SceneAPI/SceneCore/DataTypes/IGraphObject.h>
  14. #include <SceneAPI/SceneData/GraphData/MeshData.h>
  15. namespace AZ
  16. {
  17. namespace SceneAPI
  18. {
  19. namespace SceneBuilder
  20. {
  21. TEST(RenamedNodesMapTests, SanitizeNodeName_ValidNameProvided_ReturnsFalseAndNameUnchanged)
  22. {
  23. Containers::SceneGraph graph;
  24. AZStd::string name = "ValidName";
  25. bool result = RenamedNodesMap::SanitizeNodeName(name, graph, graph.GetRoot());
  26. EXPECT_FALSE(result);
  27. EXPECT_STREQ("ValidName", name.c_str());
  28. }
  29. TEST(RenamedNodesMapTests, SanitizeNodeName_NameWithInvalidCharacter_ReturnsTrueAndNameChanged)
  30. {
  31. Containers::SceneGraph graph;
  32. AZStd::string check = "Valid";
  33. check += Containers::SceneGraph::GetNodeSeperationCharacter();
  34. check += "Name";
  35. AZStd::string name = check;
  36. bool result = RenamedNodesMap::SanitizeNodeName(name, graph, graph.GetRoot());
  37. EXPECT_TRUE(result);
  38. EXPECT_STRNE(check.c_str(), name.c_str());
  39. }
  40. TEST(RenamedNodesMapTests, SanitizeNodeName_BlankName_ReturnsTrueAndNameSetToDefault)
  41. {
  42. Containers::SceneGraph graph;
  43. AZStd::string name;
  44. bool result = RenamedNodesMap::SanitizeNodeName(name, graph, graph.GetRoot(), "Default");
  45. EXPECT_TRUE(result);
  46. EXPECT_STREQ("Default", name.c_str());
  47. }
  48. TEST(RenamedNodesMapTests, SanitizeNodeName_SingleCollision_ReturnsTrueAndNameHasAppendixOf1)
  49. {
  50. Containers::SceneGraph graph;
  51. graph.AddChild(graph.GetRoot(), "Child");
  52. AZStd::string name = "Child";
  53. bool result = RenamedNodesMap::SanitizeNodeName(name, graph, graph.GetRoot());
  54. EXPECT_TRUE(result);
  55. EXPECT_STREQ("Child_1", name.c_str());
  56. }
  57. TEST(RenamedNodesMapTests, SanitizeNodeName_MultipleCollisions_ReturnsTrueAndNameHasAppendixOf2)
  58. {
  59. Containers::SceneGraph graph;
  60. auto child = graph.AddChild(graph.GetRoot(), "Child");
  61. graph.AddSibling(child, "Child_1");
  62. AZStd::string name = "Child";
  63. bool result = RenamedNodesMap::SanitizeNodeName(name, graph, graph.GetRoot());
  64. EXPECT_TRUE(result);
  65. EXPECT_STREQ("Child_2", name.c_str());
  66. }
  67. } // namespace SceneBuilder
  68. } // namespace SceneAPI
  69. } // namespace AZ