aboutsummaryrefslogtreecommitdiffstats
path: root/util/testsrc
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-16 17:09:36 +0000
committerwisberg <wisberg>2002-12-16 17:09:36 +0000
commitc3300283ecc397d26ad9dfe31d1710ec45db2af0 (patch)
treee9acb7f3d33c1499975cec9ef3cc7ea151078344 /util/testsrc
parent3cde920c3f7eb8241bf569007e25225d80b43c0f (diff)
downloadaspectj-c3300283ecc397d26ad9dfe31d1710ec45db2af0.tar.gz
aspectj-c3300283ecc397d26ad9dfe31d1710ec45db2af0.zip
initial version
Diffstat (limited to 'util/testsrc')
-rw-r--r--util/testsrc/UtilModuleTests.java30
-rw-r--r--util/testsrc/org/aspectj/util/FileUtilTest.java377
-rw-r--r--util/testsrc/org/aspectj/util/LangUtilTest.java266
-rw-r--r--util/testsrc/org/aspectj/util/UtilTests.java32
4 files changed, 705 insertions, 0 deletions
diff --git a/util/testsrc/UtilModuleTests.java b/util/testsrc/UtilModuleTests.java
new file mode 100644
index 000000000..ddb1da5f5
--- /dev/null
+++ b/util/testsrc/UtilModuleTests.java
@@ -0,0 +1,30 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+// default package
+
+import junit.framework.*;
+import junit.framework.Test;
+
+public class UtilModuleTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(UtilModuleTests.class.getName());
+ suite.addTest(org.aspectj.util.UtilTests.suite());
+ return suite;
+ }
+
+ public UtilModuleTests(String name) { super(name); }
+
+}
diff --git a/util/testsrc/org/aspectj/util/FileUtilTest.java b/util/testsrc/org/aspectj/util/FileUtilTest.java
new file mode 100644
index 000000000..7cda1692c
--- /dev/null
+++ b/util/testsrc/org/aspectj/util/FileUtilTest.java
@@ -0,0 +1,377 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.util;
+
+import java.io.EOFException;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+/**
+ *
+ */
+public class FileUtilTest extends TestCase {
+ public static final String[] NONE = new String[0];
+
+ boolean log = false;
+
+ /** List of File files or directories to delete when exiting */
+ final ArrayList tempFiles;
+ public FileUtilTest(String s) {
+ super(s);
+ tempFiles = new ArrayList();
+ }
+
+ public static void main(String[] args) {
+ TestRunner.main(new String[] {"org.aspectj.util.FileUtilUT"});
+ }
+
+ public void tearDown() {
+ for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) {
+ File dir = (File) iter.next();
+ FileUtil.deleteContents(dir);
+ dir.delete();
+ iter.remove();
+ }
+ }
+
+ public void testDirCopySubdirs() throws IOException { // XXX dir diff
+ File srcDir = new File("src");
+ File destDir = FileUtil.getTempDir("testDirCopySubdirs");
+ FileUtil.copyDir(srcDir, destDir);
+ FileUtil.deleteContents(destDir);
+ destDir.delete();
+ }
+
+ public void testDirCopySubdirsSuffix() throws IOException { // XXX dir diff
+ File srcDir = new File("src");
+ File destDir = FileUtil.getTempDir("testDirCopySubdirsSuffix");
+ FileUtil.copyDir(srcDir, destDir, ".java", ".aj");
+
+ FileUtil.deleteContents(destDir);
+ destDir.delete();
+ }
+
+ public void testGetURL() {
+ String[] args = new String[]
+ {".", "../util/testdata", "../lib/test/aspectjrt.jar" };
+ for (int i = 0; i < args.length; i++) {
+ checkGetURL(args[i]);
+ }
+ }
+
+ /**
+ * Method checkGetURL.
+ * @param string
+ * @param uRL
+ */
+ private void checkGetURL(String arg) {
+ assertTrue(null != arg);
+ File f = new File(arg);
+ assertTrue(null != f);
+ URL url = FileUtil.getFileURL(f);
+ assertTrue(null != url);
+ log("url " + url);
+ if (!f.exists()) {
+ log("not exist " + f);
+ } else if (f.isDirectory()) {
+ log("directory " + f);
+ } else {
+ log(" file " + f);
+ InputStream in = null;
+ try {
+ in = url.openStream();
+ } catch (IOException e) {
+ assertTrue("IOException: " + e, false);
+ } finally {
+ if (null != in) {
+ try { in.close(); }
+ catch (IOException e) {}
+ }
+ }
+ }
+ }
+
+
+ public void testGetTempDir() {
+ boolean pass = true;
+ boolean delete = true;
+ checkGetTempDir("parent", null, pass, delete);
+ checkGetTempDir(null, "child", pass, delete);
+ tempFiles.add(checkGetTempDir("parent", "child", pass, !delete));
+ tempFiles.add(checkGetTempDir("parent", "child", pass, !delete));
+ tempFiles.add(checkGetTempDir("parent", "child", pass, !delete));
+ }
+
+ File checkGetTempDir(String parent, String child, boolean ok, boolean delete) {
+ File parentDir = FileUtil.getTempDir(parent);
+ assertTrue("unable to create " + parent, null != parentDir);
+ File dir = FileUtil.makeNewChildDir(parentDir, child);
+ log("parent=" + parent + " child=" + child + " -> " + dir);
+ assertTrue("dir: " + dir, ok == (dir.canWrite() && dir.isDirectory()));
+ if (delete) {
+ dir.delete();
+ }
+ return dir;
+ }
+
+ public void testRandomFileString() {
+ ArrayList results = new ArrayList();
+ for (int i = 0; i < 1000; i++) {
+ String s = FileUtil.randomFileString();
+ if (results.contains(s)) {
+ System.err.println("warning: got duplicate at iteration " + i);
+ }
+ results.add(s);
+// System.err.print(" " + s);
+// if (0 == (i % 5)) {
+// System.err.println("");
+// }
+ }
+ }
+
+ public void testNormalizedPath() {
+ File tempFile = null;
+ try {
+ tempFile = File.createTempFile("FileUtilTest", "tmp");
+ } catch (IOException e) {
+ System.err.println("aborting test - unable to create temp file");
+ }
+ File parentDir = tempFile.getParentFile();
+ String tempFilePath = FileUtil.normalizedPath(tempFile, parentDir);
+ assertEquals(tempFile.getName(), tempFilePath);
+ }
+
+ public void testFileToClassName() {
+
+ File basedir = new File("/base/dir");
+ File classFile = new File(basedir, "foo/Bar.class");
+ assertEquals("foo.Bar", FileUtil.fileToClassName(basedir, classFile));
+
+ classFile = new File(basedir, "foo\\Bar.class");
+ assertEquals("foo.Bar", FileUtil.fileToClassName(basedir, classFile));
+
+ assertEquals("Bar", FileUtil.fileToClassName(null, classFile));
+
+ classFile = new File("/home/classes/org/aspectj/lang/JoinPoint.class");
+ assertEquals("org.aspectj.lang.JoinPoint", FileUtil.fileToClassName(null, classFile));
+
+ classFile = new File("/home/classes/com/sun/tools/Javac.class");
+ assertEquals("com.sun.tools.Javac", FileUtil.fileToClassName(null, classFile));
+ }
+
+ public void testDeleteContents() {
+ File f = new File("testdata/foo");
+ f.mkdirs();
+ File g = new File(f, "bar");
+ g.mkdirs();
+ File h = new File(g, "bash");
+ h.mkdirs();
+ int d = FileUtil.deleteContents(f);
+ assertTrue(0 == d);
+ assertTrue(0 == f.list().length);
+ f.delete();
+ assertTrue(!f.exists());
+ }
+
+ public void testLineSeek() {
+ String path = "testdata/testLineSeek";
+ File file = new File(path);
+ path = file.getPath();
+ String contents = "0123456789" + LangUtil.EOL;
+ contents += contents;
+ FileUtil.writeAsString(file, contents);
+ tempFiles.add(file);
+ List sourceList = new ArrayList();
+ sourceList.add(file.getPath());
+
+ final ArrayList errors = new ArrayList();
+ final PrintStream errorSink = new PrintStream(System.err, true) {
+ public void println(String error) {
+ errors.add(error);
+ }
+ };
+ for (int i = 0; i < 10; i++) {
+ List result = FileUtil.lineSeek(""+i, sourceList, true, errorSink);
+ assertEquals(2, result.size());
+ assertEquals(path + ":1:" + i, result.get(0));
+ assertEquals(path + ":2:" + i, result.get(1));
+ if (!LangUtil.isEmpty(errors)) { // XXX prefer fast-fail?
+ assertTrue("errors: " + errors, false);
+ }
+ }
+
+ }
+ public void testLineSeekMore() {
+ final int MAX = 3; // 1..10
+ final String prefix = new File("testdata/testLineSeek").getPath();
+ // setup files 0..MAX with 2*MAX lines
+ String[] sources = new String[MAX];
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < sources.length; i++) {
+ sources[i] = new File(prefix + i).getPath();
+ sb.append("not matched");
+ sb.append(LangUtil.EOL);
+ sb.append("0123456789");
+ sb.append(LangUtil.EOL);
+ }
+ final String contents = sb.toString();
+ for (int i = 0; i < sources.length; i++) {
+ File file = new File(sources[i]);
+ FileUtil.writeAsString(file, contents);
+ tempFiles.add(file);
+ }
+ // now test
+ final ArrayList errors = new ArrayList();
+ final PrintStream errorSink = new PrintStream(System.err, true) {
+ public void println(String error) {
+ errors.add(error);
+ }
+ };
+ List sourceList = new ArrayList();
+ sourceList.addAll(Arrays.asList(sources));
+ sourceList = Collections.unmodifiableList(sourceList);
+ for (int k = 0; k < sources.length; k++) {
+ List result = FileUtil.lineSeek(""+k, sourceList, true, errorSink);
+ // number k found in every other line of every file at index k
+ Iterator iter = result.iterator();
+ for (int i = 0; i < MAX; i++) { // for each file
+ for (int j = 1; j < (MAX+1); j++) { // for every other line
+ assertTrue(iter.hasNext());
+ assertEquals(prefix + i + ":" + 2*j + ":" + k, iter.next());
+ }
+ }
+ if (!LangUtil.isEmpty(errors)) { // XXX prefer fast-fail?
+ assertTrue("errors: " + errors, false);
+ }
+ }
+ }
+
+ public void testDirCopyNoSubdirs() throws IOException {
+ String[] srcFiles = new String[] { "one.java", "two.java", "three.java"};
+ String[] destFiles = new String[] { "three.java", "four.java", "five.java" };
+ String[] allFiles = new String[]
+ { "one.java", "two.java", "three.java", "four.java", "five.java" };
+ File srcDir = makeDir("FileUtilUT_srcDir", srcFiles);
+ File destDir = makeDir("FileUtilUT_destDir", destFiles);
+ assertTrue(null != srcDir);
+ assertTrue(null != destDir);
+ assertTrue(NONE == dirContains(srcDir, srcFiles));
+ assertTrue(NONE == dirContains(destDir, destFiles));
+
+ FileUtil.copyDir(srcDir, destDir);
+ String[] resultOne = dirContains(destDir, allFiles);
+ FileUtil.copyDir(srcDir, destDir);
+ String[] resultTwo = dirContains(destDir, allFiles);
+
+ FileUtil.deleteContents(srcDir);
+ FileUtil.deleteContents(destDir);
+ srcDir.delete();
+ destDir.delete();
+
+ assertTrue(NONE == resultOne);
+ assertTrue(NONE == resultTwo);
+ }
+
+ public void testDirCopyNoSubdirsWithSuffixes() throws IOException {
+ String[] srcFiles = new String[] { "one.java", "two.java", "three.java"};
+ String[] destFiles = new String[] { "three.java", "four.java", "five.java" };
+ String[] allFiles = new String[]
+ { "one.aj", "two.aj", "three.aj", "three.java", "four.java", "five.java" };
+ File srcDir = makeDir("FileUtilUT_srcDir", srcFiles);
+ File destDir = makeDir("FileUtilUT_destDir", destFiles);
+ assertTrue(null != srcDir);
+ assertTrue(null != destDir);
+ assertTrue(NONE == dirContains(srcDir, srcFiles));
+ assertTrue(NONE == dirContains(destDir, destFiles));
+
+ FileUtil.copyDir(srcDir, destDir, ".java", ".aj");
+ String[] resultOne = dirContains(destDir, allFiles);
+ FileUtil.copyDir(srcDir, destDir, ".java", ".aj");
+ String[] resultTwo = dirContains(destDir, allFiles);
+
+ FileUtil.deleteContents(srcDir);
+ FileUtil.deleteContents(destDir);
+ srcDir.delete();
+ destDir.delete();
+
+ assertTrue(NONE == resultOne);
+ assertTrue(NONE == resultTwo);
+ }
+
+ public void testDirCopySubdirsSuffixRoundTrip() throws IOException {
+ final File srcDir = new File("src");
+ final File one = FileUtil.getTempDir("testDirCopySubdirsSuffixRoundTrip_1");
+ final File two = FileUtil.getTempDir("testDirCopySubdirsSuffixRoundTrip_2");
+ FileUtil.copyDir(srcDir, one); // no selection
+ FileUtil.copyDir(two, one, ".java", ".aj"); // only .java files
+ FileUtil.copyDir(one, two, ".aj", ".java");
+
+ FileUtil.deleteContents(one);
+ one.delete();
+ FileUtil.deleteContents(two);
+ two.delete();
+ }
+
+ /**
+ * Verify that dir contains files,
+ * and return the names of other files in dir.
+ * @return the contents of dir after excluding files
+ * or NONE if none
+ * @throws AssertionFailedError if any files are not in dir
+ */
+ String[] dirContains(File dir, final String[] files) {
+ final ArrayList toFind = new ArrayList(Arrays.asList(files));
+ FilenameFilter filter = new FilenameFilter() {
+ public boolean accept(File d, String name) {
+ return !toFind.remove(name);
+ }
+ };
+ String[] result = dir.list(filter);
+ if (0 < toFind.size()) {
+ assertTrue(""+toFind, false);
+ }
+ return (result.length == 0 ? NONE : result);
+ }
+
+ File makeDir(String loc, String[] files) throws IOException {
+ File d = new File(loc);
+ d.mkdirs();
+ assertTrue(d.exists());
+ assertTrue(d.canWrite());
+ for (int i = 0; i < files.length; i++) {
+ File f = new File(d, files[i]);
+ assertTrue(files[i], f.createNewFile());
+ }
+ return d;
+ }
+
+ private void log(String s) {
+ if (log) {
+ System.err.println(s);
+ }
+ }
+}
diff --git a/util/testsrc/org/aspectj/util/LangUtilTest.java b/util/testsrc/org/aspectj/util/LangUtilTest.java
new file mode 100644
index 000000000..98aab88ba
--- /dev/null
+++ b/util/testsrc/org/aspectj/util/LangUtilTest.java
@@ -0,0 +1,266 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+package org.aspectj.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class LangUtilTest extends TestCase {
+
+ public LangUtilTest(String name) {
+ super(name);
+ }
+
+ /** @see LangUtil.extractOptions(String[], String[], int[], List) */
+ public void testExtractOptions() {
+ ArrayList extracted = new ArrayList();
+ String[] args = new String[] { "-d", "classes", "-classpath", "foo.jar", "-verbose", "Bar.java" };
+ String[] validOptions = new String[] { "-classpath", "-d", "-verbose", "-help" };
+ int[] optionArgs = new int[] { 1, 1, 0, 0 };
+ String[] result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted);
+ String resultString = "" + Arrays.asList(result);
+ String EXP = "[Bar.java]";
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ EXP = "[-d, classes, -classpath, foo.jar, -verbose]";
+ resultString = "" + extracted;
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+
+ // no input, no output
+ extracted.clear();
+ args = new String[] {};
+ result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted);
+ resultString = "" + Arrays.asList(result);
+ EXP = "[]";
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ resultString = "" + extracted;
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+
+ // one input, nothing extracted
+ extracted.clear();
+ args = new String[] {"Bar.java"};
+ result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted);
+ resultString = "" + Arrays.asList(result);
+ EXP = "[Bar.java]";
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ EXP = "[]";
+ resultString = "" + extracted;
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+
+ // one input, extracted
+ extracted.clear();
+ args = new String[] {"-verbose"};
+ result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted);
+ resultString = "" + Arrays.asList(result);
+ EXP = "[]";
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ EXP = "[-verbose]";
+ resultString = "" + extracted;
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+
+ // ------- booleans
+ validOptions = new String[] { "-help", "-verbose" };
+ optionArgs = null;
+
+ // one input, extracted
+ extracted.clear();
+ args = new String[] {"-verbose"};
+ result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted);
+ resultString = "" + Arrays.asList(result);
+ EXP = "[]";
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ EXP = "[-verbose]";
+ resultString = "" + extracted;
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+
+ // one input, not extracted
+ extracted.clear();
+ args = new String[] {"Bar.java"};
+ result = LangUtil.extractOptions(args, validOptions, optionArgs, extracted);
+ resultString = "" + Arrays.asList(result);
+ EXP = "[Bar.java]";
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ EXP = "[]";
+ resultString = "" + extracted;
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ }
+
+ /** @see LangUtil.extractOptions(String[], String[][]) */
+ public void testExtractOptionsArrayCollector() {
+ String[] args = new String[] { "-d", "classes", "-classpath", "foo.jar", "-verbose", "Bar.java" };
+ String[][] OPTIONS = new String[][] {
+ new String[] {"-classpath", null },
+ new String[] {"-d", null},
+ new String[] {"-verbose"},
+ new String[] { "-help" }};
+
+ String[][] options = LangUtil.copyStrings(OPTIONS);
+
+ String[] result = LangUtil.extractOptions(args, options);
+ String resultString = "" + Arrays.asList(result);
+ String EXP = "[Bar.java]";
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ assertTrue("-verbose".equals(options[2][0]));
+ assertTrue("foo.jar".equals(options[0][1]));
+ assertTrue("classes".equals(options[1][1]));
+ assertTrue("-classpath".equals(options[0][0]));
+ assertTrue("-d".equals(options[1][0]));
+ assertTrue(null == options[3][0]);
+
+ // get args back, no options set
+ args = new String[] { "Bar.java" };
+ options = LangUtil.copyStrings(OPTIONS);
+
+ result = LangUtil.extractOptions(args, options);
+ resultString = "" + Arrays.asList(result);
+ EXP = "[Bar.java]";
+ assertTrue(resultString + " != " + EXP, resultString.equals(EXP));
+ assertTrue(null == options[0][0]);
+ assertTrue(null == options[1][0]);
+ assertTrue(null == options[2][0]);
+ assertTrue(null == options[3][0]);
+ }
+
+ public void testOptionVariants() {
+ String[] NONE = new String[0];
+ String[] one = new String[] {"-1"};
+ String[] two = new String[] {"-2"};
+ String[] three= new String[] {"-3"};
+ String[] both = new String[] {"-1", "-2" };
+ String[] oneB = new String[] {"-1-"};
+ String[] bothB = new String[] {"-1-", "-2-" };
+ String[] onetwoB = new String[] {"-1", "-2-" };
+ String[] oneBtwo = new String[] {"-1-", "-2" };
+ String[] threeB = new String[] {"-1-", "-2-", "-3-"};
+ String[] athreeB = new String[] {"a", "-1-", "-2-", "-3-"};
+ String[] threeaB = new String[] {"-1-", "a", "-2-", "-3-"};
+
+ checkOptionVariants(NONE, new String[][] { NONE });
+ checkOptionVariants(one, new String[][] { one });
+ checkOptionVariants(both, new String[][] { both });
+ checkOptionVariants(oneB, new String[][] { NONE, one });
+ checkOptionVariants(bothB, new String[][] { NONE, one, new String[] {"-2"}, both });
+ checkOptionVariants(onetwoB, new String[][] { one, new String[] {"-1", "-2"}});
+ checkOptionVariants(oneBtwo, new String[][] { two, new String[] {"-1", "-2"}});
+ checkOptionVariants(threeB, new String[][]
+ {
+ NONE,
+ one,
+ two,
+ new String[] {"-1", "-2"},
+ three,
+ new String[] {"-1", "-3"},
+ new String[] {"-2", "-3"},
+ new String[] {"-1", "-2", "-3"}
+ });
+ checkOptionVariants(athreeB, new String[][]
+ {
+ new String[] {"a"},
+ new String[] {"a", "-1"},
+ new String[] {"a", "-2"},
+ new String[] {"a", "-1", "-2"},
+ new String[] {"a", "-3"},
+ new String[] {"a", "-1", "-3"},
+ new String[] {"a", "-2", "-3"},
+ new String[] {"a", "-1", "-2", "-3"}
+ });
+ checkOptionVariants(threeaB, new String[][]
+ {
+ new String[] {"a"},
+ new String[] {"-1", "a"},
+ new String[] {"a", "-2"},
+ new String[] {"-1", "a", "-2"},
+ new String[] {"a", "-3"},
+ new String[] {"-1", "a", "-3"},
+ new String[] {"a", "-2", "-3"},
+ new String[] {"-1", "a", "-2", "-3"}
+ });
+ }
+
+ void checkOptionVariants(String[] options, String[][] expected) {
+ String[][] result = LangUtil.optionVariants(options);
+ if (expected.length != result.length) {
+ assertTrue("exp=" + expected.length + " actual=" + result.length, false);
+ }
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals(""+i,
+ "" + Arrays.asList(expected[i]),
+ "" + Arrays.asList(result[i]));
+ }
+ }
+
+ /** @see XMLWriterTest#testUnflattenList() */
+ public void testCommaSplit() {
+ checkCommaSplit("", new String[] {""});
+ checkCommaSplit("1", new String[] {"1"});
+ checkCommaSplit(" 1 2 ", new String[] {"1 2"});
+ checkCommaSplit(" 1 , 2 ", new String[] {"1", "2"});
+ checkCommaSplit("1,2,3,4", new String[] {"1", "2", "3", "4"});
+ }
+
+ void checkCommaSplit(String input, String[] expected) {
+ List actual = LangUtil.commaSplit(input);
+ String a = "" + actual;
+ String e = "" + Arrays.asList(expected);
+ assertTrue(e + "==" + a, e.equals(a));
+ }
+
+ public void testElideEndingLines() {
+ StringBuffer stackBuffer = LangUtil.stackToString(new RuntimeException(""), true);
+ LangUtil.elideEndingLines(LangUtil.StringChecker.TEST_PACKAGES, stackBuffer, 100);
+ String result = stackBuffer.toString();
+ if (-1 == result.indexOf("(... ")) {
+ // brittle - will fail under different top-level drivers
+ String m = "when running under eclipse or Ant, expecting (... in trace: ";
+ assertTrue( m + result, false);
+ }
+
+ stackBuffer = new StringBuffer("java.lang.RuntimeException: unimplemented"
+ + "\n at org.aspectj.ajdt.internal.core.builder.EclipseUnwovenClassFile.writeWovenBytes(EclipseUnwovenClassFile.java:59)"
+ + "\n at org.aspectj.bcweaver.bcel.BcelWeaver.dump(BcelWeaver.java:271)"
+ + "\n at org.aspectj.bcweaver.bcel.BcelWeaver.weave(BcelWeaver.java:233)"
+ + "\n at org.aspectj.bcweaver.bcel.BcelWeaver.weave(BcelWeaver.java:198)"
+ + "\n at org.aspectj.ajdt.internal.core.builder.AjBuildManager.weaveAndGenerateClassFiles(AjBuildanager.java:230)"
+ + "\n at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:50)"
+ + "\n at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:42)"
+ + "\n at org.aspectj.testing.harness.bridge.CompilerRun.run(CompilerRun.java:222)"
+ + "\n at org.aspectj.testing.run.Runner.runPrivate(Runner.java:363)"
+ + "\n at org.aspectj.testing.run.Runner.runChild(Runner.java:167)"
+ + "\n at org.aspectj.testing.run.Runner.runChild(Runner.java:126)"
+ + "\n at org.aspectj.testing.run.Runner$IteratorWrapper.run(Runner.java:441)"
+ + "\n at org.aspectj.testing.run.Runner.runPrivate(Runner.java:363)"
+ + "\n at org.aspectj.testing.run.Runner.runChild(Runner.java:167)"
+ + "\n at org.aspectj.testing.run.Runner.runChild(Runner.java:126)"
+ + "\n at org.aspectj.testing.run.Runner$IteratorWrapper.run(Runner.java:441)"
+ + "\n at org.aspectj.testing.run.Runner.runPrivate(Runner.java:363)"
+ + "\n at org.aspectj.testing.run.Runner.run(Runner.java:114)"
+ + "\n at org.aspectj.testing.run.Runner.run(Runner.java:105)"
+ + "\n at org.aspectj.testing.run.Runner.runIterator(Runner.java:228)"
+ + "\n at org.aspectj.testing.drivers.Harness.run(Harness.java:254)"
+ + "\n at org.aspectj.testing.drivers.Harness.runMain(Harness.java:217)"
+ + "\n at org.aspectj.testing.drivers.Harness.main(Harness.java:99)"
+ + "\n at org.aspectj.testing.Harness.main(Harness.java:37)"
+ + "\n clip me");
+
+ LangUtil.elideEndingLines(LangUtil.StringChecker.TEST_PACKAGES, stackBuffer, 25);
+ result = stackBuffer.toString();
+ assertTrue(result, -1 != result.indexOf("(... "));
+ assertTrue(result, -1 == result.indexOf("org.aspectj.testing"));
+ }
+}
diff --git a/util/testsrc/org/aspectj/util/UtilTests.java b/util/testsrc/org/aspectj/util/UtilTests.java
new file mode 100644
index 000000000..7dc577941
--- /dev/null
+++ b/util/testsrc/org/aspectj/util/UtilTests.java
@@ -0,0 +1,32 @@
+/* *******************************************************************
+ * Copyright (c) 1999-2001 Xerox Corporation,
+ * 2002 Palo Alto Research Center, Incorporated (PARC).
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Xerox/PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.util;
+
+import junit.framework.*;
+
+public class UtilTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(UtilTests.class.getName());
+ //$JUnit-BEGIN$
+ suite.addTestSuite(FileUtilTest.class);
+ suite.addTestSuite(LangUtilTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+ public UtilTests(String name) { super(name); }
+
+}