/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include "ViewportCameraSelectorWindow_Internals.h" class CameraEditorUITests : public UnitTest::AllocatorsTestFixture { }; TEST_F(CameraEditorUITests, TestCameraListModelAddAndRemove) { QScopedPointer model( new Camera::Internal::CameraListModel(nullptr)); int expectedAdds = 0; int expectedRemoves = 0; QObject::connect(model.get(), &QAbstractItemModel::rowsAboutToBeInserted, [&]() { EXPECT_TRUE(expectedAdds > 0); expectedAdds -= 1; }); QObject::connect(model.get(), &QAbstractItemModel::rowsAboutToBeRemoved, [&]() { EXPECT_TRUE(expectedRemoves > 0); expectedRemoves -= 1; }); AZ::EntityId e1{1}, e2{2}, e3{3}; using CameraNotificationBus = AZ::EBus; expectedAdds = 2; CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraAdded, e1); CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraAdded, e2); EXPECT_TRUE(expectedAdds == 0); // There should be three rows, two for our additions and one default editor camera entry EXPECT_TRUE(model->rowCount() == 3); expectedRemoves = 2; CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraRemoved, e1); CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraRemoved, e2); // We never added e3, so the model should just ignore this CameraNotificationBus::Broadcast(&CameraNotificationBus::Events::OnCameraRemoved, e3); EXPECT_TRUE(expectedRemoves == 0); EXPECT_TRUE(model->rowCount() == 1); }