@@ -19,7 +19,60 @@ void UnitTestParseHttpRequest::init() {
1919
2020bool UnitTestParseHttpRequest::run () {
2121 bool bTestSuccess = true ;
22- // compareB(bTestSuccess, "Not implemented", true, false);
22+ struct LPartsOfRequest {
23+ LPartsOfRequest (std::string sPart , bool enough) {
24+ this ->sPart = sPart ;
25+ this ->enough = enough;
26+ }
27+ std::string sPart ;
28+ bool enough;
29+ };
30+
31+ struct LTest {
32+ LTest (
33+ int sockFd,
34+ std::string address,
35+ std::vector<LPartsOfRequest> parts
36+ ) {
37+ this ->sockFd = sockFd;
38+ this ->address = address;
39+ this ->parts = parts;
40+ }
41+ int sockFd;
42+ std::string address;
43+ std::vector<LPartsOfRequest> parts;
44+ };
45+
46+ std::vector<LTest> tests;
47+ tests.push_back (LTest (0 , " some-address" , {
48+ LPartsOfRequest (" GET /pub/WWW/TheProject.html HTTP/1.1\n " , false ),
49+ LPartsOfRequest (" Host: www.w3.org\n " , false ),
50+ LPartsOfRequest (" Content-Length: 0\n " , false ),
51+ LPartsOfRequest (" \n " , true )
52+ }));
53+
54+ tests.push_back (LTest (1 , " some-address2" , {
55+ LPartsOfRequest (" GET /pub/WWW/TheProject.html HTTP/1.1\n " , false ),
56+ LPartsOfRequest (" Host: www.w3.org\n " , false ),
57+ LPartsOfRequest (" Content-Length: 1\n " , false ),
58+ LPartsOfRequest (" \n " , false ),
59+ LPartsOfRequest (" 1" , true )
60+ }));
61+
62+ for (int i = 0 ; i < tests.size (); i++) {
63+ LTest test = tests[i];
64+ WSJCppLightWebHttpRequest request (test.sockFd , test.address );
65+ std::string sNTest = " test" + std::to_string (i) + " #" ;
66+
67+ compareS (bTestSuccess, sNTest + " request address" , request.getAddress (), test.address );
68+ compareN (bTestSuccess, sNTest + " request sockfd" , request.getSockFd (), test.sockFd );
69+
70+ for (int n = 0 ; n < test.parts .size (); n++) {
71+ std::string sNTest2 = sNTest + " append part" + std::to_string (n) + " #" ;
72+ request.appendRecieveRequest (test.parts [n].sPart );
73+ compareB (bTestSuccess, sNTest2 , request.isEnoughAppendReceived (), test.parts [n].enough );
74+ }
75+ }
2376 return bTestSuccess;
2477}
2578
0 commit comments