示例#1
0
def assert_keypress(sut, mocked_sdl_event_queue, stub_events, sdl_key, char):
    # given
    keydown = stub_events.malloc(RSDL.KeyboardEvent)
    keydown.c_type = RSDL.KEYDOWN
    keydown.c_keysym.c_sym = rffi.r_int(sdl_key)
    textinput = stub_events.malloc(RSDL.TextInputEvent)
    textinput.c_type = RSDL.TEXTINPUT
    rffi.str2chararray(
        str(char) + '\x00', textinput.c_text, RSDL.TEXTINPUTEVENT_TEXT_SIZE)
    keyup = stub_events.malloc(RSDL.KeyboardEvent)
    keyup.c_type = RSDL.KEYUP
    keyup.c_keysym.c_sym = rffi.r_int(sdl_key)
    mocked_sdl_event_queue.append(keydown)
    mocked_sdl_event_queue.append(textinput)
    mocked_sdl_event_queue.append(keyup)
    # when
    first_event = sut.get_next_event()
    second_event = sut.get_next_event()
    third_event = sut.get_next_event()
    # then
    assert_keyevent_array(first_event, ord(char.upper()), display.EventKeyDown,
                          0)
    assert_keyevent_array(second_event, ord(char), display.EventKeyChar, 0)
    assert_keyevent_array(third_event, ord(char.upper()), display.EventKeyUp,
                          0)
示例#2
0
def test_entering_captital_letters(sut, mocked_sdl_event_queue, stub_events,
                                   stub_mod_state):
    # when
    # shift down
    shift_down = stub_events.malloc(RSDL.KeyboardEvent)
    shift_down.c_type = RSDL.KEYDOWN
    shift_down.c_keysym.c_sym = rffi.r_int(RSDL.K_LSHIFT)
    mocked_sdl_event_queue.append(shift_down)
    stub_mod_state.set(RSDL.KMOD_SHIFT)
    sqShiftDown = sut.get_next_event()
    # A down
    a_down = stub_events.malloc(RSDL.KeyboardEvent)
    a_down.c_type = RSDL.KEYDOWN
    a_down.c_keysym.c_sym = rffi.r_int(RSDL.K_a)
    mocked_sdl_event_queue.append(a_down)
    sqADown = sut.get_next_event()
    # A entered
    a_textinput = stub_events.malloc(RSDL.TextInputEvent)
    a_textinput.c_type = RSDL.TEXTINPUT
    rffi.str2chararray('A\x00', a_textinput.c_text,
                       RSDL.TEXTINPUTEVENT_TEXT_SIZE)
    mocked_sdl_event_queue.append(a_textinput)
    sqAStroke = sut.get_next_event()
    # repeat A entered
    mocked_sdl_event_queue.append(a_down)
    mocked_sdl_event_queue.append(a_textinput)
    sqADown2 = sut.get_next_event()
    sqAStroke2 = sut.get_next_event()
    # A up
    a_up = stub_events.malloc(RSDL.KeyboardEvent)
    a_up.c_type = RSDL.KEYUP
    a_up.c_keysym.c_sym = rffi.r_int(RSDL.K_a)
    mocked_sdl_event_queue.append(a_up)
    sqAUp = sut.get_next_event()
    # shift up
    shift_up = stub_events.malloc(RSDL.KeyboardEvent)
    shift_up.c_type = RSDL.KEYUP
    shift_up.c_keysym.c_sym = rffi.r_int(RSDL.K_LSHIFT)
    mocked_sdl_event_queue.append(shift_up)
    stub_mod_state.set(RSDL.KMOD_NONE)
    sqShiftUp = sut.get_next_event()
    # then
    assert_keyevent_array(sqShiftDown, key_constants.SHIFT,
                          display.EventKeyDown, display.ShiftKeyBit)
    assert_keyevent_array(sqADown, ord('A'), display.EventKeyDown,
                          display.ShiftKeyBit)
    assert_keyevent_array(sqAStroke, ord('A'), display.EventKeyChar,
                          display.ShiftKeyBit)
    assert_keyevent_array(sqADown2, ord('A'), display.EventKeyDown,
                          display.ShiftKeyBit)
    assert_keyevent_array(sqAStroke2, ord('A'), display.EventKeyChar,
                          display.ShiftKeyBit)
    assert_keyevent_array(sqAUp, ord('A'), display.EventKeyUp,
                          display.ShiftKeyBit)
    assert_keyevent_array(sqShiftUp, key_constants.SHIFT, display.EventKeyUp,
                          0)
