Browse Source

+ Added example for iostreams and tprocess

michael 25 years ago
parent
commit
8d3f033046
6 changed files with 88 additions and 13 deletions
  1. 2 12
      fcl/tests/Makefile
  2. 2 1
      fcl/tests/Makefile.fpc
  3. 3 0
      fcl/tests/README
  4. 10 0
      fcl/tests/doecho.pp
  5. 43 0
      fcl/tests/istream.pp
  6. 28 0
      fcl/tests/testproc.pp

+ 2 - 12
fcl/tests/Makefile

@@ -1,5 +1,5 @@
 #
 #
-# Makefile generated by fpcmake v0.99.13 [2000/02/09]
+# Makefile generated by fpcmake v0.99.13 [2000/02/08]
 #
 #
 
 
 defaultrule: all
 defaultrule: all
@@ -184,7 +184,7 @@ endif
 
 
 # Targets
 # Targets
 
 
-override EXEOBJECTS+=stringl dparser fstream mstream list threads testrtf cfgtest xmldump htdump testcgi tidea b64test b64test2 b64enc b64dec restest testz testz2
+override EXEOBJECTS+=stringl dparser fstream mstream list threads testrtf cfgtest xmldump htdump testcgi tidea b64test b64test2 b64enc b64dec restest testz testz2 istream doecho testproc
 ifeq ($(OS_TARGET),win32)
 ifeq ($(OS_TARGET),win32)
 override EXEOBJECTS+=showver
 override EXEOBJECTS+=showver
 endif
 endif
@@ -793,16 +793,6 @@ override FPCOPT+=-Xs -OG2p3 -n
 endif
 endif
 endif
 endif
 
 
-# Strip
-ifdef STRIP
-override FPCOPT+=-Xs
-endif
-
-# Optimizer
-ifdef OPTIMIZE
-override FPCOPT+=-OG2p3
-endif
-
 # Verbose settings (warning,note,info)
 # Verbose settings (warning,note,info)
 ifdef VERBOSE
 ifdef VERBOSE
 override FPCOPT+=-vwni
 override FPCOPT+=-vwni

+ 2 - 1
fcl/tests/Makefile.fpc

@@ -5,7 +5,8 @@
 [targets]
 [targets]
 programs=stringl dparser fstream mstream list threads testrtf \
 programs=stringl dparser fstream mstream list threads testrtf \
          cfgtest xmldump htdump testcgi tidea \
          cfgtest xmldump htdump testcgi tidea \
-         b64test b64test2 b64enc b64dec restest testz testz2
+         b64test b64test2 b64enc b64dec restest testz testz2 \
+         istream doecho testproc
 programs_win32=showver
 programs_win32=showver
 
 
 rst=restest
 rst=restest

+ 3 - 0
fcl/tests/README

@@ -34,3 +34,6 @@ b64enc.pp    base64-encodes StdIn to StdOut (SG)
 b64dec.pp    base64-decodes StdIn to StdOut (SG)
 b64dec.pp    base64-decodes StdIn to StdOut (SG)
 restest.pp   test program for resourcestrings with GNU gettext. (MVC)
 restest.pp   test program for resourcestrings with GNU gettext. (MVC)
              (see also intl subdirectory)
              (see also intl subdirectory)
+istream.pp   testprogram for input/output streams.
+testproc.pp  testprogram for TProcess object. Needs doecho to be compiled
+             also.

+ 10 - 0
fcl/tests/doecho.pp

@@ -0,0 +1,10 @@
+program doecho;
+
+uses sysutils;
+
+var r : integer;
+
+begin
+  for r := 1 to 25 do
+    writeln ('Line : ', inttostr (r));
+end.

+ 43 - 0
fcl/tests/istream.pp

@@ -0,0 +1,43 @@
+Program TestStream;
+
+{
+  When testing, remember to send something through standard input !!
+}
+
+uses sysutils,classes,iostream;
+
+Var Stream : TIOStream;
+    S,T : String;
+    i : longint;
+    SS : ShortString;
+      
+begin
+  S:='ABCDEFGHIJKLMNOPQRSTUVWXYZ %d'#10;
+  T:=S;
+  Writeln ('Creating output stream.');
+  Stream:=TIOStream.Create(iosOutPut);
+  For I:=1 to 10 do
+    begin
+    S:=Format(T,[I]);
+    Stream.WriteBuffer (S[1],Length(S));
+    end;
+  Stream.Free;
+  Writeln ('Creating error stream.');
+  Stream:=TIOStream.Create(iosError);
+  For I:=1 to 10 do
+    begin
+    S:=Format(T,[I]);
+    Stream.WriteBuffer (S[1],Length(S));
+    end;
+  Stream.Free;
+  Writeln ('Creating input stream');
+  Stream:=TIOStream.Create(iosInput);
+  SS:='aha';
+  While Length(SS)>0 do
+    begin
+    SetLength(SS,Stream.Read(SS[1],255));
+    Write(SS);
+    end;
+  Writeln ('Read ',Stream.Position,' bytes.');
+  Stream.Free;
+end.

+ 28 - 0
fcl/tests/testproc.pp

@@ -0,0 +1,28 @@
+program testproc;
+
+uses classes,process;
+
+Const BufSize = 1024;
+
+{$ifdef linux} 
+      TheProgram = 'doecho';
+{$else}
+      TheProgram = 'doecho.exe'; 
+{$endif}
+
+
+Var S : TProcess;
+    Buf : Array[1..BUFSIZE] of char;
+    I,Count : longint;
+    
+begin
+  S:=TProcess.Create(theprogram,[poExecuteOnCreate,poUsePipes]);
+  Repeat
+    Count:=s.output.read(buf,BufSize);
+    // reverse print for fun.
+    For I:=Count downto 1 do
+      write(buf[i]);
+  until Count<BufSize;  
+  writeln;
+  S.Free;  
+end.