forked from vikshanker/sponge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
byte_stream_capacity.cc
113 lines (92 loc) · 3.6 KB
/
byte_stream_capacity.cc
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
#include "byte_stream.hh"
#include "byte_stream_test_harness.hh"
#include <exception>
#include <iostream>
using namespace std;
int main() {
try {
{
ByteStreamTestHarness test{"overwrite", 2};
test.execute(Write{"cat"}.with_bytes_written(2));
test.execute(InputEnded{false});
test.execute(BufferEmpty{false});
test.execute(Eof{false});
test.execute(BytesRead{0});
test.execute(BytesWritten{2});
test.execute(RemainingCapacity{0});
test.execute(BufferSize{2});
test.execute(Peek{"ca"});
test.execute(Write{"t"}.with_bytes_written(0));
test.execute(InputEnded{false});
test.execute(BufferEmpty{false});
test.execute(Eof{false});
test.execute(BytesRead{0});
test.execute(BytesWritten{2});
test.execute(RemainingCapacity{0});
test.execute(BufferSize{2});
test.execute(Peek{"ca"});
}
{
ByteStreamTestHarness test{"overwrite-clear-overwrite", 2};
test.execute(Write{"cat"}.with_bytes_written(2));
test.execute(Pop{2});
test.execute(Write{"tac"}.with_bytes_written(2));
test.execute(InputEnded{false});
test.execute(BufferEmpty{false});
test.execute(Eof{false});
test.execute(BytesRead{2});
test.execute(BytesWritten{4});
test.execute(RemainingCapacity{0});
test.execute(BufferSize{2});
test.execute(Peek{"ta"});
}
{
ByteStreamTestHarness test{"overwrite-pop-overwrite", 2};
test.execute(Write{"cat"}.with_bytes_written(2));
test.execute(Pop{1});
test.execute(Write{"tac"}.with_bytes_written(1));
test.execute(InputEnded{false});
test.execute(BufferEmpty{false});
test.execute(Eof{false});
test.execute(BytesRead{1});
test.execute(BytesWritten{3});
test.execute(RemainingCapacity{0});
test.execute(BufferSize{2});
test.execute(Peek{"at"});
}
{
ByteStreamTestHarness test{"long-stream", 3};
test.execute(Write{"abcdef"}.with_bytes_written(3));
test.execute(Peek{"abc"});
test.execute(Pop{1});
for (unsigned int i = 0; i < 99997; i ) {
test.execute(RemainingCapacity{1});
test.execute(BufferSize{2});
test.execute(Write{"abc"}.with_bytes_written(1));
test.execute(RemainingCapacity{0});
test.execute(Peek{"bca"});
test.execute(Pop{1});
test.execute(RemainingCapacity{1});
test.execute(BufferSize{2});
test.execute(Write{"bca"}.with_bytes_written(1));
test.execute(RemainingCapacity{0});
test.execute(Peek{"cab"});
test.execute(Pop{1});
test.execute(RemainingCapacity{1});
test.execute(BufferSize{2});
test.execute(Write{"cab"}.with_bytes_written(1));
test.execute(RemainingCapacity{0});
test.execute(Peek{"abc"});
test.execute(Pop{1});
}
test.execute(EndInput{});
test.execute(Peek{"bc"});
test.execute(Pop{2});
test.execute(Eof{true});
}
} catch (const exception &e) {
cerr << "Exception: " << e.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}