CanUseViewMenu.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <gtest/gtest.h>
  9. #include <QPushButton>
  10. #include <QAction>
  11. #include <QtTest>
  12. #include <QMessageBox>
  13. #include <Tests/UI/MenuUIFixture.h>
  14. #include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  15. namespace EMotionFX
  16. {
  17. class CanUseViewMenuFixture
  18. : public MenuUIFixture
  19. {
  20. public:
  21. void TestShowPlugin(const QMenu* viewMenu, const QString& pluginName) const
  22. {
  23. QAction* action = FindMenuAction(viewMenu, pluginName, "ViewMenu");
  24. ASSERT_TRUE(action) << "Unable to find view menu item " << pluginName.toUtf8().data();
  25. if (action->isChecked())
  26. {
  27. return;
  28. }
  29. const EMStudio::PluginManager::PluginVector pluginsBefore = EMStudio::GetPluginManager()->GetActivePlugins();
  30. action->trigger();
  31. QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  32. const EMStudio::PluginManager::PluginVector pluginsAfter = EMStudio::GetPluginManager()->GetActivePlugins();
  33. ASSERT_EQ(pluginsAfter.size(), pluginsBefore.size() + 1) << "Failed to open plugin with view menu option " << action->text().toUtf8().data();
  34. // Need to get the action again to check that the checked status has flipped.
  35. action = FindMenuAction(viewMenu, pluginName, "ViewMenu");
  36. ASSERT_TRUE(action);
  37. ASSERT_TRUE(action->isChecked()) << "View menu option not checked after opening " << action->text().toUtf8().data();
  38. }
  39. void TestHidePlugin(const QMenu* viewMenu, const QString& pluginName) const
  40. {
  41. QAction* action = FindMenuAction(viewMenu, pluginName, "ViewMenu");
  42. ASSERT_TRUE(action) << "Unable to find view menu item " << pluginName.toUtf8().data();
  43. if (!action->isChecked())
  44. {
  45. return;
  46. }
  47. const EMStudio::PluginManager::PluginVector pluginsBefore = EMStudio::GetPluginManager()->GetActivePlugins();
  48. action->trigger();
  49. const EMStudio::PluginManager::PluginVector pluginsAfter = EMStudio::GetPluginManager()->GetActivePlugins();
  50. ASSERT_EQ(pluginsAfter.size(), pluginsBefore.size() - 1) << "Failed to close plugin with view menu option " << action->text().toUtf8().data();
  51. // Need to get the action again to check that the checked status has flipped.
  52. action = FindMenuAction(viewMenu, pluginName, "ViewMenu");
  53. ASSERT_TRUE(action);
  54. ASSERT_TRUE(!action->isChecked()) << "View menu option still checked after closing " << action->text().toUtf8().data();
  55. }
  56. void TestViewMenuItem(const QMenu* viewMenu, const QString& pluginName)
  57. {
  58. QAction* action = FindMenuAction(viewMenu, pluginName, "ViewMenu");
  59. ASSERT_TRUE(action) << "Unable to find view menu item " << pluginName.toUtf8().data();
  60. if (action->isChecked())
  61. {
  62. TestHidePlugin(viewMenu, pluginName);
  63. TestShowPlugin(viewMenu, pluginName);
  64. }
  65. else
  66. {
  67. TestShowPlugin(viewMenu, pluginName);
  68. TestHidePlugin(viewMenu, pluginName);
  69. }
  70. }
  71. };
  72. TEST_F(CanUseViewMenuFixture, CanUseViewMenu)
  73. {
  74. RecordProperty("test_case_id", "C1698604");
  75. CloseAllPlugins();
  76. // Find the View menu.
  77. QMenu* viewMenu = FindMainMenuWithName("ViewMenu");
  78. ASSERT_TRUE(viewMenu) << "Unable to find view menu.";
  79. EMStudio::PluginManager* pluginManager = EMStudio::GetPluginManager();
  80. QList<QAction*> actions = viewMenu->findChildren<QAction*>();
  81. int numActions = actions.size() - 1;// -1 as we don't want to include the view menu action itself.
  82. int visiblePlugins = 0;
  83. const EMStudio::PluginManager::PluginVector& registeredPlugins = pluginManager->GetRegisteredPlugins();
  84. for (EMStudio::EMStudioPlugin* plugin : registeredPlugins)
  85. {
  86. TestViewMenuItem(viewMenu, plugin->GetName());
  87. visiblePlugins++;
  88. }
  89. ASSERT_EQ(visiblePlugins, numActions) << "View menu action count != number of visible plugins.";
  90. }
  91. } // namespace EMotionFX