You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /********************************************************************
  2. * Copyright (c) 2005 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - iniital version
  10. *******************************************************************/
  11. package org.aspectj.tools.ajdoc;
  12. import java.io.File;
  13. import java.util.List;
  14. public class ITDTest extends AjdocTestCase {
  15. /**
  16. * Test for pr119453
  17. */
  18. public void testITDDeclaredOn() throws Exception {
  19. initialiseProject("pr119453");
  20. File[] files = {
  21. new File(getAbsoluteProjectDir() + "/src/pack/C.java"),
  22. new File(getAbsoluteProjectDir() + "/src/pack/A.aj")
  23. };
  24. runAjdoc("private",files);
  25. File htmlA = new File(getAbsolutePathOutdir() + "/pack/A.html");
  26. if (!htmlA.exists()) {
  27. fail("couldn't find " + getAbsolutePathOutdir() + "/pack/A.html - were there compilation errors?");
  28. }
  29. // check field itd appears
  30. boolean b = AjdocOutputChecker.detailSectionContainsRel(
  31. htmlA,"DECLARE DETAIL SUMMARY",
  32. "C.y",
  33. HtmlDecorator.HtmlRelationshipKind.DECLARED_ON,
  34. "HREF=\"../pack/C.html\"");
  35. assertTrue("Should have 'C.y declared on HREF=\"../pack/C.html\"" +
  36. "' in the Declare Detail section", b);
  37. b = AjdocOutputChecker.summarySectionContainsRel(
  38. htmlA,"DECLARE SUMMARY",
  39. "C.y",
  40. HtmlDecorator.HtmlRelationshipKind.DECLARED_ON,
  41. "HREF=\"../pack/C.html\"");
  42. assertTrue("Should have 'C.y declared on HREF=\"../pack/C.html\"" +
  43. "' in the Declare Summary section", b);
  44. // check the modifiers are correct in the declare detail summary
  45. String[] stringsA = { "private int",
  46. "public java.lang.String",
  47. "<H3>C.y</H3>",
  48. "public&nbsp;</TT><B>C.C",
  49. "package&nbsp;void"};
  50. List missing = AjdocOutputChecker.getMissingStringsInSection(htmlA,stringsA,"DECLARE DETAIL SUMMARY");
  51. assertEquals("There should be one missing string ",1,missing.size());
  52. assertEquals("the 'package' and 'void' modifiers shouldn't appear in the 'Declare Detail' section of the ajdoc",
  53. "package&nbsp;void", missing.get(0));
  54. // check the modifiers are correct in the declare summary
  55. String[] stringsA2 = {"private", "int", "public", "String", "package&nbsp;void"};
  56. missing = AjdocOutputChecker.getMissingStringsInSection(htmlA,stringsA2,"DECLARE SUMMARY");
  57. assertEquals("There should be two missing strings ",2,missing.size());
  58. assertTrue("the public modifier shouldn't appear in the 'Declare Summary' section of the ajdoc", missing.contains("public"));
  59. assertTrue("the 'package' and 'void' modifiers shouldn't appear in the 'Declare Summary' section of the ajdoc", missing.contains("package&nbsp;void"));
  60. }
  61. /**
  62. * Test for pr119453
  63. */
  64. public void testITDMatchesDeclare() throws Exception {
  65. initialiseProject("pr119453");
  66. File[] files = {
  67. new File(getAbsoluteProjectDir() + "/src/pack/C.java"),
  68. new File(getAbsoluteProjectDir() + "/src/pack/A.aj")
  69. };
  70. runAjdoc("private",files);
  71. // Check the contents of C.html
  72. File htmlC = new File(getAbsolutePathOutdir() + "/pack/C.html");
  73. if (!htmlC.exists()) {
  74. fail("couldn't find " + getAbsolutePathOutdir()
  75. + "/pack/C.html - were there compilation errors?");
  76. }
  77. // check that the required sections exist
  78. assertTrue(htmlC.getAbsolutePath() + " should contain an "
  79. + "'INTER-TYPE METHOD SUMMARY' section",
  80. AjdocOutputChecker.containsString(htmlC, "INTER-TYPE METHOD SUMMARY"));
  81. assertTrue(htmlC.getAbsolutePath() + " should contain an "
  82. + "'INTER-TYPE FIELD SUMMARY' section",
  83. AjdocOutputChecker.containsString(htmlC, "INTER-TYPE FIELD SUMMARY"));
  84. assertTrue(htmlC.getAbsolutePath() + " should contain an "
  85. + "'INTER-TYPE CONSTRUCTOR SUMMARY' section",
  86. AjdocOutputChecker.containsString(htmlC,"INTER-TYPE CONSTRUCTOR SUMMARY"));
  87. // check the modifier information in the sections is correct
  88. String[] stringsC = { "public", "String", "pack.A" };
  89. List missing = AjdocOutputChecker.getMissingStringsInSection(htmlC,stringsC,"INTER-TYPE METHOD SUMMARY");
  90. assertEquals("There should be one missing string",1,missing.size());
  91. assertEquals("public itd methods should not have the 'public' modifier in the ajdoc",
  92. "public",missing.get(0));
  93. String[] stringsC2 = { "private" };
  94. missing = AjdocOutputChecker.getMissingStringsInSection(htmlC,stringsC2,"INTER-TYPE FIELD SUMMARY");
  95. assertTrue("the private modifier for itd methods should appear in the ajdoc ",missing.size() == 0);
  96. }
  97. /**
  98. * Test that the ITD's do not appear in as 'aspect declarations' in the
  99. * class data information.
  100. */
  101. public void testNoAspectDeclarations() throws Exception {
  102. initialiseProject("pr119453");
  103. File[] files = {
  104. new File(getAbsoluteProjectDir() + "/src/pack/C.java"),
  105. new File(getAbsoluteProjectDir() + "/src/pack/A.aj")
  106. };
  107. runAjdoc("private",files);
  108. File htmlC = new File(getAbsolutePathOutdir() + "/pack/C.html");
  109. if (htmlC == null || !htmlC.exists()) {
  110. fail("couldn't find " + getAbsolutePathOutdir()
  111. + "/pack/C.html - were there compilation errors?");
  112. }
  113. boolean b = AjdocOutputChecker.classDataSectionContainsRel(
  114. htmlC,
  115. HtmlDecorator.HtmlRelationshipKind.ASPECT_DECLARATIONS,
  116. "pack.A.C.y");
  117. assertFalse("The class data section should not have 'aspect declarations" +
  118. " pack.A.C.y' since this is an ITD",b);
  119. }
  120. }