Introduction of VconfTypeMenuItem 13/152013/8
authorPawel Kurowski <p.kurowski2@samsung.com>
Sun, 24 Sep 2017 13:59:37 +0000 (15:59 +0200)
committerPawel Kurowski <p.kurowski2@samsung.com>
Fri, 29 Sep 2017 14:36:14 +0000 (16:36 +0200)
MenuBuilder refactor.
MenuBuilderTests moved to ui-scenarios.

Change-Id: I4a577bf831ee117c0ec64a5a527110f6ae58bc4d

src/MenuBuilder.cpp
src/MenuBuilder.hpp
tests/no-ui-scenarios/TranslationsTests.cpp [new file with mode: 0644]
tests/ui-scenarios/MenuBuilderTests.cpp [moved from tests/no-ui-scenarios/MenuBuilderTests.cpp with 90% similarity]

index 4a06242..053efc5 100644 (file)
@@ -7,38 +7,80 @@
 #include "Window.hpp"
 #include "Quickpanel.hpp"
 
-MenuItem::MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
-                                  VconfKeyType vconfStateKeysType, std::vector<std::string> vconfStateKeys,
-                                  std::string subMenuLabel, std::string showingStateVconfKey)
+MenuItem::MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType, std::string subMenuLabel, std::string showingStateVconfKey)
        : names(std::move(names)), iconPath(std::move(iconPath)), activityType(std::move(activityType)),
-         vconfStateKeysType(vconfStateKeysType), vconfStateKeys(std::move(vconfStateKeys)),
-         subMenuLabel(std::move(subMenuLabel)), showingStateVconfKey(std::move(showingStateVconfKey)),
-         quickpanelItem(false)
-{}
-
-MenuItem::MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType, bool quickpanelItem)
-       : names(std::move(names)), iconPath(std::move(iconPath)), activityType(std::move(activityType)),
-         vconfStateKeysType(VconfKeyType::NONE), quickpanelItem(quickpanelItem)
-{}
+         subMenuLabel(std::move(subMenuLabel)), showingStateVconfKey(std::move(showingStateVconfKey)) {}
 
 std::string MenuItem::getName() const
 {
-       if (names.empty())
-               return {};
+       return names.empty() ? std::string() : gettext(names[0].c_str());
+}
 
-       if (quickpanelItem) {
-               /*
-                * Using window will crash MenuBuilderTests
-                * TODO solve in next patch
-               **/
-               auto window =  Singleton<UniversalSwitch>::instance().getMainWindow();
-               ASSERT(window, "NULL Window");
-               return gettext(names[window->getQuickpanel()->isVisible() ? 1 : 0].c_str());
-       }
+std::string MenuItem::getIconPath() const
+{
+       return iconPath;
+}
+
+std::string MenuItem::getActivityType() const
+{
+       return activityType;
+}
+
+VconfKeyType MenuItem::getVconfStateKeysType() const
+{
+       return VconfKeyType::NONE;
+}
+
+std::vector<std::string> MenuItem::getVconfStateKeys() const
+{
+       return {};
+}
+
+std::string MenuItem::getSubMenuLabel() const
+{
+       return subMenuLabel;
+}
+
+std::string MenuItem::getShowingStateVconfKey() const
+{
+       return showingStateVconfKey;
+}
+
+class VconfTypeMenuItem : public MenuItem
+{
+public:
+       VconfTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
+                                         VconfKeyType vconfStateKeysType, std::vector<std::string> vconfStateKeys,
+                                         std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
+
+       std::string getName() const override;
+       VconfKeyType getVconfStateKeysType() const override;
+       std::vector<std::string> getVconfStateKeys() const override;
+
+private:
+       VconfKeyType vconfStateKeysType;
+       std::vector<std::string> vconfStateKeys;
+};
+
+class QuickpanelTypeMenuItem : public MenuItem
+{
+public:
+       QuickpanelTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType);
 
-       if (vconfStateKeys.empty())
-               return gettext(names[0].c_str());
+       std::string getName() const override;
+};
 
