forked from vikshanker/sponge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsm_stream_reassembler_single.cc
145 lines (107 loc) · 3.83 KB
/
fsm_stream_reassembler_single.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
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
143
144
145
#include "byte_stream.hh"
#include "fsm_stream_reassembler_harness.hh"
#include "stream_reassembler.hh"
#include "util.hh"
#include <exception>
#include <iostream>
using namespace std;
int main() {
try {
{
ReassemblerTestHarness test{65000};
test.execute(BytesAssembled(0));
test.execute(BytesAvailable(""));
test.execute(NotAtEof{});
}
{
ReassemblerTestHarness test{65000};
test.execute(SubmitSegment{"a", 0});
test.execute(BytesAssembled(1));
test.execute(BytesAvailable("a"));
test.execute(NotAtEof{});
}
{
ReassemblerTestHarness test{65000};
test.execute(SubmitSegment{"a", 0}.with_eof(true));
test.execute(BytesAssembled(1));
test.execute(BytesAvailable("a"));
test.execute(AtEof{});
}
{
ReassemblerTestHarness test{65000};
test.execute(SubmitSegment{"", 0}.with_eof(true));
test.execute(BytesAssembled(0));
test.execute(BytesAvailable(""));
test.execute(AtEof{});
}
{
ReassemblerTestHarness test{65000};
test.execute(SubmitSegment{"b", 0}.with_eof(true));
test.execute(BytesAssembled(1));
test.execute(BytesAvailable("b"));
test.execute(AtEof{});
}
{
ReassemblerTestHarness test{65000};
test.execute(SubmitSegment{"", 0});
test.execute(BytesAssembled(0));
test.execute(BytesAvailable(""));
test.execute(NotAtEof{});
}
{
ReassemblerTestHarness test{8};
test.execute(SubmitSegment{"abcdefgh", 0});
test.execute(BytesAssembled(8));
test.execute(BytesAvailable{"abcdefgh"});
test.execute(NotAtEof{});
}
{
ReassemblerTestHarness test{8};
test.execute(SubmitSegment{"abcdefgh", 0}.with_eof(true));
test.execute(BytesAssembled(8));
test.execute(BytesAvailable{"abcdefgh"});
test.execute(AtEof{});
}
{
ReassemblerTestHarness test{8};
test.execute(SubmitSegment{"abc", 0});
test.execute(BytesAssembled(3));
test.execute(SubmitSegment{"bcdefgh", 1}.with_eof(true));
test.execute(BytesAssembled(8));
test.execute(BytesAvailable{"abcdefgh"});
test.execute(AtEof{});
}
{
ReassemblerTestHarness test{8};
test.execute(SubmitSegment{"abc", 0});
test.execute(BytesAssembled(3));
test.execute(NotAtEof{});
test.execute(SubmitSegment{"ghX", 6}.with_eof(true));
test.execute(BytesAssembled(3));
test.execute(NotAtEof{});
test.execute(SubmitSegment{"cdefg", 2});
test.execute(BytesAssembled(8));
test.execute(BytesAvailable{"abcdefgh"});
test.execute(NotAtEof{});
}
// credit for test: Bill Lin (2020)
{
ReassemblerTestHarness test{8};
test.execute(SubmitSegment{"abc", 0});
test.execute(BytesAssembled(3));
test.execute(NotAtEof{});
// Stream re-assembler should ignore empty segments
test.execute(SubmitSegment{"", 6});
test.execute(BytesAssembled(3));
test.execute(NotAtEof{});
test.execute(SubmitSegment{"de", 3}.with_eof(true));
test.execute(BytesAssembled(5));
test.execute(BytesAvailable("abcde"));
test.execute(AtEof{});
}
} catch (const exception &e) {
cerr << "Exception: " << e.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}