Add tests for SGR protocol encoding
This commit is contained in:
parent
13d5f04ad9
commit
ce230b071b
@ -185,6 +185,7 @@ extern bool init_state(PyObject *module);
|
||||
extern bool init_keys(PyObject *module);
|
||||
extern bool init_graphics(PyObject *module);
|
||||
extern bool init_shaders(PyObject *module);
|
||||
extern bool init_mouse(PyObject *module);
|
||||
#ifdef __APPLE__
|
||||
extern int init_CoreText(PyObject *);
|
||||
extern bool init_cocoa(PyObject *module);
|
||||
@ -217,6 +218,7 @@ PyInit_fast_data_types(void) {
|
||||
if (!init_keys(m)) return NULL;
|
||||
if (!init_graphics(m)) return NULL;
|
||||
if (!init_shaders(m)) return NULL;
|
||||
if (!init_mouse(m)) return NULL;
|
||||
#ifdef __APPLE__
|
||||
if (!init_CoreText(m)) return NULL;
|
||||
if (!init_cocoa(m)) return NULL;
|
||||
|
||||
@ -385,3 +385,23 @@ scroll_event(double UNUSED xoffset, double yoffset) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
test_encode_mouse(PyObject *self UNUSED, PyObject *args) {
|
||||
unsigned int x, y;
|
||||
int mouse_tracking_protocol, button, action, mods;
|
||||
if (!PyArg_ParseTuple(args, "IIiiii", &x, &y, &mouse_tracking_protocol, &button, &action, &mods)) return NULL;
|
||||
int sz = encode_mouse_event_impl(x, y, mouse_tracking_protocol, button, action, mods);
|
||||
return PyUnicode_FromStringAndSize(mouse_event_buf, sz);
|
||||
}
|
||||
|
||||
static PyMethodDef module_methods[] = {
|
||||
METHODB(test_encode_mouse, METH_VARARGS),
|
||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
bool
|
||||
init_mouse(PyObject *module) {
|
||||
if (PyModule_AddFunctions(module, module_methods) != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -78,3 +78,30 @@ class TestParser(BaseTest):
|
||||
keycode = getattr(defines, 'GLFW_KEY_' + key)
|
||||
base_key = smkx_key_map[keycode]
|
||||
km(modify_key_bytes(base_key, num).decode('ascii')[1:], key)
|
||||
|
||||
def test_encode_mouse_event(self):
|
||||
PRESS, RELEASE, DRAG, MOVE = range(4)
|
||||
NORMAL_PROTOCOL, UTF8_PROTOCOL, SGR_PROTOCOL, URXVT_PROTOCOL = range(4)
|
||||
L, M, R = defines.GLFW_MOUSE_BUTTON_LEFT, defines.GLFW_MOUSE_BUTTON_MIDDLE, defines.GLFW_MOUSE_BUTTON_RIGHT
|
||||
protocol = SGR_PROTOCOL
|
||||
|
||||
def enc(button=L, action=PRESS, mods=0, x=1, y=1):
|
||||
return defines.test_encode_mouse(x, y, protocol, button, action, mods)
|
||||
|
||||
self.ae(enc(), '<0;1;1M')
|
||||
self.ae(enc(action=RELEASE), '<0;1;1m')
|
||||
self.ae(enc(action=MOVE), '<35;1;1M')
|
||||
self.ae(enc(action=DRAG), '<32;1;1M')
|
||||
|
||||
self.ae(enc(R), '<2;1;1M')
|
||||
self.ae(enc(R, action=RELEASE), '<2;1;1m')
|
||||
self.ae(enc(R, action=DRAG), '<34;1;1M')
|
||||
|
||||
self.ae(enc(M), '<1;1;1M')
|
||||
self.ae(enc(M, action=RELEASE), '<1;1;1m')
|
||||
self.ae(enc(M, action=DRAG), '<33;1;1M')
|
||||
|
||||
self.ae(enc(x=1234, y=5678), '<0;1234;5678M')
|
||||
self.ae(enc(mods=defines.GLFW_MOD_SHIFT), '<4;1;1M')
|
||||
self.ae(enc(mods=defines.GLFW_MOD_ALT), '<8;1;1M')
|
||||
self.ae(enc(mods=defines.GLFW_MOD_CONTROL), '<16;1;1M')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user