Browse Source

Initial implementation

michael 27 years ago
parent
commit
7d8d7f093a
3 changed files with 187 additions and 0 deletions
  1. 78 0
      fcl/tests/Makefile
  2. 10 0
      fcl/tests/README
  3. 99 0
      fcl/tests/t001.pp

+ 78 - 0
fcl/tests/Makefile

@@ -0,0 +1,78 @@
+#######################################################################
+#   Makefile for Free Pascal
+#   (C) 1998 Michael van Canneyt
+#######################################################################
+#
+#  Configurable section
+#
+
+# What Compiler should we use ?
+PP=../../compiler/ppc386
+
+# Where are the Free Pascal units ? (Optional)
+UNITDIR = ../linux\;../../rtl/linux
+
+
+# Any options you wish to pass to the compiler
+OPT=
+
+# Where to install the units ?
+UNITINSTALLDIR=/usr/lib/fpc/0.99.5/linuxunits
+
+# Where to install the programs ?
+BININSTALLDIR=/usr/local/bin
+
+#######################################################################
+# End of configurable section. Do not edit below this line.
+#######################################################################
+
+.SUFFIXES: .pp .ppu .pas
+.PHONY: all install clean units progs
+
+# If nothing special needs doing, then just fill in the names here.
+# The rest should be automatic.
+#UNITNAMES=
+PROGNAMES=t001
+UNITOBJECTS=$(addsuffix .o, $(UNITNAMES))
+UNITFILES=$(addsuffix .ppu, $(UNITNAMES))
+PROGSOURCES=$(addsiffix .pp, $(PROGNAMES))
+PROGOBJECTS=$(addsuffix .o, $(PROGNAMES))
+
+# Adapt options. Add unit path if needed.
+ifdef UNITDIR
+override OPT:=$(OPT) -S2 -Up$(UNITDIR)
+endif
+
+
+# Default rule for units
+.pp.ppu:
+	$(PP) $(OPT) $<
+
+# Default target.
+all: $(UNITFILES) $(PROGNAMES)
+
+units: $(UNITFILES)
+
+progs: $(PROGNAMES)
+
+# Default rule for programs
+$(PROGNAMES): %:%.pp
+	$(PP) $(OPT) $<
+
+#
+# Generic install and clean targets
+#
+
+install: all
+	install -m 755 $(UNITINSTALLDIR)
+ifdef UNITNAMES
+	install -m 666 $(UNITNAMES) $(UNITINSTALLDIR)
+endif
+ifdef PROGNAMES
+	install -m 755 $(PROGNAMES) $(BININSTALLDIR)
+endif
+
+clean:
+	rm -f $(UNITOBJECTS) $(UNITFILES) $(PROGNAMES) $(PROGOBJECTS)
+
+# End of makefile.

+ 10 - 0
fcl/tests/README

@@ -0,0 +1,10 @@
+This directory contains test programs for different elements/classes in
+the FCL. 
+
+If you add a test, please number it with 3 digits, and give in this file 
+a short description of what class/function it tests.
+
+File    Tests
+t001.pp TList object from unit classes.
+
+  

+ 99 - 0
fcl/tests/t001.pp

@@ -0,0 +1,99 @@
+Program TestList;
+
+Uses objpas, classes;
+
+const a1 : pchar = '0';
+      a2 : pchar = '1';
+      a3 : pchar = '2';
+      a4 : pchar = '3';
+      a5 : pchar = '4';
+      a6 : pchar = '5';
+      a7 : pchar = '6';
+      a8 : pchar = '7';
+      a9 : pchar = '8';
+      a10 : pchar = '9'; 
+
+Var List : TList;
+    StartMem,Runner : longint;
+
+Function ACompare (P1,P2 : Pointer) : Integer;
+
+Type PByte = ^Byte;
+
+begin
+  Result:=PByte(p1)^-PByte(P2)^;
+end;
+    
+Procedure DumpMem;    
+
+begin
+  Writeln ('    Memavail : ',memavail,' (=',StartMem-Memavail,' Bytes lost).')
+end; 
+
+Procedure DumpList;
+
+Var I : longint;
+
+begin
+  Write ('Count/Capacity : ',List.Count,'/',List.Capacity);dumpmem;
+  If List.Count>0 then
+    begin
+    For i:=0 to List.Count-1 do 
+      if assigned(List.items[I]) then write (Pchar(List.items[i])) else write ('*');
+    Writeln;
+    end;
+end;
+
+
+begin
+  StartMem:=Memavail;
+  Writeln ('Creating List');
+  List:=TList.Create;
+  DumpList;
+  Writeln ('Increasing capacity to 10');
+  List.Capacity:=10;
+  DumpList;
+  Writeln ('Setting capacity to zero');
+  List.capacity:=0;
+  DumpList;
+  Writeln ('Adding 10 elements in random sequence.');
+  List.add (a2);
+  List.add (a1);
+  List.add (a3);
+  List.add (a8);
+  List.add (a5);
+  List.add (a9);
+  List.add (a4);
+  List.Add (a8);
+  List.Add (a7);
+  List.Add (a6);
+  Dumplist;
+  Writeln ('Removing Third element.');
+  List.Delete(2);
+  DumpList;
+  Writeln ('Inserting "0" at third place');
+  List.Insert (2,a1);
+  DumpList;
+  Writeln ('Setting elmts 3 to 6 to Nil.');
+  For Runner:=2 to 5 do List.Items[Runner]:=Nil;
+  Dumplist;
+  Writeln ('Packing list');
+  List.Pack;
+  DumpList;
+  Writeln ('Setting capacity to count');
+  List.Capacity:=List.Count;
+  DumpList;
+  Writeln ('Expanding list');
+  List.Expand;
+  DumpList;
+  Writeln ('Index of ',a1,' : ',List.IndexOf(a1));
+  Writeln ('Removing "',A1,'" from list.');
+  List.Remove (a1);
+  DumpList;
+  Writeln ('Sorting List.');
+  List.Sort (@ACompare);
+  DumpList;
+  Writeln ('Freeing list.');
+  List.Free;
+  DumpMem;
+end.