From 38f22192a435ce2df6dbb2a266df8feb97e0bd47 Mon Sep 17 00:00:00 2001 From: Lars Langhans Date: Tue, 29 Jun 2010 13:43:01 +0200 Subject: sb123:#i111449# cleanups in test environment --- .../java/org/openoffice/test/FileHelper.java | 63 ++++++++++++++++++++++ .../java/org/openoffice/test/OfficeConnection.java | 37 ++++++++----- test/source/java/org/openoffice/test/makefile.mk | 1 + 3 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 test/source/java/org/openoffice/test/FileHelper.java (limited to 'test') diff --git a/test/source/java/org/openoffice/test/FileHelper.java b/test/source/java/org/openoffice/test/FileHelper.java new file mode 100644 index 000000000000..bd1a00370479 --- /dev/null +++ b/test/source/java/org/openoffice/test/FileHelper.java @@ -0,0 +1,63 @@ +/* + * ************************************************************************ + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + * ************************************************************************ + */ + +package org.openoffice.test; + +/** + * + * @author ll93751 + */ +public class FileHelper +{ + public FileHelper() + { + } + /** + * Concat a _sRelativePathToAdd to a _sPath and append a '/' to the _sPath only if need. + * + * @param _sPath + * @param _sRelativePathToAdd + * @return a right concated path + */ + public static String appendPath(String _sPath, String _sRelativePathToAdd) + { + String sNewPath = _sPath; + String fs = System.getProperty("file.separator"); + if (_sPath.startsWith("file:")) + { + fs = "/"; // we use a file URL so only '/' is allowed. + } + if (! (sNewPath.endsWith("/") || sNewPath.endsWith("\\") ) ) + { + sNewPath += fs; + } + sNewPath += _sRelativePathToAdd; + return sNewPath; + } +} diff --git a/test/source/java/org/openoffice/test/OfficeConnection.java b/test/source/java/org/openoffice/test/OfficeConnection.java index f87947137167..a7c75557b217 100644 --- a/test/source/java/org/openoffice/test/OfficeConnection.java +++ b/test/source/java/org/openoffice/test/OfficeConnection.java @@ -31,6 +31,7 @@ import com.sun.star.comp.helper.Bootstrap; import com.sun.star.connection.NoConnectException; import com.sun.star.frame.XDesktop; import com.sun.star.lang.DisposedException; +import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import java.io.IOException; @@ -103,23 +104,31 @@ public final class OfficeConnection { throws InterruptedException, com.sun.star.uno.Exception { boolean desktopTerminated = true; - if (context != null) { - XDesktop desktop = UnoRuntime.queryInterface( - XDesktop.class, - context.getServiceManager().createInstanceWithContext( - "com.sun.star.frame.Desktop", context)); - context = null; - try { - desktopTerminated = desktop.terminate(); - } catch (DisposedException e) {} - // it appears that DisposedExceptions can already happen while - // receiving the response of the terminate call - desktop = null; - } else if (process != null) { + if (context != null) + { + XMultiComponentFactory xMSF = context.getServiceManager(); + if (xMSF != null) + { + XDesktop desktop = UnoRuntime.queryInterface( + XDesktop.class, + xMSF.createInstanceWithContext( + "com.sun.star.frame.Desktop", context)); + context = null; + try { + desktopTerminated = desktop.terminate(); + } catch (DisposedException e) {} + // it appears that DisposedExceptions can already happen while + // receiving the response of the terminate call + desktop = null; + } + } + else if (process != null) + { process.destroy(); } int code = 0; - if (process != null) { + if (process != null) + { code = process.waitFor(); } boolean outTerminated = outForward == null || outForward.terminated(); diff --git a/test/source/java/org/openoffice/test/makefile.mk b/test/source/java/org/openoffice/test/makefile.mk index 94b629a69ed0..9314ea6a1506 100644 --- a/test/source/java/org/openoffice/test/makefile.mk +++ b/test/source/java/org/openoffice/test/makefile.mk @@ -32,6 +32,7 @@ TARGET = java PACKAGE = org/openoffice/test JAVAFILES = \ Argument.java \ + FileHelper.java \ OfficeConnection.java \ OfficeFileUrl.java \ TestArgument.java -- cgit