Menu

[r2336]: / framework / trunk / tests / proto_test.cpp  Maximize  Restore  History

Download this file

93 lines (85 with data), 2.8 kB

 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
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#include <cppcms/service.h>
#include <cppcms/application.h>
#include <cppcms/applications_pool.h>
#include <cppcms/http_request.h>
#include <cppcms/http_response.h>
#include <cppcms/http_context.h>
#include <cppcms/json.h>
#include <iostream>
#include "client.h"
#include "test.h"
bool is_async;
bool is_nonblocking;
class unit_test : public cppcms::application {
public:
unit_test(cppcms::service &s) : cppcms::application(s)
{
}
virtual void main(std::string /*unused*/)
{
response().set_plain_text_header();
response().setbuf(64);
TEST(is_async == is_asynchronous());
if(!is_asynchronous()) {
TEST(response().io_mode() == cppcms::http::response::normal);
response().io_mode(cppcms::http::response::nogzip);
}
else {
TEST(response().io_mode() == cppcms::http::response::asynchronous);
}
if(is_nonblocking) {
response().full_asynchronous_buffering(false);
}
std::map<std::string,std::string> env=request().getenv();
std::ostream &out = response().out();
for(std::map<std::string,std::string>::const_iterator p=env.begin();p!=env.end();++p) {
out << p->first <<':'<<p->second << '\n';
}
out << '\n';
typedef cppcms::http::request::form_type form_type;
form_type const &form=request().post();
for(form_type::const_iterator p=form.begin();p!=form.end();++p) {
out << p->first <<'='<<p->second << '\n';
}
}
};
int main(int argc,char **argv)
{
try {
cppcms::service srv(argc,argv);
if(srv.settings().get("test.async","sync")=="sync") {
std::cout << "Synchronous testing" << std::endl;
srv.applications_pool().mount( cppcms::create_pool<unit_test>());
}
else {
if(srv.settings().get<std::string>("test.async")=="async") {
is_async = true;
std::cout << "Asynchronous testing" << std::endl;
}
else if(srv.settings().get<std::string>("test.async")=="nonblocking") {
is_async = true;
is_nonblocking = true;
std::cout << "Non blocking testing" << std::endl;
}
else {
std::cerr << "Invalid configuration value of test.async" << std::endl;
return 1;
}
srv.applications_pool().mount( cppcms::create_pool<unit_test>(),cppcms::app::asynchronous);
}
srv.after_fork(submitter(srv));
srv.run();
}
catch(std::exception const &e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
return run_ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
MongoDB Logo MongoDB