-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathsession_unit_suite.cpp
More file actions
141 lines (114 loc) · 3.59 KB
/
session_unit_suite.cpp
File metadata and controls
141 lines (114 loc) · 3.59 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//System Includes
#include <set>
#include <map>
#include <memory>
#include <string>
#include <stdexcept>
//Project Includes
#include <corvusoft/restbed/session.hpp>
//External Includes
#include <catch2/catch_all.hpp>
#include <catch2/catch_session.hpp>
//System Namespaces
using std::set;
using std::string;
using std::bad_cast;
using std::multimap;
using std::shared_ptr;
using std::make_shared;
using std::out_of_range;
using std::invalid_argument;
//Project Namespaces
using restbed::Session;
//External Namespaces
TEST_CASE( "validate default instance values", "[session]" )
{
const Session session;
REQUIRE( session.is_open( ) == false );
REQUIRE( session.is_closed( ) == true );
REQUIRE( session.get_origin( ) == "" );
REQUIRE( session.get_destination( ) == "" );
REQUIRE( session.get_headers( ).empty( ) );
}
TEST_CASE( "confirm empty session id throws no exceptions", "[session]" )
{
REQUIRE_NOTHROW( Session( ) );
}
TEST_CASE( "confirm default destructor throws no exceptions", "[session]" )
{
auto session = new Session( );
REQUIRE_NOTHROW( delete session );
}
TEST_CASE( "validate setters modify default values", "[session]" )
{
Session session;
session.set_header( "Connection", "close" );
multimap< string, string > expectation = { { "Connection", "close" } };
REQUIRE( session.get_headers( ) == expectation );
expectation =
{
{ "Content-Type", "application/yaml" },
{ "Content-Encoding", "" }
};
session.set_headers( expectation );
REQUIRE( session.get_headers( ) == expectation );
}
TEST_CASE( "invoke close on uninitialised instance", "[session]" )
{
auto session = make_shared< Session >( );
REQUIRE( session->is_closed( ) == true );
REQUIRE_NOTHROW( session->close( ) );
REQUIRE( session->is_closed( ) == true );
}
TEST_CASE( "invoke yield on uninitialised instance", "[session]" )
{
auto session = make_shared< Session >( );
REQUIRE( session->is_closed( ) == true );
REQUIRE_NOTHROW( session->yield( "test data", [ ]( const shared_ptr< Session > )
{
return;
} ) );
REQUIRE_NOTHROW( session->yield( 200, "test data", [ ]( const shared_ptr< Session > )
{
return;
} ) );
REQUIRE_NOTHROW( session->yield( 200, "test data", { { "Content-Type", "text" } }, [ ]( const shared_ptr< Session > )
{
return;
} ) );
REQUIRE_NOTHROW( session->yield( 200, { { "Content-Type", "text" } }, [ ]( const shared_ptr< Session > )
{
return;
} ) );
}
TEST_CASE( "validate set_header overrides previous value", "[request]" )
{
Session session;
session.set_header( "Content-Type", "application/json" );
session.set_header( "Content-Type", "application/xml" );
const auto headers = session.get_headers( );
REQUIRE( headers.size( ) == 1 );
const auto expectation = multimap< string, string >
{
{ "Content-Type", "application/xml" }
};
REQUIRE( headers == expectation );
}
TEST_CASE( "validate add_header does not override a previous value", "[request]" )
{
Session session;
session.add_header( "Content-Type", "application/json" );
session.add_header( "Content-Type", "application/xml" );
const auto headers = session.get_headers( );
REQUIRE( headers.size( ) == 2 );
const auto expectation = multimap< string, string >
{
{ "Content-Type", "application/json" },
{ "Content-Type", "application/xml" }
};
REQUIRE( headers == expectation );
}
int main(int argc, char* argv[])
{
return Catch::Session().run(argc, argv);
}