19package org.openoffice.test;
31import java.io.IOException;
32import java.io.InputStream;
33import java.io.PrintStream;
36import static org.junit.Assert.*;
48 public void setUp() throws Exception {
50 if (sofficeArg.startsWith(
"path:")) {
51 description =
"pipe,name=oootest" + UUID.randomUUID();
52 ProcessBuilder pb =
new ProcessBuilder(
53 sofficeArg.substring(
"path:".length()),
"--quickstart=no",
54 "--norestore",
"--nologo",
"--headless",
57 "-env:UNO_JAVA_JFW_ENV_JREHOME=true");
59 if (workdirArg !=
null) {
60 pb.directory(
new File(workdirArg));
64 Map<String, String>
env = pb.environment();
65 int i = envArg.indexOf(
'=');
69 env.put(envArg.substring(0,
i), envArg.substring(
i + 1));
77 }
else if (sofficeArg.startsWith(
"connect:")) {
81 "\"soffice\" argument \"" + sofficeArg +
82 " starts with neither \"path:\" nor \"connect:\"");
84 XUnoUrlResolver
resolver = UnoUrlResolver.create(
85 Bootstrap.createInitialComponentContext(
null));
88 context = UnoRuntime.queryInterface(
89 XComponentContext.class,
92 ";urp;StarOffice.ComponentContext"));
94 }
catch (NoConnectException e) {}
104 throws InterruptedException,
com.sun.star.
uno.Exception
106 boolean cleanTermination =
false;
113 XMultiComponentFactory factory =
115 assertNotNull(factory);
116 desktop = UnoRuntime.queryInterface(XDesktop.class,
117 factory.createInstanceWithContext(
118 "com.sun.star.frame.Desktop",
context));
119 }
catch (DisposedException e) {
127 boolean desktopTerminated =
desktop.terminate();
128 if (!desktopTerminated) {
133 assertTrue(desktopTerminated);
134 }
catch (DisposedException e) {}
150 assertEquals(0,
code);
151 cleanTermination =
true;
152 assertTrue(outTerminated);
153 assertTrue(errTerminated);
155 if (!cleanTermination) {
160 "postprocesscommand");
161 if (sofficeArg.startsWith(
"path:") && workdir !=
null
162 && postprocesscommand !=
null)
164 ProcessBuilder pb =
new ProcessBuilder(
166 sofficeArg.substring(
"path:".length()) +
".bin",
168 Process postprocess = pb.start();
170 postprocess.getInputStream(),
System.out);
171 ppoutForward.start();
173 postprocess.getErrorStream(),
System.err);
174 pperrForward.start();
175 code = postprocess.waitFor();
181 catch (IOException e) {
200 throws InterruptedException
202 final Thread t1 = Thread.currentThread();
203 Thread t2 =
new Thread(
"waitForProcess") {
206 util.utils.pause(millis);
210 boolean old = Thread.interrupted();
214 boolean done =
false;
218 }
catch (InterruptedException e) {}
222 }
catch (InterruptedException e) {
225 Thread.interrupted();
229 return done ?
Integer.valueOf(
n) :
null;
232 private static final class Forward extends Thread {
234 super(
"process output forwarder");
242 byte[] buf =
new byte[1024];
246 }
catch (IOException e) {
252 out.write(buf, 0,
n);
262 private final InputStream
in;
263 private final PrintStream
out;
271 super(
"postprocessing failed with exit code " + exitCode);
275 super(
"postprocessing failed with IOException " + cause, cause);
static String get(String name)
Forward(InputStream in, PrintStream out)
Start up and shut down an OOo instance.
XComponentContext getComponentContext()
Obtain the component context of the running OOo instance.
void setUp()
Start up an OOo instance.
XComponentContext context
void tearDown()
Shut down the OOo instance.
static Integer waitForProcess(Process process, final int millis)
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
def run(arg=None, arg2=-1)
void SC_DLLPUBLIC join(const ScDocument *pDoc, ::std::vector< ScTokenRef > &rTokens, const ScTokenRef &pToken, const ScAddress &rPos)
const rtl::Bootstrap * Bootstrap()