Skip to content

Commit b7879fa

Browse files
author
Sebastiano Merlino
committed
Added test dir.
1 parent 88416b8 commit b7879fa

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

‎test/Test.cpp‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "Test.hpp"
2+
#include <string>
3+
#include <vector>
4+
#include <unistd.h>
5+
#include <iostream>
6+
#include <stdio.h>
7+
using namespace std;
8+
9+
Test::Test() : HttpResource()
10+
{
11+
}
12+
13+
Test2::Test2() : HttpResource()
14+
{
15+
}
16+
17+
HttpResponse Test::render_GET(const HttpRequest& r)
18+
{
19+
cout << r.getVersion() << endl;
20+
cout << r.getRequestor() << endl;
21+
cout << r.getRequestorPort() << endl;
22+
cout << "PROVA: " << r.getArg("prova") << endl;
23+
cout << "ALTRO: " << r.getArg("altro") << endl;
24+
string pp = r.getArg("prova");
25+
return HttpResponse(pp, 200);
26+
}
27+
28+
HttpResponse Test::render_POST(const HttpRequest& r)
29+
{
30+
cout << r.getContent() << endl;
31+
cout << "prova: " << r.getArg("prova") << endl;
32+
33+
string pp = r.getArg("prova");
34+
cout << "DOPO" << endl;
35+
36+
return HttpResponse(pp,200);
37+
}
38+
39+
HttpResponse Test2::render_GET(const HttpRequest& r)
40+
{
41+
cout << "D2" << endl;
42+
return HttpResponse("{\" var1 \" : \" "+r.getArg("var1")+" \", \" var2 \" : \" "+r.getArg("var2")+" \", \" var3 \" : \" "+r.getArg("var3")+" \"}", 200);
43+
}
44+
45+
HttpResponse Test::render_PUT(const HttpRequest& r)
46+
{
47+
return HttpResponse(r.getContent(), 200);
48+
}
49+
50+
int main()
51+
{
52+
Webserver* ws = new Webserver(9898, 5, 1);
53+
Test dt = Test();
54+
Test2 dt2 = Test2();
55+
ws->registerResource(string("base/{var1}/{var2}/drop_test/{var3}/tail"), &dt2, true);
56+
ws->registerResource(string("other"), &dt, true);
57+
ws->start(true);
58+
return 0;
59+
}

‎test/Test.hpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef _TEST_HPP_
2+
#define _TEST_HPP_
3+
#include "Webserver.hpp"
4+
5+
class Test : virtual public HttpResource {
6+
public:
7+
Test();
8+
virtual HttpResponse render_GET(const HttpRequest&);
9+
virtual HttpResponse render_PUT(const HttpRequest&);
10+
virtual HttpResponse render_POST(const HttpRequest&);
11+
};
12+
13+
class Test2 : virtual public HttpResource {
14+
public:
15+
Test2();
16+
virtual HttpResponse render_GET(const HttpRequest&);
17+
};
18+
19+
#endif

0 commit comments

Comments
 (0)