Skip to content

Commit 37feb35

Browse files
committed
initial Request tests
1 parent a7fee40 commit 37feb35

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package http_parser.lolevel;
2+
3+
import java.nio.*;
4+
import java.util.*;
5+
6+
import static http_parser.lolevel.Util.*;
7+
import http_parser.*;
8+
9+
import primitive.collection.ByteList;
10+
11+
public class Requests {
12+
13+
static void test_simple(String req, boolean should_pass) {
14+
HTTPParser parser = new HTTPParser(ParserType.HTTP_REQUEST);
15+
ByteBuffer buf = buffer(req);
16+
boolean passed = false;
17+
int read = 0;
18+
try {
19+
parser.execute(Util.SETTINGS_NULL, buf);
20+
passed = (read == req.length());
21+
read = parser.execute(Util.SETTINGS_NULL, Util.empty());
22+
passed &= (0 == read);
23+
} catch (Throwable t) {
24+
passed = false;
25+
}
26+
check(passed == should_pass);
27+
}
28+
static void simple_tests() {
29+
test_simple("hello world", false);
30+
test_simple("GET / HTP/1.1\r\n\r\n", false);
31+
32+
test_simple("ASDF / HTTP/1.1\r\n\r\n", false);
33+
test_simple("PROPPATCHA / HTTP/1.1\r\n\r\n", false);
34+
test_simple("GETA / HTTP/1.1\r\n\r\n", false);
35+
}
36+
37+
public static void test () {
38+
39+
simple_tests();
40+
41+
List<Message> all = TestLoaderNG.load("tests.dumped");
42+
List<Message> requests = new LinkedList<Message>();
43+
for (Message m : all) {
44+
if (ParserType.HTTP_REQUEST == m.type) {
45+
requests.add(m);
46+
}
47+
}
48+
for (Message m : requests) {
49+
test_message(m);
50+
}
51+
52+
for (int i = 0; i!= requests.size(); ++i) {
53+
if (!requests.get(i).should_keep_alive) continue;
54+
for (int j = 0; j!=requests.size(); ++j) {
55+
if (!requests.get(j).should_keep_alive) continue;
56+
for (int k = 0; k!= requests.size(); ++k) {
57+
test_multiple3(requests.get(i), requests.get(j), requests.get(k));
58+
}
59+
}
60+
}
61+
62+
// postpone test_scan
63+
64+
}
65+
66+
67+
68+
69+
}

src/test/http_parser/lolevel/Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static void main (String [] args) {
77
TestHeaderOverflowError.test();
88
TestNoOverflowLongBody.test();
99
Responses.test();
10+
Requests.test();
1011
}
1112

1213
}

0 commit comments

Comments
 (0)