/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "Camera_precompiled.h" #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); }