~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to testsuite/geis1/gtest_instance.cpp

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Gtest test suite for GEIS v1 instances.
 
3
 *
 
4
 * Copyright 2012 Canonical Ltd.
 
5
 */
 
6
#include "geis_config.h"
 
7
 
 
8
#define _XOPEN_SOURCE 600
 
9
# include <stdlib.h>
 
10
#undef _XOPEN_SOURCE
 
11
#include "geis/geis.h"
 
12
#include "gtest_evemu_device.h"
 
13
#include <gtest/gtest.h>
 
14
#include <xorg/gtest/xorg-gtest.h>
 
15
 
 
16
 
 
17
namespace
 
18
{
 
19
 
 
20
const std::string TEST_DEVICE_PROP_FILE(TEST_ROOT_DIR "recordings/apple_magic_trackpad/device.prop");
 
21
 
 
22
 
 
23
/*
 
24
 * A special fixture that does not have any GEIS instances yet.
 
25
 */
 
26
class Geis1InstanceTests
 
27
: public xorg::testing::Test
 
28
{
 
29
public:
 
30
  Geis1InstanceTests()
 
31
  : evemu_device_(TEST_DEVICE_PROP_FILE), device_count_(0)
 
32
  { }
 
33
 
 
34
  void device_seen()
 
35
  { ++device_count_; }
 
36
 
 
37
  int device_seen_count() const
 
38
  { return device_count_; }
 
39
 
 
40
private:
 
41
  Testsuite::EvemuDevice evemu_device_;
 
42
  int                    device_count_;
 
43
};
 
44
 
 
45
 
 
46
/*
 
47
 * Regression test for lp:973539.
 
48
 *
 
49
 * The problem would only occur if an appropriate X server was
 
50
 * unavailable or did not support the required XI2.2 functionality.
 
51
 *
 
52
 */
 
53
TEST_F(Geis1InstanceTests, noX11Server)
 
54
{
 
55
  char* old_display = getenv("DISPLAY");
 
56
  ASSERT_TRUE(old_display != NULL);
 
57
  unsetenv("DISPLAY");
 
58
 
 
59
  GeisXcbWinInfo xcb_win_info = { NULL, NULL, 0 };
 
60
  GeisWinInfo win_info = { GEIS_XCB_FULL_WINDOW, &xcb_win_info };
 
61
  GeisInstance geis;
 
62
  ASSERT_NE(GEIS_STATUS_SUCCESS, geis_init(&win_info, &geis));
 
63
 
 
64
  setenv("DISPLAY", old_display, ~0);
 
65
}
 
66
 
 
67
static void
 
68
input_device_added(void              *context,
 
69
                   GeisInputDeviceId  device_id GEIS_UNUSED,
 
70
                   void              *attrs GEIS_UNUSED)
 
71
{
 
72
  Geis1InstanceTests* fixture = static_cast<Geis1InstanceTests*>(context);
 
73
  fixture->device_seen();
 
74
}
 
75
 
 
76
 
 
77
static void
 
78
null_device_function(void              *context GEIS_UNUSED,
 
79
                     GeisInputDeviceId  device_id GEIS_UNUSED,
 
80
                     void              *attrs GEIS_UNUSED)
 
81
{
 
82
}
 
83
 
 
84
static GeisInputFuncs input_funcs = {
 
85
  input_device_added,
 
86
  null_device_function,
 
87
  null_device_function
 
88
};
 
89
 
 
90
TEST_F(Geis1InstanceTests, reportDevices)
 
91
{
 
92
  GeisXcbWinInfo xcb_win_info = { NULL, NULL, 0 };
 
93
  GeisWinInfo win_info = { GEIS_XCB_FULL_WINDOW, &xcb_win_info };
 
94
  GeisInstance geis;
 
95
  ASSERT_EQ(GEIS_STATUS_SUCCESS,
 
96
            geis_init(&win_info, &geis));
 
97
  ASSERT_EQ(GEIS_STATUS_SUCCESS,
 
98
            geis_input_devices(geis, &input_funcs, this));
 
99
  EXPECT_GT(device_seen_count(), 0) << "no devices seen";
 
100
}
 
101
 
 
102
} // anonymous namespace