示例#3
0
def test_keyboard_chords(sut, mocked_sdl_event_queue, stub_events, stub_mod_state):
    # when
    # CTRL down
    ctrl_down = stub_events.malloc(RSDL.KeyboardEvent)
    ctrl_down.c_type = RSDL.KEYDOWN
    ctrl_down.c_keysym.c_sym = rffi.r_int(RSDL.K_LCTRL)
    mocked_sdl_event_queue.append(ctrl_down)
    stub_mod_state.set(RSDL.KMOD_CTRL)
    sqCtrlDown = sut.get_next_event()
    # A down
    a_down = stub_events.malloc(RSDL.KeyboardEvent)
    a_down.c_type = RSDL.KEYDOWN
    a_down.c_keysym.c_sym = rffi.r_int(RSDL.K_a)
    mocked_sdl_event_queue.append(a_down)
    sqADown = sut.get_next_event()
    # A entered
    if system.IS_LINUX:
        # on linux, we don't get this
        a_stroke = stub_events.malloc(RSDL.TextInputEvent)
        a_stroke.c_type = RSDL.TEXTINPUT
        rffi.str2chararray('a\x00', a_stroke.c_text, RSDL.TEXTINPUTEVENT_TEXT_SIZE)
        mocked_sdl_event_queue.append(a_stroke)
    sqAStroke = sut.get_next_event()
    # repeat A
    mocked_sdl_event_queue.append(a_down)
    sqADown2 = sut.get_next_event()
    if system.IS_LINUX:
        # on linux, we don't get this
        a_stroke = stub_events.malloc(RSDL.TextInputEvent)
        a_stroke.c_type = RSDL.TEXTINPUT
        rffi.str2chararray('a\x00', a_stroke.c_text, RSDL.TEXTINPUTEVENT_TEXT_SIZE)
        mocked_sdl_event_queue.append(a_stroke)
    sqAStroke2 = sut.get_next_event()
    # A up
    a_up = stub_events.malloc(RSDL.KeyboardEvent)
    a_up.c_type = RSDL.KEYUP
    a_up.c_keysym.c_sym = rffi.r_int(RSDL.K_a)
    mocked_sdl_event_queue.append(a_up)
    sqAUp = sut.get_next_event()
    # CTRL up
    ctrl_up = stub_events.malloc(RSDL.KeyboardEvent)
    ctrl_up.c_type = RSDL.KEYUP
    ctrl_up.c_keysym.c_sym = rffi.r_int(RSDL.K_LCTRL)
    mocked_sdl_event_queue.append(ctrl_up)
    stub_mod_state.set(RSDL.KMOD_NONE)
    sqCtrlUp = sut.get_next_event()
    # then
    assert_keyevent_array(sqCtrlDown, key_constants.CTRL, display.EventKeyDown, display.CtrlKeyBit)
    assert_keyevent_array(sqADown, ord('A'), display.EventKeyDown, display.CtrlKeyBit)
    assert_keyevent_array(sqAStroke, ord('a'), display.EventKeyChar, display.CtrlKeyBit)
    assert_keyevent_array(sqADown2, ord('A'), display.EventKeyDown, display.CtrlKeyBit)
    assert_keyevent_array(sqAStroke2, ord('a'), display.EventKeyChar, display.CtrlKeyBit)
    assert_keyevent_array(sqAUp, ord('A'), display.EventKeyUp, display.CtrlKeyBit)
    assert_keyevent_array(sqCtrlUp, key_constants.CTRL, display.EventKeyUp, 0)
