mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-04 23:55:26 +02:00
Test case's for bugs:
[208778] - [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND [211374] - [ssh] New File on SSH has unnecessary space in its contents
This commit is contained in:
parent
250570d64e
commit
c79b571cca
2 changed files with 193 additions and 17 deletions
|
@ -0,0 +1,162 @@
|
|||
/********************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation. All rights reserved.
|
||||
* This program and the accompanying materials are made available under the terms
|
||||
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
|
||||
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Initial Contributors:
|
||||
* The following IBM employees contributed to the Remote System Explorer
|
||||
* component that contains this file: Kevin Doyle.
|
||||
*
|
||||
* Contributors:
|
||||
* {Name} (company) - description of contribution.
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.tests.subsystems.files;
|
||||
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.rse.core.IRSESystemType;
|
||||
import org.eclipse.rse.core.model.IHost;
|
||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||
import org.eclipse.rse.core.model.SystemStartHere;
|
||||
import org.eclipse.rse.core.subsystems.ISubSystem;
|
||||
import org.eclipse.rse.services.files.IFileService;
|
||||
import org.eclipse.rse.services.files.IHostFile;
|
||||
import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem;
|
||||
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
|
||||
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
|
||||
import org.eclipse.rse.ui.ISystemPreferencesConstants;
|
||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||
import org.eclipse.rse.ui.internal.model.SystemRegistry;
|
||||
|
||||
public class CreateFileTestCase extends FileServiceBaseTest {
|
||||
|
||||
private String SYSTEM_ADDRESS = "sles8rm";//"SLES8RM";
|
||||
private String USER_ID = "xxxxxx";
|
||||
private String PASSWORD = "xxxxxx"; //"xxxxxx";
|
||||
private IHost host;
|
||||
//TODO: See if additional characters in the name should work.
|
||||
// Also make sure if there are that they can be entered in the New
|
||||
// File Dialog. This string can be so using this for base test.
|
||||
private String fileName = "a !@#${a}'%^&()_ =[]~+-'`;,.txt"; //$NON-NLS-1$
|
||||
private IRemoteFile tempDirectory = null;
|
||||
|
||||
private IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) {
|
||||
IRemoteFileSubSystem fss = null;
|
||||
ISystemRegistry sr = SystemStartHere.getSystemRegistry();
|
||||
ISubSystem[] ss = sr.getServiceSubSystems(host, IFileService.class);
|
||||
for (int i=0; i<ss.length; i++) {
|
||||
if (ss[i] instanceof FileServiceSubSystem) {
|
||||
fss = (IRemoteFileSubSystem)ss[i];
|
||||
return fss;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected IHost getSSHHost()
|
||||
{
|
||||
IHost sshHost = null;
|
||||
|
||||
String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_SSH_ONLY_ID;
|
||||
String SYSTEM_NAME = SYSTEM_ADDRESS + "_ssh";
|
||||
|
||||
sshHost = getRemoteSystemConnection(SYSTEM_TYPE_ID, SYSTEM_ADDRESS, SYSTEM_NAME, USER_ID, PASSWORD);
|
||||
assertNotNull(sshHost);
|
||||
return sshHost;
|
||||
}
|
||||
|
||||
protected IHost getFTPHost()
|
||||
{
|
||||
IHost ftpHost = null;
|
||||
|
||||
String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_FTP_ONLY_ID;
|
||||
String SYSTEM_NAME = SYSTEM_ADDRESS + "_ftp";
|
||||
|
||||
ftpHost = getRemoteSystemConnection(SYSTEM_TYPE_ID, SYSTEM_ADDRESS, SYSTEM_NAME, USER_ID, PASSWORD);
|
||||
assertNotNull(ftpHost);
|
||||
return ftpHost;
|
||||
}
|
||||
|
||||
protected IHost getDStoreHost()
|
||||
{
|
||||
IHost dstoreHost = null;
|
||||
|
||||
String SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_LINUX_ID;
|
||||
String SYSTEM_NAME = SYSTEM_ADDRESS + "_dstore";
|
||||
|
||||
//Ensure that the SSL acknowledge dialog does not show up.
|
||||
//We need to setDefault first in order to set the value of a preference.
|
||||
IPreferenceStore store = RSEUIPlugin.getDefault().getPreferenceStore();
|
||||
store.setDefault(ISystemPreferencesConstants.ALERT_SSL, ISystemPreferencesConstants.DEFAULT_ALERT_SSL);
|
||||
store.setDefault(ISystemPreferencesConstants.ALERT_NONSSL, ISystemPreferencesConstants.DEFAULT_ALERT_NON_SSL);
|
||||
|
||||
store.setValue(ISystemPreferencesConstants.ALERT_SSL, false);
|
||||
store.setValue(ISystemPreferencesConstants.ALERT_NONSSL, false);
|
||||
|
||||
dstoreHost = getRemoteSystemConnection(SYSTEM_TYPE_ID, SYSTEM_ADDRESS, SYSTEM_NAME, USER_ID, PASSWORD);
|
||||
assertNotNull(dstoreHost);
|
||||
|
||||
return dstoreHost;
|
||||
}
|
||||
|
||||
public void testCreateFile() throws Exception {
|
||||
host = getFTPHost();
|
||||
createFileAndAssertProperties();
|
||||
|
||||
host = getDStoreHost();
|
||||
createFileAndAssertProperties();
|
||||
|
||||
host = getSSHHost();
|
||||
createFileAndAssertProperties();
|
||||
}
|
||||
|
||||
public void createFileAndAssertProperties() throws Exception {
|
||||
String SYSTEM_TYPE = host.getSystemType().getLabel();
|
||||
FileServiceSubSystem inputFss = (FileServiceSubSystem) getRemoteFileSubSystem(host);
|
||||
|
||||
// Need to create a temporary directory for the new file to be created in.
|
||||
// this is to ensure we don't overwrite any previous files.
|
||||
inputFss.connect(new NullProgressMonitor(), false);
|
||||
IRemoteFile homeDirectory = inputFss.getRemoteFileObject(".", new NullProgressMonitor());
|
||||
String baseFolderName = "rsetest";
|
||||
String homeFolderName = homeDirectory.getAbsolutePath();
|
||||
String testFolderName = FileServiceHelper.getRandomLocation(inputFss, homeFolderName, baseFolderName, new NullProgressMonitor());
|
||||
tempDirectory = createFileOrFolder(inputFss, homeFolderName, testFolderName, true);
|
||||
|
||||
tempDirPath = tempDirectory.getAbsolutePath();
|
||||
IHostFile hostfile = inputFss.getFileService().createFile(tempDirPath, fileName, new NullProgressMonitor());
|
||||
assertTrue(SYSTEM_TYPE + ": hostfile doesn't exist.", hostfile.exists());
|
||||
assertTrue(SYSTEM_TYPE + ": hostfile canRead returns false", hostfile.canRead());
|
||||
assertTrue(SYSTEM_TYPE + ": hostfile canWrite returns false", hostfile.canWrite());
|
||||
assertEquals(SYSTEM_TYPE + ": filename does not match.", fileName, hostfile.getName());
|
||||
assertEquals(SYSTEM_TYPE + ": path's to file do not match.", tempDirPath, hostfile.getParentPath());
|
||||
// Make sure the file is empty
|
||||
assertEquals(SYSTEM_TYPE + ": file size's do not match.", 0, hostfile.getSize());
|
||||
long modDate = hostfile.getModifiedDate();
|
||||
assertTrue(SYSTEM_TYPE + ": modification date is not greater than 0.", modDate > 0);
|
||||
|
||||
// perform cleanup, so EFS uses the right file service next time
|
||||
cleanup();
|
||||
}
|
||||
|
||||
public void cleanup() throws Exception {
|
||||
if (host != null) {
|
||||
if (tempDirectory != null) {
|
||||
IRemoteFileSubSystem fss = getRemoteFileSubSystem(host);
|
||||
fss.delete(tempDirectory, new NullProgressMonitor());
|
||||
fss.disconnect();
|
||||
tempDirectory = null;
|
||||
}
|
||||
SystemRegistry.getInstance().deleteHost(host);
|
||||
host = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
cleanup();
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ import org.eclipse.rse.ui.ISystemPreferencesConstants;
|
|||
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||
import org.eclipse.rse.ui.internal.model.SystemRegistry;
|
||||
|
||||
public class FileAppendOutputSteamTestCase extends FileServiceBaseTest {
|
||||
public class FileOutputStreamTestCase extends FileServiceBaseTest {
|
||||
|
||||
private String SYSTEM_ADDRESS = "sles8rm";//"SLES8RM";
|
||||
private String USER_ID = "xxxxxx";
|
||||
|
@ -116,22 +116,34 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest {
|
|||
}
|
||||
|
||||
public void testRSEFileStoreAppendOutputStream() throws Exception {
|
||||
// Go through each connection type setting it up and calling
|
||||
// appendToOutputStream(host)
|
||||
host = getLocalHost();
|
||||
appendToOutputStream();
|
||||
outputStreamFileWriting(EFS.APPEND);
|
||||
|
||||
host = getFTPHost();
|
||||
appendToOutputStream();
|
||||
outputStreamFileWriting(EFS.APPEND);
|
||||
|
||||
host = getDStoreHost();
|
||||
appendToOutputStream();
|
||||
outputStreamFileWriting(EFS.APPEND);
|
||||
|
||||
host = getSSHHost();
|
||||
appendToOutputStream();
|
||||
outputStreamFileWriting(EFS.APPEND);
|
||||
}
|
||||
|
||||
public void appendToOutputStream() throws Exception {
|
||||
public void testRSEFileStoreOverwriteOutputStream() throws Exception {
|
||||
host = getLocalHost();
|
||||
outputStreamFileWriting(EFS.NONE);
|
||||
|
||||
host = getFTPHost();
|
||||
outputStreamFileWriting(EFS.NONE);
|
||||
|
||||
host = getDStoreHost();
|
||||
outputStreamFileWriting(EFS.NONE);
|
||||
|
||||
host = getSSHHost();
|
||||
outputStreamFileWriting(EFS.NONE);
|
||||
}
|
||||
|
||||
public void outputStreamFileWriting(int options) throws Exception {
|
||||
// RSE URI: rse://SYSTEM_ADDRESS/PATH_TO_FIlE
|
||||
OutputStream outputStream = null;
|
||||
InputStream inputStream = null;
|
||||
|
@ -160,9 +172,8 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest {
|
|||
|
||||
IFileStore childFS = parentFS.getChild("append.txt");
|
||||
|
||||
outputStream = childFS.openOutputStream(EFS.APPEND, new NullProgressMonitor());
|
||||
|
||||
// Append to an empty file
|
||||
outputStream = childFS.openOutputStream(options, new NullProgressMonitor());
|
||||
|
||||
String contents = getRandomString();
|
||||
byte[] readBytes = new byte[contents.length()];
|
||||
outputStream.write(contents.getBytes());
|
||||
|
@ -173,13 +184,16 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest {
|
|||
|
||||
String input = new String(readBytes);
|
||||
inputStream.close();
|
||||
assertTrue(systemType + ": Contents incorrect when appending to an empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input));
|
||||
assertTrue(systemType + ": Contents incorrect writing to an empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input));
|
||||
|
||||
outputStream = childFS.openOutputStream(EFS.APPEND, new NullProgressMonitor());
|
||||
outputStream = childFS.openOutputStream(options, new NullProgressMonitor());
|
||||
|
||||
// Append to a not empty file
|
||||
String write = " " + getRandomString();
|
||||
contents += write;
|
||||
if ((options & EFS.APPEND) != 0) {
|
||||
contents += write;
|
||||
} else {
|
||||
contents = write;
|
||||
}
|
||||
outputStream.write(write.getBytes());
|
||||
outputStream.close();
|
||||
|
||||
|
@ -189,7 +203,7 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest {
|
|||
|
||||
input = new String(readBytes);
|
||||
inputStream.close();
|
||||
assertTrue(systemType + ": Contents incorrect when appending to a non-empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input));
|
||||
assertTrue(systemType + ": Contents incorrect writing to a non-empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input));
|
||||
// Cleanup, so IFileStore uses the correct connection next time.
|
||||
cleanup();
|
||||
}
|
||||
|
@ -239,4 +253,4 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest {
|
|||
cleanup();
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue