unit TestUnit_OmrSp;
{Athor:月夜风筝 QQ:= 14574256 EMail:= 14574256@163.com
}
{
Delphi DUnit Test Case
----------------------
This unit contains a skeleton test case class generated by the Test Case Wizard.
Modify the generated code to correctly setup and call the methods from the unit
being tested.
}
interface
uses
TestFramework, Classes, Unit_OmrSp, Unit_VOmrSp, Windows, Unit_HBase, Forms, SysUtils;
type
// Test methods for class TOMR
TestTOMR = class(TTestCase)
strict private
FOMR: TOMR;
MEventMsgS: TStringList;
procedure CatOnError(ErrID, ErrDesc: string);
//捕捉事件
procedure CatOnFinished();
//捕捉事件
procedure CatOnOneReadOK(ReadString: string);
//捕捉事件
public
procedure SetUp;
override;
procedure TearDown;
override;
published
procedure TestValidateFomFile;
procedure TestRead_NoLib;
procedure TestRead_InValidLib;
procedure TestRead_UnSetFomFile;
procedure TestRead_OnLinePassedZero;
procedure TestRead_OnLinePassedNormal_50TFomFile;
procedure TestRead_OnLineContinousRead50TFom;
procedure TestReadSerialN
nLine;
procedure TestRead_OffLine;
procedure TestCharDeCode;
procedure TestStringDeCode;
procedure TestEncode;
end;
implementation
procedure TestTOMR.SetUp;
begin
FOMR := TOMR.Create(nil);
FOMR.LibPath:= 'In';
FOMR.OnError:= CatOnError;
FOmr.OnFinished:= CatOnFinished;
Fomr.OnOneReadOK:= CatOnOneReadOK;
MEventMsgS:= TStringList.Create;
end;
procedure TestTOMR.TearDown;
begin
FOMR.Free;
FOMR := nil;
MEventMsgS.Free;
end;
procedure TestTOMR.TestValidateFomFile;
var
ReturnValue: Boolean;
AFileName: string;
begin
AFileName:= ExtractFileDir(ParamStr(0)) + '/in/万方汇博--50题.fom';
ReturnValue := FOMR.ValidateFomFile(AFileName);
if not ReturnValue then
Fail('EspF: 语法正确的卡格式返回 True !');
AFileName:= ExtractFileDir(ParamStr(0)) + '/in/万方汇博--50题(错误改).fom';
ReturnValue := FOMR.ValidateFomFile(AFileName);
if ReturnValue then
Fail('EspF: 语法不正确的卡格式返回 False !');
end;
procedure TestTOMR.TestRead_NoLib;
var
Ret: Boolean;
begin
if FileExists(ExtractFilePath(ParamStr(0)) + 'omr.dll') then
RenameFile(ExtractFilePath(ParamStr(0)) + 'omr.dll', ExtractFilePath(ParamStr(0)) + 'omr.dll.bak');
FOMR.LibPath:= '';
FOMR.SetFomFile(ExtractFileDir(ParamStr(0)) + '/in/万方汇博--50题.fom');
FOMR.Read;
if FileExists(ExtractFilePath(ParamStr(0)) + 'omr.dll.bak') then
RenameFile(ExtractFilePath(ParamStr(0)) + 'omr.dll.bak', ExtractFilePath(ParamStr(0)) + 'omr.dll');
if FOMR.DevStatus <> dsUnInited then
Fail('EspF:动态库不存在时设备状态保持在UnInited状态!');
Ret:= (pos('[OnError]', MEventMsgS.Text) > 0 ) and (MEventMsgS.Count = 2) and (Pos('OMR01', MEventMsgS.Text) > 0);
if not Ret then
Fail('EspF:动态库不存在时触发OnError中的无库错!'#13 + 'Event Msg:' + MEventMsgS.Text);
end;
procedure TestTOMR.TestRead_InValidLib;
var
Ret: Boolean;
begin
RenameFile(ExtractFilePath(ParamStr(0)) + 'in/omr.dll', ExtractFilePath(ParamStr(0)) + 'in/omr.dll.bak');
RenameFile(ExtractFilePath(ParamStr(0)) + 'in/Invalid_OMR.DLL', ExtractFilePath(ParamStr(0)) + 'in/omr.dll');
FOMR.SetFomFile(ExtractFileDir(ParamStr(0)) + '/in/万方汇博--50题.fom');
RenameFile(ExtractFilePath(ParamStr(0)) + 'in/omr.dll', ExtractFilePath(ParamStr(0)) + 'in/Invalid_OMR.DLL');
RenameFile(ExtractFilePath(ParamStr(0)) + 'in/omr.dll.bak', ExtractFilePath(ParamStr(0)) + 'in/omr.dll');
if FOMR.DevStatus <> dsUnInited then
Fail('EspF:动态库失效时设备状态保持在UnInited状态!'#13 + 'Event Msg:' + MEventMsgS.Text);
Ret:= (pos('[OnError]', MEventMsgS.Text) > 0 ) and (MEventMsgS.Count = 1) and (Pos('OMR02', MEventMsgS.Text) > 0);
if not Ret then
Fail('EspF:动态库失效时触发OnError中的无效库错!'#13 + 'Event Msg:' + MEventMsgS.Text);
end;
procedure TestTOMR.TestRead_UnSetFomFile;
var
Ret: Boolean;
begin
FOMR.Read;
Ret:= (pos('[OnError]', MEventMsgS.Text) > 0 ) and (MEventMsgS.Count = 1) and (Pos('OMR04', MEventMsgS.Text) > 0);
if not Ret then
Fail('EspF:未设格式读卡,触发OnError中的未设置格式文件错!'#13 + 'Event Msg:' + MEventMsgS.Text);
end;
procedure TestTOMR.TestRead_OnLinePassedZero;
var
Ret: Boolean;
begin
FOMR.ContinuousRead:= False;
FOMR.SetFomFile(ExtractFileDir(ParamStr(0)) + '/in/万方汇博--50题.fom');
FOMR.Read;
Ret:= (Pos('[OnError]', MEventMsgS.Text) > 0) and (Pos('DEV16', MEventMsgS.Text) > 0) and (MEventMsgS.Count = 1);
{这里应能捕捉到OnError事件,并且是其中的无纸错}
if not Ret then
Fail('EspF:阅读机试图走纸但没有过卡触发OnError事件中的无纸错!' + #13 + '本测试需要纸进纸仓无纸的情况下进行!'#13 + 'Event Msg:' + MEventMsgS.Text);
end;
procedure TestTOMR.TestRead_OnLinePassedNormal_50TFomFile;
var
Ret: Boolean;
begin
FOMR.ContinuousRead:= False;
FOMR.SetFomFile(ExtractFileDir(ParamStr(0)) + '/in/万方汇博--50题.fom');
FOMR.Read;
Ret:= Pos('[OnOneReadOK]', MEventMsgS.Text) > 0;
{这里应能捕捉到OnReadOK事件}
if not Ret then
Fail('EspF:正常走纸解发OnOneReadOK事件!'+#13+'说明:请放50题卡一张'#13 + 'Event Msg:' + MEventMsgS.Text);
end;
procedure TestTOMR.TestRead_OnLineContinousRead50TFom;
var
Ret: Boolean;
begin
FOMR.ContinuousRead:= True;
FOMR.SetFomFile(ExtractFileDir(ParamStr(0)) + '/in/万方汇博--50题.fom');
FOMR.Read;
Ret:= (Pos('[OnOneReadOK]', MEventMsgS.Text) > 0) and (MEventMsgS.Count >= 2) and (Pos('[OnFinished]', MEventMsgS.Text) > 0);
if not Ret then
Fail('EspF:连续读卡完成时触发OnFinished事件!'#13 + '说明:请放一第或多张50题卡'#13 + 'Event Msg:' + MEventMsgS.Text);
end;
procedure TestTOMR.TestRead_OffLine;
var
AFileName: string;
Ret: Boolean;
begin
AFileName:= ExtractFileDir(ParamStr(0)) + '/in/万方汇博--50题.fom';
FOMR.SetFomFile(AFileName);
Ret:= (Pos('[OnError]', MEventMsgS.Text) > 0) and (Pos('OMR03', MEventMsgS.Text) > 0) and (MEventMsgS.Count = 1);
if not Ret then
Fail('EspF:联机失败触发OnError中联机错!' + #13 + '说明:本测试需要在未联机状态执行有效!'#13 + 'Event Msg:' + MEventMsgS.Text);
end;
procedure TestTOMR.TestReadSerialN
nLine;
{用例:读序列号
}
var
ReturnValue: string;
begin
ReturnValue := FOMR.ReadSerialNo;
// TODO: Validate method results
if Length(ReturnValue) <> 8 then
Fail('测试失败!');
end;
procedure TestTOMR.TestCharDeCode;
{用例:字解码
}
var
ReturnValue: string;
ErrorDecode: string;
BlankDecode: string;
ACh: Char;
begin
ACh:= 'H';
ErrorDecode:= '>';
BlankDecode:= '#';
// TODO: Setup method call parameters
ReturnValue := FOMR.CharDeCode(ACh, BlankDecode, ErrorDecode);
// TODO: Validate method results
if ReturnValue <> 'AB' then
Fail('测试失败!');
ACh:= #0;
ReturnValue := FOMR.CharDeCode(ACh, BlankDecode, ErrorDecode);
if ReturnValue <> '>' then
Fail('测试失败!');
end;
procedure TestTOMR.TestStringDeCode;
{用例:串解码
}
var
ReturnValue: string;
ErrorDecode: string;
BlankDecode: string;
SeparatStr: string;
AStr: string;
begin
AStr:= 'ABCO';
ErrorDecode:= '>';
BlankDecode:= '#';
SeparatStr:= ',';
// TODO: Setup method call parameters
ReturnValue := FOMR.StringDeCode(AStr, SeparatStr, BlankDecode, ErrorDecode);
// TODO: Validate method results
if ReturnValue <> 'A,B,C,ABCD' then
Fail('测试失败!');
AStr:= '';
ReturnValue:= FOMR.StringDeCode(AStr, SeparatStr, BlankDecode, ErrorDecode);
if ReturnValue <> '' then
Fail('测试失败!');
end;
procedure TestTOMR.TestEncode;
{用例:词编码
}
var
ReturnValue: string;
ErrorEncode: string;
Input: string;
begin
// TODO: Setup method call parameters
ErrorEncode:= '>';
FOMR.DeCodeMethod:= OMRCode;
Input:= ' ';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> '.' then
Fail('测试失败!');
// TODO: Validate method results
Input:= '';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> '>' then
Fail('测试失败!');
Input:= 'ABC';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> 'G' then
Fail('测试失败!');
FOMR.DeCodeMethod:= GBCode;
Input:= 'BCD';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> 'N' then
Fail('测试失败!');
Input:= ' ';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> 'P' then
Fail('测试失败!');
Input:= '';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> '>' then
Fail('测试失败!');
FOMR.DeCodeMethod:= DRSCode;
Input:= '';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> '>' then
Fail('测试失败!');
Input:= ' ';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> '*' then
Fail('测试失败!');
Input:= 'AB';
ReturnValue := FOMR.Encode(Input, ErrorEncode);
if ReturnValue <> 'C' then
Fail('测试失败!');
end;
procedure TestTOMR.CatOnError(ErrID, ErrDesc: string);
//捕捉事件
begin
MEventMsgS.Add(Format('[OnError] Param1 = %S, Param2 = %S' ,[ErrID, ErrDesc]));
end;
procedure TestTOMR.CatOnFinished();
//捕捉事件
begin
MEventMsgS.Add(Format('[OnFinished]' ,[]));
end;
procedure TestTOMR.CatOnOneReadOK(ReadString: string);
//捕捉事件
begin
MEventMsgS.Add(Format('[OnOneReadOK] Param1 = %S' ,[ReadString]));
end;
initialization
// Register any test cases with the test runner
RegisterTest(TestTOMR.Suite);
end.