forked from huangrt01/TCP-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbyte_stream_capacity.cc
77 lines (62 loc) · 2.31 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
#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"});
}
} catch (const exception &e) {
cerr << "Exception: " << e.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}