+VconfTypeMenuItem::VconfTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
+                                                                        VconfKeyType vconfStateKeysType, std::vector<std::string> vconfStateKeys,
+                                                                        std::string subMenuLabel, std::string showingStateVconfKey)
+       : MenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey)),
+         vconfStateKeysType(vconfStateKeysType), vconfStateKeys(std::move(vconfStateKeys))
+{
+       ASSERT(!VconfTypeMenuItem::names.empty() && !VconfTypeMenuItem::vconfStateKeys.empty(), "Forbidden VconfTypeMenuItem");
+}
+
+std::string VconfTypeMenuItem::getName() const
+{
        switch (vconfStateKeysType) {
        case VconfKeyType::BOOL: {
                auto idx = 0;
@@ -66,37 +108,27 @@ std::string MenuItem::getName() const
        return {};
 }
 
-std::string MenuItem::getIconPath() const
-{
-       return iconPath;
-}
-
-std::string MenuItem::getActivityType() const
-{
-       return activityType;
-}
-
-VconfKeyType MenuItem::getVconfStateKeysType() const
+VconfKeyType VconfTypeMenuItem::getVconfStateKeysType() const
 {
        return vconfStateKeysType;
 }
 
-std::vector<std::string> MenuItem::getVconfStateKeys() const
+std::vector<std::string> VconfTypeMenuItem::getVconfStateKeys() const
 {
        return vconfStateKeys;
 }
 
-std::string MenuItem::getSubMenuLabel() const
-{
-       return subMenuLabel;
-}
+QuickpanelTypeMenuItem::QuickpanelTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType)
+       : MenuItem(std::move(names), std::move(iconPath), std::move(activityType))
+{}
 
-std::string MenuItem::getShowingStateVconfKey() const
+std::string QuickpanelTypeMenuItem::getName() const
 {
-       return showingStateVconfKey;
+       auto window =  Singleton<UniversalSwitch>::instance().getMainWindow();
+       ASSERT(window, "NULL Window");
+       return gettext(names[window->getQuickpanel()->isVisible() ? 1 : 0].c_str());
 }
 
-
 MenuMap::MenuMap()
 {
        const std::string defaultImg = ICONS_DIR "/tizen.png";
@@ -109,29 +141,22 @@ MenuMap::MenuMap()
                                                                                std::vector<std::string> {"IDS_HOME_SCREEN"},
                                                                                defaultImg,
                                                                                "START_HOME_SCREEN",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                std::string {},
                                                                                VCONF_KEY_SHOW_HOME_SCREEN_MENU_ITEM);
        auto back                                       =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_BACK"},
                                                                                defaultImg,
                                                                                "BACK",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                std::string {},
                                                                                VCONF_KEY_SHOW_BACK_MENU_ITEM);
-       auto openCloseNotifications     =       std::make_shared<MenuItem>(
+       auto openCloseNotifications     =       std::make_shared<QuickpanelTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_OPEN_NOTI_PANEL", "IDS_CLOSE_NOTI_PANEL"},
                                                                                defaultImg,
-                                                                               "TOGGLE_QUICKPANEL",
-                                                                               true);
+                                                                               "TOGGLE_QUICKPANEL");
        auto recentApps                         =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_RECENT_APPS"},
                                                                                defaultImg,
                                                                                "START_TASK_MGR",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                std::string {},
                                                                                VCONF_KEY_SHOW_RECENT_APPS_MENU_ITEM);
        auto accept                                     =       std::make_shared<MenuItem>(
@@ -166,13 +191,13 @@ MenuMap::MenuMap()
        auto selectAll                          =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_SELECT_ALL"},
                                                                                defaultImg);
