1 // -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi:tw=80:et:ts=2:sts=2
3 //
4 // -----------------------------------------------------------------------
5 //
6 // This file is part of RLVM, a RealLive virtual machine clone.
7 //
8 // -----------------------------------------------------------------------
9 //
10 // Copyright (C) 2008 Elliot Glaysher
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 //
26 // -----------------------------------------------------------------------
27 
28 #ifndef TEST_TEST_SYSTEM_TEST_EVENT_SYSTEM_H_
29 #define TEST_TEST_SYSTEM_TEST_EVENT_SYSTEM_H_
30 
31 #include "systems/base/event_system.h"
32 
33 #include <memory>
34 
35 // Provides behaviour for the TestEventSystem.
36 class EventSystemMockHandler {
37  public:
EventSystemMockHandler()38   EventSystemMockHandler() : counter_(0) {}
~EventSystemMockHandler()39   virtual ~EventSystemMockHandler() {}
40 
shiftPressed()41   virtual bool shiftPressed() const { return false; }
ctrlPressed()42   virtual bool ctrlPressed() const { return false; }
GetTicks()43   virtual unsigned int GetTicks() const { return counter_++; }
44 
45  private:
46   mutable int counter_;
47 };
48 
49 // Mock enabled event system. Returned values are controlled by
50 // EventSystemMockHandler.
51 class TestEventSystem : public EventSystem {
52  public:
53   explicit TestEventSystem(Gameexe& gexe);
54   void SetMockHandler(const std::shared_ptr<EventSystemMockHandler>& handler);
55 
56   // Implementation of EventSystem:
57   virtual void ExecuteEventSystem(RLMachine& machine) override;
58   virtual unsigned int GetTicks() const override;
59   virtual void Wait(unsigned int milliseconds) const override;
60   virtual bool ShiftPressed() const override;
61   virtual bool CtrlPressed() const override;
62   virtual Point GetCursorPos() override;
63   virtual void GetCursorPos(Point& position,
64                             int& button1,
65                             int& button2) override;
66   virtual void FlushMouseClicks() override;
67   virtual unsigned int TimeOfLastMouseMove() override;
68   virtual void InjectMouseMovement(RLMachine& machine,
69                                    const Point& loc) override;
70   virtual void InjectMouseDown(RLMachine& machine) override;
71   virtual void InjectMouseUp(RLMachine& machine) override;
72 
73  private:
74   // Defines test specific behaviour for the TestEventSystem
75   std::shared_ptr<EventSystemMockHandler> event_system_mock_;
76 };
77 
78 #endif  // TEST_TEST_SYSTEM_TEST_EVENT_SYSTEM_H_
79