Browse Source

+ Renamed testcgi to testez and added new testcgi

michael 22 years ago
parent
commit
1eae29e931
3 changed files with 198 additions and 108 deletions
  1. 26 0
      fcl/tests/testcgi.html
  2. 53 108
      fcl/tests/testcgi.pp
  3. 119 0
      fcl/tests/testez.pp

+ 26 - 0
fcl/tests/testcgi.html

@@ -0,0 +1,26 @@
+<HTML>
+<TITLE>Test cgi form methods</TITLE>
+<BODY>
+<FORM ACTION="testcgi.cgi" METHOD="GET">
+<H2>Testcgi</H2>
+<INPUT TYPE="hidden" NAME="confirm" VALUE="yes">
+<TABLE WIDTH="100%" CELLPADDING=2 CELLSPACING=1 BORDER=1>
+<TR><TD>Title:</TD><TD><INPUT NAME="title" MAXLENGTH=128 SIZE=50></TD></TR>
+<TR><TD>name:</TD><TD><INPUT NAME="name" MAXLENGTH=128 SIZE=50></TD></TR>
+<TR><TD>Email:</TD><TD><INPUT NAME="email" MAXLENGTH=80 SIZE=50></TD></TR>
+<TR><TD>description:<BR></TD><TD><TEXTAREA NAME="descr" ROWS=10 COLS=50></TEXTAREA></TD></TR>
+</TABLE>
+Select a category:
+<SELECT NAME="category">
+<OPTION value="0" SELECTED>Category 0
+<OPTION value="1" >Category 1
+<OPTION value="2" >Category 2
+<OPTION value="3" >Category 3
+<OPTION value="4" >Category 4
+</SELECT>
+<P>
+<INPUT TYPE="submit" VALUE="Submit values">
+<INPUT TYPE="reset" VALUE="Clear values">
+</FORM>
+</BODY>
+<HTML>

+ 53 - 108
fcl/tests/testcgi.pp

@@ -1,116 +1,61 @@
+{$mode objfpc}
+{$H+}
 
-program CGITest;
+program testcgi;
 
-{$mode delphi}
+uses cgiapp,classes,sysutils;
 
-uses classes, ezcgi;
+Type
+  TTestCGI = Class(TCGIApplication)
+    Procedure DoRun; override;
+  end;
+  
+Procedure TTestCGI.DoRun;
 
-// In the following class you only need to use either DoPost or DoGet
-// depending on what type of CGI request you want to use. If you only
-// are going to be making GET requests that you only need to define
-// and override DoGet and like wise for POST requests.
-
-type
-   TCGIData = class(TEZcgi)
-      procedure DoPost; override;
-      procedure DoGet; override;
-      procedure ShowStuff;
-   end;
-
-var
-   cgiStuff : TCGIData;
-
-// All output from the CGI must first begin with the WriteContent
-// call. This places the passed information and the correct CR's
-// required. In most cases you will always use it as shown below.
-// However if you ever need to return content that isn't standard
-// text/html this allows you to set what that content type is.
-//
-// The PutLine call just passes the information indicated out into
-// the stream for return to the client browser.
-
-
-procedure TCGIData.DoGet;
+Var
+  L : TStrings;
+  I: Integer;
+   
 begin
-   WriteContent('text/html');
-   PutLine('++++++++++ Using GET +++++++++');
-   ShowStuff;
+  ContentType:='text/html';
+  EmitContentType;
+  L:=TStringList.Create;
+  Writeln('<HTML><TITLE>',title,'</TITLE><BODY>');
+  Try
+    Writeln('<H1>List of CGI variables:</H1>');
+    GetCGIVarList(L);
+    For I:=0 to L.Count-1 do
+      Writeln(L[i],'<BR/>');
+    Writeln('<H1>List of environment variables:</H1>');
+    GetEnvironmentList(L);
+    For I:=0 to L.Count-1 do
+      Writeln(L[i],'<BR/>');
+    If (RequestVariableCount>0) then
+      begin
+      Writeln('<H1>List of form variables:</H1>');
+      GetRequestVarList(L);
+      For I:=0 to L.Count-1 do
+        Writeln(L[i],'<BR/>');
+      Writeln('<H1>List of form variables, tabular format:</H1>');
+      Writeln('<table width="100%" border="1">');
+      Writeln('<TR><TH>Name</TH><TH>Value</TH></TR>');
+      GetRequestVarList(L,True);
+      For I:=0 to L.Count-1 do
+        Writeln('<TR><TD>',L[i],'</TD><TD>',RequestVariables[L[i]],'</TD></TR>');
+      end;  
+  Finally
+    Writeln('</BODY></HTML>');
+    Terminate;
+  end;  
 end;
 
-procedure TCGIData.DoPost;
 begin
