test and finish FS
[brdnet.git] / TestFS.pas
blob0f26327e1cb70a0bad6a4f5024b80611be90ff97
1 unit TestFS;
3 INTERFACE
4 IMPLEMENTATION
5 USES ServerLoop,Chat,SysUtils,MemStream,NetAddr,opcode;
7 type t=object
8 ch: tChat;
9 //procedure UserInput
10 procedure ST1(msg:tSMsg; data:boolean);
11 procedure ST2(msg:tSMsg; data:boolean);
12 procedure ST3(msg:tSMsg; data:boolean);
13 procedure Rekt;
14 procedure HardTimeout;
15 end;
17 procedure t.ST1(msg:tSMsg; data:boolean);
18 var s:tMemoryStream;
19 begin
20 write('TestFS: ST1 reply from FS: ');
21 if not data then begin
22 writeln('ack');
23 s.init(GetMem(56),0,56);
24 ch.AddHeaders(s);
25 s.WriteByte(99);
26 ch.Send(s);
27 ch.Callback:=@ST2;
28 halt(32);
29 end else writeln('unexpected data');
30 end;
31 procedure t.ST2(msg:tSMsg; data:boolean);
32 var s:tMemoryStream;
33 begin
34 write('TestFS: ST2 reply from FS: ');
35 if data then begin
36 writeln(msg.stream.ReadByte,'-',msg.stream.ReadByte);
37 s.init(GetMem(56),0,56);
38 ch.AddHeaders(s);
39 s.WriteByte(opcode.upClose);
40 ch.Send(s);
41 ch.Callback:=@ST3;
42 end else writeln('ack');
43 end;
44 procedure t.ST3(msg:tSMsg; data:boolean);
45 begin
46 write('TestFS: ST3 reply from FS: ');
47 if data then writeln('unepected data') else begin
48 writeln('ack');
49 UnShedule(@HardTimeout);
50 ch.DisposeHook:=@Rekt;
51 ch.Close;
52 end;
53 end;
55 procedure t.Rekt;
56 begin
57 writeln('TestFS: rekt');
58 FreeMem(@self,sizeof(self));
59 end;
61 procedure t.HardTimeout;
62 begin
63 writeln('TestFS: hardtimeout');
64 ch.DisposeHook:=@Rekt;
65 ch.Close;
66 end;
68 procedure init;
69 var o:^t;
70 var oi:word;
71 var s:tMemoryStream;
72 const opt='-test-fs';
73 begin
74 oi:=OptIndex(opt);
75 if oi>0 then begin
76 assert(OptParamCount(oi)=1,opt+'(rcpt:tNetAddr)');
77 writeln('TestFS: rcpt '+paramstr(oi+1));
78 new(o); with o^ do begin
79 ch.Init(paramstr(oi+1));
80 ch.Callback:=@ST1;
81 Shedule(7000,@HardTimeout);
82 s.init(GetMem(56),0,56);
83 ch.AddHeaders(s);
84 s.WriteByte(opcode.upFileServer);
85 ch.Send(s);
86 end;
87 end;
88 end;
90 BEGIN
91 init;
92 END.