Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SavedModelConsistencyTests.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Mik Kersten initial implementation
  11. * Helen Hawkins Converted to new interface (bug 148190)
  12. * ******************************************************************/
  13. package org.aspectj.ajde.core.tests.model;
  14. import java.io.File;
  15. import java.util.ArrayList;
  16. import java.util.Collections;
  17. import java.util.List;
  18. import org.aspectj.ajde.core.AjdeCoreTestCase;
  19. import org.aspectj.ajde.core.TestCompilerConfiguration;
  20. import org.aspectj.ajde.core.TestMessageHandler;
  21. import org.aspectj.asm.AsmManager;
  22. import org.aspectj.asm.HierarchyWalker;
  23. import org.aspectj.asm.IHierarchy;
  24. import org.aspectj.asm.IProgramElement;
  25. public class SavedModelConsistencyTests extends AjdeCoreTestCase {
  26. private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" };
  27. private TestMessageHandler handler;
  28. private TestCompilerConfiguration compilerConfig;
  29. protected void setUp() throws Exception {
  30. super.setUp();
  31. initialiseProject("coverage");
  32. handler = (TestMessageHandler) getCompiler().getMessageHandler();
  33. compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
  34. compilerConfig.setProjectSourceFiles(getSourceFileList(files));
  35. // In order to get a model on the disk to read in, do a build with the right flag set !
  36. try {
  37. AsmManager.dumpModelPostBuild = true;
  38. doBuild();
  39. } finally {
  40. AsmManager.dumpModelPostBuild = false;
  41. }
  42. assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
  43. }
  44. protected void tearDown() throws Exception {
  45. super.tearDown();
  46. handler = null;
  47. compilerConfig = null;
  48. }
  49. public void testInterfaceIsSameInBoth() {
  50. AsmManager asm = AsmManager.createNewStructureModel(Collections.EMPTY_MAP);
  51. asm.readStructureModel(getAbsoluteProjectDir());
  52. IHierarchy model = asm.getHierarchy();
  53. assertTrue("model exists", model != null);
  54. assertTrue("root exists", model.getRoot() != null); // TODO-path
  55. File testFile = openFile("ModelCoverage.java");
  56. assertTrue("Expected " + testFile.getAbsolutePath() + " to exist, but it did not", testFile.exists());
  57. IProgramElement nodePreBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);
  58. doBuild();
  59. assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
  60. IProgramElement nodePostBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);
  61. assertTrue(
  62. "Nodes should be identical: Prebuild kind = " + nodePreBuild.getKind() + " Postbuild kind = "
  63. + nodePostBuild.getKind(), nodePreBuild.getKind().equals(nodePostBuild.getKind()));
  64. }
  65. public void testModelIsSamePreAndPostBuild() {
  66. AsmManager asm = AsmManager.createNewStructureModel(Collections.EMPTY_MAP);
  67. asm.readStructureModel(getAbsoluteProjectDir());
  68. // AsmManager.getDefault().readStructureModel(getAbsoluteProjectDir());
  69. IHierarchy model = asm.getHierarchy();
  70. assertTrue("model exists", model != null);
  71. final List<IProgramElement.Kind> preBuildKinds = new ArrayList<IProgramElement.Kind>();
  72. HierarchyWalker walker = new HierarchyWalker() {
  73. public void preProcess(IProgramElement node) {
  74. preBuildKinds.add(node.getKind());
  75. }
  76. };
  77. asm.getHierarchy().getRoot().walk(walker);
  78. assertFalse("Expected there to be build kinds but didn't " + "find any", preBuildKinds.isEmpty());
  79. doBuild();
  80. assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
  81. final List<IProgramElement.Kind> postBuildKinds = new ArrayList<IProgramElement.Kind>();
  82. HierarchyWalker walker2 = new HierarchyWalker() {
  83. public void preProcess(IProgramElement node) {
  84. postBuildKinds.add(node.getKind());
  85. }
  86. };
  87. asm.getHierarchy().getRoot().walk(walker2);
  88. assertFalse("Expected there to be build kinds but didn't " + "find any", preBuildKinds.isEmpty());
  89. assertTrue("Lists should be the same: PRE" + preBuildKinds.toString() + " POST" + postBuildKinds.toString(),
  90. preBuildKinds.equals(postBuildKinds));
  91. }
  92. }