[Aprog]
[aprog.git] / Aprog / test / net / sourceforge / aprog / tools / LauncherTest.java
blobc085a6c6211e0496d7553d5d426f6a04e80246d5
1 /*
2 * The MIT License
3 *
4 * Copyright 2010 Codist Monk.
5 *
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
22 * THE SOFTWARE.
25 package net.sourceforge.aprog.tools;
27 import static net.sourceforge.aprog.tools.Tools.*;
29 import java.io.ByteArrayInputStream;
30 import java.io.ByteArrayOutputStream;
31 import java.io.File;
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;
41 /**
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());
53 @Test
54 public final void testCreateLibraryPath() {
55 debugPrint("TODO"); // TODO
58 @Test
59 public final void testExecute() {
60 debugPrint("TODO"); // TODO
63 @Test
64 public final void testGetClassPathInIDE() {
65 debugPrint("TODO"); // TODO
68 @Test
69 public final void testGetJars() {
70 debugPrint("TODO"); // TODO
73 @Test
74 public final void testGetLibraryPath() {
75 debugPrint("TODO"); // TODO
78 @Test
79 public final void testGetNativeLibraryFiles() {
80 debugPrint("TODO"); // TODO
83 @Test
84 public final void testIsJar() {
85 assertTrue(Launcher.isJar(new File("aprog.jar")));
88 @Test
89 public final void testIsNativeLibrary() {
90 switch (OS.getCurrentOS()) {
91 case LINUX:
92 assertTrue(Launcher.isNativeLibrary(new File("library.so")));
93 break;
94 case MAC_OS_X:
95 assertTrue(Launcher.isNativeLibrary(new File("library.dylib")));
96 assertTrue(Launcher.isNativeLibrary(new File("library.jnilib")));
97 break;
98 case SOLARIS:
99 assertTrue(Launcher.isNativeLibrary(new File("library.so")));
100 break;
101 case WINDOWS:
102 assertTrue(Launcher.isNativeLibrary(new File("library.dll")));
103 break;
104 default:
105 debugPrint("TODO: " + SystemProperties.getOSName());
106 break;
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));
118 input.close();
119 buffer.flush();
120 pipe.join();
122 assertEquals(string, buffer.toString());
125 @Test
126 public final void testRedirectOutputsToConsole() {
127 debugPrint("TODO"); // TODO
130 @Test
131 public final void testStartApplicationFromJar() {
132 debugPrint("TODO"); // TODO
135 @Test
136 public final void testStartApplicationFromIDE() {
137 debugPrint("TODO"); // TODO
140 @Test
141 public final void testRecursiveCollector() {
142 debugPrint("TODO"); // TODO
145 @Test
146 public final void testJarCollector() {
147 assertEquals(1, new Launcher.JarCollector().collect(new File("test")).size());
150 @Test
151 public final void testNativeLibraryCollector() {
152 final List<File> nativeLibraries = new Launcher.NativeLibraryCollector().collect(new File("test"));
154 switch (OS.getCurrentOS()) {
155 case MAC_OS_X:
156 assertEquals(2, nativeLibraries.size());
157 break;
158 case LINUX:
159 case SOLARIS:
160 case WINDOWS:
161 assertEquals(1, nativeLibraries.size());
162 break;
163 default:
164 debugPrint("TODO: " + SystemProperties.getOSName());
165 break;
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;
185 * @return
186 * <br>Not null
188 public static final OS getCurrentOS() {
189 final String osName = SystemProperties.getOSName().toLowerCase(Locale.ENGLISH);
191 if (osName.startsWith("linux")) {
192 return LINUX;
193 } else if (osName.startsWith("mac os x")) {
194 return MAC_OS_X;
195 } else if (osName.startsWith("solaris")) {
196 return SOLARIS;
197 } else if (osName.startsWith("windows")) {
198 return WINDOWS;
201 return null;