| 1 |
/** |
| 2 |
* Test touchscreen input transformation |
| 3 |
|
| 4 |
* Copyright (C) 2015 Sylvain Beucler |
| 5 |
|
| 6 |
* This file is part of GNU FreeDink |
| 7 |
|
| 8 |
* GNU FreeDink is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU General Public License as |
| 10 |
* published by the Free Software Foundation; either version 3 of the |
| 11 |
* License, or (at your option) any later version. |
| 12 |
|
| 13 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* General Public License for more details. |
| 17 |
|
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see |
| 20 |
* <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifdef HAVE_CONFIG_H |
| 24 |
#include <config.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include "IOTouchDragAnywhere.h" |
| 28 |
#include "SDL.h" |
| 29 |
|
| 30 |
void pushEvent(IOTouchDragAnywhere *conv, SDL_EventType type, SDL_TouchID tid, SDL_FingerID fid, float x, float y) { |
| 31 |
SDL_Event ev; |
| 32 |
ev.type = type; |
| 33 |
ev.tfinger.touchId = tid; |
| 34 |
ev.tfinger.fingerId = fid; |
| 35 |
ev.tfinger.x = x; |
| 36 |
ev.tfinger.y = y; |
| 37 |
conv->convertInput(&ev); |
| 38 |
} |
| 39 |
|
| 40 |
class TestTouch : public CxxTest::TestSuite { |
| 41 |
public: |
| 42 |
void setUp() { |
| 43 |
} |
| 44 |
void tearDown() { |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
void testTransform() { |
| 49 |
IOTouchDragAnywhere conv; |
| 50 |
|
| 51 |
// Set center of virtual joystick |
| 52 |
{ |
| 53 |
pushEvent(&conv, SDL_FINGERDOWN, 9,0, .2,.7); |
| 54 |
TS_ASSERT_DELTA(conv.anchor.x, .2, 1e-7); |
| 55 |
SDL_Event getev; |
| 56 |
TS_ASSERT_EQUALS(0, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP)); |
| 57 |
} |
| 58 |
|
| 59 |
// First motion above the center triggers KEYUP |
| 60 |
{ |
| 61 |
pushEvent(&conv, SDL_FINGERMOTION, 9,0, .2,.5); |
| 62 |
SDL_Event getev; |
| 63 |
TS_ASSERT_EQUALS(1, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYDOWN)); |
| 64 |
TS_ASSERT_EQUALS(getev.key.state, SDL_PRESSED); |
| 65 |
TS_ASSERT_EQUALS(getev.key.keysym.scancode, SDL_SCANCODE_UP); |
| 66 |
TS_ASSERT_EQUALS(0, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYUP, SDL_KEYDOWN)); |
| 67 |
} |
| 68 |
|
| 69 |
// Next motions don't trigger nothin' |
| 70 |
{ |
| 71 |
pushEvent(&conv, SDL_FINGERMOTION, 9,0, .2,.51); |
| 72 |
SDL_Event getev; |
| 73 |
TS_ASSERT_EQUALS(0, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP)); |
| 74 |
} |
| 75 |
|
| 76 |
// Touching a different finger is ignored |
| 77 |
{ |
| 78 |
pushEvent(&conv, SDL_FINGERDOWN, 9,1, .2,.5); |
| 79 |
pushEvent(&conv, SDL_FINGERMOTION, 9,1, .2,.7); |
| 80 |
pushEvent(&conv, SDL_FINGERUP, 9,1, .2,.5); |
| 81 |
pushEvent(&conv, SDL_FINGERMOTION, 9,1, .2,.71); |
| 82 |
pushEvent(&conv, SDL_FINGERUP, 9,1, .2,.5); |
| 83 |
SDL_Event getev; |
| 84 |
TS_ASSERT_EQUALS(0, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP)); |
| 85 |
} |
| 86 |
|
| 87 |
// Going back to center triggers KEYUP |
| 88 |
{ |
| 89 |
pushEvent(&conv, SDL_FINGERMOTION, 9,0, .2,.7); |
| 90 |
SDL_Event getev; |
| 91 |
TS_ASSERT_EQUALS(1, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYUP, SDL_KEYUP)); |
| 92 |
TS_ASSERT_EQUALS(getev.key.state, SDL_RELEASED); |
| 93 |
TS_ASSERT_EQUALS(getev.key.keysym.scancode, SDL_SCANCODE_UP); |
| 94 |
TS_ASSERT_EQUALS(0, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP)); |
| 95 |
} |
| 96 |
|
| 97 |
// Releasing the original finger stops tracking + triggers KEYUP |
| 98 |
{ |
| 99 |
pushEvent(&conv, SDL_FINGERMOTION, 9,0, .2,.5); |
| 100 |
SDL_Event getev; |
| 101 |
TS_ASSERT_EQUALS(1, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYDOWN)); |
| 102 |
TS_ASSERT_EQUALS(getev.key.state, SDL_PRESSED); |
| 103 |
TS_ASSERT_EQUALS(getev.key.keysym.scancode, SDL_SCANCODE_UP); |
| 104 |
TS_ASSERT_EQUALS(0, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP)); |
| 105 |
|
| 106 |
pushEvent(&conv, SDL_FINGERUP, 9,0, .2,.5); |
| 107 |
TS_ASSERT_EQUALS(1, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYUP, SDL_KEYUP)); |
| 108 |
TS_ASSERT_EQUALS(getev.key.state, SDL_RELEASED); |
| 109 |
TS_ASSERT_EQUALS(getev.key.keysym.scancode, SDL_SCANCODE_UP); |
| 110 |
TS_ASSERT_EQUALS(0, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYUP)); |
| 111 |
pushEvent(&conv, SDL_FINGERUP, 9,0, .2,.5); |
| 112 |
TS_ASSERT_EQUALS(0, SDL_PeepEvents(&getev, 1, SDL_GETEVENT, SDL_KEYUP, SDL_KEYUP)); |
| 113 |
} |
| 114 |
} |
| 115 |
}; |