Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-04-19 09:34:48


Author: drrngrvy
Date: 2008-04-19 09:34:48 EDT (Sat, 19 Apr 2008)
New Revision: 44577
URL: http://svn.boost.org/trac/boost/changeset/44577

Log:
Added basic tests for cgi::name and cgi::map and another for a cgi::request.
Added:
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/map_test.cpp (contents, props changed)
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/name_test.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/Jamfile.v2 | 7 ++++++-
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/response.cpp | 13 ++++++++++++-
   2 files changed, 18 insertions(+), 2 deletions(-)

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/Jamfile.v2 (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/Jamfile.v2 2008-04-19 09:34:48 EDT (Sat, 19 Apr 2008)
@@ -9,6 +9,7 @@
     <library>/boost/test//boost_unit_test_framework/
     <library>/boost/system/
     <library>/boost/thread/
+ <library>/boost/regex/
   ;
 
 #local rule run-test( name )
@@ -24,11 +25,15 @@
     
     [ run cookie.cpp ]
     [ run response.cpp ]
+ [ run cgi_simple_request.cpp ]
+ [ run name_test.cpp ]
+ [ run map_test.cpp ]
   ;
 
 test-suite wget_test
   :
- [ run wget.cpp : "--log_level=message" ]
+ #[ run wget.cpp : "--log_level=message" ]
+ [ run hello_world.cpp /boost/filesystem/ ]
   ;
 
 explicit wget_test ;

Added: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp 2008-04-19 09:34:48 EDT (Sat, 19 Apr 2008)
@@ -0,0 +1,96 @@
+// -- cgi_simple_request.hpp --
+//
+// Copyright (c) Darren Garvey 2007-2008.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+//
+// Check that cgi::request works as expected.
+//
+
+#include "boost/cgi/cgi.hpp"
+#define BOOST_TEST_MODULE cgi_request_test
+#include <boost/test/unit_test.hpp>
+
+void init_env()
+{
+ using namespace std;
+ setenv("HTTP_HOST", "localhost", 1);
+ setenv("SCRIPT_NAME", "some/test/script", 1);
+ setenv("EMPTY_VAR", "", 1);
+ setenv("UGLY_VAR", "$££$^%%£&&^%@%26$ £_abcd", 1);
+ setenv("HTTP_COOKIE", "foo=bar", 1);
+ setenv("QUERY_STRING", "hello=world&foo=bar&encoded=%22!%C2%A3$%^$*^hh%%thd@:~", 1);
+ setenv("REQUEST_METHOD", "GET", 1);
+}
+
+BOOST_AUTO_TEST_CASE( env_test )
+{
+ init_env();
+
+ using namespace boost::cgi;
+ request req;
+
+ // Check environment parsing
+ BOOST_CHECK( req[env_data].size() );
+ BOOST_CHECK_EQUAL( req[env_data]["HTTP_HOST"], "localhost" );
+ BOOST_CHECK_EQUAL( req[env_data]["EMPTY_VAR"], "" );
+ BOOST_CHECK_EQUAL( req[env_data]["UGLY_VAR"], "$££$^%%£&&^%@%26$ £_abcd" );
+ BOOST_CHECK_EQUAL( req[env_data]["QUERY_STRING"]
+ , "hello=world&foo=bar&encoded=%22!%C2%A3$%^$*^hh%%thd@:~" );
+ // Check case-insensitive name comparing
+ BOOST_CHECK_EQUAL( req[env_data]["http_host"], "localhost" );
+ // Check helper function (need to test them all?)
+ BOOST_CHECK_EQUAL( req.script_name(), "some/test/script" );
+}
+
+BOOST_AUTO_TEST_CASE( cookie_test )
+{
+ using namespace boost::cgi;
+
+ {
+ request req;
+
+ // Check cookie parsing
+ BOOST_CHECK( req[cookie_data].size() );
+ BOOST_CHECK_EQUAL( req[cookie_data]["foo"], "bar" );
+ // Check case-insensitive name comparing
+ BOOST_CHECK_EQUAL( req[cookie_data]["FOO"], "bar" );
+ }
+
+ {
+ // Set two cookies
+ setenv("HTTP_COOKIE", "foo=bar;another_one=stuff", 1);
+
+ request req;
+ BOOST_CHECK_EQUAL( req[cookie_data]["foo"], "bar" );
+ BOOST_CHECK_EQUAL( req[cookie_data]["another_one"], "stuff" );
+ }
+
+ {
+ // Set a url-encoded cookie (with a '; ' separator).
+ setenv("HTTP_COOKIE", "foo=bar; encoded=%22%C2%A3$%^$*^hh%%thd@:", 1);
+
+ request req;
+ BOOST_CHECK_EQUAL( req[cookie_data]["foo"], "bar" );
+ BOOST_CHECK_EQUAL( req[cookie_data]["encoded"], "\"£$%^$*^hh%%thd@:" );
+ }
+}
+
+BOOST_AUTO_TEST_CASE( get_data_test )
+{
+ using namespace boost::cgi;
+ request req;
+
+ // Make sure the data is going to be parsed
+ BOOST_CHECK_EQUAL( req.request_method(), "GET" );
+
+ // Check GET data/query string parsing
+ BOOST_CHECK( req[get_data].size() );
+ BOOST_CHECK_EQUAL( req[get_data]["hello"], "world" );
+ BOOST_CHECK_EQUAL( req[get_data]["foo"], "bar" );
+ BOOST_CHECK_EQUAL( req[get_data]["encoded"], "\"!£$%^$*^hh%%thd@:~" );
+}
+

Added: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/map_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/map_test.cpp 2008-04-19 09:34:48 EDT (Sat, 19 Apr 2008)
@@ -0,0 +1,21 @@
+
+#include "boost/cgi/common/map.hpp"
+#include <iostream>
+
+#define BOOST_TEST_MODULE value_test_suite
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE( map_test )
+{
+ cgi::common::map m;
+
+ /// First check that upper case compares with lower case.
+ m["foo"] = "bar";
+ BOOST_CHECK_EQUAL( m["foo"], "bar" );
+ BOOST_CHECK_EQUAL( m["FOO"], "bar" );
+
+ /// Then check that lower case compares with upper case.
+ m["FATFOO"] = "minibar";
+ BOOST_CHECK_EQUAL( m["FATFOO"], "minibar" );
+ BOOST_CHECK_EQUAL( m["fatfoo"], "minibar" );
+}

Added: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/name_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/name_test.cpp 2008-04-19 09:34:48 EDT (Sat, 19 Apr 2008)
@@ -0,0 +1,35 @@
+
+#include "boost/cgi/common/name.hpp"
+#include <iostream>
+
+#define BOOST_TEST_MODULE name_test_suite
+#include <boost/test/unit_test.hpp>
+
+using cgi::common::name;
+
+BOOST_AUTO_TEST_CASE( name_test )
+{
+ name n1("foo");
+ name n2("FOO");
+ name n3("bar");
+
+ BOOST_CHECK_EQUAL( n1, n2 );
+ BOOST_CHECK_NE( n1, n3 );
+ BOOST_CHECK_NE( n2, n3 );
+}
+
+BOOST_AUTO_TEST_CASE( name_from_string )
+{
+ std::string s("foo");
+ name n1 = s.c_str();
+ name n2("FOO");
+ s = n2.c_str();
+ //s = n2; // won't compile
+
+ BOOST_CHECK_EQUAL( n1, n2 );
+ BOOST_CHECK_EQUAL( s, "FOO" );
+ BOOST_CHECK_EQUAL( s.c_str(), n1 );
+ BOOST_CHECK_EQUAL( n1, s.c_str() );
+ BOOST_CHECK_NE( s, n1.c_str() );
+}
+

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/response.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/response.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/response.cpp 2008-04-19 09:34:48 EDT (Sat, 19 Apr 2008)
@@ -1,4 +1,15 @@
-// Test the cgi::response class works as advertised
+// -- response.hpp --
+//
+// Copyright (c) Darren Garvey 2007-2008.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+////////////////////////////////////////////////////////////////
+//
+// Test the cgi::response class works as advertised.
+//
+
 #define BOOST_TEST_MODULE response_test
 #include <boost/test/unit_test.hpp>
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk