Boost logo

Boost-Commit :

From: lists.drrngrvy_at_[hidden]
Date: 2008-04-29 08:23:51


Author: drrngrvy
Date: 2008-04-29 08:23:50 EDT (Tue, 29 Apr 2008)
New Revision: 44880
URL: http://svn.boost.org/trac/boost/changeset/44880

Log:
Extracting out cgi/acgi test commonality. Checking name(bar) < name(foo) in name_test too.
Added:
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/request_test_template.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/acgi_simple_request.cpp | 52 +++++++++++----------------------------
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp | 50 ++++++++++---------------------------
   sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/name_test.cpp | 17 ++++++++++++
   3 files changed, 45 insertions(+), 74 deletions(-)

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/acgi_simple_request.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/acgi_simple_request.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/acgi_simple_request.cpp 2008-04-29 08:23:50 EDT (Tue, 29 Apr 2008)
@@ -14,6 +14,8 @@
 #define BOOST_TEST_MODULE acgi_request_test
 #include <boost/test/unit_test.hpp>
 
+#include "request_test_template.hpp"
+
 void init_env()
 {
   using namespace std;
@@ -34,17 +36,16 @@
   service s;
   request req(s, true);
 
- // 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" );
+ TEST_ENV_DATA(req);
+}
+
+BOOST_AUTO_TEST_CASE( get_data_test )
+{
+ using namespace boost::acgi;
+ service s;
+ request req(s, true);
+
+ TEST_GET_DATA(req);
 }
 
 BOOST_AUTO_TEST_CASE( cookie_test )
@@ -54,12 +55,7 @@
   {
     service s;
     request req(s, true);
-
- // 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" );
+ TEST_ONE_COOKIE(req);
   }
   
   {
@@ -68,8 +64,7 @@
 
     service s;
     request req(s, true);
- BOOST_CHECK_EQUAL( req[cookie_data]["foo"], "bar" );
- BOOST_CHECK_EQUAL( req[cookie_data]["another_one"], "stuff" );
+ TEST_TWO_COOKIES(req);
   }
 
   {
@@ -78,24 +73,7 @@
 
     service s;
     request req(s, true);
- BOOST_CHECK_EQUAL( req[cookie_data]["foo"], "bar" );
- BOOST_CHECK_EQUAL( req[cookie_data]["encoded"], "\"£$%^$*^hh%%thd@:" );
+ TEST_ENCODED_COOKIE(req);
   }
 }
 
-BOOST_AUTO_TEST_CASE( get_data_test )
-{
- using namespace boost::acgi;
- service s;
- request req(s, true);
-
- // 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@:~" );
-}
-

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/cgi_simple_request.cpp 2008-04-29 08:23:50 EDT (Tue, 29 Apr 2008)
@@ -14,6 +14,8 @@
 #define BOOST_TEST_MODULE cgi_request_test
 #include <boost/test/unit_test.hpp>
 
+#include "request_test_template.hpp"
+
 void init_env()
 {
   using namespace std;
@@ -33,17 +35,15 @@
   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" );
+ TEST_ENV_DATA(req);
+}
+
+BOOST_AUTO_TEST_CASE( get_data_test )
+{
+ using namespace boost::cgi;
+ request req;
+
+ TEST_GET_DATA(req);
 }
 
 BOOST_AUTO_TEST_CASE( cookie_test )
@@ -52,12 +52,7 @@
 
   {
     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" );
+ TEST_ONE_COOKIE(req);
   }
   
   {
@@ -65,8 +60,7 @@
     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" );
+ TEST_TWO_COOKIES(req);
   }
 
   {
@@ -74,23 +68,7 @@
     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@:" );
+ TEST_ENCODED_COOKIE(req);
   }
 }
 
-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@:~" );
-}
-

Modified: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/name_test.cpp
==============================================================================
--- sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/name_test.cpp (original)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/name_test.cpp 2008-04-29 08:23:50 EDT (Tue, 29 Apr 2008)
@@ -7,7 +7,7 @@
 
 using cgi::common::name;
 
-BOOST_AUTO_TEST_CASE( name_test )
+BOOST_AUTO_TEST_CASE( case_insensitive_cmp )
 {
   name n1("foo");
   name n2("FOO");
@@ -33,3 +33,18 @@
   BOOST_CHECK_NE( s, n1.c_str() );
 }
 
+BOOST_AUTO_TEST_CASE( lt_compare )
+{
+ name n1("lexicographically_diddy");
+ name n2("lexicographically_large");
+
+ BOOST_CHECK( n1 < n2 );
+}
+
+BOOST_AUTO_TEST_CASE( adding_names )
+{
+ name FOO("FOO");
+ name foo("foo");
+
+ BOOST_CHECK_EQUAL( FOO + foo, foo + FOO );
+}

Added: sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/request_test_template.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/cgi/trunk/libs/cgi/test/run/request_test_template.hpp 2008-04-29 08:23:50 EDT (Tue, 29 Apr 2008)
@@ -0,0 +1,51 @@
+
+#define TEST_ENV_DATA(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" );
+
+
+#define TEST_GET_DATA(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" ); \
+ /* Case-insensitive check */ \
+ BOOST_CHECK_EQUAL( req[get_data]["FOO"], "bar" ); \
+ /* Value should be case-sensitive */ \
+ BOOST_CHECK_NE( req[get_data]["foo"], "BAR" ); \
+ /* Check url-decoding */ \
+ BOOST_CHECK_EQUAL( req[get_data]["encoded"], "\"!£$%^$*^hh%%thd@:~" );
+
+
+#define TEST_ONE_COOKIE(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" );
+
+#define TEST_TWO_COOKIES(req) \
+ \
+ BOOST_CHECK_EQUAL( req[cookie_data]["foo"], "bar" ); \
+ BOOST_CHECK_EQUAL( req[cookie_data]["another_one"], "stuff" );
+
+#define TEST_ENCODED_COOKIE(req) \
+ \
+ BOOST_CHECK_EQUAL( req[cookie_data]["foo"], "bar" ); \
+ BOOST_CHECK_EQUAL( req[cookie_data]["encoded"], "\"£$%^$*^hh%%thd@:" );
+


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