1 : /*
2 : * Copyright 2010 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can
4 : * be found in the LICENSE file.
5 : */
6 : #ifndef NATIVE_CLIENT_GDB_RSP_SESSION_MOCK_H_
7 : #define NATIVE_CLIENT_GDB_RSP_SESSION_MOCK_H_ 1
8 :
9 : #include <string>
10 : #include <vector>
11 :
12 : #include "native_client/src/trusted/gdb_rsp/packet.h"
13 : #include "native_client/src/trusted/gdb_rsp/session.h"
14 : #include "native_client/src/trusted/port/platform.h"
15 : #include "native_client/src/trusted/port/transport.h"
16 :
17 : namespace gdb_rsp {
18 :
19 : class SessionMock : public Session {
20 : public:
21 : enum ActionType {
22 : SEND,
23 : RECV,
24 : TIMEOUT,
25 : DISCONNECT
26 : };
27 :
28 84 : struct Action {
29 : std::string str_;
30 : ActionType type_;
31 : };
32 :
33 4 : class TransportMock : public port::ITransport {
34 : public:
35 0 : virtual int32_t Read(void *ptr, int32_t len) {
36 : (void) ptr;
37 : (void) len;
38 0 : return -1;
39 : }
40 0 : virtual int32_t Write(const void *ptr, int32_t len) {
41 : (void) ptr;
42 : (void) len;
43 0 : return -1;
44 : }
45 0 : virtual bool ReadWaitWithTimeout(uint32_t ms) {
46 : (void) ms;
47 0 : return false;
48 : }
49 0 : virtual void Disconnect() { }
50 : };
51 :
52 : explicit SessionMock(bool target);
53 : ~SessionMock();
54 :
55 : bool SendPacketOnly(gdb_rsp::Packet *packet);
56 : bool GetPacket(gdb_rsp::Packet *packet);
57 : bool DataAvailable();
58 : ActionType PeekAction();
59 : Action *GetAction();
60 :
61 : void AddAction(ActionType act, const char *str);
62 : void AddTransaction(const char *snd, const char *rcv);
63 :
64 : private:
65 : std::vector<Action*> actions_;
66 : size_t cur_;
67 : bool target_;
68 : };
69 :
70 : SessionMock *GetGoldenSessionMock(bool target, bool debug);
71 : void AddMockInit(SessionMock *ses);
72 : void AddMockUpdate(SessionMock *ses, uint8_t sig);
73 :
74 :
75 :
76 : } // namespace gdb_rsp
77 :
78 : #endif // NATIVE_CLIENT_GDB_RSP_SESSION_MOCK_H_
|