Initial GUI.
[brdnet.git] / TestFS.pas
blob167459637f24a75d83505b5656d5aef040ba335a
1 unit TestFS;
3 INTERFACE
4 IMPLEMENTATION
5 USES ServerLoop,Chat,SysUtils,MemStream,NetAddr,opcode,Download;
7 type t=object
8 ch: tChat;
9 dw:Download.tAggr;
10 //procedure UserInput
11 procedure ST1(msg:tSMsg; data:boolean);
12 procedure ST2(msg:tSMsg; data:boolean);
13 procedure ST3(msg:tSMsg; data:boolean);
14 procedure Rekt;
15 procedure HardTimeout;
16 end;
18 procedure t.ST1(msg:tSMsg; data:boolean);
19 var r:tMemoryStream absolute msg.stream;
20 var s:tMemoryStream;
21 var op:byte;
22 begin
23 {reply from GET request}
24 write('TestFS: ST1 reply from FS: ');
25 if not data then begin
26 writeln('ack');
27 end else begin
28 ch.Ack;
29 op:=msg.stream.ReadByte;
30 if op=upFAIL then writeln('FAIL ',r.readbyte{,'-',r.readbyte})
31 else if op=upINFO then begin
32 r.skip(2);
33 writeln('INFO size=',r.ReadWord(4),' final=',r.readbyte,' seg=',r.readword(4));
34 ch.Callback:=@ST2;
35 UnShedule(@HardTimeout);
36 halt(99);
37 end else if op=upClose then writeln('CLOSE')
38 else writeln('unknown');
39 end;
40 end;
41 procedure t.ST2(msg:tSMsg; data:boolean);
42 var r:tMemoryStream absolute msg.stream;
43 var s:tMemoryStream;
44 var op:byte;
45 begin
46 {Status Message}
47 write('TestFS: ST2 reply from FS: ');
48 if data then begin
49 ch.Ack;
50 op:=msg.stream.ReadByte;
51 if op=upCLOSE then writeln('CLOSE ')
52 else if op=upDONE then begin
53 writeln('DONE');
54 ch.streaminit(s,1);
55 s.WriteByte(opcode.upClose);
56 ch.Send(s);
57 ch.Callback:=@ST3;
58 end;
59 end else writeln('ack (unexpected)');
60 end;
61 procedure t.ST3(msg:tSMsg; data:boolean);
62 begin
63 {ACK to Close}
64 write('TestFS: ST3 reply from FS: ');
65 if data then writeln('unepected data') else begin
66 writeln('ack');
67 ch.DisposeHook:=@Rekt;
68 ch.Close;
69 dw.Done;
70 end;
71 end;
73 var cnt:LongWOrd=0;
74 procedure IgnoreData(msg:tSMsg);
75 begin
76 cnt:=cnt+msg.length;
77 //Writeln('Data: ',cnt);
78 end;
80 procedure t.Rekt;
81 begin
82 writeln('TestFS: rekt');
83 UnShedule(@HardTimeout);
84 FreeMem(@self,sizeof(self));
85 end;
87 procedure t.HardTimeout;
88 begin
89 writeln('TestFS: hardtimeout');
90 ch.DisposeHook:=@Rekt;
91 ch.Close;
92 end;
94 procedure init;
95 var o:^t;
96 var oi:word;
97 var s:tMemoryStream;
98 const opt='-test-fs';
99 begin
100 oi:=OptIndex(opt);
101 if oi>0 then begin
102 assert(OptParamCount(oi)=1,opt+'(rcpt:tNetAddr)');
103 writeln('TestFS: rcpt '+paramstr(oi+1));
104 new(o); with o^ do begin
105 ch.Init(paramstr(oi+1));
106 ch.Callback:=@ST1;
107 dw.Init(ch.remote);
108 Shedule(20000,@HardTimeout);
109 ch.streaminit(s,33);
110 s.WriteByte(opcode.upFileServer);
111 s.WriteByte({channel}99);
112 s.WriteByte(opcode.upGET);
113 s.Skip(20);
114 s.WriteWord(0,2);
115 s.WriteWord(0,4);
116 s.WriteWord($FFFFFFFF,4);
117 ch.Send(s);
118 //ServerLoop.SetMsgHandler(4,@IgnoreData);
119 //ServerLoop.SetMsgHandler(6,@IgnoreData);
120 end;
121 end;
122 end;
124 BEGIN
125 init;
126 END.