-       auto previous                           =       std::make_shared<MenuItem>(
+       auto previous                           =       std::make_shared<VconfTypeMenuItem>(
                                                                                std::vector<std::string> { "IDS_PREVIOUS_CHARACTER", "IDS_PREVIOUS_WORD", "IDS_PREVIOUS_LINE", "IDS_PREVIOUS_PARAGRAPH"},
                                                                                defaultImg,
                                                                                std::string {},/*TODO add activity*/
                                                                                VconfKeyType::INT,
                                                                                std::vector<std::string> {VCONF_KEY_GRANULARITY_UNIT});
-       auto next                                       =       std::make_shared<MenuItem>(
+       auto next                                       =       std::make_shared<VconfTypeMenuItem>(
                                                                                std::vector<std::string> { "IDS_NEXT_CHARACTER", "IDS_NEXT_WORD", "IDS_NEXT_LINE", "IDS_NEXT_PARAGRAPH"},
                                                                                defaultImg,
                                                                                std::string {},/*TODO add activity*/
@@ -209,7 +234,7 @@ MenuMap::MenuMap()
                                                                                std::vector<std::string> {"IDS_SWIPE_RIGHT"},
                                                                                defaultImg,
                                                                                "SWIPE_RIGHT");
-       auto turnOnOffAutoScroll        =       std::make_shared<MenuItem>(
+       auto turnOnOffAutoScroll        =       std::make_shared<VconfTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_TURN_ON_AUTO_SCROLL", "IDS_TURN_OFF_AUTO_SCROLL"},
                                                                                defaultImg,
                                                                                std::string {},/*TODO add activity*/
@@ -247,7 +272,7 @@ MenuMap::MenuMap()
                                                                                std::vector<std::string> {"IDS_ZOOM_OUT"},
                                                                                defaultImg,
                                                                                "ZOOM_OUT");
-       auto soundVibrationMute         =       std::make_shared<MenuItem>(
+       auto soundVibrationMute         =       std::make_shared<VconfTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_SOUND", "IDS_VIBRATION", "IDS_MUTE"},
                                                                                defaultImg,
                                                                                "CHANGE_SOUND_PROFILE_ACTIVITY",
@@ -277,25 +302,25 @@ MenuMap::MenuMap()
                                                                                std::vector<std::string> {"IDS_SLOW_DOWN_SCANING"},
                                                                                defaultImg,
                                                                                std::string{"SLOW_DOWN_AUTO_SCAN_ACTIVITY"});
-       auto scanMethod                         =       std::make_shared<MenuItem>(
+       auto scanMethod                         =       std::make_shared<VconfTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_ROW_SCAN", "IDS_POINT_SCAN"},
                                                                                defaultImg,
                                                                                std::string {"CHANGE_SCANNING_METHOD"},
                                                                                VconfKeyType::INT,
                                                                                std::vector<std::string> {VCONF_KEY_SCAN_METHOD});
-       auto scanVerticalDirection      =       std::make_shared<MenuItem>(
+       auto scanVerticalDirection      =       std::make_shared<VconfTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_BOTTOM_TO_TOP", "IDS_TOP_TO_BOTTOM"},
                                                                                defaultImg,
                                                                                std::string {}/*TODO add activity*/,
                                                                                VconfKeyType::INT,
                                                                                std::vector<std::string> {VCONF_KEY_SCAN_DIRECTION_VERTICAL});
-       auto turnOnOffVoice                     =       std::make_shared<MenuItem>(
+       auto turnOnOffVoice                     =       std::make_shared<VconfTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_TURN_ON_VOICE", "IDS_TURN_OFF_VOICE"},
                                                                                defaultImg,
                                                                                std::string {"TOGGLE_VOICE_FEEDBACK_ENABLED_ACTIVITY"},
                                                                                VconfKeyType::BOOL,
                                                                                std::vector<std::string> {VCONF_KEY_FEEDBACK_VOICE_ENABLED});
-       auto turnOnOffSound                     =       std::make_shared<MenuItem>(
+       auto turnOnOffSound                     =       std::make_shared<VconfTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_TURN_ON_SOUND", "IDS_TURN_OFF_SOUND"},
                                                                                defaultImg,
                                                                                std::string {"TOGGLE_SOUND_FEEDBACK_ENABLED_ACTIVITY"},
@@ -349,65 +374,47 @@ MenuMap::MenuMap()
                                                                                std::vector<std::string> {"IDS_AUTO_SCROLL"},
                                                                                defaultImg,
                                                                                "SELECT",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                "IDS_MENU_AUTO_SCROLL");
        auto ScreenRotation                     =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_SCREEN_ROTATION"},
                                                                                defaultImg,
                                                                                "SELECT",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                "IDS_MENU_ROTATE_SCREEN");
        auto gestures                           =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_GESTURES"},
                                                                                defaultImg,
                                                                                "SELECT",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                "IDS_MENU_GESTURES",
                                                                                VCONF_KEY_SHOW_GESTURES_MENU_ITEM);
        auto actions                            =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_ACTIONS"},
                                                                                defaultImg,
                                                                                "SELECT",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                "IDS_MENU_ACTIONS",
                                                                                VCONF_KEY_SHOW_ACTIONS_MENU_ITEM);
        auto settings                           =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_SETTINGS"},
                                                                                defaultImg,
                                                                                "SELECT",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                "IDS_MENU_SETTINGS",
                                                                                VCONF_KEY_SHOW_SETTINGS_MENU_ITEM);
        auto buttonsAndKeys                     =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_BUTTONS_AND_KEYS"},
                                                                                defaultImg,
                                                                                "SELECT",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                "IDS_MENU_BUTTONS_KEYS",
                                                                                VCONF_KEY_SHOW_BUTTONS_AND_KEYS_MENU_ITEM);
        auto editText                           =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_EDIT_TEXT"},
                                                                                defaultImg,
                                                                                "SELECT",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                "IDS_MENU_EDIT_TEXT");
        auto granularitySettings        =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_GRANULARITY_SETTINGS"},
                                                                                defaultImg,
                                                                                "SELECT",