示例#4
0
def test_entering_captital_letters(sut, mocked_sdl_event_queue, stub_events, stub_mod_state):
    # when
    # shift down
    shift_down = stub_events.malloc(RSDL.KeyboardEvent)
    shift_down.c_type = RSDL.KEYDOWN
    shift_down.c_keysym.c_sym = rffi.r_int(RSDL.K_LSHIFT)
    mocked_sdl_event_queue.append(shift_down)
    stub_mod_state.set(RSDL.KMOD_SHIFT)
    sqShiftDown = sut.get_next_event()
    # A down
    a_down = stub_events.malloc(RSDL.KeyboardEvent)
    a_down.c_type = RSDL.KEYDOWN
    a_down.c_keysym.c_sym = rffi.r_int(RSDL.K_a)
    mocked_sdl_event_queue.append(a_down)
    sqADown = sut.get_next_event()
    # A entered
    a_textinput = stub_events.malloc(RSDL.TextInputEvent)
    a_textinput.c_type = RSDL.TEXTINPUT
    rffi.str2chararray('A\x00', a_textinput.c_text, RSDL.TEXTINPUTEVENT_TEXT_SIZE)
    mocked_sdl_event_queue.append(a_textinput)
    sqAStroke = sut.get_next_event()
    # repeat A entered
    mocked_sdl_event_queue.append(a_down)
    mocked_sdl_event_queue.append(a_textinput)
    sqADown2 = sut.get_next_event()
    sqAStroke2 = sut.get_next_event()
    # A up
    a_up = stub_events.malloc(RSDL.KeyboardEvent)
    a_up.c_type = RSDL.KEYUP
    a_up.c_keysym.c_sym = rffi.r_int(RSDL.K_a)
    mocked_sdl_event_queue.append(a_up)
    sqAUp = sut.get_next_event()
    # shift up
    shift_up = stub_events.malloc(RSDL.KeyboardEvent)
    shift_up.c_type = RSDL.KEYUP
    shift_up.c_keysym.c_sym = rffi.r_int(RSDL.K_LSHIFT)
    mocked_sdl_event_queue.append(shift_up)
    stub_mod_state.set(RSDL.KMOD_NONE)
    sqShiftUp = sut.get_next_event()
    # then
    assert_keyevent_array(sqShiftDown, key_constants.SHIFT, display.EventKeyDown, display.ShiftKeyBit)
    assert_keyevent_array(sqADown, ord('A'), display.EventKeyDown, display.ShiftKeyBit)
    assert_keyevent_array(sqAStroke, ord('A'), display.EventKeyChar, display.ShiftKeyBit)
    assert_keyevent_array(sqADown2, ord('A'), display.EventKeyDown, display.ShiftKeyBit)
    assert_keyevent_array(sqAStroke2, ord('A'), display.EventKeyChar, display.ShiftKeyBit)
    assert_keyevent_array(sqAUp, ord('A'), display.EventKeyUp, display.ShiftKeyBit)
    assert_keyevent_array(sqShiftUp, key_constants.SHIFT, display.EventKeyUp, 0)
示例#5
0
文件: rsocket.py 项目: GaussDing/pypy
 def get_ifindex_from_ifname(fd, ifname):
     p = lltype.malloc(_c.ifreq, flavor="raw")
     iflen = rffi.str2chararray(ifname, rffi.cast(rffi.CCHARP, p.c_ifr_name), PacketAddress.ifr_name_size - 1)
     p.c_ifr_name[iflen] = "\0"
     err = _c.ioctl(fd, _c.SIOCGIFINDEX, p)
     ifindex = p.c_ifr_ifindex
     lltype.free(p, flavor="raw")
     if err != 0:
         raise RSocketError("invalid interface name")
     return ifindex
示例#6
0
文件: rsocket.py 项目: GaussDing/pypy
 def __init__(self, ifindex, protocol, pkttype=0, hatype=0, haddr=""):
     addr = lltype.malloc(_c.sockaddr_ll, flavor="raw", zero=True, track_allocation=False)
     self.setdata(addr, PacketAddress.maxlen)
     rffi.setintfield(addr, "c_sll_family", AF_PACKET)
     rffi.setintfield(addr, "c_sll_protocol", htons(protocol))
     rffi.setintfield(addr, "c_sll_ifindex", ifindex)
     rffi.setintfield(addr, "c_sll_pkttype", pkttype)
     rffi.setintfield(addr, "c_sll_hatype", hatype)
     halen = rffi.str2chararray(haddr, rffi.cast(rffi.CCHARP, addr.c_sll_addr), PacketAddress.sll_addr_size)
     rffi.setintfield(addr, "c_sll_halen", halen)
示例#7
0
def assert_keypress(sut, mocked_sdl_event_queue, stub_events, sdl_key, char):
    # given
    keydown = stub_events.malloc(RSDL.KeyboardEvent)
    keydown.c_type = RSDL.KEYDOWN
    keydown.c_keysym.c_sym = rffi.r_int(sdl_key)
    textinput = stub_events.malloc(RSDL.TextInputEvent)
    textinput.c_type = RSDL.TEXTINPUT
    rffi.str2chararray(str(char) + '\x00', textinput.c_text,
            RSDL.TEXTINPUTEVENT_TEXT_SIZE)
    keyup = stub_events.malloc(RSDL.KeyboardEvent)
    keyup.c_type = RSDL.KEYUP
    keyup.c_keysym.c_sym = rffi.r_int(sdl_key)
    mocked_sdl_event_queue.append(keydown)
    mocked_sdl_event_queue.append(textinput)
    mocked_sdl_event_queue.append(keyup)
    # when
    first_event = sut.get_next_event()
    second_event = sut.get_next_event()
    third_event = sut.get_next_event()
    # then
    assert_keyevent_array(first_event, ord(char.upper()), display.EventKeyDown, 0)
    assert_keyevent_array(second_event, ord(char), display.EventKeyChar, 0)
    assert_keyevent_array(third_event, ord(char.upper()), display.EventKeyUp, 0)
