~chasedouglas/frame/ubuntu-upstream-xi

« back to all changes in this revision

Viewing changes to test/events.cpp

  • Committer: Chase Douglas
  • Date: 2011-12-09 01:36:45 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: chase.douglas@ubuntu.com-20111209013645-n24l4myiumblzsfu
* New upstream release.
  - Version 2 adds a new API built on top of XInput multitouch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *
 
3
 * utouch-frame - Touch Frame Library
 
4
 *
 
5
 * Copyright (C) 2011 Canonical Ltd.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by the
 
9
 * Free Software Foundation, either version 3 of the License, or (at your
 
10
 * option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License along
 
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 ****************************************************************************/
 
21
 
 
22
#include "events.h"
 
23
 
 
24
#include <stdexcept>
 
25
 
 
26
namespace utouch {
 
27
namespace frame {
 
28
namespace testing {
 
29
 
 
30
const Value NewValue(UFTouchState state) {
 
31
  Value value;
 
32
  value.state = state;
 
33
  return value;
 
34
}
 
35
 
 
36
const Value NewValue(float floating) {
 
37
  Value value;
 
38
  value.floating = floating;
 
39
  return value;
 
40
}
 
41
 
 
42
const Value NewValue(int boolean) {
 
43
  Value value;
 
44
  value.boolean = boolean;
 
45
  return value;
 
46
}
 
47
 
 
48
bool IsEqual(const utouch::frame::testing::Touch& a,
 
49
             const utouch::frame::testing::Touch& b) {
 
50
  /* We rely on the fact that values are stored in maps, so if the values are
 
51
   * equal they will also be stored in the same order. */
 
52
  for (auto property_a = a.first.cbegin(), property_b = b.first.cbegin();
 
53
       property_a != a.first.cend() && property_b != b.first.cend();
 
54
       ++property_a, ++property_b) {
 
55
    if (property_a->first != property_b->first)
 
56
      return false;
 
57
 
 
58
    switch (property_a->first) {
 
59
      case UFTouchPropertyState:
 
60
        if (property_a->second.state != property_b->second.state)
 
61
          return false;
 
62
        break;
 
63
      case UFTouchPropertyWindowX:
 
64
      case UFTouchPropertyWindowY:
 
65
        if (property_a->second.floating != property_b->second.floating)
 
66
          return false;
 
67
        break;
 
68
      case UFTouchPropertyOwned:
 
69
      case UFTouchPropertyPendingEnd:
 
70
        if ((property_a->second.boolean && !property_b->second.boolean) ||
 
71
            (!property_a->second.boolean && property_b->second.boolean))
 
72
          return false;
 
73
        break;
 
74
      default:
 
75
        throw std::runtime_error("Unknown property to check for equality");
 
76
    }
 
77
  }
 
78
 
 
79
  for (auto value_a = a.second.cbegin(), value_b = b.second.cbegin();
 
80
       value_a != a.second.cend() && value_b != b.second.cend();
 
81
       ++value_a, ++value_b)
 
82
    if (value_a->first != value_b->first || value_a->second != value_b->second)
 
83
      return false;
 
84
 
 
85
  return true;
 
86
}
 
87
 
 
88
} // namespace testing
 
89
} // namespace frame
 
90
} // namespace utouch