[PATCH xorg-gtest 5/5] Add xorg::testing::evemu::{Device, Recording}
Chase Douglas
chase.douglas at canonical.com
Mon Mar 5 14:05:27 PST 2012
On 03/05/2012 11:47 AM, Chase Douglas wrote:
> These new classes use utouch-evemu for input device recording playback.
>
> Signed-off-by: Chase Douglas<chase.douglas at canonical.com>
> ---
> configure.ac | 13 +++++
> include/Makefile.am | 6 ++
> include/xorg/gtest/evemu/device.h | 85 ++++++++++++++++++++++++++++++++
> include/xorg/gtest/evemu/recording.h | 89 ++++++++++++++++++++++++++++++++++
> src/Makefile.am | 8 +++
> src/device.cpp | 84 ++++++++++++++++++++++++++++++++
> src/recording.cpp | 51 +++++++++++++++++++
> 7 files changed, 336 insertions(+), 0 deletions(-)
> create mode 100644 include/xorg/gtest/evemu/device.h
> create mode 100644 include/xorg/gtest/evemu/recording.h
> create mode 100644 src/device.cpp
> create mode 100644 src/recording.cpp
>
> diff --git a/configure.ac b/configure.ac
> index 3178a3f..5e760e2 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -41,6 +41,19 @@ AS_IF([test "x$ac_cv_lib_gtest_main" != xyes],
>
> AC_SUBST([GTEST_CPPFLAGS])
>
> +# Check if we should include support for utouch-evemu
> +AC_ARG_WITH([evemu],
> + [AS_HELP_STRING([--with-evemu],
> + [support Linux input device recording playback (default: enabled if available)])],
> + [],
> + [with_evemu=check])
> +
> +AS_IF([test "x$with_evemu" == xyes],
> + [PKG_CHECK_MODULES(EVEMU, utouch-evemu, [have_evemu=yes])],
> + [test "x$with_evemu" == xcheck],
> + [PKG_CHECK_MODULES(EVEMU, utouch-evemu, [have_evemu=yes], [:])])
> +AM_CONDITIONAL([HAVE_EVEMU], [test "x$have_evemu" = "xyes"])
> +
> AC_SUBST(DUMMY_CONF_PATH, "$datadir/xorg/gtest/dummy.conf")
>
> AC_CONFIG_FILES([Makefile
> diff --git a/include/Makefile.am b/include/Makefile.am
> index 14768c3..26ce264 100644
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -27,3 +27,9 @@ nobase_include_HEADERS = \
> xorg/gtest/environment.h \
> xorg/gtest/process.h \
> xorg/gtest/test.h
> +
> +if HAVE_EVEMU
> +nobase_include_HEADERS += \
> + xorg/gtest/evemu/device.h \
> + xorg/gtest/evemu/recording.h
> +endif
> diff --git a/include/xorg/gtest/evemu/device.h b/include/xorg/gtest/evemu/device.h
> new file mode 100644
> index 0000000..0105da2
> --- /dev/null
> +++ b/include/xorg/gtest/evemu/device.h
> @@ -0,0 +1,85 @@
> +/*******************************************************************************
> + *
> + * X testing environment - Google Test environment feat. dummy x server
> + *
> + * Copyright (C) 2012 Canonical Ltd.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + *
> + ******************************************************************************/
> +
> +#ifndef XORG_GTEST_EVEMU_DEVICE_H_
> +#define XORG_GTEST_EVEMU_DEVICE_H_
> +
> +#include<memory>
> +
> +extern "C" {
> +
> +#include<evemu.h>
> +
> +} // extern "C"
> +
> +namespace xorg {
> +namespace testing {
> +namespace evemu {
> +
> +/**
> + * @class Device device.h xorg/gtest/evemu/device.h
> + *
> + * uTouch-Evemu input device for replaying events through the Linux uinput
> + * evdev subsystem.
> + *
> + * Use the Recording class to play back a specific recording.
> + */
> +
> +class Device {
> + public:
> + /**
> + * Create a new device context.
> + *
> + * @param [in] file Path to uTouch-Evemu device property file.
> + *
> + * @throws std::runtime_error if the device property file could not be found
> + * or the device could not be created.
> + */
> + explicit Device(const char* file);
> + ~Device();
> +
> + /**
> + * Retrieve the file descriptor for the device context.
> + *
> + * @returns The file descriptor.
> + */
> + int fd() const;
> +
> + private:
> + struct Private;
> + std::auto_ptr<Private> d_;
> +
> + /* Disable copy constructor& assignment operator */
> + Device(const Device&);
> + Device& operator=(const Device&);
> +};
> +
> +} // namespace evemu
> +} // namespace testing
> +} // namespace xorg
> +
> +#endif // XORG_GTEST_EVEMU_DEVICE_H_
> diff --git a/include/xorg/gtest/evemu/recording.h b/include/xorg/gtest/evemu/recording.h
> new file mode 100644
> index 0000000..ab4d283
> --- /dev/null
> +++ b/include/xorg/gtest/evemu/recording.h
> @@ -0,0 +1,89 @@
> +/*******************************************************************************
> + *
> + * X testing environment - Google Test environment feat. dummy x server
> + *
> + * Copyright (C) 2012 Canonical Ltd.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + *
> + ******************************************************************************/
> +
> +#ifndef XORG_GTEST_EVEMU_RECORDING_H_
> +#define XORG_GTEST_EVEMU_RECORDING_H_
> +
> +#include<stdio.h>
> +
> +#include<memory>
> +
> +extern "C" {
> +
> +#include<evemu.h>
> +
> +} // extern "C"
> +
> +#include "device.h"
> +
> +namespace xorg {
> +namespace testing {
> +namespace evemu {
> +
> +/**
> + * @class Recording recording.h xorg/gtest/evemu/recording.h
> + *
> + * uTouch-Evemu recording for replaying events through the Linux uinput evdev
> + * subsystem.
> + */
> +
> +class Recording {
> + public:
> + /**
> + * Create a new recording context.
> + *
> + * @param [in] file Path to uTouch-Evemu recording file.
> + *
> + * @throws std::runtime_error if the recording file could not be found.
> + */
> + Recording(const Device& device, const char* file);
> + ~Recording();
> +
> + /**
> + * Play the recording.
> + *
> + * Plays the recording from the beginning through the end. This call will
> + * block until the recording has finished.
> + *
> + * @throws std::runtime_error if playback failed for any reason.
> + */
> + void Play() const;
> +
> + private:
> + struct Private;
> + std::auto_ptr<Private> d_;
> +
> + /* Disable copy constructor& assignment operator */
> + Recording(const Recording&);
> + Recording& operator=(const Recording&);
> +};
> +
> +} // namespace evemu
> +} // namespace testing
> +} // namespace xorg
> +
> +#endif // XORG_GTEST_EVEMU_RECORDING_H_
> diff --git a/src/Makefile.am b/src/Makefile.am
> index acea1ff..72ce4ca 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -54,4 +54,12 @@ libxorg_gtest_main_la_LDFLAGS = \
> $(XSERVER_LIBS) \
> -Wl,--version-script=$(top_srcdir)/src/libxorg-gtest_main.ver
>
> +if HAVE_EVEMU
> +libxorg_gtest_la_SOURCES += \
> + device.cpp \
> + recording.cpp
> +
> +libxorg_gtest_la_LIBADD = $(EVEMU_LIBS)
> +endif
> +
> EXTRA_DIST = libxorg-gtest.ver libxorg-gtest_main.ver
> diff --git a/src/device.cpp b/src/device.cpp
> new file mode 100644
> index 0000000..601ca49
> --- /dev/null
> +++ b/src/device.cpp
> @@ -0,0 +1,84 @@
> +/*******************************************************************************
> + *
> + * X testing environment - Google Test environment feat. dummy x server
> + *
> + * Copyright (C) 2012 Canonical Ltd.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + *
> + ******************************************************************************/
> +
> +#include "xorg/gtest/evemu/device.h"
> +
> +#include<fcntl.h>
> +
> +#include<stdexcept>
> +
> +#include<gtest/gtest.h>
> +
> +struct xorg::testing::evemu::Device::Private {
> + Private() : fd(-1), device(NULL) {}
> +
> + int fd;
> + struct evemu_device* device;
> +};
> +
> +xorg::testing::evemu::Device::Device(const char* path) : d_(new Private) {
> + static const char UINPUT_NODE[] = "/dev/uinput";
> +
> + d_->device = evemu_new(NULL);
> + if (!d_->device)
> + throw std::runtime_error("Failed to create evemu record");
> +
> + FILE* fp = fopen(path, "r");
> + if (fp == NULL) {
> + evemu_delete(d_->device);
> + throw std::runtime_error("Failed to open device file");
> + }
> +
> + if (evemu_read(d_->device, fp)<= 0) {
> + fclose(fp);
> + evemu_delete(d_->device);
> + throw std::runtime_error("Failed to read device file");
> + }
> +
> + fclose(fp);
> +
> + d_->fd = open(UINPUT_NODE, O_WRONLY);
> + if (d_->fd< 0) {
> + evemu_delete(d_->device);
> + throw std::runtime_error("Failed to open uinput node");
> + }
> +
> + if (evemu_create(d_->device, d_->fd)< 0) {
> + close(d_->fd);
> + evemu_delete(d_->device);
> + throw std::runtime_error("Failed to create evemu device");
> + }
> +}
> +
> +int xorg::testing::evemu::Device::fd() const {
> + return d_->fd;
> +}
> +
> +xorg::testing::evemu::Device::~Device() {
> + close(d_->fd);
> + evemu_delete(d_->device);
> +}
> diff --git a/src/recording.cpp b/src/recording.cpp
> new file mode 100644
> index 0000000..52dbdf7
> --- /dev/null
> +++ b/src/recording.cpp
> @@ -0,0 +1,51 @@
> +/*****************************************************************************
> + *
> + * utouch-frame - Touch Frame Library
> + *
> + * Copyright (C) 2011 Canonical Ltd.
> + *
> + * This program is free software: you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation, either version 3 of the License, or (at your
> + * option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program. If not, see<http://www.gnu.org/licenses/>.
> + *
> + ****************************************************************************/
Oops, copy/paste error. Will fix up the license in a new revision.
-- Chase
More information about the xorg-devel
mailing list