示例#8
0
 def setslice(self, index, s):
     assert s is not None
     ptr = rffi.ptradd(cts.cast('char *', self.view.ptr), index)
     rffi.str2chararray(s, ptr, len(s))
示例#9
0
def test_keyboard_chords(sut, mocked_sdl_event_queue, stub_events,
                         stub_mod_state):
    # when
    # CTRL down
    ctrl_down = stub_events.malloc(RSDL.KeyboardEvent)
    ctrl_down.c_type = RSDL.KEYDOWN
    ctrl_down.c_keysym.c_sym = rffi.r_int(RSDL.K_LCTRL)
    mocked_sdl_event_queue.append(ctrl_down)
    stub_mod_state.set(RSDL.KMOD_CTRL)
    sqCtrlDown = sut.get_next_event()
    # A down
    a_down = stub_events.malloc(RSDL.KeyboardEvent)
    a_down.c_type = RSDL.KEYDOWN
    a_down.c_keysym.c_sym = rffi.r_int(RSDL.K_a)
    mocked_sdl_event_queue.append(a_down)
    sqADown = sut.get_next_event()
    # A entered
    if system.IS_LINUX:
        # on linux, we don't get this
        a_stroke = stub_events.malloc(RSDL.TextInputEvent)
        a_stroke.c_type = RSDL.TEXTINPUT
        rffi.str2chararray('a\x00', a_stroke.c_text,
                           RSDL.TEXTINPUTEVENT_TEXT_SIZE)
        mocked_sdl_event_queue.append(a_stroke)
    sqAStroke = sut.get_next_event()
    # repeat A
    mocked_sdl_event_queue.append(a_down)
    sqADown2 = sut.get_next_event()
    if system.IS_LINUX:
        # on linux, we don't get this
        a_stroke = stub_events.malloc(RSDL.TextInputEvent)
        a_stroke.c_type = RSDL.TEXTINPUT
        rffi.str2chararray('a\x00', a_stroke.c_text,
                           RSDL.TEXTINPUTEVENT_TEXT_SIZE)
        mocked_sdl_event_queue.append(a_stroke)
    sqAStroke2 = sut.get_next_event()
    # A up
    a_up = stub_events.malloc(RSDL.KeyboardEvent)
    a_up.c_type = RSDL.KEYUP
    a_up.c_keysym.c_sym = rffi.r_int(RSDL.K_a)
    mocked_sdl_event_queue.append(a_up)
    sqAUp = sut.get_next_event()
    # CTRL up
    ctrl_up = stub_events.malloc(RSDL.KeyboardEvent)
    ctrl_up.c_type = RSDL.KEYUP
    ctrl_up.c_keysym.c_sym = rffi.r_int(RSDL.K_LCTRL)
    mocked_sdl_event_queue.append(ctrl_up)
    stub_mod_state.set(RSDL.KMOD_NONE)
    sqCtrlUp = sut.get_next_event()
    # then
    assert_keyevent_array(sqCtrlDown, key_constants.CTRL, display.EventKeyDown,
                          display.CtrlKeyBit)
    assert_keyevent_array(sqADown, ord('A'), display.EventKeyDown,
                          display.CtrlKeyBit)
    assert_keyevent_array(sqAStroke, ord('a'), display.EventKeyChar,
                          display.CtrlKeyBit)
    assert_keyevent_array(sqADown2, ord('A'), display.EventKeyDown,
                          display.CtrlKeyBit)
    assert_keyevent_array(sqAStroke2, ord('a'), display.EventKeyChar,
                          display.CtrlKeyBit)
    assert_keyevent_array(sqAUp, ord('A'), display.EventKeyUp,
                          display.CtrlKeyBit)
    assert_keyevent_array(sqCtrlUp, key_constants.CTRL, display.EventKeyUp, 0)