Commit 0a550434 authored by Chase Douglas's avatar Chase Douglas
Browse files

Add xorg::testing::evemu::Device



Device uses utouch-evemu for input device recording playback through the
Linux kernel.
Signed-off-by: default avatarChase Douglas <chase.douglas@canonical.com>
Acked-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: default avatarStephen Webb <stephen.webb@canonical.com>
parent bf4a7db2
......@@ -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
......
......@@ -27,3 +27,7 @@ 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
endif
/*******************************************************************************
*
* 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>
#include <string>
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] path 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 std::string& path);
~Device();
/**
* Play a uTouch-Evemu recording through the device.
*
* Plays the recording from the beginning through the end. This call will
* block until the recording has finished.
*
* @param [in] path Path to uTouch-Evemu recording file.
*
* @throws std::runtime_error if playback failed for any reason.
*/
void Play(const std::string& path) 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_
......@@ -54,4 +54,10 @@ 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
libxorg_gtest_la_LIBADD = $(EVEMU_LIBS)
endif
EXTRA_DIST = libxorg-gtest.ver libxorg-gtest_main.ver
/*******************************************************************************
*
* 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 std::string& 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.c_str(), "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");
}
}
void xorg::testing::evemu::Device::Play(const std::string& path) const {
FILE* file = fopen(path.c_str(), "r");
if (!file)
throw std::runtime_error("Failed to open recording file");
if (evemu_play(file, d_->fd) != 0) {
fclose(file);
throw std::runtime_error("Failed to play evemu recording");
}
fclose(file);
}
xorg::testing::evemu::Device::~Device() {
close(d_->fd);
evemu_delete(d_->device);
}
XORG_GTEST_1.0 {
global:
extern "C++" {
xorg::testing::*;
xorg::testing::Environment::*;
xorg::testing::Process::*;
xorg::testing::Test::*;
"typeinfo for xorg::testing::Environment";
"typeinfo for xorg::testing::Test";
"typeinfo name for xorg::testing::Environment";
......@@ -13,3 +15,10 @@ XORG_GTEST_1.0 {
local:
*;
};
XORG_GTEST_1.1 {
global:
extern "C++" {
xorg::testing::evemu::*;
};
} XORG_GTEST_1.0;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment