[PATCH xorg-gtest] device: add PlayOne() for single event replaying

Chase Douglas chase.douglas at canonical.com
Wed Jul 11 22:07:30 PDT 2012


On 07/11/2012 09:59 PM, Peter Hutterer wrote:
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>   include/xorg/gtest/evemu/xorg-gtest-device.h |   14 ++++++++++++++
>   src/device.cpp                               |   20 ++++++++++++++++++++
>   2 files changed, 34 insertions(+)
>
> device->PlayOne(EV_KEY, KEY_Q, 1) is much nicer than having recordings for this.
>
> diff --git a/include/xorg/gtest/evemu/xorg-gtest-device.h b/include/xorg/gtest/evemu/xorg-gtest-device.h
> index e4b3c4e..35e5459 100644
> --- a/include/xorg/gtest/evemu/xorg-gtest-device.h
> +++ b/include/xorg/gtest/evemu/xorg-gtest-device.h
> @@ -76,6 +76,20 @@ class Device {
>     void Play(const std::string& path) const;
>
>     /**
> +   * Play a single event through the device.
> +   *
> +   * Plays an event with the given type, code and value through the device.
> +   *
> +   * @param [in] type Evdev interface event type, e.g. EV_ABS, EV_REL, EV_KEY.
> +   * @param [in] code Evdev interface event code, e.g. ABS_X, REL_Y, BTN_LEFT
> +   * @param [in] value Event value
> +   * @param [in] sync If true, submit an EV_SYN event after this event
> +   *
> +   * @throws std::runtime_error if playback failed for any reason.
> +   */
> +  void PlayOne(int type, int code, int value, bool sync = false);
> +
> +  /**
>      * Return the /dev/input/eventX device node for this device.
>      *
>      * Note that evemu doesn't know the device node, so we traverse the file
> diff --git a/src/device.cpp b/src/device.cpp
> index 0f1cef7..e23e52e 100644
> --- a/src/device.cpp
> +++ b/src/device.cpp
> @@ -27,6 +27,7 @@
>
>   #include "xorg/gtest/evemu/xorg-gtest-device.h"
>
> +#include <linux/input.h>
>   #include <fcntl.h>
>   #include <dirent.h>
>
> @@ -149,6 +150,25 @@ void xorg::testing::evemu::Device::Play(const std::string& path) const {
>     fclose(file);
>   }
>
> +void xorg::testing::evemu::Device::PlayOne(int type, int code, int value, bool sync)
> +{
> +  struct input_event ev;
> +  if (evemu_create_event(&ev, type, code, value))
> +    throw std::runtime_error("Failed to create event");
> +
> +  if (evemu_play_one(d_->fd, &ev))
> +    throw std::runtime_error("Failed to play event");
> +
> +  if (sync) {
> +    if (evemu_create_event(&ev, EV_SYN, SYN_REPORT, 0))
> +      throw std::runtime_error("Failed to create EV_SYN event");
> +
> +    if (evemu_play_one(d_->fd, &ev))
> +      throw std::runtime_error("Failed to play EV_SYN event");
> +  }
> +

Stray newline ^^

> +}
> +
>   const std::string& xorg::testing::evemu::Device::GetDeviceNode(void) {
>     return d_->device_node;
>   }
>

Looks good!

Reviewed-by: Chase Douglas <chase.douglas at canonical.com>


More information about the xorg-devel mailing list