package aQute.lib.io;

import java.io.File;

import junit.framework.TestCase;

public class IOTest extends TestCase {

	public void testSafeFileName() {
		if (IO.isWindows()) {
			assertEquals("abc%def", IO.toSafeFileName("abc:def"));
			assertEquals("%abc%def%", IO.toSafeFileName("<abc:def>"));
		} else {
			assertEquals("abc%def", IO.toSafeFileName("abc/def"));
			assertEquals("<abc%def>", IO.toSafeFileName("<abc/def>"));
		}
	}

	public void testFilesetCopy() throws Exception {
		File destDir = new File("generated/fileset-copy-test");

		if (destDir.exists()) {
			IO.delete(destDir);
			assertFalse(destDir.exists());
		}

		assertTrue(destDir.mkdirs());

		File srcDir = new File("testresources/fileset");

		IO.copy(srcDir, destDir);

		assertTrue(new File(destDir, "a/b/c/d/e/f/a.abc").exists());
		assertTrue(new File(destDir, "a/b/c/c.abc").exists());
		assertTrue(new File(destDir, "root").exists());
	}

	public void testDestDirIsChildOfSource() throws Exception {
		File parentDir = new File("generated/test/parentDir");

		if (parentDir.exists()) {
			IO.delete(parentDir);
			assertFalse(parentDir.exists());
		}

		assertTrue(parentDir.mkdirs());

		File childDir = new File("generated/test/parentDir/childDir");

		try {
			IO.copy(parentDir, childDir);

			fail("Expected IllegalArgumentException");
		} catch (IllegalArgumentException e) {
		}
	}
}

@@ -36,16 +36,44 @@
 io.File;
+%0Aimport java.nio.file.Files;
 %0A%0Aimport
@@ -1391,11 +1391,1270 @@
 %7B%0A%09%09%7D%0A%09%7D
+%0A%0A%09public void testIfCreateSymlinkOrCopyFileDependingOnOS() throws Exception %7B%0A%09%09File link = new File(%22generated/test/target.dat%22);%0A%0A%09%09IO.delete(link);%0A%0A%09%09assertFalse(link.exists() %7C%7C Files.isSymbolicLink(link.toPath()));%0A%0A%09%09link.getParentFile().mkdirs();%0A%0A%09%09File target = new File(%22testresources/zipped.dat%22);%0A%0A%09%09assertTrue(target.exists());%0A%0A%09%09assertTrue(IO.createSymbolicLinkOrCopy(link, target));%0A%0A%09%09if (IO.isWindows()) %7B%0A%09%09%09assertFalse(Files.isSymbolicLink(link.toPath()));%0A%09%09%7D else %7B%0A%09%09%09assertTrue(Files.isSymbolicLink(link.toPath()));%0A%09%09%7D%0A%09%7D%0A%0A%09public void testOnlyCopyIfReallyNeededOnWindows() throws Exception %7B%0A%09%09if (IO.isWindows()) %7B%0A%09%09%09File link = new File(%22generated/test/target.dat%22);%0A%0A%09%09%09IO.delete(link);%0A%0A%09%09%09assertFalse(link.exists() %7C%7C Files.isSymbolicLink(link.toPath()));%0A%0A%09%09%09link.getParentFile().mkdirs();%0A%0A%09%09%09File target = new File(%22testresources/zipped.dat%22);%0A%09%09%09assertTrue(target.exists());%0A%0A%09%09%09assertTrue(IO.createSymbolicLinkOrCopy(link, target));%0A%0A%09%09%09assertEquals(link.lastModified(), target.lastModified());%0A%09%09%09assertEquals(link.length(), target.length());%0A%0A%09%09%09assertTrue(IO.createSymbolicLinkOrCopy(link, target));%0A%0A%09%09%09assertEquals(link.lastModified(), target.lastModified());%0A%09%09%09assertEquals(link.length(), target.length());%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

add tests