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

Email服务器

开发平台:

Delphi

  1. unit XPTestedUnitParserTests;
  2. interface
  3. uses
  4.   TestFrameWork,
  5.   XPTestedUnitParser,
  6.   XPTestedUnitUtils,
  7.   Classes;          // TStream;
  8. type
  9.   TXPTestedUnitParserTests = class(TTestCase)
  10.   private
  11.     FParser: IXPTestedUnitParser;
  12.     FStream: TStream;
  13.     function MethodCount(const AVisibilityNode: IXPVisibilityNode): integer;
  14.     function PropertyCount(const AVisibilityNode: IXPVisibilityNode): integer;
  15.   protected
  16.     procedure SetUp; override;
  17.     procedure TearDown; override;
  18.   published
  19.     procedure TestParse;
  20.     procedure TestGetError;
  21.     procedure TestExistsMethods;
  22.     procedure TestEmpty;
  23.     procedure TestClassNames;
  24.     procedure TestClassCount;
  25.     procedure TestClassUnitSections;
  26.     procedure TestClassBoundaries;
  27.     procedure TestReParse;
  28.     procedure TestMethodByClassVisibilityCount;
  29.     procedure TestMethodByClassCount;
  30.     procedure TestMethodByVisibilityCount;
  31.     procedure TestPropertyByClassVisibilityCount;
  32.     procedure TestPropertyByClassCount;
  33.     procedure TestPropertyByVisibilityCount;
  34.     procedure TestGlobalFunctionCount;
  35.   end;
  36. implementation
  37. uses
  38.   SysUtils, XPObserver;
  39. const
  40.   UnitSectionStrs: array[TXPUnitSection] of string
  41.     = ('usNone', 'usInterface', 'usImplementation', 'usInitialization',
  42.     'usFinalization');
  43.   ClassVisibilityStrs: array[TXPClassVisibility] of string
  44.     = ( 'cvNone', 'cvPrivate', 'cvProtected', 'cvPublic',
  45.     'cvPublished' );
  46.   TotalSectionCount = 3;
  47.   // Classes in declaration order in example file:
  48.   // INTERFACE
  49.   TSC1_Name = 'TXPStubClass1';
  50.   // Empty stub class
  51.   TSC6_Name = 'TXPStubClass6';
  52.   TSC2_Name = 'TXPStubClass2';
  53.   // IMPLEMENTATION
  54.   TSC3_Name = 'TXPStubClass3';
  55.   // Empty stub classes
  56.   TSC4_Name = 'TXPStubClass4';
  57.   // class implementations
  58.   TSC5_Name = 'TXPStubClass5';
  59.   // INITIALIZATION
  60. // TXPStubClass1
  61.   TSC1_PrivateMethodCount = 1;
  62.   TSC1_ProtectedMethodCount = 2;
  63.   TSC1_PublicMethodCount = 2;
  64.   TSC1_PublishedMethodCount = 11;
  65.   TSC1_MethodCount = TSC1_PrivateMethodCount + TSC1_ProtectedMethodCount
  66.     + TSC1_PublicMethodCount + TSC1_PublishedMethodCount;
  67.   TSC1_PrivatePropertyCount = 2;
  68.   TSC1_ProtectedPropertyCount = 0;
  69.   TSC1_PublicPropertyCount = 0;
  70.   TSC1_PublishedPropertyCount = 3;
  71.   TSC1_PropertyCount = TSC1_PrivatePropertyCount + TSC1_ProtectedPropertyCount
  72.     + TSC1_PublicPropertyCount + TSC1_PublishedPropertyCount;
  73. // TXPStubClass2,3
  74.   TSC2_MethodCount = 15;
  75.   TSC2_PrivateMethodCount = 1;
  76.   TSC2_ProtectedMethodCount = 2;
  77.   TSC2_PublicMethodCount = 2;
  78.   TSC2_PublishedMethodCount = 10;
  79.   TSC2_PropertyCount = 3;
  80.   TSC2_PrivatePropertyCount = 0;
  81.   TSC2_ProtectedPropertyCount = 0;
  82.   TSC2_PublicPropertyCount = 1;
  83.   TSC2_PublishedPropertyCount = 2;
  84.   TotalClassCount = 6;
  85.   TotalPrivateMethodCount = TSC1_PrivateMethodCount + 2 * TSC2_PrivateMethodCount;
  86.   TotalProtectedMethodCount = TSC1_ProtectedMethodCount + 2 * TSC2_ProtectedMethodCount;
  87.   TotalPublicMethodCount = TSC1_PublicMethodCount + 2 * TSC2_PublicMethodCount;
  88.   TotalPublishedMethodCount = TSC1_PublishedMethodCount + 2 * TSC2_PublishedMethodCount;
  89.   TotalPrivatePropertyCount = TSC1_PrivatePropertyCount + 2 * TSC2_PrivatePropertyCount;
  90.   TotalProtectedPropertyCount = TSC1_ProtectedPropertyCount + 2 * TSC2_ProtectedPropertyCount;
  91.   TotalPublicPropertyCount = TSC1_PublicPropertyCount + 2 * TSC2_PublicPropertyCount;
  92.   TotalPublishedPropertyCount = TSC1_PublishedPropertyCount + 2 * TSC2_PublishedPropertyCount;
  93. { TXPTestedUnitParserTests }
  94. procedure TXPTestedUnitParserTests.SetUp;
  95. begin
  96.   inherited;
  97.   FParser := XPTestedUnitParser.CreateXPTestedUnitParser;
  98.   FStream := TFileStream.Create('ExamplesTestedUnitParserTest_1.pas',
  99.     fmOpenRead);
  100. end;
  101. procedure TXPTestedUnitParserTests.TearDown;
  102. begin
  103.   FStream.Free;
  104.   FParser := nil;
  105.   inherited;
  106. end;
  107. procedure TXPTestedUnitParserTests.TestEmpty;
  108. var
  109.   ClassNode: IXPParserNode;
  110. begin
  111.   FParser.ParseTree.Children.Start;
  112.   Check(not FParser.ParseTree.Children.Next(ClassNode));
  113. end;
  114. procedure TXPTestedUnitParserTests.TestExistsMethods;
  115. begin
  116.   Check(FParser.ParseTree.Children <> nil);
  117. end;
  118. procedure TXPTestedUnitParserTests.TestGetError;
  119. var
  120.   Description: string;
  121.   Error: TXPParserError;
  122. begin
  123.   FParser.GetError(Description, Error);
  124.   Check(Error = peNone);
  125. end;
  126. procedure TXPTestedUnitParserTests.TestParse;
  127. begin
  128.   Check(FParser.Parse(FStream));
  129. end;
  130. procedure TXPTestedUnitParserTests.TestClassNames;
  131. var
  132.   SectionNode: IXPParserNode;
  133.   ClassNode, Node: IXPParserNode;
  134.   Names: TStrings;
  135.   ExpectedNames: string;
  136. begin
  137.   ExpectedNames := Format('%s,%s,%s,%s,%s,%s',
  138.     [TSC1_Name, TSC6_Name, TSC2_Name, TSC3_Name, TSC4_Name, TSC5_Name]);
  139.   Names := TStringList.Create;
  140.   try
  141.     FParser.Parse(FStream);
  142.     FParser.ParseTree.Children.Start;
  143.     while FParser.ParseTree.Children.Next(SectionNode) do
  144.     begin
  145.       SectionNode.Children.Start;
  146.       while SectionNode.Children.Next(Node) do
  147.         if Supports(Node, IXPClassNode, ClassNode) then
  148.           Names.Add(ClassNode.Name);
  149.     end;
  150.     CheckEquals(ExpectedNames, Names.CommaText, 'ClassNames');
  151.   finally
  152.     Names.Free;
  153.   end;
  154. end;
  155. procedure TXPTestedUnitParserTests.TestClassCount;
  156. var
  157.   SectionNode: IXPParserNode;
  158.   Node, ClassNode: IXPParserNode;
  159.   Count: integer;
  160. begin
  161.   Count := 0;
  162.   FParser.Parse(FStream);
  163.   FParser.ParseTree.Children.Start;
  164.   while FParser.ParseTree.Children.Next(SectionNode) do
  165.   begin
  166.     SectionNode.Children.Start;
  167.     while SectionNode.Children.Next(Node) do
  168.       if Supports(Node, IXPClassNode, ClassNode) then
  169.         System.Inc(Count);
  170.   end;
  171.   CheckEquals(TotalClassCount, Count, 'TotalClassCount');
  172. end;
  173. procedure TXPTestedUnitParserTests.TestMethodByVisibilityCount;
  174. var
  175.   SectionNode: IXPParserNode;
  176.   ClassNode: IXPParserNode;
  177.   VisibilityNode: IXPVisibilityNode;
  178.   PrivateCount: integer;
  179.   ProtectedCount: integer;
  180.   PublicCount: integer;
  181.   PublishedCount: integer;
  182. begin
  183.   PrivateCount := 0;
  184.   ProtectedCount := 0;
  185.   PublicCount := 0;
  186.   PublishedCount := 0;
  187.   FParser.Parse(FStream);
  188.   FParser.ParseTree.Children.Start;
  189.   while FParser.ParseTree.Children.Next(SectionNode) do
  190.   begin
  191.     SectionNode.Children.Start;
  192.     while SectionNode.Children.Next(ClassNode) do
  193.     begin
  194.       ClassNode.Children.Start;
  195.       while ClassNode.Children.Next(VisibilityNode) do
  196.       begin
  197.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPrivate then
  198.           System.Inc(PrivateCount,
  199.             MethodCount(VisibilityNode as IXPVisibilityNode));
  200.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvProtected then
  201.           System.Inc(ProtectedCount,
  202.             MethodCount(VisibilityNode as IXPVisibilityNode));
  203.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPublic then
  204.           System.Inc(PublicCount,
  205.             MethodCount(VisibilityNode as IXPVisibilityNode));
  206.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPublished then
  207.           System.Inc(PublishedCount,
  208.             MethodCount(VisibilityNode as IXPVisibilityNode));
  209.       end;
  210.     end;
  211.   end;
  212.   CheckEquals(TotalPrivateMethodCount, PrivateCount, 'TotalPrivateCount');
  213.   CheckEquals(TotalProtectedMethodCount, ProtectedCount, 'TotalProtectedCount');
  214.   CheckEquals(TotalPublicMethodCount, PublicCount, 'TotalPublicCount');
  215.   CheckEquals(TotalPublishedMethodCount, PublishedCount, 'TotalPublishedCount');
  216. end;
  217. procedure TXPTestedUnitParserTests.TestReParse;
  218. var
  219.   SectionNode, Node, ClassNode: IXPParserNode;
  220.   ClassCount: integer;
  221.   SectionCount: integer;
  222.   StreamPos: integer;
  223. begin
  224.   ClassCount := 0;
  225.   StreamPos := FStream.Position;
  226.   FParser.Parse(FStream);
  227.   FStream.Position := StreamPos;
  228.   FParser.Parse(FStream);
  229.   SectionCount := FParser.ParseTree.ChildCount;
  230.   CheckEquals(TotalSectionCount, SectionCount);
  231.   FParser.ParseTree.Children.Start;
  232.   while FParser.ParseTree.Children.Next(SectionNode) do
  233.   begin
  234.     SectionNode.Children.Start;
  235.     while SectionNode.Children.Next(Node) do
  236.       if Supports(Node, IXPClassNode, ClassNode) then
  237.         System.Inc(ClassCount);
  238.   end;
  239.   CheckEquals(TotalClassCount, ClassCount);
  240. end;
  241. procedure TXPTestedUnitParserTests.TestMethodByClassCount;
  242. var
  243.   SectionNode: IXPParserNode;
  244.   ClassNode: IXPParserNode;
  245.   VisibilityNode: IXPParserNode;
  246.   Methods: integer;
  247. begin
  248.   FParser.Parse(FStream);
  249.   FParser.ParseTree.Children.Start;
  250.   while FParser.ParseTree.Children.Next(SectionNode) do
  251.   begin
  252.     SectionNode.Children.Start;
  253.     while SectionNode.Children.Next(ClassNode) do
  254.     begin
  255.       Methods := 0;
  256.       ClassNode.Children.Start;
  257.       while ClassNode.Children.Next(VisibilityNode) do
  258.         System.Inc(Methods, MethodCount(VisibilityNode as IXPVisibilityNode));
  259.       if ClassNode.Name = TSC1_Name then
  260.         CheckEquals(TSC1_MethodCount, Methods, Format('%s Count', [TSC1_Name]));
  261.       if ClassNode.Name = TSC2_Name then
  262.         CheckEquals(TSC2_MethodCount, Methods, Format('%s Count', [TSC2_Name]));
  263.       if ClassNode.Name = TSC3_Name then
  264.         CheckEquals(TSC2_MethodCount, Methods, Format('%s Count', [TSC3_Name]));
  265.       if ClassNode.Name = TSC4_Name then
  266.         CheckEquals(0, Methods, Format('%s Count', [TSC4_Name]));
  267.       if ClassNode.Name = TSC5_Name then
  268.         CheckEquals(0, Methods, Format('%s Count', [TSC5_Name]));
  269.       if ClassNode.Name = TSC6_Name then
  270.         CheckEquals(0, Methods, Format('%s Count', [TSC6_Name]));
  271.     end;
  272.   end;
  273. end;
  274. procedure TXPTestedUnitParserTests.TestMethodByClassVisibilityCount;
  275. var
  276.   SectionNode: IXPParserNode;
  277.   ClassNode: IXPParserNode;
  278.   VisibilityNode: IXPParserNode;
  279.   PrivateCount: integer;
  280.   ProtectedCount: integer;
  281.   PublicCount: integer;
  282.   PublishedCount: integer;
  283. begin
  284.   FParser.Parse(FStream);
  285.   FParser.ParseTree.Children.Start;
  286.   while FParser.ParseTree.Children.Next(SectionNode) do
  287.   begin
  288.     SectionNode.Children.Start;
  289.     while SectionNode.Children.Next(ClassNode) do
  290.     begin
  291.       ClassNode.Children.Start;
  292.       PrivateCount := 0;
  293.       ProtectedCount := 0;
  294.       PublicCount := 0;
  295.       PublishedCount := 0;
  296.       while ClassNode.Children.Next(VisibilityNode) do
  297.       begin
  298.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPrivate then
  299.           PrivateCount := MethodCount(VisibilityNode as IXPVisibilityNode);
  300.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvProtected then
  301.           ProtectedCount := MethodCount(VisibilityNode as IXPVisibilityNode);
  302.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPublic then
  303.           PublicCount := MethodCount(VisibilityNode as IXPVisibilityNode);
  304.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPublished then
  305.           PublishedCount := MethodCount(VisibilityNode as IXPVisibilityNode);
  306.       end;
  307.       if ClassNode.Name = TSC1_Name then
  308.         CheckEquals(TSC1_PublishedMethodCount, PublishedCount, Format('%s Published Count', [TSC1_Name]));
  309.       if ClassNode.Name = TSC2_Name then
  310.         CheckEquals(TSC2_PublishedMethodCount, PublishedCount, Format('%s Published Count', [TSC2_Name]));
  311.       if ClassNode.Name = TSC3_Name then
  312.         CheckEquals(TSC2_PublishedMethodCount, PublishedCount, Format('%s Published Count', [TSC3_Name]));
  313.       if ClassNode.Name = TSC4_Name then
  314.         CheckEquals(0, PublishedCount, Format('%s Published Count', [TSC4_Name]));
  315.       if ClassNode.Name = TSC5_Name then
  316.         CheckEquals(0, PublishedCount, Format('%s Published Count', [TSC5_Name]));
  317.       if ClassNode.Name = TSC6_Name then
  318.         CheckEquals(0, PublishedCount, Format('%s Published Count', [TSC6_Name]));
  319.       if ClassNode.Name = TSC1_Name then
  320.         CheckEquals(TSC1_PublicMethodCount, PublicCount, Format('%s Public Count', [TSC1_Name]));
  321.       if ClassNode.Name = TSC2_Name then
  322.         CheckEquals(TSC2_PublicMethodCount, PublicCount, Format('%s Public Count', [TSC2_Name]));
  323.       if ClassNode.Name = TSC3_Name then
  324.         CheckEquals(TSC2_PublicMethodCount, PublicCount, Format('%s Public Count', [TSC3_Name]));
  325.       if ClassNode.Name = TSC4_Name then
  326.         CheckEquals(0, PublicCount, Format('%s Public Count', [TSC4_Name]));
  327.       if ClassNode.Name = TSC5_Name then
  328.         CheckEquals(0, PublicCount, Format('%s Public Count', [TSC5_Name]));
  329.       if ClassNode.Name = TSC6_Name then
  330.         CheckEquals(0, PublicCount, Format('%s Public Count', [TSC6_Name]));
  331.       if ClassNode.Name = TSC1_Name then
  332.         CheckEquals(TSC1_ProtectedMethodCount, ProtectedCount, Format('%s Protected Count', [TSC1_Name]));
  333.       if ClassNode.Name = TSC2_Name then
  334.         CheckEquals(TSC2_ProtectedMethodCount, ProtectedCount, Format('%s Protected Count', [TSC2_Name]));
  335.       if ClassNode.Name = TSC3_Name then
  336.         CheckEquals(TSC2_ProtectedMethodCount, ProtectedCount, Format('%s Protected Count', [TSC3_Name]));
  337.       if ClassNode.Name = TSC4_Name then
  338.         CheckEquals(0, ProtectedCount, Format('%s Protected Count', [TSC4_Name]));
  339.       if ClassNode.Name = TSC5_Name then
  340.         CheckEquals(0, ProtectedCount, Format('%s Protected Count', [TSC5_Name]));
  341.       if ClassNode.Name = TSC6_Name then
  342.         CheckEquals(0, ProtectedCount, Format('%s Protected Count', [TSC6_Name]));
  343.       if ClassNode.Name = TSC1_Name then
  344.         CheckEquals(TSC1_PrivateMethodCount, PrivateCount, Format('%s Private Count', [TSC1_Name]));
  345.       if ClassNode.Name = TSC2_Name then
  346.         CheckEquals(TSC2_PrivateMethodCount, PrivateCount, Format('%s Private Count', [TSC2_Name]));
  347.       if ClassNode.Name = TSC3_Name then
  348.         CheckEquals(TSC2_PrivateMethodCount, PrivateCount, Format('%s Private Count', [TSC3_Name]));
  349.       if ClassNode.Name = TSC4_Name then
  350.         CheckEquals(0, PrivateCount, Format('%s Private Count', [TSC4_Name]));
  351.       if ClassNode.Name = TSC5_Name then
  352.         CheckEquals(0, PrivateCount, Format('%s Private Count', [TSC5_Name]));
  353.       if ClassNode.Name = TSC6_Name then
  354.         CheckEquals(0, PrivateCount, Format('%s Private Count', [TSC6_Name]));
  355.     end;
  356.   end;
  357. end;
  358. procedure TXPTestedUnitParserTests.TestClassBoundaries;
  359. var
  360.   Node, ClassNode: IXPParserNode;
  361.   SectionNode: IXPParserNode;
  362.   LastEnd: longint;
  363. begin
  364.   FParser.Parse(FStream);
  365.   FParser.ParseTree.Children.Start;
  366.   while FParser.ParseTree.Children.Next(SectionNode) do
  367.   begin
  368.     LastEnd := 0;
  369.     SectionNode.Children.Start;
  370.     while SectionNode.Children.Next(Node) do
  371.       if Supports(Node, IXPClassNode, ClassNode) then
  372.       begin
  373.         Check((ClassNode as IXPClassNode).ClassEnd
  374.           > (ClassNode as IXPClassNode).ClassBegin,
  375.           Format('%s: Class length <= 0', [ClassNode.Name]));
  376.         Check((ClassNode as IXPClassNode).ClassBegin > 0,
  377.           Format('%s: Class begin < 0', [ClassNode.Name]));
  378.         Check((ClassNode as IXPClassNode).ClassBegin > LastEnd,
  379.           Format('%s: overlaps with previous class', [ClassNode.Name]));
  380.         LastEnd := (ClassNode as IXPClassNode).ClassEnd;
  381.       end;
  382.   end;
  383. end;
  384. procedure TXPTestedUnitParserTests.TestClassUnitSections;
  385. var
  386.   Node: IXPParserNode;
  387.   ClassNode: IXPClassNode;
  388.   SectionNode: IXPParserNode;
  389. begin
  390.   FParser.Parse(FStream);
  391.   FParser.ParseTree.Children.Start;
  392.   while FParser.ParseTree.Children.Next(SectionNode) do
  393.   begin
  394.     SectionNode.Children.Start;
  395.     while SectionNode.Children.Next(Node) do
  396.       if Supports(Node, IXPClassNode, ClassNode) then
  397.       begin
  398.         if ClassNode.Name = TSC1_Name then
  399.           Check(usInterface = (ClassNode.Parent as IXPSectionNode).GetSection,
  400.             Format('%s %s<>%s', [TSC1_Name,
  401.               UnitSectionStrs[(ClassNode.Parent as IXPSectionNode).GetSection],
  402.               UnitSectionStrs[usInterface]]));
  403.         if ClassNode.Name = TSC2_Name then
  404.           Check(usInterface = (ClassNode.Parent as IXPSectionNode).GetSection,
  405.             Format('%s %s<>%s', [TSC2_Name,
  406.               UnitSectionStrs[(ClassNode.Parent as IXPSectionNode).GetSection],
  407.               UnitSectionStrs[usInterface]]));
  408.         if ClassNode.Name = TSC3_Name then
  409.           Check(usImplementation = (ClassNode.Parent as IXPSectionNode).GetSection,
  410.             Format('%s %s<>%s', [TSC3_Name,
  411.               UnitSectionStrs[(ClassNode.Parent as IXPSectionNode).GetSection],
  412.               UnitSectionStrs[usImplementation]]));
  413.         if ClassNode.Name = TSC4_Name then
  414.           Check(usImplementation = (ClassNode.Parent as IXPSectionNode).GetSection,
  415.             Format('%s %s<>%s', [TSC4_Name,
  416.               UnitSectionStrs[(ClassNode.Parent as IXPSectionNode).GetSection],
  417.               UnitSectionStrs[usImplementation]]));
  418.         if ClassNode.Name = TSC5_Name then
  419.           Check(usImplementation = (ClassNode.Parent as IXPSectionNode).GetSection,
  420.             Format('%s %s<>%s', [TSC5_Name,
  421.               UnitSectionStrs[(ClassNode.Parent as IXPSectionNode).GetSection],
  422.               UnitSectionStrs[usImplementation]]));
  423.         if ClassNode.Name = TSC6_Name then
  424.           Check(usInterface = (ClassNode.Parent as IXPSectionNode).GetSection,
  425.             Format('%s %s<>%s', [TSC6_Name,
  426.               UnitSectionStrs[(ClassNode.Parent as IXPSectionNode).GetSection],
  427.               UnitSectionStrs[usInterface]]));
  428.       end;
  429.   end;
  430. end;
  431. procedure TXPTestedUnitParserTests.TestPropertyByClassCount;
  432. var
  433.   SectionNode: IXPParserNode;
  434.   ClassNode: IXPParserNode;
  435.   VisibilityNode: IXPParserNode;
  436.   Propertys: integer;
  437. begin
  438.   FParser.Parse(FStream);
  439.   FParser.ParseTree.Children.Start;
  440.   while FParser.ParseTree.Children.Next(SectionNode) do
  441.   begin
  442.     SectionNode.Children.Start;
  443.     while SectionNode.Children.Next(ClassNode) do
  444.     begin
  445.       Propertys := 0;
  446.       ClassNode.Children.Start;
  447.       while ClassNode.Children.Next(VisibilityNode) do
  448.         System.Inc(Propertys, PropertyCount(VisibilityNode as IXPVisibilityNode));
  449.       if ClassNode.Name = TSC1_Name then
  450.         CheckEquals(TSC1_PropertyCount, Propertys, Format('%s Count', [TSC1_Name]));
  451.       if ClassNode.Name = TSC2_Name then
  452.         CheckEquals(TSC2_PropertyCount, Propertys, Format('%s Count', [TSC2_Name]));
  453.       if ClassNode.Name = TSC3_Name then
  454.         CheckEquals(TSC2_PropertyCount, Propertys, Format('%s Count', [TSC3_Name]));
  455.       if ClassNode.Name = TSC4_Name then
  456.         CheckEquals(0, Propertys, Format('%s Count', [TSC4_Name]));
  457.       if ClassNode.Name = TSC5_Name then
  458.         CheckEquals(0, Propertys, Format('%s Count', [TSC5_Name]));
  459.       if ClassNode.Name = TSC6_Name then
  460.         CheckEquals(0, Propertys, Format('%s Count', [TSC6_Name]));
  461.     end;
  462.   end;
  463. end;
  464. procedure TXPTestedUnitParserTests.TestPropertyByClassVisibilityCount;
  465. var
  466.   SectionNode: IXPParserNode;
  467.   ClassNode: IXPParserNode;
  468.   VisibilityNode: IXPParserNode;
  469.   PrivateCount: integer;
  470.   ProtectedCount: integer;
  471.   PublicCount: integer;
  472.   PublishedCount: integer;
  473. begin
  474.   FParser.Parse(FStream);
  475.   FParser.ParseTree.Children.Start;
  476.   while FParser.ParseTree.Children.Next(SectionNode) do
  477.   begin
  478.     SectionNode.Children.Start;
  479.     while SectionNode.Children.Next(ClassNode) do
  480.     begin
  481.       ClassNode.Children.Start;
  482.       PrivateCount := 0;
  483.       ProtectedCount := 0;
  484.       PublicCount := 0;
  485.       PublishedCount := 0;
  486.       while ClassNode.Children.Next(VisibilityNode) do
  487.       begin
  488.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPrivate then
  489.           PrivateCount := PropertyCount(VisibilityNode as IXPVisibilityNode);
  490.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvProtected then
  491.           ProtectedCount := PropertyCount(VisibilityNode as IXPVisibilityNode);
  492.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPublic then
  493.           PublicCount := PropertyCount(VisibilityNode as IXPVisibilityNode);
  494.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPublished then
  495.           PublishedCount := PropertyCount(VisibilityNode as IXPVisibilityNode);
  496.       end;
  497.       if ClassNode.Name = TSC1_Name then
  498.         CheckEquals(TSC1_PublishedPropertyCount, PublishedCount, Format('%s Published Count', [TSC1_Name]));
  499.       if ClassNode.Name = TSC2_Name then
  500.         CheckEquals(TSC2_PublishedPropertyCount, PublishedCount, Format('%s Published Count', [TSC2_Name]));
  501.       if ClassNode.Name = TSC3_Name then
  502.         CheckEquals(TSC2_PublishedPropertyCount, PublishedCount, Format('%s Published Count', [TSC3_Name]));
  503.       if ClassNode.Name = TSC4_Name then
  504.         CheckEquals(0, PublishedCount, Format('%s Published Count', [TSC4_Name]));
  505.       if ClassNode.Name = TSC5_Name then
  506.         CheckEquals(0, PublishedCount, Format('%s Published Count', [TSC5_Name]));
  507.       if ClassNode.Name = TSC6_Name then
  508.         CheckEquals(0, PublishedCount, Format('%s Published Count', [TSC6_Name]));
  509.       if ClassNode.Name = TSC1_Name then
  510.         CheckEquals(TSC1_PublicPropertyCount, PublicCount, Format('%s Public Count', [TSC1_Name]));
  511.       if ClassNode.Name = TSC2_Name then
  512.         CheckEquals(TSC2_PublicPropertyCount, PublicCount, Format('%s Public Count', [TSC2_Name]));
  513.       if ClassNode.Name = TSC3_Name then
  514.         CheckEquals(TSC2_PublicPropertyCount, PublicCount, Format('%s Public Count', [TSC3_Name]));
  515.       if ClassNode.Name = TSC4_Name then
  516.         CheckEquals(0, PublicCount, Format('%s Public Count', [TSC4_Name]));
  517.       if ClassNode.Name = TSC5_Name then
  518.         CheckEquals(0, PublicCount, Format('%s Public Count', [TSC5_Name]));
  519.       if ClassNode.Name = TSC6_Name then
  520.         CheckEquals(0, PublicCount, Format('%s Public Count', [TSC6_Name]));
  521.       if ClassNode.Name = TSC1_Name then
  522.         CheckEquals(TSC1_ProtectedPropertyCount, ProtectedCount, Format('%s Protected Count', [TSC1_Name]));
  523.       if ClassNode.Name = TSC2_Name then
  524.         CheckEquals(TSC2_ProtectedPropertyCount, ProtectedCount, Format('%s Protected Count', [TSC2_Name]));
  525.       if ClassNode.Name = TSC3_Name then
  526.         CheckEquals(TSC2_ProtectedPropertyCount, ProtectedCount, Format('%s Protected Count', [TSC3_Name]));
  527.       if ClassNode.Name = TSC4_Name then
  528.         CheckEquals(0, ProtectedCount, Format('%s Protected Count', [TSC4_Name]));
  529.       if ClassNode.Name = TSC5_Name then
  530.         CheckEquals(0, ProtectedCount, Format('%s Protected Count', [TSC5_Name]));
  531.       if ClassNode.Name = TSC6_Name then
  532.         CheckEquals(0, ProtectedCount, Format('%s Protected Count', [TSC6_Name]));
  533.       if ClassNode.Name = TSC1_Name then
  534.         CheckEquals(TSC1_PrivatePropertyCount, PrivateCount, Format('%s Private Count', [TSC1_Name]));
  535.       if ClassNode.Name = TSC2_Name then
  536.         CheckEquals(TSC2_PrivatePropertyCount, PrivateCount, Format('%s Private Count', [TSC2_Name]));
  537.       if ClassNode.Name = TSC3_Name then
  538.         CheckEquals(TSC2_PrivatePropertyCount, PrivateCount, Format('%s Private Count', [TSC3_Name]));
  539.       if ClassNode.Name = TSC4_Name then
  540.         CheckEquals(0, PrivateCount, Format('%s Private Count', [TSC4_Name]));
  541.       if ClassNode.Name = TSC5_Name then
  542.         CheckEquals(0, PrivateCount, Format('%s Private Count', [TSC5_Name]));
  543.       if ClassNode.Name = TSC6_Name then
  544.         CheckEquals(0, PrivateCount, Format('%s Private Count', [TSC6_Name]));
  545.     end;
  546.   end;
  547. end;
  548. procedure TXPTestedUnitParserTests.TestPropertyByVisibilityCount;
  549. var
  550.   SectionNode: IXPParserNode;
  551.   ClassNode: IXPParserNode;
  552.   VisibilityNode: IXPVisibilityNode;
  553.   PrivateCount: integer;
  554.   ProtectedCount: integer;
  555.   PublicCount: integer;
  556.   PublishedCount: integer;
  557. begin
  558.   PrivateCount := 0;
  559.   ProtectedCount := 0;
  560.   PublicCount := 0;
  561.   PublishedCount := 0;
  562.   FParser.Parse(FStream);
  563.   FParser.ParseTree.Children.Start;
  564.   while FParser.ParseTree.Children.Next(SectionNode) do
  565.   begin
  566.     SectionNode.Children.Start;
  567.     while SectionNode.Children.Next(ClassNode) do
  568.     begin
  569.       ClassNode.Children.Start;
  570.       while ClassNode.Children.Next(VisibilityNode) do
  571.       begin
  572.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPrivate then
  573.           System.Inc(PrivateCount,
  574.             PropertyCount(VisibilityNode as IXPVisibilityNode));
  575.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvProtected then
  576.           System.Inc(ProtectedCount,
  577.             PropertyCount(VisibilityNode as IXPVisibilityNode));
  578.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPublic then
  579.           System.Inc(PublicCount,
  580.             PropertyCount(VisibilityNode as IXPVisibilityNode));
  581.         if (VisibilityNode as IXPVisibilityNode).GetVisibility = cvPublished then
  582.           System.Inc(PublishedCount,
  583.             PropertyCount(VisibilityNode as IXPVisibilityNode));
  584.       end;
  585.     end;
  586.   end;
  587.   CheckEquals(TotalPrivatePropertyCount, PrivateCount, 'TotalPrivateCount');
  588.   CheckEquals(TotalProtectedPropertyCount, ProtectedCount, 'TotalProtectedCount');
  589.   CheckEquals(TotalPublicPropertyCount, PublicCount, 'TotalPublicCount');
  590.   CheckEquals(TotalPublishedPropertyCount, PublishedCount, 'TotalPublishedCount');
  591. end;
  592. function TXPTestedUnitParserTests.MethodCount(
  593.   const AVisibilityNode: IXPVisibilityNode): integer;
  594. var
  595.   Child: IXPParserNode;
  596.   MethodNode: IXPMethodNode;
  597. begin
  598.   Result := 0;
  599.   AVisibilityNode.Children.Start;
  600.   while AVisibilityNode.Children.Next(Child) do
  601.     if Supports(Child, IXPMethodNode, MethodNode) then
  602.       Inc(Result);
  603. end;
  604. function TXPTestedUnitParserTests.PropertyCount(
  605.   const AVisibilityNode: IXPVisibilityNode): integer;
  606. var
  607.   Child: IXPParserNode;
  608.   PropertyNode: IXPPropertyNode;
  609. begin
  610.   Result := 0;
  611.   AVisibilityNode.Children.Start;
  612.   while AVisibilityNode.Children.Next(Child) do
  613.     if Supports(Child, IXPPropertyNode, PropertyNode) then
  614.       Inc(Result);
  615. end;
  616. procedure TXPTestedUnitParserTests.TestGlobalFunctionCount;
  617. var
  618.   SectionNode: IXPParserNode;
  619.   GlobalFunctionCount: integer;
  620.   Node: IXPParserNode;
  621.   FunctionNode: IXPFunctionNode;
  622. begin
  623.   GlobalFunctionCount := 0;
  624.   FParser.Parse(FStream);
  625.   FParser.ParseTree.Children.Start;
  626.   while FParser.ParseTree.Children.Next(SectionNode) do
  627.   begin
  628.     SectionNode.Children.Start;
  629.     while SectionNode.Children.Next(Node) do
  630.     begin
  631.       if Supports(Node, IXPFunctionNode, FunctionNode) then
  632.         Inc(GlobalFunctionCount);
  633.     end;
  634.   end;
  635.   CheckEquals(4, GlobalFunctionCount, 'TotalGlobalFunctionCount');
  636. end;
  637. initialization
  638.   TestFramework.RegisterTest('XPTestedUnitParserTests Suite',
  639.     TXPTestedUnitParserTests.Suite);
  640. end.