uTestRuleMgr.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:3k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit uTestRuleMgr;
  2. interface
  3. uses
  4.   TestFrameWork,uRulerMgr,StrUtils,SysUtils;
  5. type
  6.   TTestCaseRulerMgr = class(TTestCase)
  7.   private
  8.     FRI,FClone:TRuleItems;
  9.   public
  10.     procedure Setup; override ;
  11.     procedure TearDown;      override;
  12.   published
  13.     procedure TestReadFromFile;
  14.     procedure TestNameEqu;
  15.     procedure TestRowsCountEqu;
  16.     procedure TestRowContent;
  17.   end;
  18. implementation
  19. { TTestCaseFirst }
  20. procedure TTestCaseRulerMgr.Setup;
  21. begin
  22.   FRI:=TRuleItems.Create;
  23.   with FRI.Add do
  24.   begin
  25.     Name:='add1';
  26.     with Rows.Add do
  27.     begin
  28.       Text:='text1';
  29.       Compare:=rcContains;
  30.       Area:=raSubject;
  31.     end;
  32.     RulerAction.DeleteOnServer:=True;
  33.   end;
  34.   with FRI.Add do
  35.   begin
  36.     Name:='add2';
  37.     Account:='Account2';
  38.     with Rows.Add do
  39.     begin
  40.       Text:='text2_1';
  41.       Compare:=rcContains;
  42.       Area:=raTo;
  43.     end;
  44.     with Rows.Add do
  45.     begin
  46.       Text:='text2_2';
  47.       Compare:=rcEquals;
  48.       Area:=raTo;
  49.     end;
  50.     RulerAction.PlaySound:='PlaySound2';
  51.   end;
  52.   FClone:=TRuleItems.Create;
  53.   FClone.Assign(FRI);
  54. end;
  55. procedure TTestCaseRulerMgr.TearDown;
  56. begin
  57.   FClone.free;
  58.   FRI.Free;
  59. end;
  60. procedure TTestCaseRulerMgr.TestNameEqu;
  61. begin
  62.   check((FRI.Items[0].Name=FClone.Items[0].Name) and (FRI.Items[1].Name=FClone.Items[1].Name) ,'名字不相同' ) ;
  63. end;
  64. procedure TTestCaseRulerMgr.TestReadFromFile;
  65. var
  66.   r,x:TRuleItems;
  67.   S:string;
  68. begin
  69.   r:=TRuleItems.Create;
  70.   with r.Add do
  71.   begin
  72.     Name:='add1';
  73.     RulerAction:=TRuleAction.Create;
  74.     RulerAction.PlaySound:='playsound';
  75.     RulerAction.RunExe:='Runexepath';
  76.     Rows:=TRuleRows.Create;
  77.     with Rows.Add do
  78.     begin
  79.       Area:=raHeader;
  80.       Text:='rowstext1';
  81.     end;
  82.     with Rows.Add do
  83.     begin
  84.       Area:=raFrom;
  85.       Text:='rowstext2';
  86.     end;
  87.   end;
  88.   r.SaveToFile('E:1.xml');
  89.   r.Free;
  90.   x:=TRuleItems.Create;
  91.   TRuleItems.ReadFromFile('E:1.xml',X);
  92.   S:='x.Items[0]).Rows.Count: '+IntToStr(TRuleItem(x.Items[0]).Rows.Count)+#13#10;
  93.   S:=S+'Text1:  '+TRuleRow(TRuleItem(x.Items[0]).Rows.Items[0]).Text+#13#10;
  94.   S:=S+'Text2:  '+TRuleRow(TRuleItem(x.Items[0]).Rows.Items[1]).Text+#13#10;
  95.   S:=S+'Values must be 2,rowstext1,rowstext2';
  96.   Status(S);
  97.   x.Free;
  98. end;
  99. procedure TTestCaseRulerMgr.TestRowContent;
  100. begin
  101.   CheckEqualsString('text2_1',FClone.Items[1].Rows[0].Text,'FClone.Items[1].Rows[0].Text');
  102. end;
  103. procedure TTestCaseRulerMgr.TestRowsCountEqu;
  104. begin
  105.   CheckEquals(2,FClone.Items[1].Rows.Count,'FClone.Items[1].Rows.Count');
  106. end;
  107. initialization
  108.   TestFramework.RegisterTest(TTestCaseRulerMgr.Suite);
  109. end.