CameraEditorUITests.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <AzTest/AzTest.h>
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. #include "ViewportCameraSelectorWindow_Internals.h"
  11. class CameraEditorUITests
  12. : public UnitTest::LeakDetectionFixture
  13. {
  14. };
  15. TEST_F(CameraEditorUITests, TestCameraListModelAddAndRemove)
  16. {
  17. QScopedPointer<Camera::Internal::CameraListModel> model(
  18. new Camera::Internal::CameraListModel(nullptr));
  19. int expectedAdds = 0;
  20. int expectedRemoves = 0;
  21. QObject::connect(model.get(), &QAbstractItemModel::rowsAboutToBeInserted, [&]() {
  22. EXPECT_TRUE(expectedAdds > 0);
  23. expectedAdds -= 1;
  24. });
  25. QObject::connect(model.get(), &QAbstractItemModel::rowsAboutToBeRemoved, [&]() {
  26. EXPECT_TRUE(expectedRemoves > 0);
  27. expectedRemoves -= 1;
  28. });
  29. AZ::EntityId e1{1}, e2{2}, e3{3};
  30. using CameraNotificationBus = AZ::EBus<Camera::CameraNotifications>;
  31. expectedAdds = 2;
  32. CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraAdded, e1);
  33. CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraAdded, e2);
  34. EXPECT_TRUE(expectedAdds == 0);
  35. // There should be three rows, two for our additions and one default editor camera entry
  36. EXPECT_TRUE(model->rowCount() == 3);
  37. expectedRemoves = 2;
  38. CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraRemoved, e1);
  39. CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraRemoved, e2);
  40. // We never added e3, so the model should just ignore this
  41. CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraRemoved, e3);
  42. EXPECT_TRUE(expectedRemoves == 0);
  43. EXPECT_TRUE(model->rowCount() == 1);
  44. }