Kaydet (Commit) b7f52d9a authored tarafından Lars Langhans's avatar Lars Langhans

sb123:#i111449# cleanups in vcl qa/complex tests

üst 69309ccb
...@@ -48,3 +48,9 @@ vc vcl\mac\source\src nmake - m vc__srcm vc_inc NULL ...@@ -48,3 +48,9 @@ vc vcl\mac\source\src nmake - m vc__srcm vc_inc NULL
vc vcl\util nmake - all vc_util vc__plug.u vc__desk.u vc__aquy.u vc__appa.u vc__dtra.u vc__appm.m vc__appu.u vc__dtru.u vc__appw.w vc__appp.p vc__gdia.u vc__gdim.m vc__gdiu.u vc__gdiw.w vc__gdip.p vc__srcm.m vc__srcw.w vc__srcp.p vc__wina.u vc__winm.m vc__winu.u vc__winw.w vc__winp.p vc__gtka.u vc__gtky.u vc__gtkw.u vc__gtkg.u vc__kde.u vc__kde4.u vc__hl.u vc__ftmu.u vc__prgu.u vc__prnu.u vc_app vc_ctrl vc_gdi vc_hlp vc_src vc_win vc_glyphs vc_fts vc_components NULL vc vcl\util nmake - all vc_util vc__plug.u vc__desk.u vc__aquy.u vc__appa.u vc__dtra.u vc__appm.m vc__appu.u vc__dtru.u vc__appw.w vc__appp.p vc__gdia.u vc__gdim.m vc__gdiu.u vc__gdiw.w vc__gdip.p vc__srcm.m vc__srcw.w vc__srcp.p vc__wina.u vc__winm.m vc__winu.u vc__winw.w vc__winp.p vc__gtka.u vc__gtky.u vc__gtkw.u vc__gtkg.u vc__kde.u vc__kde4.u vc__hl.u vc__ftmu.u vc__prgu.u vc__prnu.u vc_app vc_ctrl vc_gdi vc_hlp vc_src vc_win vc_glyphs vc_fts vc_components NULL
vc vcl\util\linksvp nmake - u vc_lsvp vc_util NULL vc vcl\util\linksvp nmake - u vc_lsvp vc_util NULL
vc vcl\workben nmake - all vc_wrkb vc_util vc_salmain NULL vc vcl\workben nmake - all vc_wrkb vc_util vc_salmain NULL
# memCheck works only within unix
# memCheck is not right yet
# vc vcl\qa\complex\memCheck nmake - u vc_qa_complex vc_util NULL
vc vcl\qa\complex\persistent_window_states nmake - all vc_qa_complex vc_util NULL
...@@ -32,19 +32,27 @@ import com.sun.star.lang.XComponent; ...@@ -32,19 +32,27 @@ import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.XCloseable; import com.sun.star.util.XCloseable;
import complexlib.ComplexTestCase; // import complexlib.ComplexTestCase;
import helper.ProcessHandler; import helper.ProcessHandler;
import java.io.File; import java.io.File;
import java.io.FilePermission; // import java.io.FilePermission;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;
import lib.*;
import util.DesktopTools; import util.DesktopTools;
import util.WriterTools; // import util.WriterTools;
import util.utils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openoffice.test.OfficeConnection;
import static org.junit.Assert.*;
/** /**
* Documents are opened and exported with StarOffice. The memory usage of * Documents are opened and exported with StarOffice. The memory usage of
...@@ -66,95 +74,141 @@ import util.utils; ...@@ -66,95 +74,141 @@ import util.utils;
* All parameters are used for iteration over the test document path. * All parameters are used for iteration over the test document path.
* </ul> * </ul>
*/ */
public class CheckMemoryUsage extends ComplexTestCase { class TempDir
{
private String m_sTempDir;
public TempDir(String _sTempDir)
{
m_sTempDir = _sTempDir;
}
public String getOfficeTempDir()
{
return m_sTempDir;
}
public String getTempDir()
{
final String sTempDir = FileHelper.getJavaCompatibleFilename(m_sTempDir);
return sTempDir;
}
}
public class CheckMemoryUsage /* extends ComplexTestCase */
{
private final String sWriterDoc = "sxw,writer_pdf_Export"; private final String sWriterDoc = "sxw,writer_pdf_Export";
private final String sCalcDoc = "sxc,calc_pdf_Export"; private final String sCalcDoc = "sxc,calc_pdf_Export";
private final String sImpressDoc = "sxi,impress_pdf_Export"; private final String sImpressDoc = "sxi,impress_pdf_Export";
private String sProcessId = "ps -ef | grep $USER | grep soffice | grep -v grep"; // private String sProcessIdCommand = null;
private String sMemoryMonitor = "pmap <processID> | grep total"; TempDir m_aTempDir;
private String sChmod = "chmod 777 "; // private String sFS = null;
private String sProcessIdCommand = null; // private String sMemoryMap1 = null;
private String sOfficeMemoryCommand = null; // private String sMemoryMap2 = null;
private String sTempDir = null; // private String sDocumentPath = "";
private String sFS = null;
private String sMemoryMap1 = null;
private String sMemoryMap2 = null;
private String bash = "#!/bin/bash";
private String sDocumentPath = "";
private String[][] sDocTypeExportFilter; private String[][] sDocTypeExportFilter;
private String[][] sDocuments; private String[][] sDocuments;
private int iAllowMemoryIncrease = 10; private int iAllowMemoryIncrease = 10;
private int iExportDocCount = 25; private int iExportDocCount = 25;
/**
* The test parameters
*/
private static TestParameters param = null;
/** /**
* Get all test methods * Get all test methods
* @return The test methods. * @return The test methods.
*/ // */
public String[] getTestMethodNames() { // public String[] getTestMethodNames() {
return new String[] {"loadAndSaveDocuments"}; // return new String[] {"loadAndSaveDocuments"};
} // }
/** /**
* Collect all documnets to load and all filters used for export. * Collect all documnets to load and all filters used for export.
*/ */
public void before() { @Before
public void before()
{
final XMultiServiceFactory xMsf = getMSF();
// some Tests need the qadevOOo TestParameters, it is like a Hashmap for Properties.
param = new TestParameters();
param.put("ServiceFactory", xMsf); // some qadevOOo functions need the ServiceFactory
// test does definitely not run on Windows. // test does definitely not run on Windows.
if (param.get("OperatingSystem").equals("wntmsci")) { if (param.get("OperatingSystem").equals("wntmsci"))
log.println("Test can only reasonably be executed with a tool that " {
System.out.println("Test can only reasonably be executed with a tool that "
+ "displays the memory usage of StarOffice."); + "displays the memory usage of StarOffice.");
failed("Test does not run on Windows, only on Solaris or Linux."); System.out.println("Test does not run on Windows, only on Solaris or Linux.");
// in an automatic environment it is better to say, there is no error here.
// it is a limitation, but no error.
System.exit(0);
} }
// how many times is every document exported. // how many times is every document exported.
int count = param.getInt("ExportDocCount"); int count = param.getInt("ExportDocCount");
if (count != 0) if (count != 0)
{
iExportDocCount = count; iExportDocCount = count;
}
// get the temp dir for creating the command scripts. // get the temp dir for creating the command scripts.
sTempDir = System.getProperty("java.io.tmpdir"); // sTempDir = System.getProperty("java.io.tmpdir");
sProcessIdCommand = sTempDir + "getPS"; m_aTempDir = new TempDir(util.utils.getOfficeTemp/*Dir*/(xMsf));
sOfficeMemoryCommand = sTempDir + "getPmap";
// get the file extension, export filter connection // get the file extension, export filter connection
Enumeration keys = param.keys(); Enumeration keys = param.keys();
Vector v = new Vector(); Vector<String> v = new Vector<String>();
while(keys.hasMoreElements()) { while (keys.hasMoreElements())
String key = (String)keys.nextElement(); {
if (key.startsWith("FileExportFilter")) { String key = (String) keys.nextElement();
v.add(param.get(key)); if (key.startsWith("FileExportFilter"))
{
v.add((String) param.get(key));
} }
} }
// if no param given, set defaults. // if no param given, set defaults.
if (v.size() == 0){ if (v.size() == 0)
{
v.add(sWriterDoc); v.add(sWriterDoc);
v.add(sCalcDoc); v.add(sCalcDoc);
v.add(sImpressDoc); v.add(sImpressDoc);
} }
// store a file extension // store a file extension
sDocTypeExportFilter = new String[v.size()][2]; sDocTypeExportFilter = new String[v.size()][2];
for (int i=0; i<v.size(); i++) { for (int i = 0; i < v.size(); i++)
{
// 2do: error routine for wrong given params // 2do: error routine for wrong given params
StringTokenizer t = new StringTokenizer((String)v.get(i), ","); final String sVContent = v.get(i);
sDocTypeExportFilter[i][0] = t.nextToken(); StringTokenizer t = new StringTokenizer(sVContent, ",");
sDocTypeExportFilter[i][1] = t.nextToken(); final String sExt = t.nextToken();
final String sName = t.nextToken();
sDocTypeExportFilter[i][0] = sExt;
sDocTypeExportFilter[i][1] = sName;
} }
// get files to load and export // get files to load and export
sDocumentPath = (String)param.get("TestDocumentPath"); // sDocumentPath = (String) param.get("TestDocumentPath");
File f = new File(sDocumentPath); String sDocumentPath = TestDocument.getUrl();
sDocumentPath = f.getAbsolutePath(); File f = new File(FileHelper.getJavaCompatibleFilename(sDocumentPath));
String sFS = System.getProperty("file.separator"); // sDocumentPath = f.getAbsolutePath();
// String sFS = System.getProperty("file.separator");
sDocuments = new String[sDocTypeExportFilter.length][]; sDocuments = new String[sDocTypeExportFilter.length][];
for (int j=0; j<sDocTypeExportFilter.length; j++) { for (int j = 0; j < sDocTypeExportFilter.length; j++)
{
FileFilter filter = new FileFilter(sDocTypeExportFilter[j][0]); FileFilter filter = new FileFilter(sDocTypeExportFilter[j][0]);
String[] doc = f.list(filter); String[] doc = f.list(filter);
sDocuments[j] = new String[doc.length]; sDocuments[j] = new String[doc.length];
for (int i=0; i<doc.length; i++) { for (int i = 0; i < doc.length; i++)
if (sDocumentPath.endsWith(sFS)) {
sDocuments[j][i] = sDocumentPath + doc[i]; // final String sDocument = FileHelper.appendPath(sDocumentPath, doc[i]);
else // sDocuments[j][i] = utils.getFullURL(sDocuments[j][i]);
sDocuments[j][i] = sDocumentPath + sFS + doc[i]; sDocuments[j][i] = TestDocument.getUrl(doc[i]);
sDocuments[j][i] = utils.getFullURL(sDocuments[j][i]);
} }
} }
} }
...@@ -162,96 +216,255 @@ public class CheckMemoryUsage extends ComplexTestCase { ...@@ -162,96 +216,255 @@ public class CheckMemoryUsage extends ComplexTestCase {
/** /**
* delete all created files on disk * delete all created files on disk
*/ */
public void after() { @After
public void after()
{
// delete the constructed files. // delete the constructed files.
for (int i=0; i<iExportDocCount; i++) { // we don't need to delete anything, all is stored in $USER_TREE
File f = new File(sTempDir + "DocExport" + i + ".pdf"); // for (int i = 0; i < iExportDocCount; i++)
f.delete(); // {
} // final String sDocumentName = "DocExport" + i + ".pdf";
File f = new File(sProcessIdCommand); // final String sFilename = FileHelper.appendPath(m_sTempDir, sDocumentName);
f.delete(); // File f = new File(FileHelper.getJavaCompatibleFilename(sFilename));
f = new File(sOfficeMemoryCommand); // f.delete();
f.delete(); // }
// File f = new File(sProcessIdCommand);
// f.delete();
// f = new File(sOfficeMemoryCommand);
// f.delete();
} }
/** /**
* Thet etst function: load documents and save them using the given filters * The test function: load documents and save them using the given filters
* for each given document type. * for each given document type.
*/ */
public void loadAndSaveDocuments() { @Test
int storageBefore = getOfficeMemoryUsage(); public void loadAndSaveDocuments()
{
int nOk = 0;
int nRunThrough = 0;
XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF(); // At first:
// we load the document, there will be some post work in office like late initialisations
// we store exact one time the document
// so the memory footprint should be right
// iterate over all document types // iterate over all document types
for (int k=0; k<sDocTypeExportFilter.length; k++) { for (int k = 0; k < sDocTypeExportFilter.length; k++)
{
// iterate over all documents of this type // iterate over all documents of this type
for (int i=0; i<sDocuments[k].length; i++) { for (int i = 0; i < sDocuments[k].length; i++)
System.out.println("Document: "+ sDocuments[k][i]); {
XComponent xComponent = DesktopTools.loadDoc(xMSF, sDocuments[k][i], null);
XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, xComponent); final String sDocument = sDocuments[k][i];
if (xStorable != null) { final String sExtension = sDocTypeExportFilter[k][1];
// OfficeMemchecker aChecker = new OfficeMemchecker();
// aChecker.setDocumentName(FileHelper.getBasename(sDocument));
// aChecker.setExtension(sExtension);
// aChecker.start();
loadAndSaveNTimesDocument(sDocument, 1, sExtension);
// nOk += checkMemory(aChecker);
// nRunThrough ++;
}
System.out.println();
System.out.println();
}
shortWait(10000);
// Now the real test, load document and store 25 times
// iterate over all document types
for (int k = 0; k < sDocTypeExportFilter.length; k++)
{
// iterate over all documents of this type
for (int i = 0; i < sDocuments[k].length; i++)
{
final String sDocument = sDocuments[k][i];
final String sExtension = sDocTypeExportFilter[k][1];
OfficeMemchecker aChecker = new OfficeMemchecker();
aChecker.setDocumentName(FileHelper.getBasename(sDocument));
aChecker.setExtension(sExtension);
aChecker.start();
loadAndSaveNTimesDocument(sDocument, iExportDocCount, sExtension);
aChecker.stop();
final int nConsumMore = aChecker.getConsumMore();
nOk += checkMemory(nConsumMore);
nRunThrough++;
}
System.out.println();
System.out.println();
}
System.out.println("Find the output of used 'pmap' here: " + m_aTempDir.getTempDir() + " if test failed.");
assertTrue("Office consumes too many memory.", nOk == nRunThrough);
}
/**
* Checks how much memory should consum
* @param storageBefore
* @return 1 if consum is ok, else 0
*/
private int checkMemory(int nConsumMore)
{
int nAllowed = iAllowMemoryIncrease * iExportDocCount;
System.out.println("The Office consumes now " + nConsumMore
+ "K more memory than at the start of the test; allowed were "
+ nAllowed + "K.");
if (nConsumMore > nAllowed)
{
System.out.println("ERROR: This is not allowed.");
return 0;
}
System.out.println("OK.");
return 1;
}
/**
* load and save exact one document
*/
private void loadAndSaveNTimesDocument(String _sDocument, int _nCount, String _sStoreExtension)
{
System.out.println("Document: " + _sDocument);
XComponent xComponent = DesktopTools.loadDoc(getMSF(), _sDocument, null);
XStorable xStorable = UnoRuntime.queryInterface(XStorable.class, xComponent);
if (xStorable != null)
{
// export each document iExportDocCount times // export each document iExportDocCount times
for (int j=0; j<iExportDocCount; j++) { for (int j = 0; j < _nCount; j++)
String url = utils.getFullURL(sTempDir + "DocExport" + j + ".pdf"); {
try { final String sDocumentName = FileHelper.getBasename(_sDocument) + "_" + j + ".pdf";
final String sFilename = FileHelper.appendPath(m_aTempDir.getOfficeTempDir(), sDocumentName);
// String url = utils.getFullURL(sFilename);
String url = sFilename; // graphical.FileHelper.getFileURLFromSystemPath(sFilename);
try
{
PropertyValue[] props = new PropertyValue[1]; PropertyValue[] props = new PropertyValue[1];
props[0] = new PropertyValue(); props[0] = new PropertyValue();
props[0].Name = "FilterName"; props[0].Name = "FilterName";
// use export filter for this doc type // use export filter for this doc type
props[0].Value = sDocTypeExportFilter[k][1]; props[0].Value = _sStoreExtension;
xStorable.storeToURL(url, props); xStorable.storeToURL(url, props);
} }
catch(com.sun.star.io.IOException e) { catch (com.sun.star.io.IOException e)
failed("Could not store to '" + url + "'", true); {
fail("Could not store to '" + url + "'");
} }
} }
// close the doc // close the doc
XCloseable xCloseable = (XCloseable)UnoRuntime.queryInterface(XCloseable.class, xStorable); XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, xStorable);
try { try
{
xCloseable.close(true); xCloseable.close(true);
} }
catch(com.sun.star.util.CloseVetoException e) { catch (com.sun.star.util.CloseVetoException e)
e.printStackTrace((java.io.PrintWriter)log); {
failed("Cannot close document: test is futile, Office will surely use more space."); e.printStackTrace();
fail("Cannot close document: test is futile, Office will surely use more space.");
}
}
else
{
System.out.println("Cannot query for XStorable interface on document '" + _sDocument + "'");
System.out.println(" -> Skipping storage.");
} }
} }
else {
log.println("Cannot query for XStorable interface on document '" + sDocuments[i] + "'"); // -----------------------------------------------------------------------------
log.println(" -> Skipping storage."); private class OfficeMemchecker
{
/**
* After called start() it contains the memory need at startup
*/
private int m_nMemoryStart;
/**
* After called stop() it contains the memory usage
*/
private int m_nMemoryUsage;
private String m_sDocumentName;
private String m_sExtension;
public OfficeMemchecker()
{
m_nMemoryStart = 0;
} }
public void setDocumentName(String _sDocName)
{
m_sDocumentName = _sDocName;
} }
public void setExtension(String _sExt)
{
m_sExtension = _sExt;
} }
public void start()
{
m_nMemoryStart = getOfficeMemoryUsage(createModeName("start", 0));
}
private String createModeName(String _sSub, int _nCount)
{
StringBuffer aBuf = new StringBuffer();
aBuf.append(_sSub);
aBuf.append('_').append(m_sDocumentName).append('_').append(m_sExtension);
aBuf.append('_').append(_nCount);
return aBuf.toString();
}
public void stop()
{
// short wait for the office to 'calm down' and free some memory // short wait for the office to 'calm down' and free some memory
shortWait(5000); shortWait(20000);
// wait util memory is not freed anymore. // wait util memory is not freed anymore.
int storageAfter = getOfficeMemoryUsage(); int storageAfter = getOfficeMemoryUsage(createModeName("stop", 0));
int mem = 0; int mem = 0;
int count = 0; int count = 0;
while (storageAfter != mem && count < 10) { while (storageAfter != mem && count < 10)
{
count++; count++;
mem = storageAfter; mem = storageAfter;
storageAfter = getOfficeMemoryUsage(); storageAfter = getOfficeMemoryUsage(createModeName("stop", count));
shortWait(1000); shortWait(1000);
} }
assure("The Office consumes now " + (storageAfter - storageBefore) m_nMemoryUsage = (storageAfter - m_nMemoryStart);
+ "K more memory than at the start of the test; allowed were " }
+ iAllowMemoryIncrease * iExportDocCount + "K.",
storageAfter - storageBefore < iAllowMemoryIncrease * iExportDocCount);
public int getConsumMore()
{
return m_nMemoryUsage;
} }
/** /**
* Get the process ID from the Office * Get the process ID from the Office
* @return the Id as String * @return the Id as String
*/ */
private String getOfficeProcessID() { private String getOfficeProcessID()
writeExecutableFile(sProcessIdCommand, sProcessId); {
String sProcessIdCommand = FileHelper.appendPath(m_aTempDir.getTempDir(), "getPS");
final String sofficeArg = org.openoffice.test.Argument.get("soffice");
final String sPSGrep = "ps -ef | grep $USER | grep <soffice>.bin | grep -v grep";
final String sProcessId = sPSGrep.replaceAll("<soffice>", FileHelper.getJavaCompatibleFilename(sofficeArg));
createExecutableFile(sProcessIdCommand, sProcessId);
ProcessHandler processID = new ProcessHandler(sProcessIdCommand); ProcessHandler processID = new ProcessHandler(sProcessIdCommand);
processID.noOutput();
processID.executeSynchronously(); processID.executeSynchronously();
String text = processID.getOutputText(); String text = processID.getOutputText();
if (text == null || text.equals("") || text.indexOf(' ') == -1) if (text == null || text.equals("") || text.indexOf(' ') == -1)
failed("Could not determine Office process ID. Check " + sProcessIdCommand); {
fail("Could not determine Office process ID. Check " + sProcessIdCommand);
}
StringTokenizer aToken = new StringTokenizer(text); StringTokenizer aToken = new StringTokenizer(text);
// this is not nice, but ps gives the same output on every machine // this is not nice, but ps gives the same output on every machine
aToken.nextToken(); aToken.nextToken();
...@@ -263,14 +476,26 @@ public class CheckMemoryUsage extends ComplexTestCase { ...@@ -263,14 +476,26 @@ public class CheckMemoryUsage extends ComplexTestCase {
* Get the memory usage of the Office in KByte. * Get the memory usage of the Office in KByte.
* @return The memory used by the Office. * @return The memory used by the Office.
*/ */
private int getOfficeMemoryUsage() { private int getOfficeMemoryUsage(String _sMode)
{
final String sMemoryMonitor = "pmap <processID> |tee <pmapoutputfile> | grep total";
String sOfficeMemoryCommand = null;
sOfficeMemoryCommand = FileHelper.appendPath(m_aTempDir.getTempDir(), "getPmap");
// sOfficeMemoryCommand = FileHelper.getJavaCompatibleFilename(sOfficeMemoryCommand);
String command = sMemoryMonitor.replaceAll("<processID>", getOfficeProcessID()); String command = sMemoryMonitor.replaceAll("<processID>", getOfficeProcessID());
writeExecutableFile(sOfficeMemoryCommand, command); String sPmapOutputFile = FileHelper.appendPath(m_aTempDir.getTempDir(), "pmap_" + _sMode + ".txt");
command = command.replaceAll("<pmapoutputfile>", sPmapOutputFile);
createExecutableFile(sOfficeMemoryCommand, command);
ProcessHandler processID = new ProcessHandler(sOfficeMemoryCommand); ProcessHandler processID = new ProcessHandler(sOfficeMemoryCommand);
processID.noOutput();
processID.executeSynchronously(); processID.executeSynchronously();
int nError = processID.getExitCode();
assertTrue("Execute of " + sOfficeMemoryCommand + " failed", nError == 0);
String text = processID.getOutputText(); String text = processID.getOutputText();
if (text == null || text.equals("") || text.indexOf(' ') == -1) { if (text == null || text.equals("") || text.indexOf(' ') == -1)
failed("Could not determine Office memory usage. Check " + sOfficeMemoryCommand); {
fail("Could not determine Office memory usage. Check " + sOfficeMemoryCommand);
} }
StringTokenizer aToken = new StringTokenizer(text); StringTokenizer aToken = new StringTokenizer(text);
// this works, because the output of pmap is quite standardized. // this works, because the output of pmap is quite standardized.
...@@ -286,17 +511,28 @@ public class CheckMemoryUsage extends ComplexTestCase { ...@@ -286,17 +511,28 @@ public class CheckMemoryUsage extends ComplexTestCase {
* @param fileName The name of the created file * @param fileName The name of the created file
* @param line The commandline that has to be written inside of the file. * @param line The commandline that has to be written inside of the file.
*/ */
private void writeExecutableFile(String fileName, String line) { private void createExecutableFile(String fileName, String line)
try { {
PrintWriter fWriter = new PrintWriter(new FileWriter(fileName)); final String sChmod = "chmod a+x ";
final String bash = "#!/bin/bash";
try
{
String sFilename = FileHelper.getJavaCompatibleFilename(fileName);
PrintWriter fWriter = new PrintWriter(new FileWriter(sFilename));
fWriter.println(bash); fWriter.println(bash);
fWriter.println(line); fWriter.println(line);
fWriter.close(); fWriter.close();
// change rights to rwxrwxrwx // change rights to rwxrwxrwx
ProcessHandler processID = new ProcessHandler(sChmod + fileName); ProcessHandler processID = new ProcessHandler(sChmod + sFilename);
processID.noOutput();
processID.executeSynchronously(); processID.executeSynchronously();
int nError = processID.getExitCode();
assertTrue("chmod failed. ", nError == 0);
}
catch (java.io.IOException e)
{
} }
catch(java.io.IOException e) {
} }
} }
...@@ -304,11 +540,15 @@ public class CheckMemoryUsage extends ComplexTestCase { ...@@ -304,11 +540,15 @@ public class CheckMemoryUsage extends ComplexTestCase {
* Let this thread sleep for some time * Let this thread sleep for some time
* @param milliSeconds time to wait in milliseconds. * @param milliSeconds time to wait in milliseconds.
*/ */
private void shortWait(int milliSeconds) { public static void shortWait(int milliSeconds)
try { {
System.out.println("Wait for: " + milliSeconds + "ms");
try
{
Thread.sleep(milliSeconds); Thread.sleep(milliSeconds);
} }
catch(java.lang.InterruptedException e) { // ignore catch (java.lang.InterruptedException e)
{ // ignore
} }
} }
...@@ -316,15 +556,20 @@ public class CheckMemoryUsage extends ComplexTestCase { ...@@ -316,15 +556,20 @@ public class CheckMemoryUsage extends ComplexTestCase {
* Own file filter, will just return ok for all files that end with a given * Own file filter, will just return ok for all files that end with a given
* suffix * suffix
*/ */
private class FileFilter implements FilenameFilter { private class FileFilter implements FilenameFilter
{
private String suffix = null; private String suffix = null;
/** /**
* C'tor. * C'tor.
* @param suffix The suffix each filename should end with. * @param suffix The suffix each filename should end with.
*/ */
public FileFilter(String suffix) { public FileFilter(String suffix)
{
this.suffix = suffix; this.suffix = suffix;
} }
/** /**
* Returns true, if the name of the file has the suffix given to the * Returns true, if the name of the file has the suffix given to the
* c'tor. * c'tor.
...@@ -332,9 +577,32 @@ public class CheckMemoryUsage extends ComplexTestCase { ...@@ -332,9 +577,32 @@ public class CheckMemoryUsage extends ComplexTestCase {
* @param file Not used. * @param file Not used.
* @return True, if name ends with suffix. * @return True, if name ends with suffix.
*/ */
public boolean accept(File file, String name) { public boolean accept(File file, String name)
{
return name.endsWith(suffix); return name.endsWith(suffix);
} }
}; }
private XMultiServiceFactory getMSF()
{
final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
return xMSF1;
}
// 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();
} }
/*************************************************************************
*
* 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
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
package complex.memCheck;
import java.io.File;
/**
*
* @author ll93751
*/
public class FileHelper
{
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;
}
public static String getJavaCompatibleFilename(String _sFilename)
{
// It is a little bit stupid that office urls not compatible to java file urls
// System.out.println("java.io.File can't access Office file urls.");
if(_sFilename.startsWith("path:"))
{
final String sPath = _sFilename.substring(5);
return sPath;
}
String sSystemPath = graphical.FileHelper.getSystemPathFromFileURL(_sFilename);
if (sSystemPath == null)
{
sSystemPath = _sFilename;
}
return sSystemPath;
}
public static String getBasename(String _sFilename)
{
if (_sFilename == null)
{
return "";
}
// String fs = System.getProperty("file.separator");
int nIdx = _sFilename.lastIndexOf("\\");
if (nIdx == -1)
{
nIdx = _sFilename.lastIndexOf("/");
}
if (nIdx > 0)
{
return _sFilename.substring(nIdx + 1);
}
return _sFilename;
}
}
/*************************************************************************
*
* 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
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
package complex.memCheck;
import java.io.File;
import org.openoffice.test.OfficeFileUrl;
final class TestDocument
{
final static String sPathname = "testdocuments";
public static String getUrl(String name)
{
return OfficeFileUrl.getAbsolute(new File(sPathname, name));
}
public static String getUrl()
{
return OfficeFileUrl.getAbsolute(new File(sPathname));
}
private TestDocument() {}
}
...@@ -25,65 +25,111 @@ ...@@ -25,65 +25,111 @@
# #
#************************************************************************* #*************************************************************************
PRJ = ..$/..$/.. .IF "$(OOO_SUBSEQUENT_TESTS)" == ""
TARGET = MemoryCheck nothing .PHONY:
PRJNAME = $(TARGET) @echo "OOO_SUBSEQUENT_TESTS not set, do nothing."
PACKAGE = complex$/memCheck .ELSE
# --- Settings -----------------------------------------------------
.INCLUDE: settings.mk
#----- compile .java files -----------------------------------------
JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar
JAVAFILES = CheckMemoryUsage.java
#----- make a jar from compiled files ------------------------------
MAXLINELENGTH = 100000
JARCLASSDIRS = $(PACKAGE) PRJ = ../../..
JARTARGET = $(TARGET).jar PRJNAME = vcl
JARCOMPRESS = TRUE TARGET = qa_complex_memCheck
# --- Parameters for the test -------------------------------------- .IF "$(OOO_JUNIT_JAR)" != ""
PACKAGE = complex/memCheck
# start an office if the parameter is set for the makefile # here store only Files which contain a @Test
.IF "$(OFFICE)" == "" JAVATESTFILES = \
CT_APPEXECCOMMAND = CheckMemoryUsage.java
.ELSE
CT_APPEXECCOMMAND = -AppExecutionCommand \
"$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;"
.ENDIF
# test base is java complex # put here all other files
CT_TESTBASE = -TestBase java_complex JAVAFILES = $(JAVATESTFILES) \
FileHelper.java \
TestDocument.java
# replace $/ with . in package name
CT_PACKAGE = -o $(PACKAGE:s\$/\.\)
# start the runner application JARFILES = OOoRunner.jar ridl.jar test.jar unoil.jar
CT_APP = org.openoffice.Runner EXTRAJARFILES = $(OOO_JUNIT_JAR)
# --- Targets ------------------------------------------------------ # subdirectories
# SUBDIRS = helper
.IF "$(depend)" == "" # Sample how to debug
$(CLASSDIR)$/$(PACKAGE)$/CheckMemoryUsage.props : ALLTAR # JAVAIFLAGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9003,suspend=y
.ELSE
$(CLASSDIR)$/$(PACKAGE)$/CheckMemoryUsage.props : ALLTAR
.ENDIF
.INCLUDE : target.mk .END
.INCLUDE: settings.mk
.INCLUDE: target.mk
.INCLUDE: installationtest.mk
ALLTAR : javatest
$(CLASSDIR)$/$(PACKAGE)$/CheckMemoryUsage.props : CheckMemoryUsage.props .END
cp $(@:f) $@
jar uf $(CLASSDIR)$/$(JARTARGET) -C $(CLASSDIR) $(PACKAGE)$/$(@:f)
RUN: run
run: #
java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) $(CT_PACKAGE).CheckMemoryUsage #
#
# PRJ = ..$/..$/..
# TARGET = MemoryCheck
# PRJNAME = $(TARGET)
# PACKAGE = complex$/memCheck
#
# # --- Settings -----------------------------------------------------
# .INCLUDE: settings.mk
#
#
# #----- compile .java files -----------------------------------------
#
# JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar
# JAVAFILES = CheckMemoryUsage.java
#
# #----- make a jar from compiled files ------------------------------
#
# MAXLINELENGTH = 100000
#
# JARCLASSDIRS = $(PACKAGE)
# JARTARGET = $(TARGET).jar
# JARCOMPRESS = TRUE
#
# # --- Parameters for the test --------------------------------------
#
# # start an office if the parameter is set for the makefile
# .IF "$(OFFICE)" == ""
# CT_APPEXECCOMMAND =
# .ELSE
# CT_APPEXECCOMMAND = -AppExecutionCommand \
# "$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;"
# .ENDIF
#
# # test base is java complex
# CT_TESTBASE = -TestBase java_complex
#
# # replace $/ with . in package name
# CT_PACKAGE = -o $(PACKAGE:s\$/\.\)
#
# # start the runner application
# CT_APP = org.openoffice.Runner
#
# # --- Targets ------------------------------------------------------
#
# .IF "$(depend)" == ""
# $(CLASSDIR)$/$(PACKAGE)$/CheckMemoryUsage.props : ALLTAR
# .ELSE
# $(CLASSDIR)$/$(PACKAGE)$/CheckMemoryUsage.props : ALLTAR
# .ENDIF
#
# .INCLUDE : target.mk
#
#
#
# $(CLASSDIR)$/$(PACKAGE)$/CheckMemoryUsage.props : CheckMemoryUsage.props
# cp $(@:f) $@
# jar uf $(CLASSDIR)$/$(JARTARGET) -C $(CLASSDIR) $(PACKAGE)$/$(@:f)
#
#
# RUN: run
#
# run:
# java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) $(CT_PACKAGE).CheckMemoryUsage
...@@ -34,13 +34,9 @@ import com.sun.star.lang.XComponent; ...@@ -34,13 +34,9 @@ import com.sun.star.lang.XComponent;
import com.sun.star.awt.XWindow; import com.sun.star.awt.XWindow;
import com.sun.star.beans.PropertyValue; import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.PropertyState; import com.sun.star.beans.PropertyState;
import com.sun.star.frame.XController;
import com.sun.star.frame.FrameSearchFlag;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XFrame; import com.sun.star.frame.XFrame;
import com.sun.star.frame.FrameSearchFlag; import com.sun.star.frame.FrameSearchFlag;
import com.sun.star.frame.XFramesSupplier;
import helper.WindowListener; import helper.WindowListener;
/** /**
...@@ -59,7 +55,7 @@ public class DocumentHandle { ...@@ -59,7 +55,7 @@ public class DocumentHandle {
/** /**
* Constructor * Constructor
* @param xComponentLoader A loader to load a document * @param xCompLoader A loader to load a document
*/ */
public DocumentHandle(XComponentLoader xCompLoader) { public DocumentHandle(XComponentLoader xCompLoader) {
this.xCompLoader = xCompLoader; this.xCompLoader = xCompLoader;
...@@ -71,6 +67,7 @@ public class DocumentHandle { ...@@ -71,6 +67,7 @@ public class DocumentHandle {
* @param docName The name of a document as file URL * @param docName The name of a document as file URL
* @param hidden If true, the document is loaded hidden. * @param hidden If true, the document is loaded hidden.
* @return The size of the opened/created document. * @return The size of the opened/created document.
* @throws Exception
*/ */
public Rectangle loadDocument(String docName, boolean hidden) public Rectangle loadDocument(String docName, boolean hidden)
throws Exception{ throws Exception{
...@@ -91,13 +88,13 @@ public class DocumentHandle { ...@@ -91,13 +88,13 @@ public class DocumentHandle {
} }
// get the current active window // get the current active window
XFrame xCurFrame = (XFrame)UnoRuntime.queryInterface(XFrame.class, xCompLoader); XFrame xCurFrame = UnoRuntime.queryInterface(XFrame.class, xCompLoader);
// create a new frame // create a new frame
XFrame xFrame = xCurFrame.findFrame("_blank", FrameSearchFlag.CREATE); XFrame xFrame = xCurFrame.findFrame("_blank", FrameSearchFlag.CREATE);
// load document in this frame // load document in this frame
XComponentLoader xFrameLoader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, xFrame); XComponentLoader xFrameLoader = UnoRuntime.queryInterface(XComponentLoader.class, xFrame);
xComp = xFrameLoader.loadComponentFromURL( xComp = xFrameLoader.loadComponentFromURL(
docName, "_self", 0, szArgs); docName, "_self", 0, szArgs);
// wait for the document to load. // wait for the document to load.
......
...@@ -26,31 +26,27 @@ ...@@ -26,31 +26,27 @@
************************************************************************/ ************************************************************************/
package complex.persistent_window_states; package complex.persistent_window_states;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XInitialization;
import com.sun.star.uno.Type;
import com.sun.star.uno.Any; import com.sun.star.uno.Any;
import com.sun.star.lang.XTypeProvider;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XComponent;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XFramesSupplier; import com.sun.star.frame.XFramesSupplier;
import com.sun.star.frame.XFrames; import com.sun.star.frame.XFrames;
import com.sun.star.registry.XRegistryKey;
import com.sun.star.comp.loader.FactoryHelper;
import com.sun.star.container.XIndexAccess; import com.sun.star.container.XIndexAccess;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.AnyConverter; import com.sun.star.uno.AnyConverter;
import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XComponentLoader;
import com.sun.star.awt.Rectangle; import com.sun.star.awt.Rectangle;
import com.sun.star.util.XCloseable; import com.sun.star.util.XCloseable;
import helper.ConfigurationRead; import helper.ConfigurationRead;
import complexlib.ComplexTestCase;
import helper.OfficeProvider;
import complex.persistent_window_states.DocumentHandle;
// import org.junit.After;
import org.junit.AfterClass;
// import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openoffice.test.OfficeConnection;
import static org.junit.Assert.*;
/** /**
* Parameters: * Parameters:
...@@ -58,10 +54,11 @@ import complex.persistent_window_states.DocumentHandle; ...@@ -58,10 +54,11 @@ import complex.persistent_window_states.DocumentHandle;
* <li>NoOffice=yes - StarOffice is not started initially.</li> * <li>NoOffice=yes - StarOffice is not started initially.</li>
* </ul> * </ul>
*/ */
public class PersistentWindowTest extends ComplexTestCase { public class PersistentWindowTest
{
private XMultiServiceFactory xMSF; // private XMultiServiceFactory xMSF;
private OfficeProvider oProvider; // private OfficeProvider oProvider;
private int iOfficeCloseTime = 0; private int iOfficeCloseTime = 0;
/** /**
...@@ -69,9 +66,18 @@ public class PersistentWindowTest extends ComplexTestCase { ...@@ -69,9 +66,18 @@ public class PersistentWindowTest extends ComplexTestCase {
* Right now, it's only 'checkPersistentWindowState'. * Right now, it's only 'checkPersistentWindowState'.
* @return All test methods. * @return All test methods.
*/ */
public String[] getTestMethodNames() { // public String[] getTestMethodNames()
return new String[]{"checkPersistentWindowState"}; // {
} // return new String[]
// {
// "checkPersistentWindowState"
// };
// }
/**
* The test parameters
*/
// private static TestParameters param = null;
/** /**
* Test if all available document types change the * Test if all available document types change the
...@@ -94,42 +100,32 @@ public class PersistentWindowTest extends ComplexTestCase { ...@@ -94,42 +100,32 @@ public class PersistentWindowTest extends ComplexTestCase {
* - close office * - close office
* - Test finished * - Test finished
*/ */
public void checkPersistentWindowState() @Test public void checkPersistentWindowState()
{ {
try { // final XMultiServiceFactory xMsf = getMSF();
log.println("Connect the first time."); // some Tests need the qadevOOo TestParameters, it is like a Hashmap for Properties.
log.println("AppExecCommand: " + (String)param.get("AppExecutionCommand")); // param = new TestParameters();
log.println("ConnString: " + (String)param.get("ConnectionString")); // param.put("ServiceFactory", xMsf); // some qadevOOo functions need the ServiceFactory
oProvider = new OfficeProvider();
iOfficeCloseTime = param.getInt("OfficeCloseTime");
if ( iOfficeCloseTime == 0 ) {
iOfficeCloseTime = 1000;
}
if (!connect()) return; try
{
// create the configuration provider // At first we are already connected
Object o = null; // if (!connect())
try { // {
o = xMSF.createInstance( // return;
"com.sun.star.configuration.ConfigurationProvider"); // }
}
catch(com.sun.star.uno.Exception e) {
failed("Cannot create \"com.sun.star.configuration."+
"ConfigurationProvider\"");
return;
}
// fetch the multi service factory for setup // fetch the multi service factory for setup
XMultiServiceFactory xCP = (XMultiServiceFactory) // XMultiServiceFactory xCP = getMSF();
UnoRuntime.queryInterface(XMultiServiceFactory.class, o);
// create the configuration reader // create the configuration reader
ConfigurationRead cfgRead = new ConfigurationRead(xCP); // ConfigurationRead cfgRead = new ConfigurationRead(xCP);
// just test the wrong ones, not all. // just test the wrong ones, not all.
String [] els = new String[]{ String[] els = new String[]
{
"Office/Factories/com.sun.star.drawing.DrawingDocument", "Office/Factories/com.sun.star.drawing.DrawingDocument",
"Office/Factories/com.sun.star.formula.FormulaProperties", "Office/Factories/com.sun.star.formula.FormulaProperties",
//"Office/Factories/com.sun.star.presentation.PresentationDocument", //"Office/Factories/com.sun.star.presentation.PresentationDocument",
...@@ -139,34 +135,37 @@ public class PersistentWindowTest extends ComplexTestCase { ...@@ -139,34 +135,37 @@ public class PersistentWindowTest extends ComplexTestCase {
"Office/Factories/com.sun.star.text.WebDocument", "Office/Factories/com.sun.star.text.WebDocument",
}; };
// uncomment the following line for all doc types // uncomment the following line for all doc types
// String [] els = cfgRead.getSubNodeNames("Office/Factories"); // String [] els = cfgRead.getSubNodeNames("Office/Factories");
log.println("Found "+ els.length + " document types to test.\n"); System.out.println("Found " + els.length + " document types to test.\n");
if (!disconnect()) return; disconnect();
// for all types // for all types
for(int i=0; i<els.length; i++) { for (int i = 0; i < els.length; i++)
log.println("\tStart test for document type " + i + ": " + els[i]); {
System.out.println("\tStart test for document type " + i + ": " + els[i]);
// exclude chart documents: cannot be created this way. // exclude chart documents: cannot be created this way.
if ( els[i].indexOf("ChartDocument") != -1) { if (els[i].indexOf("ChartDocument") != -1)
log.println("Skipping chart document: cannot be create like this."); {
System.out.println("Skipping chart document: cannot be create like this.");
continue; continue;
} }
// start an office // start an office
if (!connect()) return; connect();
// get configuration // get configuration
String[] settings = getConfigurationAndLoader(xMSF, els[i]); String[] settings = getConfigurationAndLoader(getMSF(), els[i]);
if (settings == null) { if (settings == null)
log.println("Skipping document type " + els[i]); {
System.out.println("Skipping document type " + els[i]);
disconnect(); disconnect();
continue; continue;
} }
String cfg = settings[1]; String cfg = settings[1];
// load a document // load a document
DocumentHandle handle = loadDocument(xMSF, settings[0]); DocumentHandle handle = loadDocument(getMSF(), settings[0]);
// first size // first size
Rectangle rect1 = handle.getDocumentPosSize(); Rectangle rect1 = handle.getDocumentPosSize();
...@@ -177,53 +176,56 @@ public class PersistentWindowTest extends ComplexTestCase { ...@@ -177,53 +176,56 @@ public class PersistentWindowTest extends ComplexTestCase {
Rectangle rect2 = handle.getDocumentPosSize(); Rectangle rect2 = handle.getDocumentPosSize();
// disposeManager and start a new office // disposeManager and start a new office
if (!disconnect()) return; disconnect();
if (!connect()) return; connect();
// get configuration // get configuration
settings = getConfigurationAndLoader(xMSF, els[i]); settings = getConfigurationAndLoader(getMSF(), els[i]);
String newCfg = settings[1]; String newCfg = settings[1];
// load a document // load a document
handle = loadDocument(xMSF, settings[0]); handle = loadDocument(getMSF(), settings[0]);
Rectangle newRect = handle.getDocumentPosSize(); Rectangle newRect = handle.getDocumentPosSize();
// print the settings and window sizes // print the settings and window sizes
log.println("----------------------------"); System.out.println("----------------------------");
log.println("Initial Config String : " + cfg); System.out.println("Initial Config String : " + cfg);
log.println("Config String after restart: " + newCfg); System.out.println("Config String after restart: " + newCfg);
log.println("----------------------------"); System.out.println("----------------------------");
log.println("Initial window (X,Y,Width,Height): " System.out.println("Initial window (X,Y,Width,Height): "
+rect1.X+";"+rect1.Y+";"+ rect1.Width+";"+rect1.Height); + rect1.X + ";" + rect1.Y + ";" + rect1.Width + ";" + rect1.Height);
log.println("Window after resize (X,Y,Width,Height): " System.out.println("Window after resize (X,Y,Width,Height): "
+rect2.X+";"+rect2.Y+";"+ rect2.Width+";"+rect2.Height); + rect2.X + ";" + rect2.Y + ";" + rect2.Width + ";" + rect2.Height);
log.println("Window after restart (X,Y,Width,Height): " System.out.println("Window after restart (X,Y,Width,Height): "
+newRect.X+";"+newRect.Y+";"+newRect.Width+";" + newRect.X + ";" + newRect.Y + ";" + newRect.Width + ";"
+newRect.Height); + newRect.Height);
// compare to see if resize worked // compare to see if resize worked
log.println("----------------------------"); System.out.println("----------------------------");
assure("Resize values for "+ els[i] + if (els[i].indexOf("SpreadsheetDocument") == -1 &&
" are equal.", !compareRectangles(rect1, rect2), true); els[i].indexOf("DrawingDocument") == -1)
{
// leave out Spreadsheet- and DrawingDocumnt
assertTrue("Resize values for " + els[i] + " are equal.", !compareRectangles(rect1, rect2));
}
// compare settings and sizes // compare settings and sizes
assure("Config settings for "+ els[i] + assertTrue("Config settings for " + els[i] + " were not changed.", !cfg.equals(newCfg));
" were not changed.", !cfg.equals(newCfg), true); assertTrue("Resized and restarted window for " + els[i] + " are not equal.", compareRectangles(rect2, newRect));
assure("Resized and restarted window for "+ els[i] + System.out.println("----------------------------");
" are not equal.", compareRectangles(rect2, newRect), true);
log.println("----------------------------");
// disposeManager // disposeManager
if (!disconnect()) return; disconnect();
log.println("\tFinish test for document type " + i + ": " + els[i]); System.out.println("\tFinish test for document type " + i + ": " + els[i]);
} }
} }
catch(Exception e) { catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -235,16 +237,17 @@ public class PersistentWindowTest extends ComplexTestCase { ...@@ -235,16 +237,17 @@ public class PersistentWindowTest extends ComplexTestCase {
* @return Settings and Loader * @return Settings and Loader
*/ */
private static String[] getConfigurationAndLoader(XMultiServiceFactory xMSF, private static String[] getConfigurationAndLoader(XMultiServiceFactory xMSF,
String cfgString) { String cfgString)
{
String[] conf = new String[2]; String[] conf = new String[2];
try { try
{
Object o = xMSF.createInstance( Object o = xMSF.createInstance(
"com.sun.star.configuration.ConfigurationProvider"); "com.sun.star.configuration.ConfigurationProvider");
// fetch the multi service factory for setup // fetch the multi service factory for setup
XMultiServiceFactory xCP = (XMultiServiceFactory) XMultiServiceFactory xCP = UnoRuntime.queryInterface(XMultiServiceFactory.class, o);
UnoRuntime.queryInterface(XMultiServiceFactory.class, o);
// create the configuration reader // create the configuration reader
ConfigurationRead cfgRead = new ConfigurationRead(xCP); ConfigurationRead cfgRead = new ConfigurationRead(xCP);
...@@ -253,22 +256,28 @@ public class PersistentWindowTest extends ComplexTestCase { ...@@ -253,22 +256,28 @@ public class PersistentWindowTest extends ComplexTestCase {
String loader = getStringFromObject( String loader = getStringFromObject(
cfgRead.getByHierarchicalName(cfgString + "/ooSetupFactoryEmptyDocumentURL")); cfgRead.getByHierarchicalName(cfgString + "/ooSetupFactoryEmptyDocumentURL"));
if (loader == null) return null; if (loader == null)
log.println("\tLoader: " + loader); {
return null;
}
System.out.println("\tLoader: " + loader);
// read attributes // read attributes
String hierchName = cfgString + "/ooSetupFactoryWindowAttributes"; String hierchName = cfgString + "/ooSetupFactoryWindowAttributes";
String setupSettings = getStringFromObject(cfgRead.getByHierarchicalName(hierchName)); String setupSettings = getStringFromObject(cfgRead.getByHierarchicalName(hierchName));
// remove slots: just plain document types have to start // remove slots: just plain document types have to start
if ( loader.indexOf("?slot") != -1 ) { if (loader.indexOf("?slot") != -1)
{
loader = loader.substring(0, loader.indexOf("?slot")); loader = loader.substring(0, loader.indexOf("?slot"));
System.out.println("Loader: "+loader); System.out.println("Loader: " + loader);
} }
conf[0] = loader; conf[0] = loader;
conf[1] = setupSettings; conf[1] = setupSettings;
} }
catch(com.sun.star.uno.Exception e) {} catch (com.sun.star.uno.Exception e)
{
}
return conf; return conf;
} }
...@@ -279,97 +288,105 @@ public class PersistentWindowTest extends ComplexTestCase { ...@@ -279,97 +288,105 @@ public class PersistentWindowTest extends ComplexTestCase {
* @return A handle to the document * @return A handle to the document
*/ */
private DocumentHandle loadDocument(XMultiServiceFactory xMSF, private DocumentHandle loadDocument(XMultiServiceFactory xMSF,
String docLoader) { String docLoader)
{
DocumentHandle docHandle = null; DocumentHandle docHandle = null;
try { try
{
// create component loaader // create component loaader
XComponentLoader xCompLoader = (XComponentLoader) XComponentLoader xCompLoader = UnoRuntime.queryInterface(XComponentLoader.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
UnoRuntime.queryInterface( XFramesSupplier xFrameSupp = UnoRuntime.queryInterface(XFramesSupplier.class, xCompLoader);
XComponentLoader.class, xMSF.createInstance(
"com.sun.star.frame.Desktop"));
XFramesSupplier xFrameSupp = (XFramesSupplier)UnoRuntime.queryInterface(XFramesSupplier.class, xCompLoader);
// close all existing frames // close all existing frames
XFrames xFrames = xFrameSupp.getFrames(); XFrames xFrames = xFrameSupp.getFrames();
XIndexAccess xAcc = (XIndexAccess)UnoRuntime.queryInterface(XIndexAccess.class, xFrames); XIndexAccess xAcc = UnoRuntime.queryInterface(XIndexAccess.class, xFrames);
for ( int i=0; i<xAcc.getCount(); i++ ) { for (int i = 0; i < xAcc.getCount(); i++)
XCloseable xClose = (XCloseable)UnoRuntime.queryInterface(XCloseable.class, xAcc.getByIndex(i)); {
try { XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xAcc.getByIndex(i));
if ( xClose != null ) { try
{
if (xClose != null)
{
xClose.close(false); xClose.close(false);
} }
else { else
failed("Could not query frame for XCloseable!"); {
fail("Could not query frame for XCloseable!");
} }
} }
catch( com.sun.star.uno.Exception e ) { catch (com.sun.star.uno.Exception e)
e.printStackTrace((java.io.PrintWriter)log); {
failed("Could not query frame for XCloseable!"); e.printStackTrace();
fail("Could not query frame for XCloseable!");
} }
} }
docHandle = new DocumentHandle(xCompLoader); docHandle = new DocumentHandle(xCompLoader);
docHandle.loadDocument(docLoader, false); docHandle.loadDocument(docLoader, false);
} }
catch(com.sun.star.uno.Exception e) { catch (com.sun.star.uno.Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
catch(java.lang.Exception e) { catch (java.lang.Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
return docHandle; return docHandle;
} }
private boolean connect() { private boolean connect()
try { {
xMSF = (XMultiServiceFactory)oProvider.getManager(param); try
try { {
Thread.sleep(10000); connection.setUp();
} }
catch(java.lang.InterruptedException e) {} catch (java.lang.InterruptedException e)
{
fail("can't connect.");
} }
catch (java.lang.Exception e) { catch (Exception e)
log.println(e.getClass().getName()); {
log.println("Message: " + e.getMessage()); fail("can't connect.");
failed("Cannot connect the Office.");
return false;
} }
return true; return true;
} }
private boolean disconnect() { private boolean disconnect()
try { {
XDesktop desk = null; try
desk = (XDesktop) UnoRuntime.queryInterface( {
XDesktop.class, xMSF.createInstance( connection.tearDown();
"com.sun.star.frame.Desktop"));
xMSF = null;
desk.terminate();
log.println("Waiting " + iOfficeCloseTime + " milliseconds for the Office to close down");
try {
Thread.sleep(iOfficeCloseTime);
} }
catch(java.lang.InterruptedException e) {} catch (java.lang.InterruptedException e)
{
fail("can't disconnect.");
} }
catch (java.lang.Exception e) { catch (Exception e)
e.printStackTrace(); {
failed("Cannot dispose the Office."); fail("can't disconnect.");
return false;
} }
return true; return true;
} }
private static String getStringFromObject(Object oName) { private static String getStringFromObject(Object oName)
{
if (oName instanceof String) if (oName instanceof String)
return (String)oName; {
return (String) oName;
}
String value = null; String value = null;
if (oName instanceof Any) { if (oName instanceof Any)
try { {
try
{
value = AnyConverter.toString(oName); value = AnyConverter.toString(oName);
if (value == null) { if (value == null)
log.println("Got a void css.uno.Any as loading string."); {
System.out.println("Got a void css.uno.Any as loading string.");
} }
} }
catch(Exception e) { catch (Exception e)
log.println("This document type cannot be opened directly."); {
System.out.println("This document type cannot be opened directly.");
} }
} }
return value; return value;
...@@ -382,12 +399,37 @@ public class PersistentWindowTest extends ComplexTestCase { ...@@ -382,12 +399,37 @@ public class PersistentWindowTest extends ComplexTestCase {
* @param rect2 Second Rectangle. * @param rect2 Second Rectangle.
* @return True, if the rectangles are equal. * @return True, if the rectangles are equal.
*/ */
private boolean compareRectangles(Rectangle rect1, Rectangle rect2) { private boolean compareRectangles(Rectangle rect1, Rectangle rect2)
{
boolean result = true; boolean result = true;
result &= (rect1.X==rect2.X); result &= (rect1.X == rect2.X);
result &= (rect1.Y==rect2.Y); result &= (rect1.Y == rect2.Y);
result &= (rect1.Width==rect2.Width); result &= (rect1.Width == rect2.Width);
result &= (rect1.Height==rect2.Height); result &= (rect1.Height == rect2.Height);
return result; return result;
} }
private XMultiServiceFactory getMSF()
{
final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
return xMSF1;
}
// 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();
} }
...@@ -24,58 +24,48 @@ ...@@ -24,58 +24,48 @@
# for a copy of the LGPLv3 License. # for a copy of the LGPLv3 License.
# #
#************************************************************************* #*************************************************************************
.IF "$(OOO_SUBSEQUENT_TESTS)" == ""
nothing .PHONY:
@echo "OOO_SUBSEQUENT_TESTS not set, do nothing."
.ELSE
PRJ = ..$/..$/.. PRJ = ../../..
TARGET = PersistentWindowTest PRJNAME = vcl
PRJNAME = $(TARGET) TARGET = qa_complex_persistent_window_states
PACKAGE = complex$/persistent_window_states
# --- Settings ----------------------------------------------------- .IF "$(OOO_JUNIT_JAR)" != ""
.INCLUDE: settings.mk PACKAGE = complex/persistent_window_states
#----- compile .java files ----------------------------------------- # here store only Files which contain a @Test
JAVATESTFILES = \
PersistentWindowTest.java
JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar # put here all other files
JAVAFILES = PersistentWindowTest.java DocumentHandle.java JAVAFILES = $(JAVATESTFILES) \
DocumentHandle.java
#----- make a jar from compiled files ------------------------------
MAXLINELENGTH = 100000 JARFILES = OOoRunner.jar ridl.jar test.jar unoil.jar
EXTRAJARFILES = $(OOO_JUNIT_JAR)
JARCLASSDIRS = $(PACKAGE) # subdirectories
JARTARGET = $(TARGET).jar # SUBDIRS = helper
JARCOMPRESS = TRUE
# --- Parameters for the test -------------------------------------- # Sample how to debug
JAVAIFLAGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9003,suspend=y
# test base is java complex .END
CT_TESTBASE = -TestBase java_complex
# test looks something like the.full.package.TestName .INCLUDE: settings.mk
CT_TEST = -o $(PACKAGE:s\$/\.\).$(TARGET) .INCLUDE: target.mk
.INCLUDE: installationtest.mk
# start the runner application ALLTAR : javatest
CT_APP = org.openoffice.Runner
# --- Targets ------------------------------------------------------ .END
$(CLASSDIR)$/$(PACKAGE)$/$(TARGET).props : ALLTAR
.INCLUDE : target.mk
$(CLASSDIR)$/$(PACKAGE)$/$(TARGET).props : $(TARGET).props
cp $(TARGET).props $@
jar uf $(CLASSDIR)$/$(JARTARGET) -C $(CLASSDIR) $(PACKAGE)$/$(TARGET).props
RUN: run
# start an office if the parameter is set for the makefile
.IF "$(OFFICE)" == ""
run:
@echo "Execute this test with 'dmake run OFFICE=/system/path/to/office/program'."
@echo "The office will be started by the test with a socket connection on port 8100"
.ELSE
run: $(CLASSDIR)$/$(PACKAGE)$/$(TARGET).props
java -cp $(CLASSPATH) $(CT_APP) -AppExecutionCommand "$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;" $(CT_TESTBASE) $(CT_TEST)
.ENDIF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment