Kaydet (Commit) 84e1a01e authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Delete test*.odb files

...that are created in java.io.tmpdir (e.g., /tmp on Linux) by
connectivity.tools.HsqlDatabase.createDBDocument() during e.g.
JunitTest_dbaccess_complex.

This revealed that connectivity.tools.AbstractDatabase.delete() (even if it
would have been called by the test) would have been non-effective at deleting
the file, as the java.io.File constructor used takes a pathname not a file URL
as argument, so the call to java.io.File.delete() would not have deleted the
relevant file (and returned false, rather).

Change-Id: I268e1d1732ac7a0db9ccde7d4ac4f09aa3811e11
Reviewed-on: https://gerrit.libreoffice.org/44801Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 20f6242b
...@@ -124,14 +124,7 @@ public abstract class AbstractDatabase implements DatabaseAccess ...@@ -124,14 +124,7 @@ public abstract class AbstractDatabase implements DatabaseAccess
delete(); delete();
} }
private void delete() protected void delete() {}
{
if (m_databaseDocumentFile != null)
{
final File file = new File(m_databaseDocumentFile);
file.delete();
}
}
/** returns the underlying database document /** returns the underlying database document
*/ */
......
...@@ -33,6 +33,7 @@ import helper.URLHelper; ...@@ -33,6 +33,7 @@ import helper.URLHelper;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Assert;
public class HsqlDatabase extends AbstractDatabase public class HsqlDatabase extends AbstractDatabase
{ {
...@@ -54,10 +55,11 @@ public class HsqlDatabase extends AbstractDatabase ...@@ -54,10 +55,11 @@ public class HsqlDatabase extends AbstractDatabase
*/ */
private void createDBDocument() throws Exception private void createDBDocument() throws Exception
{ {
final File documentFile = File.createTempFile("testdb", ".odb"); Assert.assertNull(m_documentFile);
if ( documentFile.exists() ) m_documentFile = File.createTempFile("testdb", ".odb");
documentFile.delete(); if ( m_documentFile.exists() )
m_databaseDocumentFile = URLHelper.getFileURLFromSystemPath(documentFile); m_documentFile.delete();
m_databaseDocumentFile = URLHelper.getFileURLFromSystemPath(m_documentFile);
m_databaseDocument = UnoRuntime.queryInterface( m_databaseDocument = UnoRuntime.queryInterface(
XOfficeDatabaseDocument.class, m_orb.createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); XOfficeDatabaseDocument.class, m_orb.createInstance("com.sun.star.sdb.OfficeDatabaseDocument"));
...@@ -72,6 +74,13 @@ public class HsqlDatabase extends AbstractDatabase ...@@ -72,6 +74,13 @@ public class HsqlDatabase extends AbstractDatabase
} ); } );
} }
@Override protected final void delete() {
if (m_documentFile != null) {
boolean ok = m_documentFile.delete();
Assert.assertTrue("delete " + m_documentFile.getPath(), ok);
}
}
/** drops the table with a given name /** drops the table with a given name
@param _name @param _name
...@@ -188,4 +197,6 @@ public class HsqlDatabase extends AbstractDatabase ...@@ -188,4 +197,6 @@ public class HsqlDatabase extends AbstractDatabase
final XAppend appendTable = UnoRuntime.queryInterface( XAppend.class, suppTables.getTables() ); final XAppend appendTable = UnoRuntime.queryInterface( XAppend.class, suppTables.getTables() );
appendTable.appendByDescriptor(sdbcxDescriptor); appendTable.appendByDescriptor(sdbcxDescriptor);
} }
private File m_documentFile;
} }
...@@ -47,6 +47,7 @@ import java.lang.reflect.Method; ...@@ -47,6 +47,7 @@ import java.lang.reflect.Method;
import java.util.Random; import java.util.Random;
// ---------- junit imports ----------------- // ---------- junit imports -----------------
import org.junit.After;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
...@@ -127,6 +128,11 @@ public class RowSet extends TestCase ...@@ -127,6 +128,11 @@ public class RowSet extends TestCase
} }
} }
@After public final void closeAndDeleteDatabase() {
if (m_database != null) {
m_database.closeAndDelete();
}
}
/** creates a com.sun.star.sdb.RowSet to use during the test /** creates a com.sun.star.sdb.RowSet to use during the test
* @param command * @param command
......
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