Menu

[r2097]: / framework / trunk / tests / session_interface_test.cpp  Maximize  Restore  History

Download this file

125 lines (118 with data), 3.2 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
 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
///////////////////////////////////////////////////////////////////////////////
//
// 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/session_interface.h>
#include <cppcms/json.h>
#include <iostream>
#include "client.h"
#include "test.h"
class unit_test : public cppcms::application {
public:
unit_test(cppcms::service &s) : cppcms::application(s)
{
}
virtual void main(std::string u)
{
if(u=="/new") {
session().set("x",1);
}
else if(u=="/update") {
session().set("x",session().get<int>("x") + 1);
}
else if(u=="/clear") {
session().clear();
response().out() << "clear";
}
else if(u=="/new_short") {
session().set("x",1);
session().age(1);
}
else if(u=="/is_expired") {
if(session().is_set("x"))
response().out() << "not expired";
else
response().out() << "expired";
}
else if(u=="/expose") {
session().expose("x");
}
else if(u=="/unexpose") {
session().hide("x");
}
else if(u=="/fixed") {
session().expiration(cppcms::session_interface::fixed);
}
else if(u=="/renew") {
session().expiration(cppcms::session_interface::renew);
}
else if(u=="/browser") {
session().expiration(cppcms::session_interface::browser);
}
else if(u=="/reset") {
session().reset_session();
}
else if(u=="/on_server") {
session().on_server(true);
}
else if(u=="/not_on_server") {
session().on_server(false);
}
else if(u=="/huge") {
std::string tmp="x";
for(int i=0;i<10;i++)
tmp=tmp+tmp;
session().set("y",tmp);
}
else if(u=="/small") {
session().erase("y");
session().set("x","1");
}
else if(u=="/info") {
bool is_set_x = session().is_set("x");
bool is_exposed_x = session().is_exposed("x");
int age = session().age();
int expiration = session().expiration();
bool on_server = session().on_server();
response().out()
<< "is_set_x=" << is_set_x << "\n"
<< "is_exposed_x=" << is_exposed_x << "\n"
<< "age="<<age<<"\n"
<< "expiration=" << expiration << "\n"
<< "on_server=" << on_server ;
}
else if(u=="/api") {
try {
// Fix Me Later
response().out() << "ok";
}
catch(std::exception const &e) {
std::cerr << "Failed " << e.what() << std::endl;
response().out() << "not ok";
}
}
}
};
int main(int argc,char **argv)
{
try {
cppcms::service srv(argc,argv);
srv.applications_pool().mount( cppcms::applications_factory<unit_test>());
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