00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
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 }