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.

StructureViewManagerTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. * Xerox/PARC initial implementation
  11. * Helen Hawkins Converted to new interface (bug 148190)
  12. * ******************************************************************/
  13. package org.aspectj.ajde.ui;
  14. import java.io.File;
  15. import java.util.Iterator;
  16. import org.aspectj.ajde.Ajde;
  17. import org.aspectj.ajde.AjdeTestCase;
  18. import org.aspectj.asm.AsmManager;
  19. import org.aspectj.asm.IHierarchy;
  20. import org.aspectj.asm.IProgramElement;
  21. import junit.framework.TestSuite;
  22. /**
  23. * @author Mik Kersten
  24. */
  25. public class StructureViewManagerTest extends AjdeTestCase {
  26. // TODO-path
  27. private final String CONFIG_FILE_PATH = "all.lst";
  28. private final String CONFIG_FILE_PATH_2 = "inheritance.lst";
  29. private FileStructureView currentView;
  30. private final NullIdeStructureViewRenderer renderer = new NullIdeStructureViewRenderer();
  31. private File testFile;
  32. private StructureViewProperties properties;
  33. public static void main(String[] args) {
  34. junit.swingui.TestRunner.run(StructureViewManagerTest.class);
  35. }
  36. public static TestSuite suite() {
  37. TestSuite result = new TestSuite();
  38. result.addTestSuite(StructureViewManagerTest.class);
  39. return result;
  40. }
  41. public void testModelExists() {
  42. assertTrue(Ajde.getDefault().getModel().getHierarchy() != null);
  43. }
  44. public void testNotificationAfterConfigFileChange() {
  45. initialiseProject("inheritance");
  46. doBuild(CONFIG_FILE_PATH_2);
  47. renderer.setHasBeenNotified(false);
  48. assertTrue("not yet notified", !renderer.getHasBeenNotified());
  49. Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(CONFIG_FILE_PATH_2);
  50. assertTrue("notified", renderer.getHasBeenNotified());
  51. renderer.setHasBeenNotified(false);
  52. Ajde.getDefault().getBuildConfigManager().setActiveConfigFile("MumbleDoesNotExist.lst");
  53. assertTrue("notified", renderer.getHasBeenNotified());
  54. assertTrue("no structure", currentView.getRootNode().getStructureNode().getChildren().get(0) == IHierarchy.NO_STRUCTURE);
  55. }
  56. /**
  57. * @todo this should be moved to a StructureModelManager test
  58. */
  59. public void testFreshStructureModelCreation() {
  60. renderer.setHasBeenNotified(false);
  61. String modelPath = genStructureModelExternFilePath(CONFIG_FILE_PATH);
  62. openFile(modelPath).delete();
  63. Ajde.getDefault().getModel().readStructureModel(CONFIG_FILE_PATH);
  64. assertTrue("notified", renderer.getHasBeenNotified());
  65. // AMC should this be currentView, or should we recreate the root... do the latter
  66. // IProgramElement n = currentView.getRootNode().getIProgramElement();
  67. IProgramElement n = Ajde.getDefault().getModel().getHierarchy().getRoot();
  68. assertTrue("no structure",
  69. // currentView.getRootNode().getIProgramElement().getChildren().get(0)
  70. n == IHierarchy.NO_STRUCTURE);
  71. }
  72. public void testModelIntegrity() {
  73. doBuild(CONFIG_FILE_PATH);
  74. IProgramElement modelRoot = Ajde.getDefault().getModel().getHierarchy().getRoot();
  75. assertTrue("root exists", modelRoot != null);
  76. try {
  77. testModelIntegrityHelper(modelRoot);
  78. } catch (Exception e) {
  79. assertTrue(e.toString(), false);
  80. }
  81. }
  82. private void testModelIntegrityHelper(IProgramElement node) throws Exception {
  83. for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
  84. IProgramElement child = (IProgramElement) it.next();
  85. if (node == child.getParent()) {
  86. testModelIntegrityHelper(child);
  87. } else {
  88. throw new Exception("parent-child check failed for child: " + child.toString());
  89. }
  90. }
  91. }
  92. public void testNotificationAfterBuild() {
  93. renderer.setHasBeenNotified(false);
  94. doBuild(CONFIG_FILE_PATH);
  95. assertTrue("notified", renderer.getHasBeenNotified());
  96. }
  97. public void testViewCreationWithNullSourceFileAndProperties() {
  98. currentView = Ajde.getDefault().getStructureViewManager().createViewForSourceFile(null, null);
  99. assertTrue("no structure", currentView.getRootNode().getStructureNode() == IHierarchy.NO_STRUCTURE);
  100. }
  101. protected void setUp() throws Exception {
  102. super.setUp();
  103. AsmManager.forceSingletonBehaviour = true;
  104. initialiseProject("figures-coverage");
  105. doBuild(CONFIG_FILE_PATH);
  106. properties = Ajde.getDefault().getStructureViewManager().getDefaultViewProperties();
  107. // TODO-path
  108. testFile = openFile("../examples/figures-coverage/figures/Figure.java");
  109. currentView = Ajde.getDefault().getStructureViewManager().createViewForSourceFile(testFile.getAbsolutePath(), properties);
  110. currentView.setRenderer(renderer);
  111. }
  112. protected void tearDown() throws Exception {
  113. super.tearDown();
  114. AsmManager.forceSingletonBehaviour = false;
  115. }
  116. }