Dali 3D User Interface Engine
utc-Dali-KeyGrab.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 #include <dali/public-api/adaptor-framework/key-grab.h>
29 
30 extern int gArgc;
31 extern char ** gArgv;
32 
33 using namespace Dali;
34 
36 {
38 }
39 
41 {
43 }
44 
45 // Copied from key-impl.cpp
46 struct KeyLookup
47 {
48  const char* keyName;
49  const KEY daliKeyCode;
50  const bool deviceButton;
51 };
52 
53 // Taken from key-impl.cpp
55 {
56  { "Escape", DALI_KEY_ESCAPE, false }, // item not defined in utilX
57  { "Menu", DALI_KEY_MENU, false }, // item not defined in utilX
58 
59  // Now the key names are used as literal string not defined symbols,
60  // since these definition in utilX.h is deprecated and we're guided not to use them
61  { "XF86Camera", DALI_KEY_CAMERA, false },
62  { "XF86Camera_Full", DALI_KEY_CONFIG, false },
63  { "XF86PowerOff", DALI_KEY_POWER, true },
64  { "Cancel", DALI_KEY_CANCEL, false },
65  { "XF86AudioPlay", DALI_KEY_PLAY_CD, false },
66  { "XF86AudioStop", DALI_KEY_STOP_CD, false },
67  { "XF86AudioPause", DALI_KEY_PAUSE_CD, false },
68  { "XF86AudioNext", DALI_KEY_NEXT_SONG, false },
69  { "XF86AudioPrev", DALI_KEY_PREVIOUS_SONG, false },
70  { "XF86AudioRewind", DALI_KEY_REWIND, false },
71  { "XF86AudioForward", DALI_KEY_FASTFORWARD, false },
72  { "XF86AudioMedia", DALI_KEY_MEDIA, false },
73  { "XF86AudioPlayPause", DALI_KEY_PLAY_PAUSE, false },
74  { "XF86AudioMute", DALI_KEY_MUTE, false },
75  { "XF86Menu", DALI_KEY_MENU, true },
76  { "XF86HomePage", DALI_KEY_HOMEPAGE, false },
77  { "XF86WWW", DALI_KEY_WEBPAGE, false },
78  { "XF86Mail", DALI_KEY_MAIL, false },
79  { "XF86ScreenSaver", DALI_KEY_SCREENSAVER, false },
80  { "XF86MonBrightnessUp", DALI_KEY_BRIGHTNESS_UP, false },
81  { "XF86MonBrightnessDown", DALI_KEY_BRIGHTNESS_DOWN, false },
82  { "XF86SoftKBD", DALI_KEY_SOFT_KBD, false },
83  { "XF86QuickPanel", DALI_KEY_QUICK_PANEL, false },
84  { "XF86TaskPane", DALI_KEY_TASK_SWITCH, false },
85  { "XF86Apps", DALI_KEY_APPS, false },
86  { "XF86Search", DALI_KEY_SEARCH, false },
87  { "XF86Voice", DALI_KEY_VOICE, false },
88  { "Hangul", DALI_KEY_LANGUAGE, false },
89  { "XF86AudioRaiseVolume", DALI_KEY_VOLUME_UP, true },
90  { "XF86AudioLowerVolume", DALI_KEY_VOLUME_DOWN, true },
91 
92  { "BackSpace", DALI_KEY_BACKSPACE, false },
93  { "Left", DALI_KEY_CURSOR_LEFT, false },
94  { "Right", DALI_KEY_CURSOR_RIGHT, false }
95 };
96 
97 const std::size_t KEY_LOOKUP_COUNT = (sizeof( TestKeyLookupTable))/ (sizeof(KeyLookup));
98 
100 {
103 };
104 
106 {
107  MyTestApp( Application& app, int type )
108  : mApplication( app ),
109  mTestType( type )
110  {
111  mApplication.InitSignal().Connect( this, &MyTestApp::OnInit );
112  }
113 
114  void OnInit(Application& app)
115  {
116  mTimer = Timer::New( 500 );
117  mTimer.TickSignal().Connect( this, &MyTestApp::Tick );
118  mTimer.Start();
119 
120  ExcuteTest();
121  }
122 
123  bool Tick()
124  {
125  mTimer.Stop();
126  mApplication.Quit();
127  return true;
128  }
129 
130  void ExcuteTest()
131  {
132  switch (mTestType)
133  {
134  case GRAB_KEY_TOPMOST_P:
135  TestGrabKeyTopmostP();
136  break;
138  TestUngrabKeyTopmostP();
139  break;
140  }
141  }
142 
143  void TestGrabKeyTopmostP()
144  {
145  for ( std::size_t i = 0; i < KEY_LOOKUP_COUNT; ++i )
146  {
147  DALI_TEST_CHECK( KeyGrab::GrabKeyTopmost( mApplication.GetWindow(), TestKeyLookupTable[i].daliKeyCode ) );
148  }
149  }
150 
151  void TestUngrabKeyTopmostP()
152  {
153  for ( std::size_t i = 0; i < KEY_LOOKUP_COUNT; ++i )
154  {
155  DALI_TEST_CHECK( KeyGrab::GrabKeyTopmost( mApplication.GetWindow(), TestKeyLookupTable[i].daliKeyCode ) );
156  DALI_TEST_CHECK( KeyGrab::UngrabKeyTopmost( mApplication.GetWindow(), TestKeyLookupTable[i].daliKeyCode ) );
157  }
158  }
159 
160  // Data
164 };
165 
167 {
168  Application application = Application::New( &gArgc, &gArgv );
169  MyTestApp testApp( application, GRAB_KEY_TOPMOST_P );
170  application.MainLoop();
171  END_TEST;
172 }
173 
175 {
176  Application application = Application::New( &gArgc, &gArgv );
177  MyTestApp testApp( application, UNGRAB_KEY_TOPMOST_P );
178  application.MainLoop();
179  END_TEST;
180 }
Dali Docs Home
Read more about Dali