00001 #include "cgiExtend.h"
00002 #include "cgiCookie.h"
00003 #include "cgiTemplates.h"
00004
00005 using namespace std;
00006
00007
00008 bool templateTests(cgiScript & script);
00009 bool cgiTests(cgiScript & script);
00010 bool cookieTesting ( void );
00011
00012
00013 int main(int argc, char ** argv)
00014 {
00015
00016
00017 #ifdef testing_cookies
00018 cgiScript script("text/html",false);
00019 cookieTesting();
00020 script.closeHeader();
00021 #else
00022
00023
00024
00025 cgiScript script("text/html",true,"uploads");
00026 #endif
00027
00028 #ifdef standard_cgi
00029 cgiTests( script );
00030 #else
00031 templateTests( script );
00032 #endif
00033 return 0;
00034 }
00035
00036 bool cgiTests(cgiScript & script)
00037 {
00038
00039 cgiHtml html;
00040 {
00041
00042 cgiHead head;
00043 {
00044 cgiCan title("title");
00045 title << "testHarness";
00046 }
00047 {
00048 cgiCan style("style");
00049 style << ".odd{ color: darkblue; background: linen;}\n"
00050 << ".even{ color: linen; background: darkblue;}\n"
00051 << ".cookie{ color: green; background: tan; }\n";
00052 }
00053
00054 }
00055 {
00056
00057 cgiBody body;
00058 body << "<h1>The test harness</h1>\n";
00059 {
00060 cgiCan div("div"," class='odd'" );
00061 div << "This is some text for the odd one.\n";
00062 }
00063 {
00064 cgiCan div("div", " class='even'" );
00065 div << "This is some text for the even one.\n";
00066 }
00067 {
00068 cgiCan div("div"," class='odd'" );
00069 div << "<h4>Testing Input Collection:</h4>" << endl;
00070 script.ClientArguments().set("This=12&This=13&This=14");
00071 div << "\"This\" count = " << script.ClientArguments().count("This") << "<br>" << endl;
00072 div << "\"This\"variables = " << script.ClientArguments()["This"].str() << "<br>" << endl;
00073 div << "<h4>Testing Nonexistant Input:</h4>" << endl;
00074 div << "\"None\" count = " << script.ClientArguments().count("None") << "<br>" << endl;
00075 div << "\"None\"variables = " << script.ClientArguments()["None"].str() << "<br>" << endl;
00076
00077 }
00078 script.DebugString();
00079 }
00080 return true;
00081 }
00082 bool templateTests(cgiScript & script)
00083 {
00084 cgiTemplates content;
00085 if( content.load( "content.html" ) != true )
00086 {
00087 script << "Failed to load content!" << endl;
00088 return false;
00089 }
00090 aString & File = script.ClientArguments()["File"];
00091 string & filepath = script.ClientArguments().FileMap()[File.str()].path;
00092 aString area = script.ClientArguments()["area"];
00093 script << content.getParagraph ( "part1" );
00094 script << ocString(content.getParagraph ( "image" )).replace("%file",filepath.c_str());
00095 script << ocString(content.getParagraph ( "part2" )).replace("%area",area.c_str());
00096 script.DebugString();
00097 script << content.getParagraph ( "part3" );
00098 return true;
00099 }
00100
00101
00102 bool cookieTesting ( void )
00103 {
00104
00105
00106 cgiCookie cookie;
00107 cookie.setTimeout( 12, 31, 2002, 12, 0 );
00108 cookie.setPath( "/" );
00109 cookie.set("Oid","1234");
00110 return true;
00111 }
00112