Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

test-session.cc

00001 /*
00002 *  Name:         test-session.cc
00003 *  Author:       Francisco Rodrigo Escobedo Robles
00004 *  Contributor:  Rafael Jesus Alcantara Perez
00005 *  Summary:      CGI Session tracking testing
00006 *  Date:         $Date: 2003/04/14 00:18:35 $
00007 *  Revision:     $Revision: 1.1 $
00008 *
00009 *  Copyright (C) 2000       Francisco Rodrigo Escobedo Robles <frer@pepix.net>
00010 *  Copyright (C) 2000-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00011 *
00012 *  This program is free software; you can redistribute it and/or modify
00013 *  it under the terms of the GNU General Public License as published by
00014 *  the Free Software Foundation; either version 2 of the License, or
00015 *  (at your option) any later version.
00016 *
00017 *  This program is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  You should have received a copy of the GNU General Public License
00023 *  along with this program; if not, write to the Free Software
00024 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00025 *  MA 02111-1307, USA.
00026 */
00027 
00028 #include <iostream>
00029 #include <mpcl/net/cgi/cookie.hh>
00030 #include <mpcl/net/cgi/session.hh>
00031 #include <mpcl/text/gmt_date.hh>
00032 #include <mpcl/text/string.hh>
00033 #include <mpcl/test.h>
00034 #include <sstream>
00035 
00036 
00037 int main (void)
00038 {
00039 
00040   using mpcl::net::cgi::TCookie;
00041   using mpcl::net::cgi::TSession;
00042   using mpcl::text::TGmtDate;
00043   using mpcl::text::TString;  
00044   using std::basic_ostringstream;
00045 
00046   TEST_INIT ("tests for class 'TSession'");
00047 
00048   basic_ostringstream<char>   tTestOutputStream;
00049   TSession<TCookie>           tSession
00050                               (
00051                                 "customer=01743"
00052                                 ";fingerprint=0123456789ABCDEF"
00053                                 ";creditcard=AndromedanExpress"
00054                                 ";shop_cart=0aabn7z3(001=7,002=9)0na00917(57=5,90=6)"
00055                                 ";model_orders=0aabn7z3,lunes(009=1,700=90)"
00056                                 "0aabn7z3,viernes(003=9,090=1)"
00057                                 "6zzabbn7,enero(009=1,030=7)"
00058                               );
00059   TString                     ySessionOutputValue
00060                               (
00061                                 "Set-Cookie: customer=01742\n"
00062                                 "Set-Cookie: fingerprint=0123456789ABCDEF\n"
00063                                 "Set-Cookie: model_orders=0aabn7z3,viernes(090=7)"
00064                                 "6zzabbn7,enero(009=1,030=7)\n"
00065                                 "Set-Cookie: shop_cart=0na00917(57=6,90=6)\n"
00066                               );
00067 
00068   //
00069   //  Makes all cookies to stand between sessions.
00070   //
00071   tSession.keep ("creditcard");
00072   tSession.keep ("customer");
00073   tSession.keep ("fingerprint");
00074   tSession.keep ("model_orders");
00075   tSession.keep ("shop_cart");
00076   TEST_NUMBERS (true, ( tSession.get ("customer") == "01743" ));
00077   TEST_NUMBERS
00078   (
00079     true                                                        ,
00080     ( tSession.get ("shop_cart", "0na00917") ["57"] == "5" )
00081   );
00082   TEST_NUMBERS
00083   (
00084     true                                                                       ,
00085     ( tSession.get ("model_orders", "0aabn7z3", "viernes") ["090"] == "1" )
00086   );
00087   tSession.get ("shop_cart",    "0na00917")            ["57"]  = "6";
00088   tSession.get ("model_orders", "0aabn7z3", "viernes") ["090"] = "7";
00089   tSession.set ("customer",     "01742");
00090   tSession.erase ("creditcard");
00091   tSession.erase ("shop_cart",    "0aabn7z3");
00092   tSession.erase ("model_orders", "0aabn7z3", "lunes");
00093   tSession.erase ("model_orders", "0aabn7z3", "viernes", "003");
00094   tTestOutputStream << tSession;
00095   TEST_NUMBERS (true, ( tTestOutputStream.str() == ySessionOutputValue ));
00096 
00097   //
00098   //  Removes 'model_orders' from cookies to stand between sessions.
00099   //
00100   tSession.keep ("model_orders", false);
00101   tTestOutputStream << tSession;
00102   TEST_NUMBERS (false, ( tTestOutputStream.str() == ySessionOutputValue ));
00103 
00104   TEST_MEMORY_STATUS;
00105   TEST_RETURN_CODE;
00106 
00107 }  // main()

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18