-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbyte_stream_test_harness.hh
142 lines (110 loc) · 3.86 KB
/
byte_stream_test_harness.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef SPONGE_BYTE_STREAM_HARNESS_HH
#define SPONGE_BYTE_STREAM_HARNESS_HH
#include "byte_stream.hh"
#include "util.hh"
#include <exception>
#include <initializer_list>
#include <iostream>
#include <memory>
#include <optional>
#include <string>
struct ByteStreamTestStep {
virtual operator std::string() const;
virtual void execute(ByteStream &) const;
virtual ~ByteStreamTestStep();
};
class ByteStreamExpectationViolation : public std::runtime_error {
public:
ByteStreamExpectationViolation(const std::string &msg);
template <typename T>
static ByteStreamExpectationViolation property(const std::string &property_name,
const T &expected,
const T &actual);
};
struct ByteStreamExpectation : public ByteStreamTestStep {
operator std::string() const override;
virtual std::string description() const;
virtual void execute(ByteStream &) const override;
virtual ~ByteStreamExpectation() override;
};
struct ByteStreamAction : public ByteStreamTestStep {
operator std::string() const override;
virtual std::string description() const;
virtual void execute(ByteStream &) const override;
virtual ~ByteStreamAction() override;
};
struct EndInput : public ByteStreamAction {
std::string description() const override;
void execute(ByteStream &) const override;
};
struct Write : public ByteStreamAction {
std::string _data;
std::optional<size_t> _bytes_written{};
Write(const std::string &data);
Write &with_bytes_written(const size_t bytes_written);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct Pop : public ByteStreamAction {
size_t _len;
Pop(const size_t len);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct InputEnded : public ByteStreamExpectation {
bool _input_ended;
InputEnded(const bool input_ended);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct BufferEmpty : public ByteStreamExpectation {
bool _buffer_empty;
BufferEmpty(const bool buffer_empty);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct Eof : public ByteStreamExpectation {
bool _eof;
Eof(const bool eof);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct BufferSize : public ByteStreamExpectation {
size_t _buffer_size;
BufferSize(const size_t buffer_size);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct BytesWritten : public ByteStreamExpectation {
size_t _bytes_written;
BytesWritten(const size_t bytes_written);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct BytesRead : public ByteStreamExpectation {
size_t _bytes_read;
BytesRead(const size_t bytes_read);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct RemainingCapacity : public ByteStreamExpectation {
size_t _remaining_capacity;
RemainingCapacity(const size_t remaining_capacity);
std::string description() const override;
void execute(ByteStream &) const override;
};
struct Peek : public ByteStreamExpectation {
std::string _output;
Peek(const std::string &output);
std::string description() const override;
void execute(ByteStream &) const override;
};
class ByteStreamTestHarness {
std::string _test_name;
ByteStream _byte_stream;
std::vector<std::string> _steps_executed{};
public:
ByteStreamTestHarness(const std::string &test_name, const size_t capacity);
void execute(const ByteStreamTestStep &step);
};
#endif // SPONGE_BYTE_STREAM_HARNESS_HH