4 * Copyright 2010 Codist Monk.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 package net
.sourceforge
.aprog
.tools
;
27 import static net
.sourceforge
.aprog
.tools
.Tools
.*;
29 import java
.io
.ByteArrayInputStream
;
30 import java
.io
.ByteArrayOutputStream
;
32 import java
.io
.IOException
;
33 import java
.io
.PrintStream
;
34 import java
.util
.List
;
35 import java
.util
.Locale
;
37 import static org
.junit
.Assert
.*;
39 import org
.junit
.Test
;
42 * Automated tests using JUnit 4 for {@link Launcher}.
44 * @author codistmonk (creation 2010-06-23)
46 public class LauncherTest
{
48 @Test(timeout
= TIMEOUT
)
49 public final void testLaunch() throws InterruptedException
{
50 assertEquals(0, Launcher
.launch(EchoApplicationFile
.class).waitFor());
54 public final void testCreateLibraryPath() {
55 debugPrint("TODO"); // TODO
59 public final void testExecute() {
60 debugPrint("TODO"); // TODO
64 public final void testGetClassPathInIDE() {
65 debugPrint("TODO"); // TODO
69 public final void testGetJars() {
70 debugPrint("TODO"); // TODO
74 public final void testGetLibraryPath() {
75 debugPrint("TODO"); // TODO
79 public final void testGetNativeLibraryFiles() {
80 debugPrint("TODO"); // TODO
84 public final void testIsJar() {
85 assertTrue(Launcher
.isJar(new File("aprog.jar")));
89 public final void testIsNativeLibrary() {
90 switch (OS
.getCurrentOS()) {
92 assertTrue(Launcher
.isNativeLibrary(new File("library.so")));
95 assertTrue(Launcher
.isNativeLibrary(new File("library.dylib")));
96 assertTrue(Launcher
.isNativeLibrary(new File("library.jnilib")));
99 assertTrue(Launcher
.isNativeLibrary(new File("library.so")));
102 assertTrue(Launcher
.isNativeLibrary(new File("library.dll")));
105 debugPrint("TODO: " + SystemProperties
.getOSName());
110 @Test(timeout
= TIMEOUT
)
111 public final void testPipe() throws IOException
, InterruptedException
{
112 final String string
= "42" + SystemProperties
.getLineSeparator();
113 final ByteArrayOutputStream buffer
= new ByteArrayOutputStream();
114 final ByteArrayInputStream input
= new ByteArrayInputStream(string
.getBytes());
116 final Thread pipe
= Launcher
.pipe(input
, new PrintStream(buffer
));
122 assertEquals(string
, buffer
.toString());
126 public final void testRedirectOutputsToConsole() {
127 debugPrint("TODO"); // TODO
131 public final void testStartApplicationFromJar() {
132 debugPrint("TODO"); // TODO
136 public final void testStartApplicationFromIDE() {
137 debugPrint("TODO"); // TODO
141 public final void testRecursiveCollector() {
142 debugPrint("TODO"); // TODO
146 public final void testJarCollector() {
147 assertEquals(1, new Launcher
.JarCollector().collect(new File("test")).size());
151 public final void testNativeLibraryCollector() {
152 final List
<File
> nativeLibraries
= new Launcher
.NativeLibraryCollector().collect(new File("test"));
154 switch (OS
.getCurrentOS()) {
156 assertEquals(2, nativeLibraries
.size());
161 assertEquals(1, nativeLibraries
.size());
164 debugPrint("TODO: " + SystemProperties
.getOSName());
170 * {@value} milliseconds.
172 public static final long TIMEOUT
= 10000L;
176 * @author codistmonk (creation 2010-10-26)
179 public static enum OS
{
181 LINUX
, MAC_OS_X
, SOLARIS
, WINDOWS
;
188 public static final OS
getCurrentOS() {
189 final String osName
= SystemProperties
.getOSName().toLowerCase(Locale
.ENGLISH
);
191 if (osName
.startsWith("linux")) {
193 } else if (osName
.startsWith("mac os x")) {
195 } else if (osName
.startsWith("solaris")) {
197 } else if (osName
.startsWith("windows")) {