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.

LstBuildConfigManagerTest.java 5.9KB

21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * Xerox/PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajde.internal;
  13. import java.io.*;
  14. import java.util.*;
  15. import junit.framework.TestSuite;
  16. import org.aspectj.ajde.*;
  17. import org.aspectj.ajde.NullIdeTaskListManager.SourceLineTask;
  18. import org.aspectj.ajde.ui.BuildConfigModel;
  19. import org.aspectj.ajde.ui.internal.AjcBuildOptions;
  20. import org.aspectj.bridge.Message;
  21. public class LstBuildConfigManagerTest extends AjdeTestCase {
  22. private AjcBuildOptions buildOptions = null;
  23. private BuildConfigManager buildConfigManager = new LstBuildConfigManager();
  24. private LstBuildConfigFileUpdater fileUpdater = new LstBuildConfigFileUpdater();
  25. public LstBuildConfigManagerTest(String name) {
  26. super(name);
  27. }
  28. public static void main(String[] args) {
  29. junit.swingui.TestRunner.run(LstBuildConfigManagerTest.class);
  30. }
  31. public static TestSuite suite() {
  32. TestSuite result = new TestSuite();
  33. result.addTestSuite(LstBuildConfigManagerTest.class);
  34. return result;
  35. }
  36. public void testConfigParserErrorMessages() {
  37. doSynchronousBuild("dir-entry.lst");
  38. List messages = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
  39. NullIdeTaskListManager.SourceLineTask message = (NullIdeTaskListManager.SourceLineTask)messages.get(0);
  40. assertEquals(message.getContainedMessage().getSourceLocation().getSourceFile().getAbsolutePath(), openFile("dir-entry.lst").getAbsolutePath());
  41. doSynchronousBuild("bad-injar.lst");
  42. messages = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
  43. message = (NullIdeTaskListManager.SourceLineTask)messages.get(0);
  44. assertTrue(message.getContainedMessage().getMessage().indexOf("bad inpath") != -1);
  45. }
  46. public void testErrorMessages() throws IOException {
  47. doSynchronousBuild("invalid-entry.lst");
  48. assertTrue("compile failed", testerBuildListener.getBuildSucceeded());
  49. List messages = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
  50. SourceLineTask message = (SourceLineTask)messages.get(0);
  51. assertTrue(message.getContainedMessage().getMessage(), message.getContainedMessage().getMessage().indexOf("aaa.bbb") != -1);
  52. }
  53. public void testNonExistentConfigFile() throws IOException {
  54. File file = openFile("mumbleDoesNotExist.lst");
  55. assertTrue("valid non-existing file", !file.exists());
  56. BuildConfigModel model = buildConfigManager.buildModel(file.getCanonicalPath());
  57. assertTrue("root: " + model.getRoot(), model.getRoot() != null);
  58. }
  59. public void testFileRelativePathSameDir() throws IOException {
  60. File file = openFile("file-relPath-sameDir.lst");
  61. BuildConfigModel model = buildConfigManager.buildModel(file.getCanonicalPath());
  62. assertTrue("single file", true);
  63. }
  64. private void verifyFile(String configFile, String fileContents) {
  65. StringTokenizer st = new StringTokenizer(fileContents, ";");
  66. BuildConfigModel model1 = buildConfigManager.buildModel(configFile);
  67. File testFile = new File(configFile + "-test.lst");
  68. model1.setSourceFile(testFile.getPath());
  69. buildConfigManager.writeModel(model1);
  70. List newList = fileUpdater.readConfigFile(testFile.getPath());
  71. testFile.delete();
  72. assertTrue("contents: " + newList, verifyLists(st, newList));
  73. }
  74. private boolean verifyLists(StringTokenizer st, List list) {
  75. Iterator it = list.iterator();
  76. while (st.hasMoreElements()) {
  77. String s1 = (String)st.nextElement();
  78. String s2 = (String)it.next();
  79. if (!s1.equals(s2)) return false;
  80. }
  81. if (it.hasNext()) {
  82. return false;
  83. } else {
  84. return true;
  85. }
  86. }
  87. protected void setUp() throws Exception {
  88. super.setUp("LstBuildConfigManagerTest");
  89. }
  90. protected void tearDown() throws Exception {
  91. super.tearDown();
  92. }
  93. private static final String WILDCARDS_FILE = "C:/Dev/aspectj/tests/ajde/examples/figures-coverage/test-config.lst";
  94. private static final String BAD_PATHS_FILE = "C:/Dev/aspectj/tests/ajde/examples/figures-coverage/test-error.lst";
  95. private static final String INCLUDES_FILE = "C:/Dev/aspectj/tests/ajde/examples/spacewar/spacewar/demo.lst";
  96. private static final String WILDCARDS_FILE_CONTENTS;
  97. private static final String BAD_PATHS_FILE_CONTENTS;
  98. private static final String INCLUDES_FILE_CONTENTS;
  99. static {
  100. WILDCARDS_FILE_CONTENTS =
  101. "figures/Debug.java;" +
  102. "figures/Figure.java;" +
  103. "figures/FigureElement.java;" +
  104. "figures/Main.java;" +
  105. "figures/composites/Line.java;" +
  106. "figures/composites/Square.java;" +
  107. "figures/primitives/planar/Point.java;" +
  108. "figures/primitives/solid/SolidPoint.java;";
  109. BAD_PATHS_FILE_CONTENTS = WILDCARDS_FILE_CONTENTS;
  110. INCLUDES_FILE_CONTENTS =
  111. "../coordination/Condition.java;" +
  112. "../coordination/CoordinationAction.java;" +
  113. "../coordination/Coordinator.java;" +
  114. "../coordination/Exclusion.java;" +
  115. "../coordination/MethodState.java;" +
  116. "../coordination/Mutex.java;" +
  117. "../coordination/Selfex.java;" +
  118. "../coordination/TimeoutException.java;" +
  119. "Bullet.java;" +
  120. "Display.java;" +
  121. "Display1.java;" +
  122. "Display2.java;" +
  123. "EnergyPacket.java;" +
  124. "EnergyPacketProducer.java;" +
  125. "EnsureShipIsAlive.java;" +
  126. "Game.java;" +
  127. "GameSynchronization.java;" +
  128. "Pilot.java;" +
  129. "Player.java;" +
  130. "Registry.java;" +
  131. "RegistrySynchronization.java;" +
  132. "Robot.java;" +
  133. "SWFrame.java;" +
  134. "Ship.java;" +
  135. "SpaceObject.java;" +
  136. "Timer.java;";
  137. }
  138. }
  139. //public void testWildcards() {
  140. // verifyFile(WILDCARDS_FILE, WILDCARDS_FILE_CONTENTS);
  141. //}
  142. //
  143. //public void testIncludes() {
  144. // verifyFile(INCLUDES_FILE, INCLUDES_FILE_CONTENTS);
  145. //}