-                                                                               VconfKeyType::NONE,
-                                                                               std::vector<std::string> {},
                                                                                "IDS_MENU_GRANULARITY");
-       auto emptyItem                          =       std::make_shared<MenuItem>(
-                                                                               std::vector<std::string> {},
-                                                                               std::string {});
+       auto emptyItem                          =       std::make_shared<MenuItem>();
 
 
        addToMap("IDS_MENU_MAIN_NORMAL",                        {tap, gestures, actions, settings, recentApps, homeScreen, back, buttonsAndKeys});
index a1fb573..95decb8 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef MENU_BUILDER_HPP
 #define MENU_BUILDER_HPP
 
-#include "Singleton.hpp"
-
 #include <vector>
 #include <string>
 #include <map>
@@ -15,29 +13,23 @@ enum class VconfKeyType {
 class MenuItem
 {
 public:
-       MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType = {},
-                        VconfKeyType vconfStateKeysType = VconfKeyType::NONE, std::vector<std::string> vconfStateKeys = {},
+       MenuItem(std::vector<std::string> names = {}, std::string iconPath = {}, std::string activityType = {},
                         std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
 
-       MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType, bool quickpanelItem);
-
-       std::string getName() const;
+       virtual std::string getName() const;
        std::string getIconPath() const;
        std::string getActivityType() const;
-       VconfKeyType getVconfStateKeysType() const;
-       std::vector<std::string> getVconfStateKeys() const;
+       virtual VconfKeyType getVconfStateKeysType() const;
+       virtual std::vector<std::string> getVconfStateKeys() const;
        std::string getSubMenuLabel() const;
        std::string getShowingStateVconfKey() const;
 
-private:
+protected:
        std::vector<std::string> names;
        std::string iconPath;
        std::string activityType;
-       VconfKeyType vconfStateKeysType;
-       std::vector<std::string> vconfStateKeys;
        std::string subMenuLabel;
        std::string showingStateVconfKey;
-       bool quickpanelItem; //TODO remove in next patch
 };
 
 class MenuMap
diff --git a/tests/no-ui-scenarios/TranslationsTests.cpp b/tests/no-ui-scenarios/TranslationsTests.cpp
new file mode 100644 (file)
index 0000000..556150b
--- /dev/null
@@ -0,0 +1,15 @@
+#include "MenuBuilder.hpp"
+#include "Singleton.hpp"
+
+#include <gtest/gtest.h>
+#include <string>
+
+TEST(Translations, testTranslations)
+{
+       auto menuItem = Singleton<MenuMap>::instance().find("IDS_MENU_MAIN_NORMAL").back();
+       EXPECT_EQ(menuItem->getName(), "IDS_TAP");
+       bindtextdomain(PROJECT_NAME, LOCALE_DIR);
+       textdomain(PROJECT_NAME);
+       setlocale(LC_ALL, "en_US.UTF-8");
+       EXPECT_EQ(menuItem->getName(), "Tap");
+}
\ No newline at end of file
similarity index 90%
rename from tests/no-ui-scenarios/MenuBuilderTests.cpp
rename to tests/ui-scenarios/MenuBuilderTests.cpp
index ecd68d0..ab4cad5 100644 (file)
@@ -1,9 +1,15 @@
 #include "VConf.hpp"
 #include "VConfKeys.hpp"
 #include "MenuBuilder.hpp"
+#include "UniversalSwitch.hpp"
+#include "Singleton.hpp"
+#include "Window.hpp"
+#include "Quickpanel.hpp"
 
 #include <gtest/gtest.h>
 #include <string>
+#include <chrono>
+#include <thread>
 
 #define VCONF_TESTS_PREFIX             "accessibilityTests/"
 
@@ -75,6 +81,27 @@ public:
                        "IDS_HOME_SCREEN", "IDS_BACK", "IDS_BUTTONS_AND_KEYS"
                });
        }
