6cd2a9dda10ad9d334d9a13e3178ed43a2f9dbe2
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-Key.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // EXTERNAL INCLUDES
19 #include <map>
20 #include <string.h>
21 #include <iostream>
22
23 // CLASS HEADER
24 #include <stdlib.h>
25 #include <iostream>
26 #include <dali.h>
27 #include <dali-test-suite-utils.h>
28
29 using namespace Dali;
30
31 void utc_dali_adaptor_key_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_adaptor_key_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 // Copied from key-impl.cpp
42 struct KeyLookup
43 {
44   const char* keyName;      ///< X string representation
45   const int   daliKeyCode;  ///< Dali Enum Representation
46   const bool  deviceButton; ///< Whether the key is from a button on the device
47 };
48
49 // Taken from utilX.h
50 #define KEY_VOLUMEUP            "XF86AudioRaiseVolume"  /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Volume Up' key */
51 #define KEY_VOLUMEDOWN          "XF86AudioLowerVolume"  /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Volume Down' key */
52
53 #define KEY_CAMERA              "XF86WebCam"    /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Half-Press of Camera' key */
54 #define KEY_CONFIG              "XF86Pictures"  /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Full-Press of Camera' key */
55
56 #define KEY_POWER               "XF86PowerOff"  /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Power' key */
57 #define KEY_PAUSE               "XF86Standby"   /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Pause' key */
58 #define KEY_CANCEL              "Cancel"        /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Cancel' key */
59
60 // Earjack/BT Headset/Multimedia keys
61 #define KEY_PLAYCD              "XF86AudioPlay" /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Play Audio' key */
62 #define KEY_STOPCD              "XF86AudioStop" /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Stop Audio' key */
63 #define KEY_PAUSECD             "XF86AudioPause"        /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Pause Audio' key */
64 #define KEY_NEXTSONG            "XF86AudioNext" /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Next Song' key */
65 #define KEY_PREVIOUSSONG        "XF86AudioPrev" /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Previous Song' key */
66 #define KEY_REWIND              "XF86AudioRewind"       /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Rewind Song' key */
67 #define KEY_FASTFORWARD         "XF86AudioForward"      /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Forward Song' key */
68 #define KEY_MEDIA               "XF86AudioMedia"        /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Media' key */
69 #define KEY_PLAYPAUSE           "XF86AudioPlayPause"    /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'PlayPause' key */
70 #define KEY_MUTE                        "XF86AudioMute" /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Mute' key */
71
72 // 3-Touch key
73 #define KEY_SEND                "XF86Send"      /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Send' key */
74 #define KEY_SELECT              "XF86Phone"     /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Home' key */
75 #define KEY_END                 "XF86Stop"      /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'End' key */
76
77 // Renamed 3-Touch key
78 #define KEY_MENU                "XF86Send"      /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Send' key */
79 #define KEY_HOME                "XF86Phone"     /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Home' key */
80 #define KEY_BACK                "XF86Stop"      /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'End' key */
81
82 //Other functions keys
83 #define KEY_HOMEPAGE            "XF86HomePage"  /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'HomePage' key */
84 #define KEY_WEBPAGE             "XF86WWW"       /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'WWW' key */
85 #define KEY_MAIL                        "XF86Mail"      /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Mail' key */
86 #define KEY_SCREENSAVER "XF86ScreenSaver"       /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'ScreenSaver' key */
87 #define KEY_BRIGHTNESSUP        "XF86MonBrightnessUp"   /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'BrightnessUp' key */
88 #define KEY_BRIGHTNESSDOWN      "XF86MonBrightnessDown" /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'BrightnessDown' key */
89 #define KEY_SOFTKBD                     "XF86MenuKB"    /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Soft keyboard(toggle)' key */
90 #define KEY_QUICKPANEL          "XF86Tools"     /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Quick panel(toggle)' key */
91 #define KEY_TASKSWITCH          "XF86TaskPane"  /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Task switcher(toggle)' key */
92 #define KEY_APPS                "XF86Launch0"   /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Apptray(toggle)' key */
93 #define KEY_SEARCH              "XF86Search"            /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Search(toggle)' key */
94 #define KEY_VOICE               "XF86Launch2"           /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Voice(toggle)' key */
95 #define KEY_LANGUAGE            "Hangul"                /**< this macro means the XKeySym (XServer Key Symbol) corresponds to 'Language(toggle)' key */
96
97 // Taken from key-impl.cpp
98 KeyLookup KeyLookupTable[]=
99 {
100   // KeyName                DALi Equivalent           true if device key
101   { "Escape",               DALI_KEY_ESCAPE,          false },
102   { "Menu",                 DALI_KEY_MENU,            false },
103   { KEY_CAMERA,             DALI_KEY_CAMERA,          false },
104   { KEY_CONFIG,             DALI_KEY_CONFIG,          false },
105   { KEY_POWER,              DALI_KEY_POWER,           true  },
106   { KEY_PAUSE,              DALI_KEY_PAUSE,           false },
107   { KEY_CANCEL,             DALI_KEY_CANCEL,          false },
108   { KEY_PLAYCD,             DALI_KEY_PLAY_CD,         false },
109   { KEY_STOPCD,             DALI_KEY_STOP_CD,         false },
110   { KEY_PAUSECD,            DALI_KEY_PAUSE_CD,        false },
111   { KEY_NEXTSONG,           DALI_KEY_NEXT_SONG,       false },
112   { KEY_PREVIOUSSONG,       DALI_KEY_PREVIOUS_SONG,   false },
113   { KEY_REWIND,             DALI_KEY_REWIND,          false },
114   { KEY_FASTFORWARD,        DALI_KEY_FASTFORWARD,     false },
115   { KEY_MEDIA,              DALI_KEY_MEDIA,           false },
116   { KEY_PLAYPAUSE,          DALI_KEY_PLAY_PAUSE,      false },
117   { KEY_MUTE,               DALI_KEY_MUTE,            false },
118   { KEY_SEND,               DALI_KEY_SEND,            true  },
119   { KEY_SELECT,             DALI_KEY_SELECT,          true  },
120   { KEY_END,                DALI_KEY_END,             true  },
121   { KEY_MENU,               DALI_KEY_MENU,            true  },
122   { KEY_HOME,               DALI_KEY_HOME,            true  },
123   { KEY_BACK,               DALI_KEY_BACK,            true  },
124   { KEY_HOMEPAGE,           DALI_KEY_HOMEPAGE,        false },
125   { KEY_WEBPAGE,            DALI_KEY_WEBPAGE,         false },
126   { KEY_MAIL,               DALI_KEY_MAIL,            false },
127   { KEY_SCREENSAVER,        DALI_KEY_SCREENSAVER,     false },
128   { KEY_BRIGHTNESSUP,       DALI_KEY_BRIGHTNESS_UP,   false },
129   { KEY_BRIGHTNESSDOWN,     DALI_KEY_BRIGHTNESS_DOWN, false },
130   { KEY_SOFTKBD,            DALI_KEY_SOFT_KBD,        false },
131   { KEY_QUICKPANEL,         DALI_KEY_QUICK_PANEL,     false },
132   { KEY_TASKSWITCH,         DALI_KEY_TASK_SWITCH,     false },
133   { KEY_APPS,               DALI_KEY_APPS,            false },
134   { KEY_SEARCH,             DALI_KEY_SEARCH,          false },
135   { KEY_VOICE,              DALI_KEY_VOICE,           false },
136   { KEY_LANGUAGE,           DALI_KEY_LANGUAGE,        false },
137   { KEY_VOLUMEUP,           DALI_KEY_VOLUME_UP,       true  },
138   { KEY_VOLUMEDOWN,         DALI_KEY_VOLUME_DOWN,     true  },
139 };
140 const std::size_t KEY_LOOKUP_COUNT = (sizeof( KeyLookupTable))/ (sizeof(KeyLookup));
141
142
143 // Generate a KeyPressEvent to send to Core
144 Dali::KeyEvent GenerateKeyPress( const std::string& keyName )
145 {
146   KeyEvent keyPress;
147   keyPress.keyPressedName = keyName;
148   return keyPress;
149 }
150
151 int UtcDaliKeyIsKey(void)
152 {
153   TestApplication application;
154
155   for ( std::size_t i = 0; i < KEY_LOOKUP_COUNT; ++i )
156   {
157     tet_printf( "Checking %s", KeyLookupTable[i].keyName );
158     DALI_TEST_CHECK( IsKey( GenerateKeyPress( KeyLookupTable[i].keyName ), KeyLookupTable[i].daliKeyCode ) );
159   }
160   END_TEST;
161 }
162
163 int UtcDaliKeyIsKeyNegative(void)
164 {
165   TestApplication application;
166
167   // Random value
168   DALI_TEST_CHECK( IsKey( GenerateKeyPress( "invalid-key-name" ), DALI_KEY_MUTE ) == false );
169
170   // Compare with another key value
171   for ( std::size_t i = 0; i < KEY_LOOKUP_COUNT; ++i )
172   {
173     tet_printf( "Checking %s", KeyLookupTable[i].keyName );
174     DALI_TEST_CHECK( IsKey( GenerateKeyPress( KeyLookupTable[i].keyName ), KeyLookupTable[ ( i + 1 ) % KEY_LOOKUP_COUNT ].daliKeyCode ) == false );
175   }
176   END_TEST;
177 }