项目分析笔记(2)---聊天室项目分析与实现(2008.6.12)
粗略的类分析:
TCharRoomServer TCharRoom TClient
Count MaxCount ClientName
Charroom[]:TCharRoom ClientCount CharRoomName
Address Clients[]: TClient RecvMsgs: TMessage
MsgCount RecvMsgCount
Msgs[]: TMessage SendMsg(Msg: string)
TMessage
ClientName;
Msg
实现
1 TTestChar = class(TTestCase)
private
Srv: TCharRoomServer;
CharRoom: TCharRoom;
CliArr: array [0..MaxClient] of TClient;
protected
procedure Setup(); override;
procedure TearDown(); override;
published
procedure TestOneClient();
procedure TestMaxConnect();
end;
.//...
procedure TTestChar.Setup();
var
I: Integer;
begin
Srv:= TServer.Create;
CharRoom:= TCharRoom.Create(Srv);
CharRoom.CharName:= '怡红院';
for I:= 0 to MaxClient-1 do
CliArr[I]:= TClient.Create;
end;
procedure TTestChar.TearDown();
var
I: Integer;
begin
for I:= 0 to MaxClient-1 do
if Assigned(CliArr[I]) then
FreeAndNil(CliArr[I]);
Srv.free;
end;
procedure TTestChar.TestOncClient()
begin
Check(Srv.CharRoom[0].CharName='怡红院');
Check(CliArr[0].Connect('Srv')=True);
Check(CliArr[0].CharRoomName = '怡红院');
Check(Srv.CharRoom[0].Client[0].ClientName='色狼');
end;
procedure TTestChar.TestMaxConnect();
var
Cli: TClient;
begin
Check(CharRoom.MaxClient
for I:= 0 to MaxCount-1 do
CliArr[I].Connect('Srv');
Check(CharRoom.Count=CharRoom.MaxCount);
Cli:= TClient.Create;
Check(Cli.Connect('Srv')=False);
Cli.free;
end;
待续。。。。