123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754 |
- /*
- * 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 <Tests/ActionManager/ActionManagerFixture.h>
- #include <AzToolsFramework/API/ToolsApplicationAPI.h>
- namespace UnitTest
- {
- TEST_F(ActionManagerFixture, RegisterActionContext)
- {
- auto outcome =
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, VerifyActionContextIsRegistered)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- EXPECT_TRUE(m_actionManagerInterface->IsActionContextRegistered("o3de.context.test"));
- }
- TEST_F(ActionManagerFixture, RegisterActionToUnregisteredContext)
- {
- auto outcome = m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RegisterAction)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- auto outcome = m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RegisterActionTwice)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- auto outcome = m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, VerifyActionIsRegistered)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- EXPECT_TRUE(m_actionManagerInterface->IsActionRegistered("o3de.action.test"));
- }
- TEST_F(ActionManagerFixture, RegisterCheckableActionToUnregisteredContext)
- {
- auto outcome = m_actionManagerInterface->RegisterCheckableAction("o3de.context.test", "o3de.action.test", {}, []{}, []()->bool{ return true; });
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RegisterCheckableAction)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- auto outcome = m_actionManagerInterface->RegisterCheckableAction("o3de.context.test", "o3de.action.test", {}, []{}, []()->bool{ return true; });
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RegisterCheckableActionTwice)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterCheckableAction("o3de.context.test", "o3de.action.test", {}, []{}, []()->bool{ return true; });
- auto outcome = m_actionManagerInterface->RegisterCheckableAction("o3de.context.test", "o3de.action.test", {}, []{}, []()->bool{ return true; });
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, GetUnregisteredAction)
- {
- QAction* action = m_actionManagerInternalInterface->GetAction("o3de.action.test");
- EXPECT_EQ(action, nullptr);
- }
- TEST_F(ActionManagerFixture, GetAction)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- QAction* action = m_actionManagerInternalInterface->GetAction("o3de.action.test");
- EXPECT_TRUE(action != nullptr);
- }
- TEST_F(ActionManagerFixture, GetAndTriggerAction)
- {
- bool actionTriggered = false;
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction(
- "o3de.context.test", "o3de.action.test", {},
- [&actionTriggered]()
- {
- actionTriggered = true;
- }
- );
- QAction* action = m_actionManagerInternalInterface->GetAction("o3de.action.test");
-
- action->trigger();
- EXPECT_TRUE(actionTriggered);
- }
- TEST_F(ActionManagerFixture, GetActionName)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
-
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_name = "Test Name";
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- auto outcome = m_actionManagerInterface->GetActionName("o3de.action.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_THAT(outcome.GetValue().c_str(), ::testing::StrEq("Test Name"));
- }
- TEST_F(ActionManagerFixture, SetActionName)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
-
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_name = "Wrong Name";
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- auto setOutcome = m_actionManagerInterface->SetActionName("o3de.action.test", "Correct Name");
- EXPECT_TRUE(setOutcome.IsSuccess());
- auto getOutcome = m_actionManagerInterface->GetActionName("o3de.action.test");
- EXPECT_THAT(getOutcome.GetValue().c_str(), ::testing::StrEq("Correct Name"));
- }
- TEST_F(ActionManagerFixture, GetActionDescription)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
-
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_description = "Test Description";
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- auto outcome = m_actionManagerInterface->GetActionDescription("o3de.action.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_THAT(outcome.GetValue().c_str(), ::testing::StrEq("Test Description"));
- }
- TEST_F(ActionManagerFixture, SetActionDescription)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
-
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_description = "Wrong Description";
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- auto setOutcome = m_actionManagerInterface->SetActionDescription("o3de.action.test", "Correct Description");
- EXPECT_TRUE(setOutcome.IsSuccess());
- auto getOutcome = m_actionManagerInterface->GetActionDescription("o3de.action.test");
- EXPECT_THAT(getOutcome.GetValue().c_str(), ::testing::StrEq("Correct Description"));
- }
- TEST_F(ActionManagerFixture, GetActionCategory)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
-
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_category = "Test Category";
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- auto outcome = m_actionManagerInterface->GetActionCategory("o3de.action.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_THAT(outcome.GetValue().c_str(), ::testing::StrEq("Test Category"));
- }
- TEST_F(ActionManagerFixture, SetActionCategory)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
-
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_category = "Wrong Category";
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- auto setOutcome = m_actionManagerInterface->SetActionCategory("o3de.action.test", "Correct Category");
- EXPECT_TRUE(setOutcome.IsSuccess());
- auto getOutcome = m_actionManagerInterface->GetActionCategory("o3de.action.test");
- EXPECT_THAT(getOutcome.GetValue().c_str(), ::testing::StrEq("Correct Category"));
- }
- TEST_F(ActionManagerFixture, VerifyIncorrectIconPath)
- {
- // Since we don't want to have the unit tests depend on a resource file, this will only test the case where an incorrect path is set.
- // When a path that does not point to a resource is passed, the icon path string is cleared and the icon will be null.
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
-
- AzToolsFramework::ActionProperties actionProperties;
- actionProperties.m_iconPath = ":/Some/Incorrect/Path.svg";
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", actionProperties, []{});
- auto outcome = m_actionManagerInterface->GetActionIconPath("o3de.action.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_TRUE(outcome.GetValue().empty());
- QAction* action = m_actionManagerInternalInterface->GetAction("o3de.action.test");
- EXPECT_TRUE(action->icon().isNull());
- }
- TEST_F(ActionManagerFixture, TriggerUnregisteredAction)
- {
- auto outcome = m_actionManagerInterface->TriggerAction("o3de.action.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, TriggerAction)
- {
- bool actionTriggered = false;
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction(
- "o3de.context.test", "o3de.action.test", {},
- [&actionTriggered]()
- {
- actionTriggered = true;
- }
- );
- auto outcome = m_actionManagerInterface->TriggerAction("o3de.action.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_TRUE(actionTriggered);
- }
- TEST_F(ActionManagerFixture, TriggerCheckableAction)
- {
- // Verify that triggering a checkable action automatically calls the update callback to refresh the checkable state.
- bool actionToggle = false;
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterCheckableAction(
- "o3de.context.test", "o3de.action.checkableTest", {},
- [&]()
- {
- actionToggle = !actionToggle;
- },
- [&]() -> bool
- {
- return actionToggle;
- }
- );
- auto outcome = m_actionManagerInterface->TriggerAction("o3de.action.checkableTest");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_TRUE(actionToggle);
- // Note that we don't expose an API to directly query the checked state of an action.
- // This is because the checkable state is just a UI indicator. Operations relying on the
- // checked state of an action should instead rely on the value of the property they visualize.
- // In this example, logic should not rely on the checked state of o3de.action.checkableTest,
- // but on the value of actionToggle itself (just like the update callback does).
-
- QAction* action = m_actionManagerInternalInterface->GetAction("o3de.action.checkableTest");
- EXPECT_TRUE(action->isChecked());
- }
- TEST_F(ActionManagerFixture, InstallEnabledStateCallback)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
-
- auto outcome = m_actionManagerInterface->InstallEnabledStateCallback("o3de.action.test", []() { return false; });
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, VerifyEnabledStateCallback)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_TRUE(enabledOutcome.GetValue());
- }
- m_actionManagerInterface->InstallEnabledStateCallback("o3de.action.test", []() { return false; });
-
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_FALSE(enabledOutcome.GetValue());
- }
- }
- TEST_F(ActionManagerFixture, VerifyEnabledStateCallbackUpdate)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- bool enabledState = false;
- m_actionManagerInterface->InstallEnabledStateCallback("o3de.action.test", [&]() {
- return enabledState;
- });
-
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_FALSE(enabledOutcome.GetValue());
- }
- enabledState = true;
-
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_FALSE(enabledOutcome.GetValue());
- }
- m_actionManagerInterface->UpdateAction("o3de.action.test");
-
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_TRUE(enabledOutcome.GetValue());
- }
- }
- TEST_F(ActionManagerFixture, InstallMultipleEnabledStateCallbacks)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
-
- m_actionManagerInterface->InstallEnabledStateCallback("o3de.action.test", []() { return false; });
- auto outcome = m_actionManagerInterface->InstallEnabledStateCallback("o3de.action.test", []() { return false; });
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, VerifyEnabledStateCallbacks)
- {
- // Results of Enabled State Callbacks are chained with AND.
- // So all callbacks need to return TRUE for an Action to be enabled.
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
-
- m_actionManagerInterface->InstallEnabledStateCallback("o3de.action.test", []() { return true; });
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_TRUE(enabledOutcome.GetValue());
- }
- m_actionManagerInterface->InstallEnabledStateCallback("o3de.action.test", []() { return false; });
-
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_FALSE(enabledOutcome.GetValue());
- }
- }
- TEST_F(ActionManagerFixture, UpdateUnregisteredAction)
- {
- auto outcome = m_actionManagerInterface->UpdateAction("o3de.action.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, UpdateCheckableAction)
- {
- // Verify the ability to update the checked state of a Checkable Action.
- bool actionToggle = false;
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterCheckableAction(
- "o3de.context.test", "o3de.action.checkableTest", {},
- [&]()
- {
- actionToggle = !actionToggle;
- },
- [&]() -> bool
- {
- return actionToggle;
- }
- );
-
- QAction* action = m_actionManagerInternalInterface->GetAction("o3de.action.checkableTest");
- EXPECT_FALSE(action->isChecked());
- // When the property driving the action's state is changed outside the Action Manager system,
- // the caller should ensure the actions relying on it are updated accordingly.
- actionToggle = true;
-
- EXPECT_FALSE(action->isChecked());
-
- auto outcome = m_actionManagerInterface->UpdateAction("o3de.action.checkableTest");
-
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_TRUE(action->isChecked());
- }
- TEST_F(ActionManagerFixture, RegisterWidgetAction)
- {
- auto outcome = m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test", {},
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, RegisterWidgetActionTwice)
- {
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test", {},
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- auto outcome = m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test", {},
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, VerifyWidgetActionIsRegistered)
- {
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test",
- {},
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- EXPECT_TRUE(m_actionManagerInterface->IsWidgetActionRegistered("o3de.widgetAction.test"));
- }
- TEST_F(ActionManagerFixture, GetWidgetActionName)
- {
- AzToolsFramework::WidgetActionProperties widgetActionProperties;
- widgetActionProperties.m_name = "Test Widget";
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test",
- widgetActionProperties,
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- auto outcome = m_actionManagerInterface->GetWidgetActionName("o3de.widgetAction.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_THAT(outcome.GetValue().c_str(), ::testing::StrEq("Test Widget"));
- }
- TEST_F(ActionManagerFixture, SetWidgetActionName)
- {
- AzToolsFramework::WidgetActionProperties widgetActionProperties;
- widgetActionProperties.m_name = "Wrong Widget Name";
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test",
- widgetActionProperties,
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- auto setOutcome = m_actionManagerInterface->SetWidgetActionName("o3de.widgetAction.test", "Correct Widget Name");
- EXPECT_TRUE(setOutcome.IsSuccess());
- auto getOutcome = m_actionManagerInterface->GetWidgetActionName("o3de.widgetAction.test");
- EXPECT_THAT(getOutcome.GetValue().c_str(), ::testing::StrEq("Correct Widget Name"));
- }
- TEST_F(ActionManagerFixture, GetWidgetActionCategory)
- {
- AzToolsFramework::WidgetActionProperties widgetActionProperties;
- widgetActionProperties.m_category = "Test Widget Category";
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test",
- widgetActionProperties,
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- auto outcome = m_actionManagerInterface->GetWidgetActionCategory("o3de.widgetAction.test");
- EXPECT_TRUE(outcome.IsSuccess());
- EXPECT_THAT(outcome.GetValue().c_str(), ::testing::StrEq("Test Widget Category"));
- }
- TEST_F(ActionManagerFixture, SetWidgetActionCategory)
- {
- AzToolsFramework::WidgetActionProperties widgetActionProperties;
- widgetActionProperties.m_category = "Wrong Widget Category";
- m_actionManagerInterface->RegisterWidgetAction(
- "o3de.widgetAction.test",
- widgetActionProperties,
- []() -> QWidget*
- {
- return nullptr;
- }
- );
- auto setOutcome = m_actionManagerInterface->SetWidgetActionCategory("o3de.widgetAction.test", "Correct Widget Category");
- EXPECT_TRUE(setOutcome.IsSuccess());
- auto getOutcome = m_actionManagerInterface->GetWidgetActionCategory("o3de.widgetAction.test");
- EXPECT_THAT(getOutcome.GetValue().c_str(), ::testing::StrEq("Correct Widget Category"));
- }
- TEST_F(ActionManagerFixture, RegisterActionUpdater)
- {
- auto outcome = m_actionManagerInterface->RegisterActionUpdater("o3de.updater.onTestChange");
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddUnregisteredActionToUpdater)
- {
- m_actionManagerInterface->RegisterActionUpdater("o3de.updater.onTestChange");
- auto outcome = m_actionManagerInterface->AddActionToUpdater("o3de.updater.onTestChange", "o3de.action.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddActionToUnregisteredUpdater)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- auto outcome = m_actionManagerInterface->AddActionToUpdater("o3de.updater.onTestChange", "o3de.action.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, AddActionToUpdater)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_actionManagerInterface->RegisterActionUpdater("o3de.updater.onTestChange");
- auto outcome = m_actionManagerInterface->AddActionToUpdater("o3de.updater.onTestChange", "o3de.action.test");
- EXPECT_TRUE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, TriggerActionUpdater)
- {
- // Action Updaters are meant to be triggered when a specific event happens.
- // This will mostly be achieved by handling a notification bus and calling the
- // "TriggerActionUpdater" function for the updater identifier there.
- // This test only verifies that the underlying function works, but does not
- // represent the expected setup for using the system.
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- m_actionManagerInterface->RegisterActionUpdater("o3de.updater.onTestChange");
- m_actionManagerInterface->AddActionToUpdater("o3de.updater.onTestChange", "o3de.action.test");
- bool enabledState = false;
- m_actionManagerInterface->InstallEnabledStateCallback("o3de.action.test", [&]() {
- return enabledState;
- });
-
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_FALSE(enabledOutcome.GetValue());
- }
- enabledState = true;
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_FALSE(enabledOutcome.GetValue());
- }
- m_actionManagerInterface->TriggerActionUpdater("o3de.updater.onTestChange");
- {
- auto enabledOutcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(enabledOutcome.IsSuccess());
- EXPECT_TRUE(enabledOutcome.GetValue());
- }
- }
- TEST_F(ActionManagerFixture, SetUnregisteredActionContextModeOnAction)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- auto outcome = m_actionManagerInterface->AssignModeToAction("o3de.context.mode.test", "o3de.action.test");
- EXPECT_FALSE(outcome.IsSuccess());
- }
- TEST_F(ActionManagerFixture, SetActionContextModeOnAction)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterActionContextMode("o3de.context.test", "o3de.context.mode.test");
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(outcome.GetValue());
- }
- // Set Action to the "o3de.context.mode.test" mode and verify it's no longer enabled (since "o3de.context.test" is set to "default").
- m_actionManagerInterface->AssignModeToAction("o3de.context.mode.test", "o3de.action.test");
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_FALSE(outcome.GetValue());
- }
- }
- TEST_F(ActionManagerFixture, SetActionContextDefaultModeOnAction)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(outcome.GetValue());
- }
- // Set Action to the "default" mode and verify it's still enabled (since "o3de.context.test" is set to "default").
- m_actionManagerInterface->AssignModeToAction("default", "o3de.action.test");
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(outcome.GetValue());
- }
- }
- TEST_F(ActionManagerFixture, ChangeModeAndVerifyActionWithNoSetMode)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterActionContextMode("o3de.context.test", "o3de.context.mode.test");
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(outcome.GetValue());
- }
- // Set the Action Context Mode to "o3de.context.mode.test" and verify that the action is still enabled.
- m_actionManagerInterface->SetActiveActionContextMode("o3de.context.test", "o3de.context.mode.test");
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(outcome.GetValue());
- }
- }
- TEST_F(ActionManagerFixture, ChangeModeAndVerifyActionSetToDefaultMode)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterActionContextMode("o3de.context.test", "o3de.context.mode.test");
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test", {}, []{});
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(outcome.GetValue());
- }
- // Set Action to the "default" mode and verify it's still enabled (since "o3de.context.test" is set to "default").
- m_actionManagerInterface->AssignModeToAction("default", "o3de.action.test");
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_TRUE(outcome.GetValue());
- }
- // Set the Action Context Mode to "o3de.context.mode.test" and verify that the action is now disabled.
- m_actionManagerInterface->SetActiveActionContextMode("o3de.context.test", "o3de.context.mode.test");
- {
- auto outcome = m_actionManagerInterface->IsActionEnabled("o3de.action.test");
- EXPECT_FALSE(outcome.GetValue());
- }
- }
- TEST_F(ActionManagerFixture, ModeSwitchingTest)
- {
- m_actionManagerInterface->RegisterActionContext("o3de.context.test", {});
- m_actionManagerInterface->RegisterActionContextMode("o3de.context.test", "o3de.context.mode.test1");
- m_actionManagerInterface->RegisterActionContextMode("o3de.context.test", "o3de.context.mode.test2");
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.testDefault", {}, []{});
- m_actionManagerInterface->AssignModeToAction("default", "o3de.action.testDefault");
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test1", {}, []{});
- m_actionManagerInterface->AssignModeToAction("o3de.context.mode.test1", "o3de.action.test1");
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.test2", {}, []{});
- m_actionManagerInterface->AssignModeToAction("o3de.context.mode.test2", "o3de.action.test2");
- m_actionManagerInterface->RegisterAction("o3de.context.test", "o3de.action.testAll", {}, []{});
- // At the beginning, "o3de.context.test" is set to mode "default".
- EXPECT_TRUE(m_actionManagerInterface->IsActionEnabled("o3de.action.testDefault").GetValue());
- EXPECT_FALSE(m_actionManagerInterface->IsActionEnabled("o3de.action.test1").GetValue());
- EXPECT_FALSE(m_actionManagerInterface->IsActionEnabled("o3de.action.test2").GetValue());
- EXPECT_TRUE(m_actionManagerInterface->IsActionEnabled("o3de.action.testAll").GetValue());
- // Set the Action Context Mode to "o3de.context.mode.test1" and verify that the actions are updated accordingly.
- m_actionManagerInterface->SetActiveActionContextMode("o3de.context.test", "o3de.context.mode.test1");
- EXPECT_FALSE(m_actionManagerInterface->IsActionEnabled("o3de.action.testDefault").GetValue());
- EXPECT_TRUE(m_actionManagerInterface->IsActionEnabled("o3de.action.test1").GetValue());
- EXPECT_FALSE(m_actionManagerInterface->IsActionEnabled("o3de.action.test2").GetValue());
- EXPECT_TRUE(m_actionManagerInterface->IsActionEnabled("o3de.action.testAll").GetValue());
- // Set the Action Context Mode to "o3de.context.mode.test2" and verify that the actions are updated accordingly.
- m_actionManagerInterface->SetActiveActionContextMode("o3de.context.test", "o3de.context.mode.test2");
- EXPECT_FALSE(m_actionManagerInterface->IsActionEnabled("o3de.action.testDefault").GetValue());
- EXPECT_FALSE(m_actionManagerInterface->IsActionEnabled("o3de.action.test1").GetValue());
- EXPECT_TRUE(m_actionManagerInterface->IsActionEnabled("o3de.action.test2").GetValue());
- EXPECT_TRUE(m_actionManagerInterface->IsActionEnabled("o3de.action.testAll").GetValue());
- // Set the Action Context Mode back to "default" and verify that the actions are updated accordingly.
- m_actionManagerInterface->SetActiveActionContextMode("o3de.context.test", "default");
- EXPECT_TRUE(m_actionManagerInterface->IsActionEnabled("o3de.action.testDefault").GetValue());
- EXPECT_FALSE(m_actionManagerInterface->IsActionEnabled("o3de.action.test1").GetValue());
- EXPECT_FALSE(m_actionManagerInterface->IsActionEnabled("o3de.action.test2").GetValue());
- EXPECT_TRUE(m_actionManagerInterface->IsActionEnabled("o3de.action.testAll").GetValue());
- }
- } // namespace UnitTest
|