+
+       void testSoundProfile(const std::string &soundProfile)
+       {
+               testMenuContent("IDS_MENU_ACTIONS", {
+                       "IDS_ZOOM_IN", "IDS_ZOOM_OUT", "IDS_SCREEN_ROTATION", soundProfile,
+                       "IDS_LOCK", "IDS_OPEN_NOTI_PANEL", "IDS_CAPTURE_SCREENSHOT"
+               }, {
+                       {}, {}, {}, {VCONF_KEY_SOUND_ENABLED, VCONF_KEY_VIBRATION_ENABLED}, {}, {}, {}
+               });
+       }
+
+       void testQuickpanel(const std::string &quickpanelState)
+       {
+               std::this_thread::sleep_for(std::chrono::seconds(1));
+               testMenuContent("IDS_MENU_ACTIONS", {
+                       "IDS_ZOOM_IN", "IDS_ZOOM_OUT", "IDS_SCREEN_ROTATION", "IDS_SOUND",
+                       "IDS_LOCK", quickpanelState, "IDS_CAPTURE_SCREENSHOT"
+               }, {
+                       {}, {}, {}, {VCONF_KEY_SOUND_ENABLED, VCONF_KEY_VIBRATION_ENABLED}, {}, {}, {}
+               });
+       }
 };
 
 TEST_F(MenuBuilderTest, testContentOfMenuMainNormal)
@@ -166,27 +193,17 @@ TEST_F(MenuBuilderTest, testContentOfMenuGestures)
 
 TEST_F(MenuBuilderTest, testContentOfMenuActions)
 {
-       auto test = [this](std::string soundProfile) {
-               this->testMenuContent("IDS_MENU_ACTIONS", {
-                       "IDS_ZOOM_IN", "IDS_ZOOM_OUT", "IDS_SCREEN_ROTATION", soundProfile,
-                       "IDS_LOCK", "IDS_OPEN_NOTI_PANEL", "IDS_CAPTURE_SCREENSHOT"
-               }, {
-                       std::vector<std::string> {},
-                       std::vector<std::string> {},
-                       std::vector<std::string> {},
-                       std::vector<std::string> {VCONF_KEY_SOUND_ENABLED, VCONF_KEY_VIBRATION_ENABLED},
-                       std::vector<std::string> {},
-                       std::vector<std::string> {},
-                       std::vector<std::string> {}
-               });
-       };
-
        setSoundProfileKeys("IDS_SOUND");
-       test("IDS_VIBRATION");
+       testSoundProfile("IDS_VIBRATION");
        setSoundProfileKeys("IDS_VIBRATION");
-       test("IDS_MUTE");
+       testSoundProfile("IDS_MUTE");
        setSoundProfileKeys("IDS_MUTE");
-       test("IDS_SOUND");
+       testSoundProfile("IDS_SOUND");
+
+       Singleton<UniversalSwitch>::instance().getMainWindow()->getQuickpanel()->show();
+       testQuickpanel("IDS_CLOSE_NOTI_PANEL");
+       Singleton<UniversalSwitch>::instance().getMainWindow()->getQuickpanel()->hide();
+       testQuickpanel("IDS_OPEN_NOTI_PANEL");
 }
 
 TEST_F(MenuBuilderTest, testContentOfMenuRotateScreen)
@@ -300,14 +317,4 @@ TEST_F(MenuBuilderTest, testAllGranularityOptions)
                EXPECT_EQ(prev->getName(), "IDS_PREVIOUS_" + requiredStates[ii]);
                EXPECT_EQ(next->getName(), "IDS_NEXT_" + requiredStates[ii]);
        }
-}
-
-TEST_F(MenuBuilderTest, testTranslations)
-{
-       auto menuItem = Singleton<MenuMap>::instance().find("IDS_MENU_MAIN_NORMAL").back();
-       EXPECT_EQ(menuItem->getName(), "IDS_TAP");
-       bindtextdomain(PROJECT_NAME, LOCALE_DIR);
-       textdomain(PROJECT_NAME);
-       setlocale(LC_ALL, "en_US.UTF-8");
-       EXPECT_EQ(menuItem->getName(), "Tap");
 }
\ No newline at end of file