2012-06-29 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2007-07-24 12:24:22 +00:00
|
|
|
package complex.api_internal;
|
|
|
|
|
2012-06-28 15:16:48 +02:00
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import static org.junit.Assert.fail;
|
2007-07-24 12:24:22 +00:00
|
|
|
import helper.OfficeProvider;
|
|
|
|
import helper.ProcessHandler;
|
|
|
|
|
2012-06-28 15:16:48 +02:00
|
|
|
import java.util.ArrayList;
|
2007-07-24 12:24:22 +00:00
|
|
|
import java.util.StringTokenizer;
|
2010-06-28 12:54:49 +02:00
|
|
|
import lib.TestParameters;
|
2012-06-28 15:16:48 +02:00
|
|
|
|
2010-06-28 12:54:49 +02:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.openoffice.test.OfficeConnection;
|
2012-06-28 15:16:48 +02:00
|
|
|
|
|
|
|
import com.sun.star.beans.NamedValue;
|
|
|
|
import com.sun.star.beans.PropertyValue;
|
|
|
|
import com.sun.star.beans.XPropertyAccess;
|
|
|
|
import com.sun.star.lang.XMultiServiceFactory;
|
|
|
|
import com.sun.star.task.XJob;
|
|
|
|
import com.sun.star.uno.UnoRuntime;
|
2010-06-28 12:54:49 +02:00
|
|
|
|
2007-07-24 12:24:22 +00:00
|
|
|
/**
|
|
|
|
* This test executes the API tests internally in StarOffice. Prerequiste is
|
|
|
|
* that a OOoRunner.jar is registered inseide of StarOffice. Adjust the joblist
|
|
|
|
* inside of the ChekAPI.props to determine which tetss will be executed.
|
|
|
|
*/
|
2010-06-28 12:54:49 +02:00
|
|
|
public class CheckAPI {
|
2007-07-24 12:24:22 +00:00
|
|
|
|
2010-06-28 12:54:49 +02:00
|
|
|
/**
|
|
|
|
* The test parameters
|
|
|
|
*/
|
|
|
|
private static TestParameters param = null;
|
2007-07-24 12:24:22 +00:00
|
|
|
|
2010-06-28 12:54:49 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Before public void before()
|
|
|
|
{
|
|
|
|
param = new TestParameters();
|
|
|
|
}
|
2007-07-24 12:24:22 +00:00
|
|
|
/**
|
|
|
|
* Execute the API tests inside of the Office. If the Office crashes, it
|
|
|
|
* will be restarted and the job will continue after the one that caused the crash.
|
|
|
|
*/
|
2010-06-28 12:54:49 +02:00
|
|
|
@Test public void checkAPI() {
|
|
|
|
System.out.println("Start with test");
|
2007-07-24 12:24:22 +00:00
|
|
|
// if test is idle for 5 minutes, assume that it hangs and kill it.
|
2010-06-28 12:54:49 +02:00
|
|
|
XMultiServiceFactory xMSF = getMSF();
|
2007-07-24 12:24:22 +00:00
|
|
|
Object oObj = null;
|
|
|
|
try {
|
|
|
|
oObj = xMSF.createInstance("org.openoffice.RunnerService");
|
|
|
|
}
|
|
|
|
catch(com.sun.star.uno.Exception e) {
|
2010-06-28 12:54:49 +02:00
|
|
|
fail("Could not create Instance of 'org.openoffice.RunnerService'");
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
2010-06-28 12:54:49 +02:00
|
|
|
assertNotNull("Cannot create 'org.openoffice.RunnerService'", oObj);
|
|
|
|
|
2007-07-24 12:24:22 +00:00
|
|
|
// get the parameters for the internal test
|
|
|
|
String paramList = (String)param.get("ParamList");
|
2012-06-28 15:19:57 +02:00
|
|
|
ArrayList<Object> p = new ArrayList<Object>();
|
2007-07-24 12:24:22 +00:00
|
|
|
StringTokenizer paramTokens = new StringTokenizer(paramList, " ");
|
2010-06-28 12:54:49 +02:00
|
|
|
while(paramTokens.hasMoreTokens())
|
|
|
|
{
|
2007-07-24 12:24:22 +00:00
|
|
|
p.add(paramTokens.nextToken());
|
|
|
|
}
|
|
|
|
int length = p.size()/2+1;
|
|
|
|
NamedValue[] internalParams = new NamedValue[length];
|
|
|
|
for (int i=0; i<length-1; i++) {
|
|
|
|
internalParams[i] = new NamedValue();
|
|
|
|
internalParams[i].Name = (String)p.get(i*2);
|
|
|
|
internalParams[i].Value = p.get(i*2+1);
|
2010-06-28 12:54:49 +02:00
|
|
|
System.out.println("Name: "+internalParams[i].Name);
|
|
|
|
System.out.println("Value: "+(String)internalParams[i].Value);
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// do we have test jobs?
|
|
|
|
String testJob = (String)param.get("job");
|
|
|
|
PropertyValue[]props;
|
2010-06-28 12:54:49 +02:00
|
|
|
if (testJob==null)
|
|
|
|
{
|
|
|
|
if ( param.get("job1")==null )
|
|
|
|
{
|
2007-07-24 12:24:22 +00:00
|
|
|
// get all test jobs from runner service
|
2012-06-28 15:19:57 +02:00
|
|
|
XPropertyAccess xPropAcc = UnoRuntime.queryInterface(XPropertyAccess.class, oObj);
|
2007-07-24 12:24:22 +00:00
|
|
|
props = xPropAcc.getPropertyValues();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int index=1;
|
2012-06-28 15:19:57 +02:00
|
|
|
p = new ArrayList<Object>();
|
2007-07-24 12:24:22 +00:00
|
|
|
while ( param.get("job"+index) != null ) {
|
|
|
|
p.add(param.get("job"+index));
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
props = new PropertyValue[p.size()];
|
|
|
|
for ( int i=0; i<props.length; i++ ) {
|
|
|
|
props[i] = new PropertyValue();
|
|
|
|
props[i].Value = p.get(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
props = new PropertyValue[1];
|
|
|
|
props[0] = new PropertyValue();
|
|
|
|
props[0].Value = testJob;
|
|
|
|
}
|
|
|
|
|
2010-06-28 12:54:49 +02:00
|
|
|
System.out.println("Props length: "+ props.length);
|
2007-07-24 12:24:22 +00:00
|
|
|
for (int i=0; i<props.length; i++) {
|
2010-06-28 12:54:49 +02:00
|
|
|
XJob xJob = UnoRuntime.queryInterface(XJob.class, oObj);
|
2007-07-24 12:24:22 +00:00
|
|
|
internalParams[length-1] = new NamedValue();
|
|
|
|
internalParams[length-1].Name = "-o";
|
|
|
|
internalParams[length-1].Value = props[i].Value;
|
2010-06-28 12:54:49 +02:00
|
|
|
System.out.println("Executing: " + (String)props[i].Value);
|
2007-07-24 12:24:22 +00:00
|
|
|
|
|
|
|
String erg = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
erg = (String)xJob.execute(internalParams);
|
|
|
|
}
|
|
|
|
catch(Throwable t) {
|
|
|
|
// restart and go on with test!!
|
2010-06-28 12:54:49 +02:00
|
|
|
t.printStackTrace();
|
|
|
|
fail("Test run '" + (String)props[i].Value +"' could not be executed: Office crashed and is killed!");
|
2007-07-24 12:24:22 +00:00
|
|
|
xMSF = null;
|
|
|
|
ProcessHandler handler = (ProcessHandler)param.get("AppProvider");
|
|
|
|
handler.kill();
|
|
|
|
try {
|
|
|
|
Thread.sleep(10000);
|
|
|
|
}
|
2014-08-19 14:18:44 +02:00
|
|
|
catch(InterruptedException e) {}
|
2007-07-24 12:24:22 +00:00
|
|
|
OfficeProvider op = new OfficeProvider();
|
|
|
|
xMSF = (XMultiServiceFactory)op.getManager(param);
|
|
|
|
param.put("ServiceFactory",xMSF);
|
|
|
|
try {
|
|
|
|
oObj = xMSF.createInstance("org.openoffice.RunnerService");
|
|
|
|
}
|
|
|
|
catch(com.sun.star.uno.Exception e) {
|
2010-06-28 12:54:49 +02:00
|
|
|
fail("Could not create Instance of 'org.openoffice.RunnerService'");
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-28 12:54:49 +02:00
|
|
|
System.out.println(erg);
|
2007-07-24 12:24:22 +00:00
|
|
|
String processedErg = parseResult(erg);
|
2010-06-28 12:54:49 +02:00
|
|
|
assertTrue("Run '" + (String)props[i].Value + "' has result '" + processedErg + "'", processedErg == null);
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String parseResult(String erg) {
|
|
|
|
String lineFeed = System.getProperty("line.separator");
|
|
|
|
String processedErg = null;
|
|
|
|
if (erg != null) {
|
|
|
|
StringTokenizer token = new StringTokenizer(erg, lineFeed);
|
|
|
|
String previousLine = null;
|
|
|
|
while ( token.hasMoreTokens() ) {
|
|
|
|
String line = token.nextToken();
|
|
|
|
// got a failure!
|
|
|
|
if ( line.indexOf("FAILED") != -1 ) {
|
|
|
|
processedErg = (processedErg == null)?"":processedErg + ";";
|
|
|
|
processedErg += previousLine + ":" + line;
|
|
|
|
}
|
|
|
|
if ( line.startsWith("Execute:") ) {
|
|
|
|
previousLine = line;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
previousLine += " " + line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return processedErg;
|
|
|
|
}
|
2010-06-28 12:54:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
private XMultiServiceFactory getMSF()
|
|
|
|
{
|
2014-12-09 15:09:18 +02:00
|
|
|
return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
|
2010-06-28 12:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup and close connections
|
|
|
|
@BeforeClass public static void setUpConnection() throws Exception {
|
|
|
|
System.out.println("setUpConnection()");
|
|
|
|
connection.setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
@AfterClass public static void tearDownConnection()
|
|
|
|
throws InterruptedException, com.sun.star.uno.Exception
|
|
|
|
{
|
|
|
|
System.out.println("tearDownConnection()");
|
|
|
|
connection.tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final OfficeConnection connection = new OfficeConnection();
|
|
|
|
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|