-   WriteContent('text/html');
-   PutLine('++++++++++ Using POST +++++++++');
-   ShowStuff;
-end;
-
-// I wrote this method so that you can see everything that is passed to
-// and stored by the TEZcgi class. It currently stores all normal CGI
-// as well as everything passed to the CGI by the client. These
-// variables can be accessed via the following properties.
-//
-// Values[Index : string];
-// The Index data can be something like AUTH_TYPE, SCRIPT_NAME, or any
-// standard HTML or CGI environment variable. This can also be the
-// field name of the content being passed in a query string such as
-// "name" found in  //URL/CGI/cgiapp?name=bob
-//
-// Another routine is availble GetValue(Index, defaultValue : string);
-// This routine does the same as the property Values except it allows
-// you to set a default value to be returned if no variable of type
-// name index is found.
-
-// This data is stored in a TStringList so you can retreive it by index
-// as well if you know the index location of the information.
-//
-// The properties for doing this are Names[index : integer] and
-// Variables[index : integer]. Names returns the name of the variable,
-// this would be the data passed in the values or GetValue calls.
-// Instead of returning the value "bob" it returns the value "name". The
-// variables property returns the whole string so using the name example
-// above it would return "name=bob".
-//
-// To determine how many environment variables have been stored you can
-// use the VariableCount property.
-//
-// The following procedure loops through all of the enviroment variables
-// and prints them back to the client. This is a good CGI example to
-// show you exactly what information you have to work with.
-
-procedure TCGIData.ShowStuff;
-var
-   loop : integer;
-
-begin
-   for loop := 0 to VariableCount - 1 do
-      PutLine(Variables[loop] + '<BR>');
-end;
-
-// what follows is the actual program begin..end.
-// The Create call for the class does all the work of the CGI loading
-// the environment variables.
-// The FName and FEmail data is used by the Error report. If the CGI
-// doesn't work correctly for the user this data is included in an
-// error report that is returned to the user which tells them who to
-// inform and how.
-// The Run command starts processing the CGI request and eventually
-// calls either the DoGet or DoPost depending on the request type.
-
-// I don't try and trap it but the class does raise an exception called
-// ECGIException when some error is generated.
-
-begin
-   try
-      cgiStuff := TCGIData.Create;
-      cgiStuff.Name := 'Michael A. Hess';    // replace with your name
-      cgiStuff.Email := '[email protected]';// replace with your email
-      cgiStuff.Run;
-   finally
-      cgiStuff.Free;
-   end;
-end.
-  $Log$
-  Revision 1.3  2002-09-07 15:15:28  peter
-    * old logs removed and tabs fixed
-
-}
+  With TTestCGI.Create(Nil) do
+    Try
+      Title:='Test CGI application';
+      Initialize;
+      Run;
+    Finally
+      Free;
+    end;
+end.      

+ 119 - 0
fcl/tests/testez.pp

@@ -0,0 +1,119 @@
+
+program CGITest;
+
+{$mode delphi}
+
+uses classes, ezcgi;
+
+// In the following class you only need to use either DoPost or DoGet
+// depending on what type of CGI request you want to use. If you only
+// are going to be making GET requests that you only need to define
+// and override DoGet and like wise for POST requests.
+
+type
+   TCGIData = class(TEZcgi)
+      procedure DoPost; override;
+      procedure DoGet; override;
+      procedure ShowStuff;
+   end;
+
+var
+   cgiStuff : TCGIData;
+
+// All output from the CGI must first begin with the WriteContent
+// call. This places the passed information and the correct CR's
+// required. In most cases you will always use it as shown below.
+// However if you ever need to return content that isn't standard
+// text/html this allows you to set what that content type is.
+//
+// The PutLine call just passes the information indicated out into
+// the stream for return to the client browser.
+
+
+procedure TCGIData.DoGet;
+begin
+   WriteContent('text/html');
+   PutLine('++++++++++ Using GET +++++++++');
+   ShowStuff;
+end;
+
+procedure TCGIData.DoPost;
+begin
+   WriteContent('text/html');
+   PutLine('++++++++++ Using POST +++++++++');
+   ShowStuff;
+end;
+
+// I wrote this method so that you can see everything that is passed to
+// and stored by the TEZcgi class. It currently stores all normal CGI
+// as well as everything passed to the CGI by the client. These
+// variables can be accessed via the following properties.
+//
+// Values[Index : string];
+// The Index data can be something like AUTH_TYPE, SCRIPT_NAME, or any
+// standard HTML or CGI environment variable. This can also be the
+// field name of the content being passed in a query string such as
+// "name" found in  //URL/CGI/cgiapp?name=bob
+//
+// Another routine is availble GetValue(Index, defaultValue : string);
+// This routine does the same as the property Values except it allows
+// you to set a default value to be returned if no variable of type
+// name index is found.
+
+// This data is stored in a TStringList so you can retreive it by index
+// as well if you know the index location of the information.
+//
+// The properties for doing this are Names[index : integer] and
+// Variables[index : integer]. Names returns the name of the variable,
+// this would be the data passed in the values or GetValue calls.
+// Instead of returning the value "bob" it returns the value "name". The
+// variables property returns the whole string so using the name example
+// above it would return "name=bob".
+//
+// To determine how many environment variables have been stored you can
+// use the VariableCount property.
+//
+// The following procedure loops through all of the enviroment variables
+// and prints them back to the client. This is a good CGI example to
+// show you exactly what information you have to work with.
+
+procedure TCGIData.ShowStuff;
+var
+   loop : integer;
+
+begin
+   for loop := 0 to VariableCount - 1 do
+      PutLine(Variables[loop] + '<BR>');
+end;
+
+// what follows is the actual program begin..end.
+// The Create call for the class does all the work of the CGI loading
+// the environment variables.
+// The FName and FEmail data is used by the Error report. If the CGI
+// doesn't work correctly for the user this data is included in an
+// error report that is returned to the user which tells them who to
+// inform and how.
+// The Run command starts processing the CGI request and eventually
+// calls either the DoGet or DoPost depending on the request type.
+
+// I don't try and trap it but the class does raise an exception called
+// ECGIException when some error is generated.
+
+begin
+   try
+      cgiStuff := TCGIData.Create;
+      cgiStuff.Name := 'Michael A. Hess';    // replace with your name
+      cgiStuff.Email := '[email protected]';// replace with your email
+      cgiStuff.Run;
+   finally
+      cgiStuff.Free;
+   end;
+end.
+  $Log$
+  Revision 1.1  2003-05-29 15:53:46  michael
+  + Renamed testcgi to testez and added new testcgi
+
+  Revision 1.3  2002/09/07 15:15:28  peter
+    * old logs removed and tabs fixed
+
+}