TFCweb  1.0.4 $Rev: 483 $
TFC Primavera 2012: Nucli d'un servidor web
TestPeticioHTTP.cc
Veure la documentació d'aquest fitxer.
1 
11 /*
12  * Copyright (c) 2012 Toni Corvera
13  *
14  * This file is part of TFCWeb.
15  *
16  * TFCWeb is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * TFCWeb is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with TFCWeb. If not, see <http://www.gnu.org/licenses/>.
28  */
29 
30 #include <iostream>
31 #include <sstream>
32 #include <string>
33 
34 #include <CapsaleraHTTP.h>
35 #include <Excepcions.h>
36 #include <PeticioHTTP.h>
37 #include <Uri.h>
38 
39 #include "comu.h"
40 
41 using namespace std;
42 using namespace tfc;
43 
44 namespace tfc { namespace Fixtures {
45 
46 struct FxtPeticio {
48  : get1(GET, Uri("/"), HTTP_1_1),
49  get2(GET, Uri("/"), HTTP_1_1),
50  post(POST,Uri("/"), HTTP_1_0),
51  http_1_1("HTTP/1.1")
52  {
53  BOOST_TEST_MESSAGE("Fixture setup");
54  }
56  {
57  BOOST_TEST_MESSAGE("Fixture teardown");
58  }
59  PeticioHTTP get1, get2, post;
60  string http_1_1;
61 };
62 
63 } // ns Fixtures
64 } // ns tfc
65 
66 //BOOST_AUTO_TEST_SUITE( PeticioHTTP_TestSuite )
67 BOOST_FIXTURE_TEST_SUITE( PeticioHTTP_TestSuite, Fixtures::FxtPeticio )
68 
69 BOOST_AUTO_TEST_CASE( igualtat )
70 //BOOST_FIXTURE_TEST_CASE( igualtat, PeticioFixture )
71 {
72  BOOST_CHECK( get1 == get2 );
73 }
74 
75 BOOST_AUTO_TEST_CASE( copia )
76 {
77  PeticioHTTP c(post);
78  BOOST_CHECK_EQUAL( c, post );
79 }
80 
81 BOOST_AUTO_TEST_CASE( getters )
82 {
83  BOOST_CHECK_EQUAL(get1.tipus(), GET);
84  BOOST_CHECK_EQUAL(get1.versio(), HTTP_1_1);
85  BOOST_CHECK_EQUAL(get1.ruta(), Uri("/"));
86 }
87 
88 BOOST_AUTO_TEST_CASE( MostraImpressio )
89 {
90  cerr << "Mostra d'impressió de peticions HTTP:" << endl;
91  PeticioHTTP get3(get1);
92  get3.afegeix_capsalera("Host", "www.example.com");
93  cerr << get3 << endl;
94 }
95 
97 {
98  BOOST_CHECK_EQUAL( NomTipusPeticioHTTP::nom(GET), "GET" );
99  BOOST_CHECK_EQUAL( NomTipusPeticioHTTP::nom(POST), "POST" );
100  BOOST_CHECK_EQUAL( NomTipusPeticioHTTP::nom(HEAD), "HEAD" );
101  BOOST_CHECK_EQUAL( NomTipusPeticioHTTP::nom(OPTIONS), "OPTIONS" );
102  BOOST_CHECK_EQUAL( NomTipusPeticioHTTP::nom(TRACE), "TRACE" );
103  BOOST_CHECK_EQUAL( NomTipusPeticioHTTP::nom(PUT), "PUT" );
104  BOOST_CHECK_EQUAL( NomTipusPeticioHTTP::nom(METODE_DELETE), "DELETE" );
105  BOOST_CHECK_EQUAL( NomTipusPeticioHTTP::nom(CONNECT), "CONNECT" );
106 }
107 
108 #if 0
109 BOOST_AUTO_TEST_CASE( setters )
110 {
111 }
112 #endif
113 
114 BOOST_AUTO_TEST_SUITE_END()
115 
116 // vim:set ts=